@beesolve/email-service-dashboard

中文文档
0.6.11发布于 2026/10/28MITTypeScriptES Module构建来源已验证近 30 天下载 1884

Email service dashboard — SvelteKit app for viewing email delivery status

原始使用文档
文档目录11 节
  1. Architecture
  2. What the dashboard shows
  3. Prerequisites
  4. CDK Setup
  5. Data layer (remote functions)
  6. First Deployment
  7. Local Development
  8. Faking the session
  9. Required env vars
  10. Deployment notes (kit-on-lambda + CloudFront)
  11. License

@beesolve/email-service-dashboard

SvelteKit dashboard for viewing @beesolve/email-service delivery status — deployed on AWS Lambda behind CloudFront with email-code authentication. It runs its own event-ingest Lambda that projects the email delivery lifecycle (from EventBridge) into its own DynamoDB table, so the UI has durable, queryable message + status + aggregate-stats data.

[!WARNING] Pre-1.0 — unstable API. This package is 0.x and under active development. Breaking changes can land in any 0.x release without a major version bump. Pin an exact version and review the changelog before upgrading. Once the API stabilizes and the package reaches 1.0.0, it follows semantic versioning and this notice is removed.

Architecture

  email-service ──► SES ──► EventBridge  (beesolve.email.api / aws.ses)
                                 │
                                 ▼
                    event-ingest Lambda (SQS-buffered)
                                 │  parse → Messages.upsert (transactional)
                                 ▼
┌────────────┐     ┌──────────────┐     ┌──────────┐
│ CloudFront │ ──► │ Lambda (SSR) │ ──► │ DynamoDB │  (dashboard's own projection)
└────────────┘     └──────────────┘     └──────────┘
       │                                       ▲
       └── /auth/* ──► AuthGateway             │  OTP emails via
                       (authorizer)            └─ @beesolve/email-service

What the dashboard shows

  • Overview — global aggregate counters (received / sent / delivered / bounced / complained / rejected / failed) and derived totals.
  • Messages — sent messages listed by month, newest-first, paginated; status badge per message.
  • Message detail — the per-recipient delivery timeline, variant status detail (bounce diagnostics, complaint feedback, reject reason, delivery latency), and an on-demand "view message body" action (fetched via email.getMessage(requestId), never stored — available only while the source EmailLog record still exists).
  • Recipients — all recipients with per-recipient counters, and per-recipient message history.
  • Email-code sign-in (no passwords) and admin user management.

Opens and clicks are intentionally out of scope.

Prerequisites

npm install \
  @beesolve/email-service-dashboard \
  @beesolve/email-service \
  @beesolve/auth-service \
  aws-cdk \
  aws-cdk-lib \
  constructs

CDK Setup

Only the ./cdk construct is exported. Construct an AuthGateway first, then hand it to the dashboard:

import { AuthGateway } from "@beesolve/auth-service/cdk";
import { EmailServiceDashboard } from "@beesolve/email-service-dashboard/cdk";
import { App, Stack } from "aws-cdk-lib";
import { EventBus } from "aws-cdk-lib/aws-events";

const frontendUri = process.env.FRONTEND_URI;
if (frontendUri == null) throw new Error("FRONTEND_URI environment variable is required");

const app = new App();
const stack = new Stack(app, "EmailDashboardStack", {
  env: { account: "123456789012", region: "eu-central-1" },
});

const authEventBus = new EventBus(stack, "AuthEventBus");

const auth = new AuthGateway(stack, "Auth", {
  stage: "prod",
  frontendUri,
  allowSignUp: false,
  authorizerCache: "disabled",
  // Give the dashboard's own auth its own bus so its sign-in OTP events don't
  // collide with the project's real auth on the default bus. Optional — omit to
  // share the default bus and rely on `appId` for source-based isolation instead.
  eventBusArn: authEventBus.eventBusArn,
});

const dashboard = new EmailServiceDashboard(stack, "Dashboard", {
  auth,
  emailSender: {
    name: "Email Dashboard",
    emailAddress: "[email protected]",
  },
  // isProd?: boolean       — enables PITR on the table
  // removalPolicy?: RemovalPolicy
});

The EmailServiceDashboard construct provisions:

  • a DynamoDB TableV2 (the delivery-status projection) with one reverse GSI
  • the SvelteKit app on Lambda (via kit-on-lambda) behind CloudFront, with auth cookie enforcement and an /auth/* behavior
  • an @beesolve/email-service Emails construct for OTP mail
  • an auth-events consumer Lambda + EventBridge rule that sends the sign-in OTP emails, bound to auth.eventBus and filtered on auth.eventSource (so it follows whatever bus/appId the auth deployment uses)
  • an event-ingest Lambda fronted by an SQS queue + DLQ, with an EventBridge rule on source: ["beesolve.email.api", "aws.ses"] on the default bus, projecting the delivery lifecycle into the table

Two buses, by design. The dashboard's own sign-in auth can live on a dedicated bus (via auth's eventBusArn), but the delivery-status events it displays always arrive on the account default bus — SES configuration-set event destinations can only target the default bus. The two internal rules are bound accordingly: the auth rule to auth.eventBus, the email-events rule to default. The dashboard therefore has no eventBusName prop.

Data layer (remote functions)

The dashboard reads and writes its data through SvelteKit remote functions, not +page.server.ts load/actions. Definitions live in src/lib/remote/*.remote.ts, organized by domain area (overview, messages, recipients, users, setup):

  • query(...) for reads (overview, message list, message detail, recipients list, recipient detail). URL filters such as year/month/cursor are passed as Valibot-validated arguments.
  • form(...) for user-submitted mutations (invite user, edit user, complete setup).
  • command(...) for programmatic mutations invoked from event handlers. The on-demand message body (loadMessageBody) is a command so S3 is read only when the user triggers it, never during the detail query.

Each function reads request context via getRequestEvent().locals (locals.user, locals.session, locals.services), which hooks.server.ts populates. Admin guards live inside the remote functions. After a mutation, the relevant query(...).refresh() is called for a single-flight UI update.

Error mapping is centralized in src/lib/server/httpErrors.ts: toRemoteError(error, { redirectOnUnauthorized }) turns domain errors into SvelteKit error()/redirect(), and requireUser(user) guards a present session. Call toRemoteError(...) directly inside a catch - never throw its result.

Remote functions are enabled by experimental.remoteFunctions and compilerOptions.experimental.async in vite.config.ts. The only retained server loads are +layout.server.ts (supplies user and the setup redirect), the setup/+page.server.ts redirect guard, and the sign-in universal/layout loads. Environment variables are declared in src/env.ts via defineEnvVars and imported, typed and validated, from $app/env/private.

First Deployment

The SvelteKit build requires a FRONTEND_URI environment variable (the CloudFront URL), which does not exist until after the first deploy:

  1. Set FRONTEND_URI to a placeholder URL (e.g. https://placeholder.cloudfront.net)
  2. Deploy — note the CloudFront URL from CDK output
  3. Update FRONTEND_URI with the real URL and redeploy

Local Development

bun install
cp .env.local.example .env.local   # then fill in real values
aws sso login                      # (or export AWS_PROFILE) so SDK clients can reach AWS
bun run dev

bun run dev serves on http://localhost:5173. The dev script runs bun --env-file=.env.local vite dev, so .env.local is loaded into process.env before the server starts. The table vars are then declared in src/env.ts (defineEnvVars) and read, typed and validated, from $app/env/private in hooks.server.ts; the workspace SDK clients still read their own vars from process.env at import time.

Faking the session

There is no Lambda authorizer locally, so @beesolve/auth-service injects a dev session automatically. Set DEV_USER_EMAIL in .env.local to a real user's email so the app resolves that user's role and shows the UI they would see. This is guarded by import.meta.env.DEV and is never included in the deployed bundle.

Required env vars

  • DASHBOARD_TABLE_NAME — the projection table name (injected by the construct in deployment)
  • DASHBOARD_REVERSE_INDEX — the reverse GSI name (injected by the construct in deployment)
  • DASHBOARD_REQUESTS_BUCKET — the bucket holding on-demand message request bodies
  • DEV_USER_EMAIL — local development only; the user whose session is faked

The table/bucket vars are declared in src/env.ts and validated by defineEnvVars when first imported from $app/env/private, so they must be present for the app to start — the build script sets build-placeholder values for exactly this reason (see below).

Deployment notes (kit-on-lambda + CloudFront)

  • Externalize @beesolve/lambda-fetch-api for SSR. The vite config must set ssr.external: ["@beesolve/lambda-fetch-api"]. Without it, Vite creates a duplicate AsyncLocalStorage instance and the SDK's handler context is lost at runtime.
  • Use default form actions. SvelteKit named form actions use ?/name in the URL; the / in the query string is rejected/misrouted by CloudFront behind kit-on-lambda. Use the default (unnamed) form action.
  • Placeholder build env. The env vars declared in src/env.ts are validated by defineEnvVars when $app/env/private is first imported during SSR analysis, so the build script supplies DASHBOARD_TABLE_NAME / DASHBOARD_REVERSE_INDEX / DASHBOARD_REQUESTS_BUCKET placeholders to let the build complete.

License

MIT

版本与发布记录

@beesolve/email-service-dashboard 共发布 26 个版本,首次发布于 2026/09/06;过去 12 个月发布了 26 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.11latest2026/10/2811 天前
0.6.102026/10/2019 天前
0.6.92026/10/2019 天前
0.6.82026/10/1721 天前
0.6.72026/10/1326 天前
0.6.62026/10/1326 天前

关于 @beesolve/email-service-dashboard 的常见问题

@beesolve/email-service-dashboard 是什么?

Email service dashboard — SvelteKit app for viewing email delivery status

如何安装 @beesolve/email-service-dashboard?

在项目目录运行 npm install @beesolve/email-service-dashboard,或使用 pnpm add / yarn add / bun add。

@beesolve/email-service-dashboard 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@beesolve/email-service-dashboard 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@beesolve/email-service-dashboard 可以商用吗?

@beesolve/email-service-dashboard 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@beesolve/email-service-dashboard 的下载量有多少?

根据 npm 官方下载统计,@beesolve/email-service-dashboard 在 2026/10/08 – 2026/11/06 这 30 天内被下载 1,884 次,日均约 63 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@beesolve/email-service-dashboard 还在维护吗?

最新版本 0.6.11 发布于 2026/10/28(11 天前);至今共发布 26 个版本,其中过去 12 个月发布了 26 个;首次发布于 2026/09/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。