@asteby/storefront 0.22.1 → 0.23.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/mock.cjs CHANGED
@@ -2369,6 +2369,18 @@ function createMockStorefront(options = {}) {
2369
2369
  if (!region) throw new HttpError(404, "not_found", "No region configured");
2370
2370
  return { body: region, cache: "public" };
2371
2371
  });
2372
+ route("GET", "/address/suggest", "catalog:read", ({ search }) => {
2373
+ const q = (search.get("q") ?? "").trim().replace(/\s+/g, " ");
2374
+ if ([...q].length < 3) throw new HttpError(400, "validation", "q needs at least 3 characters", "q");
2375
+ const pool = options.addressSuggestions;
2376
+ if (!pool) return { body: { suggestions: [], available: false }, cache: "private" };
2377
+ const fold = (v) => v.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase();
2378
+ const country = search.get("country")?.toUpperCase();
2379
+ const zip = search.get("zip")?.trim();
2380
+ const limit = Math.min(Math.max(Number(search.get("limit")) || 5, 1), 8);
2381
+ const hits = pool.filter((p) => fold(p.label).includes(fold(q)) && (!country || p.country === country) && (!zip || !p.zip || p.zip === zip));
2382
+ return { body: { suggestions: hits.slice(0, limit), available: true }, cache: "private" };
2383
+ });
2372
2384
  route("GET", "/products", "catalog:read", ({ search }) => ({ body: listProducts(search), cache: "public" }));
2373
2385
  route("GET", "/products/:handle", "catalog:read", ({ params }) => ({
2374
2386
  body: requireNode(state.products.find((p) => p.handle === params[0]), `Product ${params[0]}`),