SDK Reference
The @espace-tech/sdk is the official TypeScript SDK for Espace-Tech Cloud. It provides typed clients for storage, authentication, and database management.
Installation
npm install github:bz-reda/Espace-Tech-Cloud-SDKQuick Start
import { EspaceTech } from "@espace-tech/sdk";
const client = new EspaceTech({
apiToken: process.env.ESPACE_TECH_TOKEN!,
});
// Upload a file
await client.storage.upload("bucket-id", "photo.jpg", file);
// Verify a user token
const user = await client.auth.verifyToken("auth-app-id", token);
// Get database connection
const conn = await client.database.getConnection("db-id");Configuration
const client = new EspaceTech({
apiToken: "et_...", // Required — get from Settings → API Tokens
baseUrl: "https://api.espace-tech.com", // Default
timeout: 30000, // 30 seconds default
maxRetries: 2, // Retries on 5xx errors
});| Option | Type | Default | Description |
|---|---|---|---|
apiToken | string | — | Required. API token from your dashboard |
baseUrl | string | https://api.espace-tech.com | API base URL |
timeout | number | 30000 | Request timeout in milliseconds |
maxRetries | number | 2 | Retry count on server errors |
Tree-Shakeable Imports
Import only the modules you need to reduce bundle size:
// Full SDK
import { EspaceTech } from "@espace-tech/sdk";
// Individual modules
import { StorageClient } from "@espace-tech/sdk/storage";
import { AuthClient } from "@espace-tech/sdk/auth";
import { DatabaseClient } from "@espace-tech/sdk/database";Error Handling
All methods throw EspaceError on failure:
import { EspaceError } from "@espace-tech/sdk";
try {
await client.storage.upload("bucket-id", "file.txt", blob);
} catch (err) {
if (err instanceof EspaceError) {
console.error(err.message); // "Bucket not found"
console.error(err.status); // 404
console.error(err.code); // "HTTP_404"
}
}Environment Variables
Store your API token securely:
.env.local
ESPACE_TECH_TOKEN=et_your_api_tokenconst client = new EspaceTech({
apiToken: process.env.ESPACE_TECH_TOKEN!,
});Compatibility
The SDK works in any JavaScript runtime with native fetch:
- Node.js 18+
- Deno
- Bun
- Cloudflare Workers
- Browsers (for presigned URL usage)