import { z } from "zod/mini" // This type represents response format from oEmbed API export const EmbedSchema = z.strictObject({ type: z.string(), version: z.nullish(z.string()), author_name: z.nullish(z.string()), author_url: z.nullish(z.string()), provider_name: z.nullish(z.string()), provider_url: z.nullish(z.string()), cache_age: z.nullish(z.string()), thumbnail_url: z.nullish(z.string()), thumbnail_width: z.nullish(z.number()), thumbnail_height: z.nullish(z.number()), html: z.nullish(z.string()), title: z.nullish(z.string()), }) export type Embed = z.infer export const getEmbedOrThrow = (embeds: Record): ((embedUrl: string) => Embed) => (embedUrl: string): Embed => { const embed = embeds[embedUrl] if (!embed) throw new Error(`Missing embed with url '${embedUrl}'`) return embed }