@findlane/browser 0.28.1 → 0.30.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/images.d.ts +2 -0
- package/dist/images.js +2 -0
- package/dist/index.d.ts +51 -3
- package/dist/index.js +17 -6
- package/package.json +1 -1
package/dist/images.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare function imageHostsOf(header: string | null | undefined): Set<str
|
|
|
11
11
|
/** The header naming where the index's optimized images load from (0.28.0), such as https://images.findlane.dev.
|
|
12
12
|
* Without it they load from the API's own origin. */
|
|
13
13
|
export declare const imageOriginHeader = "x-findlane-image-origin";
|
|
14
|
+
/** Where the hosted API's optimized images load from, for a client told its image hosts before any answer (0.29.0). */
|
|
15
|
+
export declare const defaultImageOrigin = "https://images.findlane.dev";
|
|
14
16
|
/** The origin an `x-findlane-image-origin` header names, or null for none or one that isn't an http(s) origin. */
|
|
15
17
|
export declare function imageOriginOf(header: string | null | undefined): string | null;
|
|
16
18
|
/** Where an index's images loaded from on an earlier page, kept in this browser (localStorage), so the next page
|
package/dist/images.js
CHANGED
|
@@ -19,6 +19,8 @@ export function imageHostsOf(header) {
|
|
|
19
19
|
/** The header naming where the index's optimized images load from (0.28.0), such as https://images.findlane.dev.
|
|
20
20
|
* Without it they load from the API's own origin. */
|
|
21
21
|
export const imageOriginHeader = "x-findlane-image-origin";
|
|
22
|
+
/** Where the hosted API's optimized images load from, for a client told its image hosts before any answer (0.29.0). */
|
|
23
|
+
export const defaultImageOrigin = "https://images.findlane.dev";
|
|
22
24
|
/** The origin an `x-findlane-image-origin` header names, or null for none or one that isn't an http(s) origin. */
|
|
23
25
|
export function imageOriginOf(header) {
|
|
24
26
|
if (!header)
|
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,12 @@ export type SearchRequest = {
|
|
|
66
66
|
* unless it says, or `true` for that. Up to 5. Their results come back in `subindexes`; the search and its
|
|
67
67
|
* subindexes count as one search (0.22.0). */
|
|
68
68
|
subindexes?: Record<string, SubindexSearch | true>;
|
|
69
|
+
/** The facet values the query names, such as a category, a brand or a zip, to offer beside the results
|
|
70
|
+
* (0.30.0): `true` for every field of the index's facet matches setting, or `{ fields }` for some of them.
|
|
71
|
+
* They come back in `facetMatches`, in the same search. */
|
|
72
|
+
facetMatches?: boolean | {
|
|
73
|
+
fields?: string[];
|
|
74
|
+
};
|
|
69
75
|
};
|
|
70
76
|
/** A subindex's own search, in a search that asks for it. */
|
|
71
77
|
export type SubindexSearch = Omit<SearchRequest, "subindexes">;
|
|
@@ -165,6 +171,34 @@ export type SearchResponse<T> = {
|
|
|
165
171
|
id: string;
|
|
166
172
|
variant: "a" | "b";
|
|
167
173
|
};
|
|
174
|
+
/** With `facetMatches`: the facet values the query names, best first, at most 10 (0.30.0). Empty when it
|
|
175
|
+
* names none or the index has no facet matches setting. */
|
|
176
|
+
facetMatches?: FacetMatch[];
|
|
177
|
+
};
|
|
178
|
+
/** A facet value a query names (0.30.0), such as the category Prótein for "prót":
|
|
179
|
+
* - `values`: the field's values it stands for, as facet counts write them; several when values share a label,
|
|
180
|
+
* as a town's zips do.
|
|
181
|
+
* - `label`: its name, from the records beside the value, the setting, or the value itself.
|
|
182
|
+
* - `count`: its records that the search's filters allow.
|
|
183
|
+
* - `match`: how the query named it: `exact`, `prefix` (a word still being typed), `typo`, or `contains` (the
|
|
184
|
+
* whole query is a later word of the value).
|
|
185
|
+
* - `whole`: it took every word of the query. `typed`: where those words are in `q`, as UTF-16 offsets (end
|
|
186
|
+
* exclusive), so they can be set apart.
|
|
187
|
+
* - `link`: where the setting links it, with its values. `filter`: filters for it, to add to a search's `filters`.
|
|
188
|
+
* - `applied`: whether this search used the filter itself; false for now. */
|
|
189
|
+
export type FacetMatch = {
|
|
190
|
+
field: string;
|
|
191
|
+
values: string[];
|
|
192
|
+
label: string;
|
|
193
|
+
count: number;
|
|
194
|
+
match: "exact" | "prefix" | "typo" | "contains";
|
|
195
|
+
whole: boolean;
|
|
196
|
+
typed?: [number, number];
|
|
197
|
+
link?: string;
|
|
198
|
+
filter: Record<string, {
|
|
199
|
+
in: Array<string | number | boolean>;
|
|
200
|
+
}>;
|
|
201
|
+
applied: boolean;
|
|
168
202
|
};
|
|
169
203
|
/** One search of a multi-index search (multiSearch): its index's public ID, the client's own when left out. */
|
|
170
204
|
export type MultiSearchQuery = SearchRequest & {
|
|
@@ -405,6 +439,14 @@ export type BrowserClientOptions = {
|
|
|
405
439
|
* allowed sites. Or a function that fetches one: called for the first search, again shortly before the key
|
|
406
440
|
* expires, and once more if the API says it has. Make a new client when the person changes. */
|
|
407
441
|
signedKey?: string | (() => string | Promise<string>);
|
|
442
|
+
/** Optimized images (0.29.0): the hosts your records' images are on, when you know the index has optimized images on
|
|
443
|
+
* for them, such as ["cdn.shop.example"]. `imageUrl` then resizes them from the first render, before an answer has
|
|
444
|
+
* said which hosts the index allows. What an earlier answer said in this browser comes first, and from the first
|
|
445
|
+
* answer on the answers decide; a host the index doesn't allow loads as it is after one refused request. */
|
|
446
|
+
imageHosts?: string[];
|
|
447
|
+
/** Where those images load from until an answer names it (0.29.0): https://images.findlane.dev with the hosted API,
|
|
448
|
+
* else the API's own address. */
|
|
449
|
+
imageOrigin?: string;
|
|
408
450
|
};
|
|
409
451
|
export declare class SearchBrowserClient {
|
|
410
452
|
private readonly url;
|
|
@@ -429,6 +471,8 @@ export declare class SearchBrowserClient {
|
|
|
429
471
|
private knownImages;
|
|
430
472
|
/** Whether an answer has said, so what was remembered is no longer used. */
|
|
431
473
|
private answered;
|
|
474
|
+
/** The image hosts the page said it knows (options.imageHosts), and where they load from, until an answer says. */
|
|
475
|
+
private readonly givenImages;
|
|
432
476
|
constructor(options: BrowserClientOptions);
|
|
433
477
|
/** The signed key searches send: the one given, or the function's, asked for again 30 seconds before it
|
|
434
478
|
* expires, or at once when `fresh`. */
|
|
@@ -439,14 +483,18 @@ export declare class SearchBrowserClient {
|
|
|
439
483
|
* say nothing. Both are kept for later pages (0.28.1), and the connection opened now, before the results' images ask. */
|
|
440
484
|
private noteImages;
|
|
441
485
|
private remembered;
|
|
442
|
-
/**
|
|
443
|
-
*
|
|
486
|
+
/** What's known of the index's images before this page's first answer: what an earlier answer said in this browser,
|
|
487
|
+
* else what the page said it knows (options.imageHosts). */
|
|
488
|
+
private beforeAnswer;
|
|
489
|
+
/** Opens the connection to where the index's images loaded from on an earlier page (or will, as the page said), with
|
|
490
|
+
* the first request or when a search box gets focus, so the results' first image doesn't wait for it. */
|
|
444
491
|
private warmImages;
|
|
445
492
|
/** Optimized images (0.27.0): a record image's address, resized to `width` pixels (rounded up to one of
|
|
446
493
|
* `imageWidths`) and sent as WebP from the address the API names (images.findlane.dev since 0.28.0; the API's own
|
|
447
494
|
* before), when the index has optimized images on and the image is on a host it allows; otherwise `src` as it is.
|
|
448
495
|
* Known from the first answer on; since 0.28.1, before it too from what an earlier page's answers said in this
|
|
449
|
-
* browser, so results a page kept (a reload, Back) are resized
|
|
496
|
+
* browser, so results a page kept (a reload, Back) are resized; since 0.29.0 from `imageHosts` when the page says it
|
|
497
|
+
* knows them, so a first visit's first render is resized too. Load them with `crossorigin="anonymous"`, which uses
|
|
450
498
|
* the connection opened for them ahead of need. React's `Image` does all of this. */
|
|
451
499
|
imageUrl(src: string, width: number): string;
|
|
452
500
|
/** Opens the connection to the API before the first search needs it, as a preconnect hint in the page
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { imageHostsHeader, imageHostsOf, imageOriginHeader, imageOriginOf, optimizedImageUrl, preconnect, rememberedImages, rememberImages } from "./images.js";
|
|
1
|
+
import { defaultImageOrigin, imageHostsHeader, imageHostsOf, imageOriginHeader, imageOriginOf, optimizedImageUrl, preconnect, rememberedImages, rememberImages } from "./images.js";
|
|
2
2
|
export { imageWidth, imageWidths } from "./images.js";
|
|
3
3
|
export { placeholderCss, placeholderUrl, revealCss } from "./placeholder.js";
|
|
4
4
|
/** A query suggestion's text in parts: what was typed (`typed: true`) and the rest. */
|
|
@@ -295,6 +295,8 @@ export class SearchBrowserClient {
|
|
|
295
295
|
knownImages;
|
|
296
296
|
/** Whether an answer has said, so what was remembered is no longer used. */
|
|
297
297
|
answered = false;
|
|
298
|
+
/** The image hosts the page said it knows (options.imageHosts), and where they load from, until an answer says. */
|
|
299
|
+
givenImages;
|
|
298
300
|
constructor(options) {
|
|
299
301
|
if (!/^pub_[a-f0-9]{32}$/.test(options.publicId))
|
|
300
302
|
throw new Error("A valid public index ID (pub_…) is required");
|
|
@@ -306,6 +308,9 @@ export class SearchBrowserClient {
|
|
|
306
308
|
this.test = testLabel(options.publicId);
|
|
307
309
|
this.events = eventSender(options.eventsUrl ?? `${this.url}/events`, options.fetch, options.events ?? true, options.visitorIds ? deviceIds(options.publicId) : null, this.test);
|
|
308
310
|
this.recentSearches = new RecentSearches(options.publicId);
|
|
311
|
+
const given = imageHostsOf(options.imageHosts?.join(","));
|
|
312
|
+
this.givenImages = given.size ? { hosts: given,
|
|
313
|
+
origin: imageOriginOf(options.imageOrigin) ?? (this.origin === new URL(defaultBaseUrl).origin ? defaultImageOrigin : null) } : null;
|
|
309
314
|
}
|
|
310
315
|
/** The signed key searches send: the one given, or the function's, asked for again 30 seconds before it
|
|
311
316
|
* expires, or at once when `fresh`. */
|
|
@@ -378,10 +383,15 @@ export class SearchBrowserClient {
|
|
|
378
383
|
this.knownImages = rememberedImages(this.publicId);
|
|
379
384
|
return this.knownImages;
|
|
380
385
|
}
|
|
381
|
-
/**
|
|
382
|
-
*
|
|
386
|
+
/** What's known of the index's images before this page's first answer: what an earlier answer said in this browser,
|
|
387
|
+
* else what the page said it knows (options.imageHosts). */
|
|
388
|
+
beforeAnswer() {
|
|
389
|
+
return this.remembered() ?? this.givenImages;
|
|
390
|
+
}
|
|
391
|
+
/** Opens the connection to where the index's images loaded from on an earlier page (or will, as the page said), with
|
|
392
|
+
* the first request or when a search box gets focus, so the results' first image doesn't wait for it. */
|
|
383
393
|
warmImages() {
|
|
384
|
-
const origin = this.
|
|
394
|
+
const origin = this.beforeAnswer()?.origin;
|
|
385
395
|
if (origin)
|
|
386
396
|
preconnect(origin);
|
|
387
397
|
}
|
|
@@ -389,10 +399,11 @@ export class SearchBrowserClient {
|
|
|
389
399
|
* `imageWidths`) and sent as WebP from the address the API names (images.findlane.dev since 0.28.0; the API's own
|
|
390
400
|
* before), when the index has optimized images on and the image is on a host it allows; otherwise `src` as it is.
|
|
391
401
|
* Known from the first answer on; since 0.28.1, before it too from what an earlier page's answers said in this
|
|
392
|
-
* browser, so results a page kept (a reload, Back) are resized
|
|
402
|
+
* browser, so results a page kept (a reload, Back) are resized; since 0.29.0 from `imageHosts` when the page says it
|
|
403
|
+
* knows them, so a first visit's first render is resized too. Load them with `crossorigin="anonymous"`, which uses
|
|
393
404
|
* the connection opened for them ahead of need. React's `Image` does all of this. */
|
|
394
405
|
imageUrl(src, width) {
|
|
395
|
-
const known = this.answered ? null : this.
|
|
406
|
+
const known = this.answered ? null : this.beforeAnswer();
|
|
396
407
|
return optimizedImageUrl((known ? known.origin : this.imageOrigin) ?? this.origin, this.publicId, known?.hosts ?? this.imageHosts, src, width) ?? src;
|
|
397
408
|
}
|
|
398
409
|
/** Opens the connection to the API before the first search needs it, as a preconnect hint in the page
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@findlane/browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.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",
|