@miso.ai/client-sdk-ui 1.11.0-beta.1 → 1.11.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.11.0-beta.1';
7
+ var _default = exports.default = '1.11.0-beta.2';
@@ -242,7 +242,12 @@ class AnswerBasedWorkflow extends _base.default {
242
242
 
243
243
  // interactions //
244
244
  _preprocessInteraction(payload) {
245
- payload = super._preprocessInteraction(payload) || {};
245
+ payload = super._preprocessInteraction(payload);
246
+ payload = this._writeQuestionIdToInteractions(payload);
247
+ return payload;
248
+ }
249
+ _writeQuestionIdToInteractions() {
250
+ let payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
246
251
  const {
247
252
  context = {}
248
253
  } = payload;
@@ -215,6 +215,8 @@ class Workflow extends _commons.Component {
215
215
  get trackers() {
216
216
  return this._views.trackers;
217
217
  }
218
+
219
+ // TODO: extract to a separate function
218
220
  _preprocessInteraction() {
219
221
  let _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
220
222
  let {
@@ -16,7 +16,9 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
16
16
  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; }
17
17
  const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_API_OPTIONS, {
18
18
  name: _commons.API.NAME.SEARCH,
19
- payload: Object.assign({}, _answerBased.default.DEFAULT_API_OPTIONS.payload)
19
+ payload: Object.assign({}, _answerBased.default.DEFAULT_API_OPTIONS.payload, {
20
+ source_fl: [...(_answerBased.default.DEFAULT_API_OPTIONS.payload.source_fl || []), 'title', 'snippet']
21
+ })
20
22
  }));
21
23
  const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _answerBased.default.DEFAULT_LAYOUTS, {
22
24
  [_constants.ROLE.PRODUCTS]: [_index2.ListLayout.type, {
@@ -70,7 +72,7 @@ class HybridSearch extends _answerBased.default {
70
72
  filters
71
73
  } = _ref,
72
74
  payload = _objectWithoutPropertiesLoose(_ref, _excluded);
73
- const fq = this._buildFq(filters); // TODO: combine with fq in payload?
75
+ const fq = (0, _processors.composeFq)(filters); // TODO: combine with fq in payload?
74
76
  return (0, _commons.trimObj)(Object.assign({}, payload, {
75
77
  q,
76
78
  // q, not question
@@ -80,23 +82,6 @@ class HybridSearch extends _answerBased.default {
80
82
  })
81
83
  }));
82
84
  }
83
- _buildFq(filters) {
84
- if (!filters) {
85
- return undefined;
86
- }
87
- const clauses = [];
88
- const {
89
- facets
90
- } = filters;
91
- for (const field in facets) {
92
- const values = facets[field];
93
- if (!values || !values.length) {
94
- continue; // just in case
95
- }
96
- clauses.push(`${field}:(${values.map(v => `"${v}"`).join(' OR ')})`);
97
- }
98
- return clauses.map(c => `(${c})`).join(' AND ');
99
- }
100
85
  _refine(filters) {
101
86
  const query = this._hub.states[_index.fields.query()];
102
87
  const payload = this._buildPayload(Object.assign({}, query, {
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.addDataInstructions = addDataInstructions;
7
+ exports.composeFq = composeFq;
7
8
  exports.removeDataInstructions = removeDataInstructions;
8
9
  exports.writeAnswerStageToMeta = writeAnswerStageToMeta;
9
10
  exports.writeDataStatus = writeDataStatus;
@@ -110,4 +111,21 @@ function removeDataInstructions(data) {
110
111
  }
111
112
  const rest = _objectWithoutPropertiesLoose(data, _excluded);
112
113
  return rest;
114
+ }
115
+ function composeFq(filters) {
116
+ if (!filters) {
117
+ return undefined;
118
+ }
119
+ const clauses = [];
120
+ const {
121
+ facets
122
+ } = filters;
123
+ for (const field in facets) {
124
+ const values = facets[field];
125
+ if (!values || !values.length) {
126
+ continue; // just in case
127
+ }
128
+ clauses.push(`${field}:(${values.map(v => `"${v}"`).join(' OR ')})`);
129
+ }
130
+ return clauses.map(c => `(${c})`).join(' AND ');
113
131
  }
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@miso.ai/commons": "1.11.0-beta.1"
29
+ "@miso.ai/commons": "1.11.0-beta.2"
30
30
  },
31
- "version": "1.11.0-beta.1"
31
+ "version": "1.11.0-beta.2"
32
32
  }
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.11.0-beta.1';
1
+ export default '1.11.0-beta.2';
@@ -205,7 +205,12 @@ export default class AnswerBasedWorkflow extends Workflow {
205
205
 
206
206
  // interactions //
207
207
  _preprocessInteraction(payload) {
208
- payload = super._preprocessInteraction(payload) || {};
208
+ payload = super._preprocessInteraction(payload);
209
+ payload = this._writeQuestionIdToInteractions(payload);
210
+ return payload;
211
+ }
212
+
213
+ _writeQuestionIdToInteractions(payload = {}) {
209
214
  const { context = {} } = payload;
210
215
  const { custom_context = {} } = context;
211
216
  let { questionId } = this;
@@ -203,6 +203,7 @@ export default class Workflow extends Component {
203
203
  return this._views.trackers;
204
204
  }
205
205
 
206
+ // TODO: extract to a separate function
206
207
  _preprocessInteraction({
207
208
  context: {
208
209
  custom_context,
@@ -4,13 +4,14 @@ import { mergeApiOptions } from './options.js';
4
4
  import { fields } from '../actor/index.js';
5
5
  import { ROLE, ORGANIC_QUESTION_SOURCE } from '../constants.js';
6
6
  import { ListLayout, TextLayout, FacetsLayout } from '../layout/index.js';
7
- import { writeKeywordsToData, addDataInstructions } from './processors.js';
7
+ import { writeKeywordsToData, addDataInstructions, composeFq } from './processors.js';
8
8
 
9
9
  const DEFAULT_API_OPTIONS = Object.freeze({
10
10
  ...AnswerBasedWorkflow.DEFAULT_API_OPTIONS,
11
11
  name: API.NAME.SEARCH,
12
12
  payload: {
13
13
  ...AnswerBasedWorkflow.DEFAULT_API_OPTIONS.payload,
14
+ source_fl: [...(AnswerBasedWorkflow.DEFAULT_API_OPTIONS.payload.source_fl || []), 'title', 'snippet'],
14
15
  },
15
16
  });
16
17
 
@@ -65,7 +66,7 @@ export default class HybridSearch extends AnswerBasedWorkflow {
65
66
 
66
67
  // query //
67
68
  _buildPayload({ q, qs, filters, ...payload } = {}) {
68
- const fq = this._buildFq(filters); // TODO: combine with fq in payload?
69
+ const fq = composeFq(filters); // TODO: combine with fq in payload?
69
70
  return trimObj({
70
71
  ...payload,
71
72
  q, // q, not question
@@ -77,22 +78,6 @@ export default class HybridSearch extends AnswerBasedWorkflow {
77
78
  });
78
79
  }
79
80
 
80
- _buildFq(filters) {
81
- if (!filters) {
82
- return undefined;
83
- }
84
- const clauses = [];
85
- const { facets } = filters;
86
- for (const field in facets) {
87
- const values = facets[field];
88
- if (!values || !values.length) {
89
- continue; // just in case
90
- }
91
- clauses.push(`${field}:(${values.map(v => `"${v}"`).join(' OR ')})`);
92
- }
93
- return clauses.map(c => `(${c})`).join(' AND ');
94
- }
95
-
96
81
  _refine(filters) {
97
82
  const query = this._hub.states[fields.query()];
98
83
  const payload = this._buildPayload({ ...query, filters, answer: false });
@@ -93,3 +93,19 @@ export function removeDataInstructions(data) {
93
93
  const { _inst, ...rest } = data;
94
94
  return rest;
95
95
  }
96
+
97
+ export function composeFq(filters) {
98
+ if (!filters) {
99
+ return undefined;
100
+ }
101
+ const clauses = [];
102
+ const { facets } = filters;
103
+ for (const field in facets) {
104
+ const values = facets[field];
105
+ if (!values || !values.length) {
106
+ continue; // just in case
107
+ }
108
+ clauses.push(`${field}:(${values.map(v => `"${v}"`).join(' OR ')})`);
109
+ }
110
+ return clauses.map(c => `(${c})`).join(' AND ');
111
+ }