@miso.ai/client-sdk-ui 1.11.4-beta.1 → 1.11.4-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/actor/filters.js +57 -11
- package/dist/cjs/actor/tracker.js +1 -6
- package/dist/cjs/actor/view.js +6 -8
- package/dist/cjs/actor/views.js +10 -26
- package/dist/cjs/constants.js +12 -2
- package/dist/cjs/element/role/index.js +7 -0
- package/dist/cjs/element/role/miso-sort.js +20 -0
- package/dist/cjs/layout/affiliation/affiliation.js +1 -1
- package/dist/cjs/layout/container/container.js +2 -2
- package/dist/cjs/layout/index.js +7 -0
- package/dist/cjs/layout/input/facets.js +2 -2
- package/dist/cjs/layout/input/search-box.js +1 -1
- package/dist/cjs/layout/input/select.js +150 -0
- package/dist/cjs/layout/raf.js +2 -4
- package/dist/cjs/layout/trackable.js +3 -3
- package/dist/cjs/layout/triggerable.js +1 -1
- package/dist/cjs/util/trackers.js +2 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/workflow/answer-based.js +2 -2
- package/dist/cjs/workflow/ask.js +4 -1
- package/dist/cjs/workflow/base.js +4 -4
- package/dist/cjs/workflow/context.js +3 -3
- package/dist/cjs/workflow/explore.js +2 -2
- package/dist/cjs/workflow/hybrid-search-answer.js +9 -7
- package/dist/cjs/workflow/hybrid-search-results.js +18 -16
- package/dist/cjs/workflow/hybrid-search-views.js +5 -12
- package/dist/cjs/workflow/hybrid-search.js +2 -2
- package/dist/cjs/workflow/options/api.js +56 -0
- package/dist/cjs/workflow/options/configurable.js +49 -0
- package/dist/cjs/workflow/options/data-processor.js +23 -0
- package/dist/cjs/workflow/options/filters.js +18 -0
- package/dist/cjs/workflow/options/index.js +115 -0
- package/dist/cjs/workflow/options/interactions.js +44 -0
- package/dist/cjs/workflow/options/layouts.js +83 -0
- package/dist/cjs/workflow/options/options.js +154 -0
- package/dist/cjs/workflow/options/pagination.js +28 -0
- package/dist/cjs/workflow/options/roles.js +17 -0
- package/dist/cjs/workflow/options/trackers.js +39 -0
- package/dist/cjs/workflow/options/utils.js +33 -0
- package/dist/cjs/workflow/processors.js +39 -33
- package/dist/cjs/workflow/recommendation.js +2 -2
- package/dist/cjs/workflow/search-based.js +59 -22
- package/package.json +2 -2
- package/src/actor/filters.js +53 -12
- package/src/actor/tracker.js +1 -6
- package/src/actor/view.js +7 -8
- package/src/actor/views.js +9 -30
- package/src/constants.js +11 -0
- package/src/element/role/index.js +1 -0
- package/src/element/role/miso-sort.js +16 -0
- package/src/layout/affiliation/affiliation.js +1 -1
- package/src/layout/container/container.js +2 -2
- package/src/layout/index.js +1 -0
- package/src/layout/input/facets.js +3 -2
- package/src/layout/input/search-box.js +1 -1
- package/src/layout/input/select.js +142 -0
- package/src/layout/raf.js +2 -2
- package/src/layout/trackable.js +3 -3
- package/src/layout/triggerable.js +1 -1
- package/src/util/trackers.js +2 -0
- package/src/version.js +1 -1
- package/src/workflow/answer-based.js +1 -1
- package/src/workflow/ask.js +4 -1
- package/src/workflow/base.js +1 -1
- package/src/workflow/context.js +1 -1
- package/src/workflow/explore.js +1 -1
- package/src/workflow/hybrid-search-answer.js +8 -3
- package/src/workflow/hybrid-search-results.js +21 -7
- package/src/workflow/hybrid-search-views.js +4 -12
- package/src/workflow/hybrid-search.js +3 -3
- package/src/workflow/options/api.js +46 -0
- package/src/workflow/options/configurable.js +48 -0
- package/src/workflow/options/data-processor.js +15 -0
- package/src/workflow/options/filters.js +10 -0
- package/src/workflow/options/index.js +10 -0
- package/src/workflow/options/interactions.js +36 -0
- package/src/workflow/options/layouts.js +73 -0
- package/src/workflow/options/options.js +169 -0
- package/src/workflow/options/pagination.js +18 -0
- package/src/workflow/options/roles.js +12 -0
- package/src/workflow/options/trackers.js +32 -0
- package/src/workflow/options/utils.js +26 -0
- package/src/workflow/processors.js +30 -34
- package/src/workflow/recommendation.js +1 -1
- package/src/workflow/search-based.js +58 -13
- package/dist/cjs/workflow/options.js +0 -448
- package/src/workflow/options.js +0 -433
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { trimObj } from '@miso.ai/commons';
|
|
2
|
+
import { mergeOptions } from './utils.js';
|
|
3
|
+
|
|
4
|
+
export function normalizeApiOptions([name, payload] = []) {
|
|
5
|
+
// TODO: take object form as well
|
|
6
|
+
if (name === false) {
|
|
7
|
+
return { actor: false };
|
|
8
|
+
}
|
|
9
|
+
if (typeof name === 'object' && payload === undefined) {
|
|
10
|
+
payload = name;
|
|
11
|
+
name = undefined;
|
|
12
|
+
}
|
|
13
|
+
let group = undefined;
|
|
14
|
+
if (name && name.indexOf('/') !== -1) {
|
|
15
|
+
[group, name] = name.split('/');
|
|
16
|
+
}
|
|
17
|
+
if ((name && typeof name !== 'string') || (payload !== undefined && typeof payload !== 'object')) {
|
|
18
|
+
throw new Error(`Invalid arguments for useApi(): ${name}, ${payload}`);
|
|
19
|
+
}
|
|
20
|
+
return trimObj({ group, name, payload });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function mergeApiOptions(...optionsList) {
|
|
24
|
+
if (optionsList[optionsList.length - 1] === false) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return mergeOptions(optionsList, (merged, options) => Object.assign(merged, {
|
|
28
|
+
...options,
|
|
29
|
+
payload: mergeApiPayloads(merged.payload, options.payload),
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function mergeApiPayloads(base, overrides) {
|
|
34
|
+
return {
|
|
35
|
+
...base,
|
|
36
|
+
...overrides,
|
|
37
|
+
...mergeObjectValueIfPresent('_meta', base, overrides),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function mergeObjectValueIfPresent(key, base, overrides) {
|
|
42
|
+
const baseValue = base && base[key];
|
|
43
|
+
const overridesValue = overrides && overrides[key];
|
|
44
|
+
const value = baseValue ? (overridesValue ? { ...baseValue, ...overridesValue } : baseValue) : overridesValue;
|
|
45
|
+
return value !== undefined ? { [key]: value } : {};
|
|
46
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { WORKFLOW_CONFIGURABLE } from '../../constants.js';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_FEATURES = [
|
|
4
|
+
WORKFLOW_CONFIGURABLE.API,
|
|
5
|
+
WORKFLOW_CONFIGURABLE.LAYOUTS,
|
|
6
|
+
WORKFLOW_CONFIGURABLE.DATA_PROCESSOR,
|
|
7
|
+
WORKFLOW_CONFIGURABLE.TRACKERS,
|
|
8
|
+
WORKFLOW_CONFIGURABLE.INTERACTIONS,
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
export function makeConfigurable(prototype, features = DEFAULT_FEATURES) {
|
|
12
|
+
for (const feature of features) {
|
|
13
|
+
injectConfigurableFeature(prototype, feature);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function injectConfigurableFeature(prototype, feature) {
|
|
18
|
+
if (feature === 'api') {
|
|
19
|
+
Object.assign(prototype, {
|
|
20
|
+
useApi(...args) {
|
|
21
|
+
this._options.api.merge(args);
|
|
22
|
+
return this;
|
|
23
|
+
},
|
|
24
|
+
clearApi() {
|
|
25
|
+
this._options.api.set();
|
|
26
|
+
return this;
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
const upperCased = upperCase(feature);
|
|
31
|
+
Object.assign(prototype, {
|
|
32
|
+
[`use${upperCased}`](value) {
|
|
33
|
+
(this._options[feature]).merge(value);
|
|
34
|
+
return this;
|
|
35
|
+
},
|
|
36
|
+
[`clear${upperCased}`]() {
|
|
37
|
+
(this._options[feature]).set();
|
|
38
|
+
return this;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// helpers //
|
|
45
|
+
// TODO: move to commons
|
|
46
|
+
function upperCase(str) {
|
|
47
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
48
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { asArray } from '@miso.ai/commons';
|
|
2
|
+
|
|
3
|
+
export function normalizeDataProcessorOptions(fns) {
|
|
4
|
+
fns = asArray(fns);
|
|
5
|
+
for (const fn of fns) {
|
|
6
|
+
if (typeof fn !== 'function') {
|
|
7
|
+
throw new Error(`Expect data processor options to be a function: ${fn}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return fns;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function mergeDataProcessorOptions(...optionsList) {
|
|
14
|
+
return optionsList.flat().filter(Boolean);
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { mergeOptions, normalizeOptions } from './utils.js';
|
|
2
|
+
|
|
3
|
+
export const normalizeFiltersOptions = normalizeOptions;
|
|
4
|
+
|
|
5
|
+
export function mergeFiltersOptions(...optionsList) {
|
|
6
|
+
if (optionsList[optionsList.length - 1] === false) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
return mergeOptions(optionsList, (merged, options) => Object.assign(merged, options));
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './roles.js';
|
|
2
|
+
export * from './api.js';
|
|
3
|
+
export * from './layouts.js';
|
|
4
|
+
export * from './data-processor.js';
|
|
5
|
+
export * from './trackers.js';
|
|
6
|
+
export * from './interactions.js';
|
|
7
|
+
export * from './filters.js';
|
|
8
|
+
export * from './pagination.js';
|
|
9
|
+
export * from './options.js';
|
|
10
|
+
export * from './configurable.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { asArray } from '@miso.ai/commons';
|
|
2
|
+
import { mergeOptions } from './utils.js';
|
|
3
|
+
|
|
4
|
+
export function normalizeInteractionsOptions(options) {
|
|
5
|
+
if (options === undefined) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
if (options === false) {
|
|
9
|
+
return {
|
|
10
|
+
handle: () => {},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
// preprocess
|
|
14
|
+
const preprocess = asArray(options.preprocess);
|
|
15
|
+
for (const p of preprocess) {
|
|
16
|
+
if (typeof p !== 'function') {
|
|
17
|
+
throw new Error(`Expect preprocess options to be a function: ${p}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// handle
|
|
21
|
+
if (options.handle && typeof options.handle !== 'function') {
|
|
22
|
+
throw new Error(`Expect handle options to be a function: ${options.handle}`);
|
|
23
|
+
}
|
|
24
|
+
return { ...options, preprocess };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function mergeInteractionsOptions(...optionsList) {
|
|
28
|
+
if (optionsList[optionsList.length - 1] === false) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return mergeOptions(optionsList, (merged, options) => Object.assign(merged, {
|
|
32
|
+
...options,
|
|
33
|
+
preprocess: concatArrays(merged.preprocess, options.preprocess),
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { asArray, lowerCamelToSnake, kebabToSnake } from '@miso.ai/commons';
|
|
2
|
+
import { ROLE } from '../../constants.js';
|
|
3
|
+
import { mergeOptions } from './utils.js';
|
|
4
|
+
|
|
5
|
+
export function normalizeLayoutsOptions(options = {}) {
|
|
6
|
+
if (options === false) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
// fallback: results -> products
|
|
10
|
+
const { results, ...rest } = options;
|
|
11
|
+
if (results !== undefined) {
|
|
12
|
+
console.warn(`useLayouts({ results: ... }) is deprecated, use useLayouts({ ${ROLE.PRODUCTS}: ... }) instead`);
|
|
13
|
+
options = { ...rest, [ROLE.PRODUCTS]: results };
|
|
14
|
+
}
|
|
15
|
+
const normalize = {};
|
|
16
|
+
for (const [role, args] of Object.entries(options)) {
|
|
17
|
+
normalize[normalizeRole(role)] = normalizeLayoutOptions(args);
|
|
18
|
+
}
|
|
19
|
+
return normalize;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function normalizeRole(role) {
|
|
23
|
+
role = lowerCamelToSnake(role);
|
|
24
|
+
role = kebabToSnake(role);
|
|
25
|
+
return role;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function normalizeLayoutOptions(args) {
|
|
29
|
+
// take args:
|
|
30
|
+
// * undefined
|
|
31
|
+
// * false
|
|
32
|
+
// * name (string)
|
|
33
|
+
// * options (object)
|
|
34
|
+
// * [name, options]
|
|
35
|
+
if (args === undefined) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
let [name, options] = asArray(args);
|
|
39
|
+
if (typeof name === 'object') {
|
|
40
|
+
options = name;
|
|
41
|
+
name = undefined;
|
|
42
|
+
}
|
|
43
|
+
return [name, options];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function mergeLayoutsOptions(...optionsList) {
|
|
47
|
+
if (optionsList[optionsList.length - 1] === false) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return mergeOptions(optionsList, (merged, options) => {
|
|
51
|
+
for (const [role, args] of Object.entries(options)) {
|
|
52
|
+
merged[role] = mergeLayoutOptions(merged[role], args);
|
|
53
|
+
}
|
|
54
|
+
return merged;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function mergeLayoutOptions(base, overrides) {
|
|
59
|
+
overrides = normalizeLayoutOptions(overrides);
|
|
60
|
+
if (overrides[0] === false) {
|
|
61
|
+
return overrides;
|
|
62
|
+
}
|
|
63
|
+
return base && overrides ? [overrides[0] || base[0], mergeLayoutParameters(base[1], overrides[1])] : (overrides || base);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function mergeLayoutParameters(base, overrides) {
|
|
67
|
+
return {
|
|
68
|
+
...base,
|
|
69
|
+
...overrides,
|
|
70
|
+
link: { ...(base && base.link), ...(overrides && overrides.link) },
|
|
71
|
+
templates: { ...(base && base.templates), ...(overrides && overrides.templates) },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { EventEmitter, defineValues } from '@miso.ai/commons';
|
|
2
|
+
import { WORKFLOW_CONFIGURABLE } from '../../constants.js';
|
|
3
|
+
import { normalizeApiOptions, mergeApiOptions } from './api.js';
|
|
4
|
+
import { normalizeLayoutsOptions, mergeLayoutsOptions } from './layouts.js';
|
|
5
|
+
import { normalizeDataProcessorOptions, mergeDataProcessorOptions } from './data-processor.js';
|
|
6
|
+
import { normalizeTrackersOptions, mergeTrackersOptions } from './trackers.js';
|
|
7
|
+
import { normalizeInteractionsOptions, mergeInteractionsOptions } from './interactions.js';
|
|
8
|
+
import { normalizeFiltersOptions, mergeFiltersOptions } from './filters.js';
|
|
9
|
+
import { normalizePaginationOptions, mergePaginationOptions } from './pagination.js';
|
|
10
|
+
|
|
11
|
+
const FEATURES = [
|
|
12
|
+
{
|
|
13
|
+
key: WORKFLOW_CONFIGURABLE.API,
|
|
14
|
+
normalize: normalizeApiOptions,
|
|
15
|
+
merge: mergeApiOptions,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
key: WORKFLOW_CONFIGURABLE.LAYOUTS,
|
|
19
|
+
normalize: normalizeLayoutsOptions,
|
|
20
|
+
merge: mergeLayoutsOptions,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
key: WORKFLOW_CONFIGURABLE.DATA_PROCESSOR,
|
|
24
|
+
normalize: normalizeDataProcessorOptions,
|
|
25
|
+
merge: mergeDataProcessorOptions,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: WORKFLOW_CONFIGURABLE.TRACKERS,
|
|
29
|
+
normalize: normalizeTrackersOptions,
|
|
30
|
+
merge: mergeTrackersOptions,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: WORKFLOW_CONFIGURABLE.INTERACTIONS,
|
|
34
|
+
normalize: normalizeInteractionsOptions,
|
|
35
|
+
merge: mergeInteractionsOptions,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: WORKFLOW_CONFIGURABLE.FILTERS,
|
|
39
|
+
normalize: normalizeFiltersOptions,
|
|
40
|
+
merge: mergeFiltersOptions,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
key: WORKFLOW_CONFIGURABLE.PAGINATION,
|
|
44
|
+
normalize: normalizePaginationOptions,
|
|
45
|
+
merge: mergePaginationOptions,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export class WorkflowContextOptions {
|
|
52
|
+
|
|
53
|
+
constructor() {
|
|
54
|
+
this._events = new EventEmitter({ target: this });
|
|
55
|
+
this._globals = {};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_notify(name) {
|
|
59
|
+
this._events.emit(name);
|
|
60
|
+
this._events.emit('_update', name);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class WorkflowOptions {
|
|
66
|
+
|
|
67
|
+
constructor(context = {}, defaults = {}) {
|
|
68
|
+
this._events = new EventEmitter({ target: this });
|
|
69
|
+
this._defaults = defaults; // TODO: we should call normalize() on defaults
|
|
70
|
+
this._context = context || {};
|
|
71
|
+
this._locals = {};
|
|
72
|
+
|
|
73
|
+
defineValues(this, {
|
|
74
|
+
resolved: new ResolvedWorkflowOptions(this),
|
|
75
|
+
defaults,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (context && context.on) {
|
|
79
|
+
this._unsubscribes = [
|
|
80
|
+
context.on('_update', name => this._notify(name)),
|
|
81
|
+
];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_notify(name) {
|
|
86
|
+
this.resolved._invalidate(name);
|
|
87
|
+
this._events.emit(name);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
_destroy() {
|
|
91
|
+
for (const unsubscribe of this._unsubscribes || []) {
|
|
92
|
+
unsubscribe();
|
|
93
|
+
}
|
|
94
|
+
this._unsubscribes = [];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class ResolvedWorkflowOptions {
|
|
100
|
+
|
|
101
|
+
constructor(options) {
|
|
102
|
+
this._options = options;
|
|
103
|
+
this._cache = {};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_invalidate(key) {
|
|
107
|
+
this._cache[key] = undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
_get({ key, merge }) {
|
|
111
|
+
if (this._cache[key] === undefined) {
|
|
112
|
+
const options = this._options;
|
|
113
|
+
const contextFeature = options._context[key];
|
|
114
|
+
this._cache[key] = merge(options._defaults[key], contextFeature && contextFeature.get(), options._locals[key]);
|
|
115
|
+
}
|
|
116
|
+
return this._cache[key];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
class WorkflowConfigurableFeature {
|
|
122
|
+
|
|
123
|
+
constructor(options, store, key, normalize, merge) {
|
|
124
|
+
this._options = options;
|
|
125
|
+
this._store = store;
|
|
126
|
+
this._key = key;
|
|
127
|
+
this._normalize = value => value !== undefined ? normalize(value) : undefined;
|
|
128
|
+
this._merge = merge;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get() {
|
|
132
|
+
return this._store[this._key];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
set(value) {
|
|
136
|
+
this._set(this._normalize(value));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
merge(value) {
|
|
140
|
+
this._set(this._merge(this.get(), this._normalize(value)));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_set(value) {
|
|
144
|
+
this._store[this._key] = value;
|
|
145
|
+
this._options._notify(this._key);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
for (const feature of FEATURES) {
|
|
151
|
+
const { key, normalize, merge } = feature;
|
|
152
|
+
Object.defineProperty(WorkflowContextOptions.prototype, key, {
|
|
153
|
+
get: function() {
|
|
154
|
+
const _key = `_${key}`;
|
|
155
|
+
return this[_key] || (this[_key] = new WorkflowConfigurableFeature(this, this._globals, key, normalize, merge));
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
Object.defineProperty(WorkflowOptions.prototype, key, {
|
|
159
|
+
get: function() {
|
|
160
|
+
const _key = `_${key}`;
|
|
161
|
+
return this[_key] || (this[_key] = new WorkflowConfigurableFeature(this, this._locals, key, normalize, merge));
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(ResolvedWorkflowOptions.prototype, key, {
|
|
165
|
+
get: function() {
|
|
166
|
+
return this._get(feature);
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { mergeOptions } from './utils.js';
|
|
2
|
+
|
|
3
|
+
export function normalizePaginationOptions(options) {
|
|
4
|
+
if (options === undefined) {
|
|
5
|
+
throw new Error(`Expect pagination options to be an object or a boolean value: ${options}`);
|
|
6
|
+
}
|
|
7
|
+
if (typeof options === 'boolean') {
|
|
8
|
+
options = { active: options };
|
|
9
|
+
}
|
|
10
|
+
return options;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function mergePaginationOptions(...optionsList) {
|
|
14
|
+
if (optionsList[optionsList.length - 1] === false) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return mergeOptions(optionsList, (merged, options) => Object.assign(merged, options));
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function mergeRolesOptions(base, overrides) {
|
|
2
|
+
return Object.freeze({
|
|
3
|
+
...base,
|
|
4
|
+
...overrides,
|
|
5
|
+
members: mergeRolesMembers(base.members, overrides.members),
|
|
6
|
+
mappings: Object.freeze({ ...base.mappings, ...overrides.mappings }),
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function mergeRolesMembers(base = [], overrides = []) {
|
|
11
|
+
return [...new Set([...base, ...overrides])];
|
|
12
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { mergeOptions } from './utils.js';
|
|
2
|
+
|
|
3
|
+
export function normalizeTrackersOptions(options) {
|
|
4
|
+
if (options === undefined || options === false) {
|
|
5
|
+
return options;
|
|
6
|
+
}
|
|
7
|
+
const normalized = {};
|
|
8
|
+
for (const [role, args] of Object.entries(options)) {
|
|
9
|
+
normalized[role] = normalizeTrackerOptions(args);
|
|
10
|
+
}
|
|
11
|
+
return normalized;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function normalizeTrackerOptions(options) {
|
|
15
|
+
return options;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function mergeTrackersOptions(...optionsList) {
|
|
19
|
+
if (optionsList[optionsList.length - 1] === false) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return mergeOptions(optionsList, (merged, options) => Object.assign(merged, {
|
|
23
|
+
...options,
|
|
24
|
+
impression: mergeTrackerEventOptions(merged.impression, options.impression),
|
|
25
|
+
viewable: mergeTrackerEventOptions(merged.viewable, options.viewable),
|
|
26
|
+
click: mergeTrackerEventOptions(merged.click, options.click),
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function mergeTrackerEventOptions(base = {}, overrides = {}) {
|
|
31
|
+
return (overrides === false || base === false) ? overrides : { ...base, ...overrides };
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { trimObj } from '@miso.ai/commons';
|
|
2
|
+
|
|
3
|
+
export function concatArrays(a0, a1) {
|
|
4
|
+
return (a0 && a0.length) ? (a1 && a1.length) ? [...a0, ...a1] : a0 : a1;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function mergeOptions(optionsList, merge) {
|
|
8
|
+
let merged = {};
|
|
9
|
+
for (const options of optionsList) {
|
|
10
|
+
if (!options) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
merged = merge(merged, options);
|
|
14
|
+
}
|
|
15
|
+
return trimObj(merged);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function normalizeOptions(options) {
|
|
19
|
+
if (options === undefined) {
|
|
20
|
+
throw new Error(`Expect options to be an object or a boolean value: ${options}`);
|
|
21
|
+
}
|
|
22
|
+
if (typeof options === 'boolean') {
|
|
23
|
+
options = { active: options };
|
|
24
|
+
}
|
|
25
|
+
return options;
|
|
26
|
+
}
|
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import { trimObj } from '@miso.ai/commons';
|
|
2
2
|
import { STATUS, ROLE, EVENT_TYPE, isPerformanceEventType, isProductRole } from '../constants.js';
|
|
3
|
+
import { fields } from '../actor/index.js';
|
|
4
|
+
|
|
5
|
+
// role mappings //
|
|
6
|
+
export function mappingSortData(_, { hub, workflowOptions = {} } = {}) {
|
|
7
|
+
const { sort: { options = [] } = {} } = workflowOptions.filters || {};
|
|
8
|
+
if (!options.length) {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
const { sort } = hub.states[fields.filters()] || {};
|
|
12
|
+
const selectedField = (sort && sort.field) || findDefaultSortOption(options).field;
|
|
13
|
+
if (!selectedField) {
|
|
14
|
+
return options;
|
|
15
|
+
}
|
|
16
|
+
// mark selected
|
|
17
|
+
return options.map(option => {
|
|
18
|
+
return {
|
|
19
|
+
...option,
|
|
20
|
+
selected: option.field === selectedField,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function findDefaultSortOption(options) {
|
|
26
|
+
for (const option of options) {
|
|
27
|
+
if (option.default) {
|
|
28
|
+
return option;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return options[0];
|
|
32
|
+
}
|
|
3
33
|
|
|
4
34
|
// data //
|
|
5
35
|
export function getRevision(data) {
|
|
@@ -79,40 +109,6 @@ export function writeAnswerStageToMeta(data) {
|
|
|
79
109
|
};
|
|
80
110
|
}
|
|
81
111
|
|
|
82
|
-
export function writeFiltersToPayload(payload = {}, filters) {
|
|
83
|
-
return trimObj({
|
|
84
|
-
...payload,
|
|
85
|
-
...composeFiltersPayload(filters),
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function composeFiltersPayload(filters) {
|
|
90
|
-
if (!filters) {
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
93
|
-
const { facets } = filters;
|
|
94
|
-
return trimObj({
|
|
95
|
-
facet_filters: composeFacetFilters(facets),
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function composeFacetFilters(facets) {
|
|
100
|
-
if (!facets) {
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|
|
103
|
-
const filters = {};
|
|
104
|
-
for (const field in facets) {
|
|
105
|
-
const values = facets[field];
|
|
106
|
-
if (!values || !values.length) {
|
|
107
|
-
continue; // just in case
|
|
108
|
-
}
|
|
109
|
-
filters[field] = {
|
|
110
|
-
terms: values,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
return Object.keys(filters).length ? filters : undefined;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
112
|
export function retainFacetCountsInData(data, currentFacetCounts) {
|
|
117
113
|
if (!currentFacetCounts) {
|
|
118
114
|
return data;
|
|
@@ -2,7 +2,7 @@ import { defineValues, API } from '@miso.ai/commons';
|
|
|
2
2
|
import Workflow from './base.js';
|
|
3
3
|
import { ListLayout } from '../layout/index.js';
|
|
4
4
|
import { ROLE } from '../constants.js';
|
|
5
|
-
import { mergeRolesOptions } from './options.js';
|
|
5
|
+
import { mergeRolesOptions } from './options/index.js';
|
|
6
6
|
import { mergeInteraction } from './processors.js';
|
|
7
7
|
|
|
8
8
|
const DEFAULT_API_OPTIONS = Object.freeze({
|