crabfit/frontend/src/config/api.ts
2023-05-20 01:52:44 +10:00

45 lines
1.2 KiB
TypeScript

// TODO: Write a simple rust crate that generates these from the OpenAPI spec
import { z } from 'zod'
if (process.env.NEXT_PUBLIC_API_URL === undefined) {
throw new Error('Expected API url environment variable')
}
export const API_BASE = new URL(process.env.NEXT_PUBLIC_API_URL)
export const EventInput = z.object({
name: z.string().optional(),
times: z.string().array(),
timezone: z.string(),
})
export type EventInput = z.infer<typeof EventInput>
export const EventResponse = z.object({
id: z.string(),
name: z.string(),
times: z.string().array(),
timezone: z.string(),
created_at: z.number(),
})
export type EventResponse = z.infer<typeof EventResponse>
export const PersonInput = z.object({
availability: z.string().array(),
})
export type PersonInput = z.infer<typeof PersonInput>
export const PersonResponse = z.object({
name: z.string(),
availability: z.string().array(),
created_at: z.number(),
})
export type PersonResponse = z.infer<typeof PersonResponse>
export const StatsResponse = z.object({
event_count: z.number(),
person_count: z.number(),
version: z.string(),
})
export type StatsResponse = z.infer<typeof StatsResponse>