JavaScript: Functions
Call edge functions from your app, deploy and version them, run them asynchronously, read logs, and manage their access, settings and bindings with @sovaria/sdk.
Functions run your server code next to your data. Apps call them with functions.call; the management methods (deploy, versions, logs, settings) are for your team and CI.
import { createClient } from '@sovaria/sdk'
const sovaria = createClient('https://<project-ref>.sovaria.in', '<anon-key>')
const total = await sovaria.functions.call<{ total: number }>('order-total', { cartId })
console.log(total.total)Calling
sovaria.functions.call
Call a function the way an app does: POST {projectUrl}/functions/v1/{name} with the signed-in user's token (or no token for functions marked public).
sovaria.functions.call(functionName: string, payload?: JsonValue = {}): Promise<T>Returns the function's result.
Parameters
functionNamestringrequired- The function's name.
payloadJsonValueoptionaldefault{}- JSON body your function receives.
- Returns
Promise<T>— Whatever the function returns (typed with the generic).- HTTP
POST /functions/v1/{…}
- Runs as the signed-in user (or anonymously) — the function's access setting decides who may call it.
sovaria.functions.invoke
Invoke.
sovaria.functions.invoke(
functionName: string,
payload: JsonValue,
options?: { projectId?: string; deployId?: string; executionProfile?: 'standard' | 'heavy' },
): Promise<JsonObject>Parameters
functionNamestringrequiredpayloadJsonValuerequiredoptions{ projectId?: string; deployId?: string; executionProfile?: 'standard' | 'heavy' }optional
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/fn/{…}/invoke
sovaria.functions.invokeAsync
Invoke async.
sovaria.functions.invokeAsync(
functionName: string,
payload: JsonValue,
options?: { projectId?: string deployId?: string executionProfile?: 'standard' | 'heavy' simulation?: boolean },
): Promise<JsonObject>Parameters
functionNamestringrequiredpayloadJsonValuerequiredoptions{ projectId?: string deployId?: string executionProfile?: 'standard' | 'heavy' simulation?: boolean }optional
- Returns
Promise<JsonObject>—{ invocation_id }— pollinvocationStatusfor the result.- HTTP
POST /api/v1/fn/{…}/invoke/async
sovaria.functions.invocationStatus
Invocation status.
sovaria.functions.invocationStatus(invocationId: string, projectId: string): Promise<JsonObject>Parameters
invocationIdstringrequiredprojectIdstringrequired
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/invocations/{…}
sovaria.functions.simulate
Simulate.
sovaria.functions.simulate(
functionName: string,
payload: JsonValue,
options?: { projectId?: string; deployId?: string; executionProfile?: 'standard' | 'heavy' },
): Promise<JsonObject>Parameters
functionNamestringrequiredpayloadJsonValuerequiredoptions{ projectId?: string; deployId?: string; executionProfile?: 'standard' | 'heavy' }optional
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/fn/{…}/simulate
Deploying and versions
sovaria.functions.plan
Validate a bundle and get a signed plan bound to its exact bytes.
sovaria.functions.plan(bundle: Blob, name: string, projectId?: string): Promise<JsonObject>Parameters
bundleBlobrequirednamestringrequiredprojectIdstringoptional
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/fn/plan
sovaria.functions.deploy
Plans, then applies exactly the planned bundle (Forge refuses anything else).
sovaria.functions.deploy(bundle: Blob, name: string, projectId?: string): Promise<JsonObject>Parameters
bundleBlobrequired- A zip
Blobwith your code (the CLI builds it for you:sov fn deploy). namestringrequired- Function name.
projectIdstringoptional- Defaults to the client's project.
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/fn/deploy
- Plans first and applies exactly the planned bundle, so what you reviewed is what runs.
sovaria.functions.status
Status.
sovaria.functions.status(deployId: string, projectId?: string): Promise<JsonObject>Parameters
deployIdstringrequiredprojectIdstringoptional
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/{…}/status
sovaria.functions.versions
Versions.
sovaria.functions.versions(
functionName: string,
options: { projectId: string; limit?: number; offset?: number },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId: string; limit?: number; offset?: number }required
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/{…}/versions
sovaria.functions.promote
Promote.
sovaria.functions.promote(
functionName: string,
options: { projectId: string version?: number deployId?: string reason?: string },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId: string version?: number deployId?: string reason?: string }requiredprojectId, theversion(ordeployId) to make live, optionalreason.
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/fn/{…}/promote
sovaria.functions.rollback
Rollback.
sovaria.functions.rollback(
functionName: string,
options: { projectId: string version?: number reason?: string },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId: string version?: number reason?: string }requiredprojectId, optionalversionto go back to,reason.
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/fn/{…}/rollback
sovaria.functions.history
History.
sovaria.functions.history(
functionName: string,
options: { projectId: string mode?: 'invoke' | 'simulate' limit?: number offset?: number },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId: string mode?: 'invoke' | 'simulate' limit?: number offset?: number }required
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/{…}/history/invocations
sovaria.functions.simulationDiff
Simulation diff.
sovaria.functions.simulationDiff(
functionName: string,
options: { projectId: string leftInvocationId: string rightInvocationId: string },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId: string leftInvocationId: string rightInvocationId: string }required
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/{…}/history/simulation-diff
Settings and logs
sovaria.functions.list
List.
sovaria.functions.list(
options: { projectId: string; limit?: number; offset?: number },
): Promise<JsonObject>Parameters
options{ projectId: string; limit?: number; offset?: number }required
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/functions
sovaria.functions.get
Get.
sovaria.functions.get(name: string): Promise<JsonObject>Parameters
namestringrequired
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/functions/{…}
sovaria.functions.getSource
Get source.
sovaria.functions.getSource(name: string): Promise<JsonObject>Parameters
namestringrequired
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/functions/{…}/source
sovaria.functions.update
Update.
sovaria.functions.update(name: string, body: JsonObject): Promise<JsonObject>Parameters
namestringrequiredbodyJsonObjectrequired- Settings to change — public access, allowed outbound hosts, limits.
- Returns
Promise<JsonObject>- HTTP
PATCH /api/v1/fn/functions/{…}
sovaria.functions.delete
Delete.
sovaria.functions.delete(name: string): Promise<JsonObject>Parameters
namestringrequired
- Returns
Promise<JsonObject>- HTTP
DELETE /api/v1/fn/functions/{…}
sovaria.functions.logs
Logs.
sovaria.functions.logs(
name: string,
query?: { limit?: number; offset?: number; status?: string },
): Promise<JsonValue>Parameters
namestringrequiredquery{ limit?: number; offset?: number; status?: string }optionallimit,offset,status(e.g.error).
- Returns
Promise<JsonValue>- HTTP
GET /api/v1/fn/functions/{…}/logs
sovaria.functions.jobs
Jobs.
sovaria.functions.jobs(
functionName: string,
options: { projectId: string; status?: string; limit?: number; offset?: number },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId: string; status?: string; limit?: number; offset?: number }required
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/{…}/jobs
sovaria.functions.getPolicy
Get policy.
sovaria.functions.getPolicy(name: string): Promise<JsonObject>Parameters
namestringrequired
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/functions/{…}/policy
sovaria.functions.setPolicy
Set policy.
sovaria.functions.setPolicy(name: string, body: JsonObject): Promise<JsonObject>Parameters
namestringrequiredbodyJsonObjectrequired
- Returns
Promise<JsonObject>- HTTP
PUT /api/v1/fn/functions/{…}/policy
sovaria.functions.getBindings
Get bindings.
sovaria.functions.getBindings(name: string): Promise<JsonObject>Parameters
namestringrequired
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/fn/functions/{…}/bindings
sovaria.functions.setBindings
Set bindings.
sovaria.functions.setBindings(name: string, body: JsonObject): Promise<JsonObject>Parameters
namestringrequiredbodyJsonObjectrequired
- Returns
Promise<JsonObject>- HTTP
PUT /api/v1/fn/functions/{…}/bindings
GitHub
sovaria.functions.githubRepositories
Github repositories.
sovaria.functions.githubRepositories(body: JsonObject): Promise<JsonObject>Parameters
bodyJsonObjectrequired
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/fn/github/repositories
sovaria.functions.githubImport
Github import.
sovaria.functions.githubImport(body: JsonObject): Promise<JsonObject>Parameters
bodyJsonObjectrequired
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/fn/github/import
sovaria.functions.githubCommit
Github commit.
sovaria.functions.githubCommit(body: JsonObject): Promise<JsonObject>Parameters
bodyJsonObjectrequired
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/fn/github/commit
More
sovaria.functions.request
Request.
sovaria.functions.request(
method: string,
path: string,
options?: RequestOptions = {},
): Promise<JsonValue>Parameters
methodstringrequiredpathstringrequiredoptionsRequestOptionsoptionaldefault{}
- Returns
Promise<JsonValue>