Privacy Policy Generator
NDPR-compliant privacy policy generator for websites and applications
Overview
The Privacy Policy Management components provide a comprehensive solution for creating, previewing, and exporting customized, NDPR-compliant privacy policies for your website or application. The system includes three main components: PolicyGenerator, PolicyPreview, and PolicyExporter, which work together to create professional, enterprise-ready privacy policies with variable support.
NDPR Privacy Policy Requirements
Under the NDPR, organizations must maintain a clear and accessible privacy policy that informs data subjects about how their personal data is collected, processed, stored, and protected. The policy must be written in clear, plain language and cover specific elements required by the regulation.
Installation
Install the NDPR Toolkit package which includes the Privacy Policy Generator components:
npm install @tantainnovative/ndpr-toolkit
# Or with legacy peer deps if using React 19 npm install @tantainnovative/ndpr-toolkit --legacy-peer-deps
Or if you're using yarn:
yarn add @tantainnovative/ndpr-toolkit
# Or with legacy peer deps if using React 19 yarn add @tantainnovative/ndpr-toolkit --legacy-peer-deps
Components
The Privacy Policy Management system includes three main components that work together to create, preview, and export NDPR-compliant privacy policies:
PolicyGenerator
The main component that allows users to create a policy by configuring sections and variables with an intuitive interface.
import { PolicyGenerator } from '@tantainnovative/ndpr-toolkit';
<PolicyGenerator
sections={policySections}
variables={policyVariables}
onGenerate={(policy) => {
// policy.sections - Updated sections
// policy.variables - Updated variables with values
// policy.content - Generated policy content in markdown format
setPolicyContent(policy.content);
}}
title="Privacy Policy Generator"
description="Create your NDPR-compliant privacy policy"
showPreview={true}
allowEditing={true}
/>
PolicyPreview
A component for displaying the generated privacy policy with professional formatting and navigation features.
import { PolicyPreview } from '@tantainnovative/ndpr-toolkit';
<PolicyPreview
content={policyContent} // Markdown content of the policy
title="Privacy Policy"
showTableOfContents={true}
className="policy-preview"
onContentChange={(updatedContent) => {
setPolicyContent(updatedContent);
}}
/>
PolicyExporter
A utility component for exporting the generated policy in various formats (PDF, HTML, Markdown) with professional formatting.
import { PolicyExporter } from '@tantainnovative/ndpr-toolkit';
<PolicyExporter
content={policyContent} // Markdown content of the policy
title="Privacy Policy"
filename="privacy-policy"
formats={{
pdf: true,
markdown: true,
html: true
}}
companyInfo={{
name: "Your Company Name",
logo: "/path/to/logo.png", // Optional
website: "https://example.com",
email: "privacy@example.com"
}}
/>
Variable Support
The Privacy Policy Management system supports variables in templates, allowing for dynamic and enterprise-ready policies. Variables are defined with specific types and can be edited through the PolicyGenerator interface, making it easy to customize the policy for different organizations and use cases.
Defining Variables
Variables are defined as an array of PolicyVariable objects, each with properties like id, name, description, defaultValue, inputType, and required status. These variables can then be referenced in your policy sections using the {{
and }}
syntax.
// Example of defining policy variables
const policyVariables = [
{
id: 'companyName',
name: 'Company Name',
description: 'The legal name of your organization',
defaultValue: 'Your Company',
value: '',
inputType: 'text',
required: true
},
{
id: 'contactEmail',
name: 'Contact Email',
description: 'Email address for privacy inquiries',
defaultValue: 'privacy@example.com',
value: '',
inputType: 'email',
required: true
},
{
id: 'effectiveDate',
name: 'Effective Date',
description: 'When this privacy policy takes effect',
defaultValue: new Date().toISOString().split('T')[0],
value: '',
inputType: 'date',
required: true
},
{
id: 'dataRetentionPeriod',
name: 'Data Retention Period',
description: 'How long you retain user data',
defaultValue: '12 months',
value: '',
inputType: 'text',
required: true
}
];
// Example of a policy section that uses variables
const policySections = [
{
id: 'introduction',
title: 'Introduction',
content: '# Privacy Policy for {{companyName}}
Last Updated: {{effectiveDate}}
## Introduction
{{companyName}} ("we", "us", or "our") is committed to protecting your privacy. This Privacy Policy explains how we collect, use, and safeguard your information when you use our services.',
enabled: true,
order: 1
},
This page informs you of our policies regarding the collection, use, and disclosure
of personal data when you use our Service and the choices you have associated with that data.
## Contact Us
If you have any questions about this Privacy Policy, please contact us:
- By email: {{contactEmail}}
- By visiting this page on our website: {{websiteUrl}}/contact
`;
// Using the template with the generatePolicyText utility
import { generatePolicyText } from '@tantainnovative/ndpr-toolkit';
const variables = {
organizationName: 'Acme Corporation',
lastUpdated: new Date().toLocaleDateString(),
websiteUrl: 'https://acme.com',
contactEmail: 'privacy@acme.com'
};
const generatedPolicy = generatePolicyText(policyTemplate, variables);
// The result will have all variables replaced with their values
console.log(generatedPolicy);
Variable Validation
The generatePolicyText
utility also provides validation to help you identify missing variables:
// The function returns an object with additional information
const result = generatePolicyText(policyTemplate, variables);
// The full generated text
console.log(result.fullText);
// Any missing variables that weren't provided
console.log(result.missingVariables); // e.g., ['phoneNumber']
// Individual section texts if using PolicySection[] input
console.log(result.sectionTexts);
Using with PolicySection Array
Variables also work with the array-based policy section format:
import { generatePolicyText, PolicySection } from '@tantainnovative/ndpr-toolkit';
const policySections: PolicySection[] = [
{
id: 'introduction',
title: 'Introduction',
content: '{{organizationName}} ("we", "us", or "our") operates the {{websiteUrl}} website.'
},
{
id: 'data-collection',
title: 'Data Collection',
content: 'We collect several different types of information for various purposes to provide and improve our Service to you.'
},
{
id: 'contact',
title: 'Contact Us',
content: 'If you have any questions, please contact us at {{contactEmail}}.'
}
];
const variables = {
organizationName: 'Acme Corporation',
websiteUrl: 'https://acme.com',
contactEmail: 'privacy@acme.com'
};
const result = generatePolicyText(policySections, variables);
// Access the full text
console.log(result.fullText);
// Access individual section texts
console.log(result.sectionTexts.introduction);
console.log(result.sectionTexts.contact);
Usage
Here's a complete example of how to implement the Privacy Policy Generator in your application:
import { useState } from 'react';
import {
PolicyGenerator,
PolicyPreview,
PolicyExport,
generatePolicyText,
PolicySection
} from '@tantainnovative/ndpr-toolkit';
// Define your policy templates
const policyTemplates = [
{
id: 'standard',
name: 'Standard Privacy Policy',
description: 'A comprehensive privacy policy suitable for most websites and applications.',
sections: [
{
id: 'introduction',
title: 'Introduction',
content: '{{organizationName}} ("we", "us", or "our") operates the {{websiteUrl}} website ("the Service"). This page informs you of our policies regarding the collection, use, and disclosure of personal data when you use our Service and the choices you have associated with that data.'
},
{
id: 'data-collection',
title: 'Information Collection and Use',
content: 'We collect several different types of information for various purposes to provide and improve our Service to you.'
},
// More sections...
]
},
{
id: 'minimal',
name: 'Minimal Privacy Policy',
description: 'A simplified privacy policy for small websites with minimal data collection.',
sections: [
// Sections...
]
}
];
function PrivacyPolicyPage() {
const [generatedPolicy, setGeneratedPolicy] = useState(null);
const [selectedTemplate, setSelectedTemplate] = useState('standard');
const [policyData, setPolicyData] = useState({
organizationName: '',
organizationWebsite: '',
organizationContact: '',
// Other fields...
});
const [variables, setVariables] = useState({
organizationName: '',
websiteUrl: '',
contactEmail: '',
lastUpdated: new Date().toLocaleDateString()
});
const handlePolicyGenerated = (data) => {
setPolicyData(data);
// Update variables based on policy data
setVariables({
...variables,
organizationName: data.organizationName,
websiteUrl: data.organizationWebsite,
contactEmail: data.organizationContact
});
// Find the selected template
const template = policyTemplates.find(t => t.id === selectedTemplate);
// Generate the policy text with variables
const result = generatePolicyText(template.sections, variables);
setGeneratedPolicy({
title: `Privacy Policy for ${data.organizationName}`,
content: result.fullText,
sections: template.sections.map(section => ({
...section,
content: result.sectionTexts[section.id] || section.content
})),
lastUpdated: new Date()
});
};
const handleExportPolicy = (format) => {
// Export logic...
};
return (
<div>
{!generatedPolicy ? (
<PolicyGenerator
onComplete={handlePolicyGenerated}
templates={policyTemplates}
initialValues={policyData}
onTemplateSelect={(templateId) => setSelectedTemplate(templateId)}
variables={variables}
/>
) : (
<div>
<PolicyPreview
policy={generatedPolicy}
onEdit={() => setGeneratedPolicy(null)}
variables={variables}
onVariableChange={(newVariables) => {
setVariables(newVariables);
// Regenerate policy with new variables
const template = policyTemplates.find(t => t.id === selectedTemplate);
const result = generatePolicyText(template.sections, newVariables);
setGeneratedPolicy({
...generatedPolicy,
content: result.fullText,
sections: template.sections.map(section => ({
...section,
content: result.sectionTexts[section.id] || section.content
}))
});
}}
/>
<div className="mt-6">
<h3 className="text-lg font-bold mb-2">Export Options</h3>
<PolicyExport
policy={generatedPolicy}
formats={['html', 'pdf', 'markdown']}
filename={`privacy-policy-${policyData.organizationName.toLowerCase().replace(/\s+/g, '-')}`}
onExport={handleExportPolicy}
/>
</div>
</div>
)}
</div>
);
}
API Reference
PolicyGenerator Props
Prop | Type | Default | Description |
---|---|---|---|
onComplete | (data: PolicyData) => void | Required | Callback when policy generation is complete |
templates | PolicyTemplate[] | Required | Array of policy templates |
initialValues | Partial<PolicyData> | Initial values for the policy form | |
onTemplateSelect | (templateId: string) => void | undefined | Callback when a template is selected |
variables | Record<string, string> | Variables to replace in policy templates |
generatePolicyText Function
/**
* Generates policy text by replacing variables in a template
*
* @param sectionsOrTemplate - Either an array of PolicySection objects or a template string
* @param organizationInfoOrVariables - Either an OrganizationInfo object or a variables object
* @returns Either a string (if no variables used) or an object with fullText, sectionTexts, and missingVariables
*/
function generatePolicyText(
sectionsOrTemplate: PolicySection[] | string,
organizationInfoOrVariables: OrganizationInfo | Record<string, string>
): string | {
fullText: string;
sectionTexts: Record<string, string>;
missingVariables: string[];
}
PolicyTemplate Type
type PolicyTemplate = {
id: string;
name: string;
description: string;
sections: PolicySection[];
};
PolicySection Type
type PolicySection = {
id: string;
title: string;
content: string;
required?: boolean;
};
PolicyData Type
type PolicyData = {
// Organization Information
organizationName: string;
organizationWebsite: string;
organizationContact: string;
dpoName?: string;
dpoEmail?: string;
// Data Collection
dataCollectionMethods: string[];
personalDataTypes: string[];
sensitiveDataTypes?: string[];
legalBasisForProcessing: string[];
// Data Usage
dataUsagePurposes: string[];
automaticDecisionMaking: boolean;
// Data Sharing
thirdPartySharing: boolean;
thirdPartyCategories?: string[];
internationalTransfers: boolean;
transferSafeguards?: string;
// Data Subject Rights
dataSubjectRightsProcess: string;
// Security and Retention
securityMeasures: string[];
retentionPeriod: string;
// Cookies and Tracking
usesCookies: boolean;
cookieTypes?: string[];
// Additional Information
lastUpdated: Date;
effectiveDate: Date;
additionalInformation?: string;
};
Best Practices
- Clear Language: Ensure your privacy policy is written in clear, plain language that is easy for data subjects to understand.
- Regular Updates: Review and update your privacy policy regularly, especially when there are changes to your data processing activities.
- Accessibility: Make your privacy policy easily accessible on your website or application, typically through a link in the footer.
- Customization: While the generator provides a solid template, customize the policy to accurately reflect your specific data practices.
- Legal Review: Have your generated privacy policy reviewed by a legal professional familiar with the NDPR to ensure compliance.
- Use Variables: Leverage the variable system to create reusable templates that can be easily updated when your organization information changes.
Need Help?
If you have questions about implementing the Privacy Policy Generator or need assistance with NDPR compliance, check out these resources: