diff --git a/apps/beheer/Dockerfile b/apps/beheer/Dockerfile new file mode 100644 index 0000000..c8cb1ab --- /dev/null +++ b/apps/beheer/Dockerfile @@ -0,0 +1,27 @@ +# Multi-stage build for the beheer portal (Angular → nginx). +# Build context is the repo root (the app needs the pnpm workspace + libs). See infra/docker-compose.yml. +FROM node:24-slim AS build +WORKDIR /src +RUN corepack enable && corepack prepare pnpm@11.5.2 --activate + +# Restore first (cached unless the manifests change). +COPY package.json pnpm-lock.yaml pnpm-workspace.yaml nx.json tsconfig.base.json eslint.config.mjs ./ +RUN pnpm install --frozen-lockfile + +# Sources (only what the app + its libs need). +COPY apps/beheer apps/beheer +COPY libs libs +RUN pnpm nx build beheer + +FROM nginx:1.27-alpine AS runtime +COPY apps/beheer/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=build /src/dist/apps/beheer/browser /usr/share/nginx/html +# Compose-time OIDC config: the browser (Playwright, on the compose network) reaches Keycloak by +# service name, so the token issuer matches the BFF's medewerker authority (host-consistent, ADR-0013). +RUN printf '{ "authority": "http://keycloak:8080/realms/medewerker" }\n' > /usr/share/nginx/html/config.json +# Make the reverse-proxy resolver engine-portable (Docker 127.0.0.11 vs podman aardvark); runs from +# the nginx image's /docker-entrypoint.d before nginx starts. +COPY apps/portal-nginx-resolver.sh /docker-entrypoint.d/40-resolver.sh +RUN chmod +x /docker-entrypoint.d/40-resolver.sh + +EXPOSE 80 diff --git a/apps/beheer/eslint.config.mjs b/apps/beheer/eslint.config.mjs new file mode 100644 index 0000000..af5ff32 --- /dev/null +++ b/apps/beheer/eslint.config.mjs @@ -0,0 +1,34 @@ +import nx from '@nx/eslint-plugin'; +import baseConfig from '../../eslint.config.mjs'; + +export default [ + ...nx.configs['flat/angular'], + ...nx.configs['flat/angular-template'], + ...baseConfig, + { + files: ['**/*.ts'], + rules: { + '@angular-eslint/directive-selector': [ + 'error', + { + type: 'attribute', + prefix: 'app', + style: 'camelCase', + }, + ], + '@angular-eslint/component-selector': [ + 'error', + { + type: 'element', + prefix: 'app', + style: 'kebab-case', + }, + ], + }, + }, + { + files: ['**/*.html'], + // Override or add rules here + rules: {}, + }, +]; diff --git a/apps/beheer/nginx.conf b/apps/beheer/nginx.conf new file mode 100644 index 0000000..08439bc --- /dev/null +++ b/apps/beheer/nginx.conf @@ -0,0 +1,24 @@ +server { + listen 80; + server_name _; + root /usr/share/nginx/html; + index index.html; + + # Resolve the BFF via Docker's embedded DNS at request time (variable proxy_pass), so nginx starts + # even before the BFF is up and picks up restarts — instead of failing to load the config. + resolver 127.0.0.11 ipv6=off valid=30s; + + # Same-origin API: proxy the beheer endpoint group to the bff service. The api-client uses + # relative URLs, so the browser calls this origin and nginx forwards to the BFF — no CORS, and the + # medewerker token (same-origin) is attached by the app's interceptor (ADR-0013). + location /beheer/ { + set $bff http://bff:8080; + proxy_pass $bff; + proxy_set_header Host $host; + } + + # SPA fallback — Angular client-side routing. + location / { + try_files $uri $uri/ /index.html; + } +} diff --git a/apps/beheer/project.json b/apps/beheer/project.json new file mode 100644 index 0000000..890a071 --- /dev/null +++ b/apps/beheer/project.json @@ -0,0 +1,80 @@ +{ + "name": "beheer", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "prefix": "app", + "sourceRoot": "apps/beheer/src", + "tags": [], + "targets": { + "build": { + "executor": "@angular/build:application", + "outputs": ["{options.outputPath}"], + "defaultConfiguration": "production", + "options": { + "outputPath": "dist/apps/beheer", + "browser": "apps/beheer/src/main.ts", + "tsConfig": "apps/beheer/tsconfig.app.json", + "assets": [ + { + "glob": "**/*", + "input": "apps/beheer/public" + } + ], + "styles": ["apps/beheer/src/styles.css"] + }, + "configurations": { + "production": { + "budgets": [ + { + "type": "initial", + "maximumWarning": "1mb", + "maximumError": "2mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "4kb", + "maximumError": "8kb" + } + ], + "outputHashing": "all" + }, + "development": { + "optimization": false, + "extractLicenses": false, + "sourceMap": true + } + } + }, + "serve": { + "continuous": true, + "executor": "@angular/build:dev-server", + "defaultConfiguration": "development", + "configurations": { + "production": { + "buildTarget": "beheer:build:production" + }, + "development": { + "buildTarget": "beheer:build:development" + } + } + }, + "lint": { + "executor": "@nx/eslint:lint" + }, + "test": { + "executor": "@angular/build:unit-test", + "options": { + "watch": false + } + }, + "serve-static": { + "continuous": true, + "executor": "@nx/web:file-server", + "options": { + "buildTarget": "beheer:build", + "staticFilePath": "dist/apps/beheer/browser", + "spa": true + } + } + } +} diff --git a/apps/beheer/public/config.json b/apps/beheer/public/config.json new file mode 100644 index 0000000..71c0f65 --- /dev/null +++ b/apps/beheer/public/config.json @@ -0,0 +1,3 @@ +{ + "authority": "http://localhost:8180/realms/medewerker" +} diff --git a/apps/beheer/public/favicon.ico b/apps/beheer/public/favicon.ico new file mode 100644 index 0000000..317ebcb Binary files /dev/null and b/apps/beheer/public/favicon.ico differ diff --git a/apps/beheer/src/app/app.config.spec.ts b/apps/beheer/src/app/app.config.spec.ts new file mode 100644 index 0000000..241dd7d --- /dev/null +++ b/apps/beheer/src/app/app.config.spec.ts @@ -0,0 +1,65 @@ +import { provideHttpClient, withInterceptors } from '@angular/common/http'; +import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; +import { TestBed } from '@angular/core/testing'; +import { BffApiV1Service } from 'api-client'; +import { authInterceptor } from 'auth'; +import { AbstractSecurityStorage, ConfigurationService } from 'angular-auth-oidc-client'; +import { SECURE_API_ROUTES } from './app.config'; + +// Guards the medewerker token wiring end-to-end. The api-client calls the BFF with RELATIVE URLs, and +// the angular-auth-oidc-client interceptor attaches the token only when `req.url` starts with a +// configured secureRoute. A regression to an absolute origin makes the relative URL never match, so +// the beheer calls go out unauthenticated and the BFF answers 401. This drives the REAL interceptor +// and the REAL api-client against the REAL production route value (SECURE_API_ROUTES); only the config +// source and token storage are faked, so the assertion turns on the actual route-matching. +describe('beheer medewerker token wiring', () => { + let http: HttpTestingController; + let bff: BffApiV1Service; + const token = 'medewerker-access-token'; + + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ + provideHttpClient(withInterceptors([authInterceptor()])), + provideHttpClientTesting(), + { + provide: ConfigurationService, + useValue: { + hasAtLeastOneConfig: () => true, + getAllConfigurations: () => [{ configId: 'medewerker', secureRoutes: SECURE_API_ROUTES }], + }, + }, + { + // A signed-in session: the storage the interceptor's token lookup reads from. + provide: AbstractSecurityStorage, + useValue: { + read: () => JSON.stringify({ authzData: token, authnResult: { id_token: 'id-token' } }), + write: () => undefined, + remove: () => undefined, + clear: () => undefined, + }, + }, + ], + }); + http = TestBed.inject(HttpTestingController); + bff = TestBed.inject(BffApiV1Service); + }); + + afterEach(() => http.verify()); + + it('attaches the bearer token to the relative catalogus call', () => { + bff.getBeheerCatalogiZaaktypen().subscribe(); + + const req = http.expectOne('/beheer/catalogi/zaaktypen'); + expect(req.request.headers.get('Authorization')).toBe(`Bearer ${token}`); + req.flush([]); + }); + + it('leaves the anonymous openbaar register call unauthenticated', () => { + bff.getOpenbaarRegister().subscribe(); + + const req = http.expectOne((r) => r.url === '/openbaar/register'); + expect(req.request.headers.has('Authorization')).toBe(false); + req.flush([]); + }); +}); diff --git a/apps/beheer/src/app/app.config.ts b/apps/beheer/src/app/app.config.ts new file mode 100644 index 0000000..5785364 --- /dev/null +++ b/apps/beheer/src/app/app.config.ts @@ -0,0 +1,39 @@ +import { provideHttpClient, withInterceptors } from '@angular/common/http'; +import { ApplicationConfig, provideBrowserGlobalErrorListeners } from '@angular/core'; +import { provideRouter } from '@angular/router'; +import { authInterceptor, provideMedewerkerAuth } from 'auth'; +import { appRoutes } from './app.routes'; + +/** Environment-specific settings fetched from /config.json at startup (see main.ts). */ +export interface RuntimeConfig { + /** The Keycloak `medewerker` realm issuer as the browser reaches it (dev: localhost; compose: keycloak:8080). */ + authority: string; +} + +/** + * Route prefixes whose requests carry the medewerker token. These MUST match the **relative** URLs + * the api-client actually calls (same-origin via the nginx proxy) — the interceptor matches on + * `req.url`, which stays relative, so an absolute origin would never match and the token would go + * unattached. Only `/beheer/` is secured; the app calls no other endpoint group. + */ +export const SECURE_API_ROUTES = ['/beheer/']; + +/** + * Build the app providers from runtime config. `redirectUrl` is the app's own origin (where Keycloak + * redirects back). `secureRoutes` uses {@link SECURE_API_ROUTES} — relative prefixes, not the origin. + */ +export function appConfig(runtime: RuntimeConfig): ApplicationConfig { + const origin = typeof window !== 'undefined' ? window.location.origin : '/'; + return { + providers: [ + provideBrowserGlobalErrorListeners(), + provideRouter(appRoutes), + provideHttpClient(withInterceptors([authInterceptor()])), + provideMedewerkerAuth({ + authority: runtime.authority, + redirectUrl: origin, + secureRoutes: SECURE_API_ROUTES, + }), + ], + }; +} diff --git a/apps/beheer/src/app/app.css b/apps/beheer/src/app/app.css new file mode 100644 index 0000000..e69de29 diff --git a/apps/beheer/src/app/app.html b/apps/beheer/src/app/app.html new file mode 100644 index 0000000..0680b43 --- /dev/null +++ b/apps/beheer/src/app/app.html @@ -0,0 +1 @@ + diff --git a/apps/beheer/src/app/app.routes.ts b/apps/beheer/src/app/app.routes.ts new file mode 100644 index 0000000..942b1be --- /dev/null +++ b/apps/beheer/src/app/app.routes.ts @@ -0,0 +1,7 @@ +import { Route } from '@angular/router'; +import { authenticatedGuard } from 'auth'; +import { CatalogusPage } from './catalogus/catalogus-page'; + +export const appRoutes: Route[] = [ + { path: '', component: CatalogusPage, canActivate: [authenticatedGuard] }, +]; diff --git a/apps/beheer/src/app/app.spec.ts b/apps/beheer/src/app/app.spec.ts new file mode 100644 index 0000000..3ac05ab --- /dev/null +++ b/apps/beheer/src/app/app.spec.ts @@ -0,0 +1,15 @@ +import { provideRouter } from '@angular/router'; +import { render, screen } from '@testing-library/angular'; +import { App } from './app'; + +describe('App', () => { + it('renders the router outlet shell', async () => { + const { container } = await render(App, { + providers: [provideRouter([])], + }); + + // The shell is a thin host for routed pages (the CatalogusPage owns the heading). + expect(container.querySelector('router-outlet')).toBeTruthy(); + expect(screen).toBeTruthy(); + }); +}); diff --git a/apps/beheer/src/app/app.ts b/apps/beheer/src/app/app.ts new file mode 100644 index 0000000..ba93fca --- /dev/null +++ b/apps/beheer/src/app/app.ts @@ -0,0 +1,12 @@ +import { Component } from '@angular/core'; +import { RouterModule } from '@angular/router'; + +@Component({ + imports: [RouterModule], + selector: 'app-root', + templateUrl: './app.html', + styleUrl: './app.css', +}) +export class App { + protected title = 'beheer'; +} diff --git a/apps/beheer/src/app/catalogus/catalogus-page.html b/apps/beheer/src/app/catalogus/catalogus-page.html new file mode 100644 index 0000000..e9767e7 --- /dev/null +++ b/apps/beheer/src/app/catalogus/catalogus-page.html @@ -0,0 +1,40 @@ +
+ + Catalogus +

+ De gepubliceerde zaaktypen uit de ZTC-catalogus. Alleen-lezen — beheer van de default-fill volgt + in een latere slice. +

+ + @if (loading()) { +

Bezig met laden…

+ } @else if (failed()) { +

+ Kon de catalogus niet laden. Controleer of je als beheerder bent ingelogd en probeer het + opnieuw. +

+ } @else if (loaded() && items().length === 0) { +

De catalogus bevat geen gepubliceerde zaaktypen.

+ } @else if (items().length > 0) { + + + + + + + + + + @for (zaaktype of items(); track zaaktype.identificatie) { + + + + + } + +
+ Gepubliceerde zaaktypen +
IdentificatieOmschrijving
{{ zaaktype.identificatie }}{{ zaaktype.omschrijving }}
+ } +
+
diff --git a/apps/beheer/src/app/catalogus/catalogus-page.spec.ts b/apps/beheer/src/app/catalogus/catalogus-page.spec.ts new file mode 100644 index 0000000..897aa0e --- /dev/null +++ b/apps/beheer/src/app/catalogus/catalogus-page.spec.ts @@ -0,0 +1,75 @@ +import { signal } from '@angular/core'; +import { render, screen } from '@testing-library/angular'; +import { of, throwError } from 'rxjs'; +import { BeheerZaaktype, BffApiV1Service } from 'api-client'; +import { AuthService } from 'auth'; +import { axe } from 'vitest-axe'; +import { CatalogusPage } from './catalogus-page'; + +const sample: BeheerZaaktype[] = [ + { identificatie: 'BIG-REGISTRATIE', omschrijving: 'BIG-registratie' }, + { identificatie: 'BIG-HERREGISTRATIE', omschrijving: 'BIG-herregistratie' }, +]; + +class FakeAuth extends AuthService { + readonly isAuthenticated = signal(true); + readonly bsn = signal(undefined); + override readonly roles = signal(['beheerder']); + login(): void { + /* not exercised here */ + } + logout(): void { + /* not exercised here */ + } +} + +function setup(overrides: { getBeheerCatalogiZaaktypen?: ReturnType } = {}) { + const getBeheerCatalogiZaaktypen = + overrides.getBeheerCatalogiZaaktypen ?? vi.fn().mockReturnValue(of(sample)); + return { + getBeheerCatalogiZaaktypen, + providers: [ + { provide: BffApiV1Service, useValue: { getBeheerCatalogiZaaktypen } }, + { provide: AuthService, useClass: FakeAuth }, + ], + }; +} + +describe('CatalogusPage', () => { + it('lists the published zaaktypen on open', async () => { + const { getBeheerCatalogiZaaktypen, providers } = setup(); + await render(CatalogusPage, { providers }); + + expect(getBeheerCatalogiZaaktypen).toHaveBeenCalled(); + expect(await screen.findByText('BIG-REGISTRATIE')).toBeTruthy(); + expect(screen.getByText('BIG-registratie')).toBeTruthy(); + expect(screen.getByText('BIG-HERREGISTRATIE')).toBeTruthy(); + }); + + it('shows an empty state when the catalogus has no published zaaktypen', async () => { + const { providers } = setup({ getBeheerCatalogiZaaktypen: vi.fn().mockReturnValue(of([])) }); + await render(CatalogusPage, { providers }); + + expect(await screen.findByText(/geen gepubliceerde zaaktypen/i)).toBeTruthy(); + }); + + it('surfaces a load failure instead of swallowing it', async () => { + const { providers } = setup({ + getBeheerCatalogiZaaktypen: vi.fn().mockReturnValue(throwError(() => new Error('403'))), + }); + await render(CatalogusPage, { providers }); + + expect(await screen.findByText(/kon de catalogus niet laden/i)).toBeTruthy(); + }); + + it('has no WCAG 2.1 AA violations', async () => { + document.documentElement.lang = 'nl'; + const { container } = await render(CatalogusPage, { providers: setup().providers }); + + const results = await axe(container, { + runOnly: { type: 'tag', values: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'] }, + }); + + expect(results.violations).toEqual([]); + }); +}); diff --git a/apps/beheer/src/app/catalogus/catalogus-page.ts b/apps/beheer/src/app/catalogus/catalogus-page.ts new file mode 100644 index 0000000..b4922c0 --- /dev/null +++ b/apps/beheer/src/app/catalogus/catalogus-page.ts @@ -0,0 +1,26 @@ +import { Component, inject, signal } from '@angular/core'; +import { BeheerZaaktype, BffApiV1Service } from 'api-client'; +import { UtrechtComponentsModule } from 'ui'; + +/** + * The beheer catalogus viewer (S-15a): a signed-in beheerder sees the published ZTC zaaktypen, + * read-only. The list is served by the BFF (`GET /beheer/catalogi/zaaktypen`), which proxies the ACL — + * the only code allowed to read the ZGW Catalogi API (§8.1, ADR-0025). Managing default-fill is S-15b. + */ +@Component({ + selector: 'app-catalogus-page', + imports: [UtrechtComponentsModule], + templateUrl: './catalogus-page.html', +}) +export class CatalogusPage { + private readonly bff = inject(BffApiV1Service); + + protected readonly items = signal([]); + protected readonly loading = signal(false); + protected readonly loaded = signal(false); + protected readonly failed = signal(false); + + constructor() { + // ponytail: stub for the red test; the real load lands in the green commit. + } +} diff --git a/apps/beheer/src/index.html b/apps/beheer/src/index.html new file mode 100644 index 0000000..0ae574b --- /dev/null +++ b/apps/beheer/src/index.html @@ -0,0 +1,13 @@ + + + + + Beheerportaal BIG-register + + + + + + + + diff --git a/apps/beheer/src/main.ts b/apps/beheer/src/main.ts new file mode 100644 index 0000000..29b0198 --- /dev/null +++ b/apps/beheer/src/main.ts @@ -0,0 +1,10 @@ +import { bootstrapApplication } from '@angular/platform-browser'; +import { App } from './app/app'; +import { appConfig, type RuntimeConfig } from './app/app.config'; + +// Load environment config before bootstrap so the OIDC authority is set per environment +// (dev: localhost; compose: keycloak:8080) from a single build — 12-factor (S-08d). +fetch('config.json') + .then((response) => response.json() as Promise) + .then((config) => bootstrapApplication(App, appConfig(config))) + .catch((err) => console.error(err)); diff --git a/apps/beheer/src/styles.css b/apps/beheer/src/styles.css new file mode 100644 index 0000000..ade77c5 --- /dev/null +++ b/apps/beheer/src/styles.css @@ -0,0 +1,2 @@ +/* NL Design System theme — Utrecht design tokens (docs/frontend-decisions.md). */ +@import '@utrecht/design-tokens/dist/index.css'; diff --git a/apps/beheer/tsconfig.app.json b/apps/beheer/tsconfig.app.json new file mode 100644 index 0000000..a75ddab --- /dev/null +++ b/apps/beheer/tsconfig.app.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": [] + }, + "include": ["src/**/*.ts"], + "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"] +} diff --git a/apps/beheer/tsconfig.json b/apps/beheer/tsconfig.json new file mode 100644 index 0000000..bb7614f --- /dev/null +++ b/apps/beheer/tsconfig.json @@ -0,0 +1,31 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "isolatedModules": true, + "target": "es2022", + "moduleResolution": "bundler", + "emitDecoratorMetadata": false, + "module": "preserve" + }, + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.app.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/apps/beheer/tsconfig.spec.json b/apps/beheer/tsconfig.spec.json new file mode 100644 index 0000000..2d36c49 --- /dev/null +++ b/apps/beheer/tsconfig.spec.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "types": ["vitest/globals"] + }, + "include": ["src/**/*.ts", "src/**/*.d.ts"] +}