@miso.ai/client-sdk-core 1.5.1-beta.0 → 1.6.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/api/base.js +1 -15
- package/dist/cjs/api/helpers.js +2 -31
- package/dist/cjs/api/index.js +0 -9
- package/dist/cjs/api/interactions.js +7 -24
- package/dist/cjs/api/recommendation.js +0 -11
- package/dist/cjs/api/search.js +0 -8
- package/dist/cjs/classes.js +0 -9
- package/dist/cjs/client.js +0 -21
- package/dist/cjs/cmd.js +4 -8
- package/dist/cjs/context.js +0 -4
- package/dist/cjs/index.js +4 -8
- package/dist/cjs/plugin/anonymous.js +0 -4
- package/dist/cjs/plugin/auto-events.js +0 -28
- package/dist/cjs/plugin/index.js +0 -12
- package/dist/cjs/plugin/page-info.js +0 -12
- package/dist/cjs/plugin/plugin-root.js +7 -55
- package/dist/cjs/plugin/user.js +0 -26
- package/dist/cjs/root.js +4 -13
- package/dist/cjs/utils.js +7 -37
- package/dist/cjs/version.js +1 -1
- package/dist/es/api/base.js +1 -12
- package/dist/es/api/helpers.js +2 -27
- package/dist/es/api/index.js +0 -1
- package/dist/es/api/interactions.js +7 -20
- package/dist/es/api/recommendation.js +0 -7
- package/dist/es/api/search.js +0 -4
- package/dist/es/client.js +0 -13
- package/dist/es/cmd.js +4 -7
- package/dist/es/context.js +0 -1
- package/dist/es/index.js +4 -4
- package/dist/es/plugin/anonymous.js +0 -1
- package/dist/es/plugin/auto-events.js +0 -24
- package/dist/es/plugin/index.js +1 -2
- package/dist/es/plugin/page-info.js +0 -8
- package/dist/es/plugin/plugin-root.js +7 -48
- package/dist/es/plugin/user.js +0 -22
- package/dist/es/root.js +5 -7
- package/dist/es/utils.js +1 -34
- package/dist/es/version.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/plugin/units/constants.js +0 -10
- package/dist/cjs/plugin/units/index.js +0 -41
- package/dist/cjs/plugin/units/tracker.js +0 -365
- package/dist/cjs/plugin/units/unit.js +0 -63
- package/dist/cjs/plugin/units/units.js +0 -70
- package/dist/es/plugin/units/constants.js +0 -2
- package/dist/es/plugin/units/index.js +0 -27
- package/dist/es/plugin/units/tracker.js +0 -353
- package/dist/es/plugin/units/unit.js +0 -50
- package/dist/es/plugin/units/units.js +0 -56
|
@@ -8,36 +8,29 @@ export default class PluginRoot extends Registry {
|
|
|
8
8
|
keyName: 'id'
|
|
9
9
|
});
|
|
10
10
|
this._root = root;
|
|
11
|
-
|
|
12
11
|
this._events._replays.add('install').add('subtree');
|
|
13
|
-
|
|
14
12
|
this._installed = {};
|
|
15
13
|
this._useRequests = {};
|
|
16
14
|
this._subtrees = [];
|
|
17
15
|
this.context = new PluginContext(this, classes);
|
|
18
16
|
this.plugins = new Plugins(this);
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
isInstalled(id) {
|
|
22
19
|
this._checkKey(id);
|
|
23
|
-
|
|
24
20
|
return !!this._installed[id];
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
get installed() {
|
|
28
23
|
return Object.values(this._installed);
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
get(id) {
|
|
32
26
|
return this._installed[id];
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
getPluginClass(id) {
|
|
36
29
|
return this._libraries[id];
|
|
37
|
-
}
|
|
38
|
-
// TODO: refactor use() and _instantiate()
|
|
39
|
-
|
|
30
|
+
}
|
|
40
31
|
|
|
32
|
+
// TODO: we should be able to support (Class1, Class2, options2, etc.)
|
|
33
|
+
// TODO: refactor use() and _instantiate()
|
|
41
34
|
use(plugin, options) {
|
|
42
35
|
// use(PluginClass) is a shortcut of register() then use()
|
|
43
36
|
if (typeof plugin === 'function' && plugin.id && typeof plugin.id === 'string') {
|
|
@@ -45,97 +38,74 @@ export default class PluginRoot extends Registry {
|
|
|
45
38
|
this.use(plugin.id, options);
|
|
46
39
|
return;
|
|
47
40
|
}
|
|
48
|
-
|
|
49
41
|
let instance;
|
|
50
|
-
|
|
51
42
|
if (typeof plugin === 'string' && this.isInstalled(plugin)) {
|
|
52
43
|
// if already installed, try to run config() instead
|
|
53
44
|
instance = this.get(plugin);
|
|
54
|
-
|
|
55
45
|
this._tryConfig(instance, options);
|
|
56
|
-
|
|
57
46
|
return;
|
|
58
47
|
}
|
|
59
|
-
|
|
60
48
|
if (typeof plugin === 'string' && !this.isRegistered(plugin)) {
|
|
61
49
|
// not registered yet, push a use request
|
|
62
50
|
(this._useRequests[plugin] || (this._useRequests[plugin] = [])).push(options);
|
|
63
51
|
return;
|
|
64
52
|
}
|
|
65
|
-
|
|
66
53
|
instance = this._instantiate(plugin, options);
|
|
67
|
-
|
|
68
54
|
this._install(instance);
|
|
69
|
-
}
|
|
55
|
+
}
|
|
70
56
|
|
|
57
|
+
// TODO: unuse()
|
|
71
58
|
|
|
72
59
|
addSubtree(component) {
|
|
73
60
|
this._subtrees.push(component);
|
|
74
|
-
|
|
75
61
|
this._events.emit('subtree', component);
|
|
76
62
|
}
|
|
77
|
-
|
|
78
63
|
addPayloadPass(pass) {
|
|
79
64
|
if (typeof pass !== 'function') {
|
|
80
65
|
throw new Error(`Expect parameter to be a function: ${pass}`);
|
|
81
66
|
}
|
|
82
|
-
|
|
83
67
|
this._root._payloadPasses.push(pass);
|
|
84
68
|
}
|
|
85
|
-
|
|
86
69
|
addUrlPass(pass) {
|
|
87
70
|
if (typeof pass !== 'function') {
|
|
88
71
|
throw new Error(`Expect parameter to be a function: ${pass}`);
|
|
89
72
|
}
|
|
90
|
-
|
|
91
73
|
this._root._urlPasses.push(pass);
|
|
92
74
|
}
|
|
93
|
-
|
|
94
75
|
_tryConfig(instance, options) {
|
|
95
76
|
if (options === undefined) {
|
|
96
77
|
return;
|
|
97
78
|
}
|
|
98
|
-
|
|
99
79
|
if (typeof instance.config === 'function') {
|
|
100
80
|
instance.config(options);
|
|
101
81
|
} else {
|
|
102
82
|
this._warn(`Attempt to pass options to plugin "${instance.id}", which offers no config() method.`);
|
|
103
83
|
}
|
|
104
84
|
}
|
|
105
|
-
|
|
106
85
|
_instantiate(plugin, options) {
|
|
107
86
|
switch (typeof plugin) {
|
|
108
87
|
case 'string':
|
|
109
88
|
this._checkKey(plugin);
|
|
110
|
-
|
|
111
89
|
const pluginClass = this._libraries[plugin];
|
|
112
|
-
|
|
113
90
|
if (!pluginClass) {
|
|
114
91
|
throw new Error(`Plugin class not found: ${plugin}`);
|
|
115
92
|
}
|
|
116
|
-
|
|
117
93
|
const instance = new pluginClass();
|
|
118
94
|
defineValues(instance, {
|
|
119
95
|
id: plugin
|
|
120
96
|
});
|
|
121
|
-
|
|
122
97
|
this._tryConfig(instance, options);
|
|
123
|
-
|
|
124
98
|
return instance;
|
|
125
|
-
|
|
126
99
|
case 'function':
|
|
127
100
|
return new AnonymousPlugin(plugin);
|
|
128
101
|
}
|
|
129
|
-
|
|
130
102
|
throw new Error(`Unexpected parameters: ${plugin}`);
|
|
131
103
|
}
|
|
132
|
-
|
|
133
104
|
_install(instance) {
|
|
134
105
|
if (typeof instance.install !== 'function') {
|
|
135
106
|
// TODO: introduce PluginError
|
|
136
107
|
throw new Error(`Expect plugin.install to be a function: ${instance}`);
|
|
137
108
|
}
|
|
138
|
-
|
|
139
109
|
try {
|
|
140
110
|
instance.installed = false;
|
|
141
111
|
instance.install(this.MisoClient, this.context);
|
|
@@ -144,24 +114,18 @@ export default class PluginRoot extends Registry {
|
|
|
144
114
|
// TODO: introduce PluginError
|
|
145
115
|
throw e;
|
|
146
116
|
}
|
|
147
|
-
|
|
148
117
|
if (instance.id) {
|
|
149
118
|
// we don't track anonymous plugins
|
|
150
119
|
this._installed[instance.id] = instance;
|
|
151
120
|
}
|
|
152
|
-
|
|
153
121
|
this._events.emit('install', instance);
|
|
154
122
|
}
|
|
155
|
-
|
|
156
123
|
_register(lib) {
|
|
157
124
|
super._register(lib);
|
|
158
|
-
|
|
159
125
|
this._fulfillUseRequests(lib.id);
|
|
160
126
|
}
|
|
161
|
-
|
|
162
127
|
_fulfillUseRequests(id) {
|
|
163
128
|
const requests = this._useRequests[id];
|
|
164
|
-
|
|
165
129
|
if (requests) {
|
|
166
130
|
for (const options of requests) {
|
|
167
131
|
try {
|
|
@@ -170,16 +134,14 @@ export default class PluginRoot extends Registry {
|
|
|
170
134
|
this._error(e);
|
|
171
135
|
}
|
|
172
136
|
}
|
|
173
|
-
|
|
174
137
|
delete this._useRequests[id];
|
|
175
138
|
}
|
|
176
139
|
}
|
|
177
|
-
|
|
178
140
|
}
|
|
141
|
+
|
|
179
142
|
/**
|
|
180
143
|
* The interface of extended features only for plugin developers.
|
|
181
144
|
*/
|
|
182
|
-
|
|
183
145
|
class PluginContext {
|
|
184
146
|
constructor(root, classes) {
|
|
185
147
|
delegateGetters(this, root, ['getPluginClass', 'addSubtree', 'addPayloadPass', 'addUrlPass']);
|
|
@@ -187,16 +149,13 @@ class PluginContext {
|
|
|
187
149
|
classes
|
|
188
150
|
});
|
|
189
151
|
}
|
|
190
|
-
|
|
191
152
|
}
|
|
153
|
+
|
|
192
154
|
/**
|
|
193
155
|
* The interface of plugin features exposed to MisoClient.
|
|
194
156
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
197
157
|
class Plugins {
|
|
198
158
|
constructor(root) {
|
|
199
159
|
delegateGetters(this, root, ['installed', 'registered', 'isInstalled', 'isRegistered', 'get', 'register', 'use']);
|
|
200
160
|
}
|
|
201
|
-
|
|
202
161
|
}
|
package/dist/es/plugin/user.js
CHANGED
|
@@ -4,26 +4,20 @@ export default class UserPlugin extends Component {
|
|
|
4
4
|
static get id() {
|
|
5
5
|
return PLUGIN_ID;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
7
|
constructor() {
|
|
9
8
|
super('user');
|
|
10
9
|
this._contexts = new WeakMap();
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
install(MisoClient, context) {
|
|
14
12
|
context.addSubtree(this);
|
|
15
13
|
MisoClient.on('create', this._injectClient.bind(this));
|
|
16
14
|
context.addPayloadPass(this._modifyPayload.bind(this));
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
_injectClient(client) {
|
|
20
17
|
const context = new UserContext(this);
|
|
21
|
-
|
|
22
18
|
this._contexts.set(client, context);
|
|
23
|
-
|
|
24
19
|
delegateProperties(client.context, context, ['anonymous_id', 'user_id', 'user_hash']);
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
_modifyPayload(_ref) {
|
|
28
22
|
let {
|
|
29
23
|
client,
|
|
@@ -33,7 +27,6 @@ export default class UserPlugin extends Component {
|
|
|
33
27
|
} = _ref;
|
|
34
28
|
return apiGroup === 'interactions' && apiName === 'upload' ? this._modifyPayloadForInteractions(client, payload) : this._modifyPayloadForOthers(client, payload);
|
|
35
29
|
}
|
|
36
|
-
|
|
37
30
|
_modifyPayloadForOthers(client, payload) {
|
|
38
31
|
const {
|
|
39
32
|
user_id,
|
|
@@ -48,7 +41,6 @@ export default class UserPlugin extends Component {
|
|
|
48
41
|
};
|
|
49
42
|
return Object.assign({}, userInfo, payload);
|
|
50
43
|
}
|
|
51
|
-
|
|
52
44
|
_modifyPayloadForInteractions(client, _ref2) {
|
|
53
45
|
let {
|
|
54
46
|
data
|
|
@@ -66,52 +58,38 @@ export default class UserPlugin extends Component {
|
|
|
66
58
|
data
|
|
67
59
|
};
|
|
68
60
|
}
|
|
69
|
-
|
|
70
61
|
}
|
|
71
|
-
|
|
72
62
|
function getAutoAnonymousId() {
|
|
73
63
|
return getOrComputeFromStorage('miso_anonymous_id', uuidv4);
|
|
74
64
|
}
|
|
75
|
-
|
|
76
65
|
class UserContext {
|
|
77
66
|
constructor(plugin) {
|
|
78
67
|
this._plugin = plugin;
|
|
79
68
|
}
|
|
80
|
-
|
|
81
69
|
get anonymous_id() {
|
|
82
70
|
return this._anonymousId || this._autoAnonymousId || (this._autoAnonymousId = getAutoAnonymousId());
|
|
83
71
|
}
|
|
84
|
-
|
|
85
72
|
set anonymous_id(value) {
|
|
86
73
|
value = asString(value);
|
|
87
74
|
this._anonymousId = value;
|
|
88
|
-
|
|
89
75
|
this._plugin._events.emit('set', `anonymous_id = '${value}'`);
|
|
90
76
|
}
|
|
91
|
-
|
|
92
77
|
get user_id() {
|
|
93
78
|
return this._userId;
|
|
94
79
|
}
|
|
95
|
-
|
|
96
80
|
set user_id(value) {
|
|
97
81
|
value = asString(value);
|
|
98
82
|
this._userId = value;
|
|
99
|
-
|
|
100
83
|
this._plugin._events.emit('set', `user_id = '${value}'`);
|
|
101
84
|
}
|
|
102
|
-
|
|
103
85
|
get user_hash() {
|
|
104
86
|
return this._userHash;
|
|
105
87
|
}
|
|
106
|
-
|
|
107
88
|
set user_hash(value) {
|
|
108
89
|
if (typeof value !== 'string' && typeof value !== 'undefined') {
|
|
109
90
|
throw new Error(`User hash must be a string`);
|
|
110
91
|
}
|
|
111
|
-
|
|
112
92
|
this._userHash = value;
|
|
113
|
-
|
|
114
93
|
this._plugin._events.emit('set', `user_hash = '${value}'`);
|
|
115
94
|
}
|
|
116
|
-
|
|
117
95
|
}
|
package/dist/es/root.js
CHANGED
|
@@ -1,39 +1,37 @@
|
|
|
1
1
|
import { delegateGetters, Component } from '@miso.ai/commons';
|
|
2
2
|
import version from './version';
|
|
3
3
|
import PluginRoot from './plugin/plugin-root';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* The hidden singleton root component that oversees all client components.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
8
|
class Root extends Component {
|
|
9
9
|
constructor() {
|
|
10
10
|
super();
|
|
11
|
-
|
|
12
11
|
this._events._replays.add('create');
|
|
13
|
-
|
|
14
12
|
this._pluginRoot = new PluginRoot(this);
|
|
15
13
|
this._clients = [];
|
|
16
14
|
this._payloadPasses = [];
|
|
17
15
|
this._urlPasses = [];
|
|
18
16
|
this.version = version || 'dev';
|
|
19
17
|
}
|
|
20
|
-
|
|
21
18
|
get instances() {
|
|
22
19
|
return [...this._clients]; // write protection
|
|
23
20
|
}
|
|
24
21
|
|
|
22
|
+
async any() {
|
|
23
|
+
return this._clients[0] || this._any || (this._any = (await this._events.once('create')).data);
|
|
24
|
+
}
|
|
25
25
|
}
|
|
26
|
-
|
|
27
26
|
export const root = new Root();
|
|
28
27
|
export function init(MisoClient) {
|
|
29
28
|
const pluginRoot = root._pluginRoot;
|
|
30
29
|
root.MisoClient = pluginRoot.MisoClient = MisoClient;
|
|
31
|
-
delegateGetters(MisoClient, root, ['version', 'instances', 'meta', 'on', 'once']);
|
|
30
|
+
delegateGetters(MisoClient, root, ['version', 'instances', 'any', 'meta', 'on', 'once']);
|
|
32
31
|
delegateGetters(MisoClient, pluginRoot, ['plugins']);
|
|
33
32
|
return MisoClient;
|
|
34
33
|
}
|
|
35
34
|
export function register(client) {
|
|
36
35
|
root._clients.push(client);
|
|
37
|
-
|
|
38
36
|
root._events.emit('create', client);
|
|
39
37
|
}
|
package/dist/es/utils.js
CHANGED
|
@@ -1,34 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export async function viewable(element) {
|
|
3
|
-
let {
|
|
4
|
-
area = 0.5,
|
|
5
|
-
duration = 1000,
|
|
6
|
-
signal
|
|
7
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8
|
-
element = asElement(element); // TODO: check element
|
|
9
|
-
|
|
10
|
-
return new Promise(resolve => {
|
|
11
|
-
const continuity = new ContinuityObserver(value => {
|
|
12
|
-
if (value) {
|
|
13
|
-
continuity.disconnect();
|
|
14
|
-
intersection.disconnect();
|
|
15
|
-
resolve();
|
|
16
|
-
}
|
|
17
|
-
}, {
|
|
18
|
-
onDuration: duration
|
|
19
|
-
});
|
|
20
|
-
const intersection = new IntersectionObserver(entries => {
|
|
21
|
-
continuity.value = entries[0].isIntersecting;
|
|
22
|
-
}, {
|
|
23
|
-
threshold: area
|
|
24
|
-
});
|
|
25
|
-
intersection.observe(element);
|
|
26
|
-
|
|
27
|
-
if (signal && signal.addEventListener) {
|
|
28
|
-
signal.addEventListener('abort', () => {
|
|
29
|
-
continuity.disconnect();
|
|
30
|
-
intersection.disconnect();
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
1
|
+
export { viewable } from '@miso.ai/commons';
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.
|
|
1
|
+
export default '1.6.0-beta.1';
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ATTR_UNIT_ID = exports.ATTR_PRODUCT_ID = void 0;
|
|
7
|
-
const ATTR_UNIT_ID = 'data-miso-unit-id';
|
|
8
|
-
exports.ATTR_UNIT_ID = ATTR_UNIT_ID;
|
|
9
|
-
const ATTR_PRODUCT_ID = 'data-miso-product-id';
|
|
10
|
-
exports.ATTR_PRODUCT_ID = ATTR_PRODUCT_ID;
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
var _units = _interopRequireDefault(require("./units"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
const PLUGIN_ID = 'std:units';
|
|
15
|
-
|
|
16
|
-
class UnitsPlugin extends _commons.Component {
|
|
17
|
-
static get id() {
|
|
18
|
-
return PLUGIN_ID;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
constructor() {
|
|
22
|
-
super('units');
|
|
23
|
-
this._contexts = new WeakMap();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
install(MisoClient, context) {
|
|
27
|
-
context.addSubtree(this);
|
|
28
|
-
MisoClient.on('create', this._injectClient.bind(this));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
_injectClient(client) {
|
|
32
|
-
const context = new _units.default(this, client);
|
|
33
|
-
|
|
34
|
-
this._contexts.set(client, context);
|
|
35
|
-
|
|
36
|
-
client.units = context.interface;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
exports.default = UnitsPlugin;
|