mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
* fix(nuxt): pre-bundle the CommonJS deps of the markdown stack
`debug` and `extend` are imported by micromark and unified through
@elysola/ui. Served unbundled by the dev server they have no default
export, so the console page failed with a 500 in `nuxt dev`.
* docs(deployment): list the fragments and feishu link migrations
The manual `d1 execute` fallback stopped at 0008, and AGENTS.md named
0001..0010 although 0011 already exists.
* feat(storage): persist the per-group route order
Routes used to load in id order, so the order saved from the console
was lost on the next read. Migration 0012 adds `d1_routes.position`:
saving writes each route's index within its own group (saving one group
never shifts another), and routes load by `group_id, position, id`.
A database without the column keeps working: only a "no such column" /
"has no column named" error falls back to the legacy statements, and
nothing is cached, so a later migration is picked up on the next call.
* feat(console): add in-app destructive-action confirmation
Deleting a route or a group used `window.confirm`, which blocks the page
and ignores the console theme. A promise-based `useConfirm()` now drives
one <ConfirmDialog /> built on the reka-ui AlertDialog that
@elysola/ui ships; reka-ui is pre-bundled so dev keeps a single copy and
the dialog stacks with the Rc dialogs.
A request never outlives its asker: one made after the asking component
unmounted resolves false, and one still open when it unmounts is
cancelled.
* feat(console): confirm member and webhook removal
Removing a member, revoking an invite link and disabling a group's
webhook endpoint took effect on the first click. They now ask first;
disabling the webhook explains that senders still using the secret will
be rejected, and its button is styled as destructive.
* feat(console): confirm removing filled editor rows
Filter conditions and groups, delivery targets, saved fragments and forge
hosts vanished on a single click, taking whatever had been typed with
them. Rows holding content now ask first, while empty, never-filled
rows (`isBlankNode`: default operator, no path, no values, not negated)
are still removed directly.
* fix(i18n): remove duplicate button glyphs
"New Route", "New Group" and the group cards' "Open" link render a Plus
or ArrowRight icon next to their label, so the "+" and "→" baked into
the strings appeared twice.
* style(console): redesign route cards for narrow screens
The card was one flex row whose badges, filter chips, targets and five
hand-drawn icon buttons squeezed the route name on small screens. It is
now a grid driven by a container query: name and actions share the top
line, the filter summary (clamped to two lines) and targets follow, and
the tags wrap below; from 40rem the tags move up beside the title.
Targets of the same platform collapse into one tag with a count, long
ids truncate instead of widening the page, and the actions use lucide
icons with accessible labels.
* feat(console): reorder a group's routes by drag or keyboard
The per-card up/down arrows saved after every single step, so moving a
route five places took five writes. A Reorder mode on the group page now
swaps each card's switch for a drag handle: pointer drags (mouse and
touch) slide the neighbours out of the way and auto-scroll near the
viewport edges, Arrow Up/Down on a focused handle moves a card by one
and is announced to screen readers, and nothing is written until Save
order. Cancel or Escape (unless a dialog or list owns it) drops the
draft.
The cards move into a new RouteList component that owns the drag state.
* style(members): align member cards and invite actions
* style(group-editor): size forge and log target controls
Keep source hosts, platform selectors and remove actions aligned without stretching short controls across the dialog. Wrap component roots explicitly so their internal markup cannot break the grid.
* style(route-editor): group options and delivery target fields
Give each target labeled fields and a compact platform header, widen the filter workspace, and align fragment controls. Scroll failed validation into view when the footer is far from the affected section.
* feat(filters): add bilingual suggestions and value validation
Catalog forge events, actions, payload paths and known values with searchable English and Chinese descriptions. Match-value validation mirrors the server and only rejects inputs that cannot match.
* feat(filters): add searchable creatable value inputs
Build a theme-aligned combobox on the shared reka-ui primitives. Rank stored keys before bilingual descriptions, allow validated custom values, and preserve unconfirmed multi-value drafts instead of silently committing them.
* feat(filter-editor): integrate searchable condition inputs
Replace chip-only values with context-aware bilingual inputs and a compact condition grid. Preserve drafts across tree changes, block saves and tests until drafts are resolved, and keep keyword filters free of hidden operators.
* feat(filters): split pasted values without breaking regexes
Accept multiple values separated by commas or lines while retaining commas inside wrapped expressions and raw regex patterns. Pasting replaces the selected range and keeps rejected values as an explicit draft.
* fix(filters): adapt suggestions to the selected operator
Offer literal prefixes and suffixes for substring operators, escaped anchored patterns for regex, and numeric suggestions only for comparisons. Suggestion syntax must mean what the selected matcher actually reads.
* fix(filters): preserve regex meaning when changing operators
Swap wrapped and raw regex sources only when both compile identically after saving. Leave literal, glob, multiline and Unicode-sensitive comparisons unchanged rather than inventing non-equivalent conversions.
* a11y(filter-editor): label type and operator controls
Associate each fixed select with a stable per-condition label while keeping the compact visual layout unchanged.
* fix(editors): ignore accidental backdrop dismissal
Do not discard unsaved route or group edits when the user clicks outside the dialog. Preserve Escape, Cancel and explicit close, including popovers and confirmation dialogs stacked above the editor.
* feat(dispatch)!: scope stop and fallback to each group
A match in one group must not suppress delivery in another group. Track regular matches and stopped scopes independently, and document the routing-table boundary.
BREAKING CHANGE: stop and fallback no longer apply globally across
groups. Put mutually exclusive routes in the same group and define
fallback routes in each group that needs its own catch-all.
* fix(dispatch): honor stop on a matching fallback route
Once a fallback matches with stop enabled, skip later routes of the same group without affecting other groups. Cover multiple fallback routes in the group-isolation regression test.
* style(console): pin theme and language controls to the right
Separate utility controls from page actions so narrow screens retain a readable title column and right-aligned actions below. Wrap long headings without letting them push controls out of view.
* style(groups): place creation beside the aligned group count
Keep the new-group action inside the group list at every width and align the label and count on one baseline with a consistent type scale.
* style(groups): align card footers and keep role badges intact
Give long names two lines, show the current role in its own non-wrapping row, and anchor every card footer to the grid-row bottom regardless of optional source metadata.
* style(logs): prevent filter labels and metadata overflow
Keep filter labels on one line and allow long channel, thread and repository identifiers to wrap instead of widening the page.
* style(console): scale the sidebar and hide mobile tab tracks
Narrow the sidebar proportionally while retaining enough room for both locales. Keep mobile navigation swipeable without a visible horizontal scrollbar.
* feat(console): give each group its own routes URL
Resolve the selected group from /admin/groups/{groupId}, validate console paths, and use browser history for back navigation. Keep Groups active and let an active mobile-tab tap return to the list. Scope pending route loads to their group and retain the count beside long headings.
* feat(console): confirm leaving unsaved page work
Guard route changes when an editor or changed order draft is open. Cancel superseded questions and restore the shown history entry when repeated Back or Forward navigation is refused; only completed navigation resets page work.
* feat(console): confirm sign-out from desktop and mobile
Expose sign-out in the mobile topbar when the sidebar is hidden. Both entry points use the in-app confirmation before navigating to the server logout endpoint.
* fix(console): keep topbar tools clear of very narrow headings
Below 360px, place the full-width heading beneath the breadcrumb and utility row so the three top-right buttons cannot overlap it.
* feat(console): prioritize group titles over actions
Place New Route after Reorder in the group bar. Measure available space and remove the reorder label first, then the creation label, before truncating the group title; remeasure on resize, locale and font changes.
* fix(editors): focus the dialog without selecting its name field
Cancel the non-bubbling FocusScope mount event in the capture phase and focus the dialog itself. Keep keyboard navigation working without highlighting the name or opening the touch keyboard automatically.
* perf(console): preserve one instance across admin navigation
Use a fixed page key instead of remounting the whole console for each URL. Refresh each view when shown and isolate overview metrics and logs so page filters cannot leak into the dashboard.
* fix(console-data): discard superseded load responses
Only the latest request may update a list, its error or loading state. Invalidate pending group loads after a save so an older response cannot restore stale configuration during persistent-console navigation.
* fix(routes): serialize writes and reject unloaded route lists
Whole-list saves must start from loaded data and wait for other route writes. Lock switches and actions during saves, recheck deletion after confirmation, and rebuild saved ordering from the newest route objects.
* fix(editors): scope async results and fragment writes to sessions
A completed save or dry run must not close or overwrite a newer editor. Keep fragment state scoped by group, reject writes until the real list is ready, and retain in-flight fragment locks across navigation.
* fix(groups): serialize edits and isolate group detail panels
Prevent overlapping whole-list writes, avoid duplicate ids after rename, and discard delete confirmations prepared on a page that has since been left. Key member and webhook panels by group so local state cannot cross tenants.
* fix(console): omit the empty action row outside overview
Render the refresh-action container only where it has content so narrow layouts do not reserve a blank row after creation controls move into their page bars.
* perf(metrics): send all seven queries in one D1 batch
Avoid seven sequential network round trips and read totals, breakdowns and recent failures in one consistent transaction. Reuse the failed-send statement and row mapping while retaining group scoping.
* fix(admin-api): bypass browser cache locks for live requests
Use no-store on both client requests and admin responses. Personalized live data must not be reused, and one stalled same-URL cache entry must not block later log requests behind the browser cache lock.
* docs(routes): Clarify fallback hints and document group-scoped stop and fallback upgrade behavior
357 lines
10 KiB
TypeScript
357 lines
10 KiB
TypeScript
export interface Env {
|
|
GITHUB_WEBHOOK_SECRET: string;
|
|
GITEA_WEBHOOK_SECRET?: string;
|
|
GITHUB_APP_ID?: string;
|
|
GITHUB_PRIVATE_KEY?: string;
|
|
GITHUB_CLIENT_ID?: string;
|
|
GITHUB_CLIENT_SECRET?: string;
|
|
DISCORD_TOKEN?: string;
|
|
BASE_URL?: string;
|
|
ADMIN_USER_IDS?: string;
|
|
DEBUG_MODE?: string;
|
|
DISCORD_PUBLIC_KEY?: string;
|
|
DISCORD_APPLICATION_ID?: string;
|
|
TELEGRAM_TOKEN?: string;
|
|
TELEGRAM_WEBHOOK_SECRET?: string;
|
|
TELEGRAM_RICH_HEADER_HOST?: string;
|
|
FEISHU_APP_ID?: string;
|
|
FEISHU_APP_SECRET?: string;
|
|
/**
|
|
* When enabled ("1"/"true"), GitHub users without any group access get a
|
|
* personal group on first login instead of being blocked.
|
|
*/
|
|
ALLOW_SELF_SIGNUP?: string;
|
|
/** Audit log retention in days (default 90). */
|
|
AUDIT_RETENTION_DAYS?: string;
|
|
ASSETS?: Fetcher;
|
|
KV: KVNamespace;
|
|
DB: D1Database;
|
|
QUEUE?: Queue;
|
|
PAYLOAD?: R2Bucket;
|
|
}
|
|
|
|
export interface Config {
|
|
baseUrl: string;
|
|
github: {
|
|
webhookSecret: string;
|
|
appId: number;
|
|
privateKey: string;
|
|
clientId: string;
|
|
clientSecret: string;
|
|
};
|
|
discord: {
|
|
token: string;
|
|
};
|
|
routes: Route[];
|
|
}
|
|
|
|
export interface RouteTarget {
|
|
platform?: "discord" | "telegram" | "feishu";
|
|
channelId?: string;
|
|
threadId?: string;
|
|
chatId?: string;
|
|
topicId?: string;
|
|
}
|
|
|
|
export interface Route {
|
|
id: string;
|
|
name: string;
|
|
enabled: boolean;
|
|
filters: Filter[];
|
|
targets: RouteTarget[];
|
|
groupId?: string;
|
|
/**
|
|
* Optional explicit filter expression tree. When present it replaces the
|
|
* flat `filters` array (which is equivalent to `{ all: filters }`). Omitted
|
|
* on routes stored without an AST — matching falls back to `filters`.
|
|
*/
|
|
ast?: FilterNode;
|
|
/**
|
|
* Fallback route: only fires when no other (non-fallback) route of the same
|
|
* group matched the event. Multiple fallback routes may exist; a group's are
|
|
* all skipped whenever one of its regular routes matches. Its own filters
|
|
* still apply.
|
|
*/
|
|
fallback?: boolean;
|
|
/**
|
|
* Stop: when true and this route matches, no further routes of the same
|
|
* group are evaluated for this event (other groups are unaffected). Useful
|
|
* for exclusive routing where a match should prevent fallthrough to the
|
|
* group's subsequent routes.
|
|
*/
|
|
stop?: boolean;
|
|
/**
|
|
* Discord role (身份组) ids to mention/notify when this route fires. Roles
|
|
* are only mentioned in Discord targets; Telegram targets ignore this field.
|
|
*/
|
|
discordRoleIds?: string[];
|
|
}
|
|
|
|
export type GroupRole = "owner" | "admin" | "viewer";
|
|
|
|
export interface GroupMember {
|
|
/**
|
|
* GitHub login (case-insensitive). Ids are matched when stored, logins
|
|
* otherwise; identityMatches handles both.
|
|
*/
|
|
login: string;
|
|
role: GroupRole;
|
|
}
|
|
|
|
export interface Group {
|
|
id: string;
|
|
name: string;
|
|
/**
|
|
* Deprecated legacy field: GitHub user ids or logins allowed to manage this
|
|
* group. Kept for backward compatibility — when `members` is absent, these
|
|
* are normalized to `members` with role "owner". New writes use `members`.
|
|
*/
|
|
adminIds: string[];
|
|
/**
|
|
* Group members with roles. Roles: owner (manage group + members + invites),
|
|
* admin (manage routes), viewer (read-only). Super admins always bypass.
|
|
*/
|
|
members?: GroupMember[];
|
|
/**
|
|
* GitHub organization/user logins (case-insensitive) whose webhook events are
|
|
* allowed into this group's routes. Empty/omitted = no owner restriction.
|
|
* Only super admins may edit this field.
|
|
*/
|
|
owners?: string[];
|
|
/**
|
|
* Webhook providers (source platforms) allowed into this group's routes
|
|
* (e.g. `["github"]`, `["gitea"]`). Empty/omitted = all providers.
|
|
*/
|
|
providers?: WebhookProvider[];
|
|
/**
|
|
* GitHub App installation id bound to this group. When set, only webhook
|
|
* events coming from that installation (org/user) are accepted into the
|
|
* group's routes — hard tenant isolation on top of (or instead of) the
|
|
* `owners` list. Empty/omitted = no installation restriction.
|
|
*/
|
|
installationId?: number;
|
|
/**
|
|
* Whether to include emoji in messages sent through this group's routes.
|
|
* Defaults to true when omitted.
|
|
*/
|
|
emoji?: boolean;
|
|
/**
|
|
* Named forge sources shown in the footer of this group's messages. Each
|
|
* entry pairs a host (e.g. `git1.example.com`) with a source type
|
|
* (`github` / `gitea`) and an optional display `name`; an event is labeled
|
|
* with the first entry whose type matches its provider and whose host
|
|
* matches the repository URL's hostname (GitHub events match `github.com`).
|
|
* Empty/omitted = no forge label.
|
|
*/
|
|
forgeSources?: ForgeSource[];
|
|
/**
|
|
* Message language for every route in this group (e.g. "en", "zh"; custom
|
|
* via KV i18n:<lang>). Defaults to "en" when omitted.
|
|
*/
|
|
lang?: string;
|
|
/**
|
|
* Discord channel/thread or Telegram chat/topic that receives a summary of
|
|
* every webhook this group's routes dispatch (the group's webhook log).
|
|
*/
|
|
logTarget?: RouteTarget;
|
|
}
|
|
|
|
export type FilterType = "event" | "repo" | "actor" | "action" | "branch" | "keyword" | "field";
|
|
|
|
export type FilterOp =
|
|
| "eq"
|
|
| "ne"
|
|
| "contains"
|
|
| "startsWith"
|
|
| "endsWith"
|
|
| "regex"
|
|
| "gt"
|
|
| "gte"
|
|
| "lt"
|
|
| "lte"
|
|
| "in"
|
|
| "exists";
|
|
|
|
export interface Filter {
|
|
type: FilterType;
|
|
match?: string | string[];
|
|
exclude?: boolean;
|
|
/**
|
|
* JSONPath (dot notation, arrays expanded so any element matches) into
|
|
* `payload` used by `type: "field"` filters. E.g. `pull_request.user.login`.
|
|
*/
|
|
path?: string;
|
|
/**
|
|
* Comparison operator. Defaults to `eq`, which keeps the legacy glob/regex/
|
|
* case-insensitive-exact semantics. `exists` ignores `match`.
|
|
*/
|
|
op?: FilterOp;
|
|
}
|
|
|
|
/**
|
|
* A filter node matches an event when every child matches.
|
|
*/
|
|
export interface FilterAll {
|
|
all: FilterNode[];
|
|
}
|
|
|
|
/**
|
|
* A filter node matches an event when any child matches.
|
|
*/
|
|
export interface FilterAny {
|
|
any: FilterNode[];
|
|
}
|
|
|
|
/**
|
|
* A filter node matches an event when its child does not match.
|
|
*/
|
|
export interface FilterNot {
|
|
not: FilterNode;
|
|
}
|
|
|
|
/**
|
|
* A composable filter expression tree. Leaf nodes are `Filter`; the `all`,
|
|
* `any` and `not` nodes compose them. A route's `filters` array stays the
|
|
* flat AND-of-filters form (equivalent to `{ all: filters }`); `ast` optionally
|
|
* replaces it with an explicit tree.
|
|
*/
|
|
export type FilterNode = Filter | FilterAll | FilterAny | FilterNot;
|
|
|
|
export type WebhookProvider = "github" | "gitea" | "gitlab" | "custom";
|
|
|
|
export interface WebhookEvent {
|
|
event: string;
|
|
payload: Record<string, unknown>;
|
|
signature?: string;
|
|
deliveryId?: string;
|
|
provider?: WebhookProvider;
|
|
/**
|
|
* GitHub App installation id that produced this event (extracted from
|
|
* `payload.installation.id`). Gitea/custom events have none.
|
|
*/
|
|
installationId?: number;
|
|
}
|
|
|
|
/**
|
|
* A forge-agnostic webhook event after provider verification and
|
|
* normalization: the canonical shape every provider's `parse` output conforms
|
|
* to, plus the tenant scope (`groupId`) and receipt time carried through the
|
|
* delivery pipeline.
|
|
*/
|
|
export interface NormalizedWebhook {
|
|
provider: WebhookProvider;
|
|
deliveryId: string;
|
|
event: string;
|
|
groupId?: string;
|
|
payload: Record<string, unknown>;
|
|
installationId?: number;
|
|
receivedAt: number;
|
|
}
|
|
|
|
export interface NeutralAuthor {
|
|
name: string;
|
|
iconUrl?: string;
|
|
url?: string;
|
|
}
|
|
|
|
export type ForgeType = "github" | "gitea";
|
|
|
|
/**
|
|
* A forge host a group configures itself. When an event's repository host
|
|
* matches `host`, the message footer is labeled with `name` (when set) or the
|
|
* host itself — e.g. two self-hosted Gitea instances can be shown as
|
|
* "内网 Gitea" / "Git2 仓库" while matched by git1.example.com /
|
|
* git2.example.com. GitHub events match `github.com` (or a GitHub Enterprise
|
|
* host). Link/icon are derived from the repository URL (https, port preserved).
|
|
*/
|
|
export interface ForgeSource {
|
|
/** Hostname matched against the repository URL (case-insensitive). */
|
|
host: string;
|
|
type: ForgeType;
|
|
/** Optional display label shown in the message footer; falls back to `host`. */
|
|
name?: string;
|
|
}
|
|
|
|
/**
|
|
* The forge (source platform) that produced an event: shown in the message
|
|
* footer when the group defines a matching `Group.forgeSources` entry so
|
|
* recipients can tell GitHub and Gitea instances apart at a glance.
|
|
*/
|
|
export interface NeutralForge {
|
|
/** Display name: the source's `name` or its host (e.g. "内网 Gitea"). */
|
|
name: string;
|
|
/** Site URL for the hyperlink (Telegram) / brand context (Discord). */
|
|
url?: string;
|
|
/** Site favicon used as the Discord embed footer icon. */
|
|
iconUrl?: string;
|
|
}
|
|
|
|
export interface NeutralField {
|
|
name: string;
|
|
value: string;
|
|
inline?: boolean;
|
|
}
|
|
|
|
export type NeutralActionStyle = "primary" | "danger" | "secondary";
|
|
|
|
export interface NeutralAction {
|
|
id: string;
|
|
label: string;
|
|
style: NeutralActionStyle;
|
|
}
|
|
|
|
export interface NeutralMessage {
|
|
author?: NeutralAuthor;
|
|
title: string;
|
|
url?: string;
|
|
color?: number;
|
|
description?: string;
|
|
fields?: NeutralField[];
|
|
footer?: string;
|
|
timestamp?: string;
|
|
actions?: NeutralAction[];
|
|
/**
|
|
* Forge branding set by dispatch when `Group.forgeLabel` is enabled; drivers
|
|
* render it in the footer (Discord icon + name, Telegram linked name).
|
|
*/
|
|
forge?: NeutralForge;
|
|
/**
|
|
* Stable key identifying a message chain that should be updated in place
|
|
* (e.g. workflow run progress). When set, subsequent events edit the
|
|
* previously sent message instead of sending a new one.
|
|
*/
|
|
updateKey?: string;
|
|
/**
|
|
* Discord role ids to mention in the message content (set by dispatch from
|
|
* the route's `discordRoleIds`). Only used by the Discord driver.
|
|
*/
|
|
mentionRoleIds?: string[];
|
|
}
|
|
|
|
export interface FormattedMessage {
|
|
content?: string;
|
|
embeds?: Array<{
|
|
title?: string;
|
|
description?: string;
|
|
url?: string;
|
|
color?: number;
|
|
author?: {
|
|
name: string;
|
|
icon_url?: string;
|
|
url?: string;
|
|
};
|
|
fields?: Array<{ name: string; value: string; inline?: boolean }>;
|
|
footer?: { text: string; icon_url?: string };
|
|
timestamp?: string;
|
|
}>;
|
|
components?: Array<{
|
|
type: number;
|
|
components: Array<{
|
|
type: number;
|
|
style?: number;
|
|
label?: string;
|
|
custom_id?: string;
|
|
}>;
|
|
}>;
|
|
}
|