import { z } from "zod";
const Pricing = z.object({
product: z.string(),
plans: z.array(
z.object({
name: z.string(),
price: z.number().nullable(),
billing: z.enum(["monthly", "yearly"]),
}),
),
});
const headers = {
Authorization: `Bearer ${process.env.STOPHY_API_KEY}`,
"content-type": "application/json",
};
const started = await fetch("https://api.stophy.dev/v1/extract", {
method: "POST",
headers,
body: JSON.stringify({ urls: ["https://example.com/pricing"], schema: z.toJSONSchema(Pricing) }),
}).then((response) => response.json());
const result = await fetch(`https://api.stophy.dev/v1/extract/${started.id}`, { headers }).then(
(response) => response.json(),
);
console.log(Pricing.parse(result.data));