JavaScript: Simulation
Run access simulations as every user type, preview a policy or SQL change before making it, and compare runs with @sovaria/sdk.
sovaria.simulate checks who can do what in your project without writing anything. Call it with a team member's token (console session or CLI) — it acts on the project's configuration. Background: Simulate access before you ship.
import { SovariaSDK } from '@sovaria/sdk'
const sovaria = new SovariaSDK({ baseUrl: process.env.SOVARIA_URL!, accessToken: process.env.SOVARIA_ACCESS_TOKEN! })
sovaria.setScope({ orgId: process.env.SOVARIA_ORG_ID!, projectId: process.env.SOVARIA_PROJECT_ID! })
const run = await sovaria.simulate.run()
if (Number(run.cases_fail) > 0) process.exit(1)sovaria.simulate
sovaria.simulate.run
Who can do what in the live project, as visitors, the app's users and the team; nothing is written.
sovaria.simulate.run(payload?: JsonObject = {}): Promise<JsonObject>Narrow with { filter: { resource, action, role } } (role: __guest__, __app_user__, app:<role> or a team role).
Parameters
payloadJsonObjectoptionaldefault{}{ filter: { resource, action, role } }to narrow the run; empty for the whole project.role:__guest__,__app_user__,app:<role>or a team role.
- Returns
Promise<JsonObject>— The run:run_id,cases_total,cases_pass,cases_fail,cases_warn, per-caseresultsandtop_findings.- HTTP
POST /api/v1/sim/run
const run = await sovaria.simulate.run({ filter: { resource: 'public.orders', role: '__guest__' } })sovaria.simulate.change
Try a change before making it; nothing is written.
sovaria.simulate.change(payload: JsonObject): Promise<JsonObject>{ kind: 'policy', policy: { spl_source, name?, replaces? }, disable_policy_ids? } lists who gains and loses access; { kind: 'sql', sql } runs the script with every check, rolls it back and lists what it changed.
Parameters
payloadJsonObjectrequired{ kind: 'policy', policy: { spl_source, name?, replaces? }, disable_policy_ids? }or{ kind: 'sql', sql }.
- Returns
Promise<JsonObject>— For a policy: who gains and who loses access. For SQL: what it adds, drops or changes (the script is rolled back).violationslists what should block the change.- HTTP
POST /api/v1/sim/change
const preview = await sovaria.simulate.change({ kind: 'sql', sql: 'alter table orders add column note text' })sovaria.simulate.plan
Plan.
sovaria.simulate.plan(payload: JsonObject): Promise<JsonObject>Parameters
payloadJsonObjectrequired
- Returns
Promise<JsonObject>- HTTP
POST /api/v1/sim/plan
sovaria.simulate.discover
Discover.
sovaria.simulate.discover(): Promise<JsonObject>- Returns
Promise<JsonObject>- HTTP
POST /api/v1/sim/discover
sovaria.simulate.listRuns
List runs.
sovaria.simulate.listRuns(query?: { limit?: number; offset?: number }): Promise<JsonValue>Parameters
query{ limit?: number; offset?: number }optional
- Returns
Promise<JsonValue>- HTTP
GET /api/v1/sim/runs
sovaria.simulate.getRun
Get run.
sovaria.simulate.getRun(runId: string): Promise<JsonObject>Parameters
runIdstringrequired
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/sim/runs/{…}
sovaria.simulate.compareRuns
Compare runs.
sovaria.simulate.compareRuns(targetRunId: string, baselineRunId: string): Promise<JsonObject>Parameters
targetRunIdstringrequired- The newer run.
baselineRunIdstringrequired- The run to compare with.
- Returns
Promise<JsonObject>- HTTP
GET /api/v1/sim/runs/{…}/compare/{…}