OpenPolicy

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

PackageDescription
@openpolicy/sdkdefinePrivacyPolicy() and the PrivacyPolicyConfig type
@openpolicy/cliopenpolicy CLI — init, generate, validate commands
@openpolicy/viteVite plugin — compiles policies at build time and watches in dev mode

How it works

  1. Create a policy.config.ts that exports a definePrivacyPolicy() call with your company details, data categories, cookies, and jurisdictions
  2. Run openpolicy generate or add openPolicy() to your Vite config
  3. 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

On this page