Skip to content

feat(api): invitations CRUD - #2983

Merged
vitorbari merged 6 commits into
mainfrom
2852-invitations-api
Nov 12, 2026
Merged

vitorbari merged 6 commits into
mainfrom
2852-invitations-api

Conversation

@vitorbari

@vitorbari vitorbari commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Context

Summary

  • POST /invitations creates a project_member invitation and returns its link ({console}/invitations/accept#token=…) once:
    • refused on a server without a platform project, and for an unclaimed project;
    • the token is stored only as its hash;
    • metadata is encrypted with the project's key;
    • expires after 72 hours;
    • the pending cap (MaxPendingInvitations, 100) is counted under LockProject.
  • With replaces_invitation_id it replaces:
    • the new invitation keeps the original's journey_id and, without metadata of its own, takes the original's;
    • the original is deleted in the same transaction, whether pending, expired or rejected, and before the cap count. The list holds one invitation per journey, and the events keep the history;
    • an accepted original is refused with the same 404 as an unknown id.
  • GET /invitations lists newest first, with status and type filters. GET /invitations/{id} reads one. DELETE /invitations/{id} cancels a pending one. All four run the same project admin check as POST /grants.
  • Events:
    • create and replace emit invitation.created;
    • cancel emits invitation.cancelled with reason cancelled;
    • the original a replace deletes emits it with reason replaced and replaced_by_invitation_id;
    • both types move from the catalog's Contracted table to Path B;
    • no payload carries the metadata or the token.
  • A missing invitation and a finished one answer the same 404 inv.not_found, so inv.not_pending is no longer in the generated error unions.
  • team_member still answers 501. Lookup, accept and reject stay stubbed for Invitations: look up, accept and decline by link #2853.
  • ADR 086 gets a dated amendment for the replace rule, and the contract's replace wording follows it.
  • Storage: ClearInvitationMetadata from feat: add the invitations table and its statements #2980, whose only caller was replace, gives way to DeleteUnacceptedInvitation, with a stmttest suite.

Notes

  • Cancel is unchanged: it deletes only a pending invitation, and an expired one keeps its row until the cleanup job exists, as the contract says.
  • Deleting a project already removes its invitations through the cascade. The only ownership change today is claiming, which applies to unclaimed projects, and those can't hold invitations, so there is no hook for owner changes.
  • link is a plain string, not format: uri: ogen decodes a uri with url.ParseRequestURI, which would keep #token=… in the path and escape the # in the Go client.
  • I picked the cap of 100 myself; ADR 086 leaves the number open.
  • From review on feat: add the invitations table and its statements #2980: TestInvitation_StatusAt now runs in parallel.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cloud Ready Ready Preview Nov 11, 2026 3:56pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: 1d01598

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

This PR includes changesets to release 25 packages
Name Type
@zitadel/server Minor
@zitadel/cli Minor
@zitadel/testing Minor
@zitadel/server-linux-x64 Minor
@zitadel/server-linux-arm64 Minor
@zitadel/server-darwin-x64 Minor
@zitadel/server-darwin-arm64 Minor
@zitadel/server-win32-x64 Minor
@zitadel/api Minor
@zitadel/config Minor
@zitadel/components Minor
@zitadel/sdk-core Minor
@zitadel/sdk-next Minor
@zitadel/sdk-nuxt Minor
@zitadel/sdk-react Minor
@zitadel/sdk-vue Minor
@zitadel/sdk-angular Minor
@zitadel/sdk-solid Minor
@zitadel/sdk-svelte Minor
@zitadel/sdk-qwik Minor
@zitadel/sdk-sveltekit Minor
@zitadel/sdk-solid-start Minor
@zitadel/sdk-qwik-router Minor
@zitadel/sdk-tanstack-start Minor
@zitadel/cloud Patch

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

@vitorbari vitorbari changed the title feat(api): create, list, read, cancel and replace invitations feat(api): invitations CRUD Nov 11, 2026
)

// InvitationExpiration is how long an invitation's link can be redeemed.
const InvitationExpiration = 72 * time.Hour

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this iteration, we are keeping the 72h non-customizable.

Base automatically changed from 2851-invitations-storage to main November 11, 2026 14:45
vitorbari and others added 3 commits November 11, 2026 15:48
Project administrators manage a project's invitations over the API
(ADR 086 §4, §7, §10). Create mints a link token and a journey id,
encrypts the metadata with the project's key and holds the pending cap
under the project lock; replace keeps the original's journey, moves its
metadata and deletes a pending original in the same transaction. Event
emission waits for the event contract (#2850).

Refs #2852

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A replace now deletes an expired or rejected original too, so the list
holds one invitation per journey; the events keep the history. Storage
swaps ClearInvitationMetadata, which only replace used, for
DeleteUnacceptedInvitation. ADR 086 gets a dated amendment, and the
contract's replace wording follows.

Refs #2852

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Create and replace emit invitation.created; cancel and the original a
replace deletes emit invitation.cancelled, with reason cancelled or
replaced. Both types move from the catalog's Contracted section to
Path B, and their webhooks stop saying they are not sent yet.

Also runs TestInvitation_StatusAt in parallel, from review on #2980.

Refs #2852

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A key lookup inside the transaction takes a second pool connection, which
deadlocks on SQLite. Also emits the replaced original's cancelled event
before the new one's created, shares the claimed-project guard with grants,
and reuses randomSecret for invitation tokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Passing the sentinel as a func value hid it from gen_openapi_errors, which
dropped project_unclaimed from the grant and invitation error unions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vitorbari
vitorbari marked this pull request as ready for review November 11, 2026 15:25
Copilot AI balanced review requested due to automatic review settings November 11, 2026 15:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The shareable-link assertion accepts a URL that encodes the token fragment into the path, breaking redemption and exposing the token to potential proxy or access logging.

1 open issue
What changed in this PR

Implements the invitation-management API for project administrators, building on the invitation storage layer from #2980. Link lookup, acceptance and rejection remain deferred to #2853.

Changes:

  • Adds create, list, read, cancel and replace operations with encrypted metadata, hashed tokens, 72-hour expiry and a pending-invitation cap.
  • Implements transactional replacement and invitation lifecycle events across all three storage dialects.
  • Updates the API contract, generated Go code, documentation and tests.
File Description
packages/​go/​api/​oas_schemas_gen.go Regenerates client error types and lifecycle comments.
packages/​go/​api/​oas_json_gen.go Adds client serialization for newly reachable errors.
packages/​go/​api/​oas_client_gen.go Updates generated replacement comments.
docs/​design/​api/​events-catalog.md Marks create and cancel event producers as implemented.
docs/​adrs/​086-invitations.md Amends replacement to delete unaccepted originals.
apps/​api/​internal/​storage/​stmttest/​invitation_test.go Tests deletion of unaccepted invitations.
apps/​api/​internal/​storage/​dialect/​sqlite/​invitation.go Implements unaccepted-invitation deletion for SQLite.
apps/​api/​internal/​storage/​dialect/​spanner/​invitation.go Implements unaccepted-invitation deletion for Spanner.
apps/​api/​internal/​storage/​dialect/​postgres/​invitation.go Implements unaccepted-invitation deletion for PostgreSQL.
apps/​api/​internal/​service/​statement.go Updates the invitation storage interface.
apps/​api/​internal/​service/​mocks/​service.mock.go Regenerates mocks for the storage interface.
apps/​api/​internal/​service/​invitation.go Implements invitation management and audit events.
apps/​api/​internal/​service/​invitation_test.go Covers service lifecycle, validation and metadata handling.
apps/​api/​internal/​service/​grant.go Reuses the shared project-claim exemption check.
apps/​api/​internal/​service/​event_claim.go Adds the shared claim-check helper.
apps/​api/​internal/​domain/​invitation.go Adds token generation, expiry and metadata definitions.
apps/​api/​internal/​domain/​invitation_test.go Runs status tests in parallel.
apps/​api/​internal/​domain/​auth_check_type_sso.go Generalizes the random-secret error message.
apps/​api/​internal/​audit/​catalog_producers_test.go Registers implemented invitation event producers.
apps/​api/​internal/​api/​invitation.go Connects admin endpoints to the invitation service.
apps/​api/​internal/​api/​integration_test/​invitation_test.go Adds API lifecycle and event integration tests.
apps/​api/​internal/​api/​integration_test/​helpers/​server.go Wires the invitation service into the test server.
apps/​api/​internal/​api/​handler.go Adds the invitation service dependency.
apps/​api/​internal/​api/​generated/​oas_unimplemented_gen.go Updates generated replacement comments.
apps/​api/​internal/​api/​generated/​oas_server_gen.go Updates generated handler-interface comments.
apps/​api/​internal/​api/​generated/​oas_schemas_gen.go Regenerates server error types and lifecycle comments.
apps/​api/​internal/​api/​generated/​oas_json_gen.go Adds server serialization for newly reachable errors.
apps/​api/​internal/​api/​generated/​oas_handlers_gen.go Updates generated request-handler comments.
apps/​api/​cmd/​server/​server.go Wires the invitation service into server startup.
apps/​api/​api/​openapi/​endpoints/​invitations/​methods.yaml Documents replacement behavior and accepted-target errors.
apps/​api/​api/​openapi/​endpoints/​invitations/​invitation-status.yaml Updates lifecycle deletion wording.
apps/​api/​api/​openapi/​endpoints/​invitations/​invitation-metadata.yaml Documents metadata transfer during replacement.
apps/​api/​api/​openapi/​endpoints/​invitations/​invitation-common.yaml Updates metadata lifecycle wording.
apps/​api/​api/​openapi/​endpoints/​invitations/​createInvitation-error-response.yaml Regenerates the create error contract.
apps/​api/​api/​openapi/​endpoints/​invitations/​create-invitation-common.yaml Documents replacement restrictions and metadata inheritance.
apps/​api/​api/​openapi/​endpoints/​invitations/​by_id/​cancelInvitation-error-response.yaml Regenerates the cancel error contract.
apps/​api/​api/​openapi/​endpoints/​events/​webhooks/​invitation-created.yaml Removes the unimplemented-producer notice.
apps/​api/​api/​openapi/​endpoints/​events/​webhooks/​invitation-cancelled.yaml Documents implemented cancellation and replacement events.
apps/​api/​api/​openapi/​bundled/​openapi.json Refreshes the bundled API contract.
apps/​api/​api/​cmd/​gen_openapi_errors/​main.go Excludes the internally remapped not-pending error.
apps/​api/​api/​cmd/​gen_event_schemas/​main.go Updates invitation event generation metadata.
.changeset/​invitations-admin-api.md Adds the server feature release note.

Review effort: Balanced

With format: uri, ogen decodes the link through url.ParseRequestURI, which
keeps #token= in Path, so String() escapes it to %23. A plain string keeps
the link as the server sent it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review reports no active issues blocking approval of the invitation-management API changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@mridang

mridang commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Looks good. I ran the invitation tests on this branch and they pass, and I checked the cap, replace at the cap, concurrent replace, cross-project ids and pagination against SQLite: all behave as described. The only gap I found is that none of those cases has an HTTP-level integration test yet, so adding some would be worthwhile, but it doesn't block merging.

@vitorbari
vitorbari added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit 02a415d Nov 12, 2026
26 of 27 checks passed
@vitorbari
vitorbari deleted the 2852-invitations-api branch November 12, 2026 10:11
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Nov 12, 2026

This branch was successfully deployed

1 active deployment
Preview — 1d01598d Deployed Nov 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Invitations: create, list, read, cancel and replace

3 participants