2025-08-18 03:14:49 +00:00
# @serve.zone/api 🔌
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
**The powerful API client for Cloudly. ** Connect your applications to multi-cloud infrastructure with type-safe, real-time communication.
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
## 🎯 What is @serve.zone/api?
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
This is your programmatic gateway to the Cloudly platform. Built with TypeScript, it provides a robust, type-safe interface for managing cloud resources, orchestrating containers, and automating infrastructure operations.
## ✨ Features
- **🔒 Type-Safe** - Full TypeScript support with comprehensive interfaces
- **⚡ Real-Time** - WebSocket-based communication for instant updates
- **🔑 Secure Authentication** - Token-based identity management
- **📦 Resource Management** - Complete control over clusters, images, and services
- **🎭 Multi-Identity** - Support for service accounts and user authentication
- **🔄 Reactive Streams** - RxJS integration for event-driven programming
## 🚀 Installation
2024-10-28 21:49:43 +01:00
``` bash
2025-08-18 03:14:49 +00:00
pnpm add @serve.zone/api
2024-10-28 21:49:43 +01:00
```
2025-08-18 03:14:49 +00:00
## 🎬 Quick Start
``` typescript
import { CloudlyApiClient } from '@serve.zone/api' ;
// Initialize the client
const client = new CloudlyApiClient ( {
registerAs : 'api' ,
cloudlyUrl : 'https://cloudly.example.com:443'
} ) ;
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
// Start the connection
await client . start ( ) ;
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
// Authenticate with a service token
const identity = await client . getIdentityByToken ( 'your-service-token' , {
tagConnection : true ,
statefullIdentity : true
} ) ;
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
console . log ( '🎉 Connected as:' , identity . name ) ;
```
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
## 🔐 Authentication
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
### Service Token Authentication
2024-10-28 21:49:43 +01:00
``` typescript
2025-08-18 03:14:49 +00:00
// Authenticate using a service token
const identity = await client . getIdentityByToken ( serviceToken , {
tagConnection : true , // Tag this connection with the identity
statefullIdentity : true // Maintain state across reconnections
} ) ;
```
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
### Identity Management
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
``` typescript
// Get current identity
const currentIdentity = client . identity ;
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
// Check permissions
if ( currentIdentity . permissions . includes ( 'cluster:write' ) ) {
// Perform cluster operations
}
2024-10-28 21:49:43 +01:00
```
2025-08-18 03:14:49 +00:00
## 📚 Core Operations
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
### 🐳 Image Management
2024-10-28 21:49:43 +01:00
``` typescript
2025-08-18 03:14:49 +00:00
// Create an image entry
const image = await client . images . createImage ( {
name : 'my-app' ,
description : 'Production application image'
} ) ;
// Push a new version
const imageStream = fs . createReadStream ( 'app.tar' ) ;
await image . pushImageVersion ( '2.0.0' , imageStream ) ;
// List all images
const images = await client . images . listImages ( ) ;
```
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
### 🌐 Cluster Operations
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
``` typescript
// Get cluster configuration
const clusterConfig = await client . getClusterConfigFromCloudlyByIdentity ( identity ) ;
// Deploy to cluster
await client . deployToCluster ( {
clusterName : 'production' ,
serviceName : 'api-service' ,
image : 'my-app:2.0.0' ,
replicas : 3
} ) ;
```
### 🔒 Certificate Management
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
``` typescript
// Request SSL certificate
const certificate = await client . getCertificateForDomain ( {
domainName : 'api.example.com' ,
type : 'ssl' ,
identity : identity
} ) ;
// Use certificate in your application
console . log ( 'Certificate:' , certificate . cert ) ;
console . log ( 'Private Key:' , certificate . key ) ;
2024-10-28 21:49:43 +01:00
```
2025-08-18 03:14:49 +00:00
### 🔐 Secret Management
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
``` typescript
// Create secret group
const secretGroup = await client . secrets . createSecretGroup ( {
name : 'api-secrets' ,
secrets : [
{ key : 'DATABASE_URL' , value : 'postgres://...' } ,
{ key : 'REDIS_URL' , value : 'redis://...' }
]
} ) ;
// Retrieve secrets
const secrets = await client . secrets . getSecretGroup ( 'api-secrets' ) ;
```
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
## 🔄 Real-Time Updates
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
Subscribe to configuration changes and server actions using RxJS:
2024-10-28 21:49:43 +01:00
``` typescript
2025-08-18 03:14:49 +00:00
// Listen for configuration updates
client . configUpdateSubject . subscribe ( {
next : ( config ) = > {
console . log ( '📡 Configuration updated:' , config ) ;
// React to configuration changes
}
} ) ;
// Handle server action requests
client . serverActionSubject . subscribe ( {
next : ( action ) = > {
console . log ( '⚡ Server action:' , action . type ) ;
// Process server-initiated actions
}
} ) ;
```
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
## 🎯 Advanced Usage
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
### Streaming Operations
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
``` typescript
// Stream logs from a service
const logStream = await client . logs . streamLogs ( {
service : 'api-service' ,
follow : true
} ) ;
logStream . on ( 'data' , ( log ) = > {
console . log ( log . message ) ;
} ) ;
2024-10-28 21:49:43 +01:00
```
2025-08-18 03:14:49 +00:00
### Batch Operations
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
``` typescript
// Deploy multiple services
const deployments = await Promise . all ( [
client . deploy ( { service : 'frontend' , image : 'app:latest' } ) ,
client . deploy ( { service : 'backend' , image : 'api:latest' } ) ,
client . deploy ( { service : 'worker' , image : 'worker:latest' } )
] ) ;
```
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
### Error Handling
2024-10-28 21:49:43 +01:00
``` typescript
2025-08-18 03:14:49 +00:00
try {
await client . start ( ) ;
} catch ( error ) {
if ( error . code === 'AUTH_FAILED' ) {
console . error ( 'Authentication failed:' , error . message ) ;
} else if ( error . code === 'CONNECTION_LOST' ) {
console . error ( 'Connection lost, retrying...' ) ;
await client . reconnect ( ) ;
}
2024-10-28 21:49:43 +01:00
}
```
2025-08-18 03:14:49 +00:00
## 🧹 Cleanup
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
Always gracefully disconnect when done:
2024-10-28 21:49:43 +01:00
``` typescript
2025-08-18 03:14:49 +00:00
// Stop the client connection
await client . stop ( ) ;
console . log ( '✅ Disconnected cleanly' ) ;
2024-10-28 21:49:43 +01:00
```
2025-08-18 03:14:49 +00:00
## 🔌 API Reference
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
### CloudlyApiClient
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
Main client class for interacting with Cloudly.
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
#### Constructor Options
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
``` typescript
interface ICloudlyApiClientOptions {
registerAs : TClientType ; // 'api' | 'cli' | 'web'
cloudlyUrl : string ; // Full URL including protocol and port
2024-10-28 21:49:43 +01:00
}
```
2025-08-18 03:14:49 +00:00
#### Methods
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
- `start()` - Initialize connection
- `stop()` - Close connection
- `getIdentityByToken()` - Authenticate with token
- `getClusterConfigFromCloudlyByIdentity()` - Get cluster configuration
- `getCertificateForDomain()` - Request SSL certificate
- `images` - Image management namespace
- `secrets` - Secret management namespace
- `clusters` - Cluster management namespace
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
## 🎬 Complete Example
2024-10-28 21:49:43 +01:00
``` typescript
2025-08-18 03:14:49 +00:00
import { CloudlyApiClient } from '@serve.zone/api' ;
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
async function main() {
// Initialize client
const client = new CloudlyApiClient ( {
registerAs : 'api' ,
cloudlyUrl : 'https://cloudly.example.com:443'
} ) ;
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
try {
// Connect and authenticate
await client . start ( ) ;
const identity = await client . getIdentityByToken ( process . env . SERVICE_TOKEN , {
tagConnection : true ,
statefullIdentity : true
} ) ;
// Create and deploy an image
const image = await client . images . createImage ( {
name : 'my-service' ,
description : 'Microservice application'
} ) ;
// Push image version
const stream = getImageStream ( ) ; // Your image stream
await image . pushImageVersion ( '1.0.0' , stream ) ;
// Deploy to cluster
await client . deployToCluster ( {
clusterName : 'production' ,
serviceName : 'my-service' ,
image : 'my-service:1.0.0' ,
replicas : 3 ,
environment : {
NODE_ENV : 'production'
}
} ) ;
console . log ( '✅ Deployment successful!' ) ;
} catch ( error ) {
console . error ( '❌ Error:' , error ) ;
} finally {
await client . stop ( ) ;
}
}
2024-10-28 21:49:43 +01:00
2025-08-18 03:14:49 +00:00
main ( ) ;
```
2024-10-28 21:49:43 +01:00
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license ](license ) file within this repository.
**Please note: ** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task .vc.
2025-08-18 03:14:49 +00:00
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.