Canica

Email

Apps email their own users, with typed templates (React Email components, from canica/email).

// server/emails.tsx
import { email, Button, Heading, Text } from "canica/email"
import { string } from "canica/server"
export const emails = {
  listShared: email(
    { props: { listName: string(), by: string() }, subject: ({ listName }) => `${listName} was shared with you`, preview: { listName: "Groceries", by: "Ana" } },
    ({ listName, by }) => <Text>{by} shared <b>{listName}</b> with you. Open it in the app.</Text>,
  ),
}
// server/index.ts: app({ emails, … }); then in a mutation or an action (it returns the email's id):
const sent = yield* (yield* Email).send("listShared", { to: friend, props: { listName, by: me.profile?.name ?? "Someone" } })
// a query the page uses to follow it, live (useQuery("emailStatus", { id })):
emailStatus: query({ id: emailId() }, function* ({ id }) {
  const status = yield* (yield* Email).status(id) // NotFound for an unknown id
  if (status.to !== (yield* Viewer).userId) return yield* new NotFound({ table: "emails", id }) // only the recipient
  return status // { state, reason, message, attempts, … }
}),