Skip to content
smallPict

SDK oficial para Node.js y TypeScript

Paquete @smallpict/sdk para Node.js, Next.js, Express y aplicaciones TypeScript.

El SDK oficial de Node.js proporciona tipos estrictos de TypeScript, soporte para streaming y compatibilidad total con entornos Node.js 18+, Next.js y Edge Runtimes.


Instalación

Shell
npm install @smallpict/sdk# o con pnpmpnpm add @smallpict/sdk# o con yarnyarn add @smallpict/sdk

Ejemplo completo de uso

TypeScript
import { SmallPictClient } from "@smallpict/sdk";import fs from "fs";
// 1. Inicializar cliente con credenciales segurasconst client = new SmallPictClient({  apiKey: process.env.SMALLPICT_API_KEY!,  secretKey: process.env.SMALLPICT_SECRET_KEY!,  maxRetries: 3,  timeoutMs: 10000});
async function main() {  try {    // 2. Optimizar imagen local mediante Buffer    const imageBuffer = fs.readFileSync("./assets/hero.jpg");
    const result = await client.optimize({      file: imageBuffer,      filename: "hero.jpg",      format: "avif",      quality: 80,      maxWidth: 1920    });
    console.log("Optimización completada con éxito:");    console.log("- URL CDN:", result.url);    console.log("- Ahorro de tamaño:", result.savingsPercentage + "%");    console.log("- Peso final:", result.optimizedSize, "bytes");
    // 3. Consultar saldo de cuota restante    const quota = await client.getQuota();    console.log("- Cuota disponible:", quota.remaining, "/", quota.total);
  } catch (error) {    console.error("Error durante la optimización:", error);  }}
main();