Skip to content

Correct billing and org references against clerk_go - #119

Merged
manovotny merged 3 commits into
mainfrom
manovotny/reconcile-refs-clerk-go-e11ab0
Nov 11, 2026
Merged

manovotny merged 3 commits into
mainfrom
manovotny/reconcile-refs-clerk-go-e11ab0

Conversation

@manovotny

@manovotny manovotny commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

What does this solve? What changed?

While reviewing #118, I checked the billing and org references against clerk_go and found three claims that were wrong before #118. They're outside its diff, so they're fixed here. Nothing overlaps #118's changes, and the two merge cleanly in either order.

  • clerk-billing/references/billing-webhooks.md: The reference said subscriptionItem events can't be tied back to their subscription. They can. CommerceSubscriptionItemEvent sets subscription_id on every standalone event, and webhooks are always standalone. The webhook OpenAPI schema (BillingSubscriptionItemEventPayload.yml) documents it too. The handler now upserts item rows by their item id and stores subscription_id as the link to the subscription. The Payload Shape bullet and Key Rules line say the same.
  • The same handler read canceled_at and past_due_at, which the webhook payload doesn't include. It now uses updated_at. The item payload block lists the fields Clerk actually sends, and a note covers where @clerk/backend's BillingSubscriptionItemWebhookEventJSON differs from the payload: it's missing subscription_id and updated_at, and it declares canceled_at, past_due_at, and amount.
  • clerk-orgs/references/roles-permissions.md: The catalog said its 8 slugs were the only System Permissions. clerk_go's pkg/constants/roles_and_permissions.go also defines org:sys_api_keys:read, org:sys_api_keys:manage, org:sys_entconns:manage, and org:sys_entconns_sso_bypass:manage. Clerk creates each when its feature is on (API keys, self-serve SSO, SSO bypass) and grants them to org:admin by default. The SSO bypass permission stays after a plan downgrade. org:sys_enterprise_connections:manage is the legacy key that pkg/backfill/rename_entconns_permission_key renames, so the doc calls it out as legacy.
  • clerk-webhooks/SKILL.md: The Subscription Item list had subscriptionItem.created, which isn't in clerk_go's event registry, and was missing subscriptionItem.expired. It now matches the 10 events in pkg/events/event_types.go.

@clerk/backend's types have the same drift: BillingSubscriptionItemWebhookEvent lists subscriptionItem.created, omits subscriptionItem.expired, and the item JSON type lacks subscription_id. That's a clerk/javascript fix, not part of this PR.

Deadline

Other resources

🤖 Generated with Claude Code

manovotny and others added 2 commits November 10, 2026 17:14
subscriptionItem webhooks carry subscription_id, so the billing handler
links items to their subscription and falls back to payer + plan slug.
The item payload block now lists the fields Clerk sends.

The org System Permissions catalog adds the API key, enterprise
connection, and SSO bypass permissions, with the feature each needs.

The clerk-webhooks event list drops subscriptionItem.created, which
Clerk never sends, and adds subscriptionItem.expired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clerk grants the feature-gated permissions to org:admin by default, and
other roles can be given them. The SSO bypass permission survives a plan
downgrade. Also drop a repeated type-widening instruction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@manovotny
manovotny marked this pull request as ready for review November 10, 2026 23:18
@manovotny
manovotny requested review from a team as code owners November 10, 2026 23:18
@SarahSoutoul SarahSoutoul self-assigned this Nov 10, 2026
A subscription can hold several items on the same plan over time, so
subscription id plus plan slug can match more than one row. The handler
now upserts by evt.data.id and stores subscription_id as the link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@manovotny
manovotny merged commit 8f82673 into main Nov 11, 2026
6 checks passed
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.

2 participants