/** * hightrusted CAPTURE — Node.js Quickstart * * Voraussetzung: * npm install @hightrusted/capture * * API-Key holen: * https://capture.hightrusted.net/dashboard/api-keys */ import { Client, RateLimitedError } from '@hightrusted/capture'; const client = new Client({ apiKey: process.env.HIGHTRUSTED_API_KEY }); // ────────────────────────────────────────────────────────────────── // 1. Synchrone Capture // ────────────────────────────────────────────────────────────────── console.log('→ Erstelle Capture (synchron)...'); const capture = await client.capture({ url: 'https://example.com', reference: 'quickstart-demo', viewport: { width: 1920, height: 1080 }, }); console.log(` ID: ${capture.id}`); console.log(` Status: ${capture.status}`); console.log(` Verify-URL: ${capture.verify_url}`); console.log(` Zeitstempel: ${capture.timestamp.issued_at}`); // ────────────────────────────────────────────────────────────────── // 2. Verifikation (kostenlos) // ────────────────────────────────────────────────────────────────── console.log('\n→ Verifiziere die Capture...'); const result = await client.verify({ source: capture.id }); console.log(` Gültig: ${result.valid}`); // ────────────────────────────────────────────────────────────────── // 3. PDF herunterladen // ────────────────────────────────────────────────────────────────── console.log('\n→ Lade PDF herunter...'); const path = await client.downloadPdf(capture.id, `./capture_${capture.id.slice(0, 8)}.pdf`); console.log(` Gespeichert: ${path}`); // ────────────────────────────────────────────────────────────────── // 4. Quota // ────────────────────────────────────────────────────────────────── console.log('\n→ Quota-Status...'); try { const usage = await client.usage(); console.log(` Plan: ${usage.plan}`); console.log(` Verbraucht: ${usage.used_calls}/${usage.included_calls}`); } catch (err) { if (err instanceof RateLimitedError) { console.log(` Rate-limited, retry in ${err.retryAfterSeconds}s`); } else throw err; }