Skip to content

feat(cli): add the 'clerk webhooks' command group#323

Draft
rafa-thayto wants to merge 28 commits into
mainfrom
rafa-thayto/webhooks
Draft

feat(cli): add the 'clerk webhooks' command group#323
rafa-thayto wants to merge 28 commits into
mainfrom
rafa-thayto/webhooks

Conversation

@rafa-thayto

Copy link
Copy Markdown
Contributor

Summary

Adds the full clerk webhooks command group (13 commands) per the final spec: CRUD, delivery inspection, local forwarding via the Svix relay, replay, offline signature verification, and portal open.

  • CRUD & inspection: list, get, create, update, delete, secret [--rotate], event-types, messages
  • Delivery loop: listen (Svix relay WebSocket, persistent per-instance endpoint, HMAC verification, local forwarding with per-delivery diagnostics), trigger (validates event type first), replay (single message or bulk --since [--until] recovery)
  • Offline: verify — pure HMAC-SHA256 check, no auth gate, consumes listen NDJSON event lines via --delivery @file|-
  • Plumbing: 4 new ERROR_CODE entries, per-instance relay config, typed PLAPI functions for the 13 new routes (--iteratorstarting_after wire translation), group-level --app/--instance/--json with an auth preAction hook that exempts verify

Agent contract: bare domain JSON on stdout via log.data(), structured {"error":{code,…}} on stderr, exit codes 0/1/2/130, NDJSON for listen. Destructive commands (delete, secret --rotate, replay --since) prompt in human mode and require --yes in agent mode — validated before any network call.

Notable fixes that came out of the verification passes:

  • trigger validates the event type before endpoint resolution so agents always get unknown_event_type
  • listen gates delivery processing until the signing secret is fetched (no false verification warnings during startup)
  • the implicit piped-stdin --input-json expansion stands down when a literal - is in argv, unblocking verify --delivery - pipes

The 13 PLAPI routes are being built in parallel in clerk_go; unit tests mock the PLAPI layer.

Test plan

  • bun run format / lint / typecheck clean
  • bun run test — 1846 tests pass (187 in the webhooks group)
  • Live agent-flow smoke matrix (CLERK_MODE=agent, isolated CLERK_CONFIG_DIR): verify success/mismatch/usage errors, stdin pipes, fail-fast --yes gates, structured API/auth error shapes
  • E2E against real PLAPI once the clerk_go routes land

…; gate listen deliveries until setup completes
…tdin pipes

- delete / secret --rotate / replay --since now run the --yes/prompt gate
  before resolveAppContext, so agent mode gets the deterministic usage
  error without a network round-trip (and regardless of key validity)
- the implicit piped-stdin --input-json expansion now stands down when a
  literal '-' is in argv, fixing 'verify --delivery -' / '--payload -'
  which previously had their stdin consumed and rejected as nested JSON
@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9f8329d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
clerk Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

…he inbox URL

Live-relay verified: play.svix.com returns 400 'Invalid token' for
unprefixed tokens, and the relay only registers an inbox when the start
frame carries the same c_ token. With c_ in both, a POST to the inbox
round-trips through the WebSocket and the reply frame is accepted —
proven end-to-end against the real relay with no PLAPI involvement.
Reverses spec change #12 (recorded as spec change #27).
@rafa-thayto

Copy link
Copy Markdown
Contributor Author

!snapshot

@github-actions

Copy link
Copy Markdown
Contributor

Snapshot published

npm install -g clerk@2.0.1-snapshot.9f8329d
Package Version
clerk 2.0.1-snapshot.9f8329d

Published from 9f8329d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant