/** * Proxy flow: browse the catalog, buy GB on a pool, generate a connection * string, and rotate the exit IP. * * Run with: npx tsx examples/proxy.ts */ import { VirtualSMS } from '../src'; async function main() { const apiKey = process.env.VIRTUALSMS_API_KEY; if (!apiKey) throw new Error('Set VIRTUALSMS_API_KEY — get one at https://virtualsms.io'); const client = new VirtualSMS(apiKey); // 1. Browse the catalog (pool types, countries, price per GB). const catalog = await client.listProxyCatalog(); console.log(`${catalog.length} pool types available`); // 2. Buy 5GB of residential proxy traffic. const purchase = await client.buyProxy({ pool_type: 'residential', gb: 5, country_code: 'US' }); console.log(`Bought proxy ${purchase.proxy_id}: ${purchase.gb_added}GB added`); // 3. Compose a ready-to-use connection string (no extra backend call). const endpoint = await client.generateProxyEndpoint({ proxy_id: purchase.proxy_id, country_code: 'US', format: 'host:port:user:pass', }); console.log('Connection string:', endpoint.endpoints[0]); // 4. Rotate to a fresh exit IP whenever you need one. const rotated = await client.rotateProxy(purchase.proxy_id); console.log('Rotated:', rotated.message); // 5. Check usage. const usage = await client.getProxyUsage(purchase.proxy_id); console.log(`${usage.gb_remaining}GB remaining of ${usage.gb_used + usage.gb_remaining}GB`); } main().catch((err) => { console.error(err.message); process.exit(1); });