Skip to content

feat(api-keys, webhooks): organization_id on list and create (Scaffald/SaaS#1440) - #44

Merged
thinkclay merged 1 commit into
mainfrom
feat/org-scoped-keys-webhooks-1440
Nov 25, 2026
Merged

thinkclay merged 1 commit into
mainfrom
feat/org-scoped-keys-webhooks-1440

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

API keys and webhooks belong to an organization. Scaffald/SaaS#1440 moves them from Office (platform staff only) to a Developers tab on each organization. Every call from that tab names its organization, so a member of more than one never hits the api's "pass organization_id" refusal, and each tab lists only its own organization's rows.

  • apiKeys.list(params?) and webhooks.list(params?) take { organization_id } (new ListApiKeysParams, ListWebhooksParams).
  • CreateApiKeyParams and CreateWebhookParams accept organization_id. The api already accepted it on create.
  • ApiKey carries organization_id. Webhook carries the delivery statistics columns the table keeps (total_deliveries, last_delivery_at, …).

Everything is optional, so existing callers are unchanged. The matching api changes (the organization_id list filter, plus GET /v1/webhooks/{id} and /{id}/deliveries, which retrieve and listDeliveries already called but the api never served) are in the SaaS PR that bumps this pointer.

pnpm test (787 passed), pnpm typecheck clean.

🤖 Generated with Claude Code

…d/SaaS#1440)

API keys and webhooks belong to an organization. The per-organization
Developers tab passes the organization explicitly, so a member of more than
one organization never hits "pass organization_id", and each tab lists only
its own organization's keys and webhooks.

- apiKeys.list(params?) and webhooks.list(params?) take { organization_id }.
- CreateApiKeyParams and CreateWebhookParams accept organization_id.
- ApiKey carries organization_id; Webhook carries its delivery statistics.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thinkclay
thinkclay merged commit 72220d5 into main Nov 25, 2026
thinkclay added a commit to Scaffald/SaaS that referenced this pull request Nov 25, 2026
thinkclay added a commit to Scaffald/SaaS that referenced this pull request Nov 25, 2026
…evelopers tab (#1440) (#1444)

* feat(developers): API keys and webhooks move to each organization's Developers tab (#1440)

API keys and webhooks belong to an organization, but they sat in Office,
which admits only the platform `office` role, so an employer admin could not
manage their own. They now live on the organization, the way #1312 moved
Applications to /hiring.

App
- /employers/org/[slug]/developers with API keys and Webhooks views, and a
  Developers tab beside Teams and Logs (ROUTES.EMPLOYERS.ORG.DETAIL.DEVELOPERS).
  The organization comes from the slug and is sent with every call.
- DeveloperPortal takes organizationId and canManage. Create, re-scope and
  revoke are offered only to the organization's admins (owner, org `admin`
  role, or team_admin on any of its teams); everyone else gets a read-only list.
- The webhook list, create and a new detail screen (status, stats, events,
  recent deliveries, delete) moved to features/developers. The old list row
  pushed /office/webhooks/:id, which had no route file and was a 404.
- /office/api-keys and /office/webhooks/* redirect for every signed-in user:
  the Office layout skips its role gate for them (isLegacyDevelopersPath), as
  it does for the hiring paths. One organization goes straight to the same
  screen on it; several or none go to My Organizations. Office's own links to
  them are gone.

Api
- lib/org-developer-roles.ts: one rule for membership and admin, read from
  teams, ownership and org-scoped roles. api-keys read teams only, so the
  owner on no team (the seeded orgAdmin) was refused every call; webhooks read
  org-scoped roles only, so a team_admin without one could not create a webhook.
- GET /v1/api-keys takes ?organization_id= and returns organization_id.
- Creating a key or a webhook, and deleting a webhook, now need admin, like
  revoking a key already did.
- GET /v1/webhooks/{id} and /{id}/deliveries, which the SDK called and the api
  never served. List and detail no longer carry the signing secret.

SDK pointer: Scaffald/sdk#44 (organization_id on list and create).

Tests: tests/routers/org-developers-rest.test.ts (gated) covers the orgAdmin
persona, a team_admin of two organizations without the office role, a plain
member and an outsider. api-keys-org-authz-rest.test.ts uses a fresh plain
member: the seeds give nikola the org-scoped admin role.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(webhooks): declare each route's error responses, so the handlers type-check (#1440)

The openapi routes declared only their success response, so every
c.json(..., 401/403/404/500) was a type error: three on main, two more from
the detail and deliveries routes this PR added. Each route now declares the
errors it returns, and the success returns name their 200. webhooks.ts goes
from 5 type errors to 0, so its TYPECHECK_BASELINE entry (3) is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@thinkclay
thinkclay deleted the feat/org-scoped-keys-webhooks-1440 branch November 26, 2026 00:41
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