// Quattrino quickstart (TypeScript) - INTENT -> AUTHORITY -> ACTION -> PROOF. // SDK is a single dependency-free file: curl -o quattrino.ts https://quattrino.io/api/v1/public/sdk/typescript // npx tsx quickstart.ts (Node 18+, needs global fetch) import { Quattrino } from "./quattrino"; const q = new Quattrino({ apiKey: process.env.QUATTRINO_AGENT_KEY!, baseUrl: process.env.QUATTRINO_BASE ?? "https://quattrino.io" }); async function main() { // 1. INTENT: standing authority $50; the task "under $20" narrows it. It can never widen it. const r = await q.authorize({ amountMinor: 1999, merchant: "Amazon", purpose: "USB-C cable", commitment: "ONE_TIME", task: { max_amount_minor: 2000 } }); console.log(r.decision, "effective max:", r.effective_maximum_minor, "set by:", r.effective_authority?.binding_layer); // AUTHORIZED 2000 task // 2. Four answers, always handled the same way const handle = (x: any) => x.decision === "AUTHORIZED" ? "go" : x.decision === "DENIED" ? "stop: " + (x.denial_reasons ?? []).map((d: any) => d.code).join("; ") : x.decision === "APPROVAL_REQUIRED" ? "wait for the human: approval " + x.approval?.approval_id : "ask/declare: " + (x.needs_information ?? []).map((d: any) => d.code).join("; "); console.log(handle(await q.authorize({ amountMinor: 2001, merchant: "Amazon", purpose: "USB-C cable", commitment: "ONE_TIME", task: { max_amount_minor: 2000 } }))); // stop: exceeds_effective_authority // 3. AUTHORITY -> ACTION: binding authorization (single use, expires, revocable); you execute with your own provider const auth = await q.authorizeBinding({ amountMinor: 1999, merchant: "Amazon", purpose: "USB-C cable", commitment: "ONE_TIME", task: { max_amount_minor: 2000 }, execution: "external" }); if (auth.decision !== "AUTHORIZED") throw new Error(JSON.stringify(auth.denial_reasons)); // ... buy the cable with your own provider ... // 4. PROOF: record the outcome; Quattrino compares it with the authorized terms; explain in plain language const out = await q.recordOutcome(auth.authorization_id, { success: true, provider: "amazon", providerReference: "114-2233", actualAmountMinor: 1999, commitment: "ONE_TIME" }); console.log(out.status, out.compliance?.status); // CONSUMED COMPLIANT console.log((await q.explain(auth.authorization_id)).plain_language); } main().catch((e) => { console.error(e); process.exit(1); });