/** * Dev-only scraper test harness — /dev/fetch * * ⚠️ This page is mounted ONLY in DEV mode (import.meta.env.DEV). * It is never included in production builds. * * Usage: * 1. Run `npm run login` in the frontend directory. * 2. Log in through the normal app flow first (the scraper endpoints require auth). * 3. Click "Refresh" — the backend resolves your IDs automatically. * 4. Scan the QR with BankID and watch status transitions until data appears. * * This runs the REAL FK scraper against the REAL Försäkringskassan site with YOUR BankID. * Only run it intentionally. SCRAPER_ENABLED=true is set by npm run login:backend. */ import { useState, useEffect } from 'react' import * as api from '@/services/api' import { useScraperFetch } from '@/hooks' import { isUnauthorized } from '@/services/errors' export function DevFetch() { const [context, setContext] = useState(null) const [contextError, setContextError] = useState(null) const [childName, setChildName] = useState('') const [childBirth, setChildBirth] = useState('') const [creatingChild, setCreatingChild] = useState(false) const scraper = useScraperFetch() const loadContext = async () => { try { const ctx = await api.getUserContext() setContext(ctx) setContextError(null) } catch (err) { if (isUnauthorized(err)) { setContextError('Not authenticated') } else { setContextError(err instanceof Error ? err.message : 'Failed to load context') } } } useEffect(() => { loadContext() }, []) const handleRefresh = async () => { await scraper.start() } const handleCreateChild = async () => { if (!context || !childName || !childBirth) return setCreatingChild(true) try { await api.createChild({ workspace_id: context.workspace_id, name: childName, birth_date: childBirth, }) await loadContext() setChildName('') setChildBirth('') } catch (err) { setContextError(err instanceof Error ? err.message : 'Failed to create child') } finally { setCreatingChild(false) } } const hasChildren = context && context.children.length > 0 return (

🔧 FK Scraper Test Harness

Dev-only. Runs the real FK scraper against Försäkringskassan with your BankID.
Log in through the normal app first — these endpoints require an app session.

{contextError && (
Setup-fel: {contextError} {scraper.isUnauthorized && (
Logga in först
)}
)} {context && (
Workspace: {context.workspace_id}
PersonalData: {context.personal_data_uuid}
Barn:{' '} {context.children.length === 0 ? Inga barn registrerade : context.children.map(c => `${c.name} (${c.birth_date})`).join(', ')}
)} {context && !hasChildren && (
Registrera ett barn för att kunna köra scrapern
setChildName(e.target.value)} style={{ padding: '0.4rem', fontFamily: 'monospace', fontSize: '0.85rem' }} /> setChildBirth(e.target.value)} style={{ padding: '0.4rem', fontFamily: 'monospace', fontSize: '0.85rem' }} />
)}
{scraper.resolvedIds && (
workspace_id: {scraper.resolvedIds.workspace_id}
personal_data_uuid: {scraper.resolvedIds.personal_data_uuid}
child_id: {scraper.resolvedIds.child_id}
)} {scraper.error && (
Fel: {scraper.error}
)} {scraper.pollData && (
Status:{' '} {scraper.pollData.status} {scraper.pollData.message && ( — {scraper.pollData.message} )}
{scraper.pollData.status === 'awaiting_scan' && scraper.pollData.qr_data && (

Öppna BankID-appen och skanna QR-koden (uppdateras automatiskt):

BankID QR-kod
)} {(scraper.pollData.status === 'authenticating' || scraper.pollData.status === 'fetching') && (

⏳ {scraper.pollData.status === 'authenticating' ? 'Autentiserar…' : 'Hämtar data från FK…'}

)} {scraper.pollData.status === 'done' && scraper.pollData.result && (

✅ Klar! Hämtad data:

                {JSON.stringify(scraper.pollData.result, null, 2)}
              
)} {scraper.pollData.status === 'cancelled' && (

Sessionen avbröts.

)} {scraper.isRunning && ( )}
)}
) }