@iqworksai/consentiq-react 0.1.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.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # @consentiq/react
2
+
3
+ React SDK for ConsentIQ consent management platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @consentiq/react
9
+ # or
10
+ yarn add @consentiq/react
11
+ # or
12
+ pnpm add @consentiq/react
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```tsx
18
+ import { ConsentIQProvider, CookieBanner, PreferenceCenter } from '@consentiq/react';
19
+
20
+ function App() {
21
+ return (
22
+ <ConsentIQProvider propertyKey="YOUR_PROPERTY_KEY">
23
+ <CookieBanner />
24
+ <PreferenceCenter />
25
+ <YourApp />
26
+ </ConsentIQProvider>
27
+ );
28
+ }
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Provider Configuration
34
+
35
+ ```tsx
36
+ <ConsentIQProvider
37
+ propertyKey="YOUR_PROPERTY_KEY"
38
+ apiUrl="https://api.consentiq.io" // Optional: custom API URL
39
+ autoShow={true} // Optional: show banner automatically
40
+ language="en" // Optional: override detected language
41
+ debug={false} // Optional: enable debug logging
42
+ onConsentChange={(consent) => {
43
+ console.log('Consent updated:', consent);
44
+ }}
45
+ >
46
+ {children}
47
+ </ConsentIQProvider>
48
+ ```
49
+
50
+ ### Using the Consent Hook
51
+
52
+ ```tsx
53
+ import { useConsentIQ } from '@consentiq/react';
54
+
55
+ function Analytics() {
56
+ const { hasConsent } = useConsentIQ();
57
+
58
+ if (!hasConsent('analytics')) {
59
+ return null;
60
+ }
61
+
62
+ return <GoogleAnalytics />;
63
+ }
64
+ ```
65
+
66
+ ### Simplified Consent Check
67
+
68
+ ```tsx
69
+ import { useConsent } from '@consentiq/react';
70
+
71
+ function MarketingScript() {
72
+ const hasMarketing = useConsent('marketing');
73
+
74
+ if (!hasMarketing) return null;
75
+
76
+ return <FacebookPixel />;
77
+ }
78
+ ```
79
+
80
+ ### Consent Gate Component
81
+
82
+ ```tsx
83
+ import { ConsentGate } from '@consentiq/react';
84
+
85
+ function App() {
86
+ return (
87
+ <ConsentGate
88
+ category="analytics"
89
+ fallback={<p>Enable analytics for better experience</p>}
90
+ >
91
+ <AnalyticsProvider />
92
+ </ConsentGate>
93
+ );
94
+ }
95
+ ```
96
+
97
+ ### Manual Control
98
+
99
+ ```tsx
100
+ import { useConsentIQ } from '@consentiq/react';
101
+
102
+ function SettingsPage() {
103
+ const { showPreferenceCenter, resetConsent } = useConsentIQ();
104
+
105
+ return (
106
+ <>
107
+ <button onClick={showPreferenceCenter}>
108
+ Manage Cookies
109
+ </button>
110
+ <button onClick={resetConsent}>
111
+ Reset All Preferences
112
+ </button>
113
+ </>
114
+ );
115
+ }
116
+ ```
117
+
118
+ ## Consent Categories
119
+
120
+ | Category | Description |
121
+ |----------|-------------|
122
+ | `necessary` | Essential cookies (always enabled) |
123
+ | `analytics` | Analytics and measurement |
124
+ | `marketing` | Advertising and targeting |
125
+ | `preferences` | User preferences |
126
+ | `social` | Social media integration |
127
+
128
+ ## API Reference
129
+
130
+ ### `useConsentIQ()`
131
+
132
+ Returns the full consent context:
133
+
134
+ ```typescript
135
+ {
136
+ consent: ConsentState; // Current consent state
137
+ marketingConsent: MarketingConsentState;
138
+ config: PropertyConfig | null; // Property configuration
139
+ isLoading: boolean; // SDK loading state
140
+ isBannerVisible: boolean; // Banner visibility
141
+ isPreferenceCenterVisible: boolean;
142
+ language: string; // Current language
143
+ regulation: string | null; // Detected regulation
144
+ hasConsent(category): boolean; // Check consent
145
+ acceptAll(): Promise<void>; // Accept all
146
+ rejectAll(): Promise<void>; // Reject all
147
+ updateConsent(updates): Promise<void>;
148
+ showBanner(): void;
149
+ hideBanner(): void;
150
+ showPreferenceCenter(): void;
151
+ hidePreferenceCenter(): void;
152
+ resetConsent(): void;
153
+ }
154
+ ```
155
+
156
+ ## License
157
+
158
+ MIT
@@ -0,0 +1,298 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React from 'react';
3
+
4
+ /**
5
+ * ConsentIQ React SDK Types
6
+ */
7
+ type ConsentCategory = 'necessary' | 'analytics' | 'marketing' | 'preferences' | 'social';
8
+ type ConsentMethod = 'banner' | 'preference_center' | 'api' | 'sdk';
9
+ type BannerPosition = 'bottom' | 'bottom-left' | 'bottom-right' | 'top' | 'center';
10
+ type BannerLayout = 'banner' | 'floating' | 'modal';
11
+ type BannerTheme = 'light' | 'dark' | 'auto';
12
+ interface ConsentState {
13
+ necessary: boolean;
14
+ analytics: boolean;
15
+ marketing: boolean;
16
+ preferences: boolean;
17
+ social: boolean;
18
+ [key: string]: boolean;
19
+ }
20
+ interface MarketingConsentState {
21
+ email?: boolean;
22
+ sms?: boolean;
23
+ whatsapp?: boolean;
24
+ push?: boolean;
25
+ [key: string]: boolean | undefined;
26
+ }
27
+ interface ConsentIQConfig {
28
+ /** Property public key from ConsentIQ dashboard */
29
+ propertyKey: string;
30
+ /** API endpoint URL (defaults to production) */
31
+ apiUrl?: string;
32
+ /** Unique identifier for the user/visitor */
33
+ subjectId?: string;
34
+ /** Auto-generate subjectId if not provided */
35
+ autoGenerateSubjectId?: boolean;
36
+ /** Callback when consent is updated */
37
+ onConsentChange?: (consent: ConsentState, marketing?: MarketingConsentState) => void;
38
+ /** Callback when consent modal opens */
39
+ onOpen?: () => void;
40
+ /** Callback when consent modal closes */
41
+ onClose?: () => void;
42
+ /** Whether to show the banner automatically on load */
43
+ autoShow?: boolean;
44
+ /** Custom language code (overrides auto-detection) */
45
+ language?: string;
46
+ /** Debug mode for development */
47
+ debug?: boolean;
48
+ }
49
+ interface PropertyConfig {
50
+ property: {
51
+ id: string;
52
+ name: string;
53
+ domain: string;
54
+ defaultLanguage: string;
55
+ supportedLanguages: string[];
56
+ };
57
+ banner: {
58
+ position: BannerPosition;
59
+ theme: BannerTheme;
60
+ layout: BannerLayout;
61
+ showLogo: boolean;
62
+ logoUrl?: string;
63
+ primaryColor?: string;
64
+ };
65
+ categories: CategoryInfo[];
66
+ marketingChannels: MarketingChannelInfo[];
67
+ geoRules: GeoRule[];
68
+ translations: Record<string, TranslationSet>;
69
+ }
70
+ interface CategoryInfo {
71
+ code: string;
72
+ enabled: boolean;
73
+ defaultState: boolean;
74
+ name: string;
75
+ description?: string;
76
+ isRequired: boolean;
77
+ }
78
+ interface MarketingChannelInfo {
79
+ code: string;
80
+ name: string;
81
+ description?: string;
82
+ requiresDoubleOptin: boolean;
83
+ }
84
+ interface GeoRule {
85
+ countries: string[];
86
+ regulation: 'DPDPA' | 'GDPR' | 'CCPA' | 'none';
87
+ requireExplicitConsent: boolean;
88
+ }
89
+ interface TranslationSet {
90
+ bannerTitle?: string;
91
+ bannerDescription?: string;
92
+ acceptAllText: string;
93
+ rejectAllText: string;
94
+ customizeText: string;
95
+ savePreferencesText: string;
96
+ categories: Record<string, {
97
+ title: string;
98
+ description: string;
99
+ }>;
100
+ }
101
+ interface SavedConsent {
102
+ id: string;
103
+ cookieConsents: ConsentState;
104
+ marketingConsents?: MarketingConsentState;
105
+ consentedAt: string;
106
+ expiresAt?: string;
107
+ regulationApplied: string;
108
+ consentVersion?: string;
109
+ }
110
+ interface ConsentIQContextValue {
111
+ /** Current consent state */
112
+ consent: ConsentState;
113
+ /** Current marketing consent state */
114
+ marketingConsent: MarketingConsentState;
115
+ /** Property configuration from server */
116
+ config: PropertyConfig | null;
117
+ /** Whether the SDK is still loading */
118
+ isLoading: boolean;
119
+ /** Whether the banner is currently visible */
120
+ isBannerVisible: boolean;
121
+ /** Whether the preference center is visible */
122
+ isPreferenceCenterVisible: boolean;
123
+ /** Current language */
124
+ language: string;
125
+ /** Detected regulation */
126
+ regulation: string | null;
127
+ /** Check if a specific category has consent */
128
+ hasConsent: (category: ConsentCategory | string) => boolean;
129
+ /** Check if a specific marketing channel has consent */
130
+ hasMarketingConsent: (channel: string) => boolean;
131
+ /** Accept all consent categories */
132
+ acceptAll: () => Promise<void>;
133
+ /** Reject all non-essential consent categories */
134
+ rejectAll: () => Promise<void>;
135
+ /** Update specific consent categories */
136
+ updateConsent: (updates: Partial<ConsentState>) => Promise<void>;
137
+ /** Update marketing consent */
138
+ updateMarketingConsent: (updates: Partial<MarketingConsentState>) => Promise<void>;
139
+ /** Show the consent banner */
140
+ showBanner: () => void;
141
+ /** Hide the consent banner */
142
+ hideBanner: () => void;
143
+ /** Show the preference center */
144
+ showPreferenceCenter: () => void;
145
+ /** Hide the preference center */
146
+ hidePreferenceCenter: () => void;
147
+ /** Reset all consent (for debugging) */
148
+ resetConsent: () => void;
149
+ }
150
+
151
+ interface ConsentIQProviderProps extends ConsentIQConfig {
152
+ children: React.ReactNode;
153
+ }
154
+ declare function ConsentIQProvider({ children, propertyKey, apiUrl, subjectId: providedSubjectId, autoGenerateSubjectId, onConsentChange, onOpen, onClose, autoShow, language: preferredLanguage, debug, }: ConsentIQProviderProps): react_jsx_runtime.JSX.Element;
155
+ /**
156
+ * Hook to access ConsentIQ context
157
+ */
158
+ declare function useConsentIQ(): ConsentIQContextValue;
159
+ /**
160
+ * Simplified hook for checking consent status
161
+ */
162
+ declare function useConsent(category: ConsentCategory | string): boolean;
163
+ /**
164
+ * Hook for conditional rendering based on consent
165
+ */
166
+ declare function useConsentGate(category: ConsentCategory | string): {
167
+ hasConsent: boolean;
168
+ isLoading: boolean;
169
+ };
170
+
171
+ interface CookieBannerProps {
172
+ /** Custom class name for the banner container */
173
+ className?: string;
174
+ /** Override banner position */
175
+ position?: 'bottom' | 'bottom-left' | 'bottom-right' | 'top' | 'center';
176
+ /** Override banner theme */
177
+ theme?: 'light' | 'dark' | 'auto';
178
+ /** Custom styles */
179
+ style?: React.CSSProperties;
180
+ }
181
+ declare function CookieBanner({ className, position, theme, style }: CookieBannerProps): react_jsx_runtime.JSX.Element | null;
182
+
183
+ interface PreferenceCenterProps {
184
+ /** Custom class name */
185
+ className?: string;
186
+ /** Override theme */
187
+ theme?: 'light' | 'dark' | 'auto';
188
+ /** Custom styles */
189
+ style?: React.CSSProperties;
190
+ }
191
+ declare function PreferenceCenter({ className, theme, style }: PreferenceCenterProps): react_jsx_runtime.JSX.Element | null;
192
+
193
+ interface ConsentGateProps {
194
+ /** The consent category required to show children */
195
+ category: ConsentCategory | string;
196
+ /** Content to show when consent is granted */
197
+ children: React.ReactNode;
198
+ /** Content to show when consent is not granted (optional) */
199
+ fallback?: React.ReactNode;
200
+ /** Content to show while loading (optional) */
201
+ loading?: React.ReactNode;
202
+ }
203
+ /**
204
+ * ConsentGate - Conditionally render content based on consent status
205
+ *
206
+ * @example
207
+ * ```tsx
208
+ * <ConsentGate category="analytics">
209
+ * <GoogleAnalytics />
210
+ * </ConsentGate>
211
+ *
212
+ * <ConsentGate
213
+ * category="marketing"
214
+ * fallback={<p>Enable marketing cookies for personalized ads</p>}
215
+ * >
216
+ * <FacebookPixel />
217
+ * </ConsentGate>
218
+ * ```
219
+ */
220
+ declare function ConsentGate({ category, children, fallback, loading, }: ConsentGateProps): react_jsx_runtime.JSX.Element;
221
+ /**
222
+ * Higher-order component version of ConsentGate
223
+ *
224
+ * @example
225
+ * ```tsx
226
+ * const ProtectedAnalytics = withConsentGate(GoogleAnalytics, 'analytics');
227
+ * ```
228
+ */
229
+ declare function withConsentGate<P extends object>(Component: React.ComponentType<P>, category: ConsentCategory | string, FallbackComponent?: React.ComponentType<P>): (props: P) => react_jsx_runtime.JSX.Element | null;
230
+
231
+ /**
232
+ * ConsentIQ API Client
233
+ * Handles all communication with the ConsentIQ backend
234
+ */
235
+
236
+ declare class ConsentIQApiClient {
237
+ private apiUrl;
238
+ private propertyKey;
239
+ private debug;
240
+ constructor(propertyKey: string, apiUrl?: string, debug?: boolean);
241
+ private log;
242
+ private fetch;
243
+ /**
244
+ * Fetch property configuration including banner settings and translations
245
+ */
246
+ getConfig(): Promise<PropertyConfig>;
247
+ /**
248
+ * Get existing consent for a subject
249
+ */
250
+ getConsent(subjectId: string): Promise<SavedConsent | null>;
251
+ /**
252
+ * Submit consent to the server
253
+ */
254
+ submitConsent(data: {
255
+ subjectId: string;
256
+ subjectType?: 'visitor' | 'user' | 'subscriber';
257
+ cookieConsents: ConsentState;
258
+ marketingConsents?: MarketingConsentState;
259
+ geoCountry?: string;
260
+ geoRegion?: string;
261
+ geoSource?: 'ip' | 'user_override' | 'browser';
262
+ consentMethod?: 'banner' | 'preference_center' | 'api' | 'sdk';
263
+ consentVersion?: string;
264
+ }): Promise<{
265
+ success: boolean;
266
+ consentId: string;
267
+ proofHash: string;
268
+ }>;
269
+ /**
270
+ * Verify a consent record
271
+ */
272
+ verifyConsent(consentId: string): Promise<{
273
+ verified: boolean;
274
+ consent: {
275
+ id: string;
276
+ consentedAt: string;
277
+ proofHash: string;
278
+ };
279
+ }>;
280
+ }
281
+ /**
282
+ * Generate a unique subject ID for anonymous visitors
283
+ */
284
+ declare function generateSubjectId(): string;
285
+ /**
286
+ * Get or create subject ID from localStorage
287
+ */
288
+ declare function getOrCreateSubjectId(): string;
289
+ /**
290
+ * Detect user's country from browser
291
+ */
292
+ declare function detectCountry(): string | undefined;
293
+ /**
294
+ * Detect user's preferred language
295
+ */
296
+ declare function detectLanguage(supportedLanguages: string[]): string;
297
+
298
+ export { type BannerLayout, type BannerPosition, type BannerTheme, type CategoryInfo, type ConsentCategory, ConsentGate, type ConsentGateProps, ConsentIQApiClient, type ConsentIQConfig, type ConsentIQContextValue, ConsentIQProvider, type ConsentMethod, type ConsentState, CookieBanner, type CookieBannerProps, type GeoRule, type MarketingChannelInfo, type MarketingConsentState, PreferenceCenter, type PreferenceCenterProps, type PropertyConfig, type SavedConsent, type TranslationSet, detectCountry, detectLanguage, generateSubjectId, getOrCreateSubjectId, useConsent, useConsentGate, useConsentIQ, withConsentGate };