import { http, HttpResponse, type HttpHandler } from "msw";
import { z } from "zod";
export const handlers: Array<HttpHandler> = [
http.post(`https://api.resend.com/emails`, async ({ request }) => {
const headers = request.headers;
if (!headers.has("Authorization")) {
const headersString = JSON.stringify(
Object.fromEntries(headers.entries()),
null,
2,
);
throw new Error(
`Header "Authorization" required, but not found in ${headersString}`,
);
}
const body = await request.json();
console.info("🔶 mocked email contents:", body);
const email = z
.object({
to: z.string(),
from: z.string(),
subject: z.string(),
text: z.string(),
html: z.string(),
})
.parse(body);
return HttpResponse.json({
id: crypto.randomUUID(),
from: email.from,
to: email.to,
created_at: new Date().toISOString(),
});
}),
];
import { http, HttpResponse, type HttpHandler } from "msw";
import { z } from "zod";
export const handlers: Array<HttpHandler> = [
http.post(`https://api.resend.com/emails`, async ({ request }) => {
const headers = request.headers;
if (!headers.has("Authorization")) {
const headersString = JSON.stringify(
Object.fromEntries(headers.entries()),
null,
2,
);
throw new Error(
`Header "Authorization" required, but not found in ${headersString}`,
);
}
const body = await request.json();
console.info("🔶 mocked email contents:", body);
const email = z
.object({
to: z.string(),
from: z.string(),
subject: z.string(),
text: z.string(),
html: z.string(),
})
.parse(body);
return HttpResponse.json({
id: crypto.randomUUID(),
from: email.from,
to: email.to,
created_at: new Date().toISOString(),
});
}),
];