@miso.ai/client-sdk-ui 1.13.2-beta.0 → 1.14.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/asset/svgs.js +15 -4
- package/dist/cjs/combo/ask/index.js +2 -2
- package/dist/cjs/constants.js +118 -98
- package/dist/cjs/defaults/ask/controls.js +1 -1
- package/dist/cjs/defaults/hybrid-search/answer-box.js +4 -4
- package/dist/cjs/defaults.js +169 -0
- package/dist/cjs/element/container/index.js +14 -0
- package/dist/cjs/element/container/miso-ask.js +3 -3
- package/dist/cjs/element/container/miso-conversation.js +21 -0
- package/dist/cjs/element/container/miso-explore.js +1 -1
- package/dist/cjs/element/container/miso-history.js +21 -0
- package/dist/cjs/element/container/miso-hybrid-search.js +1 -1
- package/dist/cjs/element/container/miso-recommendation.js +1 -1
- package/dist/cjs/element/container/miso-search.js +1 -1
- package/dist/cjs/element/context/miso-follow-ups.js +1 -1
- package/dist/cjs/element/role/index.js +42 -0
- package/dist/cjs/element/role/miso-messages.js +20 -0
- package/dist/cjs/element/role/miso-new-thread.js +20 -0
- package/dist/cjs/element/role/miso-rename.js +20 -0
- package/dist/cjs/element/role/miso-subscription.js +20 -0
- package/dist/cjs/element/role/miso-threads.js +20 -0
- package/dist/cjs/element/role/miso-title.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +1 -1
- package/dist/cjs/layout/banner/banner.js +2 -1
- package/dist/cjs/layout/button/button.js +130 -0
- package/dist/cjs/layout/button/checkbox.js +115 -0
- package/dist/cjs/layout/button/more-button.js +3 -3
- package/dist/cjs/layout/container/container.js +1 -1
- package/dist/cjs/layout/error/error.js +2 -1
- package/dist/cjs/layout/index.js +28 -0
- package/dist/cjs/layout/input/facets.js +4 -3
- package/dist/cjs/layout/input/option-list.js +3 -2
- package/dist/cjs/layout/input/search-box.js +42 -9
- package/dist/cjs/layout/input/select.js +2 -1
- package/dist/cjs/layout/list/cards.js +2 -1
- package/dist/cjs/layout/list/carousel.js +2 -1
- package/dist/cjs/layout/list/collection.js +5 -0
- package/dist/cjs/layout/list/gallery.js +2 -1
- package/dist/cjs/layout/list/horizontal.js +2 -1
- package/dist/cjs/layout/list/list.js +2 -1
- package/dist/cjs/layout/list/messages.js +346 -0
- package/dist/cjs/layout/list/threads.js +257 -0
- package/dist/cjs/layout/mixin/trackable.js +4 -5
- package/dist/cjs/layout/mixin/triggerable.js +2 -2
- package/dist/cjs/layout/radio/feedback.js +4 -3
- package/dist/cjs/layout/templates.js +70 -0
- package/dist/cjs/layout/text/text.js +2 -1
- package/dist/cjs/layout/text/typewriter/index.js +4 -2
- package/dist/cjs/plugin.js +43 -104
- package/dist/cjs/util/confirm.js +33 -0
- package/dist/cjs/util/modal.js +48 -0
- package/dist/cjs/util/prompt.js +47 -0
- package/dist/cjs/version.js +1 -1
- package/package.json +5 -4
- package/src/CLAUDE.md +48 -105
- package/src/asset/svgs.js +14 -3
- package/src/combo/ask/index.js +2 -2
- package/src/constants.js +37 -147
- package/src/defaults/ask/controls.js +1 -1
- package/src/defaults/hybrid-search/answer-box.js +2 -2
- package/src/defaults.js +107 -0
- package/src/element/container/index.js +2 -0
- package/src/element/container/miso-ask.js +3 -3
- package/src/element/container/miso-conversation.js +19 -0
- package/src/element/container/miso-explore.js +1 -1
- package/src/element/container/miso-history.js +19 -0
- package/src/element/container/miso-hybrid-search.js +1 -1
- package/src/element/container/miso-recommendation.js +1 -1
- package/src/element/container/miso-search.js +1 -1
- package/src/element/context/miso-follow-ups.js +1 -1
- package/src/element/role/index.js +6 -0
- package/src/element/role/miso-messages.js +16 -0
- package/src/element/role/miso-new-thread.js +16 -0
- package/src/element/role/miso-rename.js +16 -0
- package/src/element/role/miso-subscription.js +16 -0
- package/src/element/role/miso-threads.js +16 -0
- package/src/element/role/miso-title.js +16 -0
- package/src/layout/affiliation/affiliation.js +2 -2
- package/src/layout/banner/banner.js +2 -1
- package/src/layout/button/button.js +116 -0
- package/src/layout/button/checkbox.js +91 -0
- package/src/layout/button/more-button.js +3 -3
- package/src/layout/container/container.js +2 -2
- package/src/layout/error/error.js +2 -1
- package/src/layout/index.js +4 -0
- package/src/layout/input/facets.js +3 -2
- package/src/layout/input/option-list.js +3 -2
- package/src/layout/input/search-box.js +41 -6
- package/src/layout/input/select.js +2 -1
- package/src/layout/list/cards.js +2 -1
- package/src/layout/list/carousel.js +2 -1
- package/src/layout/list/collection.js +6 -1
- package/src/layout/list/gallery.js +2 -1
- package/src/layout/list/horizontal.js +2 -1
- package/src/layout/list/list.js +2 -1
- package/src/layout/list/messages.js +318 -0
- package/src/layout/list/threads.js +206 -0
- package/src/layout/mixin/trackable.js +2 -3
- package/src/layout/mixin/triggerable.js +1 -1
- package/src/layout/radio/feedback.js +3 -2
- package/src/layout/templates.js +62 -0
- package/src/layout/text/text.js +2 -1
- package/src/layout/text/typewriter/index.js +5 -3
- package/src/plugin.js +31 -117
- package/src/util/confirm.js +28 -0
- package/src/util/modal.js +49 -0
- package/src/util/prompt.js +42 -0
- package/src/version.js +1 -1
- package/dist/cjs/actor/data.js +0 -132
- package/dist/cjs/actor/feedback.js +0 -29
- package/dist/cjs/actor/fields.js +0 -57
- package/dist/cjs/actor/filters.js +0 -161
- package/dist/cjs/actor/hub.js +0 -57
- package/dist/cjs/actor/index.js +0 -73
- package/dist/cjs/actor/interactions.js +0 -36
- package/dist/cjs/actor/sessions.js +0 -25
- package/dist/cjs/actor/tracker-states.js +0 -61
- package/dist/cjs/actor/tracker.js +0 -109
- package/dist/cjs/actor/trackers.js +0 -52
- package/dist/cjs/actor/utils.js +0 -15
- package/dist/cjs/actor/view.js +0 -294
- package/dist/cjs/actor/views.js +0 -209
- package/dist/cjs/source.js +0 -27
- package/dist/cjs/util/proxy.js +0 -88
- package/dist/cjs/util/trackers.js +0 -88
- package/dist/cjs/workflow/affiliations.js +0 -140
- package/dist/cjs/workflow/answer-based.js +0 -337
- package/dist/cjs/workflow/ask.js +0 -319
- package/dist/cjs/workflow/asks.js +0 -150
- package/dist/cjs/workflow/autocompletable.js +0 -63
- package/dist/cjs/workflow/autocomplete.js +0 -120
- package/dist/cjs/workflow/base.js +0 -418
- package/dist/cjs/workflow/context.js +0 -19
- package/dist/cjs/workflow/explore.js +0 -210
- package/dist/cjs/workflow/explores.js +0 -21
- package/dist/cjs/workflow/hybrid-search-answer.js +0 -88
- package/dist/cjs/workflow/hybrid-search-views.js +0 -109
- package/dist/cjs/workflow/hybrid-search.js +0 -213
- package/dist/cjs/workflow/index.js +0 -41
- package/dist/cjs/workflow/options/api.js +0 -41
- package/dist/cjs/workflow/options/auto-query.js +0 -97
- package/dist/cjs/workflow/options/configurable.js +0 -45
- package/dist/cjs/workflow/options/data-processor.js +0 -20
- package/dist/cjs/workflow/options/filters.js +0 -15
- package/dist/cjs/workflow/options/index.js +0 -126
- package/dist/cjs/workflow/options/interactions.js +0 -41
- package/dist/cjs/workflow/options/layouts.js +0 -79
- package/dist/cjs/workflow/options/options.js +0 -156
- package/dist/cjs/workflow/options/pagination.js +0 -25
- package/dist/cjs/workflow/options/roles.js +0 -15
- package/dist/cjs/workflow/options/templates.js +0 -30
- package/dist/cjs/workflow/options/trackers.js +0 -83
- package/dist/cjs/workflow/options/utils.js +0 -33
- package/dist/cjs/workflow/processors.js +0 -607
- package/dist/cjs/workflow/recommendation.js +0 -57
- package/dist/cjs/workflow/recommendations.js +0 -18
- package/dist/cjs/workflow/search-based.js +0 -337
- package/dist/cjs/workflow/search.js +0 -64
- package/dist/cjs/workflow/unit.js +0 -57
- package/dist/cjs/workflow/units.js +0 -42
- package/dist/cjs/workflow/use-link.js +0 -49
- package/src/actor/data.js +0 -106
- package/src/actor/feedback.js +0 -28
- package/src/actor/fields.js +0 -51
- package/src/actor/filters.js +0 -149
- package/src/actor/hub.js +0 -47
- package/src/actor/index.js +0 -10
- package/src/actor/interactions.js +0 -32
- package/src/actor/sessions.js +0 -21
- package/src/actor/tracker-states.js +0 -57
- package/src/actor/tracker.js +0 -104
- package/src/actor/trackers.js +0 -45
- package/src/actor/utils.js +0 -7
- package/src/actor/view.js +0 -272
- package/src/actor/views.js +0 -224
- package/src/source.js +0 -17
- package/src/util/proxy.js +0 -81
- package/src/util/trackers.js +0 -84
- package/src/workflow/affiliations.js +0 -121
- package/src/workflow/answer-based.js +0 -312
- package/src/workflow/ask.js +0 -284
- package/src/workflow/asks.js +0 -143
- package/src/workflow/autocompletable.js +0 -67
- package/src/workflow/autocomplete.js +0 -114
- package/src/workflow/base.js +0 -396
- package/src/workflow/context.js +0 -16
- package/src/workflow/explore.js +0 -194
- package/src/workflow/explores.js +0 -18
- package/src/workflow/hybrid-search-answer.js +0 -73
- package/src/workflow/hybrid-search-views.js +0 -116
- package/src/workflow/hybrid-search.js +0 -230
- package/src/workflow/index.js +0 -5
- package/src/workflow/options/api.js +0 -31
- package/src/workflow/options/auto-query.js +0 -70
- package/src/workflow/options/configurable.js +0 -48
- package/src/workflow/options/data-processor.js +0 -15
- package/src/workflow/options/filters.js +0 -10
- package/src/workflow/options/index.js +0 -11
- package/src/workflow/options/interactions.js +0 -36
- package/src/workflow/options/layouts.js +0 -73
- package/src/workflow/options/options.js +0 -175
- package/src/workflow/options/pagination.js +0 -18
- package/src/workflow/options/roles.js +0 -12
- package/src/workflow/options/templates.js +0 -27
- package/src/workflow/options/trackers.js +0 -80
- package/src/workflow/options/utils.js +0 -26
- package/src/workflow/processors.js +0 -490
- package/src/workflow/recommendation.js +0 -63
- package/src/workflow/recommendations.js +0 -14
- package/src/workflow/search-based.js +0 -329
- package/src/workflow/search.js +0 -73
- package/src/workflow/unit.js +0 -51
- package/src/workflow/units.js +0 -43
- package/src/workflow/use-link.js +0 -41
package/src/actor/fields.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export function session() {
|
|
2
|
-
return 'session';
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function completions() {
|
|
6
|
-
return 'completions';
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function filters() {
|
|
10
|
-
return 'filters';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function query() {
|
|
14
|
-
return 'query';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function request() {
|
|
18
|
-
return 'request';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function response() {
|
|
22
|
-
return 'response';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function data() {
|
|
26
|
-
return 'data';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function view(role) {
|
|
30
|
-
return role ? `view:${role}` : 'view';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function tracker() {
|
|
34
|
-
return 'tracker';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function interaction() {
|
|
38
|
-
return 'interaction';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function feedback() {
|
|
42
|
-
return 'feedback';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function input() {
|
|
46
|
-
return 'input';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function more() {
|
|
50
|
-
return 'more';
|
|
51
|
-
}
|
package/src/actor/filters.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { EventEmitter, trimObj, defineValues } from '@miso.ai/commons';
|
|
2
|
-
import * as fields from './fields.js';
|
|
3
|
-
|
|
4
|
-
function mergeState(state = {}, update = {}) {
|
|
5
|
-
return Object.freeze(trimObj({
|
|
6
|
-
...state,
|
|
7
|
-
...update,
|
|
8
|
-
facets: Object.freeze(trimObj({
|
|
9
|
-
...state.facets,
|
|
10
|
-
...update.facets,
|
|
11
|
-
})),
|
|
12
|
-
}));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function optionsToState({ sort } = {}) {
|
|
16
|
-
// TODO: facets
|
|
17
|
-
return trimObj({
|
|
18
|
-
facets: Object.freeze({}),
|
|
19
|
-
sort: sortOptionsToState(sort),
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function sortOptionsToState(sort) {
|
|
24
|
-
if (!sort) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
const { options = [] } = sort;
|
|
28
|
-
for (const option of options) {
|
|
29
|
-
if (option.default) {
|
|
30
|
-
return Object.freeze(option);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return Object.freeze(options[0]);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export default class Filters {
|
|
37
|
-
|
|
38
|
-
constructor(views, { facets: facetsOptions } = {}) {
|
|
39
|
-
this._views = views;
|
|
40
|
-
this._hub = views._hub;
|
|
41
|
-
const error = this._error = this._error.bind(this);
|
|
42
|
-
this._events = new EventEmitter({ target: this, error });
|
|
43
|
-
defineValues(this, { facets: new Facets(this, facetsOptions) });
|
|
44
|
-
|
|
45
|
-
this._unsubscribes = [
|
|
46
|
-
views._options.on('filters', () => this._syncOptions()),
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
this._syncOptions();
|
|
50
|
-
this._states = undefined;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
_syncOptions() {
|
|
54
|
-
const options = this._views._options.resolved.filters;
|
|
55
|
-
this._initialStates = optionsToState(options);
|
|
56
|
-
this.apply({ silent: true });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
_getStates() {
|
|
60
|
-
return this._states || this._initialStates;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
update(updates) {
|
|
64
|
-
const oldStates = this._getStates();
|
|
65
|
-
this._states = mergeState({ ...oldStates, ...updates });
|
|
66
|
-
const states = this._getStates();
|
|
67
|
-
this._events.emit('update', { updates, states, oldStates });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
reset({ silent = false } = {}) {
|
|
71
|
-
// TODO: review this
|
|
72
|
-
const oldStates = this._states;
|
|
73
|
-
this._states = undefined;
|
|
74
|
-
const states = this._getStates();
|
|
75
|
-
this._hub.update(fields.filters(), states, { silent });
|
|
76
|
-
this._events.emit('reset', { states, oldStates });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
apply({ silent = false } = {}) {
|
|
80
|
-
const states = this._getStates();
|
|
81
|
-
this._hub.update(fields.filters(), states, { silent });
|
|
82
|
-
!silent && this._events.emit('apply');
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
_error(error) {
|
|
86
|
-
this._views._error(error);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
_destroy() {
|
|
90
|
-
for (const unsubscribe of this._unsubscribes) {
|
|
91
|
-
unsubscribe();
|
|
92
|
-
}
|
|
93
|
-
this._unsubscribes = [];
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
class Facets {
|
|
99
|
-
|
|
100
|
-
constructor(filters, options = {}) {
|
|
101
|
-
this._filters = filters;
|
|
102
|
-
this._options = options;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
isSelected(field, value) {
|
|
106
|
-
return this._getFieldValues(field).includes(value);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
select(field, value) {
|
|
110
|
-
if (this.isSelected(field, value)) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
this._select(field, value);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
unselect(field, value) {
|
|
117
|
-
if (!this.isSelected(field, value)) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
this._unselect(field, value);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
toggle(field, value) {
|
|
124
|
-
if (this.isSelected(field, value)) {
|
|
125
|
-
this._unselect(field, value);
|
|
126
|
-
} else {
|
|
127
|
-
this._select(field, value);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
_getFieldValues(field) {
|
|
132
|
-
return this._filters._getStates().facets[field] || [];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
_select(field, value) {
|
|
136
|
-
const values = this._options.multivalued ? [...this._getFieldValues(field), value] : [value];
|
|
137
|
-
values.sort();
|
|
138
|
-
this._filters.update({ facets: { [field]: values } });
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
_unselect(field, value) {
|
|
142
|
-
let values = this._getFieldValues(field).filter(v => v !== value);
|
|
143
|
-
if (values.length === 0) {
|
|
144
|
-
values = undefined;
|
|
145
|
-
}
|
|
146
|
-
this._filters.update({ facets: { [field]: values } });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
}
|
package/src/actor/hub.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { defineValues, EventEmitter } from '@miso.ai/commons';
|
|
2
|
-
|
|
3
|
-
export default class Hub {
|
|
4
|
-
|
|
5
|
-
constructor(options = {}) {
|
|
6
|
-
(this._events = new EventEmitter())._injectSubscribeInterface(this);
|
|
7
|
-
this._options = options;
|
|
8
|
-
this._states = {};
|
|
9
|
-
defineValues(this, {
|
|
10
|
-
states: new Proxy(this._states, {
|
|
11
|
-
set() {}
|
|
12
|
-
}),
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
update(name, state, options = {}) {
|
|
17
|
-
this._states[name] = Object.freeze(state);
|
|
18
|
-
const event = Object.freeze({ action: 'update', name, state, ...options });
|
|
19
|
-
// callback after update, before emit
|
|
20
|
-
if (typeof this._options.onUpdate === 'function') {
|
|
21
|
-
this._options.onUpdate(event);
|
|
22
|
-
}
|
|
23
|
-
// emit
|
|
24
|
-
if (!options.silent) {
|
|
25
|
-
this._events.emit(name, state);
|
|
26
|
-
}
|
|
27
|
-
// callback after emit
|
|
28
|
-
if (typeof this._options.onEmit === 'function') {
|
|
29
|
-
this._options.onEmit(event);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
trigger(name, state) {
|
|
34
|
-
const event = Object.freeze({ action: 'trigger', name, state });
|
|
35
|
-
// callback before emit
|
|
36
|
-
if (typeof this._options.onUpdate === 'function') {
|
|
37
|
-
this._options.onUpdate(event);
|
|
38
|
-
}
|
|
39
|
-
// emit
|
|
40
|
-
this._events.emit(name, state);
|
|
41
|
-
// callback after emit
|
|
42
|
-
if (typeof this._options.onEmit === 'function') {
|
|
43
|
-
this._options.onEmit(event);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}
|
package/src/actor/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as fields from './fields.js';
|
|
2
|
-
|
|
3
|
-
export { fields };
|
|
4
|
-
export { default as Hub } from './hub.js';
|
|
5
|
-
export { default as SessionMaker } from './sessions.js';
|
|
6
|
-
export { default as DataActor } from './data.js';
|
|
7
|
-
export { default as ViewsActor } from './views.js';
|
|
8
|
-
export { default as FeedbackActor } from './feedback.js';
|
|
9
|
-
export { default as InteractionsActor } from './interactions.js';
|
|
10
|
-
export * from './trackers.js';
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { asArray } from '@miso.ai/commons';
|
|
2
|
-
import * as fields from './fields.js';
|
|
3
|
-
|
|
4
|
-
export default class InteractionsActor {
|
|
5
|
-
|
|
6
|
-
constructor(hub, { client, options }) {
|
|
7
|
-
this._client = client;
|
|
8
|
-
this._options = options;
|
|
9
|
-
this._unsubscribes = [
|
|
10
|
-
hub.on(fields.interaction(), payload => this._handle(payload)),
|
|
11
|
-
];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
_handle(payload) {
|
|
15
|
-
// TODO: omit when option == false
|
|
16
|
-
payload = asArray(payload);
|
|
17
|
-
|
|
18
|
-
if (payload.length === 0) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
this._client.api.interactions.upload(payload, { merge: true });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
destroy() {
|
|
26
|
-
for (const unsubscribe of this._unsubscribes) {
|
|
27
|
-
unsubscribe();
|
|
28
|
-
}
|
|
29
|
-
this._unsubscribes = [];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
package/src/actor/sessions.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { uuidv4 } from '@miso.ai/commons';
|
|
2
|
-
import * as fields from './fields.js';
|
|
3
|
-
|
|
4
|
-
export default class SessionMaker {
|
|
5
|
-
|
|
6
|
-
constructor(hub) {
|
|
7
|
-
this._hub = hub;
|
|
8
|
-
this._sessionIndex = 0;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
restart() {
|
|
12
|
-
const session = Object.freeze({
|
|
13
|
-
uuid: uuidv4(),
|
|
14
|
-
index: this._sessionIndex++,
|
|
15
|
-
startAt: Date.now(),
|
|
16
|
-
meta: {},
|
|
17
|
-
});
|
|
18
|
-
this._hub.update(fields.session(), session);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { asArray, computeIfAbsent } from '@miso.ai/commons';
|
|
2
|
-
import { EVENT_TYPE, TRACKING_STATUS, validateEventType, validateTrackingStatus } from '../constants.js';
|
|
3
|
-
|
|
4
|
-
const { IMPRESSION, VIEWABLE, CLICK } = EVENT_TYPE;
|
|
5
|
-
const { UNTRACKED, TRIGGERED } = TRACKING_STATUS;
|
|
6
|
-
|
|
7
|
-
const UNTRACKED_STATES = Object.freeze({
|
|
8
|
-
[IMPRESSION]: UNTRACKED,
|
|
9
|
-
[VIEWABLE]: UNTRACKED,
|
|
10
|
-
[CLICK]: UNTRACKED,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Tracking states for a session to keep track of the tracking status of each product.
|
|
15
|
-
* For each entry there are status of impression, viewable, and click events.
|
|
16
|
-
*/
|
|
17
|
-
export default class States {
|
|
18
|
-
|
|
19
|
-
constructor(sessionId) {
|
|
20
|
-
this.sessionId = sessionId;
|
|
21
|
-
this._states = new Map(); // item key -> {impression, viewable, click}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getFullState(item) {
|
|
25
|
-
// when we receive a bind event, impression is trigger, making an entry here
|
|
26
|
-
// so if the state is not found, the product is not present yet => all untracked
|
|
27
|
-
const state = this._states.get(this._getKey(item));
|
|
28
|
-
return state ? { ...state } : UNTRACKED_STATES;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get(item, type) {
|
|
32
|
-
const state = this._states.get(this._getKey(item));
|
|
33
|
-
return state && state[type] || UNTRACKED;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
set(items, type, status) {
|
|
37
|
-
validateEventType(type);
|
|
38
|
-
validateTrackingStatus(status);
|
|
39
|
-
for (const item of asArray(items)) {
|
|
40
|
-
this._setOne(item, type, status);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
untriggered(items, type) {
|
|
45
|
-
return items.filter(item => this.get(item, type) !== TRIGGERED);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
_getKey(item) {
|
|
49
|
-
// TODO: ad-hoc! should move away to higher level
|
|
50
|
-
return item.product_id || item.text || item.id || item;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
_setOne(item, type, status) {
|
|
54
|
-
computeIfAbsent(this._states, this._getKey(item), () => ({ ...UNTRACKED_STATES }))[type] = status;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}
|
package/src/actor/tracker.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { asArray, trimObj, snakeToLowerCamel } from '@miso.ai/commons';
|
|
2
|
-
import { PERFORMANCE_EVENT_TYPES, DIRECT_TRACKING_EVENT_TYPES, TRACKING_STATUS, validateEventType } from '../constants.js';
|
|
3
|
-
import * as fields from './fields.js';
|
|
4
|
-
import States from './tracker-states.js';
|
|
5
|
-
|
|
6
|
-
// a dummy item array for manipulating deduplication
|
|
7
|
-
const ITEMLESS_DUMMY_ITEMS = [Symbol('itemless')];
|
|
8
|
-
|
|
9
|
-
export default class Tracker {
|
|
10
|
-
|
|
11
|
-
constructor({ hub, role, options }) {
|
|
12
|
-
this._hub = hub;
|
|
13
|
-
this._role = role;
|
|
14
|
-
this._options = options;
|
|
15
|
-
// TODO: know item type
|
|
16
|
-
|
|
17
|
-
this._states = new States(this._getSessionId());
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get options() {
|
|
21
|
-
return typeof this._options === 'function' ? this._options() : this._options;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getState(item) {
|
|
25
|
-
return this._states.getFullState(item);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
_trigger(type, items, meta) {
|
|
29
|
-
validateEventType(type);
|
|
30
|
-
|
|
31
|
-
const { options } = this;
|
|
32
|
-
if (!options || options.active === false) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
this._syncSession();
|
|
37
|
-
|
|
38
|
-
const { deduplicated = true, itemless = false } = options;
|
|
39
|
-
|
|
40
|
-
if (deduplicated) {
|
|
41
|
-
if (itemless) {
|
|
42
|
-
items = ITEMLESS_DUMMY_ITEMS;
|
|
43
|
-
}
|
|
44
|
-
items = this._states.untriggered(asArray(items), type);
|
|
45
|
-
if (items.length === 0) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
this._states.set(items, type, TRACKING_STATUS.TRIGGERED);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
this._sendToHub({
|
|
52
|
-
type,
|
|
53
|
-
items: itemless ? undefined : items,
|
|
54
|
-
...meta,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
_sendToHub(args) {
|
|
59
|
-
this._hub.trigger(fields.tracker(), Object.freeze(trimObj({ role: this._role, ...args })));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
_syncSession() {
|
|
63
|
-
const sessionId = this._getSessionId();
|
|
64
|
-
if (!sessionId) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (!this._states || sessionId !== this._states.sessionId) {
|
|
68
|
-
this._states = new States(sessionId);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
_getSessionId() {
|
|
73
|
-
const { session } = this._getViewState() || {};
|
|
74
|
-
return session && session.uuid;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
_getMisoId() {
|
|
78
|
-
const state = this._getViewState();
|
|
79
|
-
return (state && state.meta && state.meta.miso_id) || undefined;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
_getRequestPayload() {
|
|
83
|
-
const { request } = this._getViewState() || {};
|
|
84
|
-
return request && request.payload;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
_getViewState() {
|
|
88
|
-
return this._hub.states[fields.view(this._role)];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
for (const type of PERFORMANCE_EVENT_TYPES) {
|
|
94
|
-
Tracker.prototype[snakeToLowerCamel(type)] = function(items, meta) {
|
|
95
|
-
this._trigger(type, items, meta);
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
for (const type of DIRECT_TRACKING_EVENT_TYPES) {
|
|
100
|
-
Tracker.prototype[snakeToLowerCamel(type)] = function(args) {
|
|
101
|
-
this._syncSession();
|
|
102
|
-
this._sendToHub({ ...args, type });
|
|
103
|
-
};
|
|
104
|
-
}
|
package/src/actor/trackers.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { ROLE } from '../constants.js';
|
|
2
|
-
import Tracker from './tracker.js';
|
|
3
|
-
|
|
4
|
-
export class TrackersActor {
|
|
5
|
-
|
|
6
|
-
constructor(hub, { roles, options }) {
|
|
7
|
-
this._hub = hub;
|
|
8
|
-
this._roles = roles;
|
|
9
|
-
this._options = options;
|
|
10
|
-
this._trackers = {};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get(role) {
|
|
14
|
-
if (!this._roles.members.includes(role)) {
|
|
15
|
-
throw new Error(`Role "${role}" is not a member of this workflow.`);
|
|
16
|
-
}
|
|
17
|
-
if (!this._trackers[role]) {
|
|
18
|
-
this._trackers[role] = new Tracker({
|
|
19
|
-
hub: this._hub,
|
|
20
|
-
role,
|
|
21
|
-
itemless: role === ROLE.CONTAINER,
|
|
22
|
-
options: () => this._getTrackerOptions(role),
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return this._trackers[role];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
_getTrackerOptions(role) {
|
|
29
|
-
const allTrackerOptions = this._options.resolved.trackers;
|
|
30
|
-
return allTrackerOptions && allTrackerOptions[role] || { active: false };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function proxyTrackers(trackers) {
|
|
36
|
-
return new Proxy(trackers, {
|
|
37
|
-
get: (target, prop) => {
|
|
38
|
-
try {
|
|
39
|
-
return target.get(prop);
|
|
40
|
-
} catch (_) {
|
|
41
|
-
}
|
|
42
|
-
return undefined;
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|