cookie-consent-gdpr 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,182 @@
1
+ /**
2
+ * GDPR Cookie Consent — TypeScript Declarations
3
+ */
4
+
5
+ export interface CookieDetail {
6
+ /** Cookie name or pattern. */
7
+ name: string;
8
+ /** Domain/company that sets this cookie. */
9
+ provider?: string;
10
+ /** Human-readable purpose. */
11
+ purpose?: string;
12
+ /** Duration string (e.g. '1 year', 'Session'). */
13
+ expiry?: string;
14
+ /** Type: 'HTTP Cookie' | 'localStorage' | 'sessionStorage' | 'Pixel'. */
15
+ type?: string;
16
+ }
17
+
18
+ export interface CategoryConfig {
19
+ /** Whether this category is enabled by default (must be false for non-necessary per GDPR). */
20
+ enabled: boolean;
21
+ /** Whether the user can toggle this off (true for strictly necessary cookies). */
22
+ readOnly: boolean;
23
+ /** Display title for this category. */
24
+ title: string;
25
+ /** Description of what this category does. */
26
+ description: string;
27
+ /** List of cookies in this category. */
28
+ cookies: CookieDetail[];
29
+ }
30
+
31
+ export interface CookieConfig {
32
+ /** Name of the consent cookie. Default: 'cc_consent'. */
33
+ name?: string;
34
+ /** Cookie domain. Set to '.example.com' for cross-subdomain sharing. */
35
+ domain?: string;
36
+ /** Cookie path. Default: '/'. */
37
+ path?: string;
38
+ /** Consent expiry in days. Default: 365. */
39
+ expiryDays?: number;
40
+ /** SameSite attribute. Default: 'Lax'. */
41
+ sameSite?: 'Lax' | 'Strict' | 'None';
42
+ /** Secure flag. Default: auto-detected from protocol. */
43
+ secure?: boolean;
44
+ }
45
+
46
+ export interface WebhookConfig {
47
+ /** URL to POST consent records to. */
48
+ url: string | null;
49
+ /** Additional headers for the webhook request. */
50
+ headers?: Record<string, string>;
51
+ }
52
+
53
+ export interface ThemeConfig {
54
+ primary?: string;
55
+ primaryHover?: string;
56
+ primaryText?: string;
57
+ background?: string;
58
+ text?: string;
59
+ textSecondary?: string;
60
+ border?: string;
61
+ overlay?: string;
62
+ toggleOn?: string;
63
+ toggleOff?: string;
64
+ toggleKnob?: string;
65
+ fontFamily?: string;
66
+ fontSize?: string;
67
+ borderRadius?: string;
68
+ zIndex?: number;
69
+ maxWidth?: string;
70
+ popupWidth?: string;
71
+ }
72
+
73
+ export interface TextsConfig {
74
+ bannerTitle?: string;
75
+ bannerDescription?: string;
76
+ acceptAll?: string;
77
+ rejectAll?: string;
78
+ settings?: string;
79
+ preferencesTitle?: string;
80
+ preferencesDescription?: string;
81
+ save?: string;
82
+ acceptAllPreferences?: string;
83
+ rejectAllPreferences?: string;
84
+ alwaysActive?: string;
85
+ cookieNameLabel?: string;
86
+ cookieProviderLabel?: string;
87
+ cookiePurposeLabel?: string;
88
+ cookieExpiryLabel?: string;
89
+ cookieTypeLabel?: string;
90
+ noCookies?: string;
91
+ privacyPolicyLabel?: string;
92
+ poweredBy?: string;
93
+ }
94
+
95
+ export interface ConsentRecord {
96
+ /** Unique consent ID (UUID). */
97
+ id: string;
98
+ /** ISO 8601 timestamp of when consent was given. */
99
+ timestamp: string;
100
+ /** Map of category keys to boolean consent values. */
101
+ categories: Record<string, boolean>;
102
+ /** Hash of the config used when consent was given. */
103
+ configHash: string;
104
+ /** ISO 8601 timestamp of when this consent expires. */
105
+ expires: string;
106
+ /** URL where consent was given. */
107
+ url: string;
108
+ /** User agent string. */
109
+ userAgent: string;
110
+ }
111
+
112
+ export type ConsentEvent =
113
+ | 'consent:given'
114
+ | 'consent:updated'
115
+ | 'consent:revoked'
116
+ | 'category:accepted'
117
+ | 'category:rejected'
118
+ | 'banner:shown'
119
+ | 'banner:hidden'
120
+ | 'preferences:shown'
121
+ | 'preferences:hidden';
122
+
123
+ export interface CookieConsentConfig {
124
+ /** CSS selector or DOM element to mount the banner in. */
125
+ container?: string | HTMLElement | null;
126
+ /** CSS selector or DOM element for the preferences button. */
127
+ preferencesButton?: string | HTMLElement | null;
128
+ /** Banner layout: 'bar' | 'modal' | 'popup'. Default: 'bar'. */
129
+ layout?: 'bar' | 'modal' | 'popup';
130
+ /** Banner position. Default: 'bottom'. */
131
+ position?: 'bottom' | 'top' | 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
132
+ /** Whether clicking the overlay closes the banner. Default: false. */
133
+ closeOnBackdrop?: boolean;
134
+ /** Auto-show banner if no consent exists. Default: true. */
135
+ autoShow?: boolean;
136
+ /** Re-show banner when config changes. Default: true. */
137
+ reconsentOnChange?: boolean;
138
+ /** Force an overlay that blocks page interaction. Default: false. */
139
+ forceOverlay?: boolean;
140
+ /** Cookie storage settings. */
141
+ cookie?: CookieConfig;
142
+ /** Webhook for consent records. */
143
+ webhook?: WebhookConfig;
144
+ /** Cookie category definitions. */
145
+ categories?: Record<string, CategoryConfig>;
146
+ /** UI text strings (for i18n). */
147
+ texts?: TextsConfig;
148
+ /** URL to the site's privacy policy. */
149
+ privacyPolicyUrl?: string;
150
+ /** Theme/appearance settings. */
151
+ theme?: ThemeConfig;
152
+ /** Callback when consent is given or updated. */
153
+ onConsent?: (consent: ConsentRecord) => void;
154
+ /** Callback when consent is revoked. */
155
+ onRevoke?: (consent: ConsentRecord | null) => void;
156
+ /** Callback when a category is accepted. */
157
+ onAccept?: (category: string) => void;
158
+ /** Callback when a category is rejected. */
159
+ onReject?: (category: string) => void;
160
+ }
161
+
162
+ export interface CookieConsentAPI {
163
+ init(config?: CookieConsentConfig): CookieConsentAPI;
164
+ show(): CookieConsentAPI;
165
+ hide(): CookieConsentAPI;
166
+ showPreferences(): CookieConsentAPI;
167
+ hidePreferences(): CookieConsentAPI;
168
+ acceptAll(): CookieConsentAPI;
169
+ rejectAll(): CookieConsentAPI;
170
+ acceptCategory(category: string): CookieConsentAPI;
171
+ getConsent(): ConsentRecord | null;
172
+ hasConsented(): boolean;
173
+ hasCategory(category: string): boolean;
174
+ revokeConsent(): CookieConsentAPI;
175
+ on(event: ConsentEvent, fn: (data?: any) => void): CookieConsentAPI;
176
+ off(event: ConsentEvent, fn?: (data?: any) => void): CookieConsentAPI;
177
+ destroy(): CookieConsentAPI;
178
+ getConfig(): CookieConsentConfig | null;
179
+ }
180
+
181
+ declare const CookieConsent: CookieConsentAPI;
182
+ export default CookieConsent;