Files
KomediruzeckiandGitHub bbb0b6896a feat(email): branded transactional emails, welcome for Google signups, bills reminders, prod crons (#347)
Every mail Token Circles sends now comes from a shared branded module
(worker/src/emailTemplates.ts, modeled on a proven pure-renderer design):
orbital dark shell (night page, hosted logo + serif wordmark, small looping
orbit GIF ornament with a standalone first frame for clients that freeze
GIFs), bulletproof 600px table layout with all-inline styles, dark-only
color-scheme meta, hidden preheader, and a footer with app / about / GitHub /
Terms / Privacy / Contact links plus a per-mail 'why you got this' line and
unsubscribe where applicable. Every renderer returns { subject, html, text }
— pure, snapshot-testable, with a plain-text twin now sent through Resend.

Rebranded + rewired: welcome, account-exists notice, password reset, budget
alert, spending report, test emails, support acknowledgement. Reminder
amounts now render in the profile's display currency (settings.currency,
EUR default) instead of hardcoded dollars.

Gaps closed:
- Brand-new GOOGLE signups now get the same welcome email as email/password
  registrations (resolveGoogleUser returns a created flag; the OAuth callback
  sends best-effort so a mail failure can never break the redirect).
- The legacy upcoming-bills reminder finally ported to the worker: daily cron
  (0 8 * * * UTC), settings toggle email_bills_reminders (matching the legacy
  key), plan-gated like the other reminders, same quota + per-day dedup, plus
  test-email/trigger types and a Settings toggle + preview button.
- Scheduled reminders now actually fire in PRODUCTION: env.prod gets the
  triggers block (bills daily, budget alerts Mondays, spending reports
  1st + 15th) — previously crons existed only in env.dev.

Plan gating is unchanged and verified: reminders and their test/preview
endpoints require the paid emailReminders feature (requireFeature +
eligible()); welcome/reset/support mails go to everyone.

Asset: frontend/public/email/orbit.gif (144px, 36 frames, 71KB) generated
from the OrbitSpinner design. 10 new worker tests cover every renderer
(branding contract, escaping, currency, null-on-empty, test subjects);
worker suite 147 green, frontend 607 green.
2026-07-16 21:07:34 +02:00

122 lines
6.6 KiB
JSON

{
"$schema": "node_modules/wrangler/config-schema.json",
// Finance Manager API worker (Hono + D1 + R2). Two deploy environments — `dev`
// (dev.<domain>) and `prod` (app.<domain>) — plus local dev off the top-level bindings.
// Everything marked PLACEHOLDER must be filled before the matching deploy; local dev
// works with the placeholders as-is.
"name": "finance-manager-api",
"main": "src/index.ts",
"compatibility_date": "2026-06-26",
"compatibility_flags": ["nodejs_compat"],
"observability": { "enabled": true },
// The Cloudflare account that owns the Worker + D1 + R2. From `wrangler whoami`,
// or export CLOUDFLARE_ACCOUNT_ID instead of setting it here.
// "account_id": "PLACEHOLDER_ACCOUNT_ID",
// ── Top-level bindings = what `pnpm run dev` (LOCAL dev) uses ──────────────────
// `wrangler dev` runs against a LOCAL D1 + R2 (state under .wrangler/, keyed by the
// binding NAME), so the placeholder database_id is fine locally. Apply the schema once
// with `pnpm run d1:migrate:local`. The env.dev / env.prod blocks override these for
// the real deployments.
"d1_databases": [{ "binding": "DB", "database_name": "finance-manager", "database_id": "local" }],
"r2_buckets": [{ "binding": "RECEIPTS", "bucket_name": "finance-manager-receipts" }],
"vars": {
"APP_ENV": "development",
"GOOGLE_CLIENT_ID": "PLACEHOLDER.apps.googleusercontent.com",
"CORS_ORIGIN": "http://localhost:3800",
// Public origin of THIS worker (email links must point here, not at the SPA host)
"API_PUBLIC_ORIGIN": "http://localhost:8787",
},
"env": {
// ── DEV → api.dev.<domain> (deploy: pnpm run deploy:dev) ──────────────────
"dev": {
"name": "finance-manager-api-dev",
// API on its own subdomain so the session cookie is same-site with the app
// (SameSite=Lax + COOKIE_DOMAIN). tokencircles.com must be an active zone in this
// Cloudflare account; `deploy:dev` then provisions the api.dev.tokencircles.com DNS.
"routes": [{ "pattern": "api.dev.tokencircles.com", "custom_domain": true }],
"vars": {
"APP_ENV": "dev",
"GOOGLE_CLIENT_ID": "961447002903-p2gkcujs85svbuf4tpmvu1cj4ge1ivh3.apps.googleusercontent.com",
"CORS_ORIGIN": "https://dev.tokencircles.com",
"APP_ORIGINS": "https://dev.tokencircles.com",
"API_PUBLIC_ORIGIN": "https://api.dev.tokencircles.com",
"COOKIE_DOMAIN": ".dev.tokencircles.com",
"EMAIL_FROM": "Token Circles <hello@tokencircles.com>",
// Stripe per-tier Price ids (TEST mode for dev) — vars, NOT secret. STRIPE_SECRET_KEY +
// STRIPE_WEBHOOK_SECRET are SECRETS (wrangler secret put). Steps: dotfiles billing-setup.md.
"STRIPE_PRICE_BASIC_MONTHLY": "price_1Tnn1kRczc8qAc4q8GsNyKQp",
"STRIPE_PRICE_BASIC_ANNUAL": "price_1TnnKVRczc8qAc4qEaqRAIwL",
"STRIPE_PRICE_ADVANCED_MONTHLY": "price_1Tnn9yRczc8qAc4qOjczMNxF",
"STRIPE_PRICE_ADVANCED_ANNUAL": "price_1TnnLCRczc8qAc4q0ISY361o",
"STRIPE_PRICE_ULTIMATE_MONTHLY": "price_1TnnB3Rczc8qAc4qN9rzHYIq",
"STRIPE_PRICE_ULTIMATE_ANNUAL": "price_1TnnI1Rczc8qAc4qzqUzzODg",
},
"d1_databases": [
{
"binding": "DB",
"database_name": "finance-manager-dev",
"database_id": "7a785adc-c378-43fa-b812-171319b81f22",
},
],
"r2_buckets": [{ "binding": "RECEIPTS", "bucket_name": "finance-manager-receipts-dev" }],
"triggers": {
// Budget alerts Mon 09:00 UTC; spending report twice monthly (1st + 15th) 10:00 UTC.
// NB: cron day-of-month and day-of-week are OR'd, so the old "1-7,15-21 * 4" fired on every
// day in those ranges AND every Thursday. Day-of-week is now "*" and the report is idempotent
// per half-month period (reminder_dedup), so a re-fire can't double-send.
"crons": ["0 8 * * *", "0 9 * * 1", "0 10 1,15 * *"],
},
},
// ── PROD → api.<domain> (deploy: pnpm run deploy:prod) ────────────────────
"prod": {
"name": "finance-manager-api",
"routes": [{ "pattern": "api.tokencircles.com", "custom_domain": true }],
"vars": {
"APP_ENV": "production",
// Dedicated prod Google OAuth client (Cloud project owned by tokencircles@tokencircles.com).
// Redirect URI https://api.tokencircles.com/api/auth/google/callback + JS origin
// https://tokencircles.com are registered on it; GOOGLE_CLIENT_SECRET is a wrangler secret.
"GOOGLE_CLIENT_ID": "711630541684-i5jhhvlcrvmuusuelfb1gmac2currit6.apps.googleusercontent.com",
// App lives at the APEX (not app.<domain>): the SPA origin is the bare apex.
"CORS_ORIGIN": "https://tokencircles.com",
"APP_ORIGINS": "https://tokencircles.com",
"API_PUBLIC_ORIGIN": "https://api.tokencircles.com",
"COOKIE_DOMAIN": ".tokencircles.com",
// Stripe LIVE per-tier Price ids (vars, not secret; sk_live + whsec are wrangler secrets).
// Webhook: https://api.tokencircles.com/api/billing/webhook — set its API version to
// 2024-06-20 to match STRIPE_API_VERSION in src/routes/billing.ts.
"STRIPE_PRICE_BASIC_MONTHLY": "price_1Tt9e0D6TRtQgXNzydHkPmBL",
"STRIPE_PRICE_BASIC_ANNUAL": "price_1Tt9e0D6TRtQgXNz1fRfUgUg",
"STRIPE_PRICE_ADVANCED_MONTHLY": "price_1Tt9gZD6TRtQgXNzCkf4E3Sg",
"STRIPE_PRICE_ADVANCED_ANNUAL": "price_1Tt9gZD6TRtQgXNznz0zjYSi",
"STRIPE_PRICE_ULTIMATE_MONTHLY": "price_1Tt9iSD6TRtQgXNzYsEt5ofa",
"STRIPE_PRICE_ULTIMATE_ANNUAL": "price_1Tt9iSD6TRtQgXNz0lrJIjbO",
},
"d1_databases": [
{
"binding": "DB",
"database_name": "finance-manager",
"database_id": "c70c3562-c081-4734-824c-9605537effda",
},
],
"r2_buckets": [{ "binding": "RECEIPTS", "bucket_name": "finance-manager-receipts" }],
// Scheduled reminder emails (paid feature; plan/pref/quota-gated per user in
// reminders.ts, idempotent via reminder_dedup so a re-fire can't double-send):
// 0 8 * * * — upcoming-bills reminder, daily 08:00 UTC
// 0 9 * * 1 — budget alerts, Mondays 09:00 UTC
// 0 10 1,15 * * — spending report, 1st + 15th 10:00 UTC
"triggers": {
"crons": ["0 8 * * *", "0 9 * * 1", "0 10 1,15 * *"],
},
},
},
// Secrets (NEVER in vars/here): JWT_SECRET, GOOGLE_CLIENT_SECRET.
// Set per env: pnpm run secret:dev / pnpm run secret:prod
// Locally they live in .dev.vars (see .dev.vars.example).
}