Skip to content

Commit

Permalink
Merge pull request #223 from poap-xyz/release/v1.12.11
Browse files Browse the repository at this point in the history
Release v1.12.11
  • Loading branch information
jm42 authored May 10, 2024
2 parents 12d66a1 + c4bb672 commit 316ef6e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/poap-family",
"version": "1.12.10",
"version": "1.12.11",
"author": {
"name": "POAP",
"url": "https://poap.xyz"
Expand Down
35 changes: 10 additions & 25 deletions src/loaders/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'
import { FAMILY_API_KEY, FAMILY_API_URL } from '../models/api'
import { encodeExpiryDates, Event, EventOwners } from '../models/event'
import { encodeExpiryDates, Event, EventMetrics, EventOwners } from '../models/event'

async function getEventAndOwners(
eventId,
Expand Down Expand Up @@ -313,27 +313,8 @@ async function getEventMetrics(eventId, abortSignal, refresh = false) {
if (response.status !== 200) {
throw new Error(`Event ${eventId} failed to fetch metrics (status ${response.status})`)
}
const metrics = await response.json()
if (
!metrics ||
typeof metrics !== 'object' ||
!('emailReservations' in metrics) || typeof metrics.emailReservations !== 'number' ||
!('emailClaimsMinted' in metrics) || typeof metrics.emailClaimsMinted !== 'number' ||
!('emailClaims' in metrics) || typeof metrics.emailClaims !== 'number' ||
!('momentsUploaded' in metrics) || typeof metrics.momentsUploaded !== 'number' ||
!('collectionsIncludes' in metrics) || typeof metrics.collectionsIncludes !== 'number' ||
!('ts' in metrics) || (typeof metrics.ts !== 'number' && metrics.ts !== null)
) {
return null
}
return {
emailReservations: metrics.emailReservations,
emailClaimsMinted: metrics.emailClaimsMinted,
emailClaims: metrics.emailClaims,
momentsUploaded: metrics.momentsUploaded,
collectionsIncludes: metrics.collectionsIncludes,
ts: metrics.ts,
}
const body = await response.json()
return EventMetrics(body)
}

async function getEventsMetrics(eventIds, abortSignal) {
Expand Down Expand Up @@ -367,11 +348,15 @@ async function getEventsMetrics(eventIds, abortSignal) {
}
throw new Error(`Events (${eventIds.length}) failed to fetch metrics (status ${response.status})`)
}
const metricsMap = await response.json()
if (typeof metricsMap !== 'object') {
const body = await response.json()
if (typeof body !== 'object') {
return null
}
return metricsMap
return Object.fromEntries(
Object.entries(body).map(
([eventId, event]) => [eventId, EventMetrics(event)]
)
)
}

async function auth(passphrase) {
Expand Down
41 changes: 36 additions & 5 deletions src/models/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ function Event(event, includeDescription) {
}

function EventOwners(eventOwners) {
if (eventOwners == null) {
return null
}
if (
eventOwners == null ||
typeof eventOwners !== 'object' ||
!('owners' in eventOwners) ||
(
eventOwners.owners != null &&
!Array.isArray(eventOwners.owners)
) ||
!Array.isArray(eventOwners.owners) ||
!('ts' in eventOwners) ||
eventOwners.ts == null ||
typeof eventOwners.ts !== 'number'
Expand All @@ -39,6 +38,37 @@ function EventOwners(eventOwners) {
}
}

function EventMetrics(eventMetrics) {
if (eventMetrics == null) {
return null
}
if (
typeof eventMetrics !== 'object' ||
!('emailReservations' in eventMetrics) ||
typeof eventMetrics.emailReservations !== 'number' ||
!('emailClaimsMinted' in eventMetrics) ||
typeof eventMetrics.emailClaimsMinted !== 'number' ||
!('emailClaims' in eventMetrics) ||
typeof eventMetrics.emailClaims !== 'number' ||
!('momentsUploaded' in eventMetrics) ||
typeof eventMetrics.momentsUploaded !== 'number' ||
!('collectionsIncludes' in eventMetrics) ||
typeof eventMetrics.collectionsIncludes !== 'number' ||
!('ts' in eventMetrics) ||
typeof eventMetrics.ts !== 'number'
) {
throw new Error('Malformed event metrics')
}
return {
emailReservations: eventMetrics.emailReservations,
emailClaimsMinted: eventMetrics.emailClaimsMinted,
emailClaims: eventMetrics.emailClaims,
momentsUploaded: eventMetrics.momentsUploaded,
collectionsIncludes: eventMetrics.collectionsIncludes,
ts: eventMetrics.ts,
}
}

function parseEventIds(rawIds) {
let eventIds = (rawIds ?? '').split(',')
.filter((value, index, all) => all.indexOf(value) === index)
Expand Down Expand Up @@ -87,6 +117,7 @@ const SEARCH_LIMIT = 10
export {
Event,
EventOwners,
EventMetrics,
parseEventIds,
joinEventIds,
parseExpiryDates,
Expand Down

0 comments on commit 316ef6e

Please sign in to comment.