import test from 'node:test'; import assert from 'node:assert/strict'; import {AS213905, APIError} from '../src/index.js'; test('sets bearer authentication and parses organization', async () => { const client = new AS213905({apiKey:'secret',fetch:async (url,init)=>{assert.equal(init.headers.Authorization,'Bearer secret');return new Response(JSON.stringify({organization:{asn:213905}}),{status:200,headers:{'content-type':'application/json'}})}}); assert.equal((await client.organization()).asn,213905); }); test('throws a structured APIError', async () => { const client = new AS213905({apiKey:'secret',fetch:async()=>new Response(JSON.stringify({error:'scope_required',message:'need traffic:read'}),{status:403})}); await assert.rejects(client.traffic(),error=>error instanceof APIError&&error.status===403&&error.code==='scope_required'); });