openapi: 3.1.0 info: title: Tenant Registry version: 0.1.0 description: | Internal platform API. Owns the multi-tenant glue: tenants, projects, product entitlements, API keys, audit log. See `PLATFORM_ARCHITECTURE.md §5c` for the schema, and `PRODUCT_INTEGRATION_SPEC.md §8.4` for the audit shape. Auth (RBAC Phase 1): with AUTH_ENABLED=true every route except /healthz, /readyz and /version requires a Keycloak-issued bearer token whose audience contains AUTH_EXPECTED_AUDIENCE (INTERNAL_SERVICE_ONLY posture). With AUTH_ENABLED=false (dev default) the API is open. Per-client authorization (M-MIG-5): AUTHZ_RULES maps each client (JWT azp) to route groups — tenants(.read|.write), catalog, entitlements, api-keys(.verify), audit(.read|.write), users, keycloak, erp, usage, licences. Unlisted clients get 403. Tenant status ladder (ERP/02): demo, trial, active (Betriebsbereit), warning (Warnung), restricted (Eingeschränkt, read-only), halted (Angehalten), archived. 'frozen' is legacy = restricted. contact: email: oncall@breakpilot.com license: name: Proprietary servers: - url: http://localhost:8090 description: Local dev - url: https://registry-stage.breakpilot.com description: Stage - url: https://registry.breakpilot.com description: Production paths: /healthz: get: summary: Liveness probe responses: "200": description: Always returns ok. content: application/json: schema: type: object properties: { status: { type: string, example: ok } } /version: get: summary: Build version and commit (public, no auth). responses: "200": description: The build the registry runs; "dev" and "" for a local build. content: application/json: schema: type: object required: [version, commit] properties: version: { type: string, example: v0.1.4 } commit: { type: string, description: full git commit hash } /readyz: get: summary: Readiness probe — pings the store. responses: "200": description: Store reachable. "503": description: Store unreachable. content: application/json: { schema: { $ref: "#/components/schemas/Error" } } /v1/tenants: get: summary: List tenants (service-only; keyset paginated). parameters: - in: query name: status schema: { $ref: "#/components/schemas/TenantStatus" } - in: query name: kind schema: { type: string, enum: [customer, demo] } - in: query name: limit schema: { type: integer, minimum: 1, maximum: 500, default: 100 } - in: query name: cursor schema: { type: string, description: "next_cursor from the previous page" } responses: "200": description: Page of tenants; next_cursor omitted on the last page. content: application/json: schema: type: object properties: items: type: array items: { $ref: "#/components/schemas/Tenant" } next_cursor: { type: string } "400": { $ref: "#/components/responses/BadRequest" } post: summary: Create a tenant. description: | Creates the tenant row, and if `admin_email` is provided, also creates a Keycloak organization + invites the user as IT_ADMIN. Keycloak failures DO NOT roll the tenant back — they emit a `keycloak.provision_failed` audit event so the operator can resend the invite from the KC admin UI. requestBody: required: true content: application/json: { schema: { $ref: "#/components/schemas/TenantCreate" } } responses: "201": description: Created. `invite_url` is non-empty when an `admin_email` was passed and Keycloak provisioning succeeded. content: application/json: { schema: { $ref: "#/components/schemas/TenantCreated" } } "400": { $ref: "#/components/responses/BadRequest" } "409": { $ref: "#/components/responses/Conflict" } /v1/tenants/{id}: get: summary: Get tenant by id. parameters: - in: path name: id required: true schema: { type: string, format: uuid } responses: "200": description: Found. content: application/json: { schema: { $ref: "#/components/schemas/Tenant" } } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/by-slug/{slug}: get: summary: Get tenant by slug. parameters: - in: path name: slug required: true schema: { type: string, pattern: '^[a-z0-9][a-z0-9-]{1,38}[a-z0-9]$' } responses: "200": description: Found. content: application/json: { schema: { $ref: "#/components/schemas/Tenant" } } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/activate: post: summary: Move tenant to status=active. parameters: - in: path name: id required: true schema: { type: string, format: uuid } requestBody: required: false content: application/json: { schema: { $ref: "#/components/schemas/TenantActivate" } } responses: "200": description: Updated. content: application/json: { schema: { $ref: "#/components/schemas/Tenant" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/status: post: summary: Move a tenant along the status ladder (ERP link, Backstage). description: | The one transition endpoint outside activate/cancel. Syncs the coarse `tenant_status` claim to every Keycloak member of the tenant's organization and writes a `tenant.status_changed` audit event. parameters: - in: path name: id required: true schema: { type: string, format: uuid } requestBody: required: true content: application/json: schema: type: object required: [status] properties: status: { $ref: "#/components/schemas/TenantStatus" } reason: { type: string } source: { type: string, enum: [erp, backstage, system, test] } responses: "200": description: Updated. content: application/json: { schema: { $ref: "#/components/schemas/Tenant" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/cancel: post: summary: Move tenant to status=halted (Angehalten). parameters: - in: path name: id required: true schema: { type: string, format: uuid } requestBody: required: false content: application/json: { schema: { $ref: "#/components/schemas/TenantCancel" } } responses: "200": description: Updated. content: application/json: { schema: { $ref: "#/components/schemas/Tenant" } } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/documents: get: summary: A tenant's published documents. description: Served by the same `{id}/{sub}` route as members; user tokens reach their own tenant only. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } responses: "200": description: Published documents, newest first. content: application/json: schema: { type: object, properties: { items: { type: array, items: { $ref: "#/components/schemas/Document" } } } } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/projects: get: summary: A tenant's projects (Projekte), by name. description: | Served by the `{id}/{sub}` route; user tokens reach their own tenant only. Products read it with their service token (tenants.read) to validate project ids on their own objects. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } responses: "200": description: The projects. content: application/json: schema: { type: object, properties: { items: { type: array, items: { $ref: "#/components/schemas/Project" } } } } "404": { $ref: "#/components/responses/NotFound" } post: summary: Create a project. description: | The portal calls this for staff (X-Staff-* headers) and for tenant admins (it checks their org role and names them in X-Portal-User-Email). Names are unique per tenant, ignoring case. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } requestBody: required: true content: application/json: { schema: { $ref: "#/components/schemas/ProjectWrite" } } responses: "201": description: Created. content: application/json: { schema: { $ref: "#/components/schemas/Project" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "409": { description: A project with this name exists (name_taken). } /v1/tenants/{id}/projects/{pid}: patch: summary: Rename or change a project (fields given are changed). parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: pid, required: true, schema: { type: string, format: uuid } } requestBody: required: true content: application/json: { schema: { $ref: "#/components/schemas/ProjectWrite" } } responses: "200": description: The project. content: application/json: { schema: { $ref: "#/components/schemas/Project" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "409": { description: A project with this name exists (name_taken). } delete: summary: Delete a project. Its documents stay; they lose the assignment. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: pid, required: true, schema: { type: string, format: uuid } } responses: "204": { description: Deleted. } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/projects/{pid}/targets: get: summary: The project's Prüfwerk objects (read from Prüfwerk). description: | The registry asks Prüfwerk's platform API with its service token. When Prüfwerk cannot answer, `items` is empty and `available` false. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: pid, required: true, schema: { type: string, format: uuid } } responses: "200": description: The objects. content: application/json: schema: type: object properties: available: { type: boolean } items: type: array items: type: object properties: id: { type: string } name: { type: string } target_type: { type: string } last_scan_at: { type: string, format: date-time } open_findings: { type: integer } project_ids: { type: array, items: { type: string } } url: { type: string, description: The object in the Prüfwerk dashboard. } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/managed-services: get: summary: A tenant's managed services (Verwaltete Infrastruktur), oldest first. description: | Served by the `{id}/{sub}` route; user tokens reach their own tenant only and need the org role IT_ADMIN, OWNER or CXO (else 403 FORBIDDEN_ROLE). Service clients read with tenants.read. Never carries instance_id or notes. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } responses: "200": description: The services, by created_at. content: application/json: schema: { type: object, required: [items], properties: { items: { type: array, items: { $ref: "#/components/schemas/ManagedService" } } } } "403": { description: The user's org role may not see managed services (FORBIDDEN_ROLE). } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/members: get: summary: List the tenant's Keycloak organization members. description: | The portal's Settings/Users page. A user token may only read its own tenant — another tenant's id answers 404, never a hint that it exists. Service clients are gated on the `tenants.read` route group. A tenant whose organization was never created (sales-led) answers with an empty list rather than an error. parameters: - in: path name: id required: true schema: { type: string, format: uuid } responses: "200": description: Members of the organization. content: application/json: schema: type: object required: [members] properties: members: type: array items: { $ref: "#/components/schemas/OrgMember" } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/invites: post: summary: Invite a user into the tenant's organization. description: | Creates the Keycloak user if needed, adds it to the tenant's organization, writes the tenant-context user attributes and sends the same execute-actions email the first admin receives. Idempotent: an existing member answers `200 {status: member}` and sends no mail. User tokens need the `IT_ADMIN` or `OWNER` org role; service clients need the `tenants.write` route group. parameters: - in: path name: id required: true schema: { type: string, format: uuid } requestBody: required: true content: application/json: schema: type: object required: [email] properties: email: { type: string, format: email } first_name: { type: string, maxLength: 100 } last_name: { type: string, maxLength: 100 } role: type: string pattern: '^[A-Z][A-Z0-9_]{1,31}$' default: USER description: "org_roles attribute written for the user" responses: "202": description: Invited; the mail is on its way. content: application/json: { schema: { $ref: "#/components/schemas/Invite" } } "200": description: Already a member; nothing sent. content: application/json: { schema: { $ref: "#/components/schemas/Invite" } } "400": { $ref: "#/components/responses/BadRequest" } "403": { $ref: "#/components/responses/Forbidden" } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/members/{uid}: patch: summary: Change a member's role, or block / unblock the member in this workspace. description: | User tokens need IT_ADMIN or OWNER in their own tenant; service clients the `tenants.write` route group. The portal names the acting person in `X-Portal-User-Subject` / `X-Portal-User-Email`. Send exactly one of `role` or `blocked`. A role change rewrites the member's `org_roles` attribute and takes effect at the member's next login or token refresh. A block is per workspace: the tenant id is added to the member's `org_blocked` user attribute (never `enabled=false`), the member's Keycloak sessions are ended (realm wide) and their active API keys are listed for revocation, not revoked. Guards (409): `self` — nobody changes their own membership; `last_admin` — the last active IT_ADMIN/OWNER cannot be demoted or blocked. Audit: `user.role_changed` (from → to), `user.blocked`, `user.unblocked`. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: uid, required: true, schema: { type: string }, description: Keycloak user id of the member } requestBody: required: true content: application/json: schema: type: object properties: role: { type: string, enum: [IT_ADMIN, OWNER, CXO, FINANCE, LEGAL, USER] } blocked: { type: boolean } responses: "200": description: Done (or `unchanged`). content: application/json: { schema: { $ref: "#/components/schemas/MemberAction" } } "400": { $ref: "#/components/responses/BadRequest" } "403": { $ref: "#/components/responses/Forbidden" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } delete: summary: Remove a member, or revoke a pending invitation. description: | User tokens need IT_ADMIN or OWNER in their own tenant; service clients the `tenants.write` route group. The portal names the acting person in `X-Portal-User-Subject` / `X-Portal-User-Email`. An accepted member loses the organization membership and the workspace attributes; their sessions are ended and their active API keys are listed for revocation (`user.removed`). A pending invitation (no password set yet) is revoked: the membership goes, and the Keycloak account is deleted only when this tenant's invitation created it and it belongs to no other organization — which also voids the link in the invitation mail (`user.invite_revoked`). Guards as for PATCH. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: uid, required: true, schema: { type: string }, description: Keycloak user id of the member } responses: "200": description: Removed or revoked. content: application/json: { schema: { $ref: "#/components/schemas/MemberAction" } } "403": { $ref: "#/components/responses/Forbidden" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } /v1/tenants/{id}/members/{uid}/resend: post: summary: Send a pending member's invitation mail again. description: | User tokens need IT_ADMIN or OWNER in their own tenant; service clients the `tenants.write` route group. The portal names the acting person in `X-Portal-User-Subject` / `X-Portal-User-Email`. 409 `not_pending` when the member has already accepted. Audit: `user.invite_resent`. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: uid, required: true, schema: { type: string }, description: Keycloak user id of the member } responses: "202": description: Sent. content: application/json: { schema: { $ref: "#/components/schemas/MemberAction" } } "403": { $ref: "#/components/responses/Forbidden" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } /v1/admin/tenants: get: summary: Staff tenant list with search and 30-day activity. description: | Route group `admin` (the portal's service client). `q` matches slug, name or admin email, case-insensitively. Each item is a Tenant plus `activity`: usage totals per metric over the last 30 days and the time of the latest audit entry. Changes made through the admin routes are audited under the staff member named in `X-Staff-Subject` / `X-Staff-Email`. parameters: - { in: query, name: q, schema: { type: string, maxLength: 100 } } - { in: query, name: status, schema: { type: string } } - { in: query, name: kind, schema: { type: string } } - { in: query, name: cursor, schema: { type: string } } - { in: query, name: limit, schema: { type: integer, minimum: 1, maximum: 500 } } responses: "200": description: One page of tenants. content: application/json: schema: type: object properties: items: type: array items: allOf: - { $ref: "#/components/schemas/Tenant" } - type: object properties: activity: { $ref: "#/components/schemas/TenantActivity" } next_cursor: { type: string } "400": { $ref: "#/components/responses/BadRequest" } /v1/admin/tenants/{id}: get: summary: Everything staff need about one tenant. description: | Tenant, 30-day activity, entitlements, subscriptions, licences, the latest 25 audit entries and the Keycloak organization members (best effort: on failure `members` is empty and `members_error` says why). parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } responses: "200": description: The tenant detail. content: application/json: schema: type: object properties: tenant: { $ref: "#/components/schemas/Tenant" } activity: { $ref: "#/components/schemas/TenantActivity" } entitlements: { type: array, items: { type: object } } subscriptions: { type: array, items: { type: object } } licences: { type: array, items: { type: object } } members: { type: array, items: { type: object } } members_error: { type: string } audit: { type: array, items: { type: object } } "404": { $ref: "#/components/responses/NotFound" } delete: summary: Delete an archived tenant for good. description: | Removes the document files, the Keycloak organization and the accounts that belong to the tenant, then the tenant with everything attached. The ERP customer and the audit trail stay; a tenant.purged event records who did it. Frees the tenant's name. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: query, name: confirm, required: true, schema: { type: string }, description: The tenant's slug. } responses: "200": { description: Deleted. } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } /v1/admin/tenants/{id}/trial: post: summary: Extend a trial. description: | Moves the trial end `days` after the later of now and the current end, moves trial entitlements with it, and returns a tenant that an expired trial made read-only (and that never had a subscription) to `trial`. Audited as `tenant.trial_extended`. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } requestBody: required: true content: application/json: schema: type: object required: [days] properties: days: { type: integer, minimum: 1, maximum: 90 } responses: "200": description: The updated tenant. content: application/json: { schema: { $ref: "#/components/schemas/Tenant" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } /v1/admin/tenants/{id}/invites/resend: post: summary: Send a member's invitation mail again. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } requestBody: required: true content: application/json: schema: type: object required: [email] properties: email: { type: string, format: email } responses: "202": { description: Sent. } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } /v1/admin/tenants/{id}/members/{uid}: patch: summary: Change a member's role, or block / unblock the member in this workspace. description: | Staff (route group `admin`); attributed to `X-Staff-Subject` / `X-Staff-Email`. Send exactly one of `role` or `blocked`. A role change rewrites the member's `org_roles` attribute and takes effect at the member's next login or token refresh. A block is per workspace: the tenant id is added to the member's `org_blocked` user attribute (never `enabled=false`), the member's Keycloak sessions are ended (realm wide) and their active API keys are listed for revocation, not revoked. Guards (409): `self` — nobody changes their own membership; `last_admin` — the last active IT_ADMIN/OWNER cannot be demoted or blocked. Audit: `user.role_changed` (from → to), `user.blocked`, `user.unblocked`. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: uid, required: true, schema: { type: string }, description: Keycloak user id of the member } requestBody: required: true content: application/json: schema: type: object properties: role: { type: string, enum: [IT_ADMIN, OWNER, CXO, FINANCE, LEGAL, USER] } blocked: { type: boolean } responses: "200": description: Done (or `unchanged`). content: application/json: { schema: { $ref: "#/components/schemas/MemberAction" } } "400": { $ref: "#/components/responses/BadRequest" } "403": { $ref: "#/components/responses/Forbidden" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } delete: summary: Remove a member, or revoke a pending invitation. description: | Staff (route group `admin`); attributed to `X-Staff-Subject` / `X-Staff-Email`. An accepted member loses the organization membership and the workspace attributes; their sessions are ended and their active API keys are listed for revocation (`user.removed`). A pending invitation (no password set yet) is revoked: the membership goes, and the Keycloak account is deleted only when this tenant's invitation created it and it belongs to no other organization — which also voids the link in the invitation mail (`user.invite_revoked`). Guards as for PATCH. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: uid, required: true, schema: { type: string }, description: Keycloak user id of the member } responses: "200": description: Removed or revoked. content: application/json: { schema: { $ref: "#/components/schemas/MemberAction" } } "403": { $ref: "#/components/responses/Forbidden" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } /v1/admin/tenants/{id}/members/{uid}/resend: post: summary: Send a pending member's invitation mail again. description: | Staff (route group `admin`); attributed to `X-Staff-Subject` / `X-Staff-Email`. 409 `not_pending` when the member has already accepted. Audit: `user.invite_resent`. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: uid, required: true, schema: { type: string }, description: Keycloak user id of the member } responses: "202": description: Sent. content: application/json: { schema: { $ref: "#/components/schemas/MemberAction" } } "403": { $ref: "#/components/responses/Forbidden" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } /v1/admin/tenants/{id}/reprovision: post: summary: Repair a tenant's sign-in when its Keycloak organization or admin account is missing. description: | Creates the organization with the admin invited when it is missing, invites the admin into an existing one, or sends the invitation again when the admin is already a member. The admin is the one given, else the tenant's first admin on record. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } requestBody: required: false content: application/json: schema: type: object properties: email: { type: string, format: email } responses: "200": { description: "Done: status is invited, resent or created_mail_failed." } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } /v1/admin/audit: get: summary: The audit log across all tenants (same filters as /v1/audit). parameters: - { in: query, name: tenant_id, schema: { type: string } } - { in: query, name: action, schema: { type: string } } - { in: query, name: cursor, schema: { type: integer } } - { in: query, name: limit, schema: { type: integer, minimum: 1, maximum: 500 } } responses: "200": { description: One page of audit entries. } "400": { $ref: "#/components/responses/BadRequest" } /v1/admin/tenants/{id}/documents: get: summary: A tenant's documents, drafts included (staff). parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } responses: "200": description: The documents, newest first. content: application/json: schema: { type: object, properties: { items: { type: array, items: { $ref: "#/components/schemas/Document" } } } } "404": { $ref: "#/components/responses/NotFound" } post: summary: Upload a document as a draft (staff). description: | multipart/form-data with optional `title` and `description` fields before the `file` part. The file is streamed to object storage (limit DOCUMENTS_MAX_MB, default 200). Allowed: pdf, zip, docx, xlsx, pptx, png, jpg, txt, csv, json, xml. The title defaults to the file name. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } requestBody: required: true content: multipart/form-data: schema: type: object required: [file] properties: title: { type: string, maxLength: 200 } description: { type: string, maxLength: 2000 } own_document: { type: string, enum: ["on", "true", "1"], description: "The tenant's own document: publishing it sends no mail." } project_ids: { type: string, description: "Project ids of the tenant; repeat the field or separate with commas." } file: { type: string, format: binary } responses: "201": description: Stored as a draft. content: application/json: { schema: { $ref: "#/components/schemas/Document" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "413": { description: Larger than the upload limit. } "415": { description: File type not allowed. } "503": { description: Document storage not configured. } /v1/admin/documents/{doc}/publish: post: summary: Publish a draft so the tenant sees it (staff). Idempotent. parameters: - { in: path, name: doc, required: true, schema: { type: string, format: uuid } } responses: "200": description: The published document. content: application/json: { schema: { $ref: "#/components/schemas/Document" } } "404": { $ref: "#/components/responses/NotFound" } /v1/admin/documents/{doc}: patch: summary: Assign a document to projects and mark it as the tenant's own (staff). description: | `project_ids` replaces the set (an empty list removes all); every project must belong to the document's tenant. `own_document` marks the tenant's own files: shown like any other, but publishing them sends no notification. Works on drafts and published documents. parameters: - { in: path, name: doc, required: true, schema: { type: string, format: uuid } } requestBody: required: true content: application/json: schema: type: object properties: project_ids: { type: array, items: { type: string, format: uuid } } own_document: { type: boolean } responses: "200": description: The updated document. content: application/json: { schema: { $ref: "#/components/schemas/Document" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } delete: summary: Delete a document and its file (staff). parameters: - { in: path, name: doc, required: true, schema: { type: string, format: uuid } } responses: "204": { description: Deleted. } "404": { $ref: "#/components/responses/NotFound" } /v1/admin/tenants/{id}/managed-services: get: summary: A tenant's managed services with instance id and notes (staff). parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } responses: "200": description: The services, by created_at. content: application/json: schema: { type: object, required: [items], properties: { items: { type: array, items: { $ref: "#/components/schemas/ManagedServiceAdmin" } } } } "404": { $ref: "#/components/responses/NotFound" } post: summary: Record a managed service of the tenant (staff). description: | Error codes (400): invalid_kind, invalid_name, invalid_url, invalid_sku, invalid_status, invalid_instance_id, invalid_notes. The staff member (X-Staff-Subject / X-Staff-Email) is the audit actor of managed_service.created. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } requestBody: required: true content: application/json: { schema: { $ref: "#/components/schemas/ManagedServiceCreate" } } responses: "201": description: Created. content: application/json: { schema: { $ref: "#/components/schemas/ManagedServiceAdmin" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "409": { description: The tenant has a Git instance at this url (duplicate; several runners may share one). } /v1/admin/tenants/{id}/managed-services/{sid}: patch: summary: Change a managed service (staff); the fields given are changed. description: | The kind is fixed. Same validation as create. Audited as managed_service.updated with the changed fields and, when the status moves, old_status and new_status. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: sid, required: true, schema: { type: string, format: uuid } } requestBody: required: true content: application/json: { schema: { $ref: "#/components/schemas/ManagedServiceUpdate" } } responses: "200": description: The service. content: application/json: { schema: { $ref: "#/components/schemas/ManagedServiceAdmin" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "409": { description: The tenant has a Git instance at this url (duplicate; several runners may share one). } delete: summary: Delete the record of a managed service (staff). parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: sid, required: true, schema: { type: string, format: uuid } } responses: "204": { description: Deleted. } "404": { $ref: "#/components/responses/NotFound" } /v1/tenants/{id}/documents/{doc}/download: get: summary: A five-minute download link for a published document. description: | User tokens only reach their own tenant. A service client may name the downloading person in `X-Portal-User-Email` for the audit log. parameters: - { in: path, name: id, required: true, schema: { type: string, format: uuid } } - { in: path, name: doc, required: true, schema: { type: string, format: uuid } } responses: "200": description: The link. content: application/json: schema: type: object properties: url: { type: string } filename: { type: string } content_type: { type: string } expires_at: { type: string, format: date-time } "404": { $ref: "#/components/responses/NotFound" } /v1/notifications: post: summary: Ask the platform to tell a workspace something (route group notify). description: | Products report news for a workspace; the platform mails the members whose org role should hear it (findings.new: IT_ADMIN, OWNER, CXO, LEGAL), in the BreakPilot layout, through an outbox. Demo tenants and tenants without an organization get nothing. Idempotent per idempotency_key. requestBody: required: true content: application/json: schema: type: object required: [tenant_id, kind, idempotency_key, data] properties: tenant_id: { type: string, format: uuid } kind: { type: string, enum: [findings.new] } idempotency_key: { type: string, maxLength: 200 } data: type: object required: [target_name, new_count] properties: target_name: { type: string, maxLength: 200 } new_count: { type: integer, minimum: 1 } critical: { type: integer } high: { type: integer } medium: { type: integer } low: { type: integer } url: { type: string, description: "https link into the product; defaults to the portal dashboard" } responses: "202": description: Queued (queued = number of recipients, 0 for a repeat). content: application/json: { schema: { type: object, properties: { queued: { type: integer } } } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } /v1/entitlements: get: summary: List product entitlements for a tenant. parameters: - in: query name: tenant_id required: true schema: { type: string, format: uuid } responses: "200": description: List response. content: application/json: schema: type: object properties: items: type: array items: { $ref: "#/components/schemas/TenantProduct" } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } /v1/internal/entitlements/check: post: summary: Is this tenant entitled to this product (and add-on) right now? description: | The authoritative entitlement answer (PRODUCT_INTEGRATION_SPEC 2.0 §4.4). Products cache it for ≤ 60 s and fail closed when the registry is unreachable. `read_only` reflects the ladder (restricted); `halted` and `archived` are never allowed. requestBody: required: true content: application/json: schema: type: object required: [tenant_id, product] properties: tenant_id: { type: string, format: uuid } product: { type: string } addon: { type: string, description: "add-on id from the catalog, e.g. werkbank" } user_id: { type: string, description: "optional Keycloak user id; a member blocked in the tenant gets reason member_blocked (portal#74)" } responses: "200": description: Decision. content: application/json: { schema: { $ref: "#/components/schemas/EntitlementCheck" } } "400": { $ref: "#/components/responses/BadRequest" } /v1/catalog: get: summary: List the products available for any tenant to request. responses: "200": description: Catalog. content: application/json: schema: type: object properties: items: type: array items: { $ref: "#/components/schemas/CatalogEntry" } /v1/catalog/request: post: summary: Request a product (creates an audit event; sales follows up). requestBody: required: true content: application/json: { schema: { $ref: "#/components/schemas/CatalogRequest" } } responses: "202": description: Accepted. "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } /v1/catalog/trial-request: post: summary: Self-serve a 14-day trial. requestBody: required: true content: application/json: { schema: { $ref: "#/components/schemas/CatalogRequest" } } responses: "201": description: Trial entitlement created. content: application/json: { schema: { $ref: "#/components/schemas/TenantProduct" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } /v1/api-keys: get: summary: List API keys for a tenant. parameters: - in: query name: tenant_id required: true schema: { type: string, format: uuid } responses: "200": description: List response. The plaintext key is NOT returned; use the create endpoint and store the value immediately. content: application/json: schema: type: object properties: items: type: array items: { $ref: "#/components/schemas/APIKey" } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } post: summary: Create an API key. The plaintext is returned ONCE. requestBody: required: true content: application/json: { schema: { $ref: "#/components/schemas/APIKeyCreate" } } responses: "201": description: Created. The plaintext field is shown only here. content: application/json: { schema: { $ref: "#/components/schemas/APIKeyCreated" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } /v1/api-keys/{id}: delete: summary: Revoke an API key (sets revoked_at). parameters: - in: path name: id required: true schema: { type: string, format: uuid } responses: "204": description: Revoked. "404": { $ref: "#/components/responses/NotFound" } /v1/users/{id}/memberships: get: summary: Resolve which tenants a user belongs to (membership authority). description: | The B2 membership-authority endpoint (ratified compliance auth design). Product backends call this with the JWT `sub` instead of trusting token claims or client-supplied headers. Keycloak supplies the user→tenant links and org_roles; where the tenant is registered here, tenant_status / plan / products are overridden from registry tables (source: "registry"), otherwise the Keycloak attribute projection is returned as-is (source: "keycloak"). parameters: - name: id in: path required: true description: Keycloak user id (the JWT `sub`). schema: { type: string } responses: "200": description: Memberships (possibly empty) for the user. content: application/json: schema: type: object required: [user_id, memberships] properties: user_id: { type: string } memberships: type: array items: allOf: - $ref: "#/components/schemas/Claims" - type: object required: [source] properties: source: { type: string, enum: [registry, keycloak] } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } "503": description: Keycloak unreachable — membership cannot be resolved. content: application/json: { schema: { $ref: "#/components/schemas/Error" } } /v1/internal/keycloak/claims: post: summary: Resolve the up-to-date claim bundle for a user/tenant. description: | Called by Keycloak's protocol mapper at token issuance (or by any operator on demand) to fetch the current tenant_id / tenant_slug / org_roles / products / plan / tenant_status claims. Lookup tries tenant_id, then tenant_slug, then user_attrs.tenant_id, then user_attrs.tenant_slug. requestBody: required: true content: application/json: schema: type: object properties: tenant_id: { type: string, format: uuid } tenant_slug: { type: string } user_attrs: type: object additionalProperties: { type: string } responses: "200": description: Resolved claim bundle. content: application/json: { schema: { $ref: "#/components/schemas/Claims" } } "400": { $ref: "#/components/responses/BadRequest" } "404": { $ref: "#/components/responses/NotFound" } /v1/internal/api-keys/verify: post: summary: Verify an API key. Used by headless products. Returns 200 with valid=false on any failure (never 401). requestBody: required: true content: application/json: schema: type: object required: [key] properties: key: { type: string } responses: "200": description: Verification result. content: application/json: { schema: { $ref: "#/components/schemas/APIKeyVerify" } } /v1/audit: post: summary: Append an audit event. requestBody: required: true content: application/json: { schema: { $ref: "#/components/schemas/AuditAppend" } } responses: "201": description: Created. content: application/json: { schema: { $ref: "#/components/schemas/AuditEvent" } } "400": { $ref: "#/components/responses/BadRequest" } get: summary: List audit events (paginated, cursor-based). parameters: - in: query name: tenant_id schema: { type: string, format: uuid } - in: query name: product schema: { type: string } - in: query name: actor_id schema: { type: string } - in: query name: action schema: { type: string } - in: query name: since schema: { type: string, format: date-time } - in: query name: until schema: { type: string, format: date-time } - in: query name: limit schema: { type: integer, minimum: 1, maximum: 500 } - in: query name: cursor schema: { type: integer, format: int64 } responses: "200": description: Paginated response. next_cursor is omitted when there are no more pages. content: application/json: schema: type: object properties: items: type: array items: { $ref: "#/components/schemas/AuditEvent" } next_cursor: type: integer format: int64 "400": { $ref: "#/components/responses/BadRequest" } /v1/internal/erp/webhook: post: summary: ERPNext webhook receiver (HMAC-signed, no bearer token). description: | PUBLIC_EXPLICIT. Body is signed with ERP_WEBHOOK_SECRET (X-Frappe-Webhook-Signature = base64 HMAC-SHA256, or X-Hub-Signature-256 = sha256=hex). Idempotent by X-Frappe-Event-Id (fallback: hash of event+name+modified+body). Events: sales_order.submit → subscriptions + entitlements + active; sales_invoice.overdue → warning / restricted (days_overdue ≥ ERP_RESTRICT_AFTER_DAYS) / halted; payment_entry.submit → active; subscription.cancel → halted. Unknown customers are acknowledged (202). requestBody: required: true content: application/json: { schema: { $ref: "#/components/schemas/ErpWebhookEvent" } } responses: "200": { description: "Applied, unchanged or duplicate." } "202": { description: "Ignored (tenant not found)." } "401": { description: Bad signature. } "503": { description: ERP_WEBHOOK_SECRET not configured. } /v1/internal/erp/status: get: summary: ERP link status (outbox backlog, webhook/licence configuration). responses: "200": description: Status. content: application/json: schema: type: object properties: erp_configured: { type: boolean } webhook_enabled: { type: boolean } outbox_pending: { type: integer } licences_enabled: { type: boolean } llm_keys_enabled: { type: boolean } /v1/internal/erp/reconcile: post: summary: Run one reconcile pass now (ops / tests). description: | Mirrors ERP subscriptions for every tenant with an ERP customer and applies the time-based ladder steps (trial expiry, warning → restricted, restricted → halted, halted → archived). Runs every ERP_RECONCILE_INTERVAL in the background as well. responses: "200": description: Report. content: application/json: { schema: { $ref: "#/components/schemas/ReconcileReport" } } /v1/subscriptions: get: summary: Subscriptions mirrored from ERPNext for one tenant. parameters: - in: query name: tenant_id required: true schema: { type: string, format: uuid } responses: "200": description: List. content: application/json: schema: type: object properties: items: type: array items: { $ref: "#/components/schemas/Subscription" } "404": { $ref: "#/components/responses/NotFound" } /v1/usage/events: post: summary: Push usage events (PRODUCT_INTEGRATION_SPEC 2.0 §9.2). description: | One event, an array, or {"events": [...]} (≤ 500). Idempotent by idempotency_key; each new event is forwarded to ERPNext as a Usage Record through the outbox. User tokens may only report for their own tenant. requestBody: required: true content: application/json: schema: oneOf: - $ref: "#/components/schemas/UsageEventIn" - type: array items: { $ref: "#/components/schemas/UsageEventIn" } - type: object properties: events: type: array items: { $ref: "#/components/schemas/UsageEventIn" } responses: "202": description: "Accepted (partial rejections listed)." content: application/json: schema: type: object properties: accepted: { type: integer } duplicates: { type: integer } rejected: { type: array, items: { type: object } } "400": { $ref: "#/components/responses/BadRequest" } get: summary: Query usage events. parameters: - { in: query, name: tenant_id, required: true, schema: { type: string, format: uuid } } - { in: query, name: product, schema: { type: string } } - { in: query, name: metric, schema: { type: string } } - { in: query, name: since, schema: { type: string, format: date-time } } - { in: query, name: until, schema: { type: string, format: date-time } } - { in: query, name: limit, schema: { type: integer, minimum: 1, maximum: 1000 } } responses: "200": description: Newest first. content: application/json: schema: type: object properties: items: type: array items: { $ref: "#/components/schemas/UsageEvent" } "400": { $ref: "#/components/responses/BadRequest" } /v1/licences: post: summary: Issue a CLI licence JWT (Werkpilot, Firmwerk). description: | Requires an active entitlement for the product. User tokens (device flow, tenant-context claims) get a licence for their own tenant; service tokens pass tenant_id. Ed25519-signed (EdDSA), verifiable offline against /.well-known/licence-keys.json; expiry = min(ttl, entitlement expiry). Grace ladder inside the token. For product=werkpilot the registry also provisions a per-tenant LiteLLM virtual key (budget by plan) and returns it once as llm_api_key; a LiteLLM failure does not fail the licence (warnings: ["llm_key_unavailable"]). Revoking the licence deletes the key. requestBody: required: true content: application/json: schema: type: object required: [product] properties: tenant_id: { type: string, format: uuid } product: { type: string } device: { type: string } ttl_days: { type: integer } responses: "201": description: Issued. content: application/json: { schema: { $ref: "#/components/schemas/LicenceIssued" } } "400": { $ref: "#/components/responses/BadRequest" } "403": { description: Not entitled. } "503": { description: Licence signer not configured. } get: summary: List licences of a tenant. parameters: - { in: query, name: tenant_id, required: true, schema: { type: string, format: uuid } } responses: "200": description: List. content: application/json: schema: type: object properties: items: type: array items: { $ref: "#/components/schemas/Licence" } "404": { $ref: "#/components/responses/NotFound" } /v1/licences/{id}/revoke: post: summary: Revoke a licence (next heartbeat reports `revoked`). parameters: - in: path name: id required: true schema: { type: string, format: uuid } responses: "200": description: Revoked. content: application/json: { schema: { $ref: "#/components/schemas/Licence" } } "404": { $ref: "#/components/responses/NotFound" } /v1/licences/heartbeat: post: summary: CLI phone-home (PUBLIC_EXPLICIT — the licence JWT is the credential). description: | Reports ok | warning | degraded | hard_stop | revoked from the tenant ladder and the token's grace policy, records last_seen, and returns a renewed licence once the current one is past half-life while the tenant is still entitled. requestBody: required: true content: application/json: schema: type: object required: [licence] properties: licence: { type: string } responses: "200": description: State. content: application/json: { schema: { $ref: "#/components/schemas/LicenceHeartbeat" } } "401": { description: "Signature invalid or licence unknown." } "503": { description: Licence signer not configured. } /.well-known/licence-keys.json: get: summary: Licence verification keys (JWKS, OKP/Ed25519). PUBLIC_EXPLICIT. responses: "200": description: JWKS. content: application/json: schema: type: object properties: keys: { type: array, items: { type: object } } components: securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT description: | Keycloak-issued token (client_credentials for services). Enforced on all non-health routes when AUTH_ENABLED=true. responses: BadRequest: description: Input failed validation. content: application/json: { schema: { $ref: "#/components/schemas/Error" } } NotFound: description: Resource does not exist. content: application/json: { schema: { $ref: "#/components/schemas/Error" } } Conflict: description: Resource already exists / unique violation. content: application/json: { schema: { $ref: "#/components/schemas/Error" } } Forbidden: description: The caller may not perform this operation. content: application/json: { schema: { $ref: "#/components/schemas/Error" } } schemas: ErpWebhookEvent: type: object required: [event, name] properties: event: { type: string, enum: [sales_order.submit, sales_invoice.overdue, payment_entry.submit, subscription.cancel] } doctype: { type: string } name: { type: string } modified: { type: string } customer: { type: string, description: "ERP customer name (tenants.erp_customer_id)" } tenant_id: { type: string, format: uuid, description: "Custom field on the Customer; preferred over customer" } items: type: array items: type: object properties: item_code: { type: string, description: "Platform SKU" } qty: { type: number } days_overdue: { type: integer } subscription: { type: string } invoice: { type: string } amount: { type: number } ReconcileReport: type: object properties: tenants: { type: integer } erp_checked: { type: integer } changed: { type: array, items: { type: string } } escalated: { type: array, items: { type: string } } errors: { type: array, items: { type: string } } erp_available: { type: boolean } Subscription: type: object properties: id: { type: string, format: uuid } tenant_id: { type: string, format: uuid } product: { type: string } sku: { type: string } plan: { type: string } seats: { type: integer } status: { type: string, enum: [active, cancelled] } erp_sales_order: { type: string } erp_subscription: { type: string } period_start: { type: string, format: date-time } period_end: { type: string, format: date-time } created_at: { type: string, format: date-time } updated_at: { type: string, format: date-time } UsageEventIn: type: object required: [idempotency_key, tenant_id, product, metric] properties: idempotency_key: { type: string } tenant_id: { type: string, format: uuid } product: { type: string } metric: { type: string, description: "e.g. scan.completed, target.added, seat.login" } quantity: { type: number, default: 1 } occurred_at: { type: string, format: date-time } properties: { type: object, additionalProperties: true } UsageEvent: allOf: - $ref: "#/components/schemas/UsageEventIn" - type: object properties: id: { type: integer } received_at: { type: string, format: date-time } erp_synced_at: { type: string, format: date-time } Licence: type: object properties: id: { type: string, format: uuid } kid: { type: string } tenant_id: { type: string, format: uuid } product: { type: string } subject: { type: string } device: { type: string } expires_at: { type: string, format: date-time } revoked_at: { type: string, format: date-time } last_seen_at: { type: string, format: date-time } created_at: { type: string, format: date-time } llm_key_id: { type: string, description: "LiteLLM hashed token id of the key issued with a Werkpilot licence (handle for revoke; never the secret)." } LicenceIssued: type: object properties: id: { type: string, format: uuid } licence: { type: string, description: "EdDSA JWT" } kid: { type: string } expires_at: { type: string, format: date-time } grace: type: object properties: warning_days: { type: integer } degraded_days: { type: integer } hard_stop_days: { type: integer } status: { type: string } llm_api_key: type: string description: | Werkpilot only: per-tenant LiteLLM virtual key (sk-…). Returned in THIS response only — never persisted, never returned again. Absent on heartbeat renewals (the CLI keeps the key it stored) and when LiteLLM is unavailable (see warnings). llm_base_url: { type: string, description: "OpenAI-compatible proxy root the key is valid for." } warnings: type: array items: { type: string, enum: [llm_key_unavailable] } description: Non-fatal issue notes; the licence itself is valid. LicenceHeartbeat: type: object properties: status: { type: string, enum: [ok, warning, degraded, hard_stop, revoked] } tenant_status: { $ref: "#/components/schemas/TenantStatus" } expires_at: { type: string, format: date-time } reason: { type: string } renewed: { $ref: "#/components/schemas/LicenceIssued" } TenantStatus: type: string enum: [demo, trial, active, warning, restricted, frozen, halted, archived] EntitlementCheck: type: object required: [allowed, read_only] properties: allowed: { type: boolean } read_only: { type: boolean } status: { $ref: "#/components/schemas/TenantStatus" } limits: { type: object, additionalProperties: true, description: "tenant_products.config — purchased limits" } expires_at: { type: string, format: date-time, nullable: true } reason: { type: string, enum: [unknown_product, unknown_addon, tenant_not_found, tenant_archived, tenant_halted, entitlement_disabled, entitlement_expired, addon_not_purchased, not_entitled, member_blocked, user_unknown] } ProductAddon: type: object required: [id, name] properties: id: { type: string } name: { type: string } limit_key: { type: string } skus: { type: array, items: { type: string } } Claims: type: object required: [tenant_id, tenant_slug, plan, tenant_status] properties: tenant_id: { type: string, format: uuid } tenant_slug: { type: string } org_roles: { type: array, items: { type: string } } products: { type: array, items: { type: string } } plan: { type: string } tenant_status: { $ref: "#/components/schemas/TenantStatus" } Error: type: object required: [error] properties: error: { type: string, example: invalid_input } message: { type: string } Document: type: object properties: id: { type: string, format: uuid } tenant_id: { type: string, format: uuid } title: { type: string } description: { type: string } filename: { type: string } content_type: { type: string } size_bytes: { type: integer } sha256: { type: string } status: { type: string, enum: [draft, published] } uploaded_by: { type: string } published_by: { type: string } published_at: { type: string, format: date-time } created_at: { type: string, format: date-time } own_document: { type: boolean, description: "The tenant's own file; publishing sends no mail." } project_ids: { type: array, items: { type: string, format: uuid } } Project: type: object properties: id: { type: string, format: uuid } tenant_id: { type: string, format: uuid } name: { type: string } kind: { type: string, enum: [product, topic] } description: { type: string } created_by: { type: string } created_at: { type: string, format: date-time } updated_at: { type: string, format: date-time } ProjectWrite: type: object properties: name: { type: string, minLength: 1, maxLength: 120 } kind: { type: string, enum: [product, topic], description: "product: one of the customer's products or machines; topic: e.g. CRA, Data Act" } description: { type: string, maxLength: 1000 } ManagedService: type: object required: [id, tenant_id, kind, name, url, sku, status, created_at, updated_at] properties: id: { type: string, format: uuid } tenant_id: { type: string, format: uuid } kind: { type: string, enum: [git, ci-runner] } name: { type: string } url: { type: string, description: "https:// URL of the Git instance (for a ci-runner: the instance it serves)" } sku: { type: string, example: INF-GIT-CLD-STD } status: { $ref: "#/components/schemas/ManagedServiceStatus" } created_at: { type: string, format: date-time } updated_at: { type: string, format: date-time } ManagedServiceAdmin: allOf: - $ref: "#/components/schemas/ManagedService" - type: object required: [instance_id, notes] properties: instance_id: { type: string } notes: { type: string } ManagedServiceStatus: type: string enum: [provisioning, active, restricted, halted] ManagedServiceCreate: type: object required: [kind, name, url, sku] properties: kind: { type: string, enum: [git, ci-runner] } name: { type: string, minLength: 1, maxLength: 100 } url: { type: string, maxLength: 300, description: "absolute https:// URL with a host" } sku: { type: string, pattern: "^INF-(GIT|CI)-(CLD|OPR)-(STD|BUS|ENT)$", description: "INF-GIT-* for kind git, INF-CI-* for kind ci-runner" } status: { $ref: "#/components/schemas/ManagedServiceStatus" } instance_id: { type: string, maxLength: 100, pattern: "^[a-z0-9-]*$" } notes: { type: string, maxLength: 2000 } ManagedServiceUpdate: type: object properties: name: { type: string, minLength: 1, maxLength: 100 } url: { type: string, maxLength: 300 } sku: { type: string, pattern: "^INF-(GIT|CI)-(CLD|OPR)-(STD|BUS|ENT)$", description: "INF-GIT-* for kind git, INF-CI-* for kind ci-runner" } status: { $ref: "#/components/schemas/ManagedServiceStatus" } instance_id: { type: string, maxLength: 100, pattern: "^[a-z0-9-]*$" } notes: { type: string, maxLength: 2000 } TenantActivity: type: object properties: usage: type: object additionalProperties: { type: number } description: usage totals per metric over the last 30 days last_activity_at: { type: string, format: date-time } Tenant: type: object required: [id, slug, name, status, kind, plan, created_at, updated_at] properties: id: { type: string, format: uuid } slug: { type: string } name: { type: string } status: { $ref: "#/components/schemas/TenantStatus" } kind: { type: string, enum: [customer, demo] } plan: { type: string } erp_customer_id: { type: string } stripe_cust_id: { type: string } trial_ends_at: { type: string, format: date-time, nullable: true } contract_start: { type: string, format: date, nullable: true } contract_end: { type: string, format: date, nullable: true } sales_owner: { type: string } admin_email: { type: string, format: email, description: "the tenant's first admin; empty for sales-led tenants" } created_at: { type: string, format: date-time } updated_at: { type: string, format: date-time } OrgMember: type: object required: [user_id, email, enabled] properties: user_id: { type: string } email: { type: string, format: email } first_name: { type: string } last_name: { type: string } org_roles: type: array items: { type: string } enabled: { type: boolean } created_at: { type: string, format: date-time, nullable: true } pending: { type: boolean, description: "invitation not accepted yet (no password, no identity-provider link)" } status: { type: string, enum: [invited, active, blocked], description: "status in this tenant (portal#74)" } MemberAction: type: object required: [status] properties: status: { type: string, enum: [role_changed, unchanged, blocked, unblocked, removed, invite_revoked, invite_resent] } member: { $ref: "#/components/schemas/OrgMember" } user_deleted: { type: boolean, description: "revoking the invitation also deleted the account" } sessions_ended: { type: boolean } api_keys: type: array description: The member's active API keys in this tenant, offered for revocation. items: { $ref: "#/components/schemas/APIKey" } Invite: type: object required: [user_id, email, status] properties: user_id: { type: string } email: { type: string, format: email } status: { type: string, enum: [invited, member] } TenantCreate: type: object required: [slug, name] properties: slug: { type: string, pattern: '^[a-z0-9][a-z0-9-]{1,38}[a-z0-9]$' } name: { type: string, minLength: 1, maxLength: 255 } plan: { type: string, default: starter } kind: { type: string, enum: [customer, demo], default: customer } sales_owner: { type: string } admin_email: { type: string, format: email, description: "IT_ADMIN to invite via Keycloak" } admin_name: { type: string } TenantCreated: type: object required: [tenant] properties: tenant: { $ref: "#/components/schemas/Tenant" } invite_url: { type: string, description: "KC action-token URL — present only when admin_email was set and KC provisioning succeeded" } TenantActivate: type: object properties: plan: { type: string } contract_start: { type: string, format: date } contract_end: { type: string, format: date } erp_customer_id: { type: string } products: type: array description: Entitlements granted with the activation (SKU limits in config). items: type: object required: [key] properties: key: { type: string } config: { type: object, additionalProperties: true } expires_at: { type: string, format: date-time } TenantCancel: type: object properties: reason: { type: string } at_period_end: { type: boolean } TenantProduct: type: object required: [tenant_id, product, enabled, config, created_at, updated_at] properties: tenant_id: { type: string, format: uuid } product: { type: string } enabled: { type: boolean } config: { type: object, additionalProperties: true } expires_at: { type: string, format: date-time, nullable: true } created_at: { type: string, format: date-time } updated_at: { type: string, format: date-time } CatalogEntry: type: object required: [key, name, description, type, plans_required, supports_trial] properties: key: { type: string } name: { type: string } description: { type: string } type: { type: string, enum: [standalone, headless, cli] } launch_url: { type: string, description: "product host for this environment (standalone) or download page (cli)" } skus: { type: array, items: { type: string } } addons: { type: array, items: { $ref: "#/components/schemas/ProductAddon" } } plans_required: { type: array, items: { type: string } } demo_url: { type: string } supports_trial: { type: boolean } trial_days: { type: integer } CatalogRequest: type: object required: [tenant_id, product] properties: tenant_id: { type: string, format: uuid } product: { type: string } APIKey: type: object required: [id, tenant_id, name, scopes, prefix, created_at] properties: id: { type: string, format: uuid } tenant_id: { type: string, format: uuid } product: { type: string } name: { type: string } scopes: { type: array, items: { type: string } } prefix: { type: string } created_by: { type: string } last_used_at: { type: string, format: date-time, nullable: true } revoked_at: { type: string, format: date-time, nullable: true } created_at: { type: string, format: date-time } APIKeyCreate: type: object required: [tenant_id, name] properties: tenant_id: { type: string, format: uuid } name: { type: string, maxLength: 100 } product: { type: string } scopes: { type: array, items: { type: string } } created_by: { type: string } APIKeyCreated: type: object required: [api_key, plaintext, warning] properties: api_key: { $ref: "#/components/schemas/APIKey" } plaintext: { type: string } warning: { type: string } APIKeyVerify: type: object required: [valid] properties: valid: { type: boolean } tenant_id: { type: string, format: uuid } product: { type: string } scopes: { type: array, items: { type: string } } AuditAppend: type: object required: [action] properties: tenant_id: { type: string, format: uuid } project_id: { type: string, format: uuid } actor_id: { type: string } actor_name: { type: string } actor_type: { type: string } action: { type: string } target_id: { type: string } target_type: { type: string } target_name: { type: string } product: { type: string } metadata: { type: object, additionalProperties: true } AuditEvent: allOf: - $ref: "#/components/schemas/AuditAppend" - type: object required: [id, created_at] properties: id: { type: integer, format: int64 } source_ip: { type: string } user_agent: { type: string } created_at: { type: string, format: date-time }