Transcend Docs

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/cli

Install OPA version 1 or later and Regal, the Rego linter. On macOS with Homebrew:

brew install opa regal

2. Create a policy workspace

From the root of your repository, run:

transcend policy init

init 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 --yes

The command creates transcend/policy/permissions-bundle:

.manifestOPA manifest; roots: ["permissions"]
input.schema.jsonPermissions API input schema
input.example.jsonExample input, committed
input.jsonLocal scratch input, gitignored
config.rego
data.jsonPurpose slugs the policy knows about
preference.regoenabled(), disabled(), undecided()
preference_test.rego
entrypoint.regopackage permissions.purposes
analytics.regoThe Analytics decision
analytics_test.rego

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 check

Add --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.json

Edit 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

CommandDoesScope
transcend policy initCreates a workspace, with optional editor, skill, and CINone
transcend policy newAdds a bundle from the permissions or generic templateNone
transcend policy checkRuns every local checkNone
transcend policy lintRuns OPA formatting and Regal onlyNone
transcend policy testRuns OPA testsNone
transcend policy evalEvaluates a bundle against an input fileNone
transcend policy publishUploads a new versionManage Policy
transcend policy activateMakes a version liveActivate Policy
transcend policy deactivateStops serving a bundleActivate Policy
transcend policy bundlesLists remote bundlesView Policy
transcend policy versionsLists the versions of a bundleView Policy
transcend policy downloadDownloads a version, by default the active oneView 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.

On this page