diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b82d02e..26644f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,8 @@ jobs: - name: Build run: yarn build + env: + ALGOLIA_SEARCH_KEY: dummy-key deploy: needs: diff --git a/package.json b/package.json index db03bcd..b72220b 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@types/node": "22.10.5", "@types/react": "19.0.2", "@types/react-dom": "19.0.2", - "algoliasearch": "4.24.0", + "algoliasearch": "5.18.0", "autoprefixer": "10.4.20", "eslint": "9.17.0", "marked": "15.0.5", diff --git a/scripts/reindex.mjs b/scripts/reindex.mjs index 7acf56a..d9ec6a6 100644 --- a/scripts/reindex.mjs +++ b/scripts/reindex.mjs @@ -1,9 +1,10 @@ -import algoliasearch from "algoliasearch"; +import { algoliasearch } from "algoliasearch"; import "dotenv/config"; const contentEndpoint = "https://api-eu-central-1.hygraph.com/v2/ckzhgf7f30mi901xs88ok02gc/master"; const client = algoliasearch("J8YFF4CZ4C", process.env.ALGOLIA_ADMIN_KEY); +const indexName = process.env.ALGOLIA_SEARCH_INDEX || "prod_recipes"; const updatedAt = new Date().getTime(); @@ -54,7 +55,7 @@ function loadRecipes(after = null, limit = 100) { } } `, - { after, limit }, + { after, limit } ); } @@ -62,10 +63,6 @@ async function main() { let after = null; const limit = 100; - const index = client.initIndex( - process.env.ALGOLIA_SEARCH_INDEX || "prod_recipes", - ); - do { const { data: recipesData, errors } = await loadRecipes(after, limit); @@ -83,7 +80,7 @@ async function main() { updated_at: updatedAt, })); - await index.saveObjects(dataset, { autoGenerateObjectIDIfNotExist: true }); + await client.saveObjects({ indexName, objects: dataset }); after = recipesData.recipes.length === limit @@ -91,8 +88,9 @@ async function main() { : null; } while (after); - await index.deleteBy({ - filters: "updated_at < " + updatedAt, + await client.deleteBy({ + indexName, + deleteByParams: { filters: "updated_at < " + updatedAt }, }); } diff --git a/src/lib/search.ts b/src/lib/search.ts index 96f8de3..381d007 100644 --- a/src/lib/search.ts +++ b/src/lib/search.ts @@ -1,15 +1,15 @@ import { PrismaClient } from "@prisma/client"; -import algoliasearch from "algoliasearch"; +import { algoliasearch } from "algoliasearch"; const prisma = new PrismaClient(); const client = algoliasearch("J8YFF4CZ4C", process.env.ALGOLIA_SEARCH_KEY); - -const index = client.initIndex( - process.env.ALGOLIA_SEARCH_INDEX || "prod_recipes", -); +const indexName = process.env.ALGOLIA_SEARCH_INDEX || "prod_recipes"; export async function search(query: string) { - const { hits } = await index.search<{ slug: string }>(query); + const { hits } = await client.searchSingleIndex<{ slug: string }>({ + indexName, + searchParams: { query }, + }); const slugs = hits.map((hit) => hit.slug); diff --git a/yarn.lock b/yarn.lock index 964da0f..b5091fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19,154 +19,145 @@ __metadata: languageName: node linkType: hard -"@algolia/cache-browser-local-storage@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/cache-browser-local-storage@npm:4.24.0" +"@algolia/client-abtesting@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/client-abtesting@npm:5.18.0" dependencies: - "@algolia/cache-common": "npm:4.24.0" - checksum: 10/f7f9bdb1fa37e788a5cb8c835e526caff2fa097f68736accd4c82ade5e5cb7f5bbd361cf8fc8c2a4628d979d81bd90597bdaed77ca72de8423593067b3d15040 + "@algolia/client-common": "npm:5.18.0" + "@algolia/requester-browser-xhr": "npm:5.18.0" + "@algolia/requester-fetch": "npm:5.18.0" + "@algolia/requester-node-http": "npm:5.18.0" + checksum: 10/209ee453f2a8892aecf60780d82aac0c58ed4a375fd3f04b587c90a98e70a8f2ca2c57e8ddda4e4c48000f77dd63d6e8032b7a1b5f7700d325b93951757810ba languageName: node linkType: hard -"@algolia/cache-common@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/cache-common@npm:4.24.0" - checksum: 10/bc1d0f8731713f7e6f10cd397b7d8f7464f14a2f4e1decc73a48e99ecbc0fe41bd4df1cc3eb0a4ecf286095e3eb3935b2ea40179de98e11676f8e7d78c622df8 - languageName: node - linkType: hard - -"@algolia/cache-in-memory@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/cache-in-memory@npm:4.24.0" +"@algolia/client-analytics@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/client-analytics@npm:5.18.0" dependencies: - "@algolia/cache-common": "npm:4.24.0" - checksum: 10/0476f65f4b622b1b38f050a03b9bf02cf6cc77fc69ec785d16e244770eb2c5eea581b089a346d24bdbc3561be78d383f2a8b81179b801b2af72d9795bc48fee2 + "@algolia/client-common": "npm:5.18.0" + "@algolia/requester-browser-xhr": "npm:5.18.0" + "@algolia/requester-fetch": "npm:5.18.0" + "@algolia/requester-node-http": "npm:5.18.0" + checksum: 10/53143df0396a00b455ba5868db0c11d7d12896a15b070817b01fed62d96d5e72e5705bfc01d034244296bb299e9a0ff6b8de958ba2d4e39bc0b84ecbdfdb7df2 languageName: node linkType: hard -"@algolia/client-account@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/client-account@npm:4.24.0" - dependencies: - "@algolia/client-common": "npm:4.24.0" - "@algolia/client-search": "npm:4.24.0" - "@algolia/transporter": "npm:4.24.0" - checksum: 10/059cf39f3e48b2e77a26435267284d2d15a7a3c4e904feb2b2ad2dd207a3ca2e2b3597847ec9f3b1141749b25fb2e6091e9933f53cb86ab278b5b93836c85aad +"@algolia/client-common@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/client-common@npm:5.18.0" + checksum: 10/14b5b18d6f00e70475b86cdc16559dd03541ed29a99f11491299f8d6948458ef843deb26f159f0a67837ee8be22f883d167a2c3464e7b454a2fa4d6b719092bb languageName: node linkType: hard -"@algolia/client-analytics@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/client-analytics@npm:4.24.0" +"@algolia/client-insights@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/client-insights@npm:5.18.0" dependencies: - "@algolia/client-common": "npm:4.24.0" - "@algolia/client-search": "npm:4.24.0" - "@algolia/requester-common": "npm:4.24.0" - "@algolia/transporter": "npm:4.24.0" - checksum: 10/eaa4be80636082a1fbeb0d099ef882ae6576fb0b6dc64988e9e6939533b4ddfffdbe16061cfd3f89b18bbf5aba21dff5a68af4f20b2719cf72d83a1f0774f6d5 + "@algolia/client-common": "npm:5.18.0" + "@algolia/requester-browser-xhr": "npm:5.18.0" + "@algolia/requester-fetch": "npm:5.18.0" + "@algolia/requester-node-http": "npm:5.18.0" + checksum: 10/be0ac032bd56845b91e3b0029981d02d2409b5225ea17141507ac30acb103494a0d5aa31af2d8578e48f66c47d501d7a8677577ee360a7f6f4c493ae1a2f60a0 languageName: node linkType: hard -"@algolia/client-common@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/client-common@npm:4.24.0" +"@algolia/client-personalization@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/client-personalization@npm:5.18.0" dependencies: - "@algolia/requester-common": "npm:4.24.0" - "@algolia/transporter": "npm:4.24.0" - checksum: 10/0271dc8d7b7008f28df612f14790a50a2297bdaac363be28b6261d2ec3ec343c06cc14f3f113d511a2eb4cda49ee4c204e37fc413c9f699234d8e5741b04c98f + "@algolia/client-common": "npm:5.18.0" + "@algolia/requester-browser-xhr": "npm:5.18.0" + "@algolia/requester-fetch": "npm:5.18.0" + "@algolia/requester-node-http": "npm:5.18.0" + checksum: 10/52ca0df00dafbd50a5a5369ba31ad5347e342c3ff292c27b6ee945fcd72d3df32f7a2adad4cb64291c0aa74f672f012f9518a24b75bdadf39a399b7e33fc8e05 languageName: node linkType: hard -"@algolia/client-personalization@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/client-personalization@npm:4.24.0" +"@algolia/client-query-suggestions@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/client-query-suggestions@npm:5.18.0" dependencies: - "@algolia/client-common": "npm:4.24.0" - "@algolia/requester-common": "npm:4.24.0" - "@algolia/transporter": "npm:4.24.0" - checksum: 10/5b922d547a31ef76cc6872de9b880ac7f5783321d441fd8d596eab57554c882183e1a24b050f411dee0235c7a99bf52393c3937e08db0a7f2c238a8c37985464 + "@algolia/client-common": "npm:5.18.0" + "@algolia/requester-browser-xhr": "npm:5.18.0" + "@algolia/requester-fetch": "npm:5.18.0" + "@algolia/requester-node-http": "npm:5.18.0" + checksum: 10/ab97280229b1d973da00b7472a030279fa76b18bfae14097bae21bb0c91950eb76e0bcc44b9369e3957bf4f18cffff3dd75962e452152185e283b045f5d8dc5b languageName: node linkType: hard -"@algolia/client-search@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/client-search@npm:4.24.0" +"@algolia/client-search@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/client-search@npm:5.18.0" dependencies: - "@algolia/client-common": "npm:4.24.0" - "@algolia/requester-common": "npm:4.24.0" - "@algolia/transporter": "npm:4.24.0" - checksum: 10/2cdcc4239b1bd84e3bd642e380d9135612b80dc68393d23211088141d7c8cb055394588babdf5c984817b997e9e0c4356cd50a8a56dd1ee6ad594f5f76c44acb + "@algolia/client-common": "npm:5.18.0" + "@algolia/requester-browser-xhr": "npm:5.18.0" + "@algolia/requester-fetch": "npm:5.18.0" + "@algolia/requester-node-http": "npm:5.18.0" + checksum: 10/145bef52ca62f9030614a529806fb0efb16163fcb444fcd570501f6a3dc9b32dd9450fc4c9b0088e17dcf88d6b7a9c9b57895e9012c64cf37d9fc832a63e22e9 languageName: node linkType: hard -"@algolia/logger-common@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/logger-common@npm:4.24.0" - checksum: 10/668fb5a2cbb6aaea7648ae522b5d088241589a9da9f8abb53e2daa89ca2d0bc04307291f57c65de7a332e092cc054cc98cc21b12af81620099632ca85c4ef074 - languageName: node - linkType: hard - -"@algolia/logger-console@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/logger-console@npm:4.24.0" +"@algolia/ingestion@npm:1.18.0": + version: 1.18.0 + resolution: "@algolia/ingestion@npm:1.18.0" dependencies: - "@algolia/logger-common": "npm:4.24.0" - checksum: 10/846d94ecac2e914a2aa7d1ace301cca7371b2bc757c737405eca8d29fc1a26e788387862851c90f611c90f43755367ce676802a21fa37a3bf8531b1a16f5183b + "@algolia/client-common": "npm:5.18.0" + "@algolia/requester-browser-xhr": "npm:5.18.0" + "@algolia/requester-fetch": "npm:5.18.0" + "@algolia/requester-node-http": "npm:5.18.0" + checksum: 10/cc364729de8974026ef15d6529dadc8b564bbf98bb424e779c9925be4e0816a664e8cf5408496ce4f5ad6d4221ff7e2d0cde74146b8d9fcf0935c329991bc225 languageName: node linkType: hard -"@algolia/recommend@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/recommend@npm:4.24.0" +"@algolia/monitoring@npm:1.18.0": + version: 1.18.0 + resolution: "@algolia/monitoring@npm:1.18.0" dependencies: - "@algolia/cache-browser-local-storage": "npm:4.24.0" - "@algolia/cache-common": "npm:4.24.0" - "@algolia/cache-in-memory": "npm:4.24.0" - "@algolia/client-common": "npm:4.24.0" - "@algolia/client-search": "npm:4.24.0" - "@algolia/logger-common": "npm:4.24.0" - "@algolia/logger-console": "npm:4.24.0" - "@algolia/requester-browser-xhr": "npm:4.24.0" - "@algolia/requester-common": "npm:4.24.0" - "@algolia/requester-node-http": "npm:4.24.0" - "@algolia/transporter": "npm:4.24.0" - checksum: 10/cd228381744ddc4547f1796e38e72e52b158823313dcdfde20d99c2510b6c76996bff98e7223e983768c2a13a3c019e65939741429c0f7de19651f98f74bd834 + "@algolia/client-common": "npm:5.18.0" + "@algolia/requester-browser-xhr": "npm:5.18.0" + "@algolia/requester-fetch": "npm:5.18.0" + "@algolia/requester-node-http": "npm:5.18.0" + checksum: 10/cceec5928b319abb7d5b6240542fbadf0c50a4855863f201c93c7fc6c2f56c93b96c38123c92ac9018b8e1fbc55929f380808552f72c4c09774a4d9123a54364 languageName: node linkType: hard -"@algolia/requester-browser-xhr@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/requester-browser-xhr@npm:4.24.0" +"@algolia/recommend@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/recommend@npm:5.18.0" dependencies: - "@algolia/requester-common": "npm:4.24.0" - checksum: 10/7c32d38d6c7a83357f52134f50271f1ee3df63888b28bc53040a3c74ef73458d80efaf44a5943a3769e84737c2ffd0743e1044a3b5e99ce69289f63e22b50f2a + "@algolia/client-common": "npm:5.18.0" + "@algolia/requester-browser-xhr": "npm:5.18.0" + "@algolia/requester-fetch": "npm:5.18.0" + "@algolia/requester-node-http": "npm:5.18.0" + checksum: 10/4af03133c083e47864f10957b2efec33d65b8350d391d25fab41866d16efbddea0cd0d8b33a16b894f2fae6f7edebba9a5221860e1df92d10980463b2ab20d37 languageName: node linkType: hard -"@algolia/requester-common@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/requester-common@npm:4.24.0" - checksum: 10/5ca1abd00918ad2c9aed379208d920883c7c3e69b480afe0b1d00b4eb205e39ccd347809b368ba764889261f659c85963f9a00d3da3bd59592db74108d54788b +"@algolia/requester-browser-xhr@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/requester-browser-xhr@npm:5.18.0" + dependencies: + "@algolia/client-common": "npm:5.18.0" + checksum: 10/444288dba274465e7b82401de907a971aa7f25fe33936e729fbeb8a05ce4111e25c95070116f5f049fd6bf9e3defb097ac59c48f2c71bc16238693d8a2ebe281 languageName: node linkType: hard -"@algolia/requester-node-http@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/requester-node-http@npm:4.24.0" +"@algolia/requester-fetch@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/requester-fetch@npm:5.18.0" dependencies: - "@algolia/requester-common": "npm:4.24.0" - checksum: 10/387ee892bf35f46be269996de88f9ea12841796aa33cb5088ba6460a48733614a33300ee44bca0af22b6fded05c16ec92631fb998e9a7e1e6a30504d8b407c23 + "@algolia/client-common": "npm:5.18.0" + checksum: 10/c9538e749b0f689e96758b93716ef1639fb83be10bdb07d3816af51d7fceaf12fd42324d8440cc5a2fe997a3af983f17034b1beb369071dd1c20fcf26414a6a5 languageName: node linkType: hard -"@algolia/transporter@npm:4.24.0": - version: 4.24.0 - resolution: "@algolia/transporter@npm:4.24.0" +"@algolia/requester-node-http@npm:5.18.0": + version: 5.18.0 + resolution: "@algolia/requester-node-http@npm:5.18.0" dependencies: - "@algolia/cache-common": "npm:4.24.0" - "@algolia/logger-common": "npm:4.24.0" - "@algolia/requester-common": "npm:4.24.0" - checksum: 10/decf4d5da37d62ff720e25313a473160c2be4c83bfb048d5caebea0320f42681138e91e78b359b8f825059c2acc83054bc17d53584701984f5e79822eb770efa + "@algolia/client-common": "npm:5.18.0" + checksum: 10/e62b97328212fc66eade6e6767e827f2f4309760de8ba46692caa43313b92b1039c56fc78927aa03c1cab0e6d5ea436b4720f832c09b1c013eccddf2d88e6a17 languageName: node linkType: hard @@ -5320,26 +5311,24 @@ __metadata: languageName: node linkType: hard -"algoliasearch@npm:4.24.0": - version: 4.24.0 - resolution: "algoliasearch@npm:4.24.0" +"algoliasearch@npm:5.18.0": + version: 5.18.0 + resolution: "algoliasearch@npm:5.18.0" dependencies: - "@algolia/cache-browser-local-storage": "npm:4.24.0" - "@algolia/cache-common": "npm:4.24.0" - "@algolia/cache-in-memory": "npm:4.24.0" - "@algolia/client-account": "npm:4.24.0" - "@algolia/client-analytics": "npm:4.24.0" - "@algolia/client-common": "npm:4.24.0" - "@algolia/client-personalization": "npm:4.24.0" - "@algolia/client-search": "npm:4.24.0" - "@algolia/logger-common": "npm:4.24.0" - "@algolia/logger-console": "npm:4.24.0" - "@algolia/recommend": "npm:4.24.0" - "@algolia/requester-browser-xhr": "npm:4.24.0" - "@algolia/requester-common": "npm:4.24.0" - "@algolia/requester-node-http": "npm:4.24.0" - "@algolia/transporter": "npm:4.24.0" - checksum: 10/fba851fb719529754b450c3d366de72289351c864aea56aa1c167ff0e36d5b015dddae7d720fe649a00d6c91d94a2091fb27789e553eb79c8d28a885585ccc6f + "@algolia/client-abtesting": "npm:5.18.0" + "@algolia/client-analytics": "npm:5.18.0" + "@algolia/client-common": "npm:5.18.0" + "@algolia/client-insights": "npm:5.18.0" + "@algolia/client-personalization": "npm:5.18.0" + "@algolia/client-query-suggestions": "npm:5.18.0" + "@algolia/client-search": "npm:5.18.0" + "@algolia/ingestion": "npm:1.18.0" + "@algolia/monitoring": "npm:1.18.0" + "@algolia/recommend": "npm:5.18.0" + "@algolia/requester-browser-xhr": "npm:5.18.0" + "@algolia/requester-fetch": "npm:5.18.0" + "@algolia/requester-node-http": "npm:5.18.0" + checksum: 10/2077389bc196f2ee5c5dd30082f37a02ff13a50da48819743fccae2254b8e8f055e9f2234983269ee5369d30b0a24aea1b1f363f4b19141137917f997403d376 languageName: node linkType: hard @@ -14474,7 +14463,7 @@ __metadata: "@types/node": "npm:22.10.5" "@types/react": "npm:19.0.2" "@types/react-dom": "npm:19.0.2" - algoliasearch: "npm:4.24.0" + algoliasearch: "npm:5.18.0" autoprefixer: "npm:10.4.20" chromatic: "npm:11.22.0" dotenv: "npm:16.4.7"