Introduction to OpenPolicy
Type-safe privacy policy generation for TypeScript projects
OpenPolicy is a TypeScript-first toolkit for generating privacy policy documents. Define your policy once as a typed configuration object, then compile it to Markdown, HTML, or other formats — at build time via the Vite plugin, or on demand via the CLI.
Why OpenPolicy
Privacy policies are documents, but their content is structured data. Company name, data retention periods, cookie categories, and jurisdiction rules don't change often and shouldn't live in a static text file that's hard to update or validate.
OpenPolicy lets you:
- Define policies as code — TypeScript gives you autocomplete, type checking, and refactoring across your policy config
- Validate for compliance — built-in checks flag missing GDPR and CCPA requirements before you publish
- Generate multiple formats — one config produces Markdown, HTML, and more
- Integrate with your build — the Vite plugin compiles policies automatically so output is always in sync
Packages
| Package | Description |
|---|---|
@openpolicy/sdk | definePrivacyPolicy() and the PrivacyPolicyConfig type |
@openpolicy/cli | openpolicy CLI — init, generate, validate commands |
@openpolicy/vite | Vite plugin — compiles policies at build time and watches in dev mode |
How it works
- Create a
policy.config.tsthat exports adefinePrivacyPolicy()call with your company details, data categories, cookies, and jurisdictions - Run
openpolicy generateor addopenPolicy()to your Vite config - Import the generated Markdown or HTML in your app and render it
// policy.config.ts
import { definePrivacyPolicy } from "@openpolicy/sdk";
export default definePrivacyPolicy({
effectiveDate: "2026-01-01",
company: {
name: "Acme Inc.",
legalName: "Acme Corporation",
address: "123 Main St, Springfield, USA",
contact: "privacy@acme.com",
},
dataCollected: {
"Account Information": ["Name", "Email address"],
"Usage Data": ["Pages visited", "Browser type", "IP address"],
},
legalBasis: "Legitimate interests and consent",
retention: {
"Account data": "Until account deletion",
"Usage logs": "90 days",
},
cookies: { essential: true, analytics: false, marketing: false },
thirdParties: [],
userRights: ["access", "erasure"],
jurisdictions: ["us", "eu"],
});Get started
- Quick Start — install, configure, and generate your first policy in minutes
- Using the CLI — interactive wizard and command reference
- Using the Vite plugin — automatic compilation during builds and in dev mode
- Using with Next.js — rendering generated policies in a Next.js app