Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,19 @@
},
{
"groupName": "SimpleWebAuthn packages",
"matchPackageNames": [
"/^@simplewebauthn//"
]
"matchPackageNames": ["/^@simplewebauthn//"]
},
{
"groupName": "Radix UI packages",
"matchPackageNames": [
"/^@radix-ui//"
]
"matchPackageNames": ["/^@radix-ui//"]
},
{
"groupName": "i18next packages",
"matchPackageNames": [
"/^i18next/",
"/^react-i18next/"
]
"matchPackageNames": ["/^i18next/", "/^react-i18next/"]
},
{
"groupName": "Tailwind CSS packages",
"matchPackageNames": [
"/^tailwindcss/",
"/^@tailwindcss//"
]
"matchPackageNames": ["/^tailwindcss/", "/^@tailwindcss//"]
},
{
"groupName": "React packages",
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
pull_request:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
name: Validate
runs-on: ubuntu-latest
env:
WRANGLER_SEND_METRICS: "false"
steps:
- uses: actions/checkout@v6

- uses: pnpm/action-setup@v6

- uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm lint

- name: Format check
run: pnpm format:check

- name: Type check
run: pnpm typecheck

- name: Build
run: pnpm build
6 changes: 4 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name: Deploy

on:
push:
branches: [main]
workflow_dispatch:
workflow_run:
workflows: ["CI"]
types: [completed]

jobs:
deploy:
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main') }}
runs-on: ubuntu-latest
env:
WRANGLER_SEND_METRICS: "false"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
tags:
- 'v*'
- "v*"

jobs:
release:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ on:
workflow_dispatch:
inputs:
tag:
description: 'Tag name (e.g., v1.0.0)'
description: "Tag name (e.g., v1.0.0)"
required: true
type: string

jobs:
create-tag:
runs-on: ubuntu-latest

steps:
- name: Validate tag format
run: |
Expand All @@ -22,14 +22,14 @@ jobs:
exit 1
fi
echo "✅ Tag format is valid: $TAG"

- name: Checkout repository
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
token: ${{ secrets.PAT_TOKEN }}

- name: Check if tag already exists
run: |
TAG="${{ inputs.tag }}"
Expand All @@ -41,12 +41,12 @@ jobs:
exit 1
fi
echo "✅ Tag '$TAG' does not exist, proceeding..."

- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Create and push tag
run: |
TAG="${{ inputs.tag }}"
Expand Down
5 changes: 5 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The worker serves the frontend's static assets from `web/dist/` via the `ASSETS`
**Entry point**: `worker/src/index.ts` — registers all Hono routes and the scheduled handler.

**Route structure** (`worker/src/routes/`):

- `auth.ts` — registration, login, logout, email verification
- `auth2fa.ts` — TOTP, Passkey (WebAuthn), email OTP
- `me.ts` — user profile, notification settings
Expand All @@ -53,11 +54,13 @@ The worker serves the frontend's static assets from `web/dist/` via the `ASSETS`
- `setup.ts` — one-time DB initialization via `SETUP_SECRET`

**Database** (`worker/src/db/`):

- Cloudflare D1 (SQLite). Schema defined in `worker/src/db/schema.sql`.
- All table names use a `{prefix}` placeholder at definition time, resolved at runtime via `TABLE_PREFIX` env var and the `getTablePrefix()` helper in `types.ts`.
- Query functions are organized by entity in `worker/src/db/queries/`. Key entities: `items`, `payments`, `users`, `notifications` (channel config), `settings`.

**Core utilities** (`worker/src/core/`):

- `auth.ts` — JWT signing/verification, password hashing, ID generation
- `time.ts` — timezone-aware date arithmetic, period calculations
- `lunar.ts` — Chinese lunar calendar support (1900–2100)
Expand All @@ -66,11 +69,13 @@ The worker serves the frontend's static assets from `web/dist/` via the `ASSETS`
**Notification services** (`worker/src/services/notify/`): Each channel (Telegram, Webhook, Email, Bark, Gotify, ServerChan, PushPlus, NotifyX, WeChatBot) is a separate file. `index.ts` fans out to all enabled channels, with optional per-item channel filtering via the `channels` parameter.

**Scheduler** (`worker/src/services/scheduler.ts`): Runs hourly via Cloudflare Cron Trigger (`0 * * * *`). For each active user it:

1. Checks their allowed notification hours (per-timezone).
2. Auto-renews expired items (with KV deduplication).
3. Sends reminders for items expiring within the user's configured threshold (with per-hour KV deduplication). If an item has specific channels configured (`channels` column), only those channels are used; otherwise all enabled channels receive the notification.

**Cloudflare bindings**:

- `DB` — D1 database
- `KV` — KV namespace (used for scheduler deduplication and status)
- `ASSETS` — static file serving
Expand Down
30 changes: 15 additions & 15 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ npx wrangler kv namespace create ENOTIFY_KV

In your repository Settings → Secrets and variables → Actions, add:

| Secret | Description |
|--------|-------------|
| Secret | Description |
| ---------------------- | ------------------------------------------------------- |
| `CLOUDFLARE_API_TOKEN` | Cloudflare API Token (needs Workers and D1 permissions) |
| `JWT_SECRET` | Any random 64-char string — e.g. `openssl rand -hex 32` |
| `SETUP_SECRET` | Any random string — e.g. `openssl rand -hex 16` |
| `JWT_SECRET` | Any random 64-char string — e.g. `openssl rand -hex 32` |
| `SETUP_SECRET` | Any random string — e.g. `openssl rand -hex 16` |

In Settings → Secrets and variables → Actions → Variables, add:

| Variable | Description |
|----------|-------------|
| `D1_DATABASE_NAME` | D1 database name |
| `D1_DATABASE_ID` | D1 database ID |
| `KV_NAMESPACE_ID` | KV namespace ID |
| `TABLE_PREFIX` | Optional prefix for all DB table names(e.g. `myapp_`) |
| Variable | Description |
| ------------------ | ----------------------------------------------------- |
| `D1_DATABASE_NAME` | D1 database name |
| `D1_DATABASE_ID` | D1 database ID |
| `KV_NAMESPACE_ID` | KV namespace ID |
| `TABLE_PREFIX` | Optional prefix for all DB table names(e.g. `myapp_`) |

### 3. Deploy

Expand Down Expand Up @@ -106,12 +106,12 @@ pnpm dev:worker

### Worker Environment Variables (wrangler.toml, injected by GitHub Actions during deployment)

| Variable | Description |
|----------|-------------|
| `JWT_SECRET` | JWT signing secret, any random 64-char string |
| Variable | Description |
| -------------- | ------------------------------------------------------- |
| `JWT_SECRET` | JWT signing secret, any random 64-char string |
| `SETUP_SECRET` | Database initialization route secret, any random string |
| `TABLE_PREFIX` | Database table prefix (e.g., `hk_`), default is empty |
| `TABLE_PREFIX` | Database table prefix (e.g., `hk_`), default is empty |

## License

[MIT](LICENSE)
[MIT](LICENSE)
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ npx wrangler kv namespace create ENOTIFY_KV

在仓库的 Settings → Secrets and variables → Actions 中添加:

| Secret | 说明 |
|--------|------|
| `CLOUDFLARE_API_TOKEN` | Cloudflare API Token(需 Workers 和 D1 权限) |
| `JWT_SECRET` | 任意 64 位随机字符串,例如 `openssl rand -hex 32` |
| `SETUP_SECRET` | 任意随机字符串,例如 `openssl rand -hex 16` |
| Secret | 说明 |
| ---------------------- | ------------------------------------------------- |
| `CLOUDFLARE_API_TOKEN` | Cloudflare API Token(需 Workers 和 D1 权限) |
| `JWT_SECRET` | 任意 64 位随机字符串,例如 `openssl rand -hex 32` |
| `SETUP_SECRET` | 任意随机字符串,例如 `openssl rand -hex 16` |

在 Settings → Secrets and variables → Actions → Variables 中添加:

| Variable | 说明 |
|----------|------|
| `D1_DATABASE_NAME` | D1 数据库名称 |
| `D1_DATABASE_ID` | D1 数据库 ID |
| `KV_NAMESPACE_ID` | KV 命名空间 ID |
| `TABLE_PREFIX` | 数据库表前缀(如 `hk_`),默认为空 |
| Variable | 说明 |
| ------------------ | ---------------------------------- |
| `D1_DATABASE_NAME` | D1 数据库名称 |
| `D1_DATABASE_ID` | D1 数据库 ID |
| `KV_NAMESPACE_ID` | KV 命名空间 ID |
| `TABLE_PREFIX` | 数据库表前缀(如 `hk_`),默认为空 |

### 3. 部署

Expand Down Expand Up @@ -106,12 +106,12 @@ pnpm dev:worker

### Worker 环境变量(wrangler.toml,部署时由 GitHub Actions 注入)

| 变量 | 说明 |
|------|------|
| `JWT_SECRET` | JWT 签名密钥,任意 64 位随机字符串 |
| 变量 | 说明 |
| -------------- | ------------------------------------ |
| `JWT_SECRET` | JWT 签名密钥,任意 64 位随机字符串 |
| `SETUP_SECRET` | 数据库初始化路由密钥,任意随机字符串 |
| `TABLE_PREFIX` | 数据库表前缀(如 `hk_`),默认为空 |
| `TABLE_PREFIX` | 数据库表前缀(如 `hk_`),默认为空 |

## 许可证

[MIT](LICENSE)
[MIT](LICENSE)
53 changes: 53 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"files": {
"ignore": [
"**/node_modules/**",
"**/dist/**",
"**/.wrangler/**",
"web/public/**",
"web/dist/**",
"worker/.wrangler/**"
]
},
"formatter": {
"enabled": true,
"indentStyle": "space"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"a11y": {
"noLabelWithoutControl": "off",
"useKeyWithClickEvents": "off",
"useButtonType": "warn",
"noAutofocus": "off"
},
"suspicious": {
"noExplicitAny": "off",
"noGlobalIsNan": "error",
"noArrayIndexKey": "warn",
"noAssignInExpressions": "error"
},
"style": {
"useTemplate": "off",
"noUnusedTemplateLiteral": "off",
"noNonNullAssertion": "off"
},
"performance": {
"noDelete": "off"
},
"correctness": {
"useExhaustiveDependencies": "error",
"noUnusedLabels": "error",
"noUnusedVariables": "error"
},
"complexity": {
"noUselessFragments": "error"
}
}
}
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
"dev": "concurrently \"pnpm dev:worker\" \"pnpm dev:web\"",
"dev:web": "pnpm --filter web dev",
"dev:worker": "pnpm --filter worker dev",
"lint": "biome lint .",
"format:check": "biome format .",
"format": "biome format --write .",
"build": "pnpm --filter web build && pnpm --filter worker build",
"build:web": "pnpm --filter web build",
"build:worker": "pnpm --filter worker build",
"deploy": "pnpm build:web && sed -i '' \"s/__APP_VERSION__/'$(node -p \"require('./package.json').version\")'/g\" worker/wrangler.toml && cd worker && pnpm deploy && git checkout -- wrangler.toml",
"typecheck": "pnpm --filter web typecheck && pnpm --filter worker typecheck"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"concurrently": "^9.2.1",
"typescript": "^6.0.3"
},
"engines": {
"node": ">=22.0.0"
},
"packageManager": "pnpm@11.5.1"
"packageManager": "pnpm@11.5.2"
}
Loading