Important: Git deploy and dashboard variables
If Workers Builds runs npx wrangler deploy without --keep-vars and without "keep_vars": true in wrangler.jsonc, Wrangler removes dashboard Plaintext variables not listed in wrangler.jsonc. Encrypted secrets usually survive.
This repo sets "keep_vars": true in wrangler.jsonc. The deploy command must still use --keep-vars (see npm run deploy). Estate standard: emailmenow-site/docs/cloudflare-workers-deploy.md.
Fix (choose one):
- Recommended: Edit
varsinwrangler.jsoncin the repo (SITE_URL, RESEND_FROM, etc.) and redeploy. Values in git are restored on every build. - Or: Set
keep_vars: trueinwrangler.jsonc(already enabled) and re-add variables in the dashboard — they will be kept on the next deploy only if you also add them tovarsOR rely on keep_vars (dashboard-only vars preserved when keep_vars is true).
After updating wrangler.jsonc, push to main or trigger a new build. You do not need to re-enter secrets.
Client checklist and Safe Harbor email workflow
Send a pre-start checklist to the client before work begins. After completion, the client signs electronically and receives signed Safe Harbor documentation by email.
One-time Cloudflare setup
1. KV namespace
Create a KV namespace named ENGAGEMENTS (dashboard or CLI):
npx wrangler kv namespace create ENGAGEMENTS
Copy the Namespace ID (32-character hex). Find it under Workers KV → ENGAGEMENTS → namespace details.
Workers Builds (required for CI deploy): add a build variable (not a runtime secret):
| Build variable | Value |
|---|---|
KV_ENGAGEMENTS_NAMESPACE_ID |
Your ENGAGEMENTS namespace ID |
The build runs scripts/patch-wrangler-kv.mjs, which replaces REPLACE_WITH_KV_NAMESPACE_ID in wrangler.jsonc before deploy.
Local / manual deploy: either set the same env var when building, or paste the id directly into wrangler.jsonc:
"id": "your_32_character_namespace_id_here"
Dashboard binding: Variable name must be ENGAGEMENTS (matches env.ENGAGEMENTS in code). The KV namespace dropdown can be the ENGAGEMENTS namespace you created.
2. Secrets and variables
In the Worker dashboard (Settings → Variables and Secrets) or via CLI:
| Name | Type | Purpose |
|---|---|---|
RESEND_API_KEY |
Secret | Resend API key for outbound email |
ADMIN_API_KEY |
Secret | Protects admin API (X-Admin-Key header) |
RESEND_FROM |
Text | e.g. Compliance Support <support@info.emailmenow.com> |
SITE_URL |
Text | Public Worker URL, e.g. https://email-security-guide.maps8656.workers.dev |
PROVIDER_NAME |
Text | e.g. EmailMeNow IT Consulting |
SUPPORT_EMAIL |
Text | e.g. support@emailmenow.com |
DEFAULT_REPLY_TO |
Text | Optional consultant reply-to for client emails |
Source of truth for Git deploy: wrangler.jsonc → vars (not dashboard-only). Update that file and push to main so Workers Builds restores them.
npx wrangler secret put RESEND_API_KEY
npx wrangler secret put ADMIN_API_KEY
3. Deploy
npm install
KV_ENGAGEMENTS_NAMESPACE_ID=your_id npm run build
npx wrangler deploy --keep-vars
Workers Builds:
| Setting | Value |
|---|---|
| Build command | npm install && npm run build |
| Deploy command | npx wrangler deploy --keep-vars (production) or npx wrangler versions upload (preview branches) |
| Build variable | KV_ENGAGEMENTS_NAMESPACE_ID = your namespace id |
Fix: KV namespace 'REPLACE_WITH_KV_NAMESPACE_ID' is not valid
The repo still contains a placeholder until the build variable is set or wrangler.jsonc is edited. Add KV_ENGAGEMENTS_NAMESPACE_ID in Worker → Settings → Builds → Build variables, then retry the build.
Daily workflow
Admin (/admin.html)
- Open Admin on your deployed site.
- Enter your
ADMIN_API_KEY(stored in the browser only). - Create an engagement (firm, domain, client email).
- Leave Send pre-start checklist checked to email the client immediately, or uncheck and use Resend checklist later.
The client receives:
- Link to the pre-start checklist
- Link to the completion page (
/complete/?token=…) for signing after work is done
Client completion (/complete/?token=…)
- Client opens the completion link from the checklist email.
- Confirms firm/domain, enters name and title, acknowledges completion.
- Worker emails signed Safe Harbor attestation to the client address on file.
API reference
| Method | Path | Auth | Action |
|---|---|---|---|
POST |
/api/engagements |
Admin | Create engagement; optional checklist email |
GET |
/api/engagements |
Admin | List engagements |
POST |
/api/engagements/:id/send-checklist |
Admin | Resend pre-start checklist |
GET |
/api/engagements/:token |
Token | Load engagement for completion UI |
POST |
/api/engagements/:token/complete |
Token | Sign and email Safe Harbor documentation |
Customize documents
- Pre-start checklist:
checklists/pre-start-checklist.md - Safe Harbor template (email body):
documents/safe-harbor-attestation.mdandsrc/worker.js(SAFE_HARBOR_MD)
After editing Markdown, run npm run build and redeploy.
Reply-to for client emails
Client-facing emails (pre-start checklist, Safe Harbor) support a Reply-To header so replies reach the consultant, not only the Resend From address.
| Setting | Type | Purpose |
|---|---|---|
DEFAULT_REPLY_TO |
Variable | Default reply address for all engagements (e.g. consultant@yourfirm.com) |
Per-engagement replyToEmail |
Admin form | Overrides default for one client |
Resolution order: engagement reply-to → DEFAULT_REPLY_TO (or legacy REPLY_TO_EMAIL) → SUPPORT_EMAIL.
RESEND_FROM stays the visible From (must be a verified sender in Resend).