gdpr-cookie-consent
Version:
Lightweight, headless cookie consent library providing technical tools for implementing consent mechanisms. Data-attribute driven, no dependencies, framework-agnostic. Legal compliance is user's responsibility - consult legal professionals.
60 lines (53 loc) • 1.68 kB
TypeScript
declare namespace GDPRCookies {
interface ConsentPreferences {
[category: string]: boolean;
}
interface ConsentData {
type: 'all' | 'essential' | 'custom';
timestamp: string;
preferences: ConsentPreferences;
}
interface ScriptConfig {
src: string;
async?: boolean;
defer?: boolean;
type?: string;
onLoad?: () => void;
onUnload?: () => void;
}
interface CategoryConfig {
title: string;
description: string;
required?: boolean;
scripts?: (string | ScriptConfig)[];
onAccept?: (category: string) => void;
onDecline?: (category: string) => void;
}
interface InitOptions {
categories: string[];
categoryConfig?: { [category: string]: CategoryConfig };
cookiePrefix?: string;
cookieDuration?: number;
autoShow?: boolean;
showDelay?: number;
debug?: boolean;
onAccept?: (preferences: ConsentPreferences) => void;
onDecline?: (preferences: ConsentPreferences) => void;
onSave?: (preferences: ConsentPreferences) => void;
}
interface GDPRCookiesInstance {
init(options: InitOptions): void;
getConsent(): ConsentData | null;
getPreferences(): ConsentPreferences;
hasConsent(category?: string): boolean;
updateCategory(category: string, enabled: boolean): void;
addScript(category: string, scriptConfig: string | ScriptConfig): void;
onCategoryChange(category: string, callback: (category: string, enabled: boolean) => void): void;
showBanner(): void;
showPreferences(): void;
clearAll(): void;
}
}
declare const GDPRCookies: GDPRCookies.GDPRCookiesInstance;
export = GDPRCookies;
export as namespace GDPRCookies;