@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 +158 -0
- package/dist/index.d.mts +298 -0
- package/dist/index.d.ts +298 -0
- package/dist/index.js +958 -0
- package/dist/index.mjs +919 -0
- package/package.json +49 -0
package/dist/index.d.ts
ADDED
|
@@ -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 };
|