Skip to content
smallPict

SDK officiel Node.js et TypeScript

Paquet @smallpict/sdk pour Node.js, Next.js, Express et applications TypeScript.

Le SDK Node.js officiel offre un typage TypeScript strict, le support des flux (streams) et une compatibilité intégrale avec Node.js 18+, Next.js et les runtimes Edge.


Installation

Shell
npm install @smallpict/sdk# ou avec pnpmpnpm add @smallpict/sdk# ou avec yarnyarn add @smallpict/sdk

Exemple complet d'utilisation

TypeScript
import { SmallPictClient } from "@smallpict/sdk";import fs from "fs";
// 1. Initialisation avec vos clés secrètesconst client = new SmallPictClient({  apiKey: process.env.SMALLPICT_API_KEY!,  secretKey: process.env.SMALLPICT_SECRET_KEY!,  maxRetries: 3,  timeoutMs: 10000});
async function main() {  try {    // 2. Optimisation d'un fichier local via 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("Optimisation réussie :");    console.log("- URL CDN :", result.url);    console.log("- Économie :", result.savingsPercentage + "%");    console.log("- Taille finale :", result.optimizedSize, "octets");
    // 3. Consultation du quota disponible    const quota = await client.getQuota();    console.log("- Quota restant :", quota.remaining, "/", quota.total);
  } catch (error) {    console.error("Erreur lors de l'optimisation :", error);  }}
main();