Repository navigation
[M2.1a] API skeleton - #27
Merged
Merged
Conversation
…RFC 9457 problem details
…API document and bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task
[M2.1a] API skeleton (first half of M2.1, split recorded in
docs/PLAN.md). Refs #20What changed
Domain (
packages/domain)Secret<T>: wraps credentials and renders[REDACTED]throughString(), template literals,JSON.stringify,util.inspect; the value is reachable only viaexpose(). Constant-timeequals. TypeScript counterpart of Golib/secret(CLAUDE.md rule 8).DomainErrorbase (kind + stablecode+ optional details) withInvalidInputError,NotFoundError,ConflictError. Pure, no framework imports.Control plane (
apps/api), NestJS 12platform/config: zod schema for the environment (DATABASE_URLbecomes aSecret, ports and URLs validated, every problem reported at once without echoing values),AppConfigtyped accessor,.envread in development only.platform/logging: pino JSON request logs through nestjs-pino. One line per request with request id (honours a safex-request-id), method, URL, status, duration.authorization,cookie,set-cookie,x-api-key, join-token headers and token query parameters are redacted; bodies are never logged; health probes are not logged.platform/http: globalProblemDetailsFilterproducing RFC 9457application/problem+jsonwithtype=https://shipkeep.dev/problems/<code>,code,instance,requestId, fielderrorsfor validation. Domain error kinds map to 400/401/403/404/409/412; unknown errors become an opaque 500 (internal messages never leak). Validation pipe: whitelist, forbid unknown properties, transform.platform/prisma: Prisma 7 with thepgdriver adapter; the connection string is exposed only into the driver.ping()for readiness. Schema andprisma.config.tsin place; the first models arrive with M2.1b. The generated client is not committed;pnpm installregenerates it.platform/health:GET /api/v1/health(liveness) andGET /api/v1/ready(database probe, 503 problem when down).platform/openapi: OpenAPI 3.1 document at/api/v1/openapi.json, bearer and session-cookie security schemes, UI at/api/v1/docswhenOPENAPI_UIis on (default outside production).helmeton every response.bootstrap.tsbuilds the app once formain.ts, the OpenAPI generator and the tests.Contract and client
apps/api/openapi.jsongenerated bypnpm gen:openapi(document-only run of the built API, no port, no database).packages/api-clientexposescreateShipkeepClient()over openapi-fetch with types generated by openapi-typescript (pnpm gen:api-client), plusisProblemDetails().pnpm genruns the whole chain; CI fails on drift.Tooling
pnpm test:integrationrunsapi:test:integration(vitest, Testcontainers PostgreSQL orDATABASE_URL).@nx/nestremoved (generator only, pinned to Nest <12).Why
Every control plane module (identity, fleet, audit...) needs configuration, logging, error mapping, the database client and the OpenAPI contract in place first. SPEC section 8 fixes the base path, the problem-details format and the OpenAPI location.
How it was tested
pnpm nx run-many -t lint typecheck test build: all 7 projects green. Unit tests: 13 domain, 15 api (config schema, filter mapping, HTTP pipeline with security headers, 404 problem, readiness 503, OpenAPI document and UI), 3 api-client, 86 config-schema, 3 proto-ts.pnpm test:integration: the API starts against a real PostgreSQL 17 started by Testcontainers andGET /api/v1/readyreturns{"status":"ok","checks":{"database":"ok"}}.pnpm gentwice: no drift.prettier --check: clean.pnpm dev:infrastack verified earlier today (PR [M0.5] Configurable dev stack ports #26).Security considerations
DATABASE_URLis aSecret; the onlyexpose()is the Prisma adapter constructor. Request logs redact credential headers and never include bodies. Internal errors are not echoed to clients.helmetdefaults;x-powered-byremoved.forbidNonWhitelisted).security-reviewlabel is set because this PR defines the error, logging and configuration foundations every later module inherits.Checklist
docs/PLAN.mdare met and M2.1a is tickedbuf lintpasstools/gen/openapi.mjsruns the built API with fixed arguments and carries a justifiednosemgrep)