← back to Dw Unbuyable Recovery Pilot

tk11040-momentum-reconcile/meilisearch-client.mjs

21 lines

export async function searchHits({ fetchImpl = fetch, host, key, query }) {
  const response = await fetchImpl(`${host}/indexes/redesign-colors/search`, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${key}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ q: query, limit: 20 }),
  });

  if (!response.ok) {
    throw new Error(`Meilisearch request failed with HTTP ${response.status}`);
  }

  const payload = await response.json();
  if (!Array.isArray(payload.hits)) {
    throw new Error('Meilisearch response is missing a hits array');
  }
  return payload.hits;
}