@findlane/browser 0.28.1 → 0.29.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 +17 -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
|
@@ -405,6 +405,14 @@ export type BrowserClientOptions = {
|
|
|
405
405
|
* allowed sites. Or a function that fetches one: called for the first search, again shortly before the key
|
|
406
406
|
* expires, and once more if the API says it has. Make a new client when the person changes. */
|
|
407
407
|
signedKey?: string | (() => string | Promise<string>);
|
|
408
|
+
/** Optimized images (0.29.0): the hosts your records' images are on, when you know the index has optimized images on
|
|
409
|
+
* for them, such as ["cdn.shop.example"]. `imageUrl` then resizes them from the first render, before an answer has
|
|
410
|
+
* said which hosts the index allows. What an earlier answer said in this browser comes first, and from the first
|
|
411
|
+
* answer on the answers decide; a host the index doesn't allow loads as it is after one refused request. */
|
|
412
|
+
imageHosts?: string[];
|
|
413
|
+
/** Where those images load from until an answer names it (0.29.0): https://images.findlane.dev with the hosted API,
|
|
414
|
+
* else the API's own address. */
|
|
415
|
+
imageOrigin?: string;
|
|
408
416
|
};
|
|
409
417
|
export declare class SearchBrowserClient {
|
|
410
418
|
private readonly url;
|
|
@@ -429,6 +437,8 @@ export declare class SearchBrowserClient {
|
|
|
429
437
|
private knownImages;
|
|
430
438
|
/** Whether an answer has said, so what was remembered is no longer used. */
|
|
431
439
|
private answered;
|
|
440
|
+
/** The image hosts the page said it knows (options.imageHosts), and where they load from, until an answer says. */
|
|
441
|
+
private readonly givenImages;
|
|
432
442
|
constructor(options: BrowserClientOptions);
|
|
433
443
|
/** The signed key searches send: the one given, or the function's, asked for again 30 seconds before it
|
|
434
444
|
* expires, or at once when `fresh`. */
|
|
@@ -439,14 +449,18 @@ export declare class SearchBrowserClient {
|
|
|
439
449
|
* say nothing. Both are kept for later pages (0.28.1), and the connection opened now, before the results' images ask. */
|
|
440
450
|
private noteImages;
|
|
441
451
|
private remembered;
|
|
442
|
-
/**
|
|
443
|
-
*
|
|
452
|
+
/** What's known of the index's images before this page's first answer: what an earlier answer said in this browser,
|
|
453
|
+
* else what the page said it knows (options.imageHosts). */
|
|
454
|
+
private beforeAnswer;
|
|
455
|
+
/** Opens the connection to where the index's images loaded from on an earlier page (or will, as the page said), with
|
|
456
|
+
* the first request or when a search box gets focus, so the results' first image doesn't wait for it. */
|
|
444
457
|
private warmImages;
|
|
445
458
|
/** Optimized images (0.27.0): a record image's address, resized to `width` pixels (rounded up to one of
|
|
446
459
|
* `imageWidths`) and sent as WebP from the address the API names (images.findlane.dev since 0.28.0; the API's own
|
|
447
460
|
* before), when the index has optimized images on and the image is on a host it allows; otherwise `src` as it is.
|
|
448
461
|
* 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
|
|
462
|
+
* browser, so results a page kept (a reload, Back) are resized; since 0.29.0 from `imageHosts` when the page says it
|
|
463
|
+
* knows them, so a first visit's first render is resized too. Load them with `crossorigin="anonymous"`, which uses
|
|
450
464
|
* the connection opened for them ahead of need. React's `Image` does all of this. */
|
|
451
465
|
imageUrl(src: string, width: number): string;
|
|
452
466
|
/** 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.29.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",
|