@miso.ai/client-sdk-codegen 1.11.6-beta.0 → 1.11.6
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/codegen.js +11 -24
- package/dist/cjs/index.js +8 -18
- package/dist/cjs/output.js +37 -0
- package/dist/cjs/params.js +11 -3
- package/dist/cjs/spec/features.js +30 -26
- package/dist/cjs/spec/index.js +15 -5
- package/dist/cjs/spec/presets.js +29 -0
- package/dist/cjs/spec/utils.js +10 -0
- package/dist/cjs/spec/workflows.js +25 -29
- package/dist/cjs/spec/workflows.slug.js +23 -0
- package/dist/cjs/template/client.js +29 -0
- package/dist/cjs/template/entrypoints.js +15 -0
- package/dist/cjs/template/features.js +19 -0
- package/dist/cjs/{utils.js → template/helpers.js} +26 -8
- package/dist/cjs/template/index.js +39 -0
- package/dist/cjs/ui/hybrid-search.js +74 -0
- package/dist/cjs/ui/index.js +38 -0
- package/dist/cjs/ui/search.js +91 -0
- package/dist/cjs/ui/ui.js +36 -0
- package/package.json +2 -2
- package/src/codegen.js +8 -20
- package/src/index.js +2 -2
- package/src/output.js +33 -0
- package/src/params.js +11 -2
- package/src/spec/features.js +24 -26
- package/src/spec/index.js +2 -5
- package/src/spec/presets.js +24 -0
- package/src/spec/utils.js +5 -0
- package/src/spec/workflows.js +23 -35
- package/src/spec/workflows.slug.js +24 -0
- package/src/template/client.js +25 -0
- package/src/template/entrypoints.js +10 -0
- package/src/template/features.js +10 -0
- package/src/{utils.js → template/helpers.js} +19 -0
- package/src/template/index.js +4 -0
- package/src/ui/hybrid-search.js +71 -0
- package/src/ui/index.js +3 -0
- package/src/ui/search.js +91 -0
- package/src/ui/ui.js +26 -0
- package/dist/cjs/features.js +0 -12
- package/dist/cjs/templates.js +0 -34
- package/dist/cjs/workflow/hybrid-search.js +0 -51
- package/dist/cjs/workflow/index.js +0 -22
- package/src/features.js +0 -5
- package/src/templates.js +0 -26
- package/src/workflow/hybrid-search.js +0 -48
- package/src/workflow/index.js +0 -3
package/src/ui/search.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { search as presets } from '../spec/presets.js';
|
|
2
|
+
import { resolvePreset } from '../template/helpers.js';
|
|
3
|
+
import { misocmd, createClient } from '../template/index.js';
|
|
4
|
+
import { facets, autoQuery } from '../template/features.js';
|
|
5
|
+
|
|
6
|
+
function normalizeOptions({ facets, ...options } = {}) {
|
|
7
|
+
if (facets === true) {
|
|
8
|
+
facets = ['categories'];
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
...options,
|
|
12
|
+
facets,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function search(options) {
|
|
17
|
+
options = normalizeOptions(resolvePreset(presets, options));
|
|
18
|
+
// TODO: extra styles for concatenate format
|
|
19
|
+
const items = [];
|
|
20
|
+
if (options.elements !== false) {
|
|
21
|
+
items.push(
|
|
22
|
+
{
|
|
23
|
+
type: 'html',
|
|
24
|
+
name: 'HTML (Search box)',
|
|
25
|
+
content: htmlSearchBox(options),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'html',
|
|
29
|
+
name: 'HTML (Results)',
|
|
30
|
+
content: htmlResults(options),
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
items.push(
|
|
35
|
+
{
|
|
36
|
+
type: 'js',
|
|
37
|
+
name: 'JavaScript',
|
|
38
|
+
content: js(options),
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
return items;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function js(options) {
|
|
45
|
+
// TODO: support loading from Node module
|
|
46
|
+
return misocmd(`
|
|
47
|
+
// client
|
|
48
|
+
${createClient(options)}
|
|
49
|
+
|
|
50
|
+
// workflow
|
|
51
|
+
const workflow = client.ui.search;
|
|
52
|
+
|
|
53
|
+
// setup: TODO
|
|
54
|
+
${facets(options.facets)}
|
|
55
|
+
|
|
56
|
+
${autoQuery(options.autoQuery)}
|
|
57
|
+
`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function html(options) {
|
|
61
|
+
if (options.elements === false) {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
return `
|
|
65
|
+
${htmlSearchBox(options)}
|
|
66
|
+
<hr>
|
|
67
|
+
${htmlResults(options)}
|
|
68
|
+
`.trim();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function htmlSearchBox(options) {
|
|
72
|
+
return `
|
|
73
|
+
<miso-search>
|
|
74
|
+
<miso-query></miso-query>
|
|
75
|
+
</miso-search>
|
|
76
|
+
`.trim();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function htmlResults(options) {
|
|
80
|
+
// TODO: useLink
|
|
81
|
+
return `
|
|
82
|
+
<miso-search visible-when="loading ready">
|
|
83
|
+
<div class="info">
|
|
84
|
+
<div class="keywords">You searched for “<miso-keywords></miso-keywords>”</div>
|
|
85
|
+
<div class="total"><miso-total></miso-total> Results</div>
|
|
86
|
+
</div>
|
|
87
|
+
<miso-facets></miso-facets>
|
|
88
|
+
<miso-products></miso-products>
|
|
89
|
+
</miso-search>
|
|
90
|
+
`.trim();
|
|
91
|
+
}
|
package/src/ui/ui.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { hybridSearch } from './hybrid-search.js';
|
|
2
|
+
import { search } from './search.js';
|
|
3
|
+
|
|
4
|
+
const workflows = {
|
|
5
|
+
['hybrid-search']: hybridSearch,
|
|
6
|
+
search,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function normalizeOptions({ workflow, ...options } = {}) {
|
|
10
|
+
if (!workflow) {
|
|
11
|
+
throw new Error('Workflow is required');
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
workflow,
|
|
15
|
+
...options,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ui(options) {
|
|
20
|
+
options = normalizeOptions(options);
|
|
21
|
+
const { workflow } = options;
|
|
22
|
+
if (!workflows[workflow]) {
|
|
23
|
+
throw new Error(`Workflow "${workflow}" is not found`);
|
|
24
|
+
}
|
|
25
|
+
return workflows[workflow](options);
|
|
26
|
+
}
|
package/dist/cjs/features.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.autoQuery = autoQuery;
|
|
7
|
-
var _utils = require("./utils.js");
|
|
8
|
-
function autoQuery(autoQuery) {
|
|
9
|
-
return autoQuery ? `workflow.autoQuery(${typeof autoQuery === 'object' ? (0, _utils.format)(autoQuery, {
|
|
10
|
-
multiline: true
|
|
11
|
-
}) : ''});` : '';
|
|
12
|
-
}
|
package/dist/cjs/templates.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createClient = createClient;
|
|
7
|
-
exports.misocmd = misocmd;
|
|
8
|
-
var _utils = require("./utils.js");
|
|
9
|
-
function misocmd(body) {
|
|
10
|
-
return `
|
|
11
|
-
const misocmd = window.misocmd || (window.misocmd = []);
|
|
12
|
-
misocmd.push(async () => {
|
|
13
|
-
${(0, _utils.indent)(body, 2)}
|
|
14
|
-
});
|
|
15
|
-
`.trim();
|
|
16
|
-
}
|
|
17
|
-
function createClient(options) {
|
|
18
|
-
return `
|
|
19
|
-
// client
|
|
20
|
-
const MisoClient = window.MisoClient;
|
|
21
|
-
const client = new MisoClient(${clientOptions(options)});
|
|
22
|
-
`.trim();
|
|
23
|
-
}
|
|
24
|
-
function clientOptions() {
|
|
25
|
-
let {
|
|
26
|
-
apiKey,
|
|
27
|
-
apiKeyParam = false
|
|
28
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
29
|
-
if (!apiKeyParam) {
|
|
30
|
-
return `'${apiKey}'`;
|
|
31
|
-
}
|
|
32
|
-
apiKeyParam = apiKeyParam === true ? 'api-key' : apiKeyParam;
|
|
33
|
-
return `new URLSearchParams(window.location.search).get('${apiKeyParam}') || '${apiKey}'`;
|
|
34
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.hybridSearch = hybridSearch;
|
|
7
|
-
exports.presets = void 0;
|
|
8
|
-
var _utils = require("../utils.js");
|
|
9
|
-
var _templates = require("../templates.js");
|
|
10
|
-
var _features = require("../features.js");
|
|
11
|
-
const presets = exports.presets = Object.freeze({
|
|
12
|
-
standard: Object.freeze({
|
|
13
|
-
workflow: 'hybrid-search',
|
|
14
|
-
autoQuery: true,
|
|
15
|
-
autocomplete: true,
|
|
16
|
-
facets: ['categories'],
|
|
17
|
-
answerBox: true
|
|
18
|
-
})
|
|
19
|
-
});
|
|
20
|
-
function hybridSearch(options) {
|
|
21
|
-
options = (0, _utils.resolvePreset)(presets, options);
|
|
22
|
-
return {
|
|
23
|
-
js: js(options),
|
|
24
|
-
html: html(options)
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function js(options) {
|
|
28
|
-
return (0, _templates.misocmd)(`
|
|
29
|
-
${(0, _templates.createClient)(options)}
|
|
30
|
-
|
|
31
|
-
// workflow
|
|
32
|
-
const workflow = client.ui.hybridSearch;
|
|
33
|
-
|
|
34
|
-
// setup: TODO
|
|
35
|
-
|
|
36
|
-
// render Miso elements
|
|
37
|
-
await client.ui.ready;
|
|
38
|
-
const { templates, wireAnswerBox } = MisoClient.ui.defaults.hybridSearch;
|
|
39
|
-
const rootElement = document.querySelector('#miso-hybrid-search-combo');
|
|
40
|
-
rootElement.innerHTML = templates.root();
|
|
41
|
-
wireAnswerBox(client, rootElement);
|
|
42
|
-
|
|
43
|
-
${(0, _features.autoQuery)(options.autoQuery)}
|
|
44
|
-
`);
|
|
45
|
-
}
|
|
46
|
-
function html(options) {
|
|
47
|
-
return `
|
|
48
|
-
<h1 class="hero-title">Miso Hybrid Search</h1>
|
|
49
|
-
<div id="miso-hybrid-search-combo" class="miso-hybrid-search-combo"></div>
|
|
50
|
-
`.trim();
|
|
51
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
workflows: true
|
|
8
|
-
};
|
|
9
|
-
exports.workflows = void 0;
|
|
10
|
-
var _hybridSearch = require("./hybrid-search.js");
|
|
11
|
-
Object.keys(_hybridSearch).forEach(function (key) {
|
|
12
|
-
if (key === "default" || key === "__esModule") return;
|
|
13
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
14
|
-
if (key in exports && exports[key] === _hybridSearch[key]) return;
|
|
15
|
-
Object.defineProperty(exports, key, {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () {
|
|
18
|
-
return _hybridSearch[key];
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
const workflows = exports.workflows = ['hybrid-search'];
|
package/src/features.js
DELETED
package/src/templates.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { indent } from './utils.js';
|
|
2
|
-
|
|
3
|
-
export function misocmd(body) {
|
|
4
|
-
return `
|
|
5
|
-
const misocmd = window.misocmd || (window.misocmd = []);
|
|
6
|
-
misocmd.push(async () => {
|
|
7
|
-
${indent(body, 2)}
|
|
8
|
-
});
|
|
9
|
-
`.trim();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function createClient(options) {
|
|
13
|
-
return `
|
|
14
|
-
// client
|
|
15
|
-
const MisoClient = window.MisoClient;
|
|
16
|
-
const client = new MisoClient(${clientOptions(options)});
|
|
17
|
-
`.trim();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function clientOptions({ apiKey, apiKeyParam = false } = {}) {
|
|
21
|
-
if (!apiKeyParam) {
|
|
22
|
-
return `'${apiKey}'`;
|
|
23
|
-
}
|
|
24
|
-
apiKeyParam = apiKeyParam === true ? 'api-key' : apiKeyParam;
|
|
25
|
-
return `new URLSearchParams(window.location.search).get('${apiKeyParam}') || '${apiKey}'`;
|
|
26
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { resolvePreset } from '../utils.js';
|
|
2
|
-
import { misocmd, createClient } from '../templates.js';
|
|
3
|
-
import { autoQuery } from '../features.js';
|
|
4
|
-
|
|
5
|
-
export const presets = Object.freeze({
|
|
6
|
-
standard: Object.freeze({
|
|
7
|
-
workflow: 'hybrid-search',
|
|
8
|
-
autoQuery: true,
|
|
9
|
-
autocomplete: true,
|
|
10
|
-
facets: ['categories'],
|
|
11
|
-
answerBox: true,
|
|
12
|
-
}),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export function hybridSearch(options) {
|
|
16
|
-
options = resolvePreset(presets, options);
|
|
17
|
-
return {
|
|
18
|
-
js: js(options),
|
|
19
|
-
html: html(options),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function js(options) {
|
|
24
|
-
return misocmd(`
|
|
25
|
-
${createClient(options)}
|
|
26
|
-
|
|
27
|
-
// workflow
|
|
28
|
-
const workflow = client.ui.hybridSearch;
|
|
29
|
-
|
|
30
|
-
// setup: TODO
|
|
31
|
-
|
|
32
|
-
// render Miso elements
|
|
33
|
-
await client.ui.ready;
|
|
34
|
-
const { templates, wireAnswerBox } = MisoClient.ui.defaults.hybridSearch;
|
|
35
|
-
const rootElement = document.querySelector('#miso-hybrid-search-combo');
|
|
36
|
-
rootElement.innerHTML = templates.root();
|
|
37
|
-
wireAnswerBox(client, rootElement);
|
|
38
|
-
|
|
39
|
-
${autoQuery(options.autoQuery)}
|
|
40
|
-
`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function html(options) {
|
|
44
|
-
return `
|
|
45
|
-
<h1 class="hero-title">Miso Hybrid Search</h1>
|
|
46
|
-
<div id="miso-hybrid-search-combo" class="miso-hybrid-search-combo"></div>
|
|
47
|
-
`.trim();
|
|
48
|
-
}
|
package/src/workflow/index.js
DELETED