Functions
Nuvem Functions son fragmentos de código TypeScript que corren en el edge (Cloudflare Workers). Se pueden invocar via HTTP, cron, eventos de DB o webhooks externos.
Edge Functions
Crear una función
POST /v1/functionsAuthorization: Bearer <api_key>{ "name": "send-welcome-email", "runtime": "typescript", "code": "export default async function handler(event) { return { body: 'Hello!' }; }", "env": { "EMAIL_FROM": "hola@tuapp.com" }}Invocar una función
POST /v1/functions/:funcId/invokeAuthorization: Bearer <api_key>{ "payload": { "userId": "usr_abc123" }}Listar versiones
GET /v1/functions/:funcId/versionsCron Jobs
# Crear cronPOST /v1/functions/crons{ "functionId": "func_abc", "schedule": "0 9 * * 1-5", "timezone": "America/Buenos_Aires", "enabled": true}
# Listar cronsGET /v1/functions/crons
# Activar/desactivarPATCH /v1/functions/crons/:cronId{ "enabled": false }Triggers (DB Events)
# Crear triggerPOST /v1/functions/triggers{ "functionId": "func_abc", "table": "orders", "event": "INSERT", "enabled": true}
# Eventos disponibles: INSERT | UPDATE | DELETEWebhooks
# Crear webhook (recibe eventos externos)POST /v1/functions/webhooks{ "functionId": "func_abc", "name": "stripe-events", "secret": "whsec_..."}
# Respuesta incluye la URL pública:# "url": "https://api.nuvem-latam.com/v1/webhooks/:webhookId"Editor online
El dashboard incluye un editor Monaco con:
- Autocompletado TypeScript
- Guardado automático
- Preview de logs en tiempo real
- Deploy con un click
URL: https://app.nuvem-latam.com/projects/:projectId/functions/:funcId/editor
SDK
import { createClient } from '@nuvem/js';
const nuvem = createClient({ apiKey: process.env.NUVEM_API_KEY! });
// Invocar funciónconst result = await nuvem.functions.invoke('send-welcome-email', { payload: { userId: 'usr_abc' },});
// Listar funcionesconst { data } = await nuvem.functions.list();Límites por plan
| Plan | Functions | Invocaciones/mes | Timeout |
|---|---|---|---|
| Free | 3 | 100,000 | 10s |
| Builder | 50 | 5,000,000 | 30s |
| Scale | Ilimitadas | Ilimitadas | 120s |
Errores comunes
| Código | Mensaje | Causa |
|---|---|---|
function_not_found | La función no existe | ID inválido |
function_timeout | La función excedió el tiempo límite | Código lento o bucle infinito |
function_error | Error de ejecución | Excepción no manejada en el código |
invalid_schedule | Expresión cron inválida | Sintaxis incorrecta |