Repository navigation
feat(api): invitations CRUD - #2983
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 1d01598 The changes in this PR will be included in the next version bump. This PR includes changesets to release 25 packages
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 |
| ) | ||
|
|
||
| // InvitationExpiration is how long an invitation's link can be redeemed. | ||
| const InvitationExpiration = 72 * time.Hour |
There was a problem hiding this comment.
In this iteration, we are keeping the 72h non-customizable.
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>
d1549a2 to
42796cb
Compare
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>
There was a problem hiding this comment.
🟡 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>
|
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. |

Context
Summary
POST /invitationscreates aproject_memberinvitation and returns its link ({console}/invitations/accept#token=…) once:metadatais encrypted with the project's key;MaxPendingInvitations, 100) is counted underLockProject.replaces_invitation_idit replaces:journey_idand, without metadata of its own, takes the original's;404as an unknown id.GET /invitationslists newest first, withstatusandtypefilters.GET /invitations/{id}reads one.DELETE /invitations/{id}cancels a pending one. All four run the same projectadmincheck asPOST /grants.invitation.created;invitation.cancelledwith reasoncancelled;replacedandreplaced_by_invitation_id;404 inv.not_found, soinv.not_pendingis no longer in the generated error unions.team_memberstill answers501. Lookup, accept and reject stay stubbed for Invitations: look up, accept and decline by link #2853.ClearInvitationMetadatafrom feat: add the invitations table and its statements #2980, whose only caller was replace, gives way toDeleteUnacceptedInvitation, with astmttestsuite.Notes
linkis a plain string, notformat: uri: ogen decodes a uri withurl.ParseRequestURI, which would keep#token=…in the path and escape the#in the Go client.TestInvitation_StatusAtnow runs in parallel.🤖 Generated with Claude Code