1import * as Cloudflare from "@/Cloudflare/index.ts";
2import * as Config from "effect/Config";
3import * as Effect from "effect/Effect";
4import * as HttpServerResponse from "effect/http/HttpServerResponse";
5
6const ZoneConfig = Config.String("CLOUDFLARE_TEST_DNS_ZONE_NAME").pipe(
7 Config.withDefault("alchemy-test-2.us"),
8);
9
10/**
11 * Fixture for the catch-all form of the event source: `email({ zone })`
12 * with no `matchers`. Cloudflare rejects a lone `{ type: "all" }` matcher
13 * on `createRule` outright ("Invalid rule operation"), so this shape only
14 * works if the event source provisions `Email.CatchAll` instead.
15 */
16export default class EmailCatchAllWorker extends Cloudflare.Worker<EmailCatchAllWorker>()(
17 "EmailCatchAllWorker",
18 {
19 main: import.meta.filename,
20 workersDev: { enabled: true, previewsEnabled: false },
21 },
22 Effect.gen(function* () {
23 const zone = yield* ZoneConfig;
24
25 yield* Cloudflare.email({ zone }).subscribe((message) =>
26 Effect.log(`received mail for ${message.to}`),
27 );
28
29 return {
30 fetch: Effect.succeed(HttpServerResponse.text("ok")),
31 };
32 }).pipe(Effect.provide(Cloudflare.EmailEventSourceLive)),
33) {}