Aller au contenu

SDK TypeScript

Le SDK TypeScript fonctionne dans Node.js, Deno, Bun et les environnements supportant fetch.

Fenêtre de terminal
npm install @deployme-cloud/sdk
import { DeploymeClient } from "@deployme-cloud/sdk";
// Via token
const client = new DeploymeClient({ apiToken: "YOUR_API_TOKEN" });
// Via variable d'environnement (DEPLOYME_API_TOKEN)
const client = new DeploymeClient();
const cluster = await client.clusters.create({
name: "production",
controlPlanes: 3,
workers: 5,
nodeSize: "large",
phase: "managed",
});
console.log(`Cluster ${cluster.name} — Status: ${cluster.status}`);
const clusters = await client.clusters.list();
for (const cluster of clusters) {
console.log(`${cluster.name}${cluster.status} (${cluster.nodeCount} nodes)`);
}
const kubeconfig = await client.clusters.getKubeconfig("cluster-id");
await writeFile("kubeconfig.yaml", kubeconfig);
await client.clusters.delete("cluster-id");

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);
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}`);
}
}