azirgo-cloud
v0.1.0
Published
TypeScript SDK for Azirgo Cloud API — file storage, workspaces, and access management
Maintainers
Readme
@azirgo/sdk
TypeScript SDK for Azirgo Cloud — file storage, workspaces, and access management.
Installation
npm install @azirgo/sdk
# or
bun add @azirgo/sdk
# or
yarn add @azirgo/sdkQuick Start
import { AzirgoClient } from '@azirgo/sdk';
const client = new AzirgoClient({
apiUrl: 'https://api.azirgo.cloud',
});
// Login
const auth = await client.login({
email: '[email protected]',
password: 'Pass123!',
});
client.setToken(auth.accessToken);
// List folders
const folders = await client.listFolders();
// Upload a file
import { readFileSync } from 'fs';
const buffer = readFileSync('./document.pdf');
const file = await client.uploadFile(folders[0].id, buffer, 'document.pdf', 'application/pdf');
// Get signed download URL
const url = await client.signedUrl(file.id);Using with API Keys
const client = new AzirgoClient({
apiUrl: 'https://api.azirgo.cloud',
apiKey: 'azk_live_abc123...',
});
// Upload directly with API key
const file = await client.uploadFile(folderId, buffer, 'image.png', 'image/png');Express.js Example
import express from 'express';
import { AzirgoClient } from '@azirgo/sdk';
const app = express();
const azirgo = new AzirgoClient({
apiUrl: process.env.AZIRGO_API_URL!,
apiKey: process.env.AZIRGO_API_KEY!,
});
app.post('/backup', async (req, res) => {
const folders = await azirgo.listFolders();
const folder = folders.find((f) => f.name === 'backups');
const file = await azirgo.uploadFile(
folder!.id,
Buffer.from(JSON.stringify(req.body)),
`backup-${Date.now()}.json`,
'application/json',
);
res.json({ fileId: file.id, url: file.publicUrl });
});NestJS Example
import { Injectable } from '@nestjs/common';
import { AzirgoClient } from '@azirgo/sdk';
@Injectable()
export class StorageService {
private client: AzirgoClient;
constructor() {
this.client = new AzirgoClient({
apiUrl: process.env.AZIRGO_API_URL!,
apiKey: process.env.AZIRGO_API_KEY!,
});
}
async upload(folderId: string, file: Buffer, filename: string) {
return this.client.uploadFile(folderId, file, filename);
}
async getDownloadUrl(fileId: string) {
return this.client.signedUrl(fileId);
}
async listFiles(folderId: string) {
return this.client.listFiles(folderId);
}
}API Reference
Constructor
new AzirgoClient(config: AzirgoConfig)| Option | Type | Description |
|--------|------|-------------|
| apiUrl | string | Base URL of the Azirgo Cloud API |
| token | string? | JWT access token |
| apiKey | string? | API key (azk_live_...) |
Auth
| Method | Returns | Description |
|--------|---------|-------------|
| register(input) | AuthPayload | Register a new user and workspace |
| login(input) | AuthPayload | Login with email/password |
| setToken(token) | void | Set the authentication token |
Files & Folders
| Method | Returns | Description |
|--------|---------|-------------|
| listFiles(folderId?) | AzirgoFile[] | List files in a folder |
| getFile(id) | AzirgoFile | Get file details |
| signedUrl(id) | string | Get a signed download URL |
| uploadFile(folderId, file, filename, mimeType?) | AzirgoFile | Upload a file |
| deleteFile(id) | boolean | Delete a file |
| listFolders(parentId?) | Folder[] | List folders |
| createFolder(name, parentId?) | Folder | Create a folder |
| deleteFolder(id) | boolean | Delete a folder |
Workspaces
| Method | Returns | Description |
|--------|---------|-------------|
| me() | Tenant | Get current workspace |
| myWorkspaces() | Tenant[] | List all workspaces |
| createWorkspace(input) | AuthPayload | Create a workspace |
| switchWorkspace(tenantId) | AuthPayload | Switch workspace |
| updateWorkspace(input) | Tenant | Update workspace |
API Keys
| Method | Returns | Description |
|--------|---------|-------------|
| apiKeys() | ApiKey[] | List API keys |
| createApiKey(name, scopes?) | ApiKeyCreated | Create an API key |
| revokeApiKey(id) | boolean | Revoke an API key |
Plans & Subscriptions
| Method | Returns | Description |
|--------|---------|-------------|
| plans() | Plan[] | List available plans |
| mySubscription() | Subscription \| null | Get current subscription |
| purchasePlan(input) | Subscription | Purchase a plan |
| cancelSubscription() | Subscription | Cancel subscription |
Cards
| Method | Returns | Description |
|--------|---------|-------------|
| cards() | Card[] | List payment cards |
| addCard(input) | Card | Add a card |
| setDefaultCard(id) | Card | Set default card |
| deleteCard(id) | boolean | Delete a card |
Requirements
- Node.js >= 18.0.0 (uses native
fetchandFormData) - Zero runtime dependencies
License
MIT
