JavaScript SDK: functions
Every method of `aura.functions`, its signature, the role it needs and what it returns.
1. Get the client
aura.functions is a FunctionsService. You almost never build it yourself.
The package @aurabase/functions is installed with @aurabase/aurabase-js. Install it alone only if you compose your own client from @aurabase/core. It requires Node.js 20 or later and ships ES modules and CommonJS with type declarations.
Every method returns Promise<AuraResponse<T>>, an object { data, error } that never throws:
| Case | data | error |
|---|---|---|
| Success | the value | null |
| Success without content (204, empty body) | null | null |
| Failure | null | an AuraError |
Test data rather than error when you need the value: only then does TypeScript know it is not null.
| Method | Role needed |
|---|---|
invoke | public key (anon), user, or service_role |
| every other method | service_role (server only) |
2. invoke
| Option | Default | |
|---|---|---|
body | none | JSON-serialisable. A Blob, ArrayBuffer, typed array, FormData, URLSearchParams or ReadableStream returns the error invalid_body without any request. |
method | 'POST' | The method the function sees |
path | '/' | The path the function sees |
headers | none | Headers given to the function. authorization, apikey, x-request-id and x-aura-* are discarded by the platform. |
timeout | client default, 30 s | Milliseconds. Cancels the call and returns the code timeout. |
signal | none | Your own AbortSignal. A cancelled call returns the code timeout. |
responseType | 'json' | How data is decoded: a parsed value, a string, a Blob or an ArrayBuffer |
name is encoded in the URL, so a value containing /, ? or # cannot leave its position. A name that contains such characters simply is not found.
invoke refreshes an expired user session first, sends the user's JWT when there is one, and never retries a call.
How to use it: Invoke a function. How it fails: Errors, timeouts and retries.
3. list and get
Both need a service_role key. get accepts the name or the id; if a function is named like an id, the name wins. A FunctionDef contains the source code and the variables of the function, which is why a public key receives 403.
There is no method to deploy, update or delete a function, or to write secrets: use the HTTP API or the CLI.
4. Jobs
enqueueJobreturns{ code: 'bad_request', status: 400 }without any request whenfunctionNameis empty or only spaces, and trims the name otherwise.listJobsfilters onstatus(pending,running,completed,failed,dead) and returns between 1 and 500 jobs, 50 by default.- Retrying dead jobs has no method: see the dead-letter queue.
5. Cron
schedule has 5 or 6 fields, in UTC. deleteCronJob takes the name, and returns 404 for an unknown name. There is no getCronJob or updateCronJob.
6. Types and errors
Exported by @aurabase/aurabase-js and @aurabase/functions:
| Export | What it is |
|---|---|
FunctionsHttpError | Your function (or a management route) answered with an error. error.context holds the body it returned. |
FunctionsRelayError | The platform failed: network (status 0) or 502, 503, 504 produced by the gateway or the runtime. |
isRelayStatus(status) | true for 0, 502, 503, 504. |
FunctionsResponseType | 'json' | 'text' | 'blob' | 'arrayBuffer' |
Both error classes extend AuraError, so isAuraError(error) is true. AuraError has status, code, message, details, retryAfter, and the getters isNotFound, isUnauthorized, isForbidden and isRateLimited.
Data types, exported by @aurabase/aurabase-js:
| Type | Fields |
|---|---|
FunctionDef | id, project_id, name, runtime, code, code_hash, env_vars, permissions, is_active, created_at, updated_at |
FunctionPermissions | allow_net: string[], memory_mb: number, timeout_secs: number |
Job | id, project_id, function_name, status, payload, attempts, max_attempts, error?, scheduled_at, started_at?, created_at, completed_at? |
CronJob | id, project_id, name, schedule, function_name, payload, is_active, last_run?, next_run?, created_at |
AuraResponse<T> | { data, error, meta? } |
When a function returns a JSON object, data also carries two non-enumerable properties, body and status, kept for code written against older versions. Do not rely on them in new code.