@indxsearch/intrface 1.0.9 → 1.1.0
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 +79 -35
- package/dist/index.es.js +502 -502
- package/dist/index.umd.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,29 +22,31 @@ npm install @indxsearch/intrface @indxsearch/systm @indxsearch/pixl
|
|
|
22
22
|
|
|
23
23
|
### 1. Set Up Environment Variables
|
|
24
24
|
|
|
25
|
-
Create a `.env.local` file in your project root
|
|
25
|
+
Create a `.env.local` file in your project root:
|
|
26
26
|
|
|
27
|
+
**Option A: Using Bearer Token (Recommended for Production)**
|
|
27
28
|
```bash
|
|
28
|
-
# INDX Server Configuration
|
|
29
29
|
VITE_INDX_URL=https://your-indx-server.com
|
|
30
|
+
VITE_INDX_TOKEN=your-jwt-bearer-token-here
|
|
31
|
+
```
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
**Option B: Using Email/Password (Quick Start)**
|
|
34
|
+
```bash
|
|
35
|
+
VITE_INDX_URL=https://your-indx-server.com
|
|
32
36
|
VITE_INDX_EMAIL=your@email.com
|
|
33
37
|
VITE_INDX_PASSWORD=yourpassword
|
|
34
38
|
```
|
|
35
39
|
|
|
36
40
|
**For local development:**
|
|
37
41
|
```bash
|
|
38
|
-
VITE_INDX_URL=http://localhost:
|
|
39
|
-
|
|
40
|
-
VITE_INDX_PASSWORD=yourpassword
|
|
42
|
+
VITE_INDX_URL=http://localhost:5001
|
|
43
|
+
# Then add either token or email/password as shown above
|
|
41
44
|
```
|
|
42
45
|
|
|
43
46
|
**Security Notes:**
|
|
44
47
|
- Never commit `.env.local` to version control
|
|
45
|
-
- Store credentials securely in environment variables
|
|
46
|
-
-
|
|
47
|
-
- Session tokens are managed internally and refreshed as needed
|
|
48
|
+
- Store credentials/tokens securely in environment variables
|
|
49
|
+
- For production deployments, prefer bearer token authentication
|
|
48
50
|
|
|
49
51
|
### 2. Import Styles
|
|
50
52
|
|
|
@@ -101,36 +103,74 @@ export default function SearchPage() {
|
|
|
101
103
|
|
|
102
104
|
## Authentication
|
|
103
105
|
|
|
104
|
-
The library
|
|
106
|
+
The library supports **two authentication methods**: bearer token and email/password login.
|
|
105
107
|
|
|
106
|
-
###
|
|
108
|
+
### Method 1: Bearer Token (Recommended for Production)
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
Use a pre-authenticated JWT bearer token. This is ideal when you have a backend that generates tokens for your users.
|
|
111
|
+
|
|
112
|
+
**Environment setup:**
|
|
113
|
+
```bash
|
|
114
|
+
VITE_INDX_URL=https://your-indx-server.com
|
|
115
|
+
VITE_INDX_TOKEN=your-jwt-bearer-token-here
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Usage:**
|
|
119
|
+
```typescript
|
|
120
|
+
<SearchProvider
|
|
121
|
+
url={import.meta.env.VITE_INDX_URL}
|
|
122
|
+
preAuthenticatedToken={import.meta.env.VITE_INDX_TOKEN}
|
|
123
|
+
dataset="products"
|
|
124
|
+
>
|
|
125
|
+
{/* Your search UI */}
|
|
126
|
+
</SearchProvider>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**When to use:**
|
|
130
|
+
- ✅ Production applications with backend authentication
|
|
131
|
+
- ✅ When you have existing token infrastructure
|
|
132
|
+
- ✅ For better security (tokens can have expiration, limited scope)
|
|
133
|
+
- ✅ When you want to avoid storing passwords client-side
|
|
134
|
+
|
|
135
|
+
### Method 2: Email/Password (Quick Start & Development)
|
|
136
|
+
|
|
137
|
+
Automatically logs in when the app initializes using email and password.
|
|
138
|
+
|
|
139
|
+
**Environment setup:**
|
|
140
|
+
```bash
|
|
141
|
+
VITE_INDX_URL=https://your-indx-server.com
|
|
142
|
+
VITE_INDX_EMAIL=your@email.com
|
|
143
|
+
VITE_INDX_PASSWORD=yourpassword
|
|
144
|
+
```
|
|
112
145
|
|
|
146
|
+
**Usage:**
|
|
113
147
|
```typescript
|
|
114
148
|
<SearchProvider
|
|
115
|
-
url=
|
|
116
|
-
email=
|
|
117
|
-
password=
|
|
149
|
+
url={import.meta.env.VITE_INDX_URL}
|
|
150
|
+
email={import.meta.env.VITE_INDX_EMAIL}
|
|
151
|
+
password={import.meta.env.VITE_INDX_PASSWORD}
|
|
118
152
|
dataset="products"
|
|
119
153
|
>
|
|
120
154
|
{/* Your search UI */}
|
|
121
155
|
</SearchProvider>
|
|
122
156
|
```
|
|
123
157
|
|
|
124
|
-
**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
158
|
+
**How it works:**
|
|
159
|
+
1. You provide email and password to `SearchProvider`
|
|
160
|
+
2. On mount, the library automatically calls the Login API endpoint
|
|
161
|
+
3. A fresh session token is obtained and used for all subsequent requests
|
|
162
|
+
4. No manual token management required
|
|
163
|
+
|
|
164
|
+
**When to use:**
|
|
165
|
+
- ✅ Quick prototyping and development
|
|
166
|
+
- ✅ Demo applications
|
|
167
|
+
- ✅ When you don't have token infrastructure yet
|
|
129
168
|
|
|
130
169
|
**Security Best Practices:**
|
|
131
|
-
- Store credentials in environment variables (`.env.local`)
|
|
132
|
-
- Never commit
|
|
170
|
+
- Store credentials/tokens in environment variables (`.env.local`)
|
|
171
|
+
- Never commit `.env.local` to version control
|
|
133
172
|
- Use secure HTTPS connections in production
|
|
173
|
+
- For production, prefer bearer token authentication
|
|
134
174
|
|
|
135
175
|
## Error Handling
|
|
136
176
|
|
|
@@ -139,8 +179,8 @@ The library includes comprehensive error handling with helpful console messages:
|
|
|
139
179
|
### Automatic Error Detection
|
|
140
180
|
|
|
141
181
|
The SearchProvider automatically validates:
|
|
142
|
-
- ✅ Authentication
|
|
143
|
-
- ✅ Login success and token retrieval
|
|
182
|
+
- ✅ Authentication (bearer token or email/password)
|
|
183
|
+
- ✅ Login success and token retrieval (when using email/password)
|
|
144
184
|
- ✅ Dataset existence and status
|
|
145
185
|
- ✅ Dataset readiness (indexing complete)
|
|
146
186
|
- ✅ Empty dataset warnings
|
|
@@ -316,8 +356,9 @@ export default function AdvancedSearch() {
|
|
|
316
356
|
| Prop | Type | Required | Default | Description |
|
|
317
357
|
|------|------|----------|---------|-------------|
|
|
318
358
|
| `url` | `string` | ✅ | - | INDX server URL |
|
|
319
|
-
| `
|
|
320
|
-
| `
|
|
359
|
+
| `preAuthenticatedToken` | `string` | ⚠️ | - | Bearer token for authentication (either this OR email/password) |
|
|
360
|
+
| `email` | `string` | ⚠️ | - | User email for authentication (either this OR token) |
|
|
361
|
+
| `password` | `string` | ⚠️ | - | User password for authentication (either this OR token) |
|
|
321
362
|
| `dataset` | `string` | ✅ | - | Dataset name |
|
|
322
363
|
| `allowEmptySearch` | `boolean` | ❌ | `false` | Show results without query |
|
|
323
364
|
| `enableFacets` | `boolean` | ❌ | `true` | Enable faceted search |
|
|
@@ -325,6 +366,7 @@ export default function AdvancedSearch() {
|
|
|
325
366
|
| `facetDebounceDelayMillis` | `number` | ❌ | `500` | Debounce delay for facet updates |
|
|
326
367
|
| `coverageDepth` | `number` | ❌ | `500` | Search depth for fuzzy matching |
|
|
327
368
|
| `removeDuplicates` | `boolean` | ❌ | `false` | Remove duplicate results |
|
|
369
|
+
| `enableDebugLogs` | `boolean` | ❌ | `false` | Enable detailed console logging |
|
|
328
370
|
|
|
329
371
|
### SearchInput Props
|
|
330
372
|
|
|
@@ -376,14 +418,16 @@ export default function AdvancedSearch() {
|
|
|
376
418
|
3. Ensure the INDX server URL is correct
|
|
377
419
|
4. Check browser console for detailed error messages
|
|
378
420
|
|
|
379
|
-
### "401 Unauthorized" errors
|
|
421
|
+
### "401 Unauthorized" errors
|
|
380
422
|
|
|
381
|
-
**Problem:**
|
|
423
|
+
**Problem:** Authentication failed or token is invalid
|
|
382
424
|
|
|
383
425
|
**Solutions:**
|
|
384
|
-
1.
|
|
385
|
-
2.
|
|
386
|
-
3. Check
|
|
426
|
+
1. **If using bearer token:** Verify the token is valid and not expired. Generate a new token if needed.
|
|
427
|
+
2. **If using email/password:** Refresh the page to get a new session token (automatic login)
|
|
428
|
+
3. Check that the token/credentials are correctly set in your environment variables
|
|
429
|
+
4. Verify the server is running and accessible
|
|
430
|
+
5. Check server logs for authentication issues
|
|
387
431
|
|
|
388
432
|
### "Failed to fetch" errors
|
|
389
433
|
|
|
@@ -391,7 +435,7 @@ export default function AdvancedSearch() {
|
|
|
391
435
|
|
|
392
436
|
**Solutions:**
|
|
393
437
|
1. Verify the server URL is correct
|
|
394
|
-
2. Check if the server is running (for local: `http://localhost:
|
|
438
|
+
2. Check if the server is running (for local: `http://localhost:5001`)
|
|
395
439
|
3. Ensure CORS is configured on the server
|
|
396
440
|
4. Check browser console for detailed error
|
|
397
441
|
|