@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/angular.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.
|
|
@@ -413,25 +600,26 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
|
|
|
413
600
|
* private widget!: ConsentiSetup
|
|
414
601
|
*
|
|
415
602
|
* ngOnInit() {
|
|
416
|
-
* this.widget = new ConsentiSetup({
|
|
603
|
+
* this.widget = new ConsentiSetup({
|
|
604
|
+
* api: { enabled: true, baseUrl: environment.apiUrl },
|
|
605
|
+
* })
|
|
417
606
|
* setConsentiWidget(this.widget)
|
|
418
607
|
* }
|
|
419
608
|
*
|
|
420
|
-
* ngOnDestroy() {
|
|
421
|
-
* this.widget.destroy()
|
|
422
|
-
* }
|
|
609
|
+
* ngOnDestroy() { this.widget.destroy() }
|
|
423
610
|
* }
|
|
424
611
|
*
|
|
425
612
|
* // any-component.ts
|
|
426
613
|
* import { Component, ChangeDetectorRef, OnInit, OnDestroy } from '@angular/core'
|
|
427
614
|
* import { injectConsent } from '@consenti/ui/angular'
|
|
428
615
|
*
|
|
429
|
-
* @Component({
|
|
430
|
-
*
|
|
431
|
-
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
616
|
+
* @Component({
|
|
617
|
+
* selector: 'app-cookie-status',
|
|
618
|
+
* template: `
|
|
619
|
+
* <p *ngIf="consent.hasConsent()">Consent given on {{ consent.getConsentDate() | date }}</p>
|
|
620
|
+
* <button *ngIf="!consent.hasConsent()" (click)="consent.showModal()">Manage Cookies</button>
|
|
621
|
+
* `,
|
|
622
|
+
* })
|
|
435
623
|
* export class CookieStatusComponent implements OnInit, OnDestroy {
|
|
436
624
|
* consent = injectConsent()
|
|
437
625
|
* private unsub!: () => void
|
|
@@ -442,9 +630,7 @@ declare class ConsentiSetup implements ConsentiWidgetAPI {
|
|
|
442
630
|
* this.unsub = this.consent.onConsentChange(() => this.cdr.markForCheck())
|
|
443
631
|
* }
|
|
444
632
|
*
|
|
445
|
-
* ngOnDestroy() {
|
|
446
|
-
* this.unsub()
|
|
447
|
-
* }
|
|
633
|
+
* ngOnDestroy() { this.unsub() }
|
|
448
634
|
* }
|
|
449
635
|
* ```
|
|
450
636
|
*/
|
|
@@ -461,21 +647,34 @@ declare function setConsentiWidget(widget: ConsentiSetup): void;
|
|
|
461
647
|
* Returns a consent accessor object for use in Angular components and services.
|
|
462
648
|
*
|
|
463
649
|
* Unlike the React and Vue integrations, Angular uses its `ChangeDetectorRef` to
|
|
464
|
-
* trigger UI updates rather than a reactive primitive.
|
|
465
|
-
* `
|
|
466
|
-
*
|
|
650
|
+
* trigger UI updates rather than a reactive primitive. Use the `onConsentChange`,
|
|
651
|
+
* `onBannerChange`, and `onModalChange` helpers in `ngOnInit` to subscribe and
|
|
652
|
+
* call `cdr.markForCheck()` inside the callback.
|
|
467
653
|
*
|
|
468
654
|
* Returns SSR-safe fallback values when `window` is not defined (Angular Universal).
|
|
469
655
|
*
|
|
470
|
-
* @returns An object with
|
|
471
|
-
* and `onConsentChange` (subscription helper).
|
|
656
|
+
* @returns An object with state accessors, widget actions, and change-subscription helpers.
|
|
472
657
|
*/
|
|
473
658
|
declare function injectConsent(): {
|
|
474
659
|
hasConsent: () => boolean;
|
|
475
660
|
getConsent: () => ConsentValue | null;
|
|
476
|
-
submitConsent: (_consent: Partial<ConsentValue>) => Promise<void>;
|
|
477
661
|
getConsentDate: () => Date | false;
|
|
662
|
+
bannerVisibility: () => "main" | "gpc" | false;
|
|
663
|
+
modalVisibility: () => "preference" | false;
|
|
664
|
+
showBanner: (_gpc?: boolean) => void;
|
|
665
|
+
hideBanner: () => void;
|
|
666
|
+
showModal: () => void;
|
|
667
|
+
hideModal: () => void;
|
|
668
|
+
grantAll: (_onlyMandatory?: boolean) => Promise<void>;
|
|
669
|
+
denyAll: (_includingMandatory?: boolean) => Promise<void>;
|
|
670
|
+
submitConsent: (_consent: Partial<ConsentValue>) => Promise<void>;
|
|
671
|
+
reConsent: () => Promise<void>;
|
|
672
|
+
isCookieGranted: (_id: string) => boolean;
|
|
673
|
+
isCategoryGranted: (_id: string) => boolean;
|
|
674
|
+
switchLocale: (_locale: string) => void;
|
|
478
675
|
onConsentChange: (_cb: () => void) => () => void;
|
|
676
|
+
onBannerChange: (_cb: () => void) => () => void;
|
|
677
|
+
onModalChange: (_cb: () => void) => () => void;
|
|
479
678
|
};
|
|
480
679
|
|
|
481
680
|
export { injectConsent, setConsentiWidget };
|