bonsai-search 3.1.1 → 3.1.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.
- package/README.md +37 -68
- package/dist/{bonsai-sdk-3.1.1.js → bonsai-sdk-3.1.3.js} +1 -1
- package/dist/bonsai-search-webcomponent-3.1.3.js +1215 -0
- package/dist/bonsai-search-webcomponent.js +3241 -0
- package/dist/bonsai-searchbar-webcomponent-3.1.3.js +1093 -0
- package/dist/bonsai-searchbar-webcomponent.js +1377 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +11 -5
- package/dist/index.d.cts +0 -312
- package/dist/index.d.ts +0 -312
- /package/dist/{bonsai-sdk-3.1.1.css → bonsai-sdk-3.1.3.css} +0 -0
- /package/dist/{bonsai-searchbar-3.1.1.js → bonsai-searchbar-3.1.3.js} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Bonsai Search
|
|
1
|
+
# Bonsai Search
|
|
2
2
|
|
|
3
|
-
AI-powered search for e-commerce. Drop-in
|
|
3
|
+
AI-powered search web components for e-commerce. Drop-in `<bonsai-search>` and `<bonsai-searchbar>` custom elements for adding semantic product search to any website.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -10,30 +10,39 @@ AI-powered search for e-commerce. Drop-in web component or JavaScript SDK for ad
|
|
|
10
10
|
npm install bonsai-search
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
```javascript
|
|
14
|
+
// Registers <bonsai-search> custom element
|
|
15
|
+
import "bonsai-search";
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
// Registers <bonsai-searchbar> custom element
|
|
18
|
+
import "bonsai-search/searchbar";
|
|
17
19
|
```
|
|
18
20
|
|
|
19
|
-
### CDN
|
|
21
|
+
### CDN
|
|
20
22
|
|
|
21
23
|
```html
|
|
22
|
-
|
|
24
|
+
<!-- Full search component -->
|
|
25
|
+
<script src="https://assets.hibonsai.com/sdk/bonsai-search-webcomponent-3.1.2.js"></script>
|
|
26
|
+
|
|
27
|
+
<!-- Searchbar only -->
|
|
28
|
+
<script src="https://assets.hibonsai.com/sdk/bonsai-searchbar-webcomponent-3.1.2.js"></script>
|
|
23
29
|
```
|
|
24
30
|
|
|
25
31
|
## Usage
|
|
26
32
|
|
|
27
|
-
###
|
|
33
|
+
### `<bonsai-search>`
|
|
34
|
+
|
|
35
|
+
Full search experience with input, suggestions, AI-powered results, and product cards.
|
|
28
36
|
|
|
29
37
|
```html
|
|
30
38
|
<bonsai-search
|
|
31
39
|
api-key="your-api-key"
|
|
32
|
-
base-url="https://api.hibonsai.com/rest/search/
|
|
40
|
+
base-url="https://api.hibonsai.com/rest/search/v3/"
|
|
33
41
|
placeholder="Describe what you're looking for..."
|
|
34
42
|
suggestions='["suggestion 1", "suggestion 2"]'
|
|
35
43
|
max-results="20"
|
|
36
44
|
render-price
|
|
45
|
+
markdown
|
|
37
46
|
brand-color="#0A5B3B"
|
|
38
47
|
text-color="#303030"
|
|
39
48
|
muted-color="#9CA3AF"
|
|
@@ -46,40 +55,27 @@ npm install bonsai-search
|
|
|
46
55
|
</bonsai-search>
|
|
47
56
|
```
|
|
48
57
|
|
|
49
|
-
###
|
|
58
|
+
### `<bonsai-searchbar>`
|
|
50
59
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
onSearch: (query) => {
|
|
61
|
-
console.log("Searching for:", query);
|
|
62
|
-
},
|
|
63
|
-
onResults: (results) => {
|
|
64
|
-
console.log("Found results:", results);
|
|
65
|
-
},
|
|
66
|
-
onAi: (data) => {
|
|
67
|
-
console.log("AI results:", data);
|
|
68
|
-
},
|
|
69
|
-
onError: (error) => {
|
|
70
|
-
console.error("Search error:", error);
|
|
71
|
-
},
|
|
72
|
-
});
|
|
60
|
+
Lightweight search input with suggestions dropdown. Use this when you want to handle results rendering yourself.
|
|
61
|
+
|
|
62
|
+
```html
|
|
63
|
+
<bonsai-searchbar
|
|
64
|
+
api-key="your-api-key"
|
|
65
|
+
base-url="https://api.hibonsai.com/rest/search/v3/"
|
|
66
|
+
placeholder="Search products..."
|
|
67
|
+
suggestions='["suggestion 1", "suggestion 2"]'>
|
|
68
|
+
</bonsai-searchbar>
|
|
73
69
|
```
|
|
74
70
|
|
|
75
71
|
## Configuration
|
|
76
72
|
|
|
77
|
-
###
|
|
73
|
+
### Attributes
|
|
78
74
|
|
|
79
75
|
| Attribute | Description | Default |
|
|
80
76
|
|-----------|-------------|---------|
|
|
81
|
-
| `api-key` | **(Required)** API key for authentication |
|
|
82
|
-
| `base-url` | API endpoint URL | `https://api.hibonsai.com/rest/search/
|
|
77
|
+
| `api-key` | **(Required)** API key for authentication | -- |
|
|
78
|
+
| `base-url` | API endpoint URL | `https://api.hibonsai.com/rest/search/v3/` |
|
|
83
79
|
| `placeholder` | Search input placeholder text | `"Describe what you're looking for..."` |
|
|
84
80
|
| `suggestions` | JSON array of suggestion strings | `[]` |
|
|
85
81
|
| `max-results` | Maximum number of results to display | `50` |
|
|
@@ -92,7 +88,7 @@ const search = new BonsaiSearch({
|
|
|
92
88
|
| `items-label` | Label for items when no recommendations | `"Items"` |
|
|
93
89
|
| `theme` | Color theme: `"light"`, `"dark"`, or `"auto"` | `"light"` |
|
|
94
90
|
|
|
95
|
-
### Theming
|
|
91
|
+
### Theming
|
|
96
92
|
|
|
97
93
|
| Attribute | Description |
|
|
98
94
|
|-----------|-------------|
|
|
@@ -110,37 +106,9 @@ const search = new BonsaiSearch({
|
|
|
110
106
|
| `canvas-color` | Canvas/page background |
|
|
111
107
|
| `results-columns` | Number of grid columns for results |
|
|
112
108
|
|
|
113
|
-
###
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|--------|------|-------------|
|
|
117
|
-
| `container` | `HTMLElement` | **(Required)** Container element for the search UI |
|
|
118
|
-
| `apiKey` | `string` | **(Required)** API key for authentication |
|
|
119
|
-
| `baseUrl` | `string` | API endpoint URL |
|
|
120
|
-
| `placeholder` | `string` | Search input placeholder text |
|
|
121
|
-
| `suggestions` | `string[]` | Array of search suggestions |
|
|
122
|
-
| `debounceMs` | `number` | Debounce delay for search-as-you-type (0 = disabled) |
|
|
123
|
-
| `maxResults` | `number` | Maximum number of results |
|
|
124
|
-
| `timeoutMs` | `number` | Request timeout in milliseconds |
|
|
125
|
-
| `renderPrice` | `boolean` | Show product prices |
|
|
126
|
-
| `imageObjectFit` | `"cover" \| "contain"` | Image fit mode |
|
|
127
|
-
| `imageHostname` | `string` | CDN hostname for image srcset generation |
|
|
128
|
-
| `generateSrcSet` | `boolean` | Generate srcset attributes for images |
|
|
129
|
-
| `srcSetSizes` | `SrcSetSize[]` | Sizes for srcset generation |
|
|
130
|
-
| `markdown` | `boolean` | Enable markdown in recommendations |
|
|
131
|
-
| `featuredItemsLabel` | `string` | Label for featured items section |
|
|
132
|
-
| `moreItemsLabel` | `string` | Label for more items section |
|
|
133
|
-
| `itemsLabel` | `string` | Label for items section |
|
|
134
|
-
| `onSearch` | `(query: string) => void` | Callback when search is initiated |
|
|
135
|
-
| `onResults` | `(results: SearchResult[]) => void` | Callback when initial results arrive |
|
|
136
|
-
| `onAi` | `(data: AiEventData) => void` | Callback when AI-scored results arrive |
|
|
137
|
-
| `onError` | `(error: Error) => void` | Callback on error |
|
|
138
|
-
| `onImg` | `(result, img, wrapper, sdk) => void` | Callback to customize image elements |
|
|
139
|
-
| `onPrice` | `(result, price, parent?) => string` | Callback to format prices |
|
|
140
|
-
|
|
141
|
-
### Events (Web Component)
|
|
142
|
-
|
|
143
|
-
The web component emits custom events that bubble and are composed:
|
|
109
|
+
### Events
|
|
110
|
+
|
|
111
|
+
The web components emit custom events that bubble and are composed:
|
|
144
112
|
|
|
145
113
|
```javascript
|
|
146
114
|
const el = document.querySelector("bonsai-search");
|
|
@@ -169,7 +137,8 @@ npm install
|
|
|
169
137
|
npm run dev # Watch mode (SDK)
|
|
170
138
|
npm run dev:webcomponents # Dev server (web components)
|
|
171
139
|
npm run build # Build SDK
|
|
172
|
-
npm run build:webcomponents
|
|
140
|
+
npm run build:webcomponents # Build web components (IIFE for CDN)
|
|
141
|
+
npm run build:webcomponents:esm # Build web components (ESM for npm)
|
|
173
142
|
npm run test # Run tests
|
|
174
143
|
npm run typecheck # Type check
|
|
175
144
|
```
|
|
@@ -911,7 +911,7 @@
|
|
|
911
911
|
|
|
912
912
|
//#endregion
|
|
913
913
|
//#region src/index.ts
|
|
914
|
-
const VERSION = "3.1.
|
|
914
|
+
const VERSION = "3.1.3";
|
|
915
915
|
const ICONS = {
|
|
916
916
|
search: `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
917
917
|
<circle cx="11" cy="11" r="8"></circle>
|