@nexqloud-dcp/sdk
v0.2.3
Published
Universal TypeScript SDK for Nexqloud DCP services
Readme
Nexqloud DCP TypeScript SDK
Official TypeScript/JavaScript SDK for Nexqloud DCP (Distributed Cloud Platform). Build, deploy, and manage cloud infrastructure with a type-safe, intuitive API.
Features
- Fully typed - Complete TypeScript definitions for all API resources
- Universal - Works in Node.js, Bun, Deno, edge runtimes, and browsers
- Auto-generated - Always up-to-date with the latest API specification
- Secure - Built-in security guardrails for sensitive operations
- Modern - ESM and CommonJS support with tree-shaking
- Resilient - Automatic retries and error handling
Installation
npm install @nexqloud-dcp/sdkOr using your preferred package manager:
yarn add @nexqloud-dcp/sdk
pnpm add @nexqloud-dcp/sdk
bun add @nexqloud-dcp/sdkRequirements
- Node.js 18 or higher
- A Nexqloud DCP API key (Get yours here)
Quick Start
import { DCPClient } from '@nexqloud-dcp/sdk';
// Initialize the client
const dcp = new DCPClient({
apiKey: process.env.DCP_API_KEY,
});
// List available node types
const nodeTypes = await dcp.nodeTypes.nodeTypesControllerFindAll();
console.log(nodeTypes);Authentication
Set your API key as an environment variable:
export DCP_API_KEY=your_api_key_hereOr pass it directly when initializing:
const dcp = new DCPClient({
apiKey: 'your_api_key_here',
});Available Services
The SDK provides access to all DCP services through intuitive service clients:
| Service | Client | Description |
| -------------- | --------------- | -------------------------------------- |
| DC2 | dcp.dc2 | Virtual machines and compute instances |
| DKS | dcp.dks | Kubernetes clusters |
| DDS | dcp.dds | Managed databases |
| DCR | dcp.dcr | Container registry |
| DSS | dcp.dss | Object storage |
| Node Types | dcp.nodeTypes | Available instance types |
| Regions | dcp.regions | Available regions and metadata |
Usage Examples
List Available Node Types
// Get all available node types
const nodeTypes = await dcp.nodeTypes.nodeTypesControllerFindAll();
nodeTypes.forEach((nodeType) => {
console.log(`${nodeType.label}: ${nodeType.vcpu} vCPU, ${nodeType.ram}GB RAM`);
});Get Node Type Details
// Get details for a specific node type
const nodeType = await dcp.nodeTypes.nodeTypesControllerFindOne({
nodeTypeId: 'standard-2c-4gb',
});
console.log(`CPU: ${nodeType.cpu.type} ${nodeType.cpu.frequency}`);
console.log(`Storage: ${nodeType.storage}GB`);Create a Virtual Machine
// Create a new virtual machine
const vm = await dcp.dc2.virtualMachinesControllerCreate({
name: 'my-app-server',
nodeTypeId: 'standard-2c-4gb',
regionId: 'us-east-1',
osImageId: 'ubuntu-22.04',
sshKeyIds: ['ssh-key-123'],
});
console.log(`VM created: ${vm.id}`);List Virtual Machines
// List all virtual machines
const vms = await dcp.dc2.virtualMachinesControllerFindAll();
vms.data.forEach((vm) => {
console.log(`${vm.name} (${vm.status}): ${vm.ipAddress}`);
});Manage VM Lifecycle
const vmId = 'vm-123456';
// Start a VM
await dcp.dc2.virtualMachinesControllerStart({ id: vmId });
// Stop a VM
await dcp.dc2.virtualMachinesControllerStop({ id: vmId });
// Restart a VM
await dcp.dc2.virtualMachinesControllerRestart({ id: vmId });
// Delete a VM
await dcp.dc2.virtualMachinesControllerRemove({ id: vmId });Create a Kubernetes Cluster
// Create a new Kubernetes cluster
const cluster = await dcp.dks.clustersControllerCreate({
name: 'production-cluster',
version: '1.28',
regionId: 'us-west-2',
nodePools: [
{
name: 'default-pool',
nodeTypeId: 'standard-4c-8gb',
minNodes: 2,
maxNodes: 10,
},
],
});
console.log(`Cluster created: ${cluster.id}`);List Available Regions
// Get all available regions
const regions = await dcp.regions.metadataControllerGetRegions();
regions.forEach((region) => {
console.log(`${region.name}: ${region.location}`);
});Create a Managed Database
// Create a PostgreSQL database
const database = await dcp.dds.managedDatabasesControllerCreate({
name: 'production-db',
engine: 'postgresql',
version: '15',
nodeTypeId: 'db-standard-2c-4gb',
regionId: 'eu-central-1',
});
console.log(`Database created: ${database.connectionString}`);Object Storage Operations
// List storage buckets
const buckets = await dcp.dss.objectStorageControllerListBuckets();
// Create a new bucket
const bucket = await dcp.dss.objectStorageControllerCreateBucket({
name: 'my-app-assets',
regionId: 'us-east-1',
});Container Registry
// List container images
const images = await dcp.dcr.containerRegistryControllerListImages();
// Create a new repository
const repo = await dcp.dcr.containerRegistryControllerCreateRepository({
name: 'my-app',
visibility: 'private',
});Error Handling
The SDK throws typed errors for different scenarios:
import { DCPClient } from '@nexqloud-dcp/sdk';
try {
const vm = await dcp.dc2.virtualMachinesControllerFindOne({
id: 'non-existent-id',
});
} catch (error) {
if (error.statusCode === 404) {
console.error('VM not found');
} else if (error.statusCode === 401) {
console.error('Authentication failed - check your API key');
} else {
console.error('An error occurred:', error.message);
}
}Advanced Configuration
Timeouts and Retries
const dcp = new DCPClient({
apiKey: process.env.DCP_API_KEY,
timeoutInSeconds: 60,
maxRetries: 3,
});Custom Headers
const dcp = new DCPClient({
apiKey: process.env.DCP_API_KEY,
headers: {
'X-Custom-Header': 'value',
},
});Custom Fetch Implementation
import fetch from 'node-fetch';
const dcp = new DCPClient({
apiKey: process.env.DCP_API_KEY,
fetch: fetch as any,
});Security Considerations
Browser Runtime Protection
Sensitive infrastructure operations are automatically blocked in browser environments and throw DCPSecurityError. Always call infrastructure management methods from a secure backend.
// Safe: Read-only operations in browser
const nodeTypes = await dcp.nodeTypes.nodeTypesControllerFindAll();
// Blocked: Write operations in browser (throws DCPSecurityError)
await dcp.dc2.virtualMachinesControllerCreate({ ... });API Key Management
- Never commit API keys to version control
- Use environment variables or secure secret management
- Rotate API keys regularly
- Use API keys with minimal required permissions
TypeScript Support
The SDK is written in TypeScript and provides complete type definitions:
import type { VmResponseDto, NodeTypeResponseDto } from '@nexqloud-dcp/sdk';
const vm: VmResponseDto = await dcp.dc2.virtualMachinesControllerFindOne({
id: 'vm-123',
});
const nodeType: NodeTypeResponseDto = await dcp.nodeTypes.nodeTypesControllerFindOne({
nodeTypeId: 'standard-2c-4gb',
});Documentation
Contributing
Contributions are welcome! Please see our Contributing Guide for details.
Support
- Email: [email protected]
- Discord: Join our community
- Issues: GitHub Issues
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for release history and updates.
Made by Nexqloud
