@beesolve/analytics-dashboard

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

CloudFront analytics dashboard — SvelteKit app for viewing traffic analytics

原始使用文档
文档目录9 节
  1. Architecture
  2. Prerequisites
  3. CDK Setup
  4. Data layer (remote functions)
  5. First Deployment
  6. Backfilling history
  7. Local Development
  8. Features
  9. License

@beesolve/analytics-dashboard

SvelteKit dashboard for viewing CloudFront traffic analytics — deployed on AWS Lambda behind CloudFront with email-code authentication.

[!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

┌────────────┐     ┌──────────────┐     ┌─────────┐     ┌──────────┐
│ CloudFront │ ──► │ Lambda (SSR) │ ──► │ DynamoDB│     │   SES    │
└────────────┘     └──────────────┘     └─────────┘     └──────────┘
       │                     ▲                                ▲
       │          read-only  │ analytics table                │
       │          (AnalyticsProcessor.grantRead)      OTP emails via
       └── /auth/* ──► AuthGateway (authorizer)       @beesolve/email-service

The dashboard reads the @beesolve/analytics-processor DynamoDB table (hourly/daily/monthly totals + per-dimension breakdowns) read-only. Its own small DynamoDB table holds the dashboard's Users/Setup records (sign-in, roles).

Prerequisites

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

CDK Setup

import { AnalyticsDashboard } from "@beesolve/analytics-dashboard/cdk";
import { requiredRecordFields } from "@beesolve/analytics-processor";
import { AnalyticsProcessor } from "@beesolve/analytics-processor/cdk";
import { AuthGateway } from "@beesolve/auth-service/cdk";
import { CloudFrontAccessLoggingSettings } from "@beesolve/cdk-constructs";
import { App, RemovalPolicy, Stack } from "aws-cdk-lib";

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, "AnalyticsStack", {
  env: { account: "123456789012", region: "eu-central-1" },
});

// 1. Log the distribution to S3 as Parquet (standard logging v2)
const logging = new CloudFrontAccessLoggingSettings(stack, "Logging", {
  athena: { account: "123456789012", recordFields: requiredRecordFields },
});

// ...create your CloudFront `distribution`, spreading
// `...logging.cloudFrontLoggingSettings` into its props, then:
logging.enableV2Logging({
  distributionArn: `arn:aws:cloudfront::123456789012:distribution/${distribution.distributionId}`,
});

// 2. Aggregate logs into DynamoDB
const processor = new AnalyticsProcessor(stack, "Processor", {
  athenaDatabase: logging.glueDatabaseName!,
  athenaV2Table: logging.glueTableName!,
  athenaWorkgroup: logging.workgroupName!,
  logBucketArn: logging.logBucket.bucketArn,
  athenaResultsBucketArn: logging.athenaResultsBucket?.bucketArn,
});

// 3. Set up authentication
const auth = new AuthGateway(stack, "Auth", {
  stage: "prod",
  frontendUri,
  allowSignUp: false,
  authorizerCache: "disabled",
});

// 4. Deploy the dashboard
const dashboard = new AnalyticsDashboard(stack, "AnalyticsDashboard", {
  auth,
  processor,
  emailSender: {
    name: "Analytics Dashboard",
    emailAddress: "[email protected]",
  },
});

The AnalyticsDashboard construct provisions:

  • SvelteKit app on Lambda (via kit-on-lambda)
  • CloudFront distribution with auth cookie enforcement
  • Auth behavior for /auth/* routes
  • A dedicated DynamoDB table (+ reverse GSI) for the dashboard's Users/Setup, wired via ANALYTICS_USERS_TABLE / ANALYTICS_USERS_REVERSE_INDEX
  • Read-only access to the processor's analytics table via processor.grantRead(handler) (ANALYTICS_TABLE_NAME / ANALYTICS_REVERSE_INDEX)
  • Email service for OTP codes
  • EventBridge rule for auth events (sends OTP emails)

Data layer (remote functions)

The dashboard reads its data through SvelteKit remote functions, not +page.server.ts load/actions. Definitions live in src/lib/remote/*.remote.ts:

  • getOverview({ grain, anchor?, size? }) — clamps the window per grain, computes boundary keys deterministically from the anchor (no DynamoDB cursors), and returns the totals series plus prev/next anchors.
  • getBreakdown({ dimension, grain, periodKey }) — reads a single bounded breakdown partition.
  • users/setup remote functions mirror @beesolve/dmarc-dashboard (admin guards, toRemoteError, requireUser/requireAdmin).

Environment variables are declared in src/env.ts via defineEnvVars (Valibot schemas) and imported, typed and validated, from $app/env/private: ANALYTICS_TABLE_NAME, ANALYTICS_REVERSE_INDEX, ANALYTICS_USERS_TABLE, ANALYTICS_USERS_REVERSE_INDEX.

First Deployment

The SvelteKit build requires a FRONTEND_URI environment variable (the CloudFront URL), which doesn't 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

Backfilling history

CloudFront standard logging v2 only starts collecting Parquet data once the upgraded CloudFrontAccessLoggingSettings is deployed. Historic traffic lives in the already-collected v1 (tab-delimited) logs. Run the one-time backfill from @beesolve/analytics-processor once, as an operator, to populate the table from v1 history before anyone relies on long-range views:

# from the analytics-processor package, with AWS creds (AWS_PROFILE) in scope
bun run backfill -- --from 2026-01-01T00:00:00Z --to 2026-02-01T00:00:00Z

The backfill is resumable and exactly-once (per-hour idempotency markers), so re-running it skips already-processed hours. See the processor README for the full flag reference.

Local Development

Run the SvelteKit dev server against the real deployed backend — no fixtures:

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

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 in the users table — the app looks it up to resolve that user's role. This is guarded by import.meta.env.DEV and never included in the deployed bundle.

Features

  • Overview with hourly/daily/monthly/yearly grain switching and rolling prev/next windows
  • Stat cards for hits, success, errors, and bytes
  • Per-dimension breakdowns: HTTP status, country, device, and top paths
  • Email-code sign-in (no passwords) + user management (invite, remove)

License

MIT

版本与发布记录

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

版本发布日期距今
0.8.3latest2026/10/2810 天前
0.8.22026/10/2018 天前
0.8.12026/10/2018 天前
0.8.02026/10/2019 天前
0.7.52026/10/2019 天前
0.7.42026/10/1820 天前

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

@beesolve/analytics-dashboard 是什么?

CloudFront analytics dashboard — SvelteKit app for viewing traffic analytics

如何安装 @beesolve/analytics-dashboard?

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

@beesolve/analytics-dashboard 支持 TypeScript 吗?

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

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

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

@beesolve/analytics-dashboard 可以商用吗?

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

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

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

@beesolve/analytics-dashboard 还在维护吗?

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