Quickstart
Publish a schema and run your first check.
You need Node.js 24 or later, and access to a Peretyn dashboard. The managed dashboard is at app.peretyn.dev. If you run Peretyn yourself, use your own domain in place of app.peretyn.dev below.
1. Create a project
In the dashboard, select Create project. Peretyn creates a production and a development environment and shows an API key for each. Copy the development key, which starts with prn_test_. The dashboard shows it only once.
2. Set your environment
The SDK and the CLI both read these variables:
export PERETYN_TOKEN=prn_test_...
export PERETYN_RUNTIME_URL=https://app.peretyn.dev
export PERETYN_CONTROL_URL=https://app.peretyn.dev3. Install the SDK
npm install @peretyn/sdk4. Write a schema
A document has owners and viewers. Anyone who is an owner or a viewer can view it.
import { any, defineSchema, type } from '@peretyn/sdk';
export const schema = defineSchema({
user: type(),
document: type({
relations: { owner: ['user'], viewer: ['user'] },
permissions: { can_view: any('owner', 'viewer') },
}),
});5. Publish the schema
Download the peretyn binary for your platform from the latest release and put it on your PATH. Then compile the schema and publish it to the environment that your API key identifies:
peretyn build --schema schema.ts
peretyn apply --label v16. Run a check
This script writes one tuple, Alice owns the roadmap, and then checks whether Alice can view it:
import { peretyn } from '@peretyn/sdk';
import type { schema } from './schema';
const authz = peretyn<typeof schema>({ token: process.env.PERETYN_TOKEN! });
await authz.write({
writes: [
{
subject: { type: 'user', id: 'alice' },
relation: 'owner',
object: { type: 'document', id: 'roadmap' },
},
],
});
const { allowed } = await authz.check({
subject: { type: 'user', id: 'alice' },
relation: 'can_view',
object: { type: 'document', id: 'roadmap' },
});
console.log(allowed ? 'allowed' : 'denied');node check.tsIt prints allowed. Alice is an owner, and owners can view.