@freshjuice/zest 2.0.0 → 2.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/dist/zest.d.ts +247 -0
- package/dist/zest.de.js +107 -3
- package/dist/zest.de.js.map +1 -1
- package/dist/zest.de.min.js +1 -1
- package/dist/zest.en.js +107 -3
- package/dist/zest.en.js.map +1 -1
- package/dist/zest.en.min.js +1 -1
- package/dist/zest.es.js +107 -3
- package/dist/zest.es.js.map +1 -1
- package/dist/zest.es.min.js +1 -1
- package/dist/zest.esm.js +107 -3
- package/dist/zest.esm.js.map +1 -1
- package/dist/zest.esm.min.js +1 -1
- package/dist/zest.fr.js +107 -3
- package/dist/zest.fr.js.map +1 -1
- package/dist/zest.fr.min.js +1 -1
- package/dist/zest.headless.d.ts +211 -0
- package/dist/zest.headless.esm.js +107 -3
- package/dist/zest.headless.esm.js.map +1 -1
- package/dist/zest.headless.esm.min.js +1 -1
- package/dist/zest.it.js +107 -3
- package/dist/zest.it.js.map +1 -1
- package/dist/zest.it.min.js +1 -1
- package/dist/zest.ja.js +107 -3
- package/dist/zest.ja.js.map +1 -1
- package/dist/zest.ja.min.js +1 -1
- package/dist/zest.js +107 -3
- package/dist/zest.js.map +1 -1
- package/dist/zest.min.js +1 -1
- package/dist/zest.nl.js +107 -3
- package/dist/zest.nl.js.map +1 -1
- package/dist/zest.nl.min.js +1 -1
- package/dist/zest.pl.js +107 -3
- package/dist/zest.pl.js.map +1 -1
- package/dist/zest.pl.min.js +1 -1
- package/dist/zest.pt.js +107 -3
- package/dist/zest.pt.js.map +1 -1
- package/dist/zest.pt.min.js +1 -1
- package/dist/zest.ru.js +107 -3
- package/dist/zest.ru.js.map +1 -1
- package/dist/zest.ru.min.js +1 -1
- package/dist/zest.uk.js +107 -3
- package/dist/zest.uk.js.map +1 -1
- package/dist/zest.uk.min.js +1 -1
- package/dist/zest.zh.js +107 -3
- package/dist/zest.zh.js.map +1 -1
- package/dist/zest.zh.min.js +1 -1
- package/package.json +9 -2
- package/src/config/defaults.js +48 -0
- package/src/core/pattern-matcher.js +37 -0
- package/src/core-lifecycle.js +23 -4
- package/src/types/zest.d.ts +247 -0
- package/src/types/zest.headless.d.ts +211 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for `@freshjuice/zest/headless`.
|
|
3
|
+
*
|
|
4
|
+
* The headless build ships the consent engine without any UI: no Shadow
|
|
5
|
+
* DOM, no styles, no DOM mounting. You bring your own banner / modal /
|
|
6
|
+
* settings markup and call into Zest for the consent state.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import Zest from '@freshjuice/zest/headless';
|
|
11
|
+
*
|
|
12
|
+
* Zest.init({ respectDNT: true, expiration: 365 });
|
|
13
|
+
*
|
|
14
|
+
* if (!Zest.hasConsentDecision()) myBanner.show();
|
|
15
|
+
*
|
|
16
|
+
* acceptBtn.addEventListener('click', () => Zest.acceptAll());
|
|
17
|
+
* rejectBtn.addEventListener('click', () => Zest.rejectAll());
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Built-in consent categories. */
|
|
22
|
+
export type ConsentCategory =
|
|
23
|
+
| 'essential'
|
|
24
|
+
| 'functional'
|
|
25
|
+
| 'analytics'
|
|
26
|
+
| 'marketing';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Per-category boolean consent state. `essential` is always `true` —
|
|
30
|
+
* consent for it cannot be revoked because it covers strictly-necessary
|
|
31
|
+
* processing.
|
|
32
|
+
*/
|
|
33
|
+
export type ConsentState =
|
|
34
|
+
& Partial<Record<ConsentCategory, boolean>>
|
|
35
|
+
& { essential: true };
|
|
36
|
+
|
|
37
|
+
/** Snapshot returned by `init()`. */
|
|
38
|
+
export interface InitSnapshot {
|
|
39
|
+
consent: ConsentState;
|
|
40
|
+
hasDecision: boolean;
|
|
41
|
+
dntApplied: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Tamper-evident proof of the user's last consent decision. */
|
|
45
|
+
export interface ConsentProof {
|
|
46
|
+
version: string;
|
|
47
|
+
timestamp: number;
|
|
48
|
+
categories: ConsentState;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Output of `getDNTDetails()`. */
|
|
52
|
+
export interface DNTDetails {
|
|
53
|
+
dnt: boolean;
|
|
54
|
+
gpc: boolean;
|
|
55
|
+
doNotTrack: string | null;
|
|
56
|
+
globalPrivacyControl: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Behaviour when DNT / GPC is detected at init time. */
|
|
60
|
+
export type DNTBehavior = 'reject' | 'preselect' | 'ignore';
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Optional consumer callbacks. Each is wrapped in a try/catch internally
|
|
64
|
+
* so a thrown error never breaks the consent pipeline.
|
|
65
|
+
*/
|
|
66
|
+
export interface ZestCallbacks {
|
|
67
|
+
onAccept?: (consent: ConsentState) => void;
|
|
68
|
+
onReject?: (consent: ConsentState) => void;
|
|
69
|
+
onChange?: (consent: ConsentState) => void;
|
|
70
|
+
onReady?: (consent: ConsentState) => void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Granular toggles for Zest's interceptor layer. Default is `true` on
|
|
75
|
+
* every channel — back-compat with previous versions.
|
|
76
|
+
*
|
|
77
|
+
* Consumers that gate optional scripts and storage themselves (typical
|
|
78
|
+
* for headless integrations) can disable interception per channel and
|
|
79
|
+
* use Zest as a pure consent-state engine.
|
|
80
|
+
*/
|
|
81
|
+
export interface InterceptToggles {
|
|
82
|
+
cookies?: boolean;
|
|
83
|
+
storage?: boolean;
|
|
84
|
+
scripts?: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Configuration accepted by `init()`. */
|
|
88
|
+
export interface InitOptions {
|
|
89
|
+
/** Respect Do Not Track / Global Privacy Control. Default `true`. */
|
|
90
|
+
respectDNT?: boolean;
|
|
91
|
+
/** What to do when DNT/GPC is on. Default `'reject'`. */
|
|
92
|
+
dntBehavior?: DNTBehavior;
|
|
93
|
+
/** Cookie expiration in days. Default `365`. */
|
|
94
|
+
expiration?: number;
|
|
95
|
+
/** Disable individual interceptors. Default: all on. */
|
|
96
|
+
intercept?: InterceptToggles;
|
|
97
|
+
/**
|
|
98
|
+
* Exact storage / cookie names to treat as strictly-necessary. Each
|
|
99
|
+
* is appended to the essential category as a fully-anchored regex,
|
|
100
|
+
* so the built-in essential patterns (zest_*, csrf*, …) stay intact.
|
|
101
|
+
*/
|
|
102
|
+
essentialKeys?: string[];
|
|
103
|
+
/**
|
|
104
|
+
* Regex source strings to treat as strictly-necessary. Validated via
|
|
105
|
+
* safeRegExp, appended (not replaced) to the essential category.
|
|
106
|
+
*/
|
|
107
|
+
essentialPatterns?: string[];
|
|
108
|
+
/**
|
|
109
|
+
* Override patterns per category. Note: this REPLACES the category's
|
|
110
|
+
* built-in patterns. Prefer `essentialKeys` / `essentialPatterns` if
|
|
111
|
+
* you only want to add to the essential category.
|
|
112
|
+
*/
|
|
113
|
+
patterns?: Partial<Record<ConsentCategory, string[]>>;
|
|
114
|
+
/** Consumer callbacks. */
|
|
115
|
+
callbacks?: ZestCallbacks;
|
|
116
|
+
/** Anything else — Zest tolerates unknown keys at runtime. */
|
|
117
|
+
[key: string]: unknown;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Event names emitted on the `window` `document.documentElement`. */
|
|
121
|
+
export interface ZestEvents {
|
|
122
|
+
READY: 'zest:ready';
|
|
123
|
+
CONSENT: 'zest:consent';
|
|
124
|
+
REJECT: 'zest:reject';
|
|
125
|
+
CHANGE: 'zest:change';
|
|
126
|
+
SHOW: 'zest:show';
|
|
127
|
+
HIDE: 'zest:hide';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export type ZestEventName = ZestEvents[keyof ZestEvents];
|
|
131
|
+
|
|
132
|
+
/** Detail payload of the consent-change event. */
|
|
133
|
+
export interface ZestEventDetail {
|
|
134
|
+
consent: ConsentState;
|
|
135
|
+
previous?: ConsentState;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
declare const Zest: {
|
|
139
|
+
/** Initialise the consent engine. Must be called before any other API. */
|
|
140
|
+
init(options?: InitOptions): InitSnapshot;
|
|
141
|
+
|
|
142
|
+
/** Current consent state (clone, safe to mutate). */
|
|
143
|
+
getConsent(): ConsentState;
|
|
144
|
+
|
|
145
|
+
/** Has the user granted consent for `category`? */
|
|
146
|
+
hasConsent(category: ConsentCategory): boolean;
|
|
147
|
+
|
|
148
|
+
/** Has the user made any consent decision yet (accept, reject, or
|
|
149
|
+
* partial)? */
|
|
150
|
+
hasConsentDecision(): boolean;
|
|
151
|
+
|
|
152
|
+
/** Tamper-evident snapshot of the last consent decision. */
|
|
153
|
+
getConsentProof(): ConsentProof | null;
|
|
154
|
+
|
|
155
|
+
/** Grant consent for every category. */
|
|
156
|
+
acceptAll(): ConsentState | null;
|
|
157
|
+
|
|
158
|
+
/** Revoke consent for every non-essential category. */
|
|
159
|
+
rejectAll(): ConsentState | null;
|
|
160
|
+
|
|
161
|
+
/** Set per-category consent. Missing keys are left untouched. */
|
|
162
|
+
updateConsent(
|
|
163
|
+
selections: Partial<Record<ConsentCategory, boolean>>
|
|
164
|
+
): ConsentState | null;
|
|
165
|
+
|
|
166
|
+
/** Wipe all consent state. Useful for "I changed my mind" flows. */
|
|
167
|
+
reset(): void;
|
|
168
|
+
|
|
169
|
+
/** True if the browser is sending DNT or GPC. */
|
|
170
|
+
isDoNotTrackEnabled(): boolean;
|
|
171
|
+
|
|
172
|
+
/** Why `isDoNotTrackEnabled()` returned what it did. */
|
|
173
|
+
getDNTDetails(): DNTDetails;
|
|
174
|
+
|
|
175
|
+
/** Subscribe to a consent event. Returns an unsubscribe function. */
|
|
176
|
+
on(
|
|
177
|
+
eventName: ZestEventName,
|
|
178
|
+
handler: (event: CustomEvent<ZestEventDetail>) => void
|
|
179
|
+
): () => void;
|
|
180
|
+
|
|
181
|
+
/** Subscribe once; auto-unsubscribes after the first call. */
|
|
182
|
+
once(
|
|
183
|
+
eventName: ZestEventName,
|
|
184
|
+
handler: (event: CustomEvent<ZestEventDetail>) => void
|
|
185
|
+
): () => void;
|
|
186
|
+
|
|
187
|
+
/** Constants for `on()` / `once()`. */
|
|
188
|
+
EVENTS: ZestEvents;
|
|
189
|
+
|
|
190
|
+
/** Active configuration after `init()`. */
|
|
191
|
+
getConfig(): InitOptions | null;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export default Zest;
|
|
195
|
+
|
|
196
|
+
// Named tree-shake-friendly exports.
|
|
197
|
+
export const init: typeof Zest.init;
|
|
198
|
+
export const acceptAll: typeof Zest.acceptAll;
|
|
199
|
+
export const rejectAll: typeof Zest.rejectAll;
|
|
200
|
+
export const updateConsent: typeof Zest.updateConsent;
|
|
201
|
+
export const reset: typeof Zest.reset;
|
|
202
|
+
export const getConsent: typeof Zest.getConsent;
|
|
203
|
+
export const hasConsent: typeof Zest.hasConsent;
|
|
204
|
+
export const hasConsentDecision: typeof Zest.hasConsentDecision;
|
|
205
|
+
export const getConsentProof: typeof Zest.getConsentProof;
|
|
206
|
+
export const isDoNotTrackEnabled: typeof Zest.isDoNotTrackEnabled;
|
|
207
|
+
export const getDNTDetails: typeof Zest.getDNTDetails;
|
|
208
|
+
export const on: typeof Zest.on;
|
|
209
|
+
export const once: typeof Zest.once;
|
|
210
|
+
export const EVENTS: ZestEvents;
|
|
211
|
+
export const getConfig: typeof Zest.getConfig;
|