@findlane/browser 0.14.0 → 0.15.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/dist/index.d.ts +50 -0
- package/dist/index.js +21 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -74,6 +74,9 @@ export type SearchResponse<T> = {
|
|
|
74
74
|
totalRelation?: "eq" | "gte";
|
|
75
75
|
hasMore?: boolean;
|
|
76
76
|
facets: Record<string, Record<string, number>>;
|
|
77
|
+
/** True when the facet counts are estimates: on an index of 100,000 records or more, a search with more
|
|
78
|
+
* than 2,000 matches counts its facets on a sample of them, scaled to the total. */
|
|
79
|
+
facetsEstimated?: boolean;
|
|
77
80
|
/** With `facetStats`: each field's smallest and largest value across the matches, without the field's
|
|
78
81
|
* own filter. A field no match has is left out. */
|
|
79
82
|
facetStats?: Record<string, {
|
|
@@ -170,6 +173,45 @@ export type RecommendationsResponse<T> = {
|
|
|
170
173
|
/** What `together`'s counts are of. */
|
|
171
174
|
togetherBasis?: "orders";
|
|
172
175
|
};
|
|
176
|
+
/** One of an index's lists, which its owner sets up in the dashboard: a row of products, such as Popular or
|
|
177
|
+
* New arrivals, from a filter and a sort, with products pinned first and others hidden; or a facet field's
|
|
178
|
+
* values with how many products each has, for a menu. `updatedAt` is when what the lists hold last changed. */
|
|
179
|
+
export type ProductList<T = Record<string, unknown>> = {
|
|
180
|
+
id: string;
|
|
181
|
+
title: string;
|
|
182
|
+
kind: "products";
|
|
183
|
+
hits: {
|
|
184
|
+
id: string;
|
|
185
|
+
record: T;
|
|
186
|
+
}[];
|
|
187
|
+
/** The list's filters and sort, for a "See all" link to the same products as a search. */
|
|
188
|
+
browse: {
|
|
189
|
+
sort: string;
|
|
190
|
+
filters: Record<string, unknown>;
|
|
191
|
+
};
|
|
192
|
+
updatedAt: string;
|
|
193
|
+
};
|
|
194
|
+
export type ValueList = {
|
|
195
|
+
id: string;
|
|
196
|
+
title: string;
|
|
197
|
+
kind: "values";
|
|
198
|
+
/** The facet field the values are of. */
|
|
199
|
+
field: string;
|
|
200
|
+
values: {
|
|
201
|
+
value: string;
|
|
202
|
+
count: number;
|
|
203
|
+
}[];
|
|
204
|
+
browse: {
|
|
205
|
+
filters: Record<string, unknown>;
|
|
206
|
+
};
|
|
207
|
+
updatedAt: string;
|
|
208
|
+
};
|
|
209
|
+
export type List<T = Record<string, unknown>> = ProductList<T> | ValueList;
|
|
210
|
+
export type ListOptions = {
|
|
211
|
+
/** At most this many products or values from each list (each list's own limit otherwise). */
|
|
212
|
+
limit?: number;
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
};
|
|
173
215
|
export declare class FindlaneError extends Error {
|
|
174
216
|
status: number;
|
|
175
217
|
constructor(status: number, message: string);
|
|
@@ -251,6 +293,7 @@ export declare class SearchBrowserClient {
|
|
|
251
293
|
private popular;
|
|
252
294
|
constructor(options: BrowserClientOptions);
|
|
253
295
|
private post;
|
|
296
|
+
private get;
|
|
254
297
|
search<T = Record<string, unknown>>(request: SearchRequest, options?: {
|
|
255
298
|
signal?: AbortSignal;
|
|
256
299
|
}): Promise<SearchResponse<T>>;
|
|
@@ -280,5 +323,12 @@ export declare class SearchBrowserClient {
|
|
|
280
323
|
recommendations<T = Record<string, unknown>>(objectID: string, request?: RecommendationsRequest, options?: {
|
|
281
324
|
signal?: AbortSignal;
|
|
282
325
|
}): Promise<RecommendationsResponse<T>>;
|
|
326
|
+
/** One of the index's lists, by its ID: a row of products, such as Popular, or a facet field's values for
|
|
327
|
+
* a menu. Built ahead and answered from a cache near the shopper, so it isn't a search and isn't counted.
|
|
328
|
+
* Throws a FindlaneError with status 404 when the index has no such list. */
|
|
329
|
+
list<T = Record<string, unknown>>(id: string, options?: ListOptions): Promise<List<T>>;
|
|
330
|
+
/** Several of the index's lists in one request (up to 10), in the order asked; IDs the index has no list
|
|
331
|
+
* for are left out. Without IDs, all of its lists, in the owner's order. Not counted as searches. */
|
|
332
|
+
lists<T = Record<string, unknown>>(ids?: string[], options?: ListOptions): Promise<List<T>[]>;
|
|
283
333
|
}
|
|
284
334
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -186,6 +186,15 @@ export class SearchBrowserClient {
|
|
|
186
186
|
throw new FindlaneError(response.status, data.error ?? `HTTP ${response.status}`);
|
|
187
187
|
return data;
|
|
188
188
|
}
|
|
189
|
+
// Lists are read with GET, which browsers send without a preflight and may keep for 30 seconds.
|
|
190
|
+
async get(path, params, signal) {
|
|
191
|
+
const query = new URLSearchParams(params).toString();
|
|
192
|
+
const response = await this.fetcher(`${this.url}/${path}${query ? `?${query}` : ""}`, { method: "GET", signal });
|
|
193
|
+
const data = await response.json();
|
|
194
|
+
if (!response.ok)
|
|
195
|
+
throw new FindlaneError(response.status, data.error ?? `HTTP ${response.status}`);
|
|
196
|
+
return data;
|
|
197
|
+
}
|
|
189
198
|
search(request, options = {}) {
|
|
190
199
|
return this.post("search", request, options.signal);
|
|
191
200
|
}
|
|
@@ -219,4 +228,16 @@ export class SearchBrowserClient {
|
|
|
219
228
|
recommendations(objectID, request = {}, options = {}) {
|
|
220
229
|
return this.post("recommendations", { objectID, ...request }, options.signal);
|
|
221
230
|
}
|
|
231
|
+
/** One of the index's lists, by its ID: a row of products, such as Popular, or a facet field's values for
|
|
232
|
+
* a menu. Built ahead and answered from a cache near the shopper, so it isn't a search and isn't counted.
|
|
233
|
+
* Throws a FindlaneError with status 404 when the index has no such list. */
|
|
234
|
+
list(id, options = {}) {
|
|
235
|
+
return this.get(`lists/${encodeURIComponent(id)}`, options.limit ? { limit: String(options.limit) } : {}, options.signal);
|
|
236
|
+
}
|
|
237
|
+
/** Several of the index's lists in one request (up to 10), in the order asked; IDs the index has no list
|
|
238
|
+
* for are left out. Without IDs, all of its lists, in the owner's order. Not counted as searches. */
|
|
239
|
+
async lists(ids, options = {}) {
|
|
240
|
+
return (await this.get("lists", { ...(ids ? { ids: ids.join(",") } : {}),
|
|
241
|
+
...(options.limit ? { limit: String(options.limit) } : {}) }, options.signal)).lists;
|
|
242
|
+
}
|
|
222
243
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@findlane/browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Findlane browser SDK: fast, typo-tolerant public search from the browser with an index's public ID, plus React hooks and components.",
|
|
5
5
|
"keywords": ["findlane", "search", "full-text search", "typo tolerance", "instant search", "ecommerce search", "browser", "react", "autocomplete"],
|
|
6
6
|
"license": "MIT",
|