@revenexx/cover 0.2.13 → 0.2.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Cover \u2014 revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -4,6 +4,18 @@ import type { SearchFacet } from "../../../app/interfaces/search-facets";
4
4
  import { loadLiveAttributeMeta } from "../../utils/liveCatalog";
5
5
  import { FACET_FIELDS, PRODUCTS_COLLECTION } from "../../utils/productsSchema";
6
6
 
7
+ /**
8
+ * Typesense's response when a facet_by names a field that doesn't exist
9
+ * in the collection schema. The SDK wraps it in an Error whose message
10
+ * starts with the Typesense body. Matching on the wording is the
11
+ * pragmatic check — the SDK doesn't surface a typed error class.
12
+ */
13
+ function isMissingFacetFieldError(err: unknown): boolean {
14
+ if (!err) return false;
15
+ const msg = err instanceof Error ? err.message : String(err);
16
+ return /Could not find a facet field named/i.test(msg);
17
+ }
18
+
7
19
  type SortOption = "relevance" | "price_asc" | "price_desc" | "name_asc" | "name_desc";
8
20
 
9
21
  const SORT_MAP: Record<SortOption, string> = {
@@ -97,22 +109,45 @@ export default defineEventHandler(async (event) => {
97
109
  // Spine facets + tenant-defined dynamic facets. category_labels is
98
110
  // locale-templated and not a facet in the deployed schema —
99
111
  // `categories` (codes) is the stable facet.
100
- const liveFacetBy = [
101
- "manufacturer",
102
- "kind",
103
- "categories",
104
- ...filterableCodes.map(c => `attrs.${c}`),
105
- ].join(",");
112
+ const spineFacetBy = "manufacturer,kind,categories";
113
+ const dynamicFacets = filterableCodes.map(c => `attrs.${c}`);
114
+ const liveFacetBy = [spineFacetBy, ...dynamicFacets].filter(Boolean).join(",");
115
+
116
+ // Schema-drift fallback: the attribute meta is cached per-tenant
117
+ // for 5min. When an operator flips is_filterable off in Cockpit,
118
+ // search-admin drops the matching `attrs.<code>` field from
119
+ // Typesense within a second (via the NATS push path), but our
120
+ // cache lags. Typesense then 4xx's with "Could not find a facet
121
+ // field named …", which would otherwise bubble up as a 503 here.
122
+ // Retry once without dynamic facets so the storefront keeps
123
+ // rendering with spine facets only; the meta cache repairs on
124
+ // its next refresh.
125
+ const runSearch = async (facetBy: string) => searchLiveProducts({
126
+ q,
127
+ queryBy: "name,sku,description,manufacturer",
128
+ filterBy: liveFilterParts.join(" && "),
129
+ facetBy,
130
+ page,
131
+ perPage,
132
+ });
106
133
 
107
134
  try {
108
- const results = await searchLiveProducts({
109
- q,
110
- queryBy: "name,sku,description,manufacturer",
111
- filterBy: liveFilterParts.join(" && "),
112
- facetBy: liveFacetBy,
113
- page,
114
- perPage,
115
- });
135
+ let results;
136
+ try {
137
+ results = await runSearch(liveFacetBy);
138
+ }
139
+ catch (err) {
140
+ if (dynamicFacets.length > 0 && isMissingFacetFieldError(err)) {
141
+ getLogService().warn(
142
+ "search: dynamic facet missing in Typesense, retrying with spine facets only",
143
+ toErrorContext(err),
144
+ );
145
+ results = await runSearch(spineFacetBy);
146
+ }
147
+ else {
148
+ throw err;
149
+ }
150
+ }
116
151
 
117
152
  // Catalog shell only — offers (price + availability) hydrate
118
153
  // separately via POST /api/offers, never blocking search.