@miso.ai/client-sdk-ui 1.11.0-beta.1 → 1.11.0-beta.11
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/data.js +6 -7
- package/dist/cjs/actor/feedback.js +6 -39
- package/dist/cjs/actor/fields.js +14 -6
- package/dist/cjs/actor/hub.js +1 -2
- package/dist/cjs/actor/index.js +0 -7
- package/dist/cjs/actor/interactions.js +4 -15
- package/dist/cjs/actor/sessions.js +2 -33
- package/dist/cjs/actor/tracker.js +25 -26
- package/dist/cjs/actor/utils.js +0 -49
- package/dist/cjs/actor/view.js +40 -40
- package/dist/cjs/actor/views.js +32 -8
- package/dist/cjs/asset/svgs.js +18 -8
- package/dist/cjs/constants.js +18 -19
- package/dist/cjs/defaults/hybrid-search/answer-box.js +19 -3
- package/dist/cjs/defaults/hybrid-search/phrases.js +5 -5
- package/dist/cjs/defaults/hybrid-search/templates.js +37 -9
- package/dist/cjs/element/role/index.js +12 -5
- package/dist/cjs/element/role/{miso-hits.js → miso-more.js} +4 -4
- package/dist/cjs/element/role/miso-total.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +0 -3
- package/dist/cjs/layout/banner/banner.js +0 -4
- package/dist/cjs/layout/button/more-button.js +73 -0
- package/dist/cjs/layout/container/container.js +0 -3
- package/dist/cjs/layout/error/error.js +0 -4
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/facets.js +5 -5
- package/dist/cjs/layout/input/option-list.js +0 -4
- package/dist/cjs/layout/input/search-box.js +35 -17
- package/dist/cjs/layout/list/cards.js +0 -3
- package/dist/cjs/layout/list/carousel.js +0 -3
- package/dist/cjs/layout/list/collection.js +22 -7
- package/dist/cjs/layout/list/list.js +0 -3
- package/dist/cjs/layout/radio/feedback.js +0 -3
- package/dist/cjs/layout/radio/radio.js +0 -4
- package/dist/cjs/layout/raf.js +4 -2
- package/dist/cjs/layout/text/text.js +0 -4
- package/dist/cjs/layout/text/typewriter/index.js +0 -3
- package/dist/cjs/layout/triggerable.js +79 -0
- package/dist/cjs/util/states.js +0 -15
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +109 -111
- package/dist/cjs/workflow/ask.js +35 -27
- package/dist/cjs/workflow/asks.js +1 -1
- package/dist/cjs/workflow/autocompletable.js +33 -0
- package/dist/cjs/workflow/autocomplete.js +122 -0
- package/dist/cjs/workflow/base.js +169 -102
- package/dist/cjs/workflow/explore.js +26 -19
- package/dist/cjs/workflow/hybrid-search-answer.js +99 -0
- package/dist/cjs/workflow/hybrid-search-results.js +66 -0
- package/dist/cjs/workflow/hybrid-search-views.js +122 -0
- package/dist/cjs/workflow/hybrid-search.js +98 -103
- package/dist/cjs/workflow/options.js +32 -17
- package/dist/cjs/workflow/processors.js +191 -17
- package/dist/cjs/workflow/recommendation.js +36 -49
- package/dist/cjs/workflow/search-based.js +228 -0
- package/dist/cjs/workflow/search.js +21 -68
- package/package.json +2 -2
- package/src/actor/data.js +2 -4
- package/src/actor/feedback.js +6 -23
- package/src/actor/fields.js +14 -6
- package/src/actor/hub.js +1 -2
- package/src/actor/index.js +0 -1
- package/src/actor/interactions.js +4 -10
- package/src/actor/sessions.js +3 -30
- package/src/actor/tracker.js +25 -19
- package/src/actor/utils.js +0 -47
- package/src/actor/view.js +27 -15
- package/src/actor/views.js +36 -8
- package/src/asset/svgs.js +19 -7
- package/src/constants.js +25 -16
- package/src/defaults/hybrid-search/answer-box.js +17 -5
- package/src/defaults/hybrid-search/phrases.js +4 -4
- package/src/defaults/hybrid-search/templates.js +25 -9
- package/src/element/role/index.js +2 -1
- package/src/element/role/{miso-hits.js → miso-more.js} +3 -3
- package/src/element/role/miso-total.js +16 -0
- package/src/layout/affiliation/affiliation.js +1 -5
- package/src/layout/banner/banner.js +0 -5
- package/src/layout/button/more-button.js +69 -0
- package/src/layout/container/container.js +1 -5
- package/src/layout/error/error.js +0 -5
- package/src/layout/index.js +2 -1
- package/src/layout/input/facets.js +5 -6
- package/src/layout/input/option-list.js +0 -5
- package/src/layout/input/search-box.js +29 -19
- package/src/layout/list/cards.js +0 -4
- package/src/layout/list/carousel.js +0 -4
- package/src/layout/list/collection.js +21 -9
- package/src/layout/list/list.js +0 -4
- package/src/layout/radio/feedback.js +0 -4
- package/src/layout/radio/radio.js +0 -5
- package/src/layout/raf.js +2 -2
- package/src/layout/text/text.js +0 -5
- package/src/layout/text/typewriter/index.js +1 -5
- package/src/layout/trackable.js +1 -1
- package/src/layout/triggerable.js +76 -0
- package/src/util/states.js +0 -14
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +101 -77
- package/src/workflow/ask.js +33 -25
- package/src/workflow/asks.js +1 -1
- package/src/workflow/autocompletable.js +29 -0
- package/src/workflow/autocomplete.js +113 -0
- package/src/workflow/base.js +147 -93
- package/src/workflow/explore.js +23 -8
- package/src/workflow/hybrid-search-answer.js +92 -0
- package/src/workflow/hybrid-search-results.js +62 -0
- package/src/workflow/hybrid-search-views.js +124 -0
- package/src/workflow/hybrid-search.js +102 -73
- package/src/workflow/options.js +26 -11
- package/src/workflow/processors.js +169 -14
- package/src/workflow/recommendation.js +32 -33
- package/src/workflow/search-based.js +222 -0
- package/src/workflow/search.js +21 -65
- package/dist/cjs/actor/autocomplete.js +0 -160
- package/dist/cjs/workflow/utils.js +0 -42
- package/src/actor/autocomplete.js +0 -133
- package/src/workflow/utils.js +0 -29
|
@@ -10,12 +10,14 @@ exports.mergeAutocompleteOptions = mergeAutocompleteOptions;
|
|
|
10
10
|
exports.mergeDataProcessorOptions = mergeDataProcessorOptions;
|
|
11
11
|
exports.mergeInteractionsOptions = mergeInteractionsOptions;
|
|
12
12
|
exports.mergeLayoutsOptions = mergeLayoutsOptions;
|
|
13
|
+
exports.mergePaginationOptions = mergePaginationOptions;
|
|
14
|
+
exports.mergeRolesOptions = mergeRolesOptions;
|
|
13
15
|
exports.mergeTrackersOptions = mergeTrackersOptions;
|
|
14
16
|
exports.normalizeApiOptions = normalizeApiOptions;
|
|
15
|
-
exports.normalizeAutocompleteOptions = normalizeAutocompleteOptions;
|
|
16
17
|
exports.normalizeDataProcessorOptions = normalizeDataProcessorOptions;
|
|
17
18
|
exports.normalizeInteractionsOptions = normalizeInteractionsOptions;
|
|
18
19
|
exports.normalizeLayoutsOptions = normalizeLayoutsOptions;
|
|
20
|
+
exports.normalizePaginationOptions = normalizePaginationOptions;
|
|
19
21
|
exports.normalizeTrackers = normalizeTrackers;
|
|
20
22
|
var _commons = require("@miso.ai/commons");
|
|
21
23
|
var _constants = require("../constants.js");
|
|
@@ -139,19 +141,16 @@ function normalizeInteractionsOptions(options) {
|
|
|
139
141
|
preprocess
|
|
140
142
|
});
|
|
141
143
|
}
|
|
142
|
-
function
|
|
144
|
+
function normalizePaginationOptions(options) {
|
|
143
145
|
if (options === undefined) {
|
|
144
|
-
throw new Error(`Expect
|
|
146
|
+
throw new Error(`Expect pagination options to be an object or a boolean value: ${options}`);
|
|
145
147
|
}
|
|
146
148
|
if (typeof options === 'boolean') {
|
|
147
149
|
options = {
|
|
148
|
-
|
|
150
|
+
active: options
|
|
149
151
|
};
|
|
150
152
|
}
|
|
151
|
-
|
|
152
|
-
return Object.assign({}, options, {
|
|
153
|
-
processData
|
|
154
|
-
});
|
|
153
|
+
return options;
|
|
155
154
|
}
|
|
156
155
|
|
|
157
156
|
// merge //
|
|
@@ -239,18 +238,34 @@ function mergeInteractionsOptions() {
|
|
|
239
238
|
preprocess: concatArrays(merged.preprocess, options.preprocess)
|
|
240
239
|
})));
|
|
241
240
|
}
|
|
242
|
-
function
|
|
241
|
+
function mergePaginationOptions() {
|
|
243
242
|
for (var _len6 = arguments.length, optionsList = new Array(_len6), _key7 = 0; _key7 < _len6; _key7++) {
|
|
244
243
|
optionsList[_key7] = arguments[_key7];
|
|
245
244
|
}
|
|
246
245
|
if (optionsList[optionsList.length - 1] === false) {
|
|
247
246
|
return false;
|
|
248
247
|
}
|
|
248
|
+
return mergeOptions(optionsList, (merged, options) => Object.assign(merged, options));
|
|
249
|
+
}
|
|
250
|
+
function mergeAutocompleteOptions() {
|
|
251
|
+
for (var _len7 = arguments.length, optionsList = new Array(_len7), _key8 = 0; _key8 < _len7; _key8++) {
|
|
252
|
+
optionsList[_key8] = arguments[_key8];
|
|
253
|
+
}
|
|
249
254
|
return mergeOptions(optionsList, (merged, options) => Object.assign(merged, Object.assign({}, options, {
|
|
250
|
-
api: mergeApiOptions(merged.api, options.api)
|
|
251
|
-
processData: mergeDataProcessorOptions(merged.processData, options.processData)
|
|
255
|
+
api: mergeApiOptions(merged.api, options.api)
|
|
252
256
|
})));
|
|
253
257
|
}
|
|
258
|
+
function mergeRolesOptions(base, overrides) {
|
|
259
|
+
return Object.freeze(Object.assign({}, base, overrides, {
|
|
260
|
+
members: mergeRolesMembers(base.members, overrides.members),
|
|
261
|
+
mappings: Object.freeze(Object.assign({}, base.mappings, overrides.mappings))
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
264
|
+
function mergeRolesMembers() {
|
|
265
|
+
let base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
266
|
+
let overrides = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
267
|
+
return [...new Set([...base, ...overrides])];
|
|
268
|
+
}
|
|
254
269
|
|
|
255
270
|
// manifest //
|
|
256
271
|
const FEATURES = [{
|
|
@@ -274,9 +289,9 @@ const FEATURES = [{
|
|
|
274
289
|
normalize: normalizeInteractionsOptions,
|
|
275
290
|
merge: mergeInteractionsOptions
|
|
276
291
|
}, {
|
|
277
|
-
key: '
|
|
278
|
-
normalize:
|
|
279
|
-
merge:
|
|
292
|
+
key: 'pagination',
|
|
293
|
+
normalize: normalizePaginationOptions,
|
|
294
|
+
merge: mergePaginationOptions
|
|
280
295
|
}];
|
|
281
296
|
class WorkflowContextOptions {
|
|
282
297
|
constructor() {
|
|
@@ -300,7 +315,7 @@ class WorkflowOptions {
|
|
|
300
315
|
this._events = new _commons.EventEmitter({
|
|
301
316
|
target: this
|
|
302
317
|
});
|
|
303
|
-
this._defaults = defaults;
|
|
318
|
+
this._defaults = defaults; // TODO: we should call normalize() on defaults
|
|
304
319
|
this._context = context || {};
|
|
305
320
|
this._locals = {};
|
|
306
321
|
(0, _commons.defineValues)(this, {
|
|
@@ -388,8 +403,8 @@ function injectConfigurableFeature(prototype, feature) {
|
|
|
388
403
|
if (feature === 'api') {
|
|
389
404
|
Object.assign(prototype, {
|
|
390
405
|
useApi() {
|
|
391
|
-
for (var
|
|
392
|
-
args[
|
|
406
|
+
for (var _len8 = arguments.length, args = new Array(_len8), _key9 = 0; _key9 < _len8; _key9++) {
|
|
407
|
+
args[_key9] = arguments[_key9];
|
|
393
408
|
}
|
|
394
409
|
this._options.api.merge(args);
|
|
395
410
|
return this;
|
|
@@ -3,23 +3,31 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.buildBaseInteraction = buildBaseInteraction;
|
|
7
|
+
exports.concatItemsFromMoreResponse = concatItemsFromMoreResponse;
|
|
8
|
+
exports.getRevision = getRevision;
|
|
9
|
+
exports.mergeInteraction = mergeInteraction;
|
|
10
|
+
exports.retainFacetCountsInData = retainFacetCountsInData;
|
|
11
|
+
exports.writeAffiliationInfoToInteraction = writeAffiliationInfoToInteraction;
|
|
8
12
|
exports.writeAnswerStageToMeta = writeAnswerStageToMeta;
|
|
9
13
|
exports.writeDataStatus = writeDataStatus;
|
|
14
|
+
exports.writeExhaustionToData = writeExhaustionToData;
|
|
15
|
+
exports.writeFiltersToPayload = writeFiltersToPayload;
|
|
10
16
|
exports.writeKeywordsToData = writeKeywordsToData;
|
|
11
17
|
exports.writeMisoIdToMeta = writeMisoIdToMeta;
|
|
12
18
|
var _commons = require("@miso.ai/commons");
|
|
13
19
|
var _constants = require("../constants.js");
|
|
14
|
-
|
|
15
|
-
function
|
|
20
|
+
// data //
|
|
21
|
+
function getRevision(data) {
|
|
22
|
+
return data && data.value && data.value.revision;
|
|
23
|
+
}
|
|
16
24
|
function writeDataStatus(data) {
|
|
17
25
|
const status = getStatus(data);
|
|
18
|
-
const ongoing = status === _constants.STATUS.READY ?
|
|
19
|
-
return (0, _commons.trimObj)(Object.assign({
|
|
26
|
+
const ongoing = status === _constants.STATUS.READY ? data.ongoing : undefined;
|
|
27
|
+
return (0, _commons.trimObj)(Object.assign({
|
|
20
28
|
status,
|
|
21
29
|
ongoing
|
|
22
|
-
}));
|
|
30
|
+
}, data)); // let orinigal data override status and ongoing
|
|
23
31
|
}
|
|
24
32
|
function getStatus(data) {
|
|
25
33
|
if (!data) {
|
|
@@ -56,7 +64,8 @@ function writeKeywordsToData(data) {
|
|
|
56
64
|
request,
|
|
57
65
|
value
|
|
58
66
|
} = data;
|
|
59
|
-
|
|
67
|
+
// we still want the value in loading status
|
|
68
|
+
if (!request) {
|
|
60
69
|
return data;
|
|
61
70
|
}
|
|
62
71
|
const {
|
|
@@ -96,18 +105,183 @@ function writeAnswerStageToMeta(data) {
|
|
|
96
105
|
})
|
|
97
106
|
});
|
|
98
107
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
108
|
+
function writeFiltersToPayload() {
|
|
109
|
+
let payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
110
|
+
let filters = arguments.length > 1 ? arguments[1] : undefined;
|
|
111
|
+
return (0, _commons.trimObj)(Object.assign({}, payload, composeFiltersPayload(filters)));
|
|
112
|
+
}
|
|
113
|
+
function composeFiltersPayload(filters) {
|
|
114
|
+
if (!filters) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const {
|
|
118
|
+
facets
|
|
119
|
+
} = filters;
|
|
120
|
+
return (0, _commons.trimObj)({
|
|
121
|
+
facet_filters: composeFacetFilters(facets)
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function composeFacetFilters(facets) {
|
|
125
|
+
if (!facets) {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
const filters = {};
|
|
129
|
+
for (const field in facets) {
|
|
130
|
+
const values = facets[field];
|
|
131
|
+
if (!values || !values.length) {
|
|
132
|
+
continue; // just in case
|
|
133
|
+
}
|
|
134
|
+
filters[field] = {
|
|
135
|
+
terms: values
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return Object.keys(filters).length ? filters : undefined;
|
|
139
|
+
}
|
|
140
|
+
function retainFacetCountsInData(data, currentFacetCounts) {
|
|
141
|
+
if (!currentFacetCounts) {
|
|
142
|
+
return data;
|
|
143
|
+
}
|
|
144
|
+
const {
|
|
145
|
+
status,
|
|
146
|
+
value
|
|
147
|
+
} = data;
|
|
148
|
+
switch (status) {
|
|
149
|
+
case _constants.STATUS.INITIAL:
|
|
150
|
+
case _constants.STATUS.LOADING:
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
return data;
|
|
154
|
+
}
|
|
155
|
+
if (value && value.facet_counts) {
|
|
101
156
|
return data;
|
|
102
157
|
}
|
|
103
|
-
return Object.assign({
|
|
104
|
-
|
|
105
|
-
|
|
158
|
+
return Object.assign({}, data, {
|
|
159
|
+
value: Object.assign({}, value, {
|
|
160
|
+
facet_counts: currentFacetCounts
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function concatItemsFromMoreResponse(oldData, newData) {
|
|
165
|
+
let {
|
|
166
|
+
role = _constants.ROLE.PRODUCTS
|
|
167
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
168
|
+
if (!newData.value) {
|
|
169
|
+
return oldData;
|
|
170
|
+
}
|
|
171
|
+
const {
|
|
172
|
+
[role]: oldProducts = [],
|
|
173
|
+
facet_counts,
|
|
174
|
+
total
|
|
175
|
+
} = oldData.value;
|
|
176
|
+
const {
|
|
177
|
+
[role]: newProducts = []
|
|
178
|
+
} = newData.value;
|
|
179
|
+
// keep old exhaustion flag, just in case
|
|
180
|
+
// TODO
|
|
181
|
+
|
|
182
|
+
// use old values of facet_counts and total, for they are affected by product_id exclusion
|
|
183
|
+
return Object.assign({}, newData, {
|
|
184
|
+
facet_counts,
|
|
185
|
+
total,
|
|
186
|
+
value: Object.assign({}, newData.value, {
|
|
187
|
+
[role]: [...oldProducts, ...newProducts]
|
|
188
|
+
})
|
|
189
|
+
});
|
|
106
190
|
}
|
|
107
|
-
function
|
|
108
|
-
|
|
191
|
+
function writeExhaustionToData(data) {
|
|
192
|
+
let {
|
|
193
|
+
role = _constants.ROLE.PRODUCTS
|
|
194
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
195
|
+
const {
|
|
196
|
+
status,
|
|
197
|
+
request,
|
|
198
|
+
value
|
|
199
|
+
} = data;
|
|
200
|
+
// keep track of the exhaustion state
|
|
201
|
+
if (status !== _constants.STATUS.READY || !request || !value) {
|
|
202
|
+
return data;
|
|
203
|
+
}
|
|
204
|
+
const {
|
|
205
|
+
[role]: items
|
|
206
|
+
} = value;
|
|
207
|
+
if (!items) {
|
|
109
208
|
return data;
|
|
110
209
|
}
|
|
111
|
-
const
|
|
112
|
-
|
|
210
|
+
const {
|
|
211
|
+
rows
|
|
212
|
+
} = request.payload;
|
|
213
|
+
const {
|
|
214
|
+
length
|
|
215
|
+
} = items;
|
|
216
|
+
const exhausted = length < rows;
|
|
217
|
+
if (!exhausted) {
|
|
218
|
+
return data;
|
|
219
|
+
}
|
|
220
|
+
return Object.assign({}, data, {
|
|
221
|
+
meta: Object.assign({}, data.meta, {
|
|
222
|
+
exhausted: true
|
|
223
|
+
})
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// interactions //
|
|
228
|
+
function buildBaseInteraction(args) {
|
|
229
|
+
const {
|
|
230
|
+
role,
|
|
231
|
+
type,
|
|
232
|
+
items
|
|
233
|
+
} = args;
|
|
234
|
+
const payload = {
|
|
235
|
+
type: type === 'viewable' ? 'viewable_impression' : type,
|
|
236
|
+
context: {
|
|
237
|
+
custom_context: (0, _commons.trimObj)({
|
|
238
|
+
property: role
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
if ((0, _constants.isPerformanceEventType)(type)) {
|
|
243
|
+
if ((0, _constants.isProductRole)(role)) {
|
|
244
|
+
payload.product_ids = (items || []).map(v => typeof v === 'string' ? v : v.product_id).filter(v => v);
|
|
245
|
+
} else {
|
|
246
|
+
payload.product_ids = [];
|
|
247
|
+
payload.context.custom_context.items = (items || []).map(v => v.text || v.id || v);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
switch (type) {
|
|
251
|
+
case _constants.EVENT_TYPE.SUBMIT:
|
|
252
|
+
payload.context.custom_context.value = args.value;
|
|
253
|
+
break;
|
|
254
|
+
case _constants.EVENT_TYPE.FEEDBACK:
|
|
255
|
+
payload.context.custom_context.value = payload.value = args.value;
|
|
256
|
+
payload.context.custom_context.result_type = payload.result_type = args.result_type;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
return (0, _commons.trimObj)(payload);
|
|
260
|
+
}
|
|
261
|
+
function writeAffiliationInfoToInteraction(payload, args) {
|
|
262
|
+
if (args.role !== _constants.ROLE.AFFILIATION) {
|
|
263
|
+
return payload;
|
|
264
|
+
}
|
|
265
|
+
const {
|
|
266
|
+
items
|
|
267
|
+
} = args;
|
|
268
|
+
const channel = items[0] && items[0].channel || undefined;
|
|
269
|
+
const positions = items.map(v => v.position);
|
|
270
|
+
return mergeInteraction(payload, {
|
|
271
|
+
context: {
|
|
272
|
+
custom_context: {
|
|
273
|
+
channel,
|
|
274
|
+
positions
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
function mergeInteraction() {
|
|
280
|
+
let base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
281
|
+
let patch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
282
|
+
return (0, _commons.trimObj)(Object.assign({}, base, patch, {
|
|
283
|
+
context: (0, _commons.trimObj)(Object.assign({}, base.context, patch.context, {
|
|
284
|
+
custom_context: (0, _commons.trimObj)(Object.assign({}, base.context && base.context.custom_context, patch.context && patch.context.custom_context))
|
|
285
|
+
}))
|
|
286
|
+
}));
|
|
113
287
|
}
|
|
@@ -6,35 +6,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
8
|
var _base = _interopRequireDefault(require("./base.js"));
|
|
9
|
-
var
|
|
10
|
-
var _index = require("../actor/index.js");
|
|
11
|
-
var _index2 = require("../layout/index.js");
|
|
9
|
+
var _index = require("../layout/index.js");
|
|
12
10
|
var _constants = require("../constants.js");
|
|
11
|
+
var _options = require("./options.js");
|
|
12
|
+
var _processors = require("./processors.js");
|
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
const DEFAULT_API_OPTIONS = Object.freeze({
|
|
14
|
+
const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_API_OPTIONS, {
|
|
15
15
|
group: _commons.API.GROUP.RECOMMENDATION,
|
|
16
16
|
name: _commons.API.NAME.USER_TO_PRODUCTS,
|
|
17
|
-
payload: {
|
|
17
|
+
payload: Object.assign({}, _base.default.DEFAULT_API_OPTIONS.payload, {
|
|
18
18
|
fl: ['*']
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
const DEFAULT_LAYOUTS = Object.freeze({
|
|
22
|
-
[_constants.ROLE.PRODUCTS]:
|
|
23
|
-
});
|
|
24
|
-
const DEFAULT_TRACKERS = Object.freeze({
|
|
19
|
+
})
|
|
20
|
+
}));
|
|
21
|
+
const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
|
|
22
|
+
[_constants.ROLE.PRODUCTS]: _index.ListLayout.type
|
|
23
|
+
}));
|
|
24
|
+
const DEFAULT_TRACKERS = Object.freeze(Object.assign({}, _base.default.DEFAULT_TRACKERS, {
|
|
25
25
|
[_constants.ROLE.PRODUCTS]: {}
|
|
26
|
-
});
|
|
27
|
-
const DEFAULT_OPTIONS = Object.freeze({
|
|
26
|
+
}));
|
|
27
|
+
const DEFAULT_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAULT_OPTIONS, {
|
|
28
28
|
api: DEFAULT_API_OPTIONS,
|
|
29
29
|
layouts: DEFAULT_LAYOUTS,
|
|
30
30
|
trackers: DEFAULT_TRACKERS
|
|
31
|
+
}));
|
|
32
|
+
const ROLES_OPTIONS = (0, _options.mergeRolesOptions)(_base.default.ROLES_OPTIONS, {
|
|
33
|
+
main: _constants.ROLE.PRODUCTS,
|
|
34
|
+
members: Object.keys(DEFAULT_LAYOUTS)
|
|
31
35
|
});
|
|
32
36
|
class Recommendation extends _base.default {
|
|
33
37
|
constructor(context, id) {
|
|
34
38
|
super({
|
|
35
39
|
name: 'recommendation',
|
|
36
40
|
context,
|
|
37
|
-
roles:
|
|
41
|
+
roles: ROLES_OPTIONS,
|
|
38
42
|
defaults: DEFAULT_OPTIONS,
|
|
39
43
|
id
|
|
40
44
|
});
|
|
@@ -48,32 +52,15 @@ class Recommendation extends _base.default {
|
|
|
48
52
|
id
|
|
49
53
|
});
|
|
50
54
|
}
|
|
51
|
-
|
|
55
|
+
_initSession(args) {
|
|
52
56
|
this._context._members.set(args.id, this);
|
|
53
|
-
super.
|
|
57
|
+
super._initSession(args);
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
// lifecycle //
|
|
57
61
|
start() {
|
|
58
|
-
this._sessions.start();
|
|
59
62
|
// in recommendation workflow, start() triggers query
|
|
60
|
-
|
|
61
|
-
const {
|
|
62
|
-
session
|
|
63
|
-
} = this;
|
|
64
|
-
this._hub.update(_index.fields.request(), (0, _options.mergeApiOptions)(this._options.resolved.api, {
|
|
65
|
-
session
|
|
66
|
-
}));
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// TODO: deprecate this
|
|
71
|
-
startTracker() {
|
|
72
|
-
this.useApi(false);
|
|
73
|
-
this.useLayouts(false);
|
|
74
|
-
this._sessions.start();
|
|
75
|
-
this.notifyViewUpdate(_constants.ROLE.CONTAINER);
|
|
76
|
-
this.notifyViewUpdate(_constants.ROLE.PRODUCTS);
|
|
63
|
+
this._request();
|
|
77
64
|
return this;
|
|
78
65
|
}
|
|
79
66
|
notifyViewUpdate() {
|
|
@@ -86,21 +73,21 @@ class Recommendation extends _base.default {
|
|
|
86
73
|
}
|
|
87
74
|
|
|
88
75
|
// interactions //
|
|
89
|
-
|
|
90
|
-
payload = super.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return
|
|
98
|
-
context:
|
|
99
|
-
custom_context:
|
|
100
|
-
unit_id
|
|
101
|
-
unit_instance_uuid
|
|
102
|
-
}
|
|
103
|
-
}
|
|
76
|
+
_defaultProcessInteraction(payload, args) {
|
|
77
|
+
payload = super._defaultProcessInteraction(payload, args);
|
|
78
|
+
payload = this._writeUnitIdToInteraction(payload, args);
|
|
79
|
+
return payload;
|
|
80
|
+
}
|
|
81
|
+
_writeUnitIdToInteraction(payload) {
|
|
82
|
+
const unit_id = this.id;
|
|
83
|
+
const unit_instance_uuid = this.uuid;
|
|
84
|
+
return (0, _processors.mergeInteraction)(payload, {
|
|
85
|
+
context: {
|
|
86
|
+
custom_context: {
|
|
87
|
+
unit_id,
|
|
88
|
+
unit_instance_uuid
|
|
89
|
+
}
|
|
90
|
+
}
|
|
104
91
|
});
|
|
105
92
|
}
|
|
106
93
|
|