Docs

JavaScript: Policies and audit

List, create, test and roll back project access policies, ask whether an action is allowed, and read or verify the tamper-evident audit log with @sovaria/sdk.

Updated Nov 11, 2026

Access policies are short rules in Sovaria's policy language that decide whether a caller may use a table, collection, bucket, channel or function. These methods manage them; run them as a team member, not from an app.

const spl = 'ALLOW IF "STAFF" IN ctx.actor.roles'
const result = await sovaria.policy.simulate(spl, { actor: { roles: ['STAFF'] }, action: 'UPDATE', resource: 'books' })
console.log(result)

await sovaria.policy.create({ policy_id: 'pol_staff_edit_books', org_id: orgId, name: 'staff edit books', spl_source: spl })

#sovaria.policy

sovaria.policy.templates

Templates.

sovaria.policy.templates(): Promise<JsonObject>

Returns

Promise<JsonObject>

{
  "templates": [
    {
      "category": "Basic",
      "label": "Signed-in users can read",
      "name": "Signed-in users can read",
      "spl": "ALLOW IF ctx.actor.is_anonymous == False AND ctx.action == \"SELECT\"",
      "desc": "Signed-in app users can read tables. Writes need another rule."
    }
  ],
  "categories": {
    "Basic": [
      {
        "label": "Signed-in users can read",
        "name": "Signed-in users can read",
        "spl": "ALLOW IF ctx.actor.is_anonymous == False AND ctx.action == \"SELECT\"",
        "desc": "Signed-in app users can read tables. Writes need another rule."
      }
    ]
  }
}

sovaria.policy.list

List.

sovaria.policy.list(): Promise<JsonValue>

Returns

Promise<JsonValue>

[
  {
    "policy_id": "pol_orders_read",
    "org_id": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
    "name": "Signed-in users read orders",
    "spl_source": "ALLOW IF ctx.resource.name == \"orders\" AND ctx.action IN [\"SELECT\", \"sql:select\"] AND ctx.actor.is_anonymous == False",
    "version": 3,
    "is_active": true,
    "env_id": null,
    "inherited": false
  }
]

sovaria.policy.get

Get.

sovaria.policy.get(policyId: string): Promise<JsonObject>

Parameters

policyIdstringrequired

Returns

Promise<JsonObject>

{
  "policy_id": "pol_orders_read",
  "org_id": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
  "name": "Signed-in users read orders",
  "spl_source": "ALLOW IF ctx.resource.name == \"orders\" AND ctx.action IN [\"SELECT\", \"sql:select\"] AND ctx.actor.is_anonymous == False",
  "version": 3,
  "is_active": true,
  "env_id": null,
  "inherited": false
}

sovaria.policy.create

Create.

sovaria.policy.create(payload: JsonObject): Promise<JsonObject>

Parameters

payloadJsonObjectrequired
policy_id (your unique id, e.g. pol_books_read), org_id, name and spl_source.

Returns

Promise<JsonObject>

{
  "policy_id": "pol_orders_read",
  "version": 1,
  "status": "compiled"
}

sovaria.policy.update

Update.

sovaria.policy.update(
  policyId: string,
  payload: JsonObject,
): Promise<JsonObject>

Parameters

policyIdstringrequired
payloadJsonObjectrequired

Returns

Promise<JsonObject>

{
  "policy_id": "pol_orders_read",
  "version": 4,
  "status": "recompiled"
}

sovaria.policy.delete

Delete.

sovaria.policy.delete(policyId: string): Promise<JsonObject>

Parameters

policyIdstringrequired

Returns

Promise<JsonObject>

sovaria.policy.evaluate

Evaluate.

sovaria.policy.evaluate(
  policyId: string,
  context: JsonObject,
): Promise<JsonObject>

Parameters

policyIdstringrequired
contextJsonObjectrequired

Returns

Promise<JsonObject>

{
  "policy_id": "pol_orders_read",
  "decision": "DENY",
  "http_status": 403,
  "deny_reason": "NO_MATCH",
  "retry_after_ms": 0,
  "latency_us": 41.2
}

sovaria.policy.check

Check.

sovaria.policy.check(
  payload: { orgId: string projectId: string action: string resource: string context?: JsonObject },
): Promise<JsonObject>

Parameters

payload{ orgId: string projectId: string action: string resource: string context?: JsonObject }required
orgId, projectId, action, resource and optional context.

Returns

Promise<JsonObject> — Whether it is allowed and which policy decided.

{
  "allowed": true,
  "reason": "ALLOW",
  "policy_id": "pol_orders_read"
}

sovaria.policy.preflight

Preflight.

sovaria.policy.preflight(
  action: string,
  resource: string,
  context?: JsonObject = {},
): Promise<JsonObject>

Parameters

actionstringrequired
e.g. UPDATE.
resourcestringrequired
e.g. books.
contextJsonObjectoptionaldefault {}
Extra request context.

Returns

Promise<JsonObject>

  • check() for the client's current project.

sovaria.policy.history

History.

sovaria.policy.history(policyId: string): Promise<JsonValue>

Parameters

policyIdstringrequired

Returns

Promise<JsonValue>

[
  {
    "audit_id": "v3",
    "policy_id": "pol_orders_read",
    "actor_user_id": "6e19c0a2-…",
    "action": "UPSERT",
    "new_spl_source": "ALLOW IF ctx.resource.name == \"orders\" AND ctx.action IN [\"SELECT\", \"sql:select\"] AND ctx.actor.is_anonymous == False",
    "version": 3,
    "created_at": "2026-10-17T12:31:08Z"
  }
]

sovaria.policy.rollback

Rollback.

sovaria.policy.rollback(
  policyId: string,
  version: number,
): Promise<JsonObject>

Parameters

policyIdstringrequired
Policy id.
versionnumberrequired
Version number from history().

Returns

Promise<JsonObject>

{
  "policy_id": "pol_orders_read",
  "version": 5,
  "restored_from": 2,
  "status": "rolled_back"
}

sovaria.policy.simulate

ALLOW/DENY for each `{ action, resource, context?

sovaria.policy.simulate(
  operations: Array<{ action: string; resource: string; context?: JsonObject }>,
  options?: { draftPolicies?: JsonObject[]; disabledPolicyIds?: string[]; envId?: string; explain?: boolean } = {},
): Promise<JsonObject>

} under the project's live policies, plus draftPolicies ({ spl_source, policy_id?, replaces? }, not saved) and minus disabledPolicyIds. Nothing is stored. Resolves { results: [{ op_index, action, resource, decision, policy_id, reason }] }; with explain: true each result also carries explanation: the steps that decided it, in order ({ step, outcome, detail, policy_name? }`).

Parameters

operationsArray<{ action: string; resource: string; context?: JsonObject }>required
options{ draftPolicies?: JsonObject[]; disabledPolicyIds?: string[]; envId?: string; explain?: boolean }optionaldefault {}

Returns

Promise<JsonObject>

#Audit log

sovaria.audit.append

Append.

sovaria.audit.append(payload: JsonObject): Promise<JsonObject>

Parameters

payloadJsonObjectrequired

Returns

Promise<JsonObject>

{
  "seq": 18343,
  "event_type": "app.refund.approved",
  "actor_id": "6e19c0a2-3f5b-4a8e-9b1d-0c7f2e8a4d51",
  "resource_id": "order:1042",
  "source": "backoffice",
  "action": "APPROVE",
  "metadata": {
    "amount": 59.9
  },
  "ip_address": "203.0.113.24",
  "timestamp": "2026-10-17T12:31:08.512Z",
  "hmac": "9f1c…",
  "prev_hmac": "41aa…",
  "chain_key": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
  "chain_seq": 913,
  "entry_hash": "c3e8…",
  "prev_hash": "7b02…"
}

sovaria.audit.list

List.

sovaria.audit.list(
  query?: { actor_id?: string event_type?: string source?: string resource_id?: string limit?: number offset?: number },
): Promise<JsonValue>

Parameters

query{ actor_id?: string event_type?: string source?: string resource_id?: string limit?: number offset?: number }optional

Returns

Promise<JsonValue>

[
  {
    "seq": 18342,
    "event_type": "policy.updated",
    "actor_id": "6e19c0a2-3f5b-4a8e-9b1d-0c7f2e8a4d51",
    "resource_id": "pol_orders_read",
    "source": "guard",
    "action": "UPDATE",
    "metadata": {
      "version": 3,
      "project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07"
    },
    "ip_address": "203.0.113.24",
    "timestamp": "2026-10-17T12:31:08.512Z",
    "hmac": "9f1c…",
    "prev_hmac": "41aa…",
    "chain_key": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
    "chain_seq": 912,
    "entry_hash": "c3e8…",
    "prev_hash": "7b02…"
  }
]

sovaria.audit.verify

Verify.

sovaria.audit.verify(): Promise<JsonObject>

Returns

Promise<JsonObject> — Whether the hash chain is intact — every entry links to the previous one, so edits are detectable.

{
  "chain_key": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
  "chain_valid": true,
  "verified_entries": 913,
  "head_chain_seq": 913,
  "head_hash": "c3e8…"
}

sovaria.audit.count

Count.

sovaria.audit.count(): Promise<JsonObject>

Returns

Promise<JsonObject>

{
  "count": 913
}

#sovaria.compliance

sovaria.compliance.overview

Audit-log check, encryption and own-key status, data regions, per-project backups/PITR/Security Advisor, access.

sovaria.compliance.overview(
  orgId?: string,
  options?: { projectId?: string } = {},
): Promise<JsonObject>

Parameters

orgIdstringoptional
options{ projectId?: string }optionaldefault {}

Returns

Promise<JsonObject>

{
  "generated_at": "2026-11-07T08:00:00+00:00",
  "scope": "organization",
  "statement": "This pack describes how Sovaria is configured … not a certification.",
  "organization": {
    "id": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
    "name": "Skolist",
    "plan": "pro",
    "default_region": "ap-south-1"
  },
  "audit_chain": {
    "status": "ok",
    "chain_valid": true
  },
  "byok": "not_enabled",
  "backup_encryption": {
    "completed": 14,
    "encrypted": 14,
    "unencrypted": 0,
    "algorithms": [
      "aes256gcm-stream-v1"
    ],
    "unreadable_projects": 0
  },
  "data_regions": [
    "ap-south-1"
  ],
  "projects": [
    {
      "id": "5e8d2a1f-3c90-4f0a-9c6b-b2f4a1c87d3e",
      "name": "shop",
      "ref": "abcdefghijkl",
      "data_region": "ap-south-1",
      "backups": "ok",
      "pitr": "ok",
      "pitr_enabled": true,
      "security_advisor": {
        "high": 1
      },
      "security_advisor_status": "ok",
      "backup_encryption": "encrypted"
    }
  ],
  "access": {
    "members": 3,
    "owners": 1,
    "admins": 1,
    "members_without_mfa": 0,
    "active_api_keys": 2,
    "service_role_keys": 1
  },
  "security_advisor": {
    "critical": 0,
    "high": 1,
    "medium": 0,
    "low": 0
  },
  "subprocessors": 9,
  "trust_center": "https://sovaria.in/trust",
  "hipaa": {
    "available": false,
    "plan": "pro",
    "required_plan": "enterprise"
  }
}

sovaria.compliance.downloadEvidence

The evidence pack as a ZIP Blob (MANIFEST.json holds every file's SHA-256).

sovaria.compliance.downloadEvidence(
  orgId?: string,
  options?: { projectId?: string } = {},
): Promise<Blob>

Counted per day; audited.

Parameters

orgIdstringoptional
options{ projectId?: string }optionaldefault {}

Returns

Promise<Blob>

sovaria.compliance.hipaa

HIPAA status (Enterprise): HIPAA mode (BAA signed), session limits, audit retention, PHI projects and the features turned off.

sovaria.compliance.hipaa(orgId?: string): Promise<JsonObject>

Other plans get 403 PLAN_FEATURE_REQUIRED with required_plan.

Parameters

orgIdstringoptional

Returns

Promise<JsonObject>

{
  "available": true,
  "plan": "enterprise",
  "required_plan": "enterprise",
  "mode": true,
  "active": true,
  "baa_signed": true,
  "session_limits": {
    "inactivityMinutes": 15,
    "timeBoxMinutes": 720
  },
  "org_session_limits": null,
  "audit_log_days": 2190,
  "phi_projects": [
    {
      "id": "5e8d2a1f-3c90-4f0a-9c6b-b2f4a1c87d3e",
      "name": "clinic",
      "ref": "abcdefghijkl"
    }
  ],
  "features_outside_baa": [
    {
      "id": "ai",
      "label": "Sovariq AI assistant and project agents",
      "why": "Prompts and data go to an LLM provider that isn't covered by the AWS BAA."
    }
  ],
  "safeguards": []
}

sovaria.compliance.downloadHipaaReport

The HIPAA safeguards report as a ZIP Blob (hipaa_safeguards.md, hipaa.json, MANIFEST.json), judged from live data.

sovaria.compliance.downloadHipaaReport(orgId?: string): Promise<Blob>

Enterprise; counted per day; audited. Evidence for your own risk analysis, not a certification.

Parameters

orgIdstringoptional

Returns

Promise<Blob>