From 539060b8af4168027d068f45260cdb0b0becfa7e Mon Sep 17 00:00:00 2001 From: Juan M Date: Thu, 2 May 2024 11:20:00 -0300 Subject: [PATCH 1/5] Fetch events fresh in functions --- netlify/loaders/api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netlify/loaders/api.js b/netlify/loaders/api.js index d196e38..b93a8d3 100644 --- a/netlify/loaders/api.js +++ b/netlify/loaders/api.js @@ -3,7 +3,7 @@ export async function getEventInfo(eventId, env) { return null } const response = await fetch( - `${env.FAMILY_API_URL}/event/${eventId}?description=false&metrics=true&fresh=false&refresh=false`, + `${env.FAMILY_API_URL}/event/${eventId}?description=false&metrics=true&fresh=false&refresh=true`, { headers: { 'x-api-key': env.FAMILY_API_KEY, @@ -64,7 +64,7 @@ export async function getEvents(eventIds, env) { return null } const response = await fetch( - `${env.FAMILY_API_URL}/events/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}?fresh=false`, + `${env.FAMILY_API_URL}/events/${eventIds.map((eventId) => encodeURIComponent(eventId)).join(',')}?fresh=true`, { headers: { 'x-api-key': env.FAMILY_API_KEY, From 9674a848e998bcf1f452c5fdb90ee9fdb9209e58 Mon Sep 17 00:00:00 2001 From: Juan M Date: Thu, 2 May 2024 11:20:20 -0300 Subject: [PATCH 2/5] Return 200 when not found --- netlify/edge-functions/event.js | 2 +- netlify/edge-functions/events.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/netlify/edge-functions/event.js b/netlify/edge-functions/event.js index bbebf20..c231b98 100644 --- a/netlify/edge-functions/event.js +++ b/netlify/edge-functions/event.js @@ -41,7 +41,7 @@ export default async function handler(request, context) { if (eventInfo == null) { return new Response(html, { - status: 404, + status: 200, headers: { 'content-type': 'text/html', }, diff --git a/netlify/edge-functions/events.js b/netlify/edge-functions/events.js index 9ffba68..84a5d40 100644 --- a/netlify/edge-functions/events.js +++ b/netlify/edge-functions/events.js @@ -61,6 +61,15 @@ export default async function handler(request, context) { }) } + if (eventsInfo == null) { + return new Response(html, { + status: 200, + headers: { + 'content-type': 'text/html', + }, + }) + } + let totalSupply = 0 let totalReservations = 0 let names = [] From 6af23a55ef3a50a1c0a7339e5659fe6d6e8d7d1e Mon Sep 17 00:00:00 2001 From: Juan M Date: Thu, 2 May 2024 11:24:00 -0300 Subject: [PATCH 3/5] When one event is not found returns 200 --- netlify/edge-functions/events.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/netlify/edge-functions/events.js b/netlify/edge-functions/events.js index 84a5d40..05a441c 100644 --- a/netlify/edge-functions/events.js +++ b/netlify/edge-functions/events.js @@ -75,7 +75,18 @@ export default async function handler(request, context) { let names = [] let ts = 0 - for (const eventInfo of Object.values(eventsInfo)) { + for (const eventId of eventIds) { + const eventInfo = eventsInfo[eventId] + + if (eventInfo.event == null || eventInfo.owners == null || eventInfo.metrics == null) { + return new Response(html, { + status: 200, + headers: { + 'content-type': 'text/html', + }, + }) + } + totalSupply += eventInfo.owners.length totalReservations += eventInfo.metrics?.emailReservations ?? 0 names = [...names, eventInfo.event.name] From 59164b7a892c03d7715d648588a75954de78535c Mon Sep 17 00:00:00 2001 From: Juan M Date: Thu, 2 May 2024 11:27:32 -0300 Subject: [PATCH 4/5] Return 400 when invalid event id --- netlify/edge-functions/event.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/netlify/edge-functions/event.js b/netlify/edge-functions/event.js index c231b98..9bb2f56 100644 --- a/netlify/edge-functions/event.js +++ b/netlify/edge-functions/event.js @@ -19,6 +19,15 @@ export default async function handler(request, context) { const eventId = parseEventId(rawEventId) const env = getEnv(context) + if (String(eventId) !== String(rawEventId)) { + return new Response(html, { + status: 400, + headers: { + 'content-type': 'text/html', + }, + }) + } + let eventInfo try { eventInfo = await getEventInfo(eventId, env) From 2c43b376cecb48aa0592bf912b12d01c9128f1ad Mon Sep 17 00:00:00 2001 From: Juan M Date: Thu, 2 May 2024 11:29:00 -0300 Subject: [PATCH 5/5] Version 1.12.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 024339b..fd7fe34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/poap-family", - "version": "1.12.7", + "version": "1.12.8", "author": { "name": "POAP", "url": "https://poap.xyz"