JavaScript SDK

Policy management

Create resources, permissions and roles, assign roles to users, change authorization settings, and backtest suggested changes.

These ScuteAdminApi methods change what your app guards and who may do what. They need the secret key of an owner or admin. Slugs are lowercase. Changes apply on the next check.

Resources#

A resource is a kind of thing your app guards (project) with its actions (view, edit). Each action is a permission: project:view.

await admin.authzCreateResource({ slug: "project", name: "Project", actions: ["view", "edit"] });const { data: resources } = await admin.authzResources();
MethodDoes
authzResources()Lists resources with actions, per-object roles and relations.
authzCreateResource({ slug, name, description?, actions? })Adds one.
authzUpdateResource(slug, { name?, description?, actions?, force? })actions replaces the list. Dropping an action a role grants needs force: true.
authzDeleteResource(slug, { force? })With grants or objects present, needs force: true.

Per-object roles and relations are edited in the dashboard.

Permissions#

await admin.authzUpdatePermission("invoice:refund", {  requires_verification: true,  verification_method: "email_otp",  verification_ttl: 300,});
MethodDoes
authzPermissions()Resource permissions and custom ones.
authzCreatePermission({ slug, name, ...changes })A custom permission not tied to a resource (export_reports).
authzUpdatePermission(slug, changes)Only the fields you pass change.
authzDeletePermission(slug, { force? })Custom permissions only. Granted ones need force: true.

Permission fields: name, description, enabled, requires_verification, verification_method (a challenge method; blank or "any" accepts any), verification_ttl (seconds), requires_approval, autonomous_allowed, blocked_while_impersonating, requester_only.

Roles#

await admin.authzCreateRole({  slug: "approver",  name: "Approver",  permissions: ["invoice:view", { permission: "invoice:approve", when: { lt: [{ var: "resource.amount" }, 5000] } }],});await admin.authzAssignRole(userId, "approver", { expiresAt: "2026-12-31" });
MethodDoes
authzRoles()Roles with permissions, conditions, is_default, deletable and holders.
authzCreateRole({ slug, name, description?, is_default?, position?, permissions? })A default role is held by everyone who signs in. A permission entry can carry a when condition.
authzUpdateRole(slug, changes)permissions replaces the whole set.
authzDeleteRole(slug, { reassignTo? })When people hold it, name the role they move to.
authzUserRoles(userId){ user_id, roles, default_roles, resource_roles }. Each role: { role, expires_at, source, active }.
authzAssignRole(userId, role, { expiresAt? })For good, or until expiresAt. Assigning again changes the expiry.
authzRevokeRole(userId, role)A role an identity provider manages (source other than "manual") cannot be removed here.

Settings#

const { data: settings } = await admin.authzSettings();await admin.authzUpdateSettings({ client_checks: true, access_requests: true });
Setting
client_checksSigned-in users may check their own permissions from the browser.
access_requestsUsers may file access requests.
log_allow_rateShare of allows kept in the decision log (0 to 1). Denials are always kept.
log_retention_days
gateway, gateway_unmatchedGateway enforcement, and what an unmatched route gets ("deny" or "allow").
impersonation, impersonation_max_minutes, impersonation_protected_rolesSupport access.
session_trust, session_trust_minutes
export_eventRead only.

Suggestions and backtests#

Scute proposes changes from the decision log. A backtest replays a change against recent decisions in memory. Nothing is ever applied.

const { data: suggestions } = await admin.authzSuggestions(30);// [{ kind: "unused_grant" | "repeated_denies" | "always_approved", title, detail?, evidence, change? }]const { data: result } = await admin.authzBacktest(  [{ op: "revoke", role: "viewer", permission: "invoice:export" }],  { days: 30 });// { days, checked, changed, summary: { "allow -> deny": 3 }, people_affected, examples, allow_sample_rate, note }

A change is a list of { op: "grant" | "revoke", role, permission } or { op: "set", permission, enabled?, requires_verification?, requires_approval?, requester_only? }.