Author and publish policies with the CLI
Create, test, publish, and activate a Policy Engine bundle for the Permissions API with the Transcend command-line interface (CLI).
Build a Permissions policy on your machine, test it, and make it live with the Transcend CLI. For how decisions work, see Policy Engine.
To let a coding agent do these steps, see Author policies with an AI agent.
Prerequisites
- Node.js 22.12 or later.
- An API key with the Manage Policy scope to upload versions. Activating a version needs the Activate Policy scope. Create the key under Developer Tools → API Keys.
- An API key with the View Managed Consent Database Admin API or Modify User Stored Preferences scope, to call the Permissions API in the last step.
1. Install the tools
Install the Transcend CLI, version 13 or later:
npm install --global @transcend-io/cliInstall OPA version 1 or later and Regal, the Rego linter. On macOS with Homebrew:
brew install opa regal2. Create a policy workspace
From the root of your repository, run:
transcend policy initinit creates an empty workspace in transcend/policy, with shared Regal settings and a README. It offers editor settings, the Policy Engine agent skill, and a GitHub Actions check. It needs no credentials.
3. Add a Permissions bundle
transcend policy new --template permissions --name permissions --yesThe command creates transcend/policy/permissions-bundle:
Three names appear in this guide. --name is the Rego package root. The folder is permissions-bundle. The remote bundle name, set when you publish, must be permissions for the Permissions API.
4. Write a purpose rule
Add one package under permissions/purposes for each purpose your application asks about. List each purpose slug in permissions/config/data.json.
This example allows the SaleOfInfo purpose only after an explicit opt-in. When the user never chose and the caller says they are in California, it escalates. Save it as permissions/purposes/sale_of_info/sale_of_info.rego:
# METADATA
# title: Sale of personal information decision
# description: Allows sale only after an explicit opt-in.
package permissions.purposes.sale_of_info
import rego.v1
import data.permissions.helpers.preference
default result := {
"decision": "deny",
"reason_code": "default_deny",
}
result := {
"decision": "allow",
"reason_code": "explicit_allow",
} if {
preference.enabled("SaleOfInfo")
}
result := {
"decision": "escalate",
"reason_code": "undecided_in_california",
} if {
preference.undecided("SaleOfInfo")
input.context.region == "US-CA"
}The response key for this purpose is sale_of_info, the last segment of the package name. Keep the conditions of each result rule mutually exclusive. Two matching rules with different values make the evaluation fail.
5. Add tests
Save tests next to the policy, in a file that ends in _test.rego. The CLI does not upload test files.
package permissions.purposes.sale_of_info_test
import rego.v1
import data.permissions.purposes.sale_of_info
test_opt_in_allows if {
result := sale_of_info.result with input as {"preferences": [{"name": "SaleOfInfo", "choice": true}]}
result.decision == "allow"
}
test_undecided_in_california_escalates if {
result := sale_of_info.result with input as {
"preferences": [{"name": "SaleOfInfo", "choice": null}],
"context": {"region": "US-CA"},
}
result.decision == "escalate"
}6. Check, test, and evaluate
Run the full gate. It checks the manifest roots, OPA formatting, strict compilation, Regal lint, and tests:
transcend policy checkAdd --fix to apply formatting and safe lint fixes. Run only the tests with transcend policy test.
Evaluate the policy against an input file to see the response your application will get:
transcend policy eval transcend/policy/permissions-bundle \
--package=data.permissions.purposes \
--input=transcend/policy/permissions-bundle/input.json \
--schema=transcend/policy/permissions-bundle/input.schema.jsonEdit input.json to try other preferences and context values. --schema rejects input that does not match the Permissions API input schema.
7. Publish a version
Upload the bundle as a new version. The first upload also creates the remote bundle.
transcend policy publish transcend/policy/permissions-bundle \
--remote-bundle-name=permissions \
--auth="$TRANSCEND_API_KEY" \
--version="permissions-v1" \
--description="Require opt-in for SaleOfInfo"Without --version, the label is the bundle name and a timestamp. The uploaded version is not live yet. On US hosting, add --transcend-url=https://api.us.transcend.io to this and every later command.
8. Activate the version
transcend policy activate \
--remote-bundle-name=permissions \
--version="permissions-v1" \
--auth="$TRANSCEND_API_KEY"Without --version, the CLI activates the most recently uploaded version. Add --dry-run to see which version it would activate.
9. Call the Permissions API
Send a user identifier and context to the Permissions API for one Preference Store partition. Use the partition key from Partition Keys:
curl -X POST "https://multi-tenant.sombra.transcend.io/v1/permissions/$PARTITION" \
-H "Authorization: Bearer $TRANSCEND_PREFERENCES_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"identifier": { "name": "email", "value": "user@example.com" },
"context": { "region": "US-CA" }
}'Replace the host with your organization's Sombra URL. On US hosting, Transcend-hosted Sombra is https://multi-tenant.sombra.us.transcend.io. The identifier name must be one configured for your Preference Store. The response has one decision per purpose, as described in Policy result.
Roll back
List the uploaded versions, then activate an earlier one:
transcend policy versions --remote-bundle-name=permissions --auth="$TRANSCEND_API_KEY"
transcend policy activate --remote-bundle-name=permissions --version="permissions-v0" --auth="$TRANSCEND_API_KEY"transcend policy deactivate --remote-bundle-name=permissions stops serving the bundle. The Permissions API then returns 503 for every call, so prefer rolling back to a known good version.
Command reference
| Command | Does | Scope |
|---|---|---|
transcend policy init | Creates a workspace, with optional editor, skill, and CI | None |
transcend policy new | Adds a bundle from the permissions or generic template | None |
transcend policy check | Runs every local check | None |
transcend policy lint | Runs OPA formatting and Regal only | None |
transcend policy test | Runs OPA tests | None |
transcend policy eval | Evaluates a bundle against an input file | None |
transcend policy publish | Uploads a new version | Manage Policy |
transcend policy activate | Makes a version live | Activate Policy |
transcend policy deactivate | Stops serving a bundle | Activate Policy |
transcend policy bundles | Lists remote bundles | View Policy |
transcend policy versions | Lists the versions of a bundle | View Policy |
transcend policy download | Downloads a version, by default the active one | View Policy |
Run any command with --help for every flag. The CLI reads TRANSCEND_API_KEY when you omit --auth, and TRANSCEND_API_URL when you omit --transcend-url.