@luwiostack/cookie-consent 0.1.0 → 0.3.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 +161 -31
- package/dist/index.cjs +257 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -53
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +10 -53
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +227 -96
- package/dist/index.mjs.map +1 -1
- package/dist/machine-names--nw4DSRE.cjs +138 -0
- package/dist/machine-names--nw4DSRE.cjs.map +1 -0
- package/dist/machine-names-DX8eCM2Q.mjs +103 -0
- package/dist/machine-names-DX8eCM2Q.mjs.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-WpJKTgRa.d.cts} +92 -16
- package/dist/types-WpJKTgRa.d.cts.map +1 -0
- package/dist/{types-BrxRJL4I.d.mts → types-WpJKTgRa.d.mts} +92 -16
- package/dist/types-WpJKTgRa.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
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-WpJKTgRa.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,kBAAk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AAE,CAAC;CAE9D,IAAI,QAAQ,WAAW,GAAG,OAAO,oBAAA,UAAA,EAAG,SAAW,CAAA;CAC/C,IAAI,OAAO,aAAa,YAAY,OAAO,oBAAA,UAAA,EAAA,UAAG,SAAW,CAAA;CACzD,OACE,oBAAA,UAAA,EAAA,UACG,SAAS;EACR;EACA,aAAa,QAAQ,MAAM,GAAG,OAAO;EACrC,iBAAiB,QAAQ;CAC3B,CAAC,EACD,CAAA;AAEN;;;ACzDA,MAAM,kBAAmC,OAAO,OAAO;CAAE,QAAQ;CAAW,UAAU;AAAK,CAAC;AAC5F,MAAM,0BAA0B;;;;;;;AAchC,SAAgB,QAAQ,EAAE,SAAS,YAA0B;CAC3D,MAAM,WAAW,qBAAqB,QAAQ,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"}
|
|
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,M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AI,WAAW,KAAA,KAAa,CAAC,SAAS,MAAM,MAAM,GAAG,OAAO;CAC5D,MAAM,UAAU,SAAS,QAAQ,OAAO,CAAC,QAAQ,UAAU,EAAE,CAAC;CAE9D,IAAI,QAAQ,WAAW,GAAG,OAAO,oBAAA,UAAA,EAAG,SAAW,CAAA;CAC/C,IAAI,OAAO,aAAa,YAAY,OAAO,oBAAA,UAAA,EAAA,UAAG,SAAW,CAAA;CACzD,OACE,oBAAA,UAAA,EAAA,UACG,SAAS;EACR;EACA,aAAa,QAAQ,MAAM,GAAG,OAAO;EACrC,iBAAiB,QAAQ;CAC3B,CAAC,EACD,CAAA;AAEN;;;ACzDA,MAAM,kBAAmC,OAAO,OAAO;CAAE,QAAQ;CAAW,UAAU;AAAK,CAAC;AAC5F,MAAM,0BAA0B;;;;;;;AAchC,SAAgB,QAAQ,EAAE,SAAS,YAA0B;CAC3D,MAAM,WAAW,qBAAqB,QAAQ,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`.
|
|
@@ -149,6 +223,8 @@ interface ConsentConfig {
|
|
|
149
223
|
* `@luwiostack/storage` (persists across tabs and restarts, synced between tabs; where storage is
|
|
150
224
|
* blocked or full the decision just isn't kept). A store you pass in fails per its own `onError`
|
|
151
225
|
* — by default a failed write throws out of `acceptAll()` & co. Pass `memoryStore()` in tests.
|
|
226
|
+
* A store of your own must return the same object from `read()` until its value changes (as
|
|
227
|
+
* `@luwiostack/storage`'s stores do): that's how consent tells a change apart.
|
|
152
228
|
*/
|
|
153
229
|
store?: ObservableStore<StoredConsent>;
|
|
154
230
|
/** The current time in epoch milliseconds. Default `Date.now` — inject for tests. */
|
|
@@ -194,5 +270,5 @@ interface ConsentManager {
|
|
|
194
270
|
reset(): void;
|
|
195
271
|
}
|
|
196
272
|
//#endregion
|
|
197
|
-
export {
|
|
198
|
-
//# sourceMappingURL=types-
|
|
273
|
+
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 };
|
|
274
|
+
//# sourceMappingURL=types-WpJKTgRa.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-WpJKTgRa.d.cts","names":[],"sources":["../src/categories.ts","../src/domain/consent-decision.ts","../src/types.ts"],"mappings":";;;;;;;;cAMa;;KAGD,4BA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"@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`.
|
|
@@ -149,6 +223,8 @@ interface ConsentConfig {
|
|
|
149
223
|
* `@luwiostack/storage` (persists across tabs and restarts, synced between tabs; where storage is
|
|
150
224
|
* blocked or full the decision just isn't kept). A store you pass in fails per its own `onError`
|
|
151
225
|
* — by default a failed write throws out of `acceptAll()` & co. Pass `memoryStore()` in tests.
|
|
226
|
+
* A store of your own must return the same object from `read()` until its value changes (as
|
|
227
|
+
* `@luwiostack/storage`'s stores do): that's how consent tells a change apart.
|
|
152
228
|
*/
|
|
153
229
|
store?: ObservableStore<StoredConsent>;
|
|
154
230
|
/** The current time in epoch milliseconds. Default `Date.now` — inject for tests. */
|
|
@@ -194,5 +270,5 @@ interface ConsentManager {
|
|
|
194
270
|
reset(): void;
|
|
195
271
|
}
|
|
196
272
|
//#endregion
|
|
197
|
-
export {
|
|
198
|
-
//# sourceMappingURL=types-
|
|
273
|
+
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 };
|
|
274
|
+
//# sourceMappingURL=types-WpJKTgRa.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-WpJKTgRa.d.mts","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;;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