SDK Node.js & TypeScript
Dokumentasi paket resmi @smallpict/sdk untuk aplikasi Node.js, Next.js, dan TypeScript.
SDK Node.js & TypeScript (@smallpict/sdk)
SDK resmi SmallPict untuk Node.js dilengkapi dengan definisi tipe TypeScript penuh, penandatanganan HMAC otomatis, dan penanganan retry terintegrasi.
📦 Instalasi
npm install @smallpict/sdk
# atau
bun add @smallpict/sdk
# atau
pnpm add @smallpict/sdk
🚀 Contoh Penggunaan Cepat
import { SmallPict } from '@smallpict/sdk';
import fs from 'node:fs';
const client = new SmallPict({
apiKey: process.env.SMALLPICT_API_KEY!,
secretKey: process.env.SMALLPICT_SECRET_KEY!,
retryConfig: { maxRetries: 3 }
});
// 1. Optimasi buffer gambar
const inputBuffer = fs.readFileSync('foto-produk.jpg');
const result = await client.optimize(inputBuffer, {
format: 'avif',
quality: 80,
maxWidth: 1920
});
console.log(`URL Teroptimasi: ${result.url}`);
console.log(`Penghematan: ${result.savingsPercentage}%`);
// 2. Cek kuota bulanan
const quota = await client.getQuota();
console.log(`Pemakaian: ${quota.bytesUsed} byte`);
