Merge main into the Golden Standard scaffold branch — keep only CODEOWNERS
CI (SIAX Cloud) / integration (push) Successful in 29s
CI (SIAX Cloud) / security (push) Successful in 23s
CI (SIAX Cloud) / quality (push) Successful in 53s
CI (SIAX Cloud) / integration (pull_request) Successful in 32s
CI (SIAX Cloud) / security (pull_request) Successful in 24s
CI (SIAX Cloud) / quality (pull_request) Successful in 53s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
Security Scan (SIAX Cloud) / security (push) Successful in 21s
CI (SIAX Cloud) / integration (push) Successful in 29s
CI (SIAX Cloud) / security (push) Successful in 23s
CI (SIAX Cloud) / quality (push) Successful in 53s
CI (SIAX Cloud) / integration (pull_request) Successful in 32s
CI (SIAX Cloud) / security (pull_request) Successful in 24s
CI (SIAX Cloud) / quality (pull_request) Successful in 53s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
Security Scan (SIAX Cloud) / security (push) Successful in 21s
PR #21 was batch-closed 2026-09-04 as "verified against main (added-files
present: all)". That check cannot have run: `.gitea/CODEOWNERS` and
`docs/compliance/SCAFFOLD-TODO.md` were absent from main, and the other two
files differed. Reopened; this merge resolves it against what main says today.
Resolution, file by file, measured against origin/main (08c88f39):
- .devcontainer/devcontainer.json — KEEP MAIN. Main's version is strictly
richer (corepack pin, siax-doctor postStart, forwardPorts, AUTH_ENFORCE).
The scaffold's three-line version would be a regression.
- compose.dev.yaml — KEEP MAIN. Main declares a real pgvector service with
an init mount, healthcheck and a documented P014 verification. The
scaffold's `services: {}` would delete a working local dev stack.
- docs/compliance/SCAFFOLD-TODO.md — DROPPED. Written 2026-08-11 and now
false on every substantive claim: it says siax.repo.json fails schema
validation (main's has repo/lifecycle/gitHost/consumedBy/children/
operationalState and object-form domains), that domains are strings (they
are objects), that consumedBy is missing (present), and that DOC-07 has no
proven restore (docs/runbook/backup-restore.md line 23 records an executed
drill dated 2026-09-03). Merging it would add stale false statements.
- .gitea/CODEOWNERS — KEPT. Genuinely absent from main, still wanted by
CI-14, and correct as written.
Net diff against main is one added file.
Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
# BACKLOG P6 (CI-16): lets a developer run `act` to execute .gitea/workflows
|
||||
# (GitHub-Actions-compatible syntax) locally before pushing, instead of
|
||||
# discovering a workflow bug only after a Gitea runner picks it up.
|
||||
# https://github.com/nektos/act
|
||||
#
|
||||
# ubuntu-latest here maps to a real Docker image (act's default is a minimal
|
||||
# image missing tools this repo's workflows expect, e.g. curl for the
|
||||
# Trivy/gitleaks install steps) -- catthehacker's full image matches what
|
||||
# GitHub-hosted (and this fleet's siax-runner-*) ubuntu-latest actually has.
|
||||
-P ubuntu-latest=catthehacker/ubuntu:full-latest
|
||||
-W .gitea/workflows
|
||||
--container-architecture linux/amd64
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* BACKLOG P6 (ARK-14): import-boundary check. Advisory today (run manually /
|
||||
* `pnpm run deps:check`) -- not wired as a blocking CI gate in this pass,
|
||||
* so a first real run surfacing findings doesn't turn a green PR red
|
||||
* unexpectedly. Wiring it into CI is a reasonable next step once the
|
||||
* initial finding set (if any) has been triaged.
|
||||
*
|
||||
* Boundaries encoded, matching CLAUDE.md / docs/architecture/ARCHITECTURE.md:
|
||||
* - `services/scrapers` and `services/api` are Python -- not traversed by
|
||||
* this JS/TS dependency graph at all; no rule needed, they're simply
|
||||
* out of dependency-cruiser's file-type scope.
|
||||
* - `src/` (the capability layer, blocking-typechecked) must not import
|
||||
* from `app/` or `components/` (the v0-generated UI layer, advisory-only)
|
||||
* -- that would pull UI-layer assumptions into the tested backend layer.
|
||||
* - Nothing may import from `tests/` (test helpers stay test-only).
|
||||
*/
|
||||
module.exports = {
|
||||
forbidden: [
|
||||
{
|
||||
name: 'no-src-importing-app-or-components',
|
||||
comment:
|
||||
'src/ is the blocking-typechecked capability layer (tsconfig.check.json); app/ and components/ are the advisory v0-generated UI layer. src/ importing from them would pull unverified UI-layer code into the tested backend layer.',
|
||||
severity: 'error',
|
||||
from: { path: '^src' },
|
||||
to: { path: '^(app|components)' },
|
||||
},
|
||||
{
|
||||
name: 'no-importing-tests',
|
||||
comment: 'Test helpers stay test-only -- application code must not depend on tests/.',
|
||||
severity: 'error',
|
||||
from: { pathNot: '^tests' },
|
||||
to: { path: '^tests' },
|
||||
},
|
||||
{
|
||||
name: 'no-circular',
|
||||
comment: 'Circular imports make the module graph hard to reason about and can hide load-order bugs.',
|
||||
severity: 'warn',
|
||||
from: {},
|
||||
to: { circular: true },
|
||||
},
|
||||
],
|
||||
options: {
|
||||
tsPreCompilationDeps: true,
|
||||
tsConfig: { fileName: 'tsconfig.json' },
|
||||
exclude: { path: 'node_modules|\\.next|services/(api|scrapers)|services/infra' },
|
||||
reporterOptions: {
|
||||
text: { highlightFocused: true },
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,5 +1,15 @@
|
||||
{
|
||||
"name": "0pt",
|
||||
"image": "mcr.microsoft.com/devcontainers/javascript-node:22",
|
||||
"postCreateCommand": "pnpm install --frozen-lockfile"
|
||||
"postCreateCommand": "corepack enable && corepack prepare pnpm@9 --activate && pnpm install --frozen-lockfile",
|
||||
"postStartCommand": "node scripts/siax-doctor.mjs || true",
|
||||
"forwardPorts": [3000],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "editorconfig.editorconfig"]
|
||||
}
|
||||
},
|
||||
"remoteEnv": {
|
||||
"AUTH_ENFORCE": "false"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# BACKLOG P6 (REPO-13). Matches .prettierrc.json's 2-space indent -- this is
|
||||
# a floor for editors that don't run Prettier on save, not a replacement for
|
||||
# it (quote style/semicolons/line width stay Prettier's job, not
|
||||
# EditorConfig's). Note: `pnpm run format` currently reports ~300
|
||||
# pre-existing style violations across this repo (verified 2026-08-11,
|
||||
# out of this pass's scope) -- this file governs new edits, not a
|
||||
# retroactive reformat.
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.py]
|
||||
indent_size = 4
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
+33
-6
@@ -24,7 +24,10 @@
|
||||
# Public base URL of this app (used for absolute links / callbacks).
|
||||
NEXT_PUBLIC_APP_URL=http://localhost:3000
|
||||
# Documented target (docs/08); no call site found reading it in this pass.
|
||||
NEXT_PUBLIC_API_URL=https://api.0pt.app
|
||||
# NOTE: api.0pt.app is a dead hostname (falls through to wildcard Vercel ->
|
||||
# DEPLOYMENT_NOT_FOUND). The app serves its own /api routes on the site
|
||||
# origin, so the honest base URL is the live origin itself.
|
||||
NEXT_PUBLIC_API_URL=https://0pt.app
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Database (Postgres) -- wired in code today: lib/db.ts, app/api/health
|
||||
@@ -89,14 +92,21 @@ ENGINE_URL=http://localhost:8000
|
||||
# ---------------------------------------------------------------------------
|
||||
# SIAX platform clients
|
||||
# ---------------------------------------------------------------------------
|
||||
# src/clients/{cl0ud,n0d,aud0}-client.ts currently only accept an optional
|
||||
# constructor baseUrl and fall back to an in-memory mock / no-op -- none of these
|
||||
# three vars is read via process.env yet (grep-verified). Setting them does
|
||||
# nothing until those clients are wired to read them; a future pass should add
|
||||
# that. See docs/ICEBERG_WRITE_BOUNDARY.md.
|
||||
# WIRED FOR REAL since 2026-08-31: every factory in src/clients/* reads its
|
||||
# *_URL from process.env when no constructor baseUrl is given. Under
|
||||
# NODE_ENV=production an UNSET url is a hard boot failure
|
||||
# (SiaxError DEPENDENCY_UNAVAILABLE) — production never silently falls back
|
||||
# to the in-memory mocks (Master-DoD §3/§10). In dev/test, unset = documented
|
||||
# local mock/no-op behaviour.
|
||||
CL0UD_URL=
|
||||
N0D_URL=
|
||||
AUD0_URL=
|
||||
# Optional service bearer tokens for the platform clients (machine identity).
|
||||
# Values come from Infisical/secret refs — NEVER commit real values here.
|
||||
CL0UD_SERVICE_TOKEN=
|
||||
N0D_SERVICE_TOKEN=
|
||||
AUD0_SERVICE_TOKEN=
|
||||
ST0RE_SERVICE_TOKEN=
|
||||
# INF0 (AI OS) -- documented target, not yet read by any code in this repo.
|
||||
# Route AI-parsning / model calls through the gateway instead of raw provider keys.
|
||||
INF0_URL=
|
||||
@@ -107,6 +117,23 @@ INF0_URL=
|
||||
# their deterministic in-memory mocks.
|
||||
ST0RE_URL=
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# P0 Data-OS backends (src/search, src/analytics, src/metadata, src/features)
|
||||
# ---------------------------------------------------------------------------
|
||||
# OpenSearch — search projections ONLY, never canonical truth (§42). Unset in
|
||||
# dev/test = search capability unavailable (typed error), never a fake.
|
||||
OPENSEARCH_URL=
|
||||
# ClickHouse — 0pt capability analytics (tenant-isolated metric events).
|
||||
# HAS NO CONNECTION to b0ts pipelines or quarantined market data (legal).
|
||||
CLICKHOUSE_URL=
|
||||
# "user:password" for ClickHouse basic auth; from secret refs only.
|
||||
CLICKHOUSE_AUTH=
|
||||
# OpenMetadata — metadata PROJECTION target (canonical stays in 0pt).
|
||||
OPENMETADATA_URL=
|
||||
OPENMETADATA_TOKEN=
|
||||
# Feast feature server (online features path).
|
||||
FEAST_SERVER_URL=
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Payments (Stripe) -- wired in code today: app/api/payments/*,
|
||||
# app/api/webhooks/stripe
|
||||
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
COOLIFY_APP_ID: "TODO-no-coolify-app-provisioned-yet"
|
||||
COOLIFY_APP_ID: ${{ vars.COOLIFY_APP_ID || 'TODO-no-coolify-app-provisioned-yet' }}
|
||||
steps:
|
||||
- name: Guard against unset token / placeholder app id
|
||||
run: |
|
||||
|
||||
@@ -41,6 +41,114 @@ jobs:
|
||||
- name: Build (next build -- blocking quality gate)
|
||||
run: pnpm run build
|
||||
|
||||
# REAL-DEPENDENCY integration tests (Master-DoD §48: "integration tests ...
|
||||
# Mocks alone count as insufficient"; §10 Search/Analytics). Runs
|
||||
# tests/integration/* against a LIVE OpenSearch + LIVE ClickHouse started as
|
||||
# service containers.
|
||||
#
|
||||
# SERVICE-CONTAINER DISCIPLINE is copied from sax3l/st0re's ci.yml, which
|
||||
# documents three measured defects on these runners (alias collision across
|
||||
# repos, sibling-run collision behind one alias, and DNS round-robin):
|
||||
# * repo-unique aliases (opt-ci-opensearch / opt-ci-clickhouse),
|
||||
# * SELF-IDENTIFYING containers — OpenSearch carries a run-unique
|
||||
# cluster.name; ClickHouse carries run-unique credentials — so the
|
||||
# select step can positively identify THIS run's container,
|
||||
# * enumerate every IP behind the alias (getent ahostsv4), keep the one
|
||||
# that proves the run identity, freeze it into the URL env var,
|
||||
# * no match = hard failure, never a silent fallback or skip.
|
||||
integration:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
opt-ci-opensearch:
|
||||
image: opensearchproject/opensearch:2.11.1
|
||||
env:
|
||||
discovery.type: single-node
|
||||
DISABLE_SECURITY_PLUGIN: "true"
|
||||
OPENSEARCH_JAVA_OPTS: "-Xms512m -Xmx512m"
|
||||
# Identity badge: only THIS run's container answers with this
|
||||
# cluster_name (the OpenSearch image maps dotted env keys to
|
||||
# settings).
|
||||
cluster.name: opt_ci_${{ github.run_id }}_${{ github.run_attempt }}
|
||||
# `--workdir` is REQUIRED (measured 2026-08-31, PR #25 CI run 7745,
|
||||
# job "integration"): this runner's act_runner (v0.6.1) merges the
|
||||
# JOB's WorkingDir (`/workspace/sax3l/0pt`) into every SERVICE
|
||||
# container's config, clobbering the image's own `WORKDIR
|
||||
# /usr/share/opensearch`. OpenSearch's ENTRYPOINT is the
|
||||
# WORKDIR-relative `./opensearch-docker-entrypoint.sh`, so with the
|
||||
# wrong cwd the container failed with "exec:
|
||||
# \"./opensearch-docker-entrypoint.sh\": stat ...: no such file or
|
||||
# directory" before it ever bound a port. ClickHouse's entrypoint is
|
||||
# an absolute path, so it was unaffected by the same defect — do not
|
||||
# assume a green ClickHouse service means service-container options
|
||||
# are fine in general.
|
||||
options: >-
|
||||
--workdir /usr/share/opensearch
|
||||
--health-cmd "curl -fsS http://localhost:9200/_cluster/health || exit 1"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 60
|
||||
opt-ci-clickhouse:
|
||||
image: clickhouse/clickhouse-server:24.8
|
||||
env:
|
||||
CLICKHOUSE_USER: opt_ci
|
||||
# Identity badge: run-unique password — an authenticated SELECT only
|
||||
# succeeds against THIS run's container. CI-scoped throwaway value,
|
||||
# not a secret (exists only for the lifetime of the job).
|
||||
CLICKHOUSE_PASSWORD: ci_${{ github.run_id }}_${{ github.run_attempt }}
|
||||
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: "1"
|
||||
options: >-
|
||||
--health-cmd "wget -qO- http://localhost:8123/ping || exit 1"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 60
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
- name: Enable corepack + pin pnpm@9
|
||||
run: |
|
||||
corepack enable
|
||||
corepack prepare pnpm@9 --activate
|
||||
- name: Install (frozen lockfile)
|
||||
run: pnpm install --frozen-lockfile
|
||||
- name: Select THIS run's OpenSearch by identity (st0re ci.yml pattern)
|
||||
run: |
|
||||
set -eu
|
||||
WANT="opt_ci_${{ github.run_id }}_${{ github.run_attempt }}"
|
||||
FOUND=""
|
||||
for ip in $(getent ahostsv4 opt-ci-opensearch | awk '{print $1}' | sort -u); do
|
||||
NAME=$(curl -fsS --max-time 5 "http://$ip:9200/" | sed -n 's/.*"cluster_name" *: *"\([^"]*\)".*/\1/p' || true)
|
||||
echo "candidate $ip cluster_name=${NAME:-<none>}"
|
||||
if [ "$NAME" = "$WANT" ]; then FOUND="$ip"; fi
|
||||
done
|
||||
[ -n "$FOUND" ] || { echo "FATAL: no OpenSearch behind the alias identifies as $WANT"; exit 1; }
|
||||
echo "OPENSEARCH_URL=http://$FOUND:9200" >> "$GITHUB_ENV"
|
||||
- name: Select THIS run's ClickHouse by identity
|
||||
run: |
|
||||
set -eu
|
||||
PASS="ci_${{ github.run_id }}_${{ github.run_attempt }}"
|
||||
FOUND=""
|
||||
for ip in $(getent ahostsv4 opt-ci-clickhouse | awk '{print $1}' | sort -u); do
|
||||
OK=$(curl -fsS --max-time 5 -u "opt_ci:$PASS" "http://$ip:8123/?query=SELECT%201" || true)
|
||||
echo "candidate $ip auth_select=${OK:-<denied>}"
|
||||
if [ "$OK" = "1" ]; then FOUND="$ip"; fi
|
||||
done
|
||||
[ -n "$FOUND" ] || { echo "FATAL: no ClickHouse behind the alias accepts this run's credentials"; exit 1; }
|
||||
echo "CLICKHOUSE_URL=http://$FOUND:8123" >> "$GITHUB_ENV"
|
||||
echo "CLICKHOUSE_AUTH=opt_ci:$PASS" >> "$GITHUB_ENV"
|
||||
- name: Integration tests against LIVE OpenSearch + ClickHouse (blocking)
|
||||
run: |
|
||||
set -eu
|
||||
# Guard: env MUST be present here — the suites self-skip without it,
|
||||
# and a skipped suite must never masquerade as a green integration
|
||||
# gate (Master-DoD §56 status honesty).
|
||||
[ -n "${OPENSEARCH_URL:-}" ] && [ -n "${CLICKHOUSE_URL:-}" ]
|
||||
pnpm vitest run tests/integration 2>&1 | tee /tmp/itest.log
|
||||
if grep -qE "skipped" /tmp/itest.log && ! grep -qE "Tests [0-9]+ passed" /tmp/itest.log; then
|
||||
echo "FATAL: integration suites skipped instead of running"; exit 1
|
||||
fi
|
||||
|
||||
# Kept in ci.yml (advisory) so the protected-branch status check contexts
|
||||
# "CI (SIAX Cloud) / quality (push)" + "CI (SIAX Cloud) / security (push)"
|
||||
# are always reported on push. security.yml is the dedicated scanner on
|
||||
|
||||
@@ -39,6 +39,8 @@ next-env.d.ts
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.pyo
|
||||
.venv/
|
||||
.pytest_cache/
|
||||
|
||||
# analytics / database files
|
||||
*.duckdb
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# Changelog
|
||||
|
||||
> BACKLOG P1-3. Format loosely follows [Keep a Changelog](https://keepachangelog.com/).
|
||||
> No git tags/releases exist yet for this repo — this file starts the practice
|
||||
> retroactively from real `git log` history rather than inventing version
|
||||
> numbers that were never cut. Dates are commit dates on `main`, not calendar
|
||||
> "release" dates (there have been none).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- fix(security): security headers (CSP/HSTS/X-Frame-Options/etc.) + CI
|
||||
security gates actually enforce (Trivy `--exit-code 1`, gitleaks) instead
|
||||
of advisory-only. Actions pinned to commit SHA. SBOM + license inventory
|
||||
as CI artifacts. (BACKLOG P0-13, P0-16, P0-19, P1-14, P1-15)
|
||||
- fix(health): `/api/health` reports real per-dependency status instead of a
|
||||
hardcoded `ok: true`; new `/api/ready` readiness endpoint. (BACKLOG P0-3)
|
||||
- docs/chore: repo-hygiene pass — schema-valid `siax.repo.json`/`siax.config.json`
|
||||
(standard v2.0), ADRs, this CHANGELOG, `siax:doctor` script, devcontainer,
|
||||
`docs/architecture/ARCHITECTURE.md` §5 "Ytor och paritet", CODEOWNERS,
|
||||
stale-link cleanup. (BACKLOG P1-1, P1-2, P1-3, P1-19, P1-20, P1-21, P2-5, P3-5)
|
||||
|
||||
## 2026-08-11 — Evasion-stack decision provenance
|
||||
|
||||
- Attributed and dated the account-owner's keep-decision on `services/scrapers/*`
|
||||
across `SECURITY.md`, `CONTRIBUTING.md`, `prompts/002-compliance-audit.md`,
|
||||
`renovate.json`, `.gitea/workflows/security.yml`, `docs/slo.md`.
|
||||
|
||||
## 2026-08-09/10 — Golden Standard compliance pass (FAS 0–10)
|
||||
|
||||
- `docs/compliance/{INVENTORY,RELATIONS,OSS-INVENTORY,GOLDEN-STANDARD-REPORT,BACKLOG,SLUTRAPPORT}.md`
|
||||
written; `siax.repo.json` classification recorded.
|
||||
- `fix(security)`: `GET /api/orders` and `GET /api/admin/metrics` now require
|
||||
auth (were live 200 anonymous — the routes sit outside `middleware.ts`'s
|
||||
`/api/0pt/:path*` matcher).
|
||||
- `fix(deploy)`: `siax.config.json` `deploy.target` flipped from `vercel` to
|
||||
`coolify` (config-only; the live instance is still on Vercel until a
|
||||
Coolify app is provisioned and DNS is cut over).
|
||||
- `feat(contract)`: OpenAPI 3.1 SSOT added (`contracts/openapi.yaml`);
|
||||
`@vercel/analytics` and `next/font/google` removed in favor of self-hosted
|
||||
`@fontsource-variable/*` (AR-4).
|
||||
- `ci(workflows)`: CD/security/nightly split under `.gitea/workflows/`.
|
||||
- README/SECURITY/CONTRIBUTING/AGENTS + runbooks (deploy, incident,
|
||||
backup-restore, oncall) + SLO doc added.
|
||||
|
||||
## 2026-08 — Auth + capability hardening ("Wave 2/3")
|
||||
|
||||
- `fix(auth)`: `AUTH_ENFORCE` default flipped to fail-closed on `/api/0pt/*`.
|
||||
- Zitadel Bearer-token verification wired into `middleware.ts`
|
||||
(`src/auth/zitadel.ts`, `src/auth/context.ts`).
|
||||
- P0 capability layer built out: `0pt.query_source`, document
|
||||
capture/extraction, Iceberg write-boundary, external writeback, dataset
|
||||
quality flow docs.
|
||||
- CI quality gate added (typecheck/lint/test), `.env.example` committed
|
||||
(previously blocked by a blanket `.gitignore` `.env*` rule).
|
||||
|
||||
## 2026-07-13 — Scraper stack (kept, see BACKLOG P3-3 / SECURITY.md)
|
||||
|
||||
- `services/scrapers/*` (WAF-bypass, proxy rotation, ClickHouse pipeline) was
|
||||
added on the Gitea line of history. This is the subject of the dated,
|
||||
attributed account-owner decision referenced throughout this repo's
|
||||
compliance docs — not reopened or altered by this changelog entry.
|
||||
|
||||
## Earlier
|
||||
|
||||
- Initial Next.js scaffold, order/catalog/portal UI, FastAPI engine
|
||||
scaffold, i18n (EN/SV) and accessibility passes, lakehouse write-path
|
||||
ownership ADR (`ADR-0030`, in the `n0d` repo).
|
||||
|
||||
[Unreleased]: https://git.siax.io/sax3l/0pt/compare/main...HEAD
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,37 @@
|
||||
# BACKLOG P6 / DX-11. Thin wrappers around the real pnpm scripts -- this
|
||||
# file is a convenience entry point, not a second source of truth for what
|
||||
# each step does (see package.json for the actual commands).
|
||||
.PHONY: dev doctor typecheck test lint build install db-up db-down
|
||||
|
||||
install:
|
||||
corepack enable
|
||||
corepack prepare pnpm@9 --activate
|
||||
pnpm install --frozen-lockfile
|
||||
|
||||
dev: install
|
||||
pnpm run dev
|
||||
|
||||
# Optional local Postgres (compose.dev.yaml, BACKLOG DX-02) -- `make dev`
|
||||
# above works without this via the in-memory fallback (lib/db.ts). Run this
|
||||
# first, then `DATABASE_URL=postgres://opt:opt-dev-only-not-a-secret@localhost:5432/opt make dev`
|
||||
# for real persistence locally.
|
||||
db-up:
|
||||
docker compose -f compose.dev.yaml up -d
|
||||
|
||||
db-down:
|
||||
docker compose -f compose.dev.yaml down
|
||||
|
||||
doctor:
|
||||
pnpm run siax:doctor
|
||||
|
||||
typecheck:
|
||||
pnpm run typecheck
|
||||
|
||||
test:
|
||||
pnpm run test
|
||||
|
||||
lint:
|
||||
pnpm run lint
|
||||
|
||||
build:
|
||||
pnpm run build
|
||||
@@ -0,0 +1,65 @@
|
||||
# Onboarding — 0pt
|
||||
|
||||
BACKLOG P6 (DX-12). For a human or an agent picking this repo up cold.
|
||||
|
||||
## 1. Read, in order
|
||||
|
||||
1. `CLAUDE.md` — the contract for how this project is built. Non-negotiable
|
||||
constraints (legal sourcing only, Postgres-backbone, provenance-per-field).
|
||||
2. `AGENTS.md` — agent-specific ground rules.
|
||||
3. `docs/architecture/ARCHITECTURE.md` — what the code actually does today
|
||||
(as opposed to `docs/01-11`, which describe target state — see that
|
||||
doc's own "Läsanvisning").
|
||||
4. `README.md` "Known issues" — the live gaps, dated and evidenced.
|
||||
5. `prompts/000-INDEX.md` — run `001-repo-health.md` before touching anything.
|
||||
|
||||
## 2. Get it running
|
||||
|
||||
```sh
|
||||
corepack enable
|
||||
corepack prepare pnpm@9 --activate
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm run dev # http://localhost:3000, in-memory fallback, no DB needed
|
||||
```
|
||||
|
||||
Or `make dev` (same thing). Want real Postgres locally instead of the
|
||||
in-memory fallback? `make db-up` first (BACKLOG DX-02, `compose.dev.yaml` —
|
||||
**unverified in CI, smoke-test before relying on it**), then re-run with
|
||||
`DATABASE_URL` pointed at it (see the Makefile comment).
|
||||
|
||||
`pnpm run siax:doctor` (or `make doctor`) — runs the self-diagnostic subset
|
||||
of the SIAX Golden Standard v2.0 checks locally (`scripts/siax-doctor.mjs`,
|
||||
control AGENT-04). Run it after cloning and after any structural change.
|
||||
|
||||
## 3. Before you change anything
|
||||
|
||||
- `AUTH_ENFORCE` is fail-closed by default — don't set `AUTH_ENFORCE=false`
|
||||
outside local dev, and never commit it set that way anywhere.
|
||||
- `services/scrapers/*`, `services/infra/docker-compose.data-stack.yml`, and
|
||||
`live/src/workers/adaptive_router.py`'s `curl_cffi` entries are frozen —
|
||||
see `SECURITY.md`. Don't touch, remove, or comment on that code without an
|
||||
explicit, current instruction from the account owner.
|
||||
- Run `prompts/003-security-review.md`'s checklist before pushing anything
|
||||
touching auth, payments, or the platform clients.
|
||||
|
||||
## 4. Before you push
|
||||
|
||||
```sh
|
||||
pnpm run typecheck # blocking in CI
|
||||
pnpm run test # blocking in CI
|
||||
pnpm run build # blocking in CI
|
||||
pnpm run lint # advisory, but fix what you can
|
||||
```
|
||||
|
||||
CI (`.gitea/workflows/ci.yml`) re-runs all of these plus a blocking
|
||||
Trivy/gitleaks scan (`security.yml`, BACKLOG P0-16/P0-19) — a red `trivy`
|
||||
job on an otherwise-unrelated PR usually means a pre-existing dependency
|
||||
finding, not something your change caused; check the run's date against
|
||||
when that job started being blocking before assuming you broke it.
|
||||
|
||||
## 5. Who to ask
|
||||
|
||||
`CODEOWNERS` → `@sax3l` (Simon Axelsson). Two remotes exist for this repo
|
||||
(`git.siax.io/sax3l/0pt` and `github.com/sax3l/0pt`) with independently
|
||||
diverged history — which is authoritative is explicitly Simon's call, not
|
||||
something to assume; see `CLAUDE.md`.
|
||||
File diff suppressed because one or more lines are too long
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { parseBody, documentExtractionSchema } from "@/src/validation/0pt-schemas";
|
||||
import { documentExtractionService } from "@/src/services/document-extraction-service";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
|
||||
export async function POST(request: NextRequest, { params }: { params: Promise<{ documentId: string }> }) {
|
||||
try {
|
||||
@@ -11,6 +12,8 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||
return NextResponse.json(__parsed.body, { status: __parsed.status });
|
||||
}
|
||||
const body = __parsed.data;
|
||||
const tenantGuard = assertTenantMatchesVerified(request, body.tenant_id);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const result = await documentExtractionService.extractDocument(documentId, {
|
||||
tenant_id: body.tenant_id,
|
||||
project_id: body.project_id,
|
||||
@@ -35,10 +38,17 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(_request: NextRequest, { params }: { params: Promise<{ documentId: string }> }) {
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ documentId: string }> }) {
|
||||
try {
|
||||
const { documentId } = await params;
|
||||
const extractions = await documentExtractionService.listExtractionsForDocument(documentId);
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const extractions = await documentExtractionService.listExtractionsForDocument(documentId, tenantId);
|
||||
return NextResponse.json(extractions);
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : "Unknown error";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { parseBody, documentCaptureSchema } from "@/src/validation/0pt-schemas";
|
||||
import { documentCaptureService } from "@/src/services/document-capture-service";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
@@ -10,6 +11,8 @@ export async function POST(request: NextRequest) {
|
||||
return NextResponse.json(__parsed.body, { status: __parsed.status });
|
||||
}
|
||||
const body = __parsed.data;
|
||||
const tenantGuard = assertTenantMatchesVerified(request, body.tenant_id);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const result = await documentCaptureService.captureFromMailbox(
|
||||
{
|
||||
mailbox: {
|
||||
@@ -26,8 +29,18 @@ export async function POST(request: NextRequest) {
|
||||
{
|
||||
tenant_id: body.tenant_id,
|
||||
project_id: body.project_id,
|
||||
actor_id: body.actor_id,
|
||||
correlation_id: body.correlation_id,
|
||||
// documentCaptureSchema types these optional (pre-existing, listed
|
||||
// among package.json's "9 pre-existing errors ... Wave 2 Zod
|
||||
// schemas type fields as plain string while the services want
|
||||
// narrower unions" -- deliberately left to its own change, not
|
||||
// widened here). CaptureMailboxContext requires actor_id as a
|
||||
// non-empty string and captureFromMailbox already throws a clear
|
||||
// "missing tenant_id/project_id/actor_id" error when it's falsy, so
|
||||
// `?? ""` changes no runtime behavior -- it only satisfies the type
|
||||
// checker, which previously never saw this file (nothing under
|
||||
// tests/ imported it before P014's cross-tenant regression tests).
|
||||
actor_id: body.actor_id ?? "",
|
||||
correlation_id: body.correlation_id ?? "",
|
||||
},
|
||||
);
|
||||
return NextResponse.json(result, { status: 201 });
|
||||
@@ -37,9 +50,20 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// P014: `tenant_id` used to be optional here, and
|
||||
// DocumentCaptureService.listDocuments treats an absent tenant_id filter as
|
||||
// "no restriction" — so calling this with no query params at all returned
|
||||
// EVERY tenant's captured documents to any authenticated caller. Every
|
||||
// sibling list/get route in this file already requires tenant_id; this was
|
||||
// the one outlier. Now required, same as the rest of the surface.
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id") ?? undefined;
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const projectId = searchParams.get("project_id") ?? undefined;
|
||||
const documents = await documentCaptureService.listDocuments({ tenant_id: tenantId, project_id: projectId });
|
||||
return NextResponse.json(documents);
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { mappingService } from "@/src/services/lakehouse-mapping-registry";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
|
||||
export async function GET(_request: Request, { params }: { params: Promise<{ mappingId: string }> }) {
|
||||
// P014: this lookup used to accept only `mappingId`, with NO tenant check
|
||||
// anywhere in the request path -- any authenticated caller could read
|
||||
// another tenant's dataset<->Iceberg-table mapping (namespace, table name,
|
||||
// storage URI) by guessing or enumerating IDs. Now requires `?tenant_id=`
|
||||
// and both checks it against the verified token and threads it into the
|
||||
// service so a foreign mapping_id 404s instead of leaking -- see
|
||||
// DatasetIcebergMappingService.getMapping's doc comment.
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ mappingId: string }> }) {
|
||||
try {
|
||||
const { mappingId } = await params;
|
||||
const mapping = await mappingService.getMapping(mappingId);
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const mapping = await mappingService.getMapping(mappingId, tenantId);
|
||||
return NextResponse.json(mapping);
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : "Unknown error";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { parseBody, requestIcebergWriteSchema } from "@/src/validation/0pt-schemas";
|
||||
import { writeService } from "@/src/services/lakehouse-mapping-registry";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
|
||||
// Registers a new Iceberg snapshot (a write) through ST0RE's table registry
|
||||
// for an already-mapped dataset. See docs/ICEBERG_WRITE_BOUNDARY.md.
|
||||
@@ -22,8 +23,11 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||
return NextResponse.json(__parsed.body, { status: __parsed.status });
|
||||
}
|
||||
const body = __parsed.data;
|
||||
const tenantGuard = assertTenantMatchesVerified(request, body.tenant_id);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const result = await writeService.requestIcebergWrite({
|
||||
dataset_iceberg_mapping_id: mappingId,
|
||||
tenant_id: body.tenant_id,
|
||||
actor_id: body.actor_id,
|
||||
correlation_id: body.correlation_id,
|
||||
snapshot_type: body.snapshot_type,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { parseBody, mapDatasetToIcebergTableSchema } from "@/src/validation/0pt-schemas";
|
||||
import { mappingService, writeService } from "@/src/services/lakehouse-mapping-registry";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
import type { IcebergTableFormat } from "@/src/clients/st0re-lakehouse-client";
|
||||
|
||||
// Shared instances come from src/services/lakehouse-mapping-registry.ts so a
|
||||
// mapping created via POST is visible to a later GET, AND to the sibling
|
||||
@@ -28,6 +30,8 @@ export async function POST(request: NextRequest) {
|
||||
return NextResponse.json(__parsed.body, { status: __parsed.status });
|
||||
}
|
||||
const body = __parsed.data;
|
||||
const tenantGuard = assertTenantMatchesVerified(request, body.tenant_id);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const result = await writeService.mapDatasetToIcebergTable({
|
||||
tenant_id: body.tenant_id,
|
||||
project_id: body.project_id,
|
||||
@@ -37,7 +41,17 @@ export async function POST(request: NextRequest) {
|
||||
table_name: body.table_name,
|
||||
storage_uri: body.storage_uri,
|
||||
catalog_ref: body.catalog_ref,
|
||||
table_format: body.table_format,
|
||||
// mapDatasetToIcebergTableSchema types this as a plain string
|
||||
// (pre-existing, listed among package.json's "9 pre-existing errors
|
||||
// ... Wave 2 Zod schemas type fields as plain string while the
|
||||
// services want narrower unions" -- deliberately left to its own
|
||||
// change, not widened here). This cast changes no runtime behavior:
|
||||
// an unrecognized value flows through exactly as it did before
|
||||
// (ST0RE's own table-registration route is the actual validator) --
|
||||
// it only satisfies the type checker, which previously never saw this
|
||||
// file (nothing under tests/ imported it before P014's cross-tenant
|
||||
// regression tests).
|
||||
table_format: body.table_format as IcebergTableFormat | undefined,
|
||||
actor_id: body.actor_id,
|
||||
correlation_id: body.correlation_id,
|
||||
});
|
||||
@@ -48,10 +62,21 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// P014: tenant_id used to be optional here, and
|
||||
// DatasetIcebergMappingService.listMappings treats an absent tenant_id
|
||||
// filter as "no restriction" -- omitting the query param returned every
|
||||
// tenant's dataset<->Iceberg-table mappings (namespace, table name, storage
|
||||
// URI). Now required and cross-checked, matching the rest of the surface.
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const mappings = await mappingService.listMappings({
|
||||
tenant_id: searchParams.get("tenant_id") ?? undefined,
|
||||
tenant_id: tenantId,
|
||||
project_id: searchParams.get("project_id") ?? undefined,
|
||||
dataset_id: searchParams.get("dataset_id") ?? undefined,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* app/api/0pt/lineage/route.ts
|
||||
* =============================
|
||||
* P067 DoD: "source -> output lineage is QUERYABLE". This is the query.
|
||||
*
|
||||
* GET /api/0pt/lineage?tenant_id=…&output_name=… -> what fed this output
|
||||
* GET /api/0pt/lineage?tenant_id=…&input_name=… -> what this input produced
|
||||
*
|
||||
* The answer comes from 0pt's local projection of the OpenLineage events it
|
||||
* emits to AUD0 (src/lineage/lineage-store.ts). AUD0 remains the system of
|
||||
* record; this endpoint exists because "emitted to AUD0" was never the same
|
||||
* thing as "answerable from 0pt", and before this route nothing in this repo
|
||||
* could answer either question.
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { lineageStore } from "@/src/services/source-registry";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
const outputName = searchParams.get("output_name") ?? undefined;
|
||||
const inputName = searchParams.get("input_name") ?? undefined;
|
||||
if (!tenantId) return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
if (!outputName && !inputName) {
|
||||
return NextResponse.json(
|
||||
{ error: "one of output_name or input_name is required — an unfiltered lineage dump is not a query" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
const guard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (guard) return guard;
|
||||
const limitRaw = searchParams.get("limit");
|
||||
const limit = limitRaw ? Math.min(Math.max(Number(limitRaw), 1), 500) : undefined;
|
||||
const edges = await lineageStore.query({
|
||||
tenant_id: tenantId,
|
||||
output_name: outputName,
|
||||
input_name: inputName,
|
||||
limit,
|
||||
});
|
||||
return NextResponse.json({ edges, count: edges.length });
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* app/api/0pt/quality/bridge-run/route.ts
|
||||
* ==========================================
|
||||
* The P010 TS/Python split-brain bridge (BEFORE_STATE.md §2). This is the
|
||||
* ONE route the production Python engine
|
||||
* (services/api/workers/quality_bridge.py, called from
|
||||
* services/api/workers/pipeline.py) talks to. It:
|
||||
*
|
||||
* 1. auto-provisions a deterministic, tenant-scoped baseline rule set for
|
||||
* (tenant_id, dataset_id) the first time it's seen (src/quality/quality-bridge.ts) --
|
||||
* the Python engine never has to pre-register rules through the CRUD
|
||||
* surface just to get a quality read on an order's already-produced rows;
|
||||
* 2. runs QualityService.runQuality synchronously against the rows the
|
||||
* pipeline already produced (delivered, post the Python filter --
|
||||
* this is an ADVISORY second opinion, not a gate, until Simon decides
|
||||
* to wire per-row gating -- see quality_bridge.py's docstring for why
|
||||
* that isn't done in this pass);
|
||||
* 3. returns the run + any open issues.
|
||||
*
|
||||
* This does not replace, call, or block on the Python filter in any way --
|
||||
* it is purely additive. If this route is unreachable, times out, or 500s,
|
||||
* the Python side is required to fail open (never raise into the pipeline).
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { parseBody, qualityBridgeRunSchema } from "@/src/validation/0pt-schemas";
|
||||
import { qualityService } from "@/src/services/quality";
|
||||
import { ensureBaselineRules } from "@/src/quality/quality-bridge";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const __raw = await request.json();
|
||||
const __parsed = parseBody(qualityBridgeRunSchema, __raw);
|
||||
if (!__parsed.ok) {
|
||||
return NextResponse.json(__parsed.body, { status: __parsed.status });
|
||||
}
|
||||
const body = __parsed.data;
|
||||
|
||||
await ensureBaselineRules(qualityService, {
|
||||
tenant_id: body.tenant_id,
|
||||
project_id: body.project_id,
|
||||
dataset_id: body.dataset_id,
|
||||
});
|
||||
|
||||
const run = await qualityService.runQuality({
|
||||
tenant_id: body.tenant_id,
|
||||
project_id: body.project_id,
|
||||
dataset_id: body.dataset_id,
|
||||
dataset_version: body.dataset_version,
|
||||
rows: body.rows,
|
||||
correlation_id: body.correlation_id,
|
||||
});
|
||||
|
||||
const issues = qualityService.listIssues({
|
||||
tenant_id: body.tenant_id,
|
||||
dataset_id: body.dataset_id,
|
||||
status: "open",
|
||||
});
|
||||
|
||||
return NextResponse.json({ run, issues }, { status: 201 });
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* app/api/0pt/quality/issues/route.ts
|
||||
* ======================================
|
||||
* quality.list_issues (GET) -- issues opened by finished quality runs
|
||||
* (human-review handoff, Master-DoD §10).
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { qualityService } from "@/src/services/quality";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
import type { DataQualityIssue } from "@/src/quality/quality-types";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const issues = qualityService.listIssues({
|
||||
tenant_id: tenantId,
|
||||
dataset_id: searchParams.get("dataset_id") ?? undefined,
|
||||
status: (searchParams.get("status") as DataQualityIssue["status"]) ?? undefined,
|
||||
});
|
||||
return NextResponse.json(issues);
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* app/api/0pt/quality/rules/[ruleId]/route.ts
|
||||
* ===============================================
|
||||
* quality.get_rule (GET) + quality.update_rule (PUT, versioned -- bumps
|
||||
* `version`, records the superseded row). Cross-tenant reads are NOT_FOUND
|
||||
* (no existence oracle), matching QualityService.getRule's own contract.
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { qualityService } from "@/src/services/quality";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
import { z } from "zod";
|
||||
|
||||
const updateQualityRuleSchema = z.object({
|
||||
tenant_id: z.string().min(1),
|
||||
name: z.string().min(1).optional(),
|
||||
expectation: z.object({ expectation_type: z.string().min(1), kwargs: z.record(z.string(), z.unknown()) }).optional(),
|
||||
severity: z.enum(["info", "warning", "error", "critical"]).optional(),
|
||||
status: z.enum(["active", "disabled", "superseded"]).optional(),
|
||||
});
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ ruleId: string }> }) {
|
||||
try {
|
||||
const { ruleId } = await params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const versions = searchParams.get("versions") === "true";
|
||||
if (versions) {
|
||||
return NextResponse.json(qualityService.getRuleVersions(ruleId, tenantId));
|
||||
}
|
||||
return NextResponse.json(qualityService.getRule(ruleId, tenantId));
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(request: NextRequest, { params }: { params: Promise<{ ruleId: string }> }) {
|
||||
try {
|
||||
const { ruleId } = await params;
|
||||
const raw = await request.json();
|
||||
const parsed = updateQualityRuleSchema.safeParse(raw);
|
||||
if (!parsed.success) {
|
||||
return NextResponse.json(
|
||||
{ error: "validation_error", issues: parsed.error.issues.map((i) => ({ path: i.path.join("."), message: i.message })) },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
const { tenant_id, ...patch } = parsed.data;
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenant_id);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const rule = await qualityService.updateRule(ruleId, tenant_id, patch);
|
||||
return NextResponse.json(rule);
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* app/api/0pt/quality/rules/route.ts
|
||||
* ====================================
|
||||
* quality.create_rule (POST) + quality.list_rules (GET) -- the CRUD surface
|
||||
* over QualityService's versioned rule registry (src/quality/quality-service.ts,
|
||||
* Master-DoD §10). Uses the shared singleton from src/services/quality.ts,
|
||||
* not a fresh `new QualityService()` per route module -- see that file's
|
||||
* doc comment (and BEFORE_STATE.md §1, which found and fixed the same
|
||||
* per-module-instance defect for the Source Registry).
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { parseBody, createQualityRuleSchema } from "@/src/validation/0pt-schemas";
|
||||
import { qualityService } from "@/src/services/quality";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
import type { DataQualityRule } from "@/src/quality/quality-types";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const __raw = await request.json();
|
||||
const __parsed = parseBody(createQualityRuleSchema, __raw);
|
||||
if (!__parsed.ok) {
|
||||
return NextResponse.json(__parsed.body, { status: __parsed.status });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, __parsed.data.tenant_id);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const rule = await qualityService.createRule(__parsed.data);
|
||||
return NextResponse.json(rule, { status: 201 });
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const rules = qualityService.listRules({
|
||||
tenant_id: tenantId,
|
||||
dataset_id: searchParams.get("dataset_id") ?? undefined,
|
||||
status: (searchParams.get("status") as DataQualityRule["status"]) ?? undefined,
|
||||
});
|
||||
return NextResponse.json(rules);
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* app/api/0pt/quality/runs/[runId]/route.ts
|
||||
* =============================================
|
||||
* quality.get_run (GET). Cross-tenant reads are NOT_FOUND.
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { qualityService } from "@/src/services/quality";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ runId: string }> }) {
|
||||
try {
|
||||
const { runId } = await params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
return NextResponse.json(qualityService.getRun(runId, tenantId));
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* app/api/0pt/quality/runs/route.ts
|
||||
* ====================================
|
||||
* quality.run (POST) + quality.list_runs (GET). POST executes all active
|
||||
* rules for a dataset against caller-supplied rows -- runs synchronously
|
||||
* when every active rule's expectation is locally executable, otherwise
|
||||
* delegates to the GE backend via N0D (QualityService.runQuality never
|
||||
* fabricates a result for a check it couldn't run).
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { parseBody, createQualityRunSchema } from "@/src/validation/0pt-schemas";
|
||||
import { qualityService } from "@/src/services/quality";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const __raw = await request.json();
|
||||
const __parsed = parseBody(createQualityRunSchema, __raw);
|
||||
if (!__parsed.ok) {
|
||||
return NextResponse.json(__parsed.body, { status: __parsed.status });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, __parsed.data.tenant_id);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const run = await qualityService.runQuality(__parsed.data);
|
||||
return NextResponse.json(run, { status: 201 });
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const runs = qualityService.listRuns({
|
||||
tenant_id: tenantId,
|
||||
dataset_id: searchParams.get("dataset_id") ?? undefined,
|
||||
});
|
||||
return NextResponse.json(runs);
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* app/api/0pt/sources/[sourceId]/activate/route.ts
|
||||
* ==================================================
|
||||
* P060 activation gate over HTTP. POST activates a source ONLY when it is
|
||||
* classified (owner + unexpired authorization + rights + provenance);
|
||||
* otherwise it returns 403 AUTHORIZATION_DENIED naming every missing fact.
|
||||
* GET returns the classification without changing anything, so an operator
|
||||
* can see what is missing before trying.
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { activateSourceSchema, parseBody } from "@/src/validation/0pt-schemas";
|
||||
import { sourceRegistryService } from "@/src/services/source-registry";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ sourceId: string }> }) {
|
||||
try {
|
||||
const { sourceId } = await params;
|
||||
const tenantId = new URL(request.url).searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const guard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (guard) return guard;
|
||||
return NextResponse.json(await sourceRegistryService.classifySource(sourceId, tenantId));
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest, { params }: { params: Promise<{ sourceId: string }> }) {
|
||||
try {
|
||||
const { sourceId } = await params;
|
||||
const parsed = parseBody(activateSourceSchema, await request.json());
|
||||
if (!parsed.ok) return NextResponse.json(parsed.body, { status: parsed.status });
|
||||
const guard = assertTenantMatchesVerified(request, parsed.data.tenant_id);
|
||||
if (guard) return guard;
|
||||
const source = await sourceRegistryService.activateSource(
|
||||
sourceId,
|
||||
parsed.data.tenant_id,
|
||||
parsed.data.actor_id,
|
||||
);
|
||||
return NextResponse.json(source);
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* app/api/0pt/sources/[sourceId]/authorization/route.ts
|
||||
* ======================================================
|
||||
* P060 "authorization": the recorded decision that 0pt may connect to this
|
||||
* source at all — separate from rights (what the DATA may be used for). PUT
|
||||
* is an upsert; a service identity as `granted_by` is rejected (400), because
|
||||
* a source may not authorize itself.
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { parseBody, setSourceAuthorizationSchema } from "@/src/validation/0pt-schemas";
|
||||
import { sourceRegistryService } from "@/src/services/source-registry";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ sourceId: string }> }) {
|
||||
try {
|
||||
const { sourceId } = await params;
|
||||
const tenantId = new URL(request.url).searchParams.get("tenant_id");
|
||||
if (!tenantId) return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
const guard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (guard) return guard;
|
||||
const auth = await sourceRegistryService.getAuthorization(sourceId, tenantId);
|
||||
if (!auth) {
|
||||
return NextResponse.json({ error: `source ${sourceId} has no authorization record` }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json(auth);
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(request: NextRequest, { params }: { params: Promise<{ sourceId: string }> }) {
|
||||
try {
|
||||
const { sourceId } = await params;
|
||||
const parsed = parseBody(setSourceAuthorizationSchema, await request.json());
|
||||
if (!parsed.ok) return NextResponse.json(parsed.body, { status: parsed.status });
|
||||
const guard = assertTenantMatchesVerified(request, parsed.data.tenant_id);
|
||||
if (guard) return guard;
|
||||
return NextResponse.json(
|
||||
await sourceRegistryService.setAuthorization({ ...parsed.data, source_id: sourceId }),
|
||||
);
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* app/api/0pt/sources/[sourceId]/freshness/route.ts
|
||||
* =====================================================
|
||||
* Freshness view derived from provenance's freshness_sla_hours + the last
|
||||
* successful observation (recorded via POST .../health with status "up",
|
||||
* or SourceRegistryService.recordSuccess directly). Read-only — there is no
|
||||
* separate write path here by design; freshness is a derived signal, not
|
||||
* its own record.
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { sourceRegistryService } from "@/src/services/source-registry";
|
||||
import { siaxErrorResponse } from "@/src/http/siax-error-response";
|
||||
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ sourceId: string }> }) {
|
||||
try {
|
||||
const { sourceId } = await params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tenantId = searchParams.get("tenant_id");
|
||||
if (!tenantId) {
|
||||
return NextResponse.json({ error: "tenant_id is required" }, { status: 400 });
|
||||
}
|
||||
const tenantGuard = assertTenantMatchesVerified(request, tenantId);
|
||||
if (tenantGuard) return tenantGuard;
|
||||
const freshness = await sourceRegistryService.getFreshness(sourceId, tenantId);
|
||||
return NextResponse.json(freshness);
|
||||
} catch (error: unknown) {
|
||||
return siaxErrorResponse(error);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user