一键导入
api-public-management
Use when changing Public Management API routes, API tokens, scopes, Bearer auth, management OpenAPI, rate limits, or API security hardening.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when changing Public Management API routes, API tokens, scopes, Bearer auth, management OpenAPI, rate limits, or API security hardening.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | api-public-management |
| description | Use when changing Public Management API routes, API tokens, scopes, Bearer auth, management OpenAPI, rate limits, or API security hardening. |
Generated from ai/registry.json. Do not edit manually.
Canonical skill: ../../../ai/skills/api-public-management.md.
Referenced context:
../../../ai/rules/api-public-management-rules.md../../../ai/rules/security-hardening-rules.md../../../ai/rules/api-tenant-access-rules.md../../../ai/architecture/public-management-api.md../../../ai/architecture/security-hardening.md../../../ai/architecture/api-app.md../../../ai/examples/good-management-api-contract.mdThis file is compiled from canonical AI knowledge files. Edit canonical files under ai, then run npm run ai:sync.
ai/skills/api-public-management.mdUse this skill when changing Public Management API routes, API tokens, token scopes, Bearer authentication, management OpenAPI output, rate limits, or security hardening in apps/api.
Preserve API-token automation as a documented, scope-limited, tenant-safe subset of /api/v1 without weakening session-only private routes or public SDK contracts.
ai/rules/api-public-management-rules.mdai/rules/security-hardening-rules.mdai/rules/api-tenant-access-rules.mdai/architecture/public-management-api.mdai/architecture/security-hardening.mdai/architecture/api-app.mdai/examples/good-management-api-contract.mddocs/ROADMAP.mddocs/TECHNICAL_DECISIONS.mddocs/MVP_VALIDATION.mdSessionOrApiTokenController and AuthenticatedApiGuard as part of the Public Management API auth boundary.managementApiRoutes as the source of truth for the documented Public Management API subset.managementApiRoutes, OpenAPI expectations, and route metadata tests together.@RequireApiTokenScopes()./api/v1/docs restricted to the supported management subset.ManagementApiRateLimitGuard positions: before Bearer authentication and after token authentication.managementApiRoutes, controller metadata, OpenAPI filtering, and tests stay aligned.npm --workspace @capture-flag/api run test -- management-api-route-metadata.spec.ts management-api-openapi.spec.ts after management route contract changes.npm --workspace @capture-flag/api run test after API token, scope, rate limit, or security changes.npm --workspace @capture-flag/api run build after controller, guard, or bootstrap changes.npm run ai:check after AI knowledge changes.ai/rules/api-public-management-rules.mdRules for API-token-backed automation routes under /api/v1.
createRawApiToken() and hash them with hashApiToken() before persistence.tokenHash and a display-safe tokenPrefix.SessionOrApiTokenController, or API-token-only routes behind ApiTokenGuard, then tenant and scope guards.@RequireApiTokenScopes() to every route that allows API token access.@RequireApiTokenTenant() when a route receives organization, project, config, environment, feature flag, or segment identifiers.managementApiRoutes aligned with every documented API-token route's controller, handler, method, path, scopes, tenant metadata, and auth mode.apiTokenScopes and docs/OpenAPI in sync./api/v1/docs restricted to the supported Public Management API subset.SessionOrApiTokenController makes every method API-token-accessible.managementApiRoutes, and route/OpenAPI tests.ManagementApiRateLimitGuard around AuthenticatedApiGuard as duplicate code.projects:* controls project listing and creation.configs:* controls project config listing and creation.members:* controls listed organization/project member automation routes, including supported organization member update and removal.flags:* controls list, create, and update for feature flags.environments:read controls environment listing only.segments:* controls segment list, create, update, and soft delete.apps/api/src/management-api/management-api-contract.ts defines the supported route set.apps/api/src/management-api/management-api-openapi.ts derives documented OpenAPI paths and scope descriptions from that contract.apps/api/test/management-api-route-metadata.spec.ts keeps controller decorators aligned with the contract.apps/api/test/management-api-openapi.spec.ts keeps OpenAPI filtering aligned with the contract.ai/rules/security-hardening-rules.mdRules for API HTTP security, rate limits, and secret handling.
applyHttpSecurity() in API bootstrap.CORS_ORIGINS, CORS_ORIGIN, or CLIENT_BASE_URL.REQUIRE_HTTPS.API_TRUST_PROXY when deployed behind trusted reverse proxies.ai/rules/api-tenant-access-rules.mdRules for private API authorization and tenant isolation.
SessionGuard and AuthenticatedRequest on session-only private API controllers.AuthenticatedApiGuard plus API token tenant/scope guards on private management routes that also accept API tokens.request.user.id, and delegate rules to services.AccessService before returning or mutating tenant-owned data.requireProjectAccess for project-scoped reads.requireProjectRole for project-scoped writes with the narrowest allowed project roles.requireOrganizationMember or requireOrganizationRole for organization-level reads and writes.owner and admin roles can satisfy project access without explicit project membership.developer scoped to feature flag writes; do not allow it to manage segments, SDK keys, environments, configs, project members, or roles.include or nested select shapes.configId and environmentId must belong to the same projectId before SDK keys, flag values, or config state changes.ai/architecture/public-management-api.mdThe Public Management API is the API-token-backed automation surface for selected /api/v1 routes.
/api/v1.ManagementApiController.SessionOrApiTokenController, which wires AuthenticatedApiGuard, management rate limits, API token tenant guards, and API token scope guards.SessionGuard and are not part of the Public Management API.managementApiRoutes is the source of truth for the documented automation subset.managementApiRoutes with controller paths, methods, scopes, tenant metadata, auth mode, and guard order.managementApiRoutes with the filtered /api/v1/docs and /api/v1/openapi.json output.tokenPrefix.request.user for the token subject and request.apiToken for organization/project/scopes.Unsupported operations should stay out of OpenAPI and docs until implemented.
/api/v1/docs and /api/v1/openapi.json expose only the supported management subset.restrictOpenApiToManagementApi() derives allowed paths and methods from managementApiRoutes and removes session-only and public SDK routes from the document.ManagementApiRateLimitGuard intentionally runs before AuthenticatedApiGuard for Bearer attempts and after authentication for token-specific buckets.ai/architecture/security-hardening.mdCapture Flag applies MVP hardening at API bootstrap and sensitive route guards.
applyHttpSecurity() installs Helmet, CORS, optional trust proxy, and HTTPS enforcement.REQUIRE_HTTPS=false.API_TRUST_PROXY so Express sees the intended protocol and IP.CORS_ORIGINS, CORS_ORIGIN, or CLIENT_BASE_URL.http://localhost:5173.sessions.token_hash.key_hash plus key_prefix.token_hash plus token_prefix.ai/architecture/api-app.mdapps/api is a NestJS API backed by Prisma and PostgreSQL.
request.user.id to services.SessionGuard and AuthenticatedRequest.AuthenticatedApiGuard, then API token tenant/scope guards.ApiTokenGuard directly, followed by tenant/scope guards.UuidParam, the shared wrapper around ParseUUIDPipe, in controllers.support services hold concrete reusable responsibilities such as access, audit, input normalization, read models, credentials, config state, references, validation, writers, or initializers.PrismaService./api/v1./api/v1/docs is filtered to the supported management subset.applyHttpSecurity() before request handling.ai/examples/good-management-api-contract.mdSource: apps/api/src/management-api/management-api-contract.ts (sha256: 020a70dc12de6839d7865a8ceb4a540681ea597703b81ee355c08c5b405cadbf)
Source: apps/api/src/management-api/management-api-openapi.ts (sha256: 70d39e4d03ecd18e900f4b9accd4b46aa0857920b65ef92512af42ec9863dfa3)
Source: apps/api/test/management-api-route-metadata.spec.ts (sha256: e66be56e794fb62486460a198fdcbcb31d603db7057c36a78b944545f6e622b9)
Source: apps/api/test/management-api-openapi.spec.ts (sha256: 6ad25a1e675fd499fe095d31c7f74393eba589a4aea32ba9e8cd6a26995934ab)
Why this is canonical:
{
apiTokenAccess: "session-or-api-token",
controller: "SegmentsController",
handler: "update",
method: "patch",
path: "/api/v1/configs/{configId}/segments/{segmentId}",
scopes: ["segments:write"],
tenant: { configParam: "configId", segmentParam: "segmentId" },
}
Every API-token-supported route records auth mode, controller method, documented path, required scopes, and tenant identifiers.
for (const route of managementApiRoutes) {
const routeMethods = routes[route.path] ?? {};
routeMethods[route.method] = route.scopes;
routes[route.path] = routeMethods;
}
The OpenAPI allowlist is derived from the route contract so unsupported session-only and public SDK routes stay out of /api/v1/docs.
for (const route of managementApiRoutes) {
expect(scopes(controllerFor(route.controller), route.handler)).toEqual(route.scopes);
expect(tenantRequirement(controllerFor(route.controller), route.handler)).toEqual(route.tenant);
}
Tests keep controller decorators aligned with the contract. Non-contract methods on dual controllers must not define API token scope or tenant metadata.
Use when adding, changing, extracting, or reusing client components, including Storybook stories and controls.
Use when adding or changing forms in apps/client.
Use when changing GitHub OAuth, session cookies, SessionGuard, logout, or authenticated API request identity.
Use when adding or changing routes in apps/client.
Use when adding or changing client state, React Query data flow, immutable context values, or Zustand stores.
Use when styling apps/client with Tailwind CSS v4.