@miso.ai/client-sdk-ui 1.13.2-beta.1 → 1.14.0-beta.3

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.
Files changed (226) hide show
  1. package/dist/cjs/asset/svgs.js +17 -4
  2. package/dist/cjs/combo/ask/index.js +2 -2
  3. package/dist/cjs/constants.js +120 -98
  4. package/dist/cjs/defaults/ask/controls.js +1 -1
  5. package/dist/cjs/defaults/hybrid-search/answer-box.js +4 -4
  6. package/dist/cjs/defaults.js +259 -0
  7. package/dist/cjs/element/container/index.js +28 -0
  8. package/dist/cjs/element/container/miso-ask.js +3 -3
  9. package/dist/cjs/element/container/miso-conversation.js +21 -0
  10. package/dist/cjs/element/container/miso-explore.js +1 -1
  11. package/dist/cjs/element/container/miso-history.js +21 -0
  12. package/dist/cjs/element/container/miso-hybrid-search.js +1 -1
  13. package/dist/cjs/element/container/miso-message-item.js +91 -0
  14. package/dist/cjs/element/container/miso-recommendation.js +1 -1
  15. package/dist/cjs/element/container/miso-search.js +1 -1
  16. package/dist/cjs/element/container/miso-thread-item.js +91 -0
  17. package/dist/cjs/element/context/miso-follow-ups.js +1 -1
  18. package/dist/cjs/element/role/index.js +49 -0
  19. package/dist/cjs/element/role/miso-delete.js +20 -0
  20. package/dist/cjs/element/role/miso-messages.js +20 -0
  21. package/dist/cjs/element/role/miso-new-thread.js +20 -0
  22. package/dist/cjs/element/role/miso-rename.js +20 -0
  23. package/dist/cjs/element/role/miso-subscription.js +20 -0
  24. package/dist/cjs/element/role/miso-threads.js +20 -0
  25. package/dist/cjs/element/role/miso-title.js +20 -0
  26. package/dist/cjs/layout/affiliation/affiliation.js +1 -1
  27. package/dist/cjs/layout/banner/banner.js +2 -1
  28. package/dist/cjs/layout/button/button.js +170 -0
  29. package/dist/cjs/layout/button/checkbox.js +116 -0
  30. package/dist/cjs/layout/button/more-button.js +3 -3
  31. package/dist/cjs/layout/container/container.js +1 -1
  32. package/dist/cjs/layout/container/item-container.js +99 -0
  33. package/dist/cjs/layout/error/error.js +2 -1
  34. package/dist/cjs/layout/index.js +42 -0
  35. package/dist/cjs/layout/input/facets.js +4 -3
  36. package/dist/cjs/layout/input/option-list.js +3 -2
  37. package/dist/cjs/layout/input/search-box.js +50 -12
  38. package/dist/cjs/layout/input/select.js +2 -1
  39. package/dist/cjs/layout/list/cards.js +2 -1
  40. package/dist/cjs/layout/list/carousel.js +2 -1
  41. package/dist/cjs/layout/list/collection.js +13 -1
  42. package/dist/cjs/layout/list/gallery.js +2 -1
  43. package/dist/cjs/layout/list/horizontal.js +2 -1
  44. package/dist/cjs/layout/list/list.js +2 -1
  45. package/dist/cjs/layout/list/messages.js +359 -0
  46. package/dist/cjs/layout/list/threads.js +199 -0
  47. package/dist/cjs/layout/mixin/trackable.js +4 -5
  48. package/dist/cjs/layout/mixin/triggerable.js +2 -2
  49. package/dist/cjs/layout/radio/feedback.js +4 -3
  50. package/dist/cjs/layout/templates.js +97 -0
  51. package/dist/cjs/layout/text/question.js +71 -0
  52. package/dist/cjs/layout/text/text.js +2 -1
  53. package/dist/cjs/layout/text/typewriter/index.js +18 -23
  54. package/dist/cjs/plugin.js +43 -104
  55. package/dist/cjs/util/confirm.js +33 -0
  56. package/dist/cjs/util/dom.js +21 -0
  57. package/dist/cjs/util/modal.js +48 -0
  58. package/dist/cjs/util/prompt.js +47 -0
  59. package/dist/cjs/version.js +1 -1
  60. package/package.json +5 -4
  61. package/src/CLAUDE.md +51 -104
  62. package/src/asset/svgs.js +16 -3
  63. package/src/combo/ask/index.js +2 -2
  64. package/src/constants.js +39 -147
  65. package/src/defaults/ask/controls.js +1 -1
  66. package/src/defaults/hybrid-search/answer-box.js +2 -2
  67. package/src/defaults.js +174 -0
  68. package/src/element/container/index.js +4 -0
  69. package/src/element/container/miso-ask.js +3 -3
  70. package/src/element/container/miso-conversation.js +19 -0
  71. package/src/element/container/miso-explore.js +1 -1
  72. package/src/element/container/miso-history.js +19 -0
  73. package/src/element/container/miso-hybrid-search.js +1 -1
  74. package/src/element/container/miso-message-item.js +94 -0
  75. package/src/element/container/miso-recommendation.js +1 -1
  76. package/src/element/container/miso-search.js +1 -1
  77. package/src/element/container/miso-thread-item.js +94 -0
  78. package/src/element/context/miso-follow-ups.js +1 -1
  79. package/src/element/role/index.js +7 -0
  80. package/src/element/role/miso-delete.js +16 -0
  81. package/src/element/role/miso-messages.js +16 -0
  82. package/src/element/role/miso-new-thread.js +16 -0
  83. package/src/element/role/miso-rename.js +16 -0
  84. package/src/element/role/miso-subscription.js +16 -0
  85. package/src/element/role/miso-threads.js +16 -0
  86. package/src/element/role/miso-title.js +16 -0
  87. package/src/layout/affiliation/affiliation.js +2 -2
  88. package/src/layout/banner/banner.js +2 -1
  89. package/src/layout/button/button.js +152 -0
  90. package/src/layout/button/checkbox.js +92 -0
  91. package/src/layout/button/more-button.js +3 -3
  92. package/src/layout/container/container.js +2 -2
  93. package/src/layout/container/item-container.js +99 -0
  94. package/src/layout/error/error.js +2 -1
  95. package/src/layout/index.js +6 -0
  96. package/src/layout/input/facets.js +3 -2
  97. package/src/layout/input/option-list.js +3 -2
  98. package/src/layout/input/search-box.js +45 -8
  99. package/src/layout/input/select.js +2 -1
  100. package/src/layout/list/cards.js +2 -1
  101. package/src/layout/list/carousel.js +2 -1
  102. package/src/layout/list/collection.js +15 -2
  103. package/src/layout/list/gallery.js +2 -1
  104. package/src/layout/list/horizontal.js +2 -1
  105. package/src/layout/list/list.js +2 -1
  106. package/src/layout/list/messages.js +316 -0
  107. package/src/layout/list/threads.js +166 -0
  108. package/src/layout/mixin/trackable.js +2 -3
  109. package/src/layout/mixin/triggerable.js +1 -1
  110. package/src/layout/radio/feedback.js +3 -2
  111. package/src/layout/templates.js +97 -0
  112. package/src/layout/text/question.js +58 -0
  113. package/src/layout/text/text.js +2 -1
  114. package/src/layout/text/typewriter/index.js +15 -18
  115. package/src/plugin.js +31 -117
  116. package/src/util/confirm.js +28 -0
  117. package/src/util/dom.js +16 -0
  118. package/src/util/modal.js +49 -0
  119. package/src/util/prompt.js +42 -0
  120. package/src/version.js +1 -1
  121. package/dist/cjs/actor/data.js +0 -132
  122. package/dist/cjs/actor/feedback.js +0 -29
  123. package/dist/cjs/actor/fields.js +0 -57
  124. package/dist/cjs/actor/filters.js +0 -161
  125. package/dist/cjs/actor/hub.js +0 -57
  126. package/dist/cjs/actor/index.js +0 -73
  127. package/dist/cjs/actor/interactions.js +0 -36
  128. package/dist/cjs/actor/sessions.js +0 -25
  129. package/dist/cjs/actor/tracker-states.js +0 -61
  130. package/dist/cjs/actor/tracker.js +0 -109
  131. package/dist/cjs/actor/trackers.js +0 -52
  132. package/dist/cjs/actor/utils.js +0 -15
  133. package/dist/cjs/actor/view.js +0 -294
  134. package/dist/cjs/actor/views.js +0 -209
  135. package/dist/cjs/source.js +0 -27
  136. package/dist/cjs/util/proxy.js +0 -88
  137. package/dist/cjs/util/trackers.js +0 -88
  138. package/dist/cjs/workflow/affiliations.js +0 -140
  139. package/dist/cjs/workflow/answer-based.js +0 -337
  140. package/dist/cjs/workflow/ask.js +0 -319
  141. package/dist/cjs/workflow/asks.js +0 -150
  142. package/dist/cjs/workflow/autocompletable.js +0 -63
  143. package/dist/cjs/workflow/autocomplete.js +0 -120
  144. package/dist/cjs/workflow/base.js +0 -418
  145. package/dist/cjs/workflow/context.js +0 -19
  146. package/dist/cjs/workflow/explore.js +0 -210
  147. package/dist/cjs/workflow/explores.js +0 -21
  148. package/dist/cjs/workflow/hybrid-search-answer.js +0 -88
  149. package/dist/cjs/workflow/hybrid-search-views.js +0 -109
  150. package/dist/cjs/workflow/hybrid-search.js +0 -213
  151. package/dist/cjs/workflow/index.js +0 -41
  152. package/dist/cjs/workflow/options/api.js +0 -41
  153. package/dist/cjs/workflow/options/auto-query.js +0 -97
  154. package/dist/cjs/workflow/options/configurable.js +0 -45
  155. package/dist/cjs/workflow/options/data-processor.js +0 -20
  156. package/dist/cjs/workflow/options/filters.js +0 -15
  157. package/dist/cjs/workflow/options/index.js +0 -126
  158. package/dist/cjs/workflow/options/interactions.js +0 -41
  159. package/dist/cjs/workflow/options/layouts.js +0 -79
  160. package/dist/cjs/workflow/options/options.js +0 -156
  161. package/dist/cjs/workflow/options/pagination.js +0 -25
  162. package/dist/cjs/workflow/options/roles.js +0 -15
  163. package/dist/cjs/workflow/options/templates.js +0 -30
  164. package/dist/cjs/workflow/options/trackers.js +0 -83
  165. package/dist/cjs/workflow/options/utils.js +0 -33
  166. package/dist/cjs/workflow/processors.js +0 -607
  167. package/dist/cjs/workflow/recommendation.js +0 -57
  168. package/dist/cjs/workflow/recommendations.js +0 -18
  169. package/dist/cjs/workflow/search-based.js +0 -337
  170. package/dist/cjs/workflow/search.js +0 -64
  171. package/dist/cjs/workflow/unit.js +0 -57
  172. package/dist/cjs/workflow/units.js +0 -42
  173. package/dist/cjs/workflow/use-link.js +0 -49
  174. package/src/actor/data.js +0 -106
  175. package/src/actor/feedback.js +0 -28
  176. package/src/actor/fields.js +0 -51
  177. package/src/actor/filters.js +0 -149
  178. package/src/actor/hub.js +0 -47
  179. package/src/actor/index.js +0 -10
  180. package/src/actor/interactions.js +0 -32
  181. package/src/actor/sessions.js +0 -21
  182. package/src/actor/tracker-states.js +0 -57
  183. package/src/actor/tracker.js +0 -104
  184. package/src/actor/trackers.js +0 -45
  185. package/src/actor/utils.js +0 -7
  186. package/src/actor/view.js +0 -272
  187. package/src/actor/views.js +0 -224
  188. package/src/source.js +0 -17
  189. package/src/util/proxy.js +0 -81
  190. package/src/util/trackers.js +0 -84
  191. package/src/workflow/affiliations.js +0 -121
  192. package/src/workflow/answer-based.js +0 -312
  193. package/src/workflow/ask.js +0 -284
  194. package/src/workflow/asks.js +0 -143
  195. package/src/workflow/autocompletable.js +0 -67
  196. package/src/workflow/autocomplete.js +0 -114
  197. package/src/workflow/base.js +0 -396
  198. package/src/workflow/context.js +0 -16
  199. package/src/workflow/explore.js +0 -194
  200. package/src/workflow/explores.js +0 -18
  201. package/src/workflow/hybrid-search-answer.js +0 -73
  202. package/src/workflow/hybrid-search-views.js +0 -116
  203. package/src/workflow/hybrid-search.js +0 -230
  204. package/src/workflow/index.js +0 -5
  205. package/src/workflow/options/api.js +0 -31
  206. package/src/workflow/options/auto-query.js +0 -70
  207. package/src/workflow/options/configurable.js +0 -48
  208. package/src/workflow/options/data-processor.js +0 -15
  209. package/src/workflow/options/filters.js +0 -10
  210. package/src/workflow/options/index.js +0 -11
  211. package/src/workflow/options/interactions.js +0 -36
  212. package/src/workflow/options/layouts.js +0 -73
  213. package/src/workflow/options/options.js +0 -175
  214. package/src/workflow/options/pagination.js +0 -18
  215. package/src/workflow/options/roles.js +0 -12
  216. package/src/workflow/options/templates.js +0 -27
  217. package/src/workflow/options/trackers.js +0 -80
  218. package/src/workflow/options/utils.js +0 -26
  219. package/src/workflow/processors.js +0 -490
  220. package/src/workflow/recommendation.js +0 -63
  221. package/src/workflow/recommendations.js +0 -14
  222. package/src/workflow/search-based.js +0 -329
  223. package/src/workflow/search.js +0 -73
  224. package/src/workflow/unit.js +0 -51
  225. package/src/workflow/units.js +0 -43
  226. package/src/workflow/use-link.js +0 -41
@@ -1,70 +0,0 @@
1
- import { trimObj } from '@miso.ai/commons';
2
- import { ROLE, QUESTION_SOURCE } from '../../constants.js';
3
-
4
- // TODO: eliminate browser dependency?
5
-
6
- export const DEFAULT_AUTO_QUERY_PARAM = 'q';
7
- export const DEFAULT_AUTO_QUERY_SOURCE_PARAM = 'qs';
8
-
9
- export function normalizeAutoQueryOptions({
10
- setValue = true,
11
- focus = true,
12
- updateUrl = true,
13
- param = DEFAULT_AUTO_QUERY_PARAM,
14
- sourceParam = DEFAULT_AUTO_QUERY_SOURCE_PARAM,
15
- ...options
16
- } = {}) {
17
- return { setValue, focus, updateUrl, param, sourceParam, ...options };
18
- }
19
-
20
- export function autoQuery(options = {}) {
21
- // TODO: support getting value from URL path
22
- const { setValue, focus, param, sourceParam } = this._autoQuery = normalizeAutoQueryOptions(options);
23
- const searchParams = new URLSearchParams(window.location.search);
24
- const q = searchParams.get(param);
25
- const qs = searchParams.get(sourceParam) || undefined;
26
-
27
- // because it's probably not there yet, but this is an ad-hoc solution
28
- setTimeout(() => {
29
- for (const view of this._views.getAll(ROLE.QUERY)) {
30
- const { layout } = view;
31
- if (q && setValue) {
32
- layout.value = q;
33
- }
34
- if (!q && focus) {
35
- layout.focus();
36
- }
37
- }
38
- });
39
-
40
- if (q) {
41
- this.query(trimObj({ q, qs }));
42
- }
43
- }
44
-
45
- export function updateQueryParametersInUrl({ value, request }) {
46
- if (!this._autoQuery || !this._autoQuery.updateUrl) {
47
- return;
48
- }
49
- const { param, sourceParam } = this._autoQuery;
50
- const query = (value && (value.question || value.keyword)) || (request && request.payload && (request.payload.question || request.payload.q));
51
- const querySource = request && request.payload && request.payload.metadata && request.payload.metadata.question_source;
52
-
53
- if (!query) {
54
- return; // at initial phase
55
- }
56
-
57
- const url = new URL(window.location);
58
- const currentQuery = url.searchParams.get(param);
59
- const currentQuerySource = url.searchParams.get(sourceParam) || QUESTION_SOURCE.ORGANIC;
60
- if (query === currentQuery && querySource === currentQuerySource) {
61
- return;
62
- }
63
- url.searchParams.set(param, query);
64
- if (querySource === QUESTION_SOURCE.ORGANIC) {
65
- url.searchParams.delete(sourceParam);
66
- } else {
67
- url.searchParams.set(sourceParam, querySource);
68
- }
69
- window.history.replaceState({}, '', url);
70
- }
@@ -1,48 +0,0 @@
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
- }
@@ -1,15 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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
- }
@@ -1,11 +0,0 @@
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';
11
- export * from './auto-query.js';
@@ -1,36 +0,0 @@
1
- import { asArray } from '@miso.ai/commons';
2
- import { mergeOptions, concatArrays } 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
-
@@ -1,73 +0,0 @@
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
- }
@@ -1,175 +0,0 @@
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
- import { normalizeTemplatesOptions, mergeTemplatesOptions } from './templates.js';
11
-
12
- const FEATURES = [
13
- {
14
- key: WORKFLOW_CONFIGURABLE.API,
15
- normalize: normalizeApiOptions,
16
- merge: mergeApiOptions,
17
- },
18
- {
19
- key: WORKFLOW_CONFIGURABLE.LAYOUTS,
20
- normalize: normalizeLayoutsOptions,
21
- merge: mergeLayoutsOptions,
22
- },
23
- {
24
- key: WORKFLOW_CONFIGURABLE.DATA_PROCESSOR,
25
- normalize: normalizeDataProcessorOptions,
26
- merge: mergeDataProcessorOptions,
27
- },
28
- {
29
- key: WORKFLOW_CONFIGURABLE.TRACKERS,
30
- normalize: normalizeTrackersOptions,
31
- merge: mergeTrackersOptions,
32
- },
33
- {
34
- key: WORKFLOW_CONFIGURABLE.INTERACTIONS,
35
- normalize: normalizeInteractionsOptions,
36
- merge: mergeInteractionsOptions,
37
- },
38
- {
39
- key: WORKFLOW_CONFIGURABLE.FILTERS,
40
- normalize: normalizeFiltersOptions,
41
- merge: mergeFiltersOptions,
42
- },
43
- {
44
- key: WORKFLOW_CONFIGURABLE.PAGINATION,
45
- normalize: normalizePaginationOptions,
46
- merge: mergePaginationOptions,
47
- },
48
- {
49
- key: WORKFLOW_CONFIGURABLE.TEMPLATES,
50
- normalize: normalizeTemplatesOptions,
51
- merge: mergeTemplatesOptions,
52
- },
53
- ];
54
-
55
-
56
-
57
- export class WorkflowContextOptions {
58
-
59
- constructor() {
60
- this._events = new EventEmitter({ target: this });
61
- this._globals = {};
62
- }
63
-
64
- _notify(name) {
65
- this._events.emit(name);
66
- this._events.emit('_update', name);
67
- }
68
-
69
- }
70
-
71
- export class WorkflowOptions {
72
-
73
- constructor(context = {}, defaults = {}) {
74
- this._events = new EventEmitter({ target: this });
75
- this._defaults = defaults; // TODO: we should call normalize() on defaults
76
- this._context = context || {};
77
- this._locals = {};
78
-
79
- defineValues(this, {
80
- resolved: new ResolvedWorkflowOptions(this),
81
- defaults,
82
- });
83
-
84
- if (context && context.on) {
85
- this._unsubscribes = [
86
- context.on('_update', name => this._notify(name)),
87
- ];
88
- }
89
- }
90
-
91
- _notify(name) {
92
- this.resolved._invalidate(name);
93
- this._events.emit(name);
94
- }
95
-
96
- _destroy() {
97
- for (const unsubscribe of this._unsubscribes || []) {
98
- unsubscribe();
99
- }
100
- this._unsubscribes = [];
101
- }
102
-
103
- }
104
-
105
- class ResolvedWorkflowOptions {
106
-
107
- constructor(options) {
108
- this._options = options;
109
- this._cache = {};
110
- }
111
-
112
- _invalidate(key) {
113
- this._cache[key] = undefined;
114
- }
115
-
116
- _get({ key, merge }) {
117
- if (this._cache[key] === undefined) {
118
- const options = this._options;
119
- const contextFeature = options._context[key];
120
- this._cache[key] = merge(options._defaults[key], contextFeature && contextFeature.get(), options._locals[key]);
121
- }
122
- return this._cache[key];
123
- }
124
-
125
- }
126
-
127
- class WorkflowConfigurableFeature {
128
-
129
- constructor(options, store, key, normalize, merge) {
130
- this._options = options;
131
- this._store = store;
132
- this._key = key;
133
- this._normalize = value => value !== undefined ? normalize(value) : undefined;
134
- this._merge = merge;
135
- }
136
-
137
- get() {
138
- return this._store[this._key];
139
- }
140
-
141
- set(value) {
142
- this._set(this._normalize(value));
143
- }
144
-
145
- merge(value) {
146
- this._set(this._merge(this.get(), this._normalize(value)));
147
- }
148
-
149
- _set(value) {
150
- this._store[this._key] = value;
151
- this._options._notify(this._key);
152
- }
153
-
154
- }
155
-
156
- for (const feature of FEATURES) {
157
- const { key, normalize, merge } = feature;
158
- Object.defineProperty(WorkflowContextOptions.prototype, key, {
159
- get: function() {
160
- const _key = `_${key}`;
161
- return this[_key] || (this[_key] = new WorkflowConfigurableFeature(this, this._globals, key, normalize, merge));
162
- },
163
- });
164
- Object.defineProperty(WorkflowOptions.prototype, key, {
165
- get: function() {
166
- const _key = `_${key}`;
167
- return this[_key] || (this[_key] = new WorkflowConfigurableFeature(this, this._locals, key, normalize, merge));
168
- },
169
- });
170
- Object.defineProperty(ResolvedWorkflowOptions.prototype, key, {
171
- get: function() {
172
- return this._get(feature);
173
- },
174
- });
175
- }
@@ -1,18 +0,0 @@
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
- }
@@ -1,12 +0,0 @@
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
- }
@@ -1,27 +0,0 @@
1
- import { mergeOptions } from './utils.js';
2
-
3
- export function normalizeTemplatesOptions(options = {}) {
4
- const normalize = {};
5
- for (const [key, args] of Object.entries(options)) {
6
- normalize[key] = normalizeTemplateOptions(args);
7
- }
8
- return normalize;
9
- }
10
-
11
- function normalizeTemplateOptions(args) {
12
- // TODO: if object, make it function arguments
13
- return args === undefined ? undefined : typeof args !== 'function' ? () => args : args;
14
- }
15
-
16
- export function mergeTemplatesOptions(...optionsList) {
17
- return mergeOptions(optionsList, (merged, options) => {
18
- for (const [key, args] of Object.entries(options)) {
19
- merged[key] = mergeTemplateOptions(merged[key], args);
20
- }
21
- return merged;
22
- });
23
- }
24
-
25
- function mergeTemplateOptions(base, overrides) {
26
- return normalizeTemplateOptions(overrides) || base;
27
- }
@@ -1,80 +0,0 @@
1
- import { TRACKING_EVENT_TYPES } from '../../constants.js';
2
- import { mergeOptions, normalizeOptions } from './utils.js';
3
-
4
- export const DEFAULT_TRACKER_OPTIONS = Object.freeze({
5
- active: true,
6
- impression: Object.freeze({
7
- active: true,
8
- }),
9
- viewable: Object.freeze({
10
- active: true,
11
- area: 0.5,
12
- duration: 1000,
13
- }),
14
- click: Object.freeze({
15
- active: true,
16
- lenient: false,
17
- }),
18
- });
19
-
20
- export function normalizeTrackersOptions(options = {}) {
21
- options = normalizeOptions(options);
22
- const { active, ...rest } = options;
23
- const normalized = {};
24
- for (const [role, args] of Object.entries(rest)) {
25
- normalized[role] = normalizeTrackerOptions(args);
26
- }
27
- return {
28
- active,
29
- ...normalized,
30
- };
31
- }
32
-
33
- function normalizeTrackerOptions(options = {}) {
34
- options = normalizeOptions(options);
35
- const { active, ...rest } = options;
36
- const normalized = {};
37
- for (const [role, args] of Object.entries(rest)) {
38
- normalized[role] = normalizeTrackerEventOptions(args);
39
- }
40
- return options;
41
- }
42
-
43
- function normalizeTrackerEventOptions(options = {}) {
44
- options = normalizeOptions(options);
45
- return options;
46
- }
47
-
48
- export function mergeTrackersOptions(...optionsList) {
49
- // TODO: should be able to remove this
50
- if (optionsList[optionsList.length - 1] === false) {
51
- return false;
52
- }
53
- return mergeOptions(optionsList, (merged, options) => {
54
- for (const [key, args] of Object.entries(options)) {
55
- if (args === undefined) {
56
- continue;
57
- }
58
- merged[key] = key === 'active' ? args : mergeTrackerOptions(merged[key], args);
59
- }
60
- return merged;
61
- });
62
- }
63
-
64
- function mergeTrackerOptions(base = {}, overrides = {}) {
65
- const merged = { ...base };
66
- for (const [key, args] of Object.entries(overrides)) {
67
- if (args === undefined) {
68
- continue;
69
- }
70
- merged[key] = TRACKING_EVENT_TYPES.includes(key) ? mergeTrackerEventOptions(base[key], args) : args;
71
- }
72
- return merged;
73
- }
74
-
75
- function mergeTrackerEventOptions(base = {}, overrides = {}) {
76
- return {
77
- ...base,
78
- ...overrides,
79
- };
80
- }
@@ -1,26 +0,0 @@
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
- }