Saltearse al contenido

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

Ventana de terminal
POST /v1/functions
Authorization: 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

Ventana de terminal
POST /v1/functions/:funcId/invoke
Authorization: Bearer <api_key>
{
"payload": { "userId": "usr_abc123" }
}

Listar versiones

Ventana de terminal
GET /v1/functions/:funcId/versions

Cron Jobs

Ventana de terminal
# Crear cron
POST /v1/functions/crons
{
"functionId": "func_abc",
"schedule": "0 9 * * 1-5",
"timezone": "America/Buenos_Aires",
"enabled": true
}
# Listar crons
GET /v1/functions/crons
# Activar/desactivar
PATCH /v1/functions/crons/:cronId
{ "enabled": false }

Triggers (DB Events)

Ventana de terminal
# Crear trigger
POST /v1/functions/triggers
{
"functionId": "func_abc",
"table": "orders",
"event": "INSERT",
"enabled": true
}
# Eventos disponibles: INSERT | UPDATE | DELETE

Webhooks

Ventana de terminal
# 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ón
const result = await nuvem.functions.invoke('send-welcome-email', {
payload: { userId: 'usr_abc' },
});
// Listar funciones
const { data } = await nuvem.functions.list();

Límites por plan

PlanFunctionsInvocaciones/mesTimeout
Free3100,00010s
Builder505,000,00030s
ScaleIlimitadasIlimitadas120s

Errores comunes

CódigoMensajeCausa
function_not_foundLa función no existeID inválido
function_timeoutLa función excedió el tiempo límiteCódigo lento o bucle infinito
function_errorError de ejecuciónExcepción no manejada en el código
invalid_scheduleExpresión cron inválidaSintaxis incorrecta