SDK TypeScript
SDK TypeScript
Section intitulée « SDK TypeScript »Le SDK TypeScript fonctionne dans Node.js, Deno, Bun et les environnements supportant fetch.
Installation
Section intitulée « Installation »npm install @deployme-cloud/sdkAuthentification
Section intitulée « Authentification »import { DeploymeClient } from "@deployme-cloud/sdk";
// Via tokenconst client = new DeploymeClient({ apiToken: "YOUR_API_TOKEN" });
// Via variable d'environnement (DEPLOYME_API_TOKEN)const client = new DeploymeClient();Gestion des clusters
Section intitulée « Gestion des clusters »Créer un cluster
Section intitulée « Créer un cluster »const cluster = await client.clusters.create({ name: "production", controlPlanes: 3, workers: 5, nodeSize: "large", phase: "managed",});console.log(`Cluster ${cluster.name} — Status: ${cluster.status}`);Lister les clusters
Section intitulée « Lister les clusters »const clusters = await client.clusters.list();for (const cluster of clusters) { console.log(`${cluster.name} — ${cluster.status} (${cluster.nodeCount} nodes)`);}Récupérer le kubeconfig
Section intitulée « Récupérer le kubeconfig »const kubeconfig = await client.clusters.getKubeconfig("cluster-id");await writeFile("kubeconfig.yaml", kubeconfig);Supprimer un cluster
Section intitulée « Supprimer un cluster »await client.clusters.delete("cluster-id");Typage complet
Section intitulée « Typage complet »Le SDK est entièrement typé :
import type { Cluster, CreateClusterInput, NodeSize } from "@deployme-cloud/sdk";
const input: CreateClusterInput = { name: "typed-cluster", controlPlanes: 1, workers: 2, nodeSize: "medium" satisfies NodeSize,};
const cluster: Cluster = await client.clusters.create(input);Gestion des erreurs
Section intitulée « Gestion des erreurs »import { DeploymeAPIError, DeploymeNotFoundError } from "@deployme-cloud/sdk";
try { const cluster = await client.clusters.get("invalid-id");} catch (error) { if (error instanceof DeploymeNotFoundError) { console.error("Cluster non trouvé"); } else if (error instanceof DeploymeAPIError) { console.error(`Erreur API ${error.statusCode}: ${error.message}`); }}