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>Pass { manifest_id } from discover() to skip discovery (manifest content is never accepted). Narrow with { filter: { resource, action, role } } (role: __guest__, __app_user__, app:<role> or a team role): up to 25 request types is a single-request check that doesn't use the allowance; a wider filter is charged as a full run. One full run at a time per organization (409 SIMULATION_RUN_IN_PROGRESS).
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-case results and top_findings.
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). violations lists what should block the change.
const preview = await sovaria.simulate.change({ kind: 'sql', sql: 'alter table orders add column note text' })Response
{
"kind": "policy",
"nothing_written": true,
"cases_checked": 48,
"changes": [
{
"persona": "__guest__",
"who": "Visitors who aren't signed in",
"action": "sql:insert",
"resource": "orders",
"before": "DENY",
"after": "ALLOW",
"before_policy": null,
"after_policy": "pol_orders_read",
"row_policies_still_apply": true
}
],
"violations": [
{
"persona": "__guest__",
"who": "Visitors who aren't signed in",
"action": "sql:insert",
"resource": "orders",
"before": "DENY",
"after": "ALLOW",
"before_policy": null,
"after_policy": "pol_orders_read",
"row_policies_still_apply": true,
"severity": "critical",
"reason": "Visitors who aren't signed in could change data"
}
],
"summary": {
"gains": 1,
"losses": 0,
"violations": 1
},
"impact": [
"1 request type(s) newly allowed",
"0 request type(s) newly denied",
"Visitors who aren't signed in could change data: sql:insert on orders"
]
}sovaria.simulate.plan
Plan.
sovaria.simulate.plan(payload: JsonObject): Promise<JsonObject>Parameters
payloadJsonObjectrequired
Returns
Promise<JsonObject>
sovaria.simulate.discover
Discover.
sovaria.simulate.discover(): Promise<JsonObject>Returns
Promise<JsonObject>
{
"manifest_id": "man_3b…",
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"org_id": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
"env_id": null,
"discovered_at": "2026-10-17T13:30:58Z",
"roles": [
"OWNER",
"ADMIN",
"MEMBER",
"VIEWER"
],
"app_personas": [
{
"persona": "app:staff",
"users": 3,
"roles": [
"staff"
],
"has_public_key": true
}
],
"user_count_by_role": {
"MEMBER": 2
},
"role_subjects": {},
"functions": [
{
"name": "send-receipt",
"method": "POST",
"invoke_permission": "authenticated",
"runtime": "python3",
"description": ""
}
],
"policies": [
{
"policy_id": "pol_orders_read",
"name": "Signed-in users read orders",
"is_active": true,
"spl_source": "ALLOW IF ctx.resource.name == \"orders\" AND ctx.action IN [\"SELECT\", \"sql:select\"] AND ctx.actor.is_anonymous == False",
"conditions": []
}
],
"collections": [
"carts"
],
"tables": [
{
"name": "orders",
"schema": "public",
"table": "orders",
"kind": "table",
"rls_enabled": true,
"rls_forced": false,
"columns": [
{
"name": "id",
"type": "bigint"
}
],
"rls_policies": [],
"security_invoker": false
}
],
"buckets": [
"avatars"
],
"bucket_details": [
{
"name": "avatars",
"public": false
}
],
"settings": {
"allowPublicSignup": true
},
"channels": [
"room-42"
],
"discovery_ms": 812.4
}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>
{
"runs": [
{
"run_id": "run_7c2e…",
"status": "complete",
"started_at": "2026-10-17T13:31:02Z",
"cases_total": 214,
"cases_fail": 2
}
],
"total": 1,
"limit": 50,
"offset": 0
}sovaria.simulate.quota
Real runs used and allowed today (UTC) and this month: { day: {used, limit, resets_at}, month: {…} }.
sovaria.simulate.quota(): Promise<JsonObject>Returns
Promise<JsonObject>
{
"day": {
"used": 1,
"limit": 2,
"resets_at": "2026-10-22T00:00:00+00:00"
},
"month": {
"used": 3,
"limit": 5,
"resets_at": "2026-11-03T10:00:00+00:00"
},
"partial_units_per_run": 5
}sovaria.simulate.listIntended
Outcomes the team marked as intended (shown green on every run, left out of findings).
sovaria.simulate.listIntended(): Promise<JsonObject>Returns
Promise<JsonObject>
{
"intended": [
{
"mark_id": "6f1c2a9d0b7e4c5a8e3f2d1c0b9a8e7f",
"role": "__guest__",
"action": "sql:select",
"resource": "public.products",
"outcome": "ALLOW",
"note": "The product catalogue is public",
"marked_by": "2c1f6b8a-4d3e-4f5a-9b8c-7d6e5f4a3b2c",
"marked_at": 1792531200
}
]
}sovaria.simulate.markIntended
Mark an outcome as intended, e.g.
sovaria.simulate.markIntended(
mark: { role: string; action: string; resource: string; outcome: 'ALLOW' | 'DENY'; note?: string },
): Promise<JsonObject>{ role: '__guest__', action: 'sql:select', resource: 'public.products', outcome: 'ALLOW', note: 'The catalogue is public' }. Needs policies.write.
Parameters
mark{ role: string; action: string; resource: string; outcome: 'ALLOW' | 'DENY'; note?: string }required
Returns
Promise<JsonObject>
{
"mark_id": "6f1c2a9d0b7e4c5a8e3f2d1c0b9a8e7f",
"role": "__guest__",
"action": "sql:select",
"resource": "public.products",
"outcome": "ALLOW",
"note": "The product catalogue is public",
"marked_by": "2c1f6b8a-4d3e-4f5a-9b8c-7d6e5f4a3b2c",
"marked_at": 1792531200
}sovaria.simulate.unmarkIntended
Remove a mark; matching cases show as measured again.
sovaria.simulate.unmarkIntended(markId: string): Promise<JsonObject>Parameters
markIdstringrequired
Returns
Promise<JsonObject>
{
"removed": true,
"mark_id": "6f1c2a9d0b7e4c5a8e3f2d1c0b9a8e7f"
}sovaria.simulate.topology
Callers, gateway checks, sign-in, resources and connectors (platform defences as "Platform protection").
sovaria.simulate.topology(): Promise<JsonObject>Returns
Promise<JsonObject>
{
"project": {
"id": "8cab1cf9-…",
"name": "Storefront",
"plan": "pro"
},
"callers": [
{
"id": "__guest__",
"label": "Visitor (not signed in)",
"kind": "guest"
}
],
"gateway": {
"checks": [
{
"id": "project_rate",
"label": "Project rate limit",
"detail": "120 requests/min per IP"
},
{
"id": "platform",
"label": "Platform protection"
}
]
},
"identity": {
"providers": [
"Email and password",
"Google"
],
"mfa": true,
"passkeys": false,
"captcha": false,
"sessions": {
"timeoutMin": 0,
"inactivityMin": 0,
"singleSession": false
}
},
"resources": {
"tables": [
"orders"
],
"collections": [],
"functions": [
"stripe-webhook"
],
"buckets": [
"invoices"
],
"channels": []
},
"integrations": [
{
"id": "smtp",
"kind": "smtp",
"name": "Sovaria email",
"vendor": "Email",
"configured": true,
"lastError": null,
"flows": [
{
"id": "password_reset",
"label": "Password reset"
}
],
"outcomes": [
"ok",
"slow",
"down",
"limit",
"creds",
"ours"
]
}
],
"settingsReview": []
}sovaria.simulate.inventory
Everything the project has, read from every engine (every schema it created, collections, buckets, secret names, functions with schedules, queues, workflows and triggers, sign-in, webhooks, channels, edge limits, backups, environments, domains, policies, plan headroom).
sovaria.simulate.inventory(
params?: { include?: string; fresh?: boolean } = {},
): Promise<JsonObject>Parameters
params{ include?: string; fresh?: boolean }optionaldefault{}
Returns
Promise<JsonObject>
sovaria.simulate.checks
What is wrong or at risk, worst first, each with a fix.
sovaria.simulate.checks(
params?: { severity?: 'critical' | 'warning' | 'info'; area?: string; fresh?: boolean } = {},
): Promise<JsonObject>severity keeps that level and worse.
Parameters
params{ severity?: 'critical' | 'warning' | 'info'; area?: string; fresh?: boolean }optionaldefault{}
Returns
Promise<JsonObject>
sovaria.simulate.graph
The architecture map: nodes by layer with their status, and the edges between them.
sovaria.simulate.graph(
params?: { fresh?: boolean } = {},
): Promise<JsonObject>Parameters
params{ fresh?: boolean }optionaldefault{}
Returns
Promise<JsonObject>
sovaria.simulate.limits
Every limit the project lives under, with its value and how it is counted.
sovaria.simulate.limits(): Promise<JsonObject>Returns
Promise<JsonObject>
{
"limits": [
{
"label": "Sign-ins per 5 minutes",
"setting": "signInsPer5Min",
"value": 30,
"unit": "per 5 min",
"keyed_by": "ip",
"method": "fixed window",
"kind": "rate"
}
]
}sovaria.simulate.integrationRun
One integration flow under a programmed outcome.
sovaria.simulate.integrationRun(
body: { connector_id: string; flow_id: string; outcome?: string; mode?: 'modelled' | 'sealed' },
): Promise<JsonObject>modelled is free and sends nothing; sealed runs the real code path to the send point and returns the recording (one single-request check).
Parameters
body{ connector_id: string; flow_id: string; outcome?: string; mode?: 'modelled' | 'sealed' }required
Returns
Promise<JsonObject>
{
"connector_id": "smtp",
"flow_id": "password_reset",
"outcome": "creds",
"mode": "modelled",
"steps": [
{
"lane": "app",
"text": "A user signs up / asks for a link",
"tone": "on"
},
{
"lane": "sovaria",
"text": "Sovaria renders your email template and hands it to the sender",
"tone": "on"
},
{
"lane": "dummy",
"text": "Email sender (dummy): Refuses the username or password",
"tone": "bad"
},
{
"lane": "sovaria",
"text": "Reports 'check your SMTP settings'",
"tone": "bad"
}
],
"user_sees": "No email at all until the SMTP password is fixed.",
"verdict": "bad",
"lesson_key": "sim.integrations.smtp.creds",
"artifact": {
"id": "",
"kind": "smtp",
"target_host": "Email",
"outcome": "creds",
"created_at": "",
"preview": {
"note": "Modelled from your settings: nothing was built or sent."
}
}
}sovaria.simulate.drillsRun
The 14 security drills judged from the project's configuration, with an optional what-if draft (never saved).
sovaria.simulate.drillsRun(
body?: { drill_ids?: string[]; overrides?: JsonObject } = {},
): Promise<JsonObject>Parameters
body{ drill_ids?: string[]; overrides?: JsonObject }optionaldefault{}
Returns
Promise<JsonObject>
{
"results": [
{
"id": "stuff",
"group": "Accounts",
"name": "Credential stuffing from a botnet",
"verdict": "exposed",
"stopped_at": null,
"why": "A botnet trying leaked passwords stays under the per-IP limits; nothing else stops it.",
"fix": {
"setting_path": "authConfig.attack.leakedPasswordCheck",
"label": "Turn on the leaked-password check or CAPTCHA",
"console_link": "auth/attack-protection"
}
}
],
"score": 71,
"real_score": 71,
"shield": false,
"overrides_applied": {},
"mode": "modelled"
}sovaria.simulate.runArtifacts
What a run's sealed send points would have sent.
sovaria.simulate.runArtifacts(runId: string): Promise<JsonObject>Parameters
runIdstringrequired
Returns
Promise<JsonObject>
{
"run_id": "7c1d…",
"artifacts": [
{
"id": "9f2e1c0a…",
"run_id": "7c1d…",
"kind": "smtp",
"target_host": "email.amazonaws.com",
"outcome": "ok",
"persona": "__guest__",
"preview": {
"to": "a***@example.com",
"subject": "Confirm your email",
"body": "(hidden: needs Project settings)"
},
"created_at": 1792531200
}
]
}sovaria.simulate.getRun
Get run.
sovaria.simulate.getRun(runId: string): Promise<JsonObject>Parameters
runIdstringrequired
Returns
Promise<JsonObject>
{
"run_id": "run_7c2e…",
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"org_id": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
"status": "complete",
"started_at": "2026-10-17T13:31:02Z",
"completed_at": "2026-10-17T13:31:40Z",
"cases_total": 214,
"cases_pass": 209,
"cases_fail": 2,
"cases_warn": 3,
"cases_deviation": 2,
"top_findings": [
{
"severity": "critical",
"category": "access_control",
"title": "2 request(s) get through that your rules deny",
"detail": "…",
"fix": "…"
}
],
"results": [
{
"case": {
"role": "__guest__",
"action": "sql:select",
"resource": "orders",
"expected": "DENY"
},
"outcome": "ALLOW",
"is_deviation": true,
"deviation_type": "UNEXPECTED_ALLOW",
"guard_decision": "DENY",
"duration_ms": 38.5
}
],
"runner_ms": 38210
}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>
{
"baseline_run_id": "run_41a…",
"target_run_id": "run_7c2e…",
"summary": {
"regressions": 1,
"improvements": 3,
"unchanged": 210,
"new_cases": 4,
"removed_cases": 0,
"new_failures": 1,
"resolved_failures": 3
},
"regressions": [
{
"case_key": "__guest__|sql:select|orders|",
"role": "__guest__",
"action": "sql:select",
"resource": "orders",
"endpoint": "",
"baseline": {
"outcome": "DENY",
"is_deviation": false,
"deviation_type": "NONE",
"severity": 0
},
"target": {
"outcome": "ALLOW",
"is_deviation": true,
"deviation_type": "UNEXPECTED_ALLOW",
"severity": 3
}
}
],
"improvements": []
}