diff --git a/.env.example b/.env.example index ea25440..d5c2bb9 100644 --- a/.env.example +++ b/.env.example @@ -58,6 +58,16 @@ DEV_LOGIN_KEY= # Shared token for internal/service-to-service calls; sent as X-Internal-Token # on every engineFetch() call (lib/engine.ts). INTERNAL_TOKEN=change-me-internal-token +# Tenant authority for the internal-token principal. Comma-separated allowlist +# of tenants this deployment's engine is entitled to write for, e.g. +# "379976258701823235". This is the ONLY source of tenant authority for +# X-Internal-Token: a request header may never name a tenant. Empty/unset means +# the service principal has no tenant authority and tenant-scoped writes +# (canonical facts, quality bridge runs) are denied with 403. Exactly ONE +# tenant is supported: the shared token identifies one service process, not a +# set of principals. A multi-tenant list is refused (401) until a verified +# workload-identity binding exists. +INTERNAL_SERVICE_TENANTS= # --------------------------------------------------------------------------- # Zitadel / OIDC Bearer verification (Wave 2 hardening) -- wired in code today diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 6b6ef5e..1e31c9a 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -294,9 +294,9 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: SonarQube analysis (self-hosted sonar.siax.io) + - name: SonarQube analysis (self-hosted sonar.siax.dev) env: - SONAR_HOST_URL: https://sonar.siax.io + SONAR_HOST_URL: https://sonar.siax.dev SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | set -euo pipefail @@ -309,3 +309,22 @@ jobs: trap 'docker rm -f "$cid" >/dev/null 2>&1 || true' EXIT docker cp . "$cid":/usr/src docker start -a "$cid" + + design-conformance: + name: Component conformance (blocking) + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '22' + - name: Checkout canonical siax-standard (SSOT) + uses: actions/checkout@v4 + with: + repository: admin/siax-standard + token: ${{ secrets.SIAX_CI_TOKEN }} + path: siax-standard-ssot + - name: Component conformance (blocking) + run: | + node --input-type=module -e "import('./siax-standard-ssot/packages/doctor/src/commands/component-conformance.mjs').then(m=>{process.exit(m.run(['--repo', process.env.GITHUB_WORKSPACE, '--allow-path-prefix', 'siax-standard-ssot/', '--fail-on=block']))})" diff --git a/.siax/component-allowlist.json b/.siax/component-allowlist.json new file mode 100644 index 0000000..d23e876 --- /dev/null +++ b/.siax/component-allowlist.json @@ -0,0 +1 @@ +{"allow":[{"pathPrefix":"components/states.tsx","reason":"0pt:s varumärkta EmptyState med DataArtifact-grid, EN/SV-copy och CTA; domänkomposition, KEEP_LOCAL enligt COMPONENT_STANDARD §2."},{"pathPrefix":"components/theme-provider.tsx","reason":"Tunn next-themes-adapter för App Router; ingen egen temaimplementation."},{"pathPrefix":"components/ui/toaster.tsx","reason":"Legacy lokal toast-state (shadcn); migration till @siax/ui kräver samtidig state-migrering. KEEP_LOCAL med backlog."}]} diff --git a/acquisition.consumer.json b/acquisition.consumer.json new file mode 100644 index 0000000..0bca0ae --- /dev/null +++ b/acquisition.consumer.json @@ -0,0 +1,36 @@ +{ + "$schema": "https://git.siax.io/sax3l/siax-standard/raw/branch/main/schema/siax.acquisition-consumer.schema.json", + "schemaVersion": "siax.acquisition-consumer/v1", + "application": "0pt", + "owner": "0pt", + "tenantScoped": true, + "capabilities": [ + "siax.acquisition.plan", + "siax.acquisition.run", + "siax.acquisition.status", + "siax.acquisition.result", + "siax.acquisition.query_existing", + "siax.acquisition.discovery_search", + "siax.acquisition.extract", + "siax.acquisition.evidence" + ], + "allowedPurposes": [ + "data.acquisition", + "source.registration" + ], + "dataCategories": [ + "public", + "company", + "product", + "pricing", + "vehicle", + "property", + "document", + "event", + "other" + ], + "maxCostSEK": 25, + "reuseExistingFacts": true, + "mustNotOwnEngines": true, + "engines": [] +} diff --git a/app/api/0pt/canonical/facts/route.ts b/app/api/0pt/canonical/facts/route.ts new file mode 100644 index 0000000..aa62664 --- /dev/null +++ b/app/api/0pt/canonical/facts/route.ts @@ -0,0 +1,52 @@ +/** + * app/api/0pt/canonical/facts/route.ts + * ==================================== + * POST — canonical structured-observation write (entities/facts/relations). + * GET — tenant-scoped read for consumers (products, agents, L0RE projection). + * + * 0pt owns observed facts; L0RE owns epistemic propositions/projections and + * consumes this API. Tenant is always cross-checked against the verified + * principal (assertTenantMatchesVerified), never trusted from the body alone. + */ +import { NextRequest, NextResponse } from "next/server"; +import { canonicalWriteSchema, parseBody } from "@/src/validation/0pt-schemas"; +import { canonicalFactService } from "@/src/services/canonical-fact-registry"; +import { siaxErrorResponse } from "@/src/http/siax-error-response"; +import { assertTenantMatchesVerified } from "@/src/http/tenant-guard"; + +export async function POST(request: NextRequest) { + try { + const parsed = parseBody(canonicalWriteSchema, await request.json()); + if (!parsed.ok) return NextResponse.json(parsed.body, { status: parsed.status }); + const body = parsed.data; + const guard = assertTenantMatchesVerified(request, body.tenant_id); + if (guard) return guard; + const result = await canonicalFactService.write(body); + return NextResponse.json(result, { 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 guard = assertTenantMatchesVerified(request, tenantId); + if (guard) return guard; + const limitRaw = searchParams.get("limit"); + const facts = await canonicalFactService.query({ + tenant_id: tenantId, + entity_id: searchParams.get("entity_id") ?? undefined, + entity_type: searchParams.get("entity_type") ?? undefined, + identity_namespace: searchParams.get("identity_namespace") ?? undefined, + identity_value: searchParams.get("identity_value") ?? undefined, + predicate: searchParams.get("predicate") ?? undefined, + limit: limitRaw ? Number(limitRaw) : undefined, + }); + return NextResponse.json({ facts }); + } catch (error: unknown) { + return siaxErrorResponse(error); + } +} diff --git a/app/api/0pt/quality/bridge-run/route.ts b/app/api/0pt/quality/bridge-run/route.ts index ecdf72b..87c96a3 100644 --- a/app/api/0pt/quality/bridge-run/route.ts +++ b/app/api/0pt/quality/bridge-run/route.ts @@ -26,6 +26,7 @@ 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"; +import { assertTenantMatchesVerified } from "@/src/http/tenant-guard"; export async function POST(request: NextRequest) { try { @@ -35,6 +36,11 @@ export async function POST(request: NextRequest) { return NextResponse.json(__parsed.body, { status: __parsed.status }); } const body = __parsed.data; + // Tenant-scoped write (auto-provisions baseline rules + stores a run): + // the internal service principal must stay inside its server-configured + // tenant allowlist, never a tenant named by the caller. + const guard = assertTenantMatchesVerified(request, body.tenant_id); + if (guard) return guard; await ensureBaselineRules(qualityService, { tenant_id: body.tenant_id, diff --git a/app/portal/dokument/page.tsx b/app/portal/dokument/page.tsx index f7fbf75..b9e14d7 100644 --- a/app/portal/dokument/page.tsx +++ b/app/portal/dokument/page.tsx @@ -1,6 +1,7 @@ 'use client'; import { useCallback, useEffect, useRef, useState } from 'react'; +import { FileDropzone } from '@siax/ui/components/file-dropzone'; import { useT } from '@/components/locale-provider'; import { PortalShell } from '@/components/portal-shell'; @@ -72,7 +73,6 @@ export default function DocumentsPage() { const [uploadNote, setUploadNote] = useState(null); const [uploading, setUploading] = useState(false); const [unknownOutcome, setUnknownOutcome] = useState(null); - const inputRef = useRef(null); // One idempotency key per selected file: a retry (double click, network // error, reload-and-pick-the-same-file) returns the SAME document instead of // creating a duplicate. Picking a different file resets it. @@ -277,34 +277,16 @@ export default function DocumentsPage() { /> -
inputRef.current?.click()} - onKeyDown={(event) => { - if (event.key === 'Enter' || event.key === ' ') { - event.preventDefault(); - inputRef.current?.click(); - } + { + uploadKey.current = null; + setFile(files[0] ?? null); }} - className="mt-4 flex cursor-pointer flex-col items-center justify-center border border-dashed border-border px-6 py-10 text-center focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" - > - {t({ en: 'choose a file', sv: 'välj en fil' })} - - {file - ? file.name - : t({ en: 'PDF, Word, Excel, CSV, images…', sv: 'PDF, Word, Excel, CSV, bilder…' })} - - { - uploadKey.current = null; - setFile(event.target.files?.[0] ?? null); - }} - /> -
+ />