Skip to content
smallPict

Offizielles Node.js und TypeScript SDK

Paket @smallpict/sdk für Node.js, Next.js, Express und moderne TypeScript-Anwendungen.

Das offizielle Node.js SDK bietet umfassende TypeScript-Typisierungen, Stream-Verarbeitung und Kompatibilität mit Node.js 18+, Next.js und Edge-Runtimes.


Installation

Shell
npm install @smallpict/sdk# oder mit pnpmpnpm add @smallpict/sdk# oder mit yarnyarn add @smallpict/sdk

Vollständiges Codebeispiel

TypeScript
import { SmallPictClient } from "@smallpict/sdk";import fs from "fs";
// 1. Client mit Zugangsdaten initialisierenconst client = new SmallPictClient({  apiKey: process.env.SMALLPICT_API_KEY!,  secretKey: process.env.SMALLPICT_SECRET_KEY!,  maxRetries: 3,  timeoutMs: 10000});
async function main() {  try {    // 2. Lokales Bild via Buffer optimieren    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("Optimierung erfolgreich abgeschlossen:");    console.log("- CDN-URL:", result.url);    console.log("- Ersparnis:", result.savingsPercentage + "%");    console.log("- Dateigröße:", result.optimizedSize, "Bytes");
    // 3. Restkontingent prüfen    const quota = await client.getQuota();    console.log("- Verfügbares Kontingent:", quota.remaining, "/", quota.total);
  } catch (error) {    console.error("Fehler bei der Optimierung:", error);  }}
main();