@revenexx/cover 0.2.35 → 0.2.36
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.
|
|
3
|
+
"version": "0.2.36",
|
|
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",
|
|
@@ -30,6 +30,25 @@ function isMissingSortFieldError(err: unknown): boolean {
|
|
|
30
30
|
return /Could not find a field named .* in the schema for sorting/i.test(msg);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Typesense's answer when a `filter_by` names a field the collection does not
|
|
35
|
+
* declare: `Could not find a filter field named \`x\` in the schema.`
|
|
36
|
+
*
|
|
37
|
+
* The same shape as the facet and sort checks below it, and the same reason —
|
|
38
|
+
* the SDK surfaces no typed error — but a filter is the one of the three that
|
|
39
|
+
* is not a nicety. `enabled:=true` is pinned on every live query, so a
|
|
40
|
+
* collection that has the field stored but not indexed answered nothing at
|
|
41
|
+
* all: every listing and every search on the storefront read "0 results" with
|
|
42
|
+
* a failure banner, in every language, while the catalogue was intact.
|
|
43
|
+
*/
|
|
44
|
+
function missingFilterField(err: unknown): string | null {
|
|
45
|
+
if (!err) return null;
|
|
46
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
47
|
+
return /Could not find a filter field named/i.test(msg)
|
|
48
|
+
? (msg.match(/filter field named `([^`]+)`/i)?.[1] ?? "")
|
|
49
|
+
: null;
|
|
50
|
+
}
|
|
51
|
+
|
|
33
52
|
/**
|
|
34
53
|
* The live category codes behind the storefront's subcategory filter values.
|
|
35
54
|
*
|
|
@@ -207,10 +226,17 @@ export default defineEventHandler(async (event) => {
|
|
|
207
226
|
? SORT_MAP[sort]
|
|
208
227
|
: undefined;
|
|
209
228
|
|
|
229
|
+
// Filter clauses the collection turned out not to carry, dropped for
|
|
230
|
+
// the retry. Read after the search so the mapper can enforce by hand
|
|
231
|
+
// what the index could not enforce for us.
|
|
232
|
+
const droppedFilterFields = new Set<string>();
|
|
233
|
+
|
|
210
234
|
const runSearch = async (facetBy: string, sortBy?: string) => searchLiveProducts({
|
|
211
235
|
q,
|
|
212
236
|
queryBy: "name,sku,description,manufacturer",
|
|
213
|
-
filterBy: liveFilterParts
|
|
237
|
+
filterBy: liveFilterParts
|
|
238
|
+
.filter(part => ![...droppedFilterFields].some(f => part.startsWith(`${f}:`)))
|
|
239
|
+
.join(" && "),
|
|
214
240
|
facetBy,
|
|
215
241
|
// Typesense answers with 10 values per facet when this is unset,
|
|
216
242
|
// which silently truncates the rail AND undercounts the subcategory
|
|
@@ -222,22 +248,45 @@ export default defineEventHandler(async (event) => {
|
|
|
222
248
|
perPage,
|
|
223
249
|
});
|
|
224
250
|
|
|
225
|
-
//
|
|
226
|
-
// tenant's schema no longer has,
|
|
251
|
+
// Three independent degradations, each retried once: a dynamic facet
|
|
252
|
+
// the tenant's schema no longer has, a sort field it never had, and a
|
|
253
|
+
// filter field it does not declare.
|
|
254
|
+
//
|
|
255
|
+
// The filter one is the newcomer and the one that hurt: a pinned
|
|
256
|
+
// clause naming an undeclared field fails the whole query, so the
|
|
257
|
+
// storefront showed nothing at all rather than showing too much. It is
|
|
258
|
+
// retried without that clause — and what the clause promised is then
|
|
259
|
+
// enforced on the documents instead, below, so dropping it narrows
|
|
260
|
+
// what the page can say about totals but never widens what it shows.
|
|
227
261
|
const searchWithFallbacks = async (sortBy?: string) => {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
262
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
263
|
+
try {
|
|
264
|
+
return await runSearch(liveFacetBy, sortBy);
|
|
265
|
+
}
|
|
266
|
+
catch (err) {
|
|
267
|
+
const missing = missingFilterField(err);
|
|
268
|
+
if (missing && !droppedFilterFields.has(missing)) {
|
|
269
|
+
getLogService().warn(
|
|
270
|
+
`search: the collection does not declare the filter field \`${missing}\`, retrying without that clause`,
|
|
271
|
+
toErrorContext(err),
|
|
272
|
+
);
|
|
273
|
+
droppedFilterFields.add(missing);
|
|
274
|
+
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (dynamicFacets.length > 0 && isMissingFacetFieldError(err)) {
|
|
278
|
+
getLogService().warn(
|
|
279
|
+
"search: dynamic facet missing in Typesense, retrying with spine facets only",
|
|
280
|
+
toErrorContext(err),
|
|
281
|
+
);
|
|
282
|
+
return await runSearch(spineFacetBy, sortBy);
|
|
283
|
+
}
|
|
284
|
+
throw err;
|
|
238
285
|
}
|
|
239
|
-
throw err;
|
|
240
286
|
}
|
|
287
|
+
// Every clause the collection rejected has been dropped once; a
|
|
288
|
+
// failure now is a real one.
|
|
289
|
+
return await runSearch(liveFacetBy, sortBy);
|
|
241
290
|
};
|
|
242
291
|
|
|
243
292
|
try {
|
|
@@ -258,9 +307,26 @@ export default defineEventHandler(async (event) => {
|
|
|
258
307
|
}
|
|
259
308
|
}
|
|
260
309
|
|
|
310
|
+
// A clause the collection could not carry is enforced here instead.
|
|
311
|
+
// `enabled` is the one that matters: Typesense STORES a field it
|
|
312
|
+
// does not index and hands it back on every hit, so the value is
|
|
313
|
+
// there to be read even when it could not be filtered on. Dropping
|
|
314
|
+
// the clause therefore costs an accurate `found` and accurate facet
|
|
315
|
+
// counts — never a product on the page that should not be there.
|
|
316
|
+
const hits = droppedFilterFields.has("enabled")
|
|
317
|
+
? (results.hits ?? []).filter(hit => hit.document?.enabled !== false)
|
|
318
|
+
: (results.hits ?? []);
|
|
319
|
+
const withheld = (results.hits ?? []).length - hits.length;
|
|
320
|
+
if (withheld > 0) {
|
|
321
|
+
getLogService().warn(
|
|
322
|
+
`search: withheld ${withheld} disabled product(s) the index could not filter out`,
|
|
323
|
+
{ collection: PRODUCTS_COLLECTION },
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
261
327
|
// Catalog shell only — offers (price + availability) hydrate
|
|
262
328
|
// separately via POST /api/offers, never blocking search.
|
|
263
|
-
const products: ProductList[] =
|
|
329
|
+
const products: ProductList[] = hits.map(hit => mapLiveDocToProduct(hit.document));
|
|
264
330
|
const facets: SearchFacet[] = (results.facet_counts ?? []).map(fc => ({
|
|
265
331
|
fieldName: fc.field_name,
|
|
266
332
|
counts: (fc.counts ?? []).map(c => ({ value: c.value, count: c.count })),
|
|
@@ -292,7 +358,12 @@ export default defineEventHandler(async (event) => {
|
|
|
292
358
|
return {
|
|
293
359
|
products,
|
|
294
360
|
facets,
|
|
295
|
-
|
|
361
|
+
// Reduced by what was withheld above, so the count and the rows
|
|
362
|
+
// agree on the page the visitor is looking at. It stays an
|
|
363
|
+
// estimate across the whole result set — only this page's hits
|
|
364
|
+
// were ever read — which is the honest cost of a filter the
|
|
365
|
+
// index could not apply.
|
|
366
|
+
found: Math.max(0, (results.found ?? 0) - withheld),
|
|
296
367
|
page: results.page ?? page,
|
|
297
368
|
perPage,
|
|
298
369
|
};
|