@miso.ai/client-sdk-ui 1.10.0-beta.0 → 1.10.0-beta.10
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/actor/autocomplete.js +157 -0
- package/dist/cjs/actor/data.js +4 -12
- package/dist/cjs/actor/fields.js +8 -0
- package/dist/cjs/actor/index.js +7 -0
- package/dist/cjs/actor/tracker.js +46 -70
- package/dist/cjs/actor/trackers.js +5 -1
- package/dist/cjs/actor/utils.js +16 -2
- package/dist/cjs/actor/view.js +14 -3
- package/dist/cjs/actor/views.js +9 -1
- package/dist/cjs/affiliation/index.js +126 -0
- package/dist/cjs/combo/ask/options.js +1 -1
- package/dist/cjs/combo/base.js +1 -1
- package/dist/cjs/constants.js +6 -3
- package/dist/cjs/defaults/ask/controls.js +1 -1
- package/dist/cjs/defaults/ask/phrases.js +1 -1
- package/dist/cjs/defaults/ask/templates.js +35 -4
- package/dist/cjs/element/role/index.js +7 -0
- package/dist/cjs/element/role/miso-affiliation.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +330 -0
- package/dist/cjs/layout/banner/banner.js +1 -1
- package/dist/cjs/layout/container/container.js +1 -1
- package/dist/cjs/layout/error/error.js +1 -1
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/option-list.js +35 -50
- package/dist/cjs/layout/input/search-box.js +227 -129
- package/dist/cjs/layout/list/cards.js +1 -1
- package/dist/cjs/layout/list/carousel.js +5 -3
- package/dist/cjs/layout/list/collection.js +44 -49
- package/dist/cjs/layout/list/list.js +1 -1
- package/dist/cjs/layout/radio/feedback.js +1 -1
- package/dist/cjs/layout/radio/radio.js +1 -1
- package/dist/cjs/layout/raf.js +1 -1
- package/dist/cjs/layout/template.js +1 -1
- package/dist/cjs/layout/templates.js +172 -66
- package/dist/cjs/layout/text/text.js +1 -1
- package/dist/cjs/layout/text/typewriter/index.js +3 -3
- package/dist/cjs/layout/trackable.js +124 -0
- package/dist/cjs/plugin.js +1 -1
- package/dist/cjs/source/index.js +20 -8
- package/dist/cjs/util/bindings.js +58 -110
- package/dist/cjs/util/states.js +31 -24
- package/dist/cjs/util/trackers.js +75 -0
- package/dist/cjs/util/viewables.js +55 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/ask.js +60 -19
- package/dist/cjs/workflow/asks.js +1 -1
- package/dist/cjs/workflow/base.js +6 -7
- package/dist/cjs/workflow/explore.js +5 -2
- package/dist/cjs/workflow/options.js +60 -14
- package/dist/cjs/workflow/recommendation.js +2 -0
- package/dist/cjs/workflow/search.js +35 -7
- package/package.json +2 -2
- package/src/actor/autocomplete.js +131 -0
- package/src/actor/data.js +3 -10
- package/src/actor/fields.js +8 -0
- package/src/actor/index.js +1 -0
- package/src/actor/tracker.js +39 -62
- package/src/actor/trackers.js +3 -1
- package/src/actor/utils.js +14 -2
- package/src/actor/view.js +12 -1
- package/src/actor/views.js +11 -0
- package/src/affiliation/index.js +108 -0
- package/src/constants.js +10 -1
- package/src/defaults/ask/phrases.js +1 -1
- package/src/defaults/ask/templates.js +34 -2
- package/src/element/role/index.js +1 -0
- package/src/element/role/miso-affiliation.js +16 -0
- package/src/layout/affiliation/affiliation.js +295 -0
- package/src/layout/index.js +1 -0
- package/src/layout/input/option-list.js +35 -43
- package/src/layout/input/search-box.js +192 -95
- package/src/layout/list/carousel.js +4 -2
- package/src/layout/list/collection.js +42 -43
- package/src/layout/templates.js +127 -46
- package/src/layout/text/typewriter/index.js +2 -2
- package/src/layout/trackable.js +106 -0
- package/src/source/index.js +14 -1
- package/src/util/bindings.js +47 -103
- package/src/util/states.js +26 -20
- package/src/util/trackers.js +69 -0
- package/src/util/viewables.js +47 -0
- package/src/version.js +1 -1
- package/src/workflow/ask.js +37 -3
- package/src/workflow/base.js +2 -3
- package/src/workflow/explore.js +1 -1
- package/src/workflow/options.js +54 -13
- package/src/workflow/recommendation.js +1 -0
- package/src/workflow/search.js +33 -1
- package/dist/cjs/util/tracker.js +0 -348
- package/src/util/tracker.js +0 -318
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _constants = require("../constants.js");
|
|
8
|
+
var fields = _interopRequireWildcard(require("./fields.js"));
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
class AutocompleteActor {
|
|
12
|
+
constructor(hub, _ref) {
|
|
13
|
+
let {
|
|
14
|
+
source,
|
|
15
|
+
options
|
|
16
|
+
} = _ref;
|
|
17
|
+
this._hub = hub;
|
|
18
|
+
this._source = source;
|
|
19
|
+
this._options = options;
|
|
20
|
+
this._index = -1;
|
|
21
|
+
this._unsubscribes = [hub.on(fields.input(), () => this._sync()), options.on('autocomplete', () => this._syncOptions())];
|
|
22
|
+
|
|
23
|
+
// sync right away
|
|
24
|
+
this._sync(true);
|
|
25
|
+
}
|
|
26
|
+
get active() {
|
|
27
|
+
return this._options.resolved.autocomplete.actor !== false;
|
|
28
|
+
}
|
|
29
|
+
get source() {
|
|
30
|
+
return this._source;
|
|
31
|
+
}
|
|
32
|
+
_syncOptions() {
|
|
33
|
+
// TODO: explore scenarios where options.actor true -> false
|
|
34
|
+
this._sync(true);
|
|
35
|
+
}
|
|
36
|
+
async _sync() {
|
|
37
|
+
let force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
38
|
+
// protocol: inactive -> no reaction
|
|
39
|
+
if (!this.active) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const {
|
|
43
|
+
input
|
|
44
|
+
} = this._hub.states;
|
|
45
|
+
const value = input && input.value && input.value.trim() || undefined;
|
|
46
|
+
if (sameInput(this._input, input) && !force) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this._input = input;
|
|
50
|
+
const index = ++this._index;
|
|
51
|
+
|
|
52
|
+
// new input, abort previous data fetch if any
|
|
53
|
+
this._clearTimeout();
|
|
54
|
+
this._abortPendingRequest({
|
|
55
|
+
type: 'new-input',
|
|
56
|
+
message: 'A new input renders previous autocomplete request obsolete.'
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// emit loading/initial state
|
|
60
|
+
this._emitCompletions({
|
|
61
|
+
index,
|
|
62
|
+
input,
|
|
63
|
+
status: value ? _constants.STATUS.LOADING : _constants.STATUS.INITIAL
|
|
64
|
+
});
|
|
65
|
+
if (!value) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
const response = await this._fetchCompletions(input);
|
|
70
|
+
if (this._index !== index) {
|
|
71
|
+
return; // new results loading, discard this one
|
|
72
|
+
}
|
|
73
|
+
this._emitCompletions({
|
|
74
|
+
index,
|
|
75
|
+
input,
|
|
76
|
+
status: _constants.STATUS.READY,
|
|
77
|
+
value: response.completions
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
this._error(error);
|
|
81
|
+
if (this._index !== index) {
|
|
82
|
+
return; // ignore
|
|
83
|
+
}
|
|
84
|
+
this._emitCompletions({
|
|
85
|
+
index,
|
|
86
|
+
input,
|
|
87
|
+
status: _constants.STATUS.ERRONEOUS,
|
|
88
|
+
error
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async _getCompletions(input) {
|
|
93
|
+
// TODO: cache
|
|
94
|
+
return await this._fetchCompletions(input);
|
|
95
|
+
}
|
|
96
|
+
async _fetchCompletions(_ref2) {
|
|
97
|
+
let {
|
|
98
|
+
value
|
|
99
|
+
} = _ref2;
|
|
100
|
+
// TODO: other options?
|
|
101
|
+
const {
|
|
102
|
+
api
|
|
103
|
+
} = this._options.resolved.autocomplete;
|
|
104
|
+
const {
|
|
105
|
+
group,
|
|
106
|
+
name
|
|
107
|
+
} = api;
|
|
108
|
+
const {
|
|
109
|
+
signal
|
|
110
|
+
} = this._ac || {};
|
|
111
|
+
const options = Object.assign({}, api.options, {
|
|
112
|
+
signal
|
|
113
|
+
});
|
|
114
|
+
const payload = Object.assign({}, api.payload, {
|
|
115
|
+
q: value
|
|
116
|
+
});
|
|
117
|
+
return await this._source({
|
|
118
|
+
group,
|
|
119
|
+
name,
|
|
120
|
+
payload,
|
|
121
|
+
options
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
_clearTimeout() {
|
|
125
|
+
if (this._timeoutId) {
|
|
126
|
+
clearTimeout(this._timeoutId);
|
|
127
|
+
this._timeoutId = undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
_abortPendingRequest(info) {
|
|
131
|
+
this._ac && this._ac.abort(info);
|
|
132
|
+
this._ac = new AbortController();
|
|
133
|
+
}
|
|
134
|
+
_emitCompletions(event) {
|
|
135
|
+
event.source = 'actor';
|
|
136
|
+
this._hub.update(fields.completions(), event);
|
|
137
|
+
}
|
|
138
|
+
_error(error) {
|
|
139
|
+
// TODO
|
|
140
|
+
console.error(error);
|
|
141
|
+
}
|
|
142
|
+
_destroy() {
|
|
143
|
+
// abort ongoing data fetch if any
|
|
144
|
+
this._ac && this._ac.abort({
|
|
145
|
+
type: 'autocomplete-actor-destroy',
|
|
146
|
+
message: 'Autocomplete actor is destroyed.'
|
|
147
|
+
});
|
|
148
|
+
for (const unsubscribe of this._unsubscribes) {
|
|
149
|
+
unsubscribe();
|
|
150
|
+
}
|
|
151
|
+
this._unsubscribes = [];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.default = AutocompleteActor;
|
|
155
|
+
function sameInput(a, b) {
|
|
156
|
+
return !a && !b || a && b && a.value === b.value;
|
|
157
|
+
}
|
package/dist/cjs/actor/data.js
CHANGED
|
@@ -5,10 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var fields = _interopRequireWildcard(require("./fields.js"));
|
|
8
|
+
var _utils = require("./utils.js");
|
|
8
9
|
const _excluded = ["session"];
|
|
9
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
12
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
12
13
|
class DataActor {
|
|
13
14
|
constructor(hub, _ref) {
|
|
14
15
|
let {
|
|
@@ -80,7 +81,7 @@ class DataActor {
|
|
|
80
81
|
let value;
|
|
81
82
|
for await (value of response) {
|
|
82
83
|
// A new session invalidates ongoing data fetch for the old session, terminating the loop
|
|
83
|
-
if (!this.
|
|
84
|
+
if (!(0, _utils.isCurrentSession)(this._hub, session)) {
|
|
84
85
|
break;
|
|
85
86
|
}
|
|
86
87
|
this._emitResponse({
|
|
@@ -107,16 +108,7 @@ class DataActor {
|
|
|
107
108
|
}
|
|
108
109
|
_emitResponseWithSessionCheck(response) {
|
|
109
110
|
// A new session invalidates ongoing data fetch
|
|
110
|
-
this.
|
|
111
|
-
}
|
|
112
|
-
_isCurrentSession(session) {
|
|
113
|
-
if (!session) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
const {
|
|
117
|
-
session: currentSession
|
|
118
|
-
} = this._hub.states;
|
|
119
|
-
return currentSession && currentSession.index === session.index;
|
|
111
|
+
(0, _utils.isCurrentSession)(this._hub, response.session) && this._emitResponse(response);
|
|
120
112
|
}
|
|
121
113
|
_emitResponse(response) {
|
|
122
114
|
this._hub.update(fields.response(), response);
|
package/dist/cjs/actor/fields.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.completions = completions;
|
|
6
7
|
exports.data = data;
|
|
7
8
|
exports.event = event;
|
|
8
9
|
exports.feedback = feedback;
|
|
10
|
+
exports.input = input;
|
|
9
11
|
exports.interaction = interaction;
|
|
10
12
|
exports.query = query;
|
|
11
13
|
exports.request = request;
|
|
@@ -42,4 +44,10 @@ function interaction() {
|
|
|
42
44
|
}
|
|
43
45
|
function feedback() {
|
|
44
46
|
return 'feedback';
|
|
47
|
+
}
|
|
48
|
+
function input() {
|
|
49
|
+
return 'input';
|
|
50
|
+
}
|
|
51
|
+
function completions() {
|
|
52
|
+
return 'completions';
|
|
45
53
|
}
|
package/dist/cjs/actor/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "AutocompleteActor", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _autocomplete.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "DataActor", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -54,6 +60,7 @@ var _data = _interopRequireDefault(require("./data.js"));
|
|
|
54
60
|
var _views = _interopRequireDefault(require("./views.js"));
|
|
55
61
|
var _trackers = _interopRequireDefault(require("./trackers.js"));
|
|
56
62
|
var _feedback = _interopRequireDefault(require("./feedback.js"));
|
|
63
|
+
var _autocomplete = _interopRequireDefault(require("./autocomplete.js"));
|
|
57
64
|
var _interactions = _interopRequireDefault(require("./interactions.js"));
|
|
58
65
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
59
66
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -4,97 +4,62 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _commons = require("@miso.ai/commons");
|
|
7
8
|
var _constants = require("../constants.js");
|
|
8
9
|
var fields = _interopRequireWildcard(require("./fields.js"));
|
|
9
|
-
var
|
|
10
|
-
var
|
|
10
|
+
var _states = _interopRequireDefault(require("../util/states.js"));
|
|
11
|
+
var _trackers = require("../util/trackers.js");
|
|
11
12
|
var _utils = require("./utils.js");
|
|
12
13
|
const _excluded = ["active", "bindings"];
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
18
|
+
const {
|
|
19
|
+
IMPRESSION,
|
|
20
|
+
VIEWABLE,
|
|
21
|
+
CLICK
|
|
22
|
+
} = _constants.EVENT_TYPE;
|
|
20
23
|
class Tracker {
|
|
21
24
|
constructor(hub, view) {
|
|
22
25
|
let _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
23
|
-
let
|
|
24
|
-
active,
|
|
25
|
-
bindings
|
|
26
|
-
} = _ref,
|
|
27
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
26
|
+
let options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
28
27
|
this._hub = hub;
|
|
29
28
|
this._view = view;
|
|
30
|
-
this.
|
|
31
|
-
const role = this._role = view.role;
|
|
29
|
+
this._role = view.role;
|
|
32
30
|
// TODO: know item type
|
|
33
31
|
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
proxyElement: view.proxyElement,
|
|
39
|
-
sessionId: () => this._getSessionId(),
|
|
40
|
-
active: active || (() => this._isViewReady())
|
|
41
|
-
}, options));
|
|
42
|
-
this._unsubscribes = [this._tracker.on('*', data => this._handleEvent(data)), hub.on(fields.view(role), () => this.refresh())];
|
|
43
|
-
this.refresh();
|
|
32
|
+
this._states = undefined;
|
|
33
|
+
this.config(options);
|
|
34
|
+
this._unsubscribes = [..._constants.TRACKING_EVENT_TYPES.map(type => this._view.trackingEvents.on(type, values => this._trigger(type, values))), hub.on(fields.view(view.role), () => this._syncSession())];
|
|
35
|
+
this._syncSession();
|
|
44
36
|
}
|
|
45
37
|
config(options) {
|
|
46
|
-
this.
|
|
38
|
+
this._options = (0, _trackers.normalizeTrackerOptions)(options);
|
|
47
39
|
}
|
|
48
40
|
start() {
|
|
49
41
|
throw new Error(`workflow.tracker.start() is deprecated. Use workflow.startTracker() instead.`);
|
|
50
42
|
}
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
}
|
|
54
|
-
impression(productIds, options) {
|
|
55
|
-
this._assertViewReady();
|
|
56
|
-
this._tracker.impression(productIds.map(product_id => ({
|
|
57
|
-
product_id
|
|
58
|
-
})), options);
|
|
43
|
+
impression(items, options) {
|
|
44
|
+
this._trigger(IMPRESSION, items, true);
|
|
59
45
|
}
|
|
60
|
-
viewable(
|
|
61
|
-
this.
|
|
62
|
-
this._tracker.viewable(productIds.map(product_id => ({
|
|
63
|
-
product_id
|
|
64
|
-
})), options);
|
|
46
|
+
viewable(items, options) {
|
|
47
|
+
this._trigger(VIEWABLE, items, true);
|
|
65
48
|
}
|
|
66
|
-
click(
|
|
67
|
-
this.
|
|
68
|
-
this._tracker.click(productIds.map(product_id => ({
|
|
69
|
-
product_id
|
|
70
|
-
})), options);
|
|
71
|
-
}
|
|
72
|
-
_listBindingsFn() {
|
|
73
|
-
if (this._bindings && typeof this._bindings.list === 'function') {
|
|
74
|
-
return this._bindings.list;
|
|
75
|
-
}
|
|
76
|
-
const {
|
|
77
|
-
layout
|
|
78
|
-
} = this._view;
|
|
79
|
-
if (layout && layout.bindings && typeof layout.bindings.list === 'function') {
|
|
80
|
-
return layout.bindings.list;
|
|
81
|
-
}
|
|
82
|
-
// TODO: only if item is product typed
|
|
83
|
-
return (0, _bindings.fallbackListFunction)(_constants.ATTR_DATA_MISO_PRODUCT_ID);
|
|
84
|
-
}
|
|
85
|
-
_assertViewReady() {
|
|
86
|
-
if (!this._hub.active) {
|
|
87
|
-
throw new Error(`Workflow is not active. Call workflow.start() to activate it.`);
|
|
88
|
-
}
|
|
89
|
-
if (!isReady(this._getViewState())) {
|
|
90
|
-
throw new Error(`Workflow is not rendered yet. If you handle rendering by yourself, call workflow.notifyViewUpdate() when DOM is ready.`);
|
|
91
|
-
}
|
|
49
|
+
click(items, options) {
|
|
50
|
+
this._trigger(CLICK, items, true);
|
|
92
51
|
}
|
|
93
52
|
_getViewState() {
|
|
94
53
|
return this._hub.states[fields.view(this._role)];
|
|
95
54
|
}
|
|
96
|
-
|
|
97
|
-
|
|
55
|
+
_syncSession() {
|
|
56
|
+
const sessionId = this._getSessionId();
|
|
57
|
+
if (!sessionId) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!this._states || sessionId !== this._states.sessionId) {
|
|
61
|
+
this._states = new _states.default(sessionId);
|
|
62
|
+
}
|
|
98
63
|
}
|
|
99
64
|
_getSessionId() {
|
|
100
65
|
const {
|
|
@@ -112,26 +77,37 @@ class Tracker {
|
|
|
112
77
|
} = this._getViewState() || {};
|
|
113
78
|
return request && request.payload;
|
|
114
79
|
}
|
|
115
|
-
getState(
|
|
116
|
-
return this.
|
|
80
|
+
getState(item) {
|
|
81
|
+
return this._states.getFullState(item);
|
|
117
82
|
}
|
|
118
|
-
|
|
83
|
+
_trigger(type, items) {
|
|
84
|
+
let manual = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
85
|
+
(0, _constants.validateEventType)(type);
|
|
86
|
+
items = this._states.untriggered((0, _commons.asArray)(items), type);
|
|
87
|
+
if (items.length === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this._states.set(items, type, _constants.TRACKING_STATUS.TRIGGERED);
|
|
119
91
|
const property = this._role === 'results' ? 'products' : this._role; // TODO: ad-hoc, see #83
|
|
120
92
|
const misoId = this._getMisoId();
|
|
121
93
|
const request = this._getRequestPayload();
|
|
94
|
+
|
|
122
95
|
// TODO: should trigger 'tracker' and let workflow translate to interactions
|
|
123
96
|
this._hub.trigger(fields.interaction(), (0, _utils.toInteraction)({
|
|
124
97
|
property,
|
|
125
98
|
misoId,
|
|
126
99
|
request
|
|
127
|
-
},
|
|
100
|
+
}, {
|
|
101
|
+
event: type,
|
|
102
|
+
values: items,
|
|
103
|
+
manual
|
|
104
|
+
}));
|
|
128
105
|
}
|
|
129
106
|
_destroy() {
|
|
130
107
|
for (const unsubscribe of this._unsubscribes) {
|
|
131
108
|
unsubscribe();
|
|
132
109
|
}
|
|
133
110
|
this._unsubscribes = [];
|
|
134
|
-
this._tracker.destroy();
|
|
135
111
|
}
|
|
136
112
|
}
|
|
137
113
|
exports.default = Tracker;
|
|
@@ -20,7 +20,11 @@ class Trackers {
|
|
|
20
20
|
this._syncConfig();
|
|
21
21
|
}
|
|
22
22
|
_syncConfig() {
|
|
23
|
-
|
|
23
|
+
// TODO: trackers itself can be falsy
|
|
24
|
+
const {
|
|
25
|
+
trackers
|
|
26
|
+
} = this._options.resolved;
|
|
27
|
+
for (const [role, options] of Object.entries(trackers)) {
|
|
24
28
|
this._createOrConfigTracker(role, options);
|
|
25
29
|
}
|
|
26
30
|
}
|
package/dist/cjs/actor/utils.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.isCurrentSession = isCurrentSession;
|
|
6
7
|
exports.isProduct = isProduct;
|
|
7
8
|
exports.toInteraction = toInteraction;
|
|
8
9
|
var _commons = require("@miso.ai/commons");
|
|
@@ -33,8 +34,10 @@ function toInteraction(_ref, _ref2) {
|
|
|
33
34
|
// TODO: ad-hoc
|
|
34
35
|
const question_source = request && request._meta && request._meta.question_source;
|
|
35
36
|
const isProductType = isProduct(property);
|
|
36
|
-
const product_ids = isProductType ? values.map(v => v.product_id).filter(v => v) : [];
|
|
37
|
-
const items = isProductType ? undefined : values.map(v => v.text || v);
|
|
37
|
+
const product_ids = isProductType ? values.map(v => typeof v === 'string' ? v : v.product_id).filter(v => v) : [];
|
|
38
|
+
const items = isProductType ? undefined : values.map(v => v.text || v.id || v);
|
|
39
|
+
const channel = property === _constants.ROLE.AFFILIATION ? values[0] && values[0].channel : undefined;
|
|
40
|
+
const positions = property === _constants.ROLE.AFFILIATION ? values.map(v => v.position) : undefined;
|
|
38
41
|
const payload = (0, _commons.trimObj)({
|
|
39
42
|
type: event === 'viewable' ? 'viewable_impression' : event,
|
|
40
43
|
product_ids,
|
|
@@ -43,11 +46,22 @@ function toInteraction(_ref, _ref2) {
|
|
|
43
46
|
custom_context: (0, _commons.trimObj)({
|
|
44
47
|
api_ts,
|
|
45
48
|
property,
|
|
49
|
+
channel,
|
|
46
50
|
items,
|
|
51
|
+
positions,
|
|
47
52
|
trigger: manual ? 'manual' : 'auto',
|
|
48
53
|
question_source
|
|
49
54
|
})
|
|
50
55
|
}
|
|
51
56
|
});
|
|
52
57
|
return payload;
|
|
58
|
+
}
|
|
59
|
+
function isCurrentSession(hub, session) {
|
|
60
|
+
if (!session) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const {
|
|
64
|
+
session: currentSession
|
|
65
|
+
} = hub.states;
|
|
66
|
+
return currentSession && currentSession.index === session.index;
|
|
53
67
|
}
|
package/dist/cjs/actor/view.js
CHANGED
|
@@ -12,7 +12,7 @@ const _excluded = ["value", "error", "status", "meta"];
|
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
15
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
16
16
|
function statesEqual(a, b) {
|
|
17
17
|
return a === b || a && b && a.status === b.status && a.error === b.error && a.value === b.value &&
|
|
18
18
|
// skip deep equals
|
|
@@ -27,9 +27,14 @@ class ViewActor {
|
|
|
27
27
|
target: this
|
|
28
28
|
});
|
|
29
29
|
this._views = views;
|
|
30
|
+
const trackingEvents = {};
|
|
31
|
+
this._trackingEvents = new _commons.EventEmitter({
|
|
32
|
+
target: trackingEvents
|
|
33
|
+
});
|
|
30
34
|
(0, _commons.defineValues)(this, {
|
|
31
35
|
role,
|
|
32
|
-
interface: new View(this)
|
|
36
|
+
interface: new View(this),
|
|
37
|
+
trackingEvents
|
|
33
38
|
});
|
|
34
39
|
}
|
|
35
40
|
get hub() {
|
|
@@ -182,6 +187,12 @@ class ViewActor {
|
|
|
182
187
|
silent
|
|
183
188
|
});
|
|
184
189
|
}
|
|
190
|
+
get trackerOptions() {
|
|
191
|
+
return this._views._getTrackerOptions(this.role);
|
|
192
|
+
}
|
|
193
|
+
_track(type, items) {
|
|
194
|
+
this._trackingEvents.emit(type, items);
|
|
195
|
+
}
|
|
185
196
|
_sliceData(_ref2) {
|
|
186
197
|
let {
|
|
187
198
|
value,
|
|
@@ -258,6 +269,6 @@ class ViewActor {
|
|
|
258
269
|
exports.default = ViewActor;
|
|
259
270
|
class View {
|
|
260
271
|
constructor(actor) {
|
|
261
|
-
(0, _commons.delegateGetters)(this, actor, ['role', 'layout', 'element', 'proxyElement', 'refresh', 'on']);
|
|
272
|
+
(0, _commons.delegateGetters)(this, actor, ['role', 'layout', 'element', 'proxyElement', 'refresh', 'on', 'trackingEvents']);
|
|
262
273
|
}
|
|
263
274
|
}
|
package/dist/cjs/actor/views.js
CHANGED
|
@@ -8,6 +8,7 @@ var _commons = require("@miso.ai/commons");
|
|
|
8
8
|
var _constants = require("../constants.js");
|
|
9
9
|
var fields = _interopRequireWildcard(require("./fields.js"));
|
|
10
10
|
var _view = _interopRequireDefault(require("./view.js"));
|
|
11
|
+
var _trackers = require("../util/trackers.js");
|
|
11
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
14
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -35,7 +36,8 @@ class ViewsActor {
|
|
|
35
36
|
});
|
|
36
37
|
const syncSize = () => this.syncSize();
|
|
37
38
|
window.addEventListener('resize', syncSize);
|
|
38
|
-
this._unsubscribes = [() => window.removeEventListener('resize', syncSize), hub.on(fields.data(), () => this.refresh()), options.on('layouts', () => this._syncLayouts())];
|
|
39
|
+
this._unsubscribes = [() => window.removeEventListener('resize', syncSize), hub.on(fields.data(), () => this.refresh()), options.on('trackers', () => this._syncTrackers()), options.on('layouts', () => this._syncLayouts())];
|
|
40
|
+
this._syncTrackers();
|
|
39
41
|
this._syncLayouts();
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -190,6 +192,12 @@ class ViewsActor {
|
|
|
190
192
|
}
|
|
191
193
|
return this._data;
|
|
192
194
|
}
|
|
195
|
+
_syncTrackers() {
|
|
196
|
+
this._trackerOptions = this._options.resolved.trackers;
|
|
197
|
+
}
|
|
198
|
+
_getTrackerOptions(role) {
|
|
199
|
+
return (0, _trackers.normalizeTrackerOptions)(this._trackerOptions && this._trackerOptions[role] || false);
|
|
200
|
+
}
|
|
193
201
|
_error(e) {
|
|
194
202
|
// TODO: hub trigger error event
|
|
195
203
|
console.error(e);
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.processData = processData;
|
|
7
|
+
exports.processSovrnProduct = processSovrnProduct;
|
|
8
|
+
var _commons = require("@miso.ai/commons");
|
|
9
|
+
const _excluded = ["sovrn_aff"],
|
|
10
|
+
_excluded2 = ["products"],
|
|
11
|
+
_excluded3 = ["id", "deeplink", "headline", "description", "currency", "retailPrice", "salePrice", "discountRate", "image", "thumbnail", "merchant"];
|
|
12
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
13
|
+
function processData(data) {
|
|
14
|
+
if (!data || !data.value) {
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
const {
|
|
18
|
+
value
|
|
19
|
+
} = data;
|
|
20
|
+
return Object.assign({}, data, {
|
|
21
|
+
value: processValue(value)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function processValue(value) {
|
|
25
|
+
if (value.sovrn_aff) {
|
|
26
|
+
const {
|
|
27
|
+
sovrn_aff
|
|
28
|
+
} = value,
|
|
29
|
+
rest = _objectWithoutPropertiesLoose(value, _excluded);
|
|
30
|
+
value = Object.assign({}, rest, {
|
|
31
|
+
affiliation: processSovrnData(sovrn_aff)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return postProcessValue(value);
|
|
35
|
+
}
|
|
36
|
+
function postProcessValue(value) {
|
|
37
|
+
const {
|
|
38
|
+
affiliation
|
|
39
|
+
} = value;
|
|
40
|
+
if (!affiliation) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
let {
|
|
44
|
+
channel,
|
|
45
|
+
products
|
|
46
|
+
} = affiliation;
|
|
47
|
+
if (!products) {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
products = products.map(product => Object.assign({}, product));
|
|
51
|
+
let i = 0;
|
|
52
|
+
for (const product of products) {
|
|
53
|
+
if (channel) {
|
|
54
|
+
product.channel = channel;
|
|
55
|
+
}
|
|
56
|
+
product.position = i++;
|
|
57
|
+
}
|
|
58
|
+
return Object.assign({}, value, {
|
|
59
|
+
affiliation: Object.assign({}, affiliation, {
|
|
60
|
+
products
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function processSovrnData(_ref) {
|
|
65
|
+
let {
|
|
66
|
+
products
|
|
67
|
+
} = _ref,
|
|
68
|
+
sovrn_aff = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
69
|
+
return Object.assign({
|
|
70
|
+
channel: 'sovrn'
|
|
71
|
+
}, sovrn_aff, {
|
|
72
|
+
products: products.map(processSovrnProduct)
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function processSovrnProduct(_ref2) {
|
|
76
|
+
let {
|
|
77
|
+
id,
|
|
78
|
+
deeplink: url,
|
|
79
|
+
headline: title,
|
|
80
|
+
description,
|
|
81
|
+
currency,
|
|
82
|
+
retailPrice: original_price,
|
|
83
|
+
salePrice: sale_price,
|
|
84
|
+
discountRate: discount_rate_percent,
|
|
85
|
+
image: cover_image,
|
|
86
|
+
thumbnail,
|
|
87
|
+
merchant
|
|
88
|
+
} = _ref2,
|
|
89
|
+
product = _objectWithoutPropertiesLoose(_ref2, _excluded3);
|
|
90
|
+
const brand = merchant && merchant.name;
|
|
91
|
+
const brand_logo = merchant && merchant.logo;
|
|
92
|
+
return (0, _commons.trimObj)({
|
|
93
|
+
id: `sovrn-${id}`,
|
|
94
|
+
title,
|
|
95
|
+
description,
|
|
96
|
+
cover_image,
|
|
97
|
+
url,
|
|
98
|
+
currency,
|
|
99
|
+
original_price,
|
|
100
|
+
sale_price,
|
|
101
|
+
discount_rate_percent,
|
|
102
|
+
brand,
|
|
103
|
+
brand_logo,
|
|
104
|
+
custom_attributes: flatten(Object.assign({
|
|
105
|
+
sovrn_id: id,
|
|
106
|
+
thumbnail,
|
|
107
|
+
merchant
|
|
108
|
+
}, product))
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function flatten(obj) {
|
|
112
|
+
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
113
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
114
|
+
const value = obj[key];
|
|
115
|
+
if (value === undefined) {
|
|
116
|
+
return acc;
|
|
117
|
+
}
|
|
118
|
+
const prefixedKey = prefix ? `${prefix}_${key}` : key;
|
|
119
|
+
if (typeof value === 'object') {
|
|
120
|
+
return Object.assign({}, acc, flatten(value, prefixedKey));
|
|
121
|
+
}
|
|
122
|
+
return Object.assign({}, acc, {
|
|
123
|
+
[prefixedKey]: value
|
|
124
|
+
});
|
|
125
|
+
}, {});
|
|
126
|
+
}
|
|
@@ -8,7 +8,7 @@ exports.mergeOptions = mergeOptions;
|
|
|
8
8
|
var _commons = require("@miso.ai/commons");
|
|
9
9
|
var _index = require("../../defaults/ask/index.js");
|
|
10
10
|
const _excluded = ["api_key", "api_host", "templates", "phrases"];
|
|
11
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.
|
|
11
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
12
12
|
// TODO: generalize
|
|
13
13
|
|
|
14
14
|
const {
|