# Your code, next to your data.

Source: https://cubibase.com/features/functions

Also available: [Markdown version](https://cubibase.com/features/functions.md) · [llms.txt](https://cubibase.com/llms.txt) · [full site content](https://cubibase.com/llms-full.txt)

CubiBase Functions run your TypeScript and JavaScript in an isolated, managed runtime. Four trigger types share one execution pipeline: HTTPS endpoints, committed database changes, storage object events, and cron schedules.

## At a glance

- **HTTPS endpoints** — GET, POST, PUT, PATCH, DELETE, and OPTIONS at /functions/{name}, with the exact raw body preserved for signature verification.
- **Database events** — After-commit INSERT, UPDATE, and DELETE events captured atomically with your data change. A function failure never rolls back your transaction.
- **Storage events** — Object created, updated, and deleted events, filtered by bucket and key prefix. File contents never ride in the payload.
- **Cron schedules** — Standard cron expressions in UTC or a configured timezone, with last and next run visibility. Missed runs collapse into one catch-up run.
- **Gateway authentication** — JWT, public, secret API key, or internal-only access, enforced before your code runs. Payload signature verification is a separate setting.
- **Signed webhooks** — Built-in HMAC-SHA256 with replay protection, or verify Stripe and GitHub signatures yourself on the untouched body.
- **Immutable deployments** — Every deploy builds a new version. A failed build leaves the working version serving; activate an older version to roll back.
- **Eight templates** — Hello World, Stripe Webhook, GitHub Webhook, Send Email, OpenAI Proxy, Image Processing, Database Change Handler, and Scheduled Cleanup.
- **Execution history** — Trigger, version, duration, status, error category, and captured console output for every run, with filters and a delivery queue.
- **Encrypted secrets** — Secrets are encrypted at rest, never returned by read APIs, and redacted from logs. Functions get a short-lived, single-invocation credential.
- **Enforced quotas** — Invocations and GB-seconds metered per organization, shared across projects. At a limit, invocations are refused with 402 by default; paid plans can opt in to metered additional usage with a spending limit.
- **Durable delivery** — Async triggers deliver at least once, with durable retries and a queryable dead-letter queue. Deduplicate on the event id.

## Functions, not SQL functions

A CubiBase Function is application code you deploy from the Console: a default-exported async handler that receives the request or event and a context with scoped database, storage and environment access. It runs on Node.js 22 in a separate, isolated environment per project and function, with no platform credentials and no access to other projects.

This is different from PostgreSQL SQL functions, which live inside your project database and are managed under Database → SQL Functions. Both exist; they do different jobs. Database Event Triggers bridge them: a committed INSERT, UPDATE or DELETE can invoke a CubiBase Function asynchronously.

Execution is regional today. CubiBase does not offer globally distributed edge execution.

## Four ways to run

- HTTP: an HTTPS endpoint at https://{project}.api.cubibase.com/functions/{name}, supporting GET, POST, PUT, PATCH, DELETE and OPTIONS, with the exact raw request body preserved for signature verification.
- Database: after-commit INSERT/UPDATE/DELETE events on tables you subscribe to, captured atomically with your data change. A function failure never rolls back your transaction.
- Storage: object created, updated and deleted events from the existing Storage event stream, filtered by bucket and key prefix. Failed uploads never emit events; file contents never ride in the payload.
- Scheduled: standard cron expressions in UTC or a configured timezone, with last/next run visibility. Missed runs collapse into one catch-up run.

Database, storage and scheduled executions are asynchronous with at-least-once delivery, durable retries and a queryable dead-letter queue. Deduplicate on the event id — the templates show the pattern.

## Authentication and signed payloads

HTTP functions choose an authentication mode enforced by the gateway before your code runs: JWT (the default, using CubiBase Auth tokens), public, secret API key, or internal-only. Payload signature verification is a separate, independent setting.

- Built-in HMAC-SHA256: the gateway verifies the exact raw bytes with timestamp tolerance, constant-time comparison and single-use nonces (replay protection). Signing secrets are encrypted, shown once, and rotatable without dropped deliveries.
- Custom verification: Stripe, GitHub and other providers keep their own signature schemes. The function receives the untouched body and headers; the Stripe and GitHub templates verify them with constant-time checks.
- Secrets are encrypted at rest, never returned by read APIs, and redacted from logs. Functions reach your database and files through scoped CubiBase APIs with a short-lived, single-invocation credential — never a database password.

## Deployments that cannot break production

Every deploy builds an immutable version. Your code is bundled, never executed at build time, and imports are limited to Node built-ins plus a pinned dependency allowlist. A successful build atomically switches the active version; a failed build leaves the working version serving. Activate an older version to roll back.

## Start from working code

Eight versioned templates generate editable, functional code with the right trigger and security defaults: Hello World, Stripe Webhook, GitHub Webhook, Send Email, OpenAI Proxy, Image Processing, Database Change Handler and Scheduled Cleanup. The Stripe template verifies Stripe-Signature on the raw body, deduplicates deliveries, and walks you through the Dashboard configuration — it never claims the integration is connected until a signed test event succeeds.

## Every run is visible

Each invocation records its trigger, deployment version, duration, status, error category and captured console output — bounded, redacted and isolated per project. The Console shows execution history with filters, a delivery queue for async events, and per-function logs. Retention follows your plan.

## Quotas on every trigger

Functions use the same subscription as the rest of CubiBase. Function count, concurrent executions and schedules are limited per project; invocations and compute (GB-seconds) are metered per organization per billing cycle, shared across all projects — the same convention as bandwidth. Every trigger type passes the same atomic reservations; there is no side door. By default, at a limit invocations are refused, not billed as overage (paid plans can explicitly enable metered additional usage with a spending limit); exhausting compute also refuses invocations even if invocation capacity remains. The Console’s Usage page shows live consumption, warnings at 50%, 75%, 90% and 100%, and exceeded state; the pricing page lists the current plan values.

## FAQ

**Where does my function code actually run?**

In a managed Node.js 22 runtime, in an isolated environment per function, with no platform credentials and no access to other projects. Execution is regional.

**Can a database event function block or roll back a write?**

No — by design. Events are captured in the same transaction as your change but delivered only after commit, asynchronously. Use PostgreSQL constraints or native database triggers for rules that must block the write itself.

**Can I use npm packages?**

Imports are restricted to Node built-ins and a pinned allowlist (currently the official Stripe SDK). No build scripts run and no per-deploy npm install happens. The allowlist is versioned and will grow deliberately.

**Is this globally distributed like edge functions?**

No. Execution is regional, which is why the product is called Functions, not Edge Functions.

**What happens when I hit a quota?**

By default, new invocations are refused with a 402 until the cycle resets or you upgrade; async events retry with backoff and then dead-letter. Concurrency pressure returns 429 to HTTP callers. Nothing is silently over-billed — metered additional usage only applies when a paid organization explicitly enables it with a spending limit.

## Related

- [Functions docs](https://cubibase.com/docs/functions) — The programming model, triggers and worked examples.
- [Templates](https://cubibase.com/docs/functions/templates) — Eight starting points, including the Stripe webhook.
- [Quotas and metering](https://cubibase.com/docs/functions/quotas) — What is counted and the current plan values.
- [Storage](https://cubibase.com/features/storage) — The object events storage triggers consume.
