@consenti/ui 0.1.0 → 0.2.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 +325 -117
- package/dist/angular.d.cts +233 -34
- package/dist/angular.d.ts +233 -34
- package/dist/angular.js +1 -73
- package/dist/angular.js.map +1 -1
- package/dist/angular.mjs +1 -52
- package/dist/angular.mjs.map +1 -1
- package/dist/chunk-K2UN3O67.mjs +2 -0
- package/dist/{chunk-ARALKXMB.mjs.map → chunk-K2UN3O67.mjs.map} +1 -1
- package/dist/hmac-UKMRMKN6.mjs +2 -0
- package/dist/{hmac-N6H7F2K2.mjs.map → hmac-UKMRMKN6.mjs.map} +1 -1
- package/dist/http-UU2NIW6M.mjs +2 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +217 -25
- package/dist/index.mjs +1 -2220
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1 -2304
- package/dist/index.umd.js.map +1 -1
- package/dist/react.d.cts +233 -29
- package/dist/react.d.ts +233 -29
- package/dist/react.js +1 -60
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +1 -39
- package/dist/react.mjs.map +1 -1
- package/dist/testing.js +1 -94
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -73
- package/dist/testing.mjs.map +1 -1
- package/dist/vue.d.cts +244 -53
- package/dist/vue.d.ts +244 -53
- package/dist/vue.js +1 -72
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +1 -51
- package/dist/vue.mjs.map +1 -1
- package/package.json +13 -5
- package/dist/chunk-ARALKXMB.mjs +0 -20
- package/dist/hmac-N6H7F2K2.mjs +0 -26
- package/dist/http-VHOGZ6ZJ.mjs +0 -7
- /package/dist/{http-VHOGZ6ZJ.mjs.map → http-UU2NIW6M.mjs.map} +0 -0
package/dist/react.d.cts
CHANGED
|
@@ -1,13 +1,54 @@
|
|
|
1
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
2
|
+
type DeepPartial<T> = T extends Function ? T : T extends Array<infer InferredArrayType> ? Array<DeepPartial<InferredArrayType>> : T extends ReadonlyArray<infer InferredReadonlyArrayType> ? ReadonlyArray<DeepPartial<InferredReadonlyArrayType>> : T extends object ? {
|
|
3
|
+
[Key in keyof T]?: DeepPartial<T[Key]>;
|
|
4
|
+
} : T;
|
|
5
|
+
|
|
6
|
+
declare const COMPLIANCE_GROUP_IDS: readonly ["opt-in", "opt-out", "opt-out-strict", "opt-in-dpdpa", "opt-in-china", "opt-in-brazil", "general-privacy-consent", "notice-only"];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Compliance-related literal types, derived from the regulation/group ID data
|
|
10
|
+
* that lives in @consenti/utils (packages/utils/src/compliance.ts).
|
|
11
|
+
*
|
|
12
|
+
* This import is type-only and fully erased at compile time — @consenti/types
|
|
13
|
+
* has no runtime dependency on @consenti/utils. The actual data (COMPLIANCE_GROUPS,
|
|
14
|
+
* EMBEDDED_COMPLIANCE_MAP, COMPLIANCE_VALIDATION_RULES, GPC_OPTIONS, etc.) lives in
|
|
15
|
+
* @consenti/utils; import it from there.
|
|
16
|
+
*
|
|
17
|
+
* HOW TO ADD A NEW REGULATION OR COMPLIANCE GROUP: see the header comment in
|
|
18
|
+
* packages/utils/src/compliance.ts — these types auto-update from that data.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
type ComplianceGroupId = typeof COMPLIANCE_GROUP_IDS[number];
|
|
22
|
+
|
|
23
|
+
interface ComplianceMapData {
|
|
24
|
+
version: string;
|
|
25
|
+
countries: Record<string, CountryComplianceEntry>;
|
|
26
|
+
}
|
|
27
|
+
interface CountryComplianceEntry {
|
|
28
|
+
complianceGroup: ComplianceGroupId;
|
|
29
|
+
default: ComplianceGroupId;
|
|
30
|
+
description: string;
|
|
31
|
+
overriddenRegions?: Record<string, {
|
|
32
|
+
complianceGroup: ComplianceGroupId;
|
|
33
|
+
description: string;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
|
|
1
37
|
type ConsentStatus = 'granted' | 'denied' | 'objected';
|
|
38
|
+
type ConsentAction = 'accept_all' | 'reject_all' | 'custom' | 'update';
|
|
2
39
|
type ConsentValue = Record<string, ConsentStatus>;
|
|
3
40
|
interface Cookie {
|
|
4
41
|
id: string;
|
|
5
|
-
|
|
42
|
+
legalBasis?: 'mandatory' | 'consent' | 'legitimate_interest';
|
|
43
|
+
/** @deprecated use legalBasis: 'mandatory' */
|
|
6
44
|
mandatory?: boolean;
|
|
45
|
+
/** @deprecated use legalBasis */
|
|
46
|
+
type?: 'consent' | 'legitimate_interest';
|
|
7
47
|
listenGpc?: boolean;
|
|
8
48
|
expiry?: number;
|
|
9
49
|
tcfVendorId?: number;
|
|
10
50
|
tcfPurposes?: number[];
|
|
51
|
+
tcfSpecialFeatures?: number[];
|
|
11
52
|
cpraCategory?: 'sale' | 'sharing' | 'sensitive';
|
|
12
53
|
}
|
|
13
54
|
type ButtonStyle = 'primary' | 'secondary' | 'text' | 'accent';
|
|
@@ -18,6 +59,7 @@ interface Button {
|
|
|
18
59
|
action: ButtonAction;
|
|
19
60
|
cookies?: string[] | '*' | '!';
|
|
20
61
|
url?: string;
|
|
62
|
+
type?: string;
|
|
21
63
|
}
|
|
22
64
|
interface MainBanner {
|
|
23
65
|
position: 'top' | 'bottom' | 'middle' | 'left-bottom' | 'right-bottom';
|
|
@@ -43,18 +85,13 @@ interface Category {
|
|
|
43
85
|
};
|
|
44
86
|
cookies: string[];
|
|
45
87
|
}
|
|
46
|
-
interface PreferenceModal {
|
|
88
|
+
interface PreferenceModal extends Omit<MainBanner, "position"> {
|
|
47
89
|
position?: 'left' | 'right' | 'center';
|
|
48
|
-
overlayOpacity?: number;
|
|
49
|
-
showClose?: boolean;
|
|
50
|
-
showLocaleSwitcher?: boolean;
|
|
51
|
-
heading?: string;
|
|
52
|
-
headingTag?: string;
|
|
53
90
|
subheading?: string;
|
|
54
|
-
htmlText?: string;
|
|
55
|
-
buttons: Button[];
|
|
56
91
|
categories: Category[];
|
|
57
92
|
persistent?: boolean;
|
|
93
|
+
/** Screen width in px below which the modal expands to full screen. Default: 576. Set to 0 to disable. */
|
|
94
|
+
mobileFullScreenBreakpoint?: number;
|
|
58
95
|
}
|
|
59
96
|
interface DpdpaConfig {
|
|
60
97
|
dataFiduciary: string;
|
|
@@ -63,6 +100,7 @@ interface DpdpaConfig {
|
|
|
63
100
|
}
|
|
64
101
|
interface ResolvedProfile {
|
|
65
102
|
id: number;
|
|
103
|
+
profileUuid?: string;
|
|
66
104
|
version: number;
|
|
67
105
|
defaultLocale: string;
|
|
68
106
|
locales?: string[];
|
|
@@ -73,6 +111,26 @@ interface ResolvedProfile {
|
|
|
73
111
|
cookieSigningKey?: string;
|
|
74
112
|
dpdpa?: DpdpaConfig;
|
|
75
113
|
darkMode?: boolean;
|
|
114
|
+
gpcMode?: 'ignore' | 'honor' | 'strict';
|
|
115
|
+
complianceGroup?: string;
|
|
116
|
+
complianceConfig?: Record<string, string>;
|
|
117
|
+
}
|
|
118
|
+
type WidgetCountryResolverFn = () => Promise<{
|
|
119
|
+
country: string | null;
|
|
120
|
+
region: string | null;
|
|
121
|
+
confidence: number;
|
|
122
|
+
}>;
|
|
123
|
+
interface AgeGateWidgetConfig {
|
|
124
|
+
enabled: boolean;
|
|
125
|
+
minimumAge: number;
|
|
126
|
+
requireParentalConsent?: boolean;
|
|
127
|
+
}
|
|
128
|
+
interface ComplianceWidgetConfig {
|
|
129
|
+
type?: 'auto' | ComplianceGroupId | string;
|
|
130
|
+
geoDataProvider?: 'default' | WidgetCountryResolverFn;
|
|
131
|
+
autoComplianceMap?: 'default' | ComplianceMapData | 'auto';
|
|
132
|
+
complianceMapUrl?: string;
|
|
133
|
+
ageGate?: AgeGateWidgetConfig;
|
|
76
134
|
}
|
|
77
135
|
interface GtmConfig {
|
|
78
136
|
containerId?: string;
|
|
@@ -88,6 +146,9 @@ interface ApiConfig {
|
|
|
88
146
|
enabled?: boolean;
|
|
89
147
|
baseUrl?: string;
|
|
90
148
|
authToken?: string;
|
|
149
|
+
tenantId?: string;
|
|
150
|
+
complianceGroup?: string;
|
|
151
|
+
trustDomain?: boolean;
|
|
91
152
|
}
|
|
92
153
|
interface ThemeConfig {
|
|
93
154
|
bgColor?: string;
|
|
@@ -109,35 +170,52 @@ interface ThemeConfig {
|
|
|
109
170
|
accentTextColor?: string;
|
|
110
171
|
}
|
|
111
172
|
interface CoreConfig {
|
|
112
|
-
|
|
173
|
+
tenantId?: string;
|
|
113
174
|
autoHonorGPC?: boolean | 'strict';
|
|
114
175
|
locale?: string;
|
|
115
176
|
disableCssTemplate?: boolean;
|
|
116
|
-
signCookies?: boolean;
|
|
117
177
|
cookieSigningKey?: string;
|
|
118
178
|
allowReceipt?: boolean;
|
|
119
179
|
cookieDomains?: string;
|
|
120
180
|
storage?: 'cookie' | 'localStorage';
|
|
121
181
|
theme?: ThemeConfig;
|
|
122
|
-
privacyPolicyUrl?: string;
|
|
123
|
-
regulation?: 'gdpr' | 'ccpa' | 'cpra' | 'dpdpa' | 'uk-gdpr' | 'lgpd' | 'pipeda' | 'popia' | 'pdpa-th' | 'appi' | 'kvkk';
|
|
124
182
|
userId?: string;
|
|
183
|
+
usePrebuiltProfiles?: 'all' | NonEmptyArray<ComplianceGroupId>;
|
|
184
|
+
cacheResolvedProfiles?: boolean;
|
|
185
|
+
console?: Array<'info' | 'log' | 'warning' | 'error'>;
|
|
125
186
|
}
|
|
126
187
|
interface ConsentiConfig {
|
|
127
188
|
core: CoreConfig;
|
|
189
|
+
compliance?: ComplianceWidgetConfig;
|
|
128
190
|
rootEl?: string | HTMLElement;
|
|
129
191
|
darkMode?: boolean;
|
|
130
192
|
autoInit?: boolean;
|
|
131
193
|
api?: ApiConfig;
|
|
132
194
|
utils?: UtilsConfig;
|
|
133
195
|
plugins?: ConsentiPlugin[];
|
|
134
|
-
profileOverride?:
|
|
196
|
+
profileOverride?: DeepPartial<ResolvedProfile>;
|
|
197
|
+
/** When true, suppresses the "Powered by Consenti" footer link in the banner and modal. */
|
|
198
|
+
hidePoweredBy?: boolean;
|
|
135
199
|
}
|
|
200
|
+
type ConsentiEventName = 'bannerInitialized' | 'consenti:bannerInitialized' | 'bannerVisibility' | 'consenti:bannerVisibility' | 'modalVisibility' | 'consenti:modalVisibility' | 'consentBeingSubmitted' | 'consenti:consentBeingSubmitted' | 'consentSubmitted' | 'consenti:consentSubmitted';
|
|
136
201
|
interface ConsentiWidgetAPI {
|
|
137
202
|
hasConsent(): boolean;
|
|
138
203
|
getConsent(): ConsentValue | null;
|
|
139
204
|
getConsentDate(): Date | false;
|
|
140
205
|
getGTMConsent(): Record<string, string> | null;
|
|
206
|
+
isCookieGranted(cookieId: string, requestValue?: boolean): boolean | ConsentStatus;
|
|
207
|
+
isCategoryGranted(categoryId: string, requestValue?: boolean): boolean | {
|
|
208
|
+
[cookieId: string]: ConsentStatus;
|
|
209
|
+
}[];
|
|
210
|
+
grantAll(onlyMandatory?: boolean): Promise<void>;
|
|
211
|
+
denyAll(includingMandatory?: boolean): Promise<void>;
|
|
212
|
+
on(event: ConsentiEventName, handler: (data: ConsentEvent) => void): void;
|
|
213
|
+
off(event: ConsentiEventName, handler: (data: ConsentEvent) => void): void;
|
|
214
|
+
version(): {
|
|
215
|
+
package: string;
|
|
216
|
+
profileVersion: number | null;
|
|
217
|
+
consentVersion: number;
|
|
218
|
+
};
|
|
141
219
|
bannerVisibility(): 'main' | 'gpc' | false;
|
|
142
220
|
modalVisibility(): 'preference' | false;
|
|
143
221
|
getProfile(): ResolvedProfile | null;
|
|
@@ -152,6 +230,10 @@ interface ConsentiWidgetAPI {
|
|
|
152
230
|
getBannerElement(): HTMLElement | null;
|
|
153
231
|
getModalElement(): HTMLElement | null;
|
|
154
232
|
switchLocale(locale: string): void;
|
|
233
|
+
setDarkMode(enable?: boolean): void;
|
|
234
|
+
setTheme(theme: Partial<ThemeConfig>): void;
|
|
235
|
+
setConfig(config: DeepPartial<ConsentiConfig>): void;
|
|
236
|
+
setProfile(override: DeepPartial<ResolvedProfile>): void;
|
|
155
237
|
init(): Promise<void>;
|
|
156
238
|
onReady(callback: () => void): void;
|
|
157
239
|
destroy(): void;
|
|
@@ -165,6 +247,19 @@ declare abstract class ConsentiPlugin {
|
|
|
165
247
|
onModalShow?(): void | Promise<void>;
|
|
166
248
|
onModalHide?(): void | Promise<void>;
|
|
167
249
|
}
|
|
250
|
+
interface ConsentEvent {
|
|
251
|
+
profileId?: number;
|
|
252
|
+
consent?: ConsentValue;
|
|
253
|
+
hasExistingConsent?: boolean;
|
|
254
|
+
show?: boolean;
|
|
255
|
+
action?: boolean;
|
|
256
|
+
consentAction?: ConsentAction;
|
|
257
|
+
consentId?: string;
|
|
258
|
+
pageUrl?: string;
|
|
259
|
+
apiResponse?: unknown;
|
|
260
|
+
fromBroadcast?: boolean;
|
|
261
|
+
gpcDetected?: boolean;
|
|
262
|
+
}
|
|
168
263
|
|
|
169
264
|
/**
|
|
170
265
|
* Main entry point for the Consenti widget.
|
|
@@ -176,7 +271,7 @@ declare abstract class ConsentiPlugin {
|
|
|
176
271
|
* @example
|
|
177
272
|
* ```ts
|
|
178
273
|
* const widget = new ConsentiSetup({
|
|
179
|
-
*
|
|
274
|
+
* compliance: { type: 'opt-in' },
|
|
180
275
|
* })
|
|
181
276
|
* await widget.ready
|
|
182
277
|
* console.log(widget.hasConsent())
|
|
@@ -188,6 +283,7 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
|
|
|
188
283
|
private initialized;
|
|
189
284
|
private initializing;
|
|
190
285
|
private profile;
|
|
286
|
+
private resolvedBase;
|
|
191
287
|
private consentStore;
|
|
192
288
|
private eventBus;
|
|
193
289
|
private banner;
|
|
@@ -201,6 +297,8 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
|
|
|
201
297
|
private lastSignature;
|
|
202
298
|
/** Tracks which banner variant is currently visible, or null when hidden. */
|
|
203
299
|
private _bannerVariant;
|
|
300
|
+
/** Maps original handler functions to their DOM-wrapped listeners for on/off bookkeeping. */
|
|
301
|
+
private _eventHandlers;
|
|
204
302
|
/**
|
|
205
303
|
* Creates and initialises the consent widget.
|
|
206
304
|
*
|
|
@@ -233,6 +331,8 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
|
|
|
233
331
|
* @param invoke - Function that calls the desired hook method on a single plugin.
|
|
234
332
|
*/
|
|
235
333
|
private callPluginHook;
|
|
334
|
+
private _buildGrantAllConsent;
|
|
335
|
+
private _buildDenyAllConsent;
|
|
236
336
|
private buildHandlers;
|
|
237
337
|
/**
|
|
238
338
|
* Classifies a consent submission as `accept_all`, `reject_all`, `custom`, or `update`.
|
|
@@ -381,6 +481,93 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
|
|
|
381
481
|
* @param locale - BCP 47 locale code to switch to (e.g. `'fr'`, `'de-AT'`).
|
|
382
482
|
*/
|
|
383
483
|
switchLocale(locale: string): void;
|
|
484
|
+
/**
|
|
485
|
+
* Returns `true` if the named cookie's consent is `'granted'`.
|
|
486
|
+
* When `requestValue` is `true`, returns the raw `ConsentStatus` string instead of a boolean,
|
|
487
|
+
* or `false` if the cookie is not in the consent map.
|
|
488
|
+
*/
|
|
489
|
+
isCookieGranted(cookieId: string, requestValue?: boolean): boolean | 'granted' | 'denied' | 'objected';
|
|
490
|
+
/**
|
|
491
|
+
* Checks consent for all cookies belonging to the given category.
|
|
492
|
+
*
|
|
493
|
+
* With `requestValue = false` (default): returns `true` only when every cookie in the
|
|
494
|
+
* category is `'granted'`, `false` otherwise.
|
|
495
|
+
*
|
|
496
|
+
* With `requestValue = true`: returns an array of one-key records — one per cookie in the
|
|
497
|
+
* category — e.g. `[{ analytics: 'granted' }, { pixel: 'denied' }]`.
|
|
498
|
+
*
|
|
499
|
+
* Returns `false` / `[]` if the category is not found or the widget is not yet initialized.
|
|
500
|
+
*/
|
|
501
|
+
isCategoryGranted(categoryId: string, requestValue?: boolean): boolean | {
|
|
502
|
+
[cookieId: string]: 'granted' | 'denied' | 'objected';
|
|
503
|
+
}[];
|
|
504
|
+
/**
|
|
505
|
+
* Programmatically accepts cookies and hides the banner.
|
|
506
|
+
*
|
|
507
|
+
* @param onlyMandatory - When `true`, only mandatory cookies are granted and all others
|
|
508
|
+
* are set to `'denied'`. Defaults to `false` (grant everything).
|
|
509
|
+
*/
|
|
510
|
+
grantAll(onlyMandatory?: boolean): Promise<void>;
|
|
511
|
+
/**
|
|
512
|
+
* Programmatically denies cookies and hides the banner.
|
|
513
|
+
*
|
|
514
|
+
* @param includingMandatory - When `true`, mandatory cookies are also denied. Defaults to
|
|
515
|
+
* `false` (mandatory cookies remain `'granted'`). Passing `true`
|
|
516
|
+
* logs a warning — ensure this is intentional.
|
|
517
|
+
*/
|
|
518
|
+
denyAll(includingMandatory?: boolean): Promise<void>;
|
|
519
|
+
/**
|
|
520
|
+
* Subscribes to a Consenti widget event. The `consenti:` prefix is optional —
|
|
521
|
+
* both `'consentSubmitted'` and `'consenti:consentSubmitted'` are accepted.
|
|
522
|
+
*
|
|
523
|
+
* The same handler reference must be passed to `off()` to unsubscribe.
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```ts
|
|
527
|
+
* const handler = (data) => console.log(data)
|
|
528
|
+
* widget.on('consentSubmitted', handler)
|
|
529
|
+
* // later:
|
|
530
|
+
* widget.off('consentSubmitted', handler)
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
on(event: ConsentiEventName, handler: (data: ConsentEvent) => void): void;
|
|
534
|
+
/**
|
|
535
|
+
* Removes a previously registered event handler. The same function reference passed to
|
|
536
|
+
* `on()` must be used here.
|
|
537
|
+
*/
|
|
538
|
+
off(event: ConsentiEventName, handler: (data: ConsentEvent) => void): void;
|
|
539
|
+
/**
|
|
540
|
+
* Returns the current version of the package and the active profile/consent versions.
|
|
541
|
+
* Useful for debugging and support diagnostics.
|
|
542
|
+
*/
|
|
543
|
+
version(): {
|
|
544
|
+
package: string;
|
|
545
|
+
profileVersion: number | null;
|
|
546
|
+
consentVersion: number;
|
|
547
|
+
};
|
|
548
|
+
/**
|
|
549
|
+
* Toggles or sets dark mode at runtime without re-initialising the widget.
|
|
550
|
+
* When `enable` is omitted, the current dark mode state is toggled.
|
|
551
|
+
*/
|
|
552
|
+
setDarkMode(enable?: boolean): void;
|
|
553
|
+
/**
|
|
554
|
+
* Applies partial theme token overrides at runtime, merging them into the current theme.
|
|
555
|
+
* CSS custom properties on the root element are updated immediately.
|
|
556
|
+
*/
|
|
557
|
+
setTheme(theme: Partial<ThemeConfig>): void;
|
|
558
|
+
/**
|
|
559
|
+
* Deep-merges a partial config into the current widget config.
|
|
560
|
+
* Theme and dark mode side-effects are re-applied immediately.
|
|
561
|
+
* Changes to locale or profile require an explicit `switchLocale()` or `init()` call.
|
|
562
|
+
*/
|
|
563
|
+
setConfig(config: DeepPartial<ConsentiConfig>): void;
|
|
564
|
+
/**
|
|
565
|
+
* Merges a partial profile override into the current profile and re-renders any visible UI.
|
|
566
|
+
* Does not make a network request — the resolved base profile from the last `init()` is reused.
|
|
567
|
+
*
|
|
568
|
+
* No-op before `init()` completes (while `resolvedBase` is null).
|
|
569
|
+
*/
|
|
570
|
+
setProfile(override: DeepPartial<ResolvedProfile>): void;
|
|
384
571
|
/**
|
|
385
572
|
* Destroys the widget — removes all DOM elements, disconnects the BroadcastChannel,
|
|
386
573
|
* and calls `destroy()` on all registered plugins.
|
|
@@ -398,7 +585,7 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
|
|
|
398
585
|
*
|
|
399
586
|
* Intended for **Next.js** (App Router and Pages Router) and any other React 18+
|
|
400
587
|
* project where you manage the `ConsentiSetup` instance yourself and want the
|
|
401
|
-
* `useConsent()` hook to re-render when consent changes.
|
|
588
|
+
* `useConsent()` hook to re-render when consent or UI state changes.
|
|
402
589
|
*
|
|
403
590
|
* @example
|
|
404
591
|
* ```tsx
|
|
@@ -410,7 +597,9 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
|
|
|
410
597
|
*
|
|
411
598
|
* export function ConsentiProvider({ children }: { children: React.ReactNode }) {
|
|
412
599
|
* useEffect(() => {
|
|
413
|
-
* const widget = new ConsentiSetup({
|
|
600
|
+
* const widget = new ConsentiSetup({
|
|
601
|
+
* api: { enabled: true, baseUrl: process.env.NEXT_PUBLIC_API_URL },
|
|
602
|
+
* })
|
|
414
603
|
* setConsentiWidget(widget)
|
|
415
604
|
* }, [])
|
|
416
605
|
* return <>{children}</>
|
|
@@ -419,10 +608,10 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
|
|
|
419
608
|
* // Any component
|
|
420
609
|
* import { useConsent } from '@consenti/ui/react'
|
|
421
610
|
*
|
|
422
|
-
* function
|
|
423
|
-
* const { hasConsent,
|
|
424
|
-
* if (hasConsent
|
|
425
|
-
* return <
|
|
611
|
+
* function CookieStatus() {
|
|
612
|
+
* const { hasConsent, consent, showModal } = useConsent()
|
|
613
|
+
* if (!hasConsent) return <button onClick={showModal}>Manage Cookies</button>
|
|
614
|
+
* return <span>{consent?.analytics === 'granted' ? 'Analytics on' : 'Analytics off'}</span>
|
|
426
615
|
* }
|
|
427
616
|
* ```
|
|
428
617
|
*/
|
|
@@ -435,18 +624,33 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
|
|
|
435
624
|
*/
|
|
436
625
|
declare function setConsentiWidget(widget: ConsentiSetup): void;
|
|
437
626
|
/**
|
|
438
|
-
* React hook that exposes consent state
|
|
627
|
+
* React hook that exposes consent state, banner/modal visibility, and widget actions.
|
|
628
|
+
*
|
|
629
|
+
* Subscribes to `consenti:consentSubmitted`, `consenti:bannerVisibility`, and
|
|
630
|
+
* `consenti:modalVisibility` on `window` and triggers re-renders on each event.
|
|
631
|
+
* Returns SSR-safe initial values during server render.
|
|
439
632
|
*
|
|
440
|
-
*
|
|
441
|
-
* each time consent is updated. Returns SSR-safe fallback values during server render.
|
|
633
|
+
* Destructure only what you need — unused values do not cause extra renders.
|
|
442
634
|
*
|
|
443
|
-
* @returns
|
|
635
|
+
* @returns Consent state values and widget action functions.
|
|
444
636
|
*/
|
|
445
637
|
declare function useConsent(): {
|
|
446
|
-
hasConsent:
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
638
|
+
hasConsent: boolean;
|
|
639
|
+
consent: ConsentValue | null;
|
|
640
|
+
consentDate: Date | false;
|
|
641
|
+
bannerVisible: "main" | "gpc" | false;
|
|
642
|
+
modalVisible: "preference" | false;
|
|
643
|
+
showBanner: (_gpc?: boolean) => void;
|
|
644
|
+
hideBanner: () => void;
|
|
645
|
+
showModal: () => void;
|
|
646
|
+
hideModal: () => void;
|
|
647
|
+
grantAll: (_onlyMandatory?: boolean) => Promise<void>;
|
|
648
|
+
denyAll: (_includingMandatory?: boolean) => Promise<void>;
|
|
649
|
+
submitConsent: (_c: Partial<ConsentValue>) => Promise<void>;
|
|
650
|
+
reConsent: () => Promise<void>;
|
|
651
|
+
isCookieGranted: (_id: string) => boolean;
|
|
652
|
+
isCategoryGranted: (_id: string) => boolean;
|
|
653
|
+
switchLocale: (_locale: string) => void;
|
|
450
654
|
};
|
|
451
655
|
|
|
452
656
|
export { setConsentiWidget, useConsent };
|