@luwiostack/cookie-consent 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 +150 -27
- package/dist/index.cjs +106 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -52
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -52
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +76 -76
- package/dist/index.mjs.map +1 -1
- package/dist/machine-names-DAJioLt5.mjs +102 -0
- package/dist/machine-names-DAJioLt5.mjs.map +1 -0
- package/dist/machine-names-DCujHBVM.cjs +137 -0
- package/dist/machine-names-DCujHBVM.cjs.map +1 -0
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.mjs +1 -1
- package/dist/react.mjs.map +1 -1
- package/dist/{types-BrxRJL4I.d.cts → types-ByyibBUg.d.cts} +90 -16
- package/dist/types-ByyibBUg.d.cts.map +1 -0
- package/dist/{types-BrxRJL4I.d.mts → types-ByyibBUg.d.mts} +90 -16
- package/dist/types-ByyibBUg.d.mts.map +1 -0
- package/dist/vendors.cjs +216 -46
- package/dist/vendors.cjs.map +1 -1
- package/dist/vendors.d.cts +20 -12
- package/dist/vendors.d.cts.map +1 -1
- package/dist/vendors.d.mts +20 -12
- package/dist/vendors.d.mts.map +1 -1
- package/dist/vendors.mjs +204 -34
- package/dist/vendors.mjs.map +1 -1
- package/package.json +3 -4
- package/dist/errors-BqpghFQf.cjs +0 -55
- package/dist/errors-BqpghFQf.cjs.map +0 -1
- package/dist/errors-D2ZIcEYK.mjs +0 -32
- package/dist/errors-D2ZIcEYK.mjs.map +0 -1
- package/dist/types-BrxRJL4I.d.cts.map +0 -1
- package/dist/types-BrxRJL4I.d.mts.map +0 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
//#region src/categories.ts
|
|
2
|
+
/**
|
|
3
|
+
* The fixed consent categories, in display order — the same four every consent tool (and Google
|
|
4
|
+
* Consent Mode) works with. `necessary` is always granted. A category's name and description are
|
|
5
|
+
* translated by machine name (`consent_category_<id>`, `consent_category_<id>_description`) from
|
|
6
|
+
* the package catalogs.
|
|
7
|
+
*/
|
|
8
|
+
const CONSENT_CATEGORIES = [
|
|
9
|
+
"necessary",
|
|
10
|
+
"preferences",
|
|
11
|
+
"statistics",
|
|
12
|
+
"marketing"
|
|
13
|
+
];
|
|
14
|
+
/** The category that is always granted and can't be refused. */
|
|
15
|
+
const REQUIRED_CATEGORY = "necessary";
|
|
16
|
+
/** Whether a value is one of the fixed category ids. */
|
|
17
|
+
function isConsentCategoryId(value) {
|
|
18
|
+
return CONSENT_CATEGORIES.includes(value);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/errors.ts
|
|
22
|
+
/** Thrown for an invalid consent configuration or an invalid stored decision. */
|
|
23
|
+
var ConsentError = class extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "ConsentError";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/utils/to-machine-name.ts
|
|
31
|
+
/**
|
|
32
|
+
* Converts a human-readable name to a stable snake_case machine name.
|
|
33
|
+
*
|
|
34
|
+
* - Normalizes Unicode (NFD) and strips diacritics (é → e, ñ → n, …)
|
|
35
|
+
* - Lowercases
|
|
36
|
+
* - Replaces any run of non-alphanumeric characters with a single underscore
|
|
37
|
+
* - Trims leading/trailing underscores
|
|
38
|
+
*/
|
|
39
|
+
function toMachineName(name) {
|
|
40
|
+
return name.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_|_$/g, "");
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/machine-names.ts
|
|
44
|
+
/** @internal A category's name key, e.g. `consent_category_statistics`. */
|
|
45
|
+
const categoryMachineName = (id) => `consent_category_${id}`;
|
|
46
|
+
/** @internal A cookie type's key, e.g. `consent_cookie_type_local_storage`. */
|
|
47
|
+
const cookieTypeMachineName = (type) => `consent_cookie_type_${type}`;
|
|
48
|
+
/** @internal A worded lifetime's key: `consent_max_age_session` / `consent_max_age_persistent`. */
|
|
49
|
+
const maxAgeMachineName = (maxAge) => `consent_max_age_${maxAge}`;
|
|
50
|
+
/** @internal A cookie party's key: `consent_cookie_party_first` / `consent_cookie_party_third`. */
|
|
51
|
+
const partyMachineName = (party) => `consent_cookie_party_${party}`;
|
|
52
|
+
/** @internal A transfer safeguard's key, e.g. `consent_transfer_safeguard_dpf`. */
|
|
53
|
+
const safeguardMachineName = (safeguard) => `consent_transfer_safeguard_${safeguard}`;
|
|
54
|
+
/**
|
|
55
|
+
* @internal A cookie's key: its vendor's machine name plus its name, a `*` read as `wildcard` —
|
|
56
|
+
* `google_analytics` + `_ga_*` → `google_analytics_ga_wildcard`.
|
|
57
|
+
*/
|
|
58
|
+
function cookieMachineName(vendor, cookieName) {
|
|
59
|
+
const name = toMachineName(cookieName.replaceAll("*", " wildcard "));
|
|
60
|
+
return name === "" ? "" : `${vendor}_${name}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* @internal A vendor declaration with its machine names, cookies included. Throws when its id or a
|
|
64
|
+
* cookie name has no letters or digits, or when two cookie names come out the same.
|
|
65
|
+
*/
|
|
66
|
+
function toConsentVendor(declaration) {
|
|
67
|
+
const where = `Vendor "${declaration.id}"`;
|
|
68
|
+
const machine_name = toMachineName(declaration.id);
|
|
69
|
+
if (machine_name === "") throw new ConsentError(`${where}: the id needs letters or digits for its machine name.`);
|
|
70
|
+
const byMachineName = /* @__PURE__ */ new Map();
|
|
71
|
+
const cookies = declaration.cookies.map((cookie) => {
|
|
72
|
+
const key = cookieMachineName(machine_name, cookie.name);
|
|
73
|
+
if (key === "") throw new ConsentError(`${where}: cookie "${cookie.name}" needs letters or digits.`);
|
|
74
|
+
const clash = byMachineName.get(key);
|
|
75
|
+
if (clash !== void 0 && clash !== cookie.name) throw new ConsentError(`${where}: cookies "${clash}" and "${cookie.name}" have the same machine name "${key}".`);
|
|
76
|
+
byMachineName.set(key, cookie.name);
|
|
77
|
+
const party = cookie.domain === void 0 ? "first" : "third";
|
|
78
|
+
return {
|
|
79
|
+
...cookie,
|
|
80
|
+
machine_name: key,
|
|
81
|
+
type_machine_name: cookieTypeMachineName(cookie.type ?? "http"),
|
|
82
|
+
party,
|
|
83
|
+
party_machine_name: partyMachineName(party),
|
|
84
|
+
...typeof cookie.max_age === "string" ? { max_age_machine_name: maxAgeMachineName(cookie.max_age) } : {}
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
const { transfers: declared, ...rest } = declaration;
|
|
88
|
+
const transfers = declared?.map((transfer) => ({
|
|
89
|
+
...transfer,
|
|
90
|
+
safeguard_machine_names: transfer.safeguards.map(safeguardMachineName)
|
|
91
|
+
}));
|
|
92
|
+
return {
|
|
93
|
+
...rest,
|
|
94
|
+
machine_name,
|
|
95
|
+
...transfers !== void 0 ? { transfers } : {},
|
|
96
|
+
cookies
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
Object.defineProperty(exports, "CONSENT_CATEGORIES", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function() {
|
|
103
|
+
return CONSENT_CATEGORIES;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(exports, "ConsentError", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function() {
|
|
109
|
+
return ConsentError;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Object.defineProperty(exports, "REQUIRED_CATEGORY", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function() {
|
|
115
|
+
return REQUIRED_CATEGORY;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
Object.defineProperty(exports, "categoryMachineName", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
get: function() {
|
|
121
|
+
return categoryMachineName;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
Object.defineProperty(exports, "isConsentCategoryId", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function() {
|
|
127
|
+
return isConsentCategoryId;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(exports, "toConsentVendor", {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
get: function() {
|
|
133
|
+
return toConsentVendor;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
//# sourceMappingURL=machine-names-DCujHBVM.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine-names-DCujHBVM.cjs","names":[],"sources":["../src/categories.ts","../src/errors.ts","../src/utils/to-machine-name.ts","../src/machine-names.ts"],"sourcesContent":["/**\n * The fixed consent categories, in display order — the same four every consent tool (and Google\n * Consent Mode) works with. `necessary` is always granted. A category's name and description are\n * translated by machine name (`consent_category_<id>`, `consent_category_<id>_description`) from\n * the package catalogs.\n */\nexport const CONSENT_CATEGORIES = ['necessary', 'preferences', 'statistics', 'marketing'] as const\n\n/** `'necessary' | 'preferences' | 'statistics' | 'marketing'` */\nexport type ConsentCategoryId = (typeof CONSENT_CATEGORIES)[number]\n\n/** The category that is always granted and can't be refused. */\nexport const REQUIRED_CATEGORY = 'necessary' satisfies ConsentCategoryId\n\n/** Whether a value is one of the fixed category ids. */\nexport function isConsentCategoryId(value: unknown): value is ConsentCategoryId {\n return (CONSENT_CATEGORIES as readonly unknown[]).includes(value)\n}\n","/** Thrown for an invalid consent configuration or an invalid stored decision. */\nexport class ConsentError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'ConsentError'\n }\n}\n","/**\n * Converts a human-readable name to a stable snake_case machine name.\n *\n * - Normalizes Unicode (NFD) and strips diacritics (é → e, ñ → n, …)\n * - Lowercases\n * - Replaces any run of non-alphanumeric characters with a single underscore\n * - Trims leading/trailing underscores\n */\nexport function toMachineName(name: string): string {\n return name\n .normalize('NFD')\n .replace(/\\p{M}/gu, '') // strip combining marks (diacritics)\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '_') // non-alphanumeric runs → _\n .replace(/^_|_$/g, '') // trim edges\n}\n","import type { ConsentCategoryId } from './categories'\nimport { ConsentError } from './errors'\nimport type {\n ConsentCookie,\n ConsentCookieParty,\n ConsentCookieType,\n ConsentCookieWordedMaxAge,\n ConsentTransferSafeguard,\n ConsentVendor,\n ConsentVendorDeclaration,\n} from './types'\nimport { toMachineName } from './utils/to-machine-name'\n\n// Every text a cookie list needs has one translation key: a snake_case machine name, like a\n// country's. The categories and the generic words carry a `consent_` prefix, so they can't clash\n// with the app's own keys; a vendor's is its id, a cookie's is its vendor's plus its name.\n\n/** @internal A category's name key, e.g. `consent_category_statistics`. */\nexport const categoryMachineName = (id: ConsentCategoryId) => `consent_category_${id}`\n\n/** @internal A cookie type's key, e.g. `consent_cookie_type_local_storage`. */\nexport const cookieTypeMachineName = (type: ConsentCookieType) => `consent_cookie_type_${type}`\n\n/** @internal A worded lifetime's key: `consent_max_age_session` / `consent_max_age_persistent`. */\nexport const maxAgeMachineName = (maxAge: ConsentCookieWordedMaxAge) => `consent_max_age_${maxAge}`\n\n/** @internal A cookie party's key: `consent_cookie_party_first` / `consent_cookie_party_third`. */\nexport const partyMachineName = (party: ConsentCookieParty) => `consent_cookie_party_${party}`\n\n/** @internal A transfer safeguard's key, e.g. `consent_transfer_safeguard_dpf`. */\nexport const safeguardMachineName = (safeguard: ConsentTransferSafeguard) =>\n `consent_transfer_safeguard_${safeguard}`\n\n/**\n * @internal A cookie's key: its vendor's machine name plus its name, a `*` read as `wildcard` —\n * `google_analytics` + `_ga_*` → `google_analytics_ga_wildcard`.\n */\nexport function cookieMachineName(vendor: string, cookieName: string): string {\n const name = toMachineName(cookieName.replaceAll('*', ' wildcard '))\n return name === '' ? '' : `${vendor}_${name}`\n}\n\n/**\n * @internal A vendor declaration with its machine names, cookies included. Throws when its id or a\n * cookie name has no letters or digits, or when two cookie names come out the same.\n */\nexport function toConsentVendor(declaration: ConsentVendorDeclaration): ConsentVendor {\n const where = `Vendor \"${declaration.id}\"`\n const machine_name = toMachineName(declaration.id)\n if (machine_name === '') {\n throw new ConsentError(`${where}: the id needs letters or digits for its machine name.`)\n }\n const byMachineName = new Map<string, string>()\n const cookies: ConsentCookie[] = declaration.cookies.map((cookie) => {\n const key = cookieMachineName(machine_name, cookie.name)\n if (key === '') {\n throw new ConsentError(`${where}: cookie \"${cookie.name}\" needs letters or digits.`)\n }\n const clash = byMachineName.get(key)\n if (clash !== undefined && clash !== cookie.name) {\n throw new ConsentError(\n `${where}: cookies \"${clash}\" and \"${cookie.name}\" have the same machine name \"${key}\".`,\n )\n }\n byMachineName.set(key, cookie.name)\n const party: ConsentCookieParty = cookie.domain === undefined ? 'first' : 'third'\n return {\n ...cookie,\n machine_name: key,\n type_machine_name: cookieTypeMachineName(cookie.type ?? 'http'),\n party,\n party_machine_name: partyMachineName(party),\n ...(typeof cookie.max_age === 'string'\n ? { max_age_machine_name: maxAgeMachineName(cookie.max_age) }\n : {}),\n }\n })\n const { transfers: declared, ...rest } = declaration\n const transfers = declared?.map((transfer) => ({\n ...transfer,\n safeguard_machine_names: transfer.safeguards.map(safeguardMachineName),\n }))\n return {\n ...rest,\n machine_name,\n ...(transfers !== undefined ? { transfers } : {}),\n cookies,\n }\n}\n"],"mappings":";;;;;;;AAMA,MAAa,qBAAqB;CAAC;CAAa;CAAe;CAAc;AAAW;;AAMxF,MAAa,oBAAoB;;AAGjC,SAAgB,oBAAoB,OAA4C;CAC9E,OAAQ,mBAA0C,SAAS,KAAK;AAClE;;;;AChBA,IAAa,eAAb,cAAkC,MAAM;CACtC,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;;;;;;;;;;;ACEA,SAAgB,cAAc,MAAsB;CAClD,OAAO,KAC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AAO,OAAO,YAAY,WAC1B,EAAE,sBAAsB,kBAAkB,OAAO,OAAO,EAAE,IAC1D,CAAC;EACP;CACF,CAAC;CACD,MAAM,EAAE,WAAW,UAAU,GAAG,SAAS;CACzC,MAAM,YAAY,UAAU,KAAK,cAAc;EAC7C,GAAG;EACH,yBAAyB,SAAS,WAAW,IAAI,oBAAoB;CACvE,EAAE;CACF,OAAO;EACL,GAAG;EACH;EACA,GAAI,cAAc,KAAA,IAAY,EAAE,UAAU,IAAI,CAAC;EAC/C;CACF;AACF"}
|
package/dist/react.cjs
CHANGED
|
@@ -27,7 +27,7 @@ function useConsent() {
|
|
|
27
27
|
setPreferencesOpen(false);
|
|
28
28
|
};
|
|
29
29
|
const usedIn = require_used_vendors.usedVendors(m.categories);
|
|
30
|
-
const isGranted = (id, vendorId) => (vendorId === void 0 || usedIn[id]
|
|
30
|
+
const isGranted = (id, vendorId) => (vendorId === void 0 || usedIn[id]?.has(vendorId) === true) && (m.isRequired(id) || (decision?.isGranted(id) ?? false));
|
|
31
31
|
return {
|
|
32
32
|
consent: m,
|
|
33
33
|
status: snapshot.status,
|
package/dist/react.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.cjs","names":["createContext","useContext","useMemo","usedVendors","useSyncExternalStore","useState","useMemo"],"sources":["../src/react/consent-context.ts","../src/react/use-consent.ts","../src/react/consent-gate.tsx","../src/react/consent-provider.tsx"],"sourcesContent":["import { createContext } from 'react'\nimport type { ConsentManager, ConsentSnapshot } from '../types'\n\nexport interface ConsentContextValue {\n consent: ConsentManager\n snapshot: ConsentSnapshot\n isPreferencesOpen: boolean\n setPreferencesOpen: (open: boolean) => void\n}\n\nexport const ConsentContext = createContext<ConsentContextValue | null>(null)\n","import { useContext, useMemo } from 'react'\nimport type { ConsentCategoryId } from '../categories'\nimport type { ConsentDecision } from '../domain/consent-decision'\nimport type { ConsentCategory, ConsentManager, ConsentStatus } from '../types'\nimport { usedVendors } from '../used-vendors'\nimport { ConsentContext, type ConsentContextValue } from './consent-context'\n\nexport interface UseConsentReturn {\n /** The underlying instance. */\n consent: ConsentManager\n /** `unknown` during SSR/hydration, then `pending` or `decided`. */\n status: ConsentStatus\n /** The valid decision, or `null` while `pending` / `unknown`. */\n decision: ConsentDecision | null\n /** The four categories in order, each with its vendors and their cookies. */\n categories: readonly ConsentCategory[]\n /** Whether the visitor should be asked (status `pending`). `false` while `unknown`. */\n needsDecision: boolean\n /**\n * Reactive: necessary always, others only once decided. With a vendor, also whether it's used in\n * that category — `isGranted('preferences', 'youtube')`.\n */\n isGranted: (category: ConsentCategoryId, vendorId?: string) => boolean\n isRequired: (category: ConsentCategoryId) => boolean\n /** Grant everything (closes the preferences). */\n acceptAll: () => void\n /** Grant only the required categories (closes the preferences). */\n rejectAll: () => void\n /** Grant exactly these (closes the preferences). */\n save: (granted: Iterable<ConsentCategoryId>) => void\n /** Grant these on top of the current decision. */\n grant: (...ids: ConsentCategoryId[]) => void\n /** Withdraw these from the current decision. */\n revoke: (...ids: ConsentCategoryId[]) => void\n /** Forget the decision — the banner shows again. */\n reset: () => void\n /** Whether the preferences are open (shared across the tree). */\n isPreferencesOpen: boolean\n openPreferences: () => void\n closePreferences: () => void\n}\n\n/** @internal Reads the raw context; throws outside `<Consent>`. */\nexport function useConsentContext(): ConsentContextValue {\n const ctx = useContext(ConsentContext)\n if (!ctx) throw new Error('useConsent must be used within <Consent consent={…}>.')\n return ctx\n}\n\n/**\n * The visitor's consent, reactively, plus the actions to change it.\n *\n * @throws {Error} outside `<Consent>`.\n */\nexport function useConsent(): UseConsentReturn {\n const { consent, snapshot, isPreferencesOpen, setPreferencesOpen } = useConsentContext()\n return useMemo(() => {\n const m = consent\n const decision = snapshot.decision\n const closing =\n <A extends unknown[]>(fn: (...args: A) => unknown) =>\n (...args: A) => {\n fn(...args)\n setPreferencesOpen(false)\n }\n const usedIn = usedVendors(m.categories)\n const isGranted = (id: ConsentCategoryId, vendorId?: string) =>\n (vendorId === undefined || usedIn[id].has(vendorId)) &&\n (m.isRequired(id) || (decision?.isGranted(id) ?? false))\n return {\n consent: m,\n status: snapshot.status,\n decision,\n categories: m.categories,\n needsDecision: snapshot.status === 'pending',\n isGranted,\n isRequired: (id) => m.isRequired(id),\n acceptAll: closing(() => m.acceptAll()),\n rejectAll: closing(() => m.rejectAll()),\n save: closing((granted: Iterable<ConsentCategoryId>) => m.save(granted)),\n grant: (...ids) => void m.grant(...ids),\n revoke: (...ids) => void m.revoke(...ids),\n reset: () => m.reset(),\n isPreferencesOpen,\n openPreferences: () => setPreferencesOpen(true),\n closePreferences: () => setPreferencesOpen(false),\n }\n }, [consent, snapshot, isPreferencesOpen, setPreferencesOpen])\n}\n","import type { ReactNode } from 'react'\nimport type { ConsentCategoryId } from '../categories'\nimport { useConsent } from './use-consent'\n\ntype Id = ConsentCategoryId\n\nexport interface ConsentGateApi {\n /** The categories still missing. */\n missing: readonly Id[]\n /** Grant the missing categories right here (\"Load video\" on a placeholder). */\n grant: () => void\n /** Open the preferences instead. */\n openPreferences: () => void\n}\n\nexport interface ConsentGateProps {\n /** The category — or categories, all required — the content needs. */\n category: Id | readonly Id[]\n /**\n * The vendor the content belongs to (`\"youtube\"`). The gate then also needs that vendor to be used\n * in the category — and renders nothing, not even the fallback, when it isn't: that integration\n * is off for this app.\n */\n vendor?: string\n /** Rendered instead while consent is missing. A function gets the gate's api. */\n fallback?: ReactNode | ((api: ConsentGateApi) => ReactNode)\n children?: ReactNode\n}\n\n/**\n * Renders its children only once consent allows them — for embeds and widgets that set cookies or\n * track (a YouTube player, a map, a chat widget). Shows `fallback` otherwise, including on the\n * server and during hydration, so tracking content never renders before consent.\n *\n * ```tsx\n * <ConsentGate\n * category=\"preferences\"\n * vendor=\"youtube\"\n * fallback={(gate) => <button type=\"button\" onClick={gate.grant}>Load video</button>}\n * >\n * <iframe src=\"https://www.youtube-nocookie.com/embed/…\" />\n * </ConsentGate>\n * ```\n */\nexport function ConsentGate({ category, vendor, fallback = null, children }: ConsentGateProps) {\n const consent = useConsent()\n const required = (typeof category === 'string' ? [category] : category) as readonly Id[]\n // A vendor that isn't used in (every one of) these categories: the integration is off.\n const usedIn = (id: Id) =>\n consent.categories.find((c) => c.id === id)?.vendors.some((v) => v.id === vendor)\n if (vendor !== undefined && !required.every(usedIn)) return null\n const missing = required.filter((id) => !consent.isGranted(id))\n\n if (missing.length === 0) return <>{children}</>\n if (typeof fallback !== 'function') return <>{fallback}</>\n return (\n <>\n {fallback({\n missing,\n grant: () => consent.grant(...missing),\n openPreferences: consent.openPreferences,\n })}\n </>\n )\n}\n","import type { ReactNode } from 'react'\nimport { useMemo, useState, useSyncExternalStore } from 'react'\nimport type { ConsentManager, ConsentSnapshot } from '../types'\nimport { ConsentContext, type ConsentContextValue } from './consent-context'\n\n// Storage is out of reach on the server: render as `unknown` (gates closed, no banner) and let the\n// client snapshot take over after hydration — so a visitor who already decided never sees a flash.\nconst SERVER_SNAPSHOT: ConsentSnapshot = Object.freeze({ status: 'unknown', decision: null })\nconst getServerSnapshot = () => SERVER_SNAPSHOT\n\nexport interface ConsentProps {\n /** The instance from `createConsent(config)`. */\n consent: ConsentManager\n children?: ReactNode\n}\n\n/**\n * Supplies a consent instance to the tree and keeps it reactive: every `useConsent()` and\n * `<ConsentGate>` below re-renders when the decision changes — in this tab or another. Also owns\n * whether your app's preferences UI is open, so a \"Cookie settings\" link anywhere (a footer) can\n * reopen it with `openPreferences()`.\n */\nexport function Consent({ consent, children }: ConsentProps) {\n const snapshot = useSyncExternalStore(consent.subscribe, consent.getSnapshot, getServerSnapshot)\n const [isPreferencesOpen, setPreferencesOpen] = useState(false)\n\n const value = useMemo<ConsentContextValue>(\n () => ({ consent, snapshot, isPreferencesOpen, setPreferencesOpen }),\n [consent, snapshot, isPreferencesOpen],\n )\n return <ConsentContext.Provider value={value}>{children}</ConsentContext.Provider>\n}\n"],"mappings":";;;;;AAUA,MAAa,kBAAA,GAAiBA,MAAAA,cAAAA,CAA0C,IAAI;;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["../src/react/consent-context.ts","../src/react/use-consent.ts","../src/react/consent-gate.tsx","../src/react/consent-provider.tsx"],"sourcesContent":["import { createContext } from 'react'\nimport type { ConsentManager, ConsentSnapshot } from '../types'\n\nexport interface ConsentContextValue {\n consent: ConsentManager\n snapshot: ConsentSnapshot\n isPreferencesOpen: boolean\n setPreferencesOpen: (open: boolean) => void\n}\n\nexport const ConsentContext = createContext<ConsentContextValue | null>(null)\n","import { useContext, useMemo } from 'react'\nimport type { ConsentCategoryId } from '../categories'\nimport type { ConsentDecision } from '../domain/consent-decision'\nimport type { ConsentCategory, ConsentManager, ConsentStatus } from '../types'\nimport { usedVendors } from '../used-vendors'\nimport { ConsentContext, type ConsentContextValue } from './consent-context'\n\nexport interface UseConsentReturn {\n /** The underlying instance. */\n consent: ConsentManager\n /** `unknown` during SSR/hydration, then `pending` or `decided`. */\n status: ConsentStatus\n /** The valid decision, or `null` while `pending` / `unknown`. */\n decision: ConsentDecision | null\n /** The four categories in order, each with its vendors and their cookies. */\n categories: readonly ConsentCategory[]\n /** Whether the visitor should be asked (status `pending`). `false` while `unknown`. */\n needsDecision: boolean\n /**\n * Reactive: necessary always, others only once decided. With a vendor, also whether it's used in\n * that category — `isGranted('preferences', 'youtube')`.\n */\n isGranted: (category: ConsentCategoryId, vendorId?: string) => boolean\n isRequired: (category: ConsentCategoryId) => boolean\n /** Grant everything (closes the preferences). */\n acceptAll: () => void\n /** Grant only the required categories (closes the preferences). */\n rejectAll: () => void\n /** Grant exactly these (closes the preferences). */\n save: (granted: Iterable<ConsentCategoryId>) => void\n /** Grant these on top of the current decision. */\n grant: (...ids: ConsentCategoryId[]) => void\n /** Withdraw these from the current decision. */\n revoke: (...ids: ConsentCategoryId[]) => void\n /** Forget the decision — the banner shows again. */\n reset: () => void\n /** Whether the preferences are open (shared across the tree). */\n isPreferencesOpen: boolean\n openPreferences: () => void\n closePreferences: () => void\n}\n\n/** @internal Reads the raw context; throws outside `<Consent>`. */\nexport function useConsentContext(): ConsentContextValue {\n const ctx = useContext(ConsentContext)\n if (!ctx) throw new Error('useConsent must be used within <Consent consent={…}>.')\n return ctx\n}\n\n/**\n * The visitor's consent, reactively, plus the actions to change it.\n *\n * @throws {Error} outside `<Consent>`.\n */\nexport function useConsent(): UseConsentReturn {\n const { consent, snapshot, isPreferencesOpen, setPreferencesOpen } = useConsentContext()\n return useMemo(() => {\n const m = consent\n const decision = snapshot.decision\n const closing =\n <A extends unknown[]>(fn: (...args: A) => unknown) =>\n (...args: A) => {\n fn(...args)\n setPreferencesOpen(false)\n }\n const usedIn = usedVendors(m.categories)\n const isGranted = (id: ConsentCategoryId, vendorId?: string) =>\n (vendorId === undefined || usedIn[id]?.has(vendorId) === true) &&\n (m.isRequired(id) || (decision?.isGranted(id) ?? false))\n return {\n consent: m,\n status: snapshot.status,\n decision,\n categories: m.categories,\n needsDecision: snapshot.status === 'pending',\n isGranted,\n isRequired: (id) => m.isRequired(id),\n acceptAll: closing(() => m.acceptAll()),\n rejectAll: closing(() => m.rejectAll()),\n save: closing((granted: Iterable<ConsentCategoryId>) => m.save(granted)),\n grant: (...ids) => void m.grant(...ids),\n revoke: (...ids) => void m.revoke(...ids),\n reset: () => m.reset(),\n isPreferencesOpen,\n openPreferences: () => setPreferencesOpen(true),\n closePreferences: () => setPreferencesOpen(false),\n }\n }, [consent, snapshot, isPreferencesOpen, setPreferencesOpen])\n}\n","import type { ReactNode } from 'react'\nimport type { ConsentCategoryId } from '../categories'\nimport { useConsent } from './use-consent'\n\ntype Id = ConsentCategoryId\n\nexport interface ConsentGateApi {\n /** The categories still missing. */\n missing: readonly Id[]\n /** Grant the missing categories right here (\"Load video\" on a placeholder). */\n grant: () => void\n /** Open the preferences instead. */\n openPreferences: () => void\n}\n\nexport interface ConsentGateProps {\n /** The category — or categories, all required — the content needs. */\n category: Id | readonly Id[]\n /**\n * The vendor the content belongs to (`\"youtube\"`). The gate then also needs that vendor to be used\n * in the category — and renders nothing, not even the fallback, when it isn't: that integration\n * is off for this app.\n */\n vendor?: string\n /** Rendered instead while consent is missing. A function gets the gate's api. */\n fallback?: ReactNode | ((api: ConsentGateApi) => ReactNode)\n children?: ReactNode\n}\n\n/**\n * Renders its children only once consent allows them — for embeds and widgets that set cookies or\n * track (a YouTube player, a map, a chat widget). Shows `fallback` otherwise, including on the\n * server and during hydration, so tracking content never renders before consent.\n *\n * ```tsx\n * <ConsentGate\n * category=\"preferences\"\n * vendor=\"youtube\"\n * fallback={(gate) => <button type=\"button\" onClick={gate.grant}>Load video</button>}\n * >\n * <iframe src=\"https://www.youtube-nocookie.com/embed/…\" />\n * </ConsentGate>\n * ```\n */\nexport function ConsentGate({ category, vendor, fallback = null, children }: ConsentGateProps) {\n const consent = useConsent()\n const required = (typeof category === 'string' ? [category] : category) as readonly Id[]\n // A vendor that isn't used in (every one of) these categories: the integration is off.\n const usedIn = (id: Id) =>\n consent.categories.find((c) => c.id === id)?.vendors.some((v) => v.id === vendor)\n if (vendor !== undefined && !required.every(usedIn)) return null\n const missing = required.filter((id) => !consent.isGranted(id))\n\n if (missing.length === 0) return <>{children}</>\n if (typeof fallback !== 'function') return <>{fallback}</>\n return (\n <>\n {fallback({\n missing,\n grant: () => consent.grant(...missing),\n openPreferences: consent.openPreferences,\n })}\n </>\n )\n}\n","import type { ReactNode } from 'react'\nimport { useMemo, useState, useSyncExternalStore } from 'react'\nimport type { ConsentManager, ConsentSnapshot } from '../types'\nimport { ConsentContext, type ConsentContextValue } from './consent-context'\n\n// Storage is out of reach on the server: render as `unknown` (gates closed, no banner) and let the\n// client snapshot take over after hydration — so a visitor who already decided never sees a flash.\nconst SERVER_SNAPSHOT: ConsentSnapshot = Object.freeze({ status: 'unknown', decision: null })\nconst getServerSnapshot = () => SERVER_SNAPSHOT\n\nexport interface ConsentProps {\n /** The instance from `createConsent(config)`. */\n consent: ConsentManager\n children?: ReactNode\n}\n\n/**\n * Supplies a consent instance to the tree and keeps it reactive: every `useConsent()` and\n * `<ConsentGate>` below re-renders when the decision changes — in this tab or another. Also owns\n * whether your app's preferences UI is open, so a \"Cookie settings\" link anywhere (a footer) can\n * reopen it with `openPreferences()`.\n */\nexport function Consent({ consent, children }: ConsentProps) {\n const snapshot = useSyncExternalStore(consent.subscribe, consent.getSnapshot, getServerSnapshot)\n const [isPreferencesOpen, setPreferencesOpen] = useState(false)\n\n const value = useMemo<ConsentContextValue>(\n () => ({ consent, snapshot, isPreferencesOpen, setPreferencesOpen }),\n [consent, snapshot, isPreferencesOpen],\n )\n return <ConsentContext.Provider value={value}>{children}</ConsentContext.Provider>\n}\n"],"mappings":";;;;;AAUA,MAAa,kBAAA,GAAiBA,MAAAA,cAAAA,CAA0C,IAAI;;;;ACiC5E,SAAgB,oBAAyC;CACvD,MAAM,OAAA,GAAMC,MAAAA,WAAAA,CAAW,cAAc;CACrC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,uDAAuD;CACjF,OAAO;AACT;;;;;;AAOA,SAAgB,aAA+B;CAC7C,MAAM,EAAE,SAAS,UAAU,mBAAmB,uBAAuB,kBAAkB;CACvF,QAAA,GAAOC,MAAAA,QAAAA,OAAc;EACnB,MAAM,IAAI;EACV,MAAM,WAAW,SAAS;EAC1B,MAAM,WACkB,QACrB,GAAG,SAAY;GACd,GAAG,GAAG,IAAI;GACV,mBAAmB,KAAK;EAC1B;EACF,MAAM,SAASC,qBAAAA,YAAY,EAAE,UAAU;EACvC,MAAM,aAAa,IAAuB,cACvC,aAAa,KAAA,KAAa,OAAO,GAAG,EAAE,IAAI,QAAQ,MAAM,UACxD,EAAE,WAAW,EAAE,MAAM,UAAU,UAAU,EAAE,KAAK;EACnD,OAAO;GACL,SAAS;GACT,QAAQ,SAAS;GACjB;GACA,YAAY,EAAE;GACd,eAAe,SAAS,WAAW;GACnC;GACA,aAAa,OAAO,EAAE,WAAW,EAAE;GACnC,WAAW,cAAc,EAAE,UAAU,CAAC;GACtC,WAAW,cAAc,EAAE,UAAU,CAAC;GACtC,MAAM,SAAS,YAAyC,EAAE,KAAK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,MAAAA,qBAAAA,CAAqB,QAAQ,WAAW,QAAQ,aAAa,iBAAiB;CAC/F,MAAM,CAAC,mBAAmB,uBAAA,GAAsBC,MAAAA,SAAAA,CAAS,KAAK;CAE9D,MAAM,SAAA,GAAQC,MAAAA,QAAAA,QACL;EAAE;EAAS;EAAU;EAAmB;CAAmB,IAClE;EAAC;EAAS;EAAU;CAAiB,CACvC;CACA,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,eAAe,UAAhB;EAAgC;EAAQ;CAAkC,CAAA;AACnF"}
|
package/dist/react.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as ConsentCategoryId, d as ConsentSnapshot, f as ConsentStatus, n as ConsentCategory, u as ConsentManager, y as ConsentDecision } from "./types-ByyibBUg.cjs";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
//#region src/react/consent-context.d.ts
|
|
4
4
|
interface ConsentContextValue {
|
package/dist/react.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as ConsentCategoryId, d as ConsentSnapshot, f as ConsentStatus, n as ConsentCategory, u as ConsentManager, y as ConsentDecision } from "./types-ByyibBUg.mjs";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
//#region src/react/consent-context.d.ts
|
|
4
4
|
interface ConsentContextValue {
|
package/dist/react.mjs
CHANGED
|
@@ -26,7 +26,7 @@ function useConsent() {
|
|
|
26
26
|
setPreferencesOpen(false);
|
|
27
27
|
};
|
|
28
28
|
const usedIn = usedVendors(m.categories);
|
|
29
|
-
const isGranted = (id, vendorId) => (vendorId === void 0 || usedIn[id]
|
|
29
|
+
const isGranted = (id, vendorId) => (vendorId === void 0 || usedIn[id]?.has(vendorId) === true) && (m.isRequired(id) || (decision?.isGranted(id) ?? false));
|
|
30
30
|
return {
|
|
31
31
|
consent: m,
|
|
32
32
|
status: snapshot.status,
|
package/dist/react.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.mjs","names":[],"sources":["../src/react/consent-context.ts","../src/react/use-consent.ts","../src/react/consent-gate.tsx","../src/react/consent-provider.tsx"],"sourcesContent":["import { createContext } from 'react'\nimport type { ConsentManager, ConsentSnapshot } from '../types'\n\nexport interface ConsentContextValue {\n consent: ConsentManager\n snapshot: ConsentSnapshot\n isPreferencesOpen: boolean\n setPreferencesOpen: (open: boolean) => void\n}\n\nexport const ConsentContext = createContext<ConsentContextValue | null>(null)\n","import { useContext, useMemo } from 'react'\nimport type { ConsentCategoryId } from '../categories'\nimport type { ConsentDecision } from '../domain/consent-decision'\nimport type { ConsentCategory, ConsentManager, ConsentStatus } from '../types'\nimport { usedVendors } from '../used-vendors'\nimport { ConsentContext, type ConsentContextValue } from './consent-context'\n\nexport interface UseConsentReturn {\n /** The underlying instance. */\n consent: ConsentManager\n /** `unknown` during SSR/hydration, then `pending` or `decided`. */\n status: ConsentStatus\n /** The valid decision, or `null` while `pending` / `unknown`. */\n decision: ConsentDecision | null\n /** The four categories in order, each with its vendors and their cookies. */\n categories: readonly ConsentCategory[]\n /** Whether the visitor should be asked (status `pending`). `false` while `unknown`. */\n needsDecision: boolean\n /**\n * Reactive: necessary always, others only once decided. With a vendor, also whether it's used in\n * that category — `isGranted('preferences', 'youtube')`.\n */\n isGranted: (category: ConsentCategoryId, vendorId?: string) => boolean\n isRequired: (category: ConsentCategoryId) => boolean\n /** Grant everything (closes the preferences). */\n acceptAll: () => void\n /** Grant only the required categories (closes the preferences). */\n rejectAll: () => void\n /** Grant exactly these (closes the preferences). */\n save: (granted: Iterable<ConsentCategoryId>) => void\n /** Grant these on top of the current decision. */\n grant: (...ids: ConsentCategoryId[]) => void\n /** Withdraw these from the current decision. */\n revoke: (...ids: ConsentCategoryId[]) => void\n /** Forget the decision — the banner shows again. */\n reset: () => void\n /** Whether the preferences are open (shared across the tree). */\n isPreferencesOpen: boolean\n openPreferences: () => void\n closePreferences: () => void\n}\n\n/** @internal Reads the raw context; throws outside `<Consent>`. */\nexport function useConsentContext(): ConsentContextValue {\n const ctx = useContext(ConsentContext)\n if (!ctx) throw new Error('useConsent must be used within <Consent consent={…}>.')\n return ctx\n}\n\n/**\n * The visitor's consent, reactively, plus the actions to change it.\n *\n * @throws {Error} outside `<Consent>`.\n */\nexport function useConsent(): UseConsentReturn {\n const { consent, snapshot, isPreferencesOpen, setPreferencesOpen } = useConsentContext()\n return useMemo(() => {\n const m = consent\n const decision = snapshot.decision\n const closing =\n <A extends unknown[]>(fn: (...args: A) => unknown) =>\n (...args: A) => {\n fn(...args)\n setPreferencesOpen(false)\n }\n const usedIn = usedVendors(m.categories)\n const isGranted = (id: ConsentCategoryId, vendorId?: string) =>\n (vendorId === undefined || usedIn[id].has(vendorId)) &&\n (m.isRequired(id) || (decision?.isGranted(id) ?? false))\n return {\n consent: m,\n status: snapshot.status,\n decision,\n categories: m.categories,\n needsDecision: snapshot.status === 'pending',\n isGranted,\n isRequired: (id) => m.isRequired(id),\n acceptAll: closing(() => m.acceptAll()),\n rejectAll: closing(() => m.rejectAll()),\n save: closing((granted: Iterable<ConsentCategoryId>) => m.save(granted)),\n grant: (...ids) => void m.grant(...ids),\n revoke: (...ids) => void m.revoke(...ids),\n reset: () => m.reset(),\n isPreferencesOpen,\n openPreferences: () => setPreferencesOpen(true),\n closePreferences: () => setPreferencesOpen(false),\n }\n }, [consent, snapshot, isPreferencesOpen, setPreferencesOpen])\n}\n","import type { ReactNode } from 'react'\nimport type { ConsentCategoryId } from '../categories'\nimport { useConsent } from './use-consent'\n\ntype Id = ConsentCategoryId\n\nexport interface ConsentGateApi {\n /** The categories still missing. */\n missing: readonly Id[]\n /** Grant the missing categories right here (\"Load video\" on a placeholder). */\n grant: () => void\n /** Open the preferences instead. */\n openPreferences: () => void\n}\n\nexport interface ConsentGateProps {\n /** The category — or categories, all required — the content needs. */\n category: Id | readonly Id[]\n /**\n * The vendor the content belongs to (`\"youtube\"`). The gate then also needs that vendor to be used\n * in the category — and renders nothing, not even the fallback, when it isn't: that integration\n * is off for this app.\n */\n vendor?: string\n /** Rendered instead while consent is missing. A function gets the gate's api. */\n fallback?: ReactNode | ((api: ConsentGateApi) => ReactNode)\n children?: ReactNode\n}\n\n/**\n * Renders its children only once consent allows them — for embeds and widgets that set cookies or\n * track (a YouTube player, a map, a chat widget). Shows `fallback` otherwise, including on the\n * server and during hydration, so tracking content never renders before consent.\n *\n * ```tsx\n * <ConsentGate\n * category=\"preferences\"\n * vendor=\"youtube\"\n * fallback={(gate) => <button type=\"button\" onClick={gate.grant}>Load video</button>}\n * >\n * <iframe src=\"https://www.youtube-nocookie.com/embed/…\" />\n * </ConsentGate>\n * ```\n */\nexport function ConsentGate({ category, vendor, fallback = null, children }: ConsentGateProps) {\n const consent = useConsent()\n const required = (typeof category === 'string' ? [category] : category) as readonly Id[]\n // A vendor that isn't used in (every one of) these categories: the integration is off.\n const usedIn = (id: Id) =>\n consent.categories.find((c) => c.id === id)?.vendors.some((v) => v.id === vendor)\n if (vendor !== undefined && !required.every(usedIn)) return null\n const missing = required.filter((id) => !consent.isGranted(id))\n\n if (missing.length === 0) return <>{children}</>\n if (typeof fallback !== 'function') return <>{fallback}</>\n return (\n <>\n {fallback({\n missing,\n grant: () => consent.grant(...missing),\n openPreferences: consent.openPreferences,\n })}\n </>\n )\n}\n","import type { ReactNode } from 'react'\nimport { useMemo, useState, useSyncExternalStore } from 'react'\nimport type { ConsentManager, ConsentSnapshot } from '../types'\nimport { ConsentContext, type ConsentContextValue } from './consent-context'\n\n// Storage is out of reach on the server: render as `unknown` (gates closed, no banner) and let the\n// client snapshot take over after hydration — so a visitor who already decided never sees a flash.\nconst SERVER_SNAPSHOT: ConsentSnapshot = Object.freeze({ status: 'unknown', decision: null })\nconst getServerSnapshot = () => SERVER_SNAPSHOT\n\nexport interface ConsentProps {\n /** The instance from `createConsent(config)`. */\n consent: ConsentManager\n children?: ReactNode\n}\n\n/**\n * Supplies a consent instance to the tree and keeps it reactive: every `useConsent()` and\n * `<ConsentGate>` below re-renders when the decision changes — in this tab or another. Also owns\n * whether your app's preferences UI is open, so a \"Cookie settings\" link anywhere (a footer) can\n * reopen it with `openPreferences()`.\n */\nexport function Consent({ consent, children }: ConsentProps) {\n const snapshot = useSyncExternalStore(consent.subscribe, consent.getSnapshot, getServerSnapshot)\n const [isPreferencesOpen, setPreferencesOpen] = useState(false)\n\n const value = useMemo<ConsentContextValue>(\n () => ({ consent, snapshot, isPreferencesOpen, setPreferencesOpen }),\n [consent, snapshot, isPreferencesOpen],\n )\n return <ConsentContext.Provider value={value}>{children}</ConsentContext.Provider>\n}\n"],"mappings":";;;;AAUA,MAAa,iBAAiB,cAA0C,IAAI;;;;ACiC5E,SAAgB,oBAAyC;CACvD,MAAM,MAAM,WAAW,cAAc;CACrC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,uDAAuD;CACjF,OAAO;AACT;;;;;;AAOA,SAAgB,aAA+B;CAC7C,MAAM,EAAE,SAAS,UAAU,mBAAmB,uBAAuB,kBAAkB;CACvF,OAAO,cAAc;EACnB,MAAM,IAAI;EACV,MAAM,WAAW,SAAS;EAC1B,MAAM,WACkB,QACrB,GAAG,SAAY;GACd,GAAG,GAAG,IAAI;GACV,mBAAmB,KAAK;EAC1B;EACF,MAAM,SAAS,YAAY,EAAE,UAAU;EACvC,MAAM,aAAa,IAAuB,cACvC,aAAa,KAAA,KAAa,OAAO,GAAG,CAAC,IAAI,QAAQ,OACjD,EAAE,WAAW,EAAE,MAAM,UAAU,UAAU,EAAE,KAAK;EACnD,OAAO;GACL,SAAS;GACT,QAAQ,SAAS;GACjB;GACA,YAAY,EAAE;GACd,eAAe,SAAS,WAAW;GACnC;GACA,aAAa,OAAO,EAAE,WAAW,EAAE;GACnC,WAAW,cAAc,EAAE,UAAU,CAAC;GACtC,WAAW,cAAc,EAAE,UAAU,CAAC;GACtC,MAAM,SAAS,YAAyC,EAAE,KAAK,OAAO,CAAC;GACvE,QAAQ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;EAAU;EAAmB;CAAmB,IAClE;EAAC;EAAS;EAAU;CAAiB,CACvC;CACA,OAAO,oBAAC,eAAe,UAAhB;EAAgC;EAAQ;CAAkC,CAAA;AACnF"}
|
|
1
|
+
{"version":3,"file":"react.mjs","names":[],"sources":["../src/react/consent-context.ts","../src/react/use-consent.ts","../src/react/consent-gate.tsx","../src/react/consent-provider.tsx"],"sourcesContent":["import { createContext } from 'react'\nimport type { ConsentManager, ConsentSnapshot } from '../types'\n\nexport interface ConsentContextValue {\n consent: ConsentManager\n snapshot: ConsentSnapshot\n isPreferencesOpen: boolean\n setPreferencesOpen: (open: boolean) => void\n}\n\nexport const ConsentContext = createContext<ConsentContextValue | null>(null)\n","import { useContext, useMemo } from 'react'\nimport type { ConsentCategoryId } from '../categories'\nimport type { ConsentDecision } from '../domain/consent-decision'\nimport type { ConsentCategory, ConsentManager, ConsentStatus } from '../types'\nimport { usedVendors } from '../used-vendors'\nimport { ConsentContext, type ConsentContextValue } from './consent-context'\n\nexport interface UseConsentReturn {\n /** The underlying instance. */\n consent: ConsentManager\n /** `unknown` during SSR/hydration, then `pending` or `decided`. */\n status: ConsentStatus\n /** The valid decision, or `null` while `pending` / `unknown`. */\n decision: ConsentDecision | null\n /** The four categories in order, each with its vendors and their cookies. */\n categories: readonly ConsentCategory[]\n /** Whether the visitor should be asked (status `pending`). `false` while `unknown`. */\n needsDecision: boolean\n /**\n * Reactive: necessary always, others only once decided. With a vendor, also whether it's used in\n * that category — `isGranted('preferences', 'youtube')`.\n */\n isGranted: (category: ConsentCategoryId, vendorId?: string) => boolean\n isRequired: (category: ConsentCategoryId) => boolean\n /** Grant everything (closes the preferences). */\n acceptAll: () => void\n /** Grant only the required categories (closes the preferences). */\n rejectAll: () => void\n /** Grant exactly these (closes the preferences). */\n save: (granted: Iterable<ConsentCategoryId>) => void\n /** Grant these on top of the current decision. */\n grant: (...ids: ConsentCategoryId[]) => void\n /** Withdraw these from the current decision. */\n revoke: (...ids: ConsentCategoryId[]) => void\n /** Forget the decision — the banner shows again. */\n reset: () => void\n /** Whether the preferences are open (shared across the tree). */\n isPreferencesOpen: boolean\n openPreferences: () => void\n closePreferences: () => void\n}\n\n/** @internal Reads the raw context; throws outside `<Consent>`. */\nexport function useConsentContext(): ConsentContextValue {\n const ctx = useContext(ConsentContext)\n if (!ctx) throw new Error('useConsent must be used within <Consent consent={…}>.')\n return ctx\n}\n\n/**\n * The visitor's consent, reactively, plus the actions to change it.\n *\n * @throws {Error} outside `<Consent>`.\n */\nexport function useConsent(): UseConsentReturn {\n const { consent, snapshot, isPreferencesOpen, setPreferencesOpen } = useConsentContext()\n return useMemo(() => {\n const m = consent\n const decision = snapshot.decision\n const closing =\n <A extends unknown[]>(fn: (...args: A) => unknown) =>\n (...args: A) => {\n fn(...args)\n setPreferencesOpen(false)\n }\n const usedIn = usedVendors(m.categories)\n const isGranted = (id: ConsentCategoryId, vendorId?: string) =>\n (vendorId === undefined || usedIn[id]?.has(vendorId) === true) &&\n (m.isRequired(id) || (decision?.isGranted(id) ?? false))\n return {\n consent: m,\n status: snapshot.status,\n decision,\n categories: m.categories,\n needsDecision: snapshot.status === 'pending',\n isGranted,\n isRequired: (id) => m.isRequired(id),\n acceptAll: closing(() => m.acceptAll()),\n rejectAll: closing(() => m.rejectAll()),\n save: closing((granted: Iterable<ConsentCategoryId>) => m.save(granted)),\n grant: (...ids) => void m.grant(...ids),\n revoke: (...ids) => void m.revoke(...ids),\n reset: () => m.reset(),\n isPreferencesOpen,\n openPreferences: () => setPreferencesOpen(true),\n closePreferences: () => setPreferencesOpen(false),\n }\n }, [consent, snapshot, isPreferencesOpen, setPreferencesOpen])\n}\n","import type { ReactNode } from 'react'\nimport type { ConsentCategoryId } from '../categories'\nimport { useConsent } from './use-consent'\n\ntype Id = ConsentCategoryId\n\nexport interface ConsentGateApi {\n /** The categories still missing. */\n missing: readonly Id[]\n /** Grant the missing categories right here (\"Load video\" on a placeholder). */\n grant: () => void\n /** Open the preferences instead. */\n openPreferences: () => void\n}\n\nexport interface ConsentGateProps {\n /** The category — or categories, all required — the content needs. */\n category: Id | readonly Id[]\n /**\n * The vendor the content belongs to (`\"youtube\"`). The gate then also needs that vendor to be used\n * in the category — and renders nothing, not even the fallback, when it isn't: that integration\n * is off for this app.\n */\n vendor?: string\n /** Rendered instead while consent is missing. A function gets the gate's api. */\n fallback?: ReactNode | ((api: ConsentGateApi) => ReactNode)\n children?: ReactNode\n}\n\n/**\n * Renders its children only once consent allows them — for embeds and widgets that set cookies or\n * track (a YouTube player, a map, a chat widget). Shows `fallback` otherwise, including on the\n * server and during hydration, so tracking content never renders before consent.\n *\n * ```tsx\n * <ConsentGate\n * category=\"preferences\"\n * vendor=\"youtube\"\n * fallback={(gate) => <button type=\"button\" onClick={gate.grant}>Load video</button>}\n * >\n * <iframe src=\"https://www.youtube-nocookie.com/embed/…\" />\n * </ConsentGate>\n * ```\n */\nexport function ConsentGate({ category, vendor, fallback = null, children }: ConsentGateProps) {\n const consent = useConsent()\n const required = (typeof category === 'string' ? [category] : category) as readonly Id[]\n // A vendor that isn't used in (every one of) these categories: the integration is off.\n const usedIn = (id: Id) =>\n consent.categories.find((c) => c.id === id)?.vendors.some((v) => v.id === vendor)\n if (vendor !== undefined && !required.every(usedIn)) return null\n const missing = required.filter((id) => !consent.isGranted(id))\n\n if (missing.length === 0) return <>{children}</>\n if (typeof fallback !== 'function') return <>{fallback}</>\n return (\n <>\n {fallback({\n missing,\n grant: () => consent.grant(...missing),\n openPreferences: consent.openPreferences,\n })}\n </>\n )\n}\n","import type { ReactNode } from 'react'\nimport { useMemo, useState, useSyncExternalStore } from 'react'\nimport type { ConsentManager, ConsentSnapshot } from '../types'\nimport { ConsentContext, type ConsentContextValue } from './consent-context'\n\n// Storage is out of reach on the server: render as `unknown` (gates closed, no banner) and let the\n// client snapshot take over after hydration — so a visitor who already decided never sees a flash.\nconst SERVER_SNAPSHOT: ConsentSnapshot = Object.freeze({ status: 'unknown', decision: null })\nconst getServerSnapshot = () => SERVER_SNAPSHOT\n\nexport interface ConsentProps {\n /** The instance from `createConsent(config)`. */\n consent: ConsentManager\n children?: ReactNode\n}\n\n/**\n * Supplies a consent instance to the tree and keeps it reactive: every `useConsent()` and\n * `<ConsentGate>` below re-renders when the decision changes — in this tab or another. Also owns\n * whether your app's preferences UI is open, so a \"Cookie settings\" link anywhere (a footer) can\n * reopen it with `openPreferences()`.\n */\nexport function Consent({ consent, children }: ConsentProps) {\n const snapshot = useSyncExternalStore(consent.subscribe, consent.getSnapshot, getServerSnapshot)\n const [isPreferencesOpen, setPreferencesOpen] = useState(false)\n\n const value = useMemo<ConsentContextValue>(\n () => ({ consent, snapshot, isPreferencesOpen, setPreferencesOpen }),\n [consent, snapshot, isPreferencesOpen],\n )\n return <ConsentContext.Provider value={value}>{children}</ConsentContext.Provider>\n}\n"],"mappings":";;;;AAUA,MAAa,iBAAiB,cAA0C,IAAI;;;;ACiC5E,SAAgB,oBAAyC;CACvD,MAAM,MAAM,WAAW,cAAc;CACrC,IAAI,CAAC,KAAK,MAAM,IAAI,MAAM,uDAAuD;CACjF,OAAO;AACT;;;;;;AAOA,SAAgB,aAA+B;CAC7C,MAAM,EAAE,SAAS,UAAU,mBAAmB,uBAAuB,kBAAkB;CACvF,OAAO,cAAc;EACnB,MAAM,IAAI;EACV,MAAM,WAAW,SAAS;EAC1B,MAAM,WACkB,QACrB,GAAG,SAAY;GACd,GAAG,GAAG,IAAI;GACV,mBAAmB,KAAK;EAC1B;EACF,MAAM,SAAS,YAAY,EAAE,UAAU;EACvC,MAAM,aAAa,IAAuB,cACvC,aAAa,KAAA,KAAa,OAAO,GAAG,EAAE,IAAI,QAAQ,MAAM,UACxD,EAAE,WAAW,EAAE,MAAM,UAAU,UAAU,EAAE,KAAK;EACnD,OAAO;GACL,SAAS;GACT,QAAQ,SAAS;GACjB;GACA,YAAY,EAAE;GACd,eAAe,SAAS,WAAW;GACnC;GACA,aAAa,OAAO,EAAE,WAAW,EAAE;GACnC,WAAW,cAA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AQ,WAAW,QAAQ,aAAa,iBAAiB;CAC/F,MAAM,CAAC,mBAAmB,sBAAsB,SAAS,KAAK;CAE9D,MAAM,QAAQ,eACL;EAAE;EAAS;EAAU;EAAmB;CAAmB,IAClE;EAAC;EAAS;EAAU;CAAiB,CACvC;CACA,OAAO,oBAAC,eAAe,UAAhB;EAAgC;EAAQ;CAAkC,CAAA;AACnF"}
|
|
@@ -2,9 +2,9 @@ import { ObservableStore } from "@luwiostack/storage";
|
|
|
2
2
|
//#region src/categories.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The fixed consent categories, in display order — the same four every consent tool (and Google
|
|
5
|
-
* Consent Mode) works with. `necessary` is always granted.
|
|
6
|
-
*
|
|
7
|
-
* package catalogs.
|
|
5
|
+
* Consent Mode) works with. `necessary` is always granted. A category's name and description are
|
|
6
|
+
* translated by machine name (`consent_category_<id>`, `consent_category_<id>_description`) from
|
|
7
|
+
* the package catalogs.
|
|
8
8
|
*/
|
|
9
9
|
declare const CONSENT_CATEGORIES: readonly ['necessary', 'preferences', 'statistics', 'marketing'];
|
|
10
10
|
/** `'necessary' | 'preferences' | 'statistics' | 'marketing'` */
|
|
@@ -53,40 +53,85 @@ declare class ConsentDecision {
|
|
|
53
53
|
/**
|
|
54
54
|
* A category as the consent instance presents it: one of the fixed four, whether it's required, and
|
|
55
55
|
* the vendors that set cookies in it — each with only its cookies of this category. Derived from the
|
|
56
|
-
* config; carries no display text
|
|
56
|
+
* config; carries no display text: `t(category.machine_name)` and
|
|
57
|
+
* `t(category.description_machine_name)`.
|
|
57
58
|
*/
|
|
58
59
|
interface ConsentCategory {
|
|
59
60
|
readonly id: ConsentCategoryId;
|
|
61
|
+
/** The translation key of its name, e.g. `consent_category_statistics`. */
|
|
62
|
+
readonly machine_name: string;
|
|
63
|
+
/** The translation key of its description, e.g. `consent_category_statistics_description`. */
|
|
64
|
+
readonly description_machine_name: string;
|
|
60
65
|
/** `true` for `necessary` only: always granted, can't be switched off. */
|
|
61
66
|
readonly required: boolean;
|
|
62
67
|
/** The vendors with cookies in this category, their cookies narrowed to it. May be empty. */
|
|
63
68
|
readonly vendors: readonly ConsentVendor[];
|
|
64
69
|
}
|
|
65
70
|
/**
|
|
66
|
-
* A partner that sets cookies — your own site, Google, Meta, YouTube
|
|
67
|
-
*
|
|
71
|
+
* A partner that sets cookies — your own site, Google, Meta, YouTube — as you declare it: its id
|
|
72
|
+
* and every cookie it sets. One vendor may set cookies in several categories. A preset from
|
|
73
|
+
* `@luwiostack/cookie-consent/vendors` is one; so is your own site.
|
|
68
74
|
*/
|
|
69
|
-
interface
|
|
70
|
-
/**
|
|
75
|
+
interface ConsentVendorDeclaration {
|
|
76
|
+
/**
|
|
77
|
+
* Stable id — what `isGranted(category, vendor)` and analytics' `vendor` refer to. snake_case by
|
|
78
|
+
* convention; its machine name is derived from it.
|
|
79
|
+
*/
|
|
71
80
|
readonly id: string;
|
|
72
81
|
/** Where the vendor explains what it does with the data. */
|
|
73
82
|
readonly privacy_policy_url?: string;
|
|
83
|
+
/**
|
|
84
|
+
* The countries outside the EEA the vendor sends visitors' personal data to, each with its
|
|
85
|
+
* safeguards. `[]`: it stays in the EEA; absent: not declared.
|
|
86
|
+
*/
|
|
87
|
+
readonly transfers?: readonly ConsentTransferDeclaration[];
|
|
74
88
|
/** Every cookie (or storage item) this vendor sets, each with its category. */
|
|
89
|
+
readonly cookies: readonly ConsentCookieDeclaration[];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A vendor as the consent instance presents it: the declaration plus its machine names. Carries no
|
|
93
|
+
* display text: render its name with `t(vendor.machine_name)`.
|
|
94
|
+
*/
|
|
95
|
+
interface ConsentVendor extends ConsentVendorDeclaration {
|
|
96
|
+
/** The translation key of its name: its id as a machine name, e.g. `google_analytics`. */
|
|
97
|
+
readonly machine_name: string;
|
|
98
|
+
readonly transfers?: readonly ConsentTransfer[];
|
|
75
99
|
readonly cookies: readonly ConsentCookie[];
|
|
76
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* What makes a transfer outside the EEA lawful (GDPR art. 45-47): an adequacy decision for the
|
|
103
|
+
* country, the vendor's EU-US Data Privacy Framework certification, standard contractual clauses or
|
|
104
|
+
* binding corporate rules.
|
|
105
|
+
*/
|
|
106
|
+
type ConsentTransferSafeguard = 'adequacy' | 'dpf' | 'scc' | 'bcr';
|
|
107
|
+
/** One country outside the EEA a vendor sends personal data to, as you declare it. */
|
|
108
|
+
interface ConsentTransferDeclaration {
|
|
109
|
+
/** ISO 3166-1 alpha-2, e.g. `US`; render it with `Intl.DisplayNames`. */
|
|
110
|
+
readonly country: string;
|
|
111
|
+
/** At least one. */
|
|
112
|
+
readonly safeguards: readonly ConsentTransferSafeguard[];
|
|
113
|
+
}
|
|
114
|
+
/** A transfer as the consent instance presents it: `t(key)` for each of `safeguard_machine_names`. */
|
|
115
|
+
interface ConsentTransfer extends ConsentTransferDeclaration {
|
|
116
|
+
/** The safeguards' translation keys, in order, e.g. `consent_transfer_safeguard_dpf`. */
|
|
117
|
+
readonly safeguard_machine_names: readonly string[];
|
|
118
|
+
}
|
|
119
|
+
/** Whether a cookie is set on the site's own domain or on the vendor's. */
|
|
120
|
+
type ConsentCookieParty = 'first' | 'third';
|
|
77
121
|
/** Where a cookie lives. `http` is a real cookie; the others are browser storage or a tracking pixel. */
|
|
78
122
|
type ConsentCookieType = 'http' | 'local_storage' | 'session_storage' | 'indexed_db' | 'pixel';
|
|
79
123
|
/**
|
|
80
124
|
* How long a cookie lives: milliseconds (like `maxAge`), `'session'` (gone when the browser closes)
|
|
81
125
|
* or `'persistent'` (no expiry — e.g. a `localStorage` item).
|
|
82
126
|
*/
|
|
83
|
-
type ConsentCookieMaxAge = number |
|
|
127
|
+
type ConsentCookieMaxAge = number | ConsentCookieWordedMaxAge;
|
|
128
|
+
/** The lifetimes that are a word, not a duration — translated, not formatted. */
|
|
129
|
+
type ConsentCookieWordedMaxAge = 'session' | 'persistent';
|
|
84
130
|
/**
|
|
85
|
-
* One cookie a vendor sets, as
|
|
86
|
-
*
|
|
87
|
-
* translate, keyed however you like (e.g. `t(\`${vendor.id}.${cookie.name}\`)`).
|
|
131
|
+
* One cookie a vendor sets, as you declare it. `name` is the real cookie name (`_ga`, `_fbp`) — a
|
|
132
|
+
* technical identifier, not display text.
|
|
88
133
|
*/
|
|
89
|
-
interface
|
|
134
|
+
interface ConsentCookieDeclaration {
|
|
90
135
|
/** The cookie's actual name, e.g. `_ga`. Unique within its vendor. */
|
|
91
136
|
readonly name: string;
|
|
92
137
|
/** What it's for — the category the visitor must grant before it may be set. */
|
|
@@ -95,6 +140,35 @@ interface ConsentCookie {
|
|
|
95
140
|
readonly type?: ConsentCookieType;
|
|
96
141
|
/** Its lifetime. Format it with `ConsentCookieFormatter.formatLocale`. */
|
|
97
142
|
readonly max_age: ConsentCookieMaxAge;
|
|
143
|
+
/**
|
|
144
|
+
* The vendor's domain it's set on (or, for storage, the origin's host), e.g. `.youtube.com`.
|
|
145
|
+
* Absent: the site's own domain, so a first-party cookie.
|
|
146
|
+
*/
|
|
147
|
+
readonly domain?: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* A cookie as the consent instance presents it: the declaration plus the translation keys of
|
|
151
|
+
* everything about it that's text — `t(cookie.machine_name)` (its purpose),
|
|
152
|
+
* `t(cookie.type_machine_name)`, `t(cookie.party_machine_name)`, and its lifetime as
|
|
153
|
+
* `ConsentCookieFormatter.formatLocale(cookie, locale) ?? t(cookie.max_age_machine_name)`.
|
|
154
|
+
*/
|
|
155
|
+
interface ConsentCookie extends ConsentCookieDeclaration {
|
|
156
|
+
/**
|
|
157
|
+
* The translation key of its purpose: the vendor's machine name plus the cookie name, a `*` read
|
|
158
|
+
* as `wildcard` — `google_analytics_ga`, `google_analytics_ga_wildcard` for `_ga_*`.
|
|
159
|
+
*/
|
|
160
|
+
readonly machine_name: string;
|
|
161
|
+
/** The translation key of its type, e.g. `consent_cookie_type_http` (the default type). */
|
|
162
|
+
readonly type_machine_name: string;
|
|
163
|
+
/** `third` when it has a `domain`, else `first`. */
|
|
164
|
+
readonly party: ConsentCookieParty;
|
|
165
|
+
/** The translation key of its party: `consent_cookie_party_first` / `consent_cookie_party_third`. */
|
|
166
|
+
readonly party_machine_name: string;
|
|
167
|
+
/**
|
|
168
|
+
* The translation key of a worded lifetime (`consent_max_age_session`,
|
|
169
|
+
* `consent_max_age_persistent`); absent for a duration, which `formatLocale` formats itself.
|
|
170
|
+
*/
|
|
171
|
+
readonly max_age_machine_name?: string;
|
|
98
172
|
}
|
|
99
173
|
/** The serialized form of a decision, as kept in the store. Fields are snake_case like every dataset. */
|
|
100
174
|
interface StoredConsent {
|
|
@@ -127,7 +201,7 @@ interface ConsentSnapshot {
|
|
|
127
201
|
* `preferences: [youtube()]` is the YouTube embed without its marketing cookies; list it under
|
|
128
202
|
* `marketing` too to declare those.
|
|
129
203
|
*/
|
|
130
|
-
type ConsentCategoriesConfig = Partial<Record<ConsentCategoryId, readonly
|
|
204
|
+
type ConsentCategoriesConfig = Partial<Record<ConsentCategoryId, readonly ConsentVendorDeclaration[]>>;
|
|
131
205
|
interface ConsentConfig {
|
|
132
206
|
/**
|
|
133
207
|
* Per category, the vendors used in it — usually presets from `@luwiostack/cookie-consent/vendors`.
|
|
@@ -194,5 +268,5 @@ interface ConsentManager {
|
|
|
194
268
|
reset(): void;
|
|
195
269
|
}
|
|
196
270
|
//#endregion
|
|
197
|
-
export {
|
|
198
|
-
//# sourceMappingURL=types-
|
|
271
|
+
export { REQUIRED_CATEGORY as C, ConsentCategoryId as S, ConsentVendorDeclaration as _, ConsentCookieDeclaration as a, ConsentDecisionInput as b, ConsentCookieType as c, ConsentSnapshot as d, ConsentStatus as f, ConsentVendor as g, ConsentTransferSafeguard as h, ConsentCookie as i, ConsentCookieWordedMaxAge as l, ConsentTransferDeclaration as m, ConsentCategory as n, ConsentCookieMaxAge as o, ConsentTransfer as p, ConsentConfig as r, ConsentCookieParty as s, ConsentCategoriesConfig as t, ConsentManager as u, StoredConsent as v, isConsentCategoryId as w, CONSENT_CATEGORIES as x, ConsentDecision as y };
|
|
272
|
+
//# sourceMappingURL=types-ByyibBUg.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-ByyibBUg.d.cts","names":[],"sources":["../src/categories.ts","../src/domain/consent-decision.ts","../src/types.ts"],"mappings":";;;;;;;;cAMa;;KAGD,4BAA4B;;cAG3B;;iBAGG,oBAAoB,iBAAiB,SAAS;;;UCX7C;EACf;EACA;EACA,SAAS,SAAS;EAClB;;;;;;;;;cAUW;;WACF;WACA;;WAEA;UAGF;;SAQA,IAAI,OAAO,uBAAuB;;SAclC,OAAO,OAAO,uBAAuB;;EAS5C,UAAU,IAAI;;EAKd,WAAW;;EAKX,OAAO,OAAO;;EAcd,UAAU;;;;;;;;;;UCtEK;WACN,IAAI;;WAEJ;;WAEA;;WAEA;;WAEA,kBAAkB;;;;;;;UAQZ;;;;;WAKN;;WAEA;;;;;WAKA,qBAAqB;;WAErB,kBAAkB;;;;;;UAOZ,sBAAsB;;WAE5B;WACA,qBAAqB;WACrB,kBAAkB;;;;;;;KAQjB;;UAGK;;WAEN;;WAEA,qBAAqB;;;UAIf,wBAAwB;;WAE9B;;;KAIC;;KAGA;;;;;KAWA,+BAA+B;;KAG/B;;;;;UAMK;;WAEN;;WAEA,UAAU;;WAEV,OAAO;;WAEP,SAAS;;;;;WAKT;;;;;;;;UASM,sBAAsB;;;;;WAK5B;;WAEA;;WAEA,OAAO;;WAEP;;;;;WAKA;;;UAIM;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;;;;KAUU;;UAGK;WACN,QAAQ;;WAER,UAAU;;;;;;;;KAST,0BAA0B,QACpC,OAAO,4BAA4B;UAGpB;;;;;EAKf,aAAa;;;;;EAKb;;;;;EAKA;;;;;;;EAOA,QAAQ,gBAAgB;;EAExB;;;;;EAKA,YAAY,MAAM,wBAAwB,UAAU;;;UAIrC;;WAEN,qBAAqB;;WAErB,kBAAkB;;WAElB;;EAET,eAAe;;EAEf,UAAU;;;;;;;EAOV,UAAU,UAAU,mBAAmB;;EAEvC,WAAW,UAAU;;EAErB,aAAa;;EAEb,aAAa;;EAEb,KAAK,SAAS,SAAS,qBAAqB;;EAE5C,SAAS,KAAK,sBAAsB;;EAEpC,UAAU,KAAK,sBAAsB;;EAErC"}
|
|
@@ -2,9 +2,9 @@ import { ObservableStore } from "@luwiostack/storage";
|
|
|
2
2
|
//#region src/categories.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The fixed consent categories, in display order — the same four every consent tool (and Google
|
|
5
|
-
* Consent Mode) works with. `necessary` is always granted.
|
|
6
|
-
*
|
|
7
|
-
* package catalogs.
|
|
5
|
+
* Consent Mode) works with. `necessary` is always granted. A category's name and description are
|
|
6
|
+
* translated by machine name (`consent_category_<id>`, `consent_category_<id>_description`) from
|
|
7
|
+
* the package catalogs.
|
|
8
8
|
*/
|
|
9
9
|
declare const CONSENT_CATEGORIES: readonly ['necessary', 'preferences', 'statistics', 'marketing'];
|
|
10
10
|
/** `'necessary' | 'preferences' | 'statistics' | 'marketing'` */
|
|
@@ -53,40 +53,85 @@ declare class ConsentDecision {
|
|
|
53
53
|
/**
|
|
54
54
|
* A category as the consent instance presents it: one of the fixed four, whether it's required, and
|
|
55
55
|
* the vendors that set cookies in it — each with only its cookies of this category. Derived from the
|
|
56
|
-
* config; carries no display text
|
|
56
|
+
* config; carries no display text: `t(category.machine_name)` and
|
|
57
|
+
* `t(category.description_machine_name)`.
|
|
57
58
|
*/
|
|
58
59
|
interface ConsentCategory {
|
|
59
60
|
readonly id: ConsentCategoryId;
|
|
61
|
+
/** The translation key of its name, e.g. `consent_category_statistics`. */
|
|
62
|
+
readonly machine_name: string;
|
|
63
|
+
/** The translation key of its description, e.g. `consent_category_statistics_description`. */
|
|
64
|
+
readonly description_machine_name: string;
|
|
60
65
|
/** `true` for `necessary` only: always granted, can't be switched off. */
|
|
61
66
|
readonly required: boolean;
|
|
62
67
|
/** The vendors with cookies in this category, their cookies narrowed to it. May be empty. */
|
|
63
68
|
readonly vendors: readonly ConsentVendor[];
|
|
64
69
|
}
|
|
65
70
|
/**
|
|
66
|
-
* A partner that sets cookies — your own site, Google, Meta, YouTube
|
|
67
|
-
*
|
|
71
|
+
* A partner that sets cookies — your own site, Google, Meta, YouTube — as you declare it: its id
|
|
72
|
+
* and every cookie it sets. One vendor may set cookies in several categories. A preset from
|
|
73
|
+
* `@luwiostack/cookie-consent/vendors` is one; so is your own site.
|
|
68
74
|
*/
|
|
69
|
-
interface
|
|
70
|
-
/**
|
|
75
|
+
interface ConsentVendorDeclaration {
|
|
76
|
+
/**
|
|
77
|
+
* Stable id — what `isGranted(category, vendor)` and analytics' `vendor` refer to. snake_case by
|
|
78
|
+
* convention; its machine name is derived from it.
|
|
79
|
+
*/
|
|
71
80
|
readonly id: string;
|
|
72
81
|
/** Where the vendor explains what it does with the data. */
|
|
73
82
|
readonly privacy_policy_url?: string;
|
|
83
|
+
/**
|
|
84
|
+
* The countries outside the EEA the vendor sends visitors' personal data to, each with its
|
|
85
|
+
* safeguards. `[]`: it stays in the EEA; absent: not declared.
|
|
86
|
+
*/
|
|
87
|
+
readonly transfers?: readonly ConsentTransferDeclaration[];
|
|
74
88
|
/** Every cookie (or storage item) this vendor sets, each with its category. */
|
|
89
|
+
readonly cookies: readonly ConsentCookieDeclaration[];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A vendor as the consent instance presents it: the declaration plus its machine names. Carries no
|
|
93
|
+
* display text: render its name with `t(vendor.machine_name)`.
|
|
94
|
+
*/
|
|
95
|
+
interface ConsentVendor extends ConsentVendorDeclaration {
|
|
96
|
+
/** The translation key of its name: its id as a machine name, e.g. `google_analytics`. */
|
|
97
|
+
readonly machine_name: string;
|
|
98
|
+
readonly transfers?: readonly ConsentTransfer[];
|
|
75
99
|
readonly cookies: readonly ConsentCookie[];
|
|
76
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* What makes a transfer outside the EEA lawful (GDPR art. 45-47): an adequacy decision for the
|
|
103
|
+
* country, the vendor's EU-US Data Privacy Framework certification, standard contractual clauses or
|
|
104
|
+
* binding corporate rules.
|
|
105
|
+
*/
|
|
106
|
+
type ConsentTransferSafeguard = 'adequacy' | 'dpf' | 'scc' | 'bcr';
|
|
107
|
+
/** One country outside the EEA a vendor sends personal data to, as you declare it. */
|
|
108
|
+
interface ConsentTransferDeclaration {
|
|
109
|
+
/** ISO 3166-1 alpha-2, e.g. `US`; render it with `Intl.DisplayNames`. */
|
|
110
|
+
readonly country: string;
|
|
111
|
+
/** At least one. */
|
|
112
|
+
readonly safeguards: readonly ConsentTransferSafeguard[];
|
|
113
|
+
}
|
|
114
|
+
/** A transfer as the consent instance presents it: `t(key)` for each of `safeguard_machine_names`. */
|
|
115
|
+
interface ConsentTransfer extends ConsentTransferDeclaration {
|
|
116
|
+
/** The safeguards' translation keys, in order, e.g. `consent_transfer_safeguard_dpf`. */
|
|
117
|
+
readonly safeguard_machine_names: readonly string[];
|
|
118
|
+
}
|
|
119
|
+
/** Whether a cookie is set on the site's own domain or on the vendor's. */
|
|
120
|
+
type ConsentCookieParty = 'first' | 'third';
|
|
77
121
|
/** Where a cookie lives. `http` is a real cookie; the others are browser storage or a tracking pixel. */
|
|
78
122
|
type ConsentCookieType = 'http' | 'local_storage' | 'session_storage' | 'indexed_db' | 'pixel';
|
|
79
123
|
/**
|
|
80
124
|
* How long a cookie lives: milliseconds (like `maxAge`), `'session'` (gone when the browser closes)
|
|
81
125
|
* or `'persistent'` (no expiry — e.g. a `localStorage` item).
|
|
82
126
|
*/
|
|
83
|
-
type ConsentCookieMaxAge = number |
|
|
127
|
+
type ConsentCookieMaxAge = number | ConsentCookieWordedMaxAge;
|
|
128
|
+
/** The lifetimes that are a word, not a duration — translated, not formatted. */
|
|
129
|
+
type ConsentCookieWordedMaxAge = 'session' | 'persistent';
|
|
84
130
|
/**
|
|
85
|
-
* One cookie a vendor sets, as
|
|
86
|
-
*
|
|
87
|
-
* translate, keyed however you like (e.g. `t(\`${vendor.id}.${cookie.name}\`)`).
|
|
131
|
+
* One cookie a vendor sets, as you declare it. `name` is the real cookie name (`_ga`, `_fbp`) — a
|
|
132
|
+
* technical identifier, not display text.
|
|
88
133
|
*/
|
|
89
|
-
interface
|
|
134
|
+
interface ConsentCookieDeclaration {
|
|
90
135
|
/** The cookie's actual name, e.g. `_ga`. Unique within its vendor. */
|
|
91
136
|
readonly name: string;
|
|
92
137
|
/** What it's for — the category the visitor must grant before it may be set. */
|
|
@@ -95,6 +140,35 @@ interface ConsentCookie {
|
|
|
95
140
|
readonly type?: ConsentCookieType;
|
|
96
141
|
/** Its lifetime. Format it with `ConsentCookieFormatter.formatLocale`. */
|
|
97
142
|
readonly max_age: ConsentCookieMaxAge;
|
|
143
|
+
/**
|
|
144
|
+
* The vendor's domain it's set on (or, for storage, the origin's host), e.g. `.youtube.com`.
|
|
145
|
+
* Absent: the site's own domain, so a first-party cookie.
|
|
146
|
+
*/
|
|
147
|
+
readonly domain?: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* A cookie as the consent instance presents it: the declaration plus the translation keys of
|
|
151
|
+
* everything about it that's text — `t(cookie.machine_name)` (its purpose),
|
|
152
|
+
* `t(cookie.type_machine_name)`, `t(cookie.party_machine_name)`, and its lifetime as
|
|
153
|
+
* `ConsentCookieFormatter.formatLocale(cookie, locale) ?? t(cookie.max_age_machine_name)`.
|
|
154
|
+
*/
|
|
155
|
+
interface ConsentCookie extends ConsentCookieDeclaration {
|
|
156
|
+
/**
|
|
157
|
+
* The translation key of its purpose: the vendor's machine name plus the cookie name, a `*` read
|
|
158
|
+
* as `wildcard` — `google_analytics_ga`, `google_analytics_ga_wildcard` for `_ga_*`.
|
|
159
|
+
*/
|
|
160
|
+
readonly machine_name: string;
|
|
161
|
+
/** The translation key of its type, e.g. `consent_cookie_type_http` (the default type). */
|
|
162
|
+
readonly type_machine_name: string;
|
|
163
|
+
/** `third` when it has a `domain`, else `first`. */
|
|
164
|
+
readonly party: ConsentCookieParty;
|
|
165
|
+
/** The translation key of its party: `consent_cookie_party_first` / `consent_cookie_party_third`. */
|
|
166
|
+
readonly party_machine_name: string;
|
|
167
|
+
/**
|
|
168
|
+
* The translation key of a worded lifetime (`consent_max_age_session`,
|
|
169
|
+
* `consent_max_age_persistent`); absent for a duration, which `formatLocale` formats itself.
|
|
170
|
+
*/
|
|
171
|
+
readonly max_age_machine_name?: string;
|
|
98
172
|
}
|
|
99
173
|
/** The serialized form of a decision, as kept in the store. Fields are snake_case like every dataset. */
|
|
100
174
|
interface StoredConsent {
|
|
@@ -127,7 +201,7 @@ interface ConsentSnapshot {
|
|
|
127
201
|
* `preferences: [youtube()]` is the YouTube embed without its marketing cookies; list it under
|
|
128
202
|
* `marketing` too to declare those.
|
|
129
203
|
*/
|
|
130
|
-
type ConsentCategoriesConfig = Partial<Record<ConsentCategoryId, readonly
|
|
204
|
+
type ConsentCategoriesConfig = Partial<Record<ConsentCategoryId, readonly ConsentVendorDeclaration[]>>;
|
|
131
205
|
interface ConsentConfig {
|
|
132
206
|
/**
|
|
133
207
|
* Per category, the vendors used in it — usually presets from `@luwiostack/cookie-consent/vendors`.
|
|
@@ -194,5 +268,5 @@ interface ConsentManager {
|
|
|
194
268
|
reset(): void;
|
|
195
269
|
}
|
|
196
270
|
//#endregion
|
|
197
|
-
export {
|
|
198
|
-
//# sourceMappingURL=types-
|
|
271
|
+
export { REQUIRED_CATEGORY as C, ConsentCategoryId as S, ConsentVendorDeclaration as _, ConsentCookieDeclaration as a, ConsentDecisionInput as b, ConsentCookieType as c, ConsentSnapshot as d, ConsentStatus as f, ConsentVendor as g, ConsentTransferSafeguard as h, ConsentCookie as i, ConsentCookieWordedMaxAge as l, ConsentTransferDeclaration as m, ConsentCategory as n, ConsentCookieMaxAge as o, ConsentTransfer as p, ConsentConfig as r, ConsentCookieParty as s, ConsentCategoriesConfig as t, ConsentManager as u, StoredConsent as v, isConsentCategoryId as w, CONSENT_CATEGORIES as x, ConsentDecision as y };
|
|
272
|
+
//# sourceMappingURL=types-ByyibBUg.d.mts.map
|