A TypeScript/JavaScript SDK for interacting with the CamposCloud API. This SDK provides a simple and intuitive way to manage applications, upload files, and perform various operations on the CamposCloud platform.
You can see the full API documentation at API Docs.
npm install @camposcloud/sdk
First, you need to obtain an API token from your CamposCloud dashboard. Then initialize the SDK:
import CamposCloudSDK from '@camposcloud/sdk';
const api = new CamposCloudSDK({
apiToken: "your-api-token-here"
});
const main = async () => {
try {
const me = await api.getMe();
console.log(`Hello ${me.name} 👋`);
} catch (error) {
console.error('Error fetching user data:', error);
}
}
main();
Get information about the authenticated user.
const userInfo = await api.getMe();
Returns: UserData
object containing user information.
Get details of a specific application.
const app = await api.getApplication({ appId: "your-app-id" });
Parameters:
-
appId
(string): The ID of the application
Returns: Application
instance
Get all applications for the authenticated user.
const result = await api.getApplications();
console.log(result.applications);
console.log(`Total RAM used: ${result.totalUsedRAM}`);
Returns: Object containing:
-
applications
: Array ofApplicationResponseData
-
totalUsedRAM
: String indicating total RAM usage -
pagination
: Pagination information
Create a new application.
import fs from 'fs';
const file = await fs.promises.readFile('path/to/your/app.zip');
const app = await api.createApplication({
appName: "My App",
file: file,
mainFile: "index.js",
memoryMB: 512,
runtimeEnvironment: "nodejs",
});
Parameters:
-
appName
(string): Name of the application -
file
(Buffer): ZIP file containing your application -
mainFile
(string): Entry point file (e.g., "index.js", "main.py") -
memoryMB
(number): Memory allocation in MB -
runtimeEnvironment
("nodejs" | "python"): Runtime environment -
exposedViaWeb
(boolean, optional): Whether to expose via web -
autoRestartEnabled
(boolean, optional): Enable auto-restart -
startupCommand
(string, optional): Custom startup command -
teamId
(string, optional): Team ID if creating for a team
Returns: Application
instance
Delete an application.
await api.deleteApplication({ appId: "your-app-id" });
Start an application.
const result = await api.startApplication({ appId: "your-app-id" });
Stop an application.
const result = await api.stopApplication({ appId: "your-app-id" });
Restart an application.
const result = await api.restartApplication({ appId: "your-app-id" });
Upload a file to an application.
import fs from 'fs';
const file = await fs.promises.readFile('path/to/file.txt');
const result = await api.uploadFile({
appId: "your-app-id",
file: file,
path: "/optional/path"
});
Parameters:
-
appId
(string): The application ID -
file
(Buffer): File content as Buffer -
path
(string, optional): Target path in the application
When you get or create an application, you receive an Application
instance with convenient methods:
const app = await api.getApplication({ appId: "your-app-id" });
// Application data
console.log(app.data);
// Control methods
await app.start();
await app.stop();
await app.restart();
await app.delete();
// Upload file directly to this application
import fs from 'fs';
const file = await fs.promises.readFile('path/to/file.txt');
await app.uploadFile(file, '/optional/path');
-
start()
: Start the application -
stop()
: Stop the application -
restart()
: Restart the application -
delete()
: Delete the application -
uploadFile(file: Buffer, path?: string)
: Upload a file to the application
import CamposCloudSDK from '@camposcloud/sdk';
import fs from 'fs';
const api = new CamposCloudSDK({
apiToken: "your-api-token-here"
});
const main = async () => {
try {
// Get user info
const me = await api.getMe();
console.log(`Hello ${me.name}!`);
// Create an application
const file = await fs.promises.readFile('my-app.zip');
const app = await api.createApplication({
appName: "My Node.js App",
file: file,
mainFile: "index.js",
memoryMB: 256,
runtimeEnvironment: "nodejs",
});
console.log(`Application created with ID: ${app.data._id}`);
// Start the application
await app.start();
console.log('Application started!');
// Upload additional file
const configFile = await fs.promises.readFile('config.json');
await app.uploadFile(configFile, '/config');
console.log('Config file uploaded!');
// Get all applications
const apps = await api.getApplications();
console.log(`You have ${apps.applications.length} applications`);
} catch (error) {
console.error('Error:', error);
}
}
main();
The SDK throws errors for various conditions. Always wrap your API calls in try-catch blocks:
try {
const app = await api.getApplication({ appId: "invalid-id" });
} catch (error: any) {
if (error.response?.status === 404) {
console.log('Application not found');
} else {
console.error('API Error:', error.message);
}
}
This SDK is written in TypeScript and provides full type definitions. You'll get autocomplete and type checking out of the box:
import { ApplicationResponseData, UserData } from '@camposcloud/sdk';
// Types are automatically inferred
const user: UserData = await api.getMe();
const apps: ApplicationResponseData[] = (await api.getApplications()).applications;
To contribute to this SDK:
# Clone the repository
git clone https://github.com/camposcloud/camposcloud-sdk
# Install dependencies
npm install
# Run tests
npm run test
# Build the project
npm run build
- Issues: GitHub Issues
- Email: kevencampos1@hotmail.com
This project is licensed under the ISC License.