@findlane/server 0.16.0 → 0.18.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.cjs CHANGED
@@ -265,6 +265,19 @@ class SearchServerClient {
265
265
  const { signal, visitor } = requestOptions(requestOptionsOrSignal);
266
266
  return request("/recommendations", "POST", { objectID, ...options }, signal, visitorHeaders(visitor));
267
267
  },
268
+ lists: {
269
+ get: (id, options = {}) => request(`/lists/${encodeURIComponent(id)}${options.limit ? `?limit=${options.limit}` : ""}`, "GET", undefined, options.signal),
270
+ getMany: async (ids, options = {}) => {
271
+ const query = new URLSearchParams({ ...ids ? { ids: ids.join(",") } : {}, ...options.limit ? { limit: String(options.limit) } : {} }).toString();
272
+ return (await request(`/lists${query ? `?${query}` : ""}`, "GET", undefined, options.signal)).lists;
273
+ },
274
+ settings: (signal) => request("/lists/settings", "GET", undefined, signal),
275
+ save: (id, list, signal) => request(`/lists/${encodeURIComponent(id)}`, "PUT", list, signal),
276
+ delete: (id, signal) => request(`/lists/${encodeURIComponent(id)}`, "DELETE", undefined, signal),
277
+ order: (ids, signal) => request("/lists/order", "PUT", { lists: ids }, signal),
278
+ refresh: (signal) => request("/lists/refresh", "POST", undefined, signal),
279
+ preview: (list, signal) => request("/lists/preview", "POST", list, signal)
280
+ },
268
281
  events: {
269
282
  send: (events, options) => sendEvents(events, options === undefined ? {} : ("aborted" in options) ? { signal: options } : options),
270
283
  importOrders: (orders, signal) => sendEvents(async function* () {
package/dist/index.d.cts CHANGED
@@ -66,6 +66,14 @@ export type IndexSettings = {
66
66
  /** Query suggestions: whole searches offered as shoppers type, and popular searches for an empty box,
67
67
  * from what shoppers search and the catalog. On by default. Changes apply within a few minutes. */
68
68
  querySuggestions?: QuerySuggestionSettings;
69
+ /** Related results (0.18.0): when a search's words find nothing, the products closest to it in meaning, in
70
+ * the response's `related`. Paid plans, indexes of up to 200,000 records. Turned on, every record is
71
+ * embedded within minutes, and `minScore`, the floor, is calibrated from the index's own searches that
72
+ * found nothing; none show until it is. Off by default. */
73
+ relatedResults?: {
74
+ enabled?: boolean;
75
+ minScore?: number | null;
76
+ };
69
77
  normalizationProfile?: "default-v2" | "default-v1" | "icelandic-ascii-v1";
70
78
  /** An object field of lat and lng numbers, such as `_geoloc`, that `near` and `within` search; null for none. */
71
79
  locationField?: string | null;
@@ -335,6 +343,8 @@ export type SearchRequest = {
335
343
  /** Only records inside a box, in degrees, such as a map's visible area. West greater than east crosses the
336
344
  * antimeridian. */
337
345
  within?: GeoBox;
346
+ /** With the index's `relatedResults` on: false asks for no related results (0.18.0). */
347
+ related?: boolean;
338
348
  };
339
349
  /** A point in degrees: lat from -90 to 90, lng from -180 to 180. */
340
350
  export type GeoPoint = {
@@ -421,6 +431,9 @@ export type SearchResponse<T> = {
421
431
  totalRelation?: "eq" | "gte";
422
432
  hasMore?: boolean;
423
433
  facets: Record<string, Record<string, number>>;
434
+ /** True when the facet counts are estimates: on an index of 100,000 records or more, a search with more
435
+ * than 2,000 matches counts its facets on a sample of them, scaled to the total. */
436
+ facetsEstimated?: boolean;
424
437
  /** With `facetStats`: each field's smallest and largest value across the matches, without the field's
425
438
  * own filter. A field no match has is left out. */
426
439
  facetStats?: Record<string, {
@@ -438,8 +451,88 @@ export type SearchResponse<T> = {
438
451
  appliedRules?: AppliedRule[];
439
452
  /** When a rule replaced words: the query that was searched. */
440
453
  rewrittenQuery?: string;
454
+ /** With the index's `relatedResults` on (0.18.0): when the query's words found nothing (`hits` empty,
455
+ * `total` 0), the products closest to it in meaning, best first, with their similarity as `score`. Show
456
+ * them under a heading of their own, such as "No exact matches. Related products". */
457
+ related?: {
458
+ hits: Array<{
459
+ id: string;
460
+ score: number | null;
461
+ record: T;
462
+ }>;
463
+ total: number;
464
+ };
441
465
  };
442
466
  /** How a product's recommendations are served (the recommendations add-on). */
467
+ /** One of an index's lists (docs: Lists): a row of products, such as Popular or New arrivals, from a filter and
468
+ * a sort, with products pinned first and others hidden; or a facet field's values with how many products each
469
+ * has, for a menu. `updatedAt` is when what the index's lists hold last changed. */
470
+ export type ProductList<T = JsonRecord> = {
471
+ id: string;
472
+ title: string;
473
+ kind: "products";
474
+ hits: {
475
+ id: string;
476
+ record: T;
477
+ }[];
478
+ /** The list's filters and sort, for a "See all" link to the same products as a search. */
479
+ browse: {
480
+ sort: string;
481
+ filters: Record<string, unknown>;
482
+ };
483
+ updatedAt: string;
484
+ };
485
+ export type ValueList = {
486
+ id: string;
487
+ title: string;
488
+ kind: "values";
489
+ field: string;
490
+ values: {
491
+ value: string;
492
+ count: number;
493
+ }[];
494
+ browse: {
495
+ filters: Record<string, unknown>;
496
+ };
497
+ updatedAt: string;
498
+ };
499
+ export type List<T = JsonRecord> = ProductList<T> | ValueList;
500
+ /** A list as it's set up. Products (`source` "sort", the default): `sort` is one of the index's sorts (its
501
+ * default without one), `limit` 1 to 50 (10 by default), `pinned` and `hidden` objectIDs, and
502
+ * `attributesToRetrieve` the fields each product has. Values (`source` "values"): `field` is a facet field,
503
+ * `sort` "count" (the default) or "name", `limit` 1 to 1,000, and `pinned` and `hidden` values. `filters` are
504
+ * a search's, for either. */
505
+ export type ListDefinition = {
506
+ title?: string;
507
+ source?: "sort" | "values";
508
+ sort?: string;
509
+ filters?: SearchRequest["filters"];
510
+ limit?: number;
511
+ pinned?: string[];
512
+ hidden?: string[];
513
+ attributesToRetrieve?: string[];
514
+ field?: string;
515
+ };
516
+ /** An index's lists as set up, each with how many products or values it held at its last build and why that
517
+ * failed, if it did; the last build; and how many lists the plan allows per index. */
518
+ export type ListSettings = {
519
+ lists: Array<ListDefinition & {
520
+ id: string;
521
+ title: string;
522
+ source: "sort" | "values";
523
+ updatedAt: string;
524
+ items: number | null;
525
+ error: string | null;
526
+ }>;
527
+ build: {
528
+ version: number;
529
+ builtAt: string | null;
530
+ buildMs: number | null;
531
+ updatedAt: string | null;
532
+ refreshAvailableAt: string | null;
533
+ } | null;
534
+ cap: number;
535
+ };
443
536
  export type RecommendationsRequest = {
444
537
  /** Up to this many products in each list, 1 to 20; 8 by default. */
445
538
  limit?: number;
@@ -554,7 +647,7 @@ export type ServerEvent = {
554
647
  objectID: string;
555
648
  position?: number;
556
649
  query?: string;
557
- list?: "goesWith" | "similar" | "together";
650
+ list?: "goesWith" | "similar" | "together" | "related";
558
651
  from?: string;
559
652
  timestamp?: number;
560
653
  } | {
@@ -649,13 +742,15 @@ export type SearchesReport = AnalyticsReport & {
649
742
  noResults: number;
650
743
  }[];
651
744
  };
652
- /** A top query: its clicks on results and their average place (from 1), or null when clicks aren't available. */
745
+ /** A top query: its clicks on results, or null when clicks aren't available; their average place, and the
746
+ * middle click's, which a few clicks far down don't pull up (from 1, or null without clicks that say their place). */
653
747
  export type TopQuery = {
654
748
  query: string;
655
749
  searches: number;
656
750
  noResults: number;
657
751
  clicks: number | null;
658
752
  averagePosition: number | null;
753
+ middlePosition: number | null;
659
754
  };
660
755
  export type QueryCount = {
661
756
  query: string;
@@ -803,6 +898,36 @@ export declare class SearchServerClient {
803
898
  /** A product's recommendations (the recommendations add-on): products that go with it, and similar products.
804
899
  * The API key needs the `search` scope; not counted as a search. */
805
900
  recommendations: <R = T>(objectID: string, options?: RecommendationsRequest, requestOptionsOrSignal?: AbortSignal | RequestOptions) => Promise<RecommendationsResponse<R>>;
901
+ /** The index's lists: rows of products, such as Popular, and facet fields' values for menus, built ahead
902
+ * and served from a cache, so reading them isn't counted as searches. Reading needs the `search` scope;
903
+ * setting them up needs `write`. */
904
+ lists: {
905
+ /** One list by its ID; throws a FindlaneError with status 404 when there's none. `limit` shows fewer. */
906
+ get: <R = T>(id: string, options?: {
907
+ limit?: number;
908
+ signal?: AbortSignal;
909
+ }) => Promise<List<R>>;
910
+ /** Several lists (up to 10) in the order asked, leaving out IDs without a list; without IDs, all of them. */
911
+ getMany: <R = T>(ids?: string[], options?: {
912
+ limit?: number;
913
+ signal?: AbortSignal;
914
+ }) => Promise<List<R>[]>;
915
+ /** How the index's lists are set up, and their last build. */
916
+ settings: (signal?: AbortSignal) => Promise<ListSettings>;
917
+ /** Creates or changes a list and builds it; one whose filters, sort or field don't work on the index is
918
+ * refused with why (400), and a new list past the plan's lists per index too (402). */
919
+ save: (id: string, list: ListDefinition, signal?: AbortSignal) => Promise<ListSettings>;
920
+ delete: (id: string, signal?: AbortSignal) => Promise<ListSettings>;
921
+ /** Puts the lists in this order: every list's ID once. */
922
+ order: (ids: string[], signal?: AbortSignal) => Promise<ListSettings>;
923
+ /** Builds the lists again now, rather than within the minute they take to follow the index; once a minute. */
924
+ refresh: (signal?: AbortSignal) => Promise<ListSettings>;
925
+ /** What a list would hold, built without saving it. */
926
+ preview: <R = T>(list: ListDefinition, signal?: AbortSignal) => Promise<{
927
+ list: List<R>;
928
+ tookMs: number;
929
+ }>;
930
+ };
806
931
  /** Events for the index's Events page and Bought together; the API key needs the `events` or `write`
807
932
  * scope. Orders count once each, however often they're sent. */
808
933
  events: {
package/dist/index.d.ts CHANGED
@@ -66,6 +66,14 @@ export type IndexSettings = {
66
66
  /** Query suggestions: whole searches offered as shoppers type, and popular searches for an empty box,
67
67
  * from what shoppers search and the catalog. On by default. Changes apply within a few minutes. */
68
68
  querySuggestions?: QuerySuggestionSettings;
69
+ /** Related results (0.18.0): when a search's words find nothing, the products closest to it in meaning, in
70
+ * the response's `related`. Paid plans, indexes of up to 200,000 records. Turned on, every record is
71
+ * embedded within minutes, and `minScore`, the floor, is calibrated from the index's own searches that
72
+ * found nothing; none show until it is. Off by default. */
73
+ relatedResults?: {
74
+ enabled?: boolean;
75
+ minScore?: number | null;
76
+ };
69
77
  normalizationProfile?: "default-v2" | "default-v1" | "icelandic-ascii-v1";
70
78
  /** An object field of lat and lng numbers, such as `_geoloc`, that `near` and `within` search; null for none. */
71
79
  locationField?: string | null;
@@ -335,6 +343,8 @@ export type SearchRequest = {
335
343
  /** Only records inside a box, in degrees, such as a map's visible area. West greater than east crosses the
336
344
  * antimeridian. */
337
345
  within?: GeoBox;
346
+ /** With the index's `relatedResults` on: false asks for no related results (0.18.0). */
347
+ related?: boolean;
338
348
  };
339
349
  /** A point in degrees: lat from -90 to 90, lng from -180 to 180. */
340
350
  export type GeoPoint = {
@@ -421,6 +431,9 @@ export type SearchResponse<T> = {
421
431
  totalRelation?: "eq" | "gte";
422
432
  hasMore?: boolean;
423
433
  facets: Record<string, Record<string, number>>;
434
+ /** True when the facet counts are estimates: on an index of 100,000 records or more, a search with more
435
+ * than 2,000 matches counts its facets on a sample of them, scaled to the total. */
436
+ facetsEstimated?: boolean;
424
437
  /** With `facetStats`: each field's smallest and largest value across the matches, without the field's
425
438
  * own filter. A field no match has is left out. */
426
439
  facetStats?: Record<string, {
@@ -438,8 +451,88 @@ export type SearchResponse<T> = {
438
451
  appliedRules?: AppliedRule[];
439
452
  /** When a rule replaced words: the query that was searched. */
440
453
  rewrittenQuery?: string;
454
+ /** With the index's `relatedResults` on (0.18.0): when the query's words found nothing (`hits` empty,
455
+ * `total` 0), the products closest to it in meaning, best first, with their similarity as `score`. Show
456
+ * them under a heading of their own, such as "No exact matches. Related products". */
457
+ related?: {
458
+ hits: Array<{
459
+ id: string;
460
+ score: number | null;
461
+ record: T;
462
+ }>;
463
+ total: number;
464
+ };
441
465
  };
442
466
  /** How a product's recommendations are served (the recommendations add-on). */
467
+ /** One of an index's lists (docs: Lists): a row of products, such as Popular or New arrivals, from a filter and
468
+ * a sort, with products pinned first and others hidden; or a facet field's values with how many products each
469
+ * has, for a menu. `updatedAt` is when what the index's lists hold last changed. */
470
+ export type ProductList<T = JsonRecord> = {
471
+ id: string;
472
+ title: string;
473
+ kind: "products";
474
+ hits: {
475
+ id: string;
476
+ record: T;
477
+ }[];
478
+ /** The list's filters and sort, for a "See all" link to the same products as a search. */
479
+ browse: {
480
+ sort: string;
481
+ filters: Record<string, unknown>;
482
+ };
483
+ updatedAt: string;
484
+ };
485
+ export type ValueList = {
486
+ id: string;
487
+ title: string;
488
+ kind: "values";
489
+ field: string;
490
+ values: {
491
+ value: string;
492
+ count: number;
493
+ }[];
494
+ browse: {
495
+ filters: Record<string, unknown>;
496
+ };
497
+ updatedAt: string;
498
+ };
499
+ export type List<T = JsonRecord> = ProductList<T> | ValueList;
500
+ /** A list as it's set up. Products (`source` "sort", the default): `sort` is one of the index's sorts (its
501
+ * default without one), `limit` 1 to 50 (10 by default), `pinned` and `hidden` objectIDs, and
502
+ * `attributesToRetrieve` the fields each product has. Values (`source` "values"): `field` is a facet field,
503
+ * `sort` "count" (the default) or "name", `limit` 1 to 1,000, and `pinned` and `hidden` values. `filters` are
504
+ * a search's, for either. */
505
+ export type ListDefinition = {
506
+ title?: string;
507
+ source?: "sort" | "values";
508
+ sort?: string;
509
+ filters?: SearchRequest["filters"];
510
+ limit?: number;
511
+ pinned?: string[];
512
+ hidden?: string[];
513
+ attributesToRetrieve?: string[];
514
+ field?: string;
515
+ };
516
+ /** An index's lists as set up, each with how many products or values it held at its last build and why that
517
+ * failed, if it did; the last build; and how many lists the plan allows per index. */
518
+ export type ListSettings = {
519
+ lists: Array<ListDefinition & {
520
+ id: string;
521
+ title: string;
522
+ source: "sort" | "values";
523
+ updatedAt: string;
524
+ items: number | null;
525
+ error: string | null;
526
+ }>;
527
+ build: {
528
+ version: number;
529
+ builtAt: string | null;
530
+ buildMs: number | null;
531
+ updatedAt: string | null;
532
+ refreshAvailableAt: string | null;
533
+ } | null;
534
+ cap: number;
535
+ };
443
536
  export type RecommendationsRequest = {
444
537
  /** Up to this many products in each list, 1 to 20; 8 by default. */
445
538
  limit?: number;
@@ -554,7 +647,7 @@ export type ServerEvent = {
554
647
  objectID: string;
555
648
  position?: number;
556
649
  query?: string;
557
- list?: "goesWith" | "similar" | "together";
650
+ list?: "goesWith" | "similar" | "together" | "related";
558
651
  from?: string;
559
652
  timestamp?: number;
560
653
  } | {
@@ -649,13 +742,15 @@ export type SearchesReport = AnalyticsReport & {
649
742
  noResults: number;
650
743
  }[];
651
744
  };
652
- /** A top query: its clicks on results and their average place (from 1), or null when clicks aren't available. */
745
+ /** A top query: its clicks on results, or null when clicks aren't available; their average place, and the
746
+ * middle click's, which a few clicks far down don't pull up (from 1, or null without clicks that say their place). */
653
747
  export type TopQuery = {
654
748
  query: string;
655
749
  searches: number;
656
750
  noResults: number;
657
751
  clicks: number | null;
658
752
  averagePosition: number | null;
753
+ middlePosition: number | null;
659
754
  };
660
755
  export type QueryCount = {
661
756
  query: string;
@@ -803,6 +898,36 @@ export declare class SearchServerClient {
803
898
  /** A product's recommendations (the recommendations add-on): products that go with it, and similar products.
804
899
  * The API key needs the `search` scope; not counted as a search. */
805
900
  recommendations: <R = T>(objectID: string, options?: RecommendationsRequest, requestOptionsOrSignal?: AbortSignal | RequestOptions) => Promise<RecommendationsResponse<R>>;
901
+ /** The index's lists: rows of products, such as Popular, and facet fields' values for menus, built ahead
902
+ * and served from a cache, so reading them isn't counted as searches. Reading needs the `search` scope;
903
+ * setting them up needs `write`. */
904
+ lists: {
905
+ /** One list by its ID; throws a FindlaneError with status 404 when there's none. `limit` shows fewer. */
906
+ get: <R = T>(id: string, options?: {
907
+ limit?: number;
908
+ signal?: AbortSignal;
909
+ }) => Promise<List<R>>;
910
+ /** Several lists (up to 10) in the order asked, leaving out IDs without a list; without IDs, all of them. */
911
+ getMany: <R = T>(ids?: string[], options?: {
912
+ limit?: number;
913
+ signal?: AbortSignal;
914
+ }) => Promise<List<R>[]>;
915
+ /** How the index's lists are set up, and their last build. */
916
+ settings: (signal?: AbortSignal) => Promise<ListSettings>;
917
+ /** Creates or changes a list and builds it; one whose filters, sort or field don't work on the index is
918
+ * refused with why (400), and a new list past the plan's lists per index too (402). */
919
+ save: (id: string, list: ListDefinition, signal?: AbortSignal) => Promise<ListSettings>;
920
+ delete: (id: string, signal?: AbortSignal) => Promise<ListSettings>;
921
+ /** Puts the lists in this order: every list's ID once. */
922
+ order: (ids: string[], signal?: AbortSignal) => Promise<ListSettings>;
923
+ /** Builds the lists again now, rather than within the minute they take to follow the index; once a minute. */
924
+ refresh: (signal?: AbortSignal) => Promise<ListSettings>;
925
+ /** What a list would hold, built without saving it. */
926
+ preview: <R = T>(list: ListDefinition, signal?: AbortSignal) => Promise<{
927
+ list: List<R>;
928
+ tookMs: number;
929
+ }>;
930
+ };
806
931
  /** Events for the index's Events page and Bought together; the API key needs the `events` or `write`
807
932
  * scope. Orders count once each, however often they're sent. */
808
933
  events: {
package/dist/index.js CHANGED
@@ -219,6 +219,19 @@ class SearchServerClient {
219
219
  const { signal, visitor } = requestOptions(requestOptionsOrSignal);
220
220
  return request("/recommendations", "POST", { objectID, ...options }, signal, visitorHeaders(visitor));
221
221
  },
222
+ lists: {
223
+ get: (id, options = {}) => request(`/lists/${encodeURIComponent(id)}${options.limit ? `?limit=${options.limit}` : ""}`, "GET", undefined, options.signal),
224
+ getMany: async (ids, options = {}) => {
225
+ const query = new URLSearchParams({ ...ids ? { ids: ids.join(",") } : {}, ...options.limit ? { limit: String(options.limit) } : {} }).toString();
226
+ return (await request(`/lists${query ? `?${query}` : ""}`, "GET", undefined, options.signal)).lists;
227
+ },
228
+ settings: (signal) => request("/lists/settings", "GET", undefined, signal),
229
+ save: (id, list, signal) => request(`/lists/${encodeURIComponent(id)}`, "PUT", list, signal),
230
+ delete: (id, signal) => request(`/lists/${encodeURIComponent(id)}`, "DELETE", undefined, signal),
231
+ order: (ids, signal) => request("/lists/order", "PUT", { lists: ids }, signal),
232
+ refresh: (signal) => request("/lists/refresh", "POST", undefined, signal),
233
+ preview: (list, signal) => request("/lists/preview", "POST", list, signal)
234
+ },
222
235
  events: {
223
236
  send: (events, options) => sendEvents(events, options === undefined ? {} : ("aborted" in options) ? { signal: options } : options),
224
237
  importOrders: (orders, signal) => sendEvents(async function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@findlane/server",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "Findlane server SDK: upload catalogs, manage index settings, and search with a secret workspace API key.",
5
5
  "keywords": ["findlane", "search", "full-text search", "typo tolerance", "ecommerce search", "search api", "sdk"],
6
6
  "license": "MIT",