@prenta/plugin-consent 0.4.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/CHANGELOG.md ADDED
@@ -0,0 +1,106 @@
1
+ # @actuate-media/plugin-consent
2
+
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5eea995: Product rename: ActuateCMS is now **Prenta**. Every package moves from the
8
+ `@actuate-media/*` scope to `@prenta/*` with simplified names (`@prenta/core`,
9
+ `@prenta/admin`, `create-prenta`), and version numbers continue from where the
10
+ old scope left off.
11
+
12
+ This is a clean break — no backwards-compat aliases:
13
+ - **npm packages**: `@actuate-media/cms-core` → `@prenta/core`,
14
+ `@actuate-media/cms-admin` → `@prenta/admin`, all other packages keep their
15
+ suffix under `@prenta/*`. `create-actuate-cms` → `create-prenta`
16
+ (`npm create prenta`), `create-actuate-astro` → `create-prenta-astro`.
17
+ CLI bins: `actuate`/`actuate-cms` → `prenta`/`prenta-cms`; `actuate-mcp` →
18
+ `prenta-mcp`.
19
+ - **Database**: migration `0012_rename_to_prenta` renames all 36 `actuate_*`
20
+ tables to `prenta_*` in place (plus prefixed constraints, indexes, and
21
+ sequences). Run `prisma migrate deploy` when upgrading.
22
+ - **Runtime identifiers**: `getActuateConfig` → `getPrentaConfig`,
23
+ `handleActuateAPI` → `handlePrentaAPI`, `ActuateClient` → `PrentaClient`,
24
+ `ActuateDB` → `PrentaDB`, config file `actuate.config.ts` →
25
+ `prenta.config.ts`, CSS scopes `.actuate-admin`/`.actuate-canvas` →
26
+ `.prenta-admin`/`.prenta-canvas`, preview protocol `actuate-preview:*` →
27
+ `prenta-preview:*`, webhook headers `X-Actuate-*` → `X-Prenta-*`, session
28
+ cookie `actuate_session` → `prenta_session`, env vars `ACTUATE_*` →
29
+ `PRENTA_*`, purge route `/api/actuate/purge` → `/api/prenta/purge`.
30
+ - **Sessions and webhooks**: all sessions reset on upgrade (cookie + JWT issuer
31
+ changed); webhook consumers must re-verify signatures against the new
32
+ `X-Prenta-*` headers.
33
+
34
+ The old `@actuate-media/*` packages are deprecated on npm and will receive no
35
+ further releases.
36
+
37
+ ## 0.3.3
38
+
39
+ ### Patch Changes
40
+
41
+ - e25cd48: Standardize React peer ranges to `^18.0.0 || ^19.0.0`.
42
+
43
+ Plugin React peer ranges were inconsistent: `plugin-ai`, `plugin-commerce`, and
44
+ `plugin-seo` pinned `react: ^19.2.0` (excluding React 18, which `cms-core`
45
+ supports via `react >=18.0.0`), while the others used `^18.0.0 || ^19.2.0`
46
+ (excluding React 19.0/19.1). Either produced an `ERESOLVE` install failure for
47
+ consumers on the excluded versions. All bundled plugins now declare `react`
48
+ (and `react-dom` where already peered) as `^18.0.0 || ^19.0.0`.
49
+
50
+ ## 0.3.2
51
+
52
+ ### Patch Changes
53
+
54
+ - c231dd0: Add `definePlugin` and migrate all 10 plugins onto the canonical `PluginDefinition` contract.
55
+
56
+ cms-core already exported `PluginDefinition`, but every plugin hand-rolled a
57
+ local `ActuatePlugin` interface — a lossy subset that dropped `version`/`init`
58
+ and, in blocks/email/ai, widened hook payloads to `unknown[]`/`event: string`.
59
+ That's copy-paste drift with no shared source of truth.
60
+
61
+ `cms-core` now exports `definePlugin(plugin: PluginDefinition)` (an identity
62
+ helper like `defineConfig`), and each plugin imports the canonical type instead
63
+ of its own: the local `ActuatePlugin` interfaces are deleted, factory return
64
+ types are `PluginDefinition`, and the widened `hooks.ts` types are retyped as
65
+ `PluginHook[]`. Type-only change — no runtime behavior, plugin `name`, or config
66
+ options changed. Net −69 lines.
67
+
68
+ - 325694f: Import `definePlugin` from the lightweight `@actuate-media/cms-core/config`
69
+ entry instead of the barrel.
70
+
71
+ The plugin-definition migration imported the `definePlugin` **value** from
72
+ `@actuate-media/cms-core`, which pulls the entire cms-core barrel (graphql,
73
+ sharp, sentry, codegen) into every plugin's runtime — bundle bloat for
74
+ consumers and, under parallel test load, a timeout. The `/config` subpath exists
75
+ precisely to avoid the barrel. Types stay as erased `import type`, so nothing
76
+ heavy is loaded. No API or behavior change.
77
+
78
+ ## 0.3.1
79
+
80
+ ### Patch Changes
81
+
82
+ - 041a228: Add the MIT `license` field to every published package (previously missing) and correct `repository.url` to `github.com/actuate-media/actuatecms` (13 packages carried the wrong org).
83
+
84
+ ## 0.3.0
85
+
86
+ ### Minor Changes
87
+
88
+ - 41bd56a: Correctness fixes from the post-Phase-3 polish plan.
89
+
90
+ **plugin-consent — granular consent categories.** Consent is no longer binary: visitors can grant individual categories (`analytics`, `marketing`, `functional`, `preferences`) via a new "Manage preferences" expansion in `ConsentBanner`. Custom selections persist as JSON in the same `am_cookie_consent` key; `all`/`essential` still persist as legacy strings so previously shipped consent gates keep working, and legacy stored values migrate transparently on read. New exports: `CONSENT_CATEGORIES`, `ConsentCategory`, `ConsentState`, `readConsentState`, `writeConsentState`, `setConsentCategories`, `hasCategoryConsent`, `categoriesForLevel`, `normalizeConsentSelection`, `waitForConsentState`. `useConsent` now reports `categories` and an `allows(category)` helper; `loadConsentGatedAnalytics` gates GA4/Google Ads on `analytics` and Meta Pixel on `marketing` when passed a consent state.
91
+
92
+ **cms-core — script-tag consent gate honors categories.** `wrapCodeInConsentGate` now grants when the visitor accepted all cookies _or_ granted the tag's specific category through a custom selection, instead of requiring full consent for every gated tag. Legacy stored `'all'` strings still pass.
93
+
94
+ **cms-admin — router query strings + idle-logout warning.** `useAdminRouter` now includes the query string in `currentPath` on mount and popstate, so deep links like `/pages/new?parent=<id>` and `/settings?tab=users` survive hard reloads and back/forward. New `parseRouteQuery` helper and `search` return value; the command palette's `?selected=` deep links now open the media detail panel and user drawer. `useIdleLogout` gains a warning stage — one minute before idle sign-out a toast offers "Stay signed in" to reset the clock.
95
+
96
+ ## 0.2.0
97
+
98
+ ### Minor Changes
99
+
100
+ - 0a170a7: Add `@actuate-media/plugin-consent` — cookie banner with `am_cookie_consent` / `am-consent` wiring and GA4, Google Ads, and Meta Pixel loaders gated on Accept all. Scaffold with `--plugins consent` to emit layout + config wiring.
101
+
102
+ ## 0.1.0
103
+
104
+ ### Minor Changes
105
+
106
+ - Initial release: cookie consent banner, `am_cookie_consent` / `am-consent` wiring, and GA4 / Google Ads / Meta Pixel loaders gated on **Accept all**.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Actuate Media
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @prenta/plugin-consent
2
+
3
+ Cookie consent banner, `am_cookie_consent` storage, and `am-consent` events for Prenta CMS public sites. Gates GA4, Google Ads, and Meta Pixel until the visitor chooses **Accept all**.
4
+
5
+ ## Quick start
6
+
7
+ ```tsx
8
+ // app/(site)/layout.tsx
9
+ import { ConsentRoot } from '@prenta/plugin-consent'
10
+ import { consentAnalyticsConfig, consentLinks } from '@/src/consent/config'
11
+
12
+ export default function SiteLayout({ children }) {
13
+ return (
14
+ <html lang="en">
15
+ <body>
16
+ {children}
17
+ <ConsentRoot analytics={consentAnalyticsConfig} {...consentLinks} />
18
+ </body>
19
+ </html>
20
+ )
21
+ }
22
+ ```
23
+
24
+ ```typescript
25
+ // src/consent/config.ts
26
+ import type { ConsentAnalyticsConfig } from '@prenta/plugin-consent'
27
+
28
+ export const consentAnalyticsConfig: ConsentAnalyticsConfig = {
29
+ ga4MeasurementId: process.env.NEXT_PUBLIC_GA4_MEASUREMENT_ID,
30
+ googleAdsId: process.env.NEXT_PUBLIC_GOOGLE_ADS_ID,
31
+ metaPixelId: process.env.NEXT_PUBLIC_META_PIXEL_ID,
32
+ }
33
+
34
+ export const consentLinks = {
35
+ privacyUrl: '/privacy-policy',
36
+ termsUrl: '/terms',
37
+ }
38
+ ```
39
+
40
+ Scaffold with `--plugins consent` (or select **Consent** in the CLI) to generate the config file and layout wiring automatically.
41
+
42
+ ## Sticky CTA / custom widgets
43
+
44
+ ```tsx
45
+ 'use client'
46
+ import { useConsent, waitForConsent } from '@prenta/plugin-consent'
47
+
48
+ export function StickyCta() {
49
+ const { allowsAnalytics, ready } = useConsent()
50
+ if (!ready || !allowsAnalytics) return null
51
+ return <button type="button">Track me</button>
52
+ }
53
+
54
+ // Or await before firing a pixel manually:
55
+ await waitForConsent()
56
+ ```
57
+
58
+ ## API
59
+
60
+ | Export | Purpose |
61
+ | ----------------------------------- | -------------------------------------- |
62
+ | `ConsentRoot` | Banner + analytics loader (mount once) |
63
+ | `ConsentBanner` | Banner only |
64
+ | `useConsent()` | React hook for gated UI |
65
+ | `onConsent(fn)` | Subscribe to `am-consent` |
66
+ | `waitForConsent()` | Promise when user has chosen |
67
+ | `setConsent('all' \| 'essential')` | Save + dispatch event |
68
+ | `readConsent()` | Read `localStorage` value |
69
+ | `loadConsentGatedAnalytics(config)` | Inject tags when `'all'` |
70
+
71
+ Storage key: `am_cookie_consent`. Event: `am-consent` with `{ detail: { level } }`.
@@ -0,0 +1,14 @@
1
+ import type { ConsentState } from './types.js';
2
+ export interface ConsentBannerProps {
3
+ privacyUrl: string;
4
+ termsUrl?: string;
5
+ message?: string;
6
+ className?: string;
7
+ onAcceptAll: () => void;
8
+ onEssentialOnly: () => void;
9
+ /** Invoked after a custom per-category selection is saved. */
10
+ onSavePreferences?: (state: ConsentState) => void;
11
+ }
12
+ /** Fixed bottom consent banner — keyboard-accessible, no third-party scripts. */
13
+ export declare function ConsentBanner({ privacyUrl, termsUrl, message, className, onAcceptAll, onEssentialOnly, onSavePreferences, }: ConsentBannerProps): React.ReactNode;
14
+ //# sourceMappingURL=ConsentBanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConsentBanner.d.ts","sourceRoot":"","sources":["../src/ConsentBanner.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAmB,YAAY,EAAE,MAAM,YAAY,CAAA;AAE/D,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,IAAI,CAAA;IACvB,eAAe,EAAE,MAAM,IAAI,CAAA;IAC3B,8DAA8D;IAC9D,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;CAClD;AAiCD,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,EAC5B,UAAU,EACV,QAAQ,EACR,OAAyB,EACzB,SAAc,EACd,WAAW,EACX,eAAe,EACf,iBAAiB,GAClB,EAAE,kBAAkB,GAAG,KAAK,CAAC,SAAS,CAuHtC"}
@@ -0,0 +1,55 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useId, useState } from 'react';
4
+ import { CONSENT_CATEGORIES } from './constants.js';
5
+ import { setConsent, setConsentCategories } from './events.js';
6
+ const DEFAULT_MESSAGE = 'We use cookies to measure traffic and improve your experience. You can accept all cookies, allow essential cookies only, or manage preferences.';
7
+ const CATEGORY_COPY = {
8
+ analytics: {
9
+ label: 'Analytics',
10
+ description: 'Traffic measurement and usage statistics.',
11
+ },
12
+ marketing: {
13
+ label: 'Marketing',
14
+ description: 'Advertising pixels and remarketing.',
15
+ },
16
+ functional: {
17
+ label: 'Functional',
18
+ description: 'Embedded widgets like chat, maps, and schedulers.',
19
+ },
20
+ preferences: {
21
+ label: 'Preferences',
22
+ description: 'Remembering choices like language or region.',
23
+ },
24
+ };
25
+ const LINK_CLASS = 'text-sm text-zinc-600 underline underline-offset-2 hover:text-zinc-900 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-900';
26
+ const SECONDARY_BUTTON_CLASS = 'rounded-lg border border-zinc-300 bg-white px-3 py-1.5 text-sm font-medium text-zinc-800 hover:bg-zinc-50 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-900';
27
+ const PRIMARY_BUTTON_CLASS = 'rounded-lg bg-zinc-900 px-3 py-1.5 text-sm font-medium text-white hover:bg-zinc-800 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-900';
28
+ /** Fixed bottom consent banner — keyboard-accessible, no third-party scripts. */
29
+ export function ConsentBanner({ privacyUrl, termsUrl, message = DEFAULT_MESSAGE, className = '', onAcceptAll, onEssentialOnly, onSavePreferences, }) {
30
+ const [managing, setManaging] = useState(false);
31
+ const [selected, setSelected] = useState([]);
32
+ const panelId = useId();
33
+ function choose(level, after) {
34
+ setConsent(level);
35
+ after();
36
+ }
37
+ function savePreferences() {
38
+ const state = setConsentCategories(selected);
39
+ if (onSavePreferences) {
40
+ onSavePreferences(state);
41
+ return;
42
+ }
43
+ // Without a preferences handler, resolve through the level callbacks so
44
+ // pre-existing two-button integrations still close the banner.
45
+ if (state.level === 'all')
46
+ onAcceptAll();
47
+ else
48
+ onEssentialOnly();
49
+ }
50
+ function toggleCategory(category) {
51
+ setSelected((prev) => prev.includes(category) ? prev.filter((c) => c !== category) : [...prev, category]);
52
+ }
53
+ return (_jsx("div", { role: "region", "aria-label": "Cookie consent", className: `fixed inset-x-0 bottom-0 z-50 border-t border-zinc-200 bg-white p-4 shadow-lg motion-safe:transition-transform ${className}`.trim(), children: _jsxs("div", { className: "mx-auto flex max-w-5xl flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between", children: [_jsx("p", { className: "text-sm text-zinc-700", children: message }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("a", { href: privacyUrl, className: LINK_CLASS, children: "Privacy" }), termsUrl && (_jsx("a", { href: termsUrl, className: LINK_CLASS, children: "Terms" })), _jsx("button", { type: "button", onClick: () => setManaging((m) => !m), "aria-expanded": managing, "aria-controls": panelId, className: SECONDARY_BUTTON_CLASS, children: "Manage preferences" }), _jsx("button", { type: "button", onClick: () => choose('essential', onEssentialOnly), className: SECONDARY_BUTTON_CLASS, children: "Essential only" }), _jsx("button", { type: "button", onClick: () => choose('all', onAcceptAll), className: PRIMARY_BUTTON_CLASS, children: "Accept all" })] })] }), managing && (_jsxs("div", { id: panelId, className: "flex flex-col gap-3 border-t border-zinc-200 pt-4", children: [_jsxs("fieldset", { className: "flex flex-col gap-2", children: [_jsx("legend", { className: "text-sm font-medium text-zinc-800", children: "Cookie preferences" }), _jsxs("label", { className: "flex items-start gap-2.5", children: [_jsx("input", { type: "checkbox", checked: true, disabled: true, className: "mt-0.5 h-4 w-4 rounded border-zinc-300" }), _jsxs("span", { className: "flex flex-col", children: [_jsx("span", { className: "text-sm font-medium text-zinc-500", children: "Essential" }), _jsx("span", { className: "text-xs text-zinc-500", children: "Required for the site to work. Always on." })] })] }), CONSENT_CATEGORIES.map((category) => (_jsxs("label", { className: "flex items-start gap-2.5", children: [_jsx("input", { type: "checkbox", checked: selected.includes(category), onChange: () => toggleCategory(category), className: "mt-0.5 h-4 w-4 rounded border-zinc-300 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-900" }), _jsxs("span", { className: "flex flex-col", children: [_jsx("span", { className: "text-sm font-medium text-zinc-800", children: CATEGORY_COPY[category].label }), _jsx("span", { className: "text-xs text-zinc-500", children: CATEGORY_COPY[category].description })] })] }, category)))] }), _jsx("div", { children: _jsx("button", { type: "button", onClick: savePreferences, className: PRIMARY_BUTTON_CLASS, children: "Save preferences" }) })] }))] }) }));
54
+ }
55
+ //# sourceMappingURL=ConsentBanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConsentBanner.js","sourceRoot":"","sources":["../src/ConsentBanner.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAc9D,MAAM,eAAe,GACnB,iJAAiJ,CAAA;AAEnJ,MAAM,aAAa,GAAoE;IACrF,SAAS,EAAE;QACT,KAAK,EAAE,WAAW;QAClB,WAAW,EAAE,2CAA2C;KACzD;IACD,SAAS,EAAE;QACT,KAAK,EAAE,WAAW;QAClB,WAAW,EAAE,qCAAqC;KACnD;IACD,UAAU,EAAE;QACV,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,mDAAmD;KACjE;IACD,WAAW,EAAE;QACX,KAAK,EAAE,aAAa;QACpB,WAAW,EAAE,8CAA8C;KAC5D;CACF,CAAA;AAED,MAAM,UAAU,GACd,oLAAoL,CAAA;AAEtL,MAAM,sBAAsB,GAC1B,uNAAuN,CAAA;AAEzN,MAAM,oBAAoB,GACxB,iMAAiM,CAAA;AAEnM,iFAAiF;AACjF,MAAM,UAAU,aAAa,CAAC,EAC5B,UAAU,EACV,QAAQ,EACR,OAAO,GAAG,eAAe,EACzB,SAAS,GAAG,EAAE,EACd,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,CAAC,EACxC,SAAS,EAAC,oJAAoJ,GAC9J,EACF,gBAAM,SAAS,EAAC,eAAe,aAC7B,eAAM,SAAS,EAAC,mCAAmC,YAChD,aAAa,CAAC,QAAQ,CAAC,CAAC,KAAK,GACzB,EACP,eAAM,SAAS,EAAC,uBAAuB,YACpC,aAAa,CAAC,QAAQ,CAAC,CAAC,WAAW,GAC/B,IACF,KAdG,QAAQ,CAeZ,CACT,CAAC,IACO,EACX,wBACE,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,oBAAoB,iCAEtE,GACL,IACF,CACP,IACG,GACF,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ConsentAnalyticsConfig } from './types.js';
2
+ interface ConsentRootProps {
3
+ analytics?: ConsentAnalyticsConfig;
4
+ privacyUrl: string;
5
+ termsUrl?: string;
6
+ message?: string;
7
+ className?: string;
8
+ }
9
+ /** Site-wide consent shell: banner + analytics loader. Mount once in the public layout. */
10
+ export declare function ConsentRoot({ analytics, privacyUrl, termsUrl, message, className, }: ConsentRootProps): React.ReactNode;
11
+ export {};
12
+ //# sourceMappingURL=ConsentRoot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConsentRoot.d.ts","sourceRoot":"","sources":["../src/ConsentRoot.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAA8B,MAAM,YAAY,CAAA;AAGpF,UAAU,gBAAgB;IACxB,SAAS,CAAC,EAAE,sBAAsB,CAAA;IAClC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AASD,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,EAC1B,SAAS,EACT,UAAU,EACV,QAAQ,EACR,OAAO,EACP,SAAS,GACV,EAAE,gBAAgB,GAAG,KAAK,CAAC,SAAS,CA8CpC"}
@@ -0,0 +1,38 @@
1
+ 'use client';
2
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useState } from 'react';
4
+ import { loadConsentGatedAnalytics } from './analytics.js';
5
+ import { dispatchConsentEvent } from './events.js';
6
+ import { categoriesForLevel, readConsentState } from './storage.js';
7
+ import { ConsentBanner } from './ConsentBanner.js';
8
+ function applyAnalytics(state, analytics) {
9
+ if (analytics) {
10
+ // Per-category gating happens inside the loader (analytics vs marketing).
11
+ loadConsentGatedAnalytics(analytics, state);
12
+ }
13
+ }
14
+ /** Site-wide consent shell: banner + analytics loader. Mount once in the public layout. */
15
+ export function ConsentRoot({ analytics, privacyUrl, termsUrl, message, className, }) {
16
+ const [state, setState] = useState(null);
17
+ const [ready, setReady] = useState(false);
18
+ useEffect(() => {
19
+ const stored = readConsentState();
20
+ setState(stored);
21
+ setReady(true);
22
+ if (stored) {
23
+ dispatchConsentEvent(stored.level, stored.categories);
24
+ applyAnalytics(stored, analytics);
25
+ }
26
+ }, [analytics]);
27
+ const handleState = useCallback((next) => {
28
+ setState(next);
29
+ applyAnalytics(next, analytics);
30
+ }, [analytics]);
31
+ const handleLevel = useCallback((level) => {
32
+ handleState({ level, categories: categoriesForLevel(level) });
33
+ }, [handleState]);
34
+ if (!ready)
35
+ return null;
36
+ return (_jsx(_Fragment, { children: state === null && (_jsx(ConsentBanner, { privacyUrl: privacyUrl, termsUrl: termsUrl, message: message, className: className, onAcceptAll: () => handleLevel('all'), onEssentialOnly: () => handleLevel('essential'), onSavePreferences: handleState })) }));
37
+ }
38
+ //# sourceMappingURL=ConsentRoot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConsentRoot.js","sourceRoot":"","sources":["../src/ConsentRoot.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAA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AAG,WAAW,CAC7B,CAAC,KAAmB,EAAE,EAAE;QACtB,WAAW,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAC/D,CAAC,EACD,CAAC,WAAW,CAAC,CACd,CAAA;IAED,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IAEvB,OAAO,CACL,4BACG,KAAK,KAAK,IAAI,IAAI,CACjB,KAAC,aAAa,IACZ,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EACrC,eAAe,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,EAC/C,iBAAiB,EAAE,WAAW,GAC9B,CACH,GACA,CACJ,CAAA;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { ConsentAnalyticsConfig, ConsentState } from './types.js';
2
+ declare global {
3
+ interface Window {
4
+ dataLayer?: unknown[];
5
+ gtag?: (...args: unknown[]) => void;
6
+ fbq?: (...args: unknown[]) => void;
7
+ _fbq?: (...args: unknown[]) => void;
8
+ }
9
+ }
10
+ /**
11
+ * Inject third-party analytics tags for the granted categories. Idempotent.
12
+ *
13
+ * GA4 and Google Ads require the `analytics` category; Meta Pixel requires
14
+ * `marketing`. Omitting `state` preserves the legacy contract ("call only
15
+ * when consent is `'all'`") and loads everything configured.
16
+ */
17
+ export declare function loadConsentGatedAnalytics(config: ConsentAnalyticsConfig, state?: ConsentState): void;
18
+ /** Reset loaded flags — for tests only. */
19
+ export declare function resetAnalyticsLoadStateForTests(): void;
20
+ //# sourceMappingURL=analytics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEtE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,SAAS,CAAC,EAAE,OAAO,EAAE,CAAA;QACrB,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;QACnC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;QAClC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;KACpC;CACF;AAuED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,sBAAsB,EAC9B,KAAK,CAAC,EAAE,YAAY,GACnB,IAAI,CAON;AAED,2CAA2C;AAC3C,wBAAgB,+BAA+B,IAAI,IAAI,CAItD"}
@@ -0,0 +1,89 @@
1
+ import { hasCategoryConsent } from './storage.js';
2
+ const loaded = {
3
+ ga4: false,
4
+ googleAds: false,
5
+ meta: false,
6
+ };
7
+ function appendScript(src, id) {
8
+ const script = document.createElement('script');
9
+ script.async = true;
10
+ script.src = src;
11
+ if (id)
12
+ script.id = id;
13
+ document.head.appendChild(script);
14
+ return script;
15
+ }
16
+ function loadGa4(measurementId) {
17
+ if (loaded.ga4 || !measurementId)
18
+ return;
19
+ loaded.ga4 = true;
20
+ window.dataLayer = window.dataLayer ?? [];
21
+ window.gtag = function gtag(...args) {
22
+ window.dataLayer.push(args);
23
+ };
24
+ window.gtag('js', new Date());
25
+ appendScript(`https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(measurementId)}`);
26
+ window.gtag('config', measurementId, { anonymize_ip: true });
27
+ }
28
+ function loadGoogleAds(conversionId) {
29
+ if (loaded.googleAds || !conversionId)
30
+ return;
31
+ loaded.googleAds = true;
32
+ window.dataLayer = window.dataLayer ?? [];
33
+ window.gtag =
34
+ window.gtag ??
35
+ function gtag(...args) {
36
+ window.dataLayer.push(args);
37
+ };
38
+ appendScript(`https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(conversionId)}`);
39
+ window.gtag('config', conversionId);
40
+ }
41
+ function loadMetaPixel(pixelId) {
42
+ if (loaded.meta || !pixelId)
43
+ return;
44
+ loaded.meta = true;
45
+ const n = function fbq(...args) {
46
+ if (n.callMethod) {
47
+ n.callMethod(...args);
48
+ }
49
+ else {
50
+ n.queue.push(args);
51
+ }
52
+ };
53
+ window.fbq = n;
54
+ if (!window._fbq)
55
+ window._fbq = n;
56
+ n.push = n;
57
+ n.loaded = true;
58
+ n.version = '2.0';
59
+ n.queue = [];
60
+ appendScript('https://connect.facebook.net/en_US/fbevents.js');
61
+ window.fbq('init', pixelId);
62
+ window.fbq('track', 'PageView');
63
+ }
64
+ /**
65
+ * Inject third-party analytics tags for the granted categories. Idempotent.
66
+ *
67
+ * GA4 and Google Ads require the `analytics` category; Meta Pixel requires
68
+ * `marketing`. Omitting `state` preserves the legacy contract ("call only
69
+ * when consent is `'all'`") and loads everything configured.
70
+ */
71
+ export function loadConsentGatedAnalytics(config, state) {
72
+ if (typeof document === 'undefined')
73
+ return;
74
+ const analyticsGranted = state ? hasCategoryConsent(state, 'analytics') : true;
75
+ const marketingGranted = state ? hasCategoryConsent(state, 'marketing') : true;
76
+ if (analyticsGranted && config.ga4MeasurementId)
77
+ loadGa4(config.ga4MeasurementId);
78
+ if (analyticsGranted && config.googleAdsId)
79
+ loadGoogleAds(config.googleAdsId);
80
+ if (marketingGranted && config.metaPixelId)
81
+ loadMetaPixel(config.metaPixelId);
82
+ }
83
+ /** Reset loaded flags — for tests only. */
84
+ export function resetAnalyticsLoadStateForTests() {
85
+ loaded.ga4 = false;
86
+ loaded.googleAds = false;
87
+ loaded.meta = false;
88
+ }
89
+ //# sourceMappingURL=analytics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics.js","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,c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,CACvC,MAA8B,EAC9B,KAAoB;IAEpB,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAM;IAC3C,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC9E,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC9E,IAAI,gBAAgB,IAAI,MAAM,CAAC,gBAAgB;QAAE,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;IACjF,IAAI,gBAAgB,IAAI,MAAM,CAAC,WAAW;QAAE,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAC7E,IAAI,gBAAgB,IAAI,MAAM,CAAC,WAAW;QAAE,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;AAC/E,CAAC;AAED,2CAA2C;AAC3C,MAAM,UAAU,+BAA+B;IAC7C,MAAM,CAAC,GAAG,GAAG,KAAK,CAAA;IAClB,MAAM,CAAC,SAAS,GAAG,KAAK,CAAA;IACxB,MAAM,CAAC,IAAI,GAAG,KAAK,CAAA;AACrB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ConsentCategory } from './types.js';
2
+ /** localStorage key for the visitor's cookie/analytics consent choice. */
3
+ export declare const CONSENT_STORAGE_KEY = "am_cookie_consent";
4
+ /** Window event name dispatched when consent is saved or restored. */
5
+ export declare const CONSENT_EVENT = "am-consent";
6
+ /** All optional cookie categories a visitor can grant individually. */
7
+ export declare const CONSENT_CATEGORIES: readonly ConsentCategory[];
8
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,0EAA0E;AAC1E,eAAO,MAAM,mBAAmB,sBAAsB,CAAA;AAEtD,sEAAsE;AACtE,eAAO,MAAM,aAAa,eAAe,CAAA;AAEzC,uEAAuE;AACvE,eAAO,MAAM,kBAAkB,EAAE,SAAS,eAAe,EAKxD,CAAA"}
@@ -0,0 +1,12 @@
1
+ /** localStorage key for the visitor's cookie/analytics consent choice. */
2
+ export const CONSENT_STORAGE_KEY = 'am_cookie_consent';
3
+ /** Window event name dispatched when consent is saved or restored. */
4
+ export const CONSENT_EVENT = 'am-consent';
5
+ /** All optional cookie categories a visitor can grant individually. */
6
+ export const CONSENT_CATEGORIES = [
7
+ 'analytics',
8
+ 'marketing',
9
+ 'functional',
10
+ 'preferences',
11
+ ];
12
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAA;AAEtD,sEAAsE;AACtE,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAA;AAEzC,uEAAuE;AACvE,MAAM,CAAC,MAAM,kBAAkB,GAA+B;IAC5D,WAAW;IACX,WAAW;IACX,YAAY;IACZ,aAAa;CACd,CAAA"}
@@ -0,0 +1,17 @@
1
+ import type { ConsentCategory, ConsentLevel, ConsentState } from './types.js';
2
+ /** Dispatch the canonical `am-consent` window event. */
3
+ export declare function dispatchConsentEvent(level: ConsentLevel, categories?: ConsentCategory[]): void;
4
+ /** Save consent, dispatch `am-consent`, and return the level. */
5
+ export declare function setConsent(level: ConsentLevel): ConsentLevel;
6
+ /**
7
+ * Save a custom per-category selection ("Manage preferences"). The selection
8
+ * is canonicalized: all categories → `'all'`, none → `'essential'`.
9
+ */
10
+ export declare function setConsentCategories(categories: readonly ConsentCategory[]): ConsentState;
11
+ /** Subscribe to consent changes (including the initial restored value on mount). */
12
+ export declare function onConsent(listener: (level: ConsentLevel, categories: ConsentCategory[]) => void): () => void;
13
+ /** Resolve when the visitor has chosen a consent level (or immediately if already set). */
14
+ export declare function waitForConsent(): Promise<ConsentLevel>;
15
+ /** Resolve with the full consent state once the visitor has chosen. */
16
+ export declare function waitForConsentState(): Promise<ConsentState>;
17
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAsB,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEjG,wDAAwD;AACxD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,CAAC,EAAE,eAAe,EAAE,GAAG,IAAI,CAO9F;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY,CAI5D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,SAAS,eAAe,EAAE,GAAG,YAAY,CAIzF;AAED,oFAAoF;AACpF,wBAAgB,SAAS,CACvB,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,IAAI,GACrE,MAAM,IAAI,CAcZ;AAED,2FAA2F;AAC3F,wBAAgB,cAAc,IAAI,OAAO,CAAC,YAAY,CAAC,CActD;AAED,uEAAuE;AACvE,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,YAAY,CAAC,CAc3D"}
package/dist/events.js ADDED
@@ -0,0 +1,73 @@
1
+ import { CONSENT_EVENT } from './constants.js';
2
+ import { categoriesForLevel, normalizeConsentSelection, readConsentState, writeConsentState, } from './storage.js';
3
+ /** Dispatch the canonical `am-consent` window event. */
4
+ export function dispatchConsentEvent(level, categories) {
5
+ if (typeof window === 'undefined')
6
+ return;
7
+ const detail = {
8
+ level,
9
+ categories: categories ?? categoriesForLevel(level),
10
+ };
11
+ window.dispatchEvent(new CustomEvent(CONSENT_EVENT, { detail }));
12
+ }
13
+ /** Save consent, dispatch `am-consent`, and return the level. */
14
+ export function setConsent(level) {
15
+ const state = writeConsentState({ level, categories: categoriesForLevel(level) });
16
+ dispatchConsentEvent(state.level, state.categories);
17
+ return state.level;
18
+ }
19
+ /**
20
+ * Save a custom per-category selection ("Manage preferences"). The selection
21
+ * is canonicalized: all categories → `'all'`, none → `'essential'`.
22
+ */
23
+ export function setConsentCategories(categories) {
24
+ const state = writeConsentState(normalizeConsentSelection(categories));
25
+ dispatchConsentEvent(state.level, state.categories);
26
+ return state;
27
+ }
28
+ /** Subscribe to consent changes (including the initial restored value on mount). */
29
+ export function onConsent(listener) {
30
+ if (typeof window === 'undefined')
31
+ return () => undefined;
32
+ const handler = (event) => {
33
+ const detail = event.detail;
34
+ if (detail?.level)
35
+ listener(detail.level, detail.categories ?? categoriesForLevel(detail.level));
36
+ };
37
+ window.addEventListener(CONSENT_EVENT, handler);
38
+ const existing = readConsentState();
39
+ if (existing)
40
+ listener(existing.level, existing.categories);
41
+ return () => window.removeEventListener(CONSENT_EVENT, handler);
42
+ }
43
+ /** Resolve when the visitor has chosen a consent level (or immediately if already set). */
44
+ export function waitForConsent() {
45
+ const existing = readConsentState();
46
+ if (existing)
47
+ return Promise.resolve(existing.level);
48
+ if (typeof window === 'undefined') {
49
+ return Promise.resolve('essential');
50
+ }
51
+ return new Promise((resolve) => {
52
+ const off = onConsent((level) => {
53
+ off();
54
+ resolve(level);
55
+ });
56
+ });
57
+ }
58
+ /** Resolve with the full consent state once the visitor has chosen. */
59
+ export function waitForConsentState() {
60
+ const existing = readConsentState();
61
+ if (existing)
62
+ return Promise.resolve(existing);
63
+ if (typeof window === 'undefined') {
64
+ return Promise.resolve({ level: 'essential', categories: [] });
65
+ }
66
+ return new Promise((resolve) => {
67
+ const off = onConsent((level, categories) => {
68
+ off();
69
+ resolve({ level, categories });
70
+ });
71
+ });
72
+ }
73
+ //# sourceMappingURL=events.js.map
@@ -0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I,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAA;IAChE,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;YAC1C,GAAG,EAAE,CAAA;YACL,OAAO,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAA;QAChC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { type PluginDefinition } from '@prenta/core/config';
2
+ export interface ConsentPluginConfig {
3
+ /** Default privacy policy path linked from the banner. */
4
+ privacyUrl?: string;
5
+ /** Optional terms path linked from the banner. */
6
+ termsUrl?: string;
7
+ }
8
+ /**
9
+ * Registers the consent plugin marker in `prenta.config.ts`.
10
+ * Public UI is wired in the site layout via `<ConsentRoot />` from this package.
11
+ */
12
+ export declare function consentPlugin(config?: ConsentPluginConfig): PluginDefinition;
13
+ export { CONSENT_CATEGORIES, CONSENT_EVENT, CONSENT_STORAGE_KEY } from './constants.js';
14
+ export { dispatchConsentEvent, onConsent, setConsent, setConsentCategories, waitForConsent, waitForConsentState, } from './events.js';
15
+ export { categoriesForLevel, hasAnalyticsConsent, hasCategoryConsent, normalizeConsentSelection, readConsent, readConsentState, writeConsent, writeConsentState, } from './storage.js';
16
+ export { loadConsentGatedAnalytics, resetAnalyticsLoadStateForTests } from './analytics.js';
17
+ export { ConsentBanner } from './ConsentBanner.js';
18
+ export { ConsentRoot } from './ConsentRoot.js';
19
+ export { useConsent } from './useConsent.js';
20
+ export type { ConsentAnalyticsConfig, ConsentCategory, ConsentEventDetail, ConsentLevel, ConsentLinks, ConsentRootProps, ConsentState, } from './types.js';
21
+ export type { ConsentBannerProps } from './ConsentBanner.js';
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEzE,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,GAAE,mBAAwB,GAAG,gBAAgB,CAKhF;AAED,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACvF,OAAO,EACL,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,oBAAoB,EACpB,cAAc,EACd,mBAAmB,GACpB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,yBAAyB,EACzB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,GAClB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,yBAAyB,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,YAAY,EACV,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,YAAY,GACb,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ import { definePlugin } from '@prenta/core/config';
2
+ /**
3
+ * Registers the consent plugin marker in `prenta.config.ts`.
4
+ * Public UI is wired in the site layout via `<ConsentRoot />` from this package.
5
+ */
6
+ export function consentPlugin(config = {}) {
7
+ void config;
8
+ return definePlugin({
9
+ name: 'plugin-consent',
10
+ });
11
+ }
12
+ export { CONSENT_CATEGORIES, CONSENT_EVENT, CONSENT_STORAGE_KEY } from './constants.js';
13
+ export { dispatchConsentEvent, onConsent, setConsent, setConsentCategories, waitForConsent, waitForConsentState, } from './events.js';
14
+ export { categoriesForLevel, hasAnalyticsConsent, hasCategoryConsent, normalizeConsentSelection, readConsent, readConsentState, writeConsent, writeConsentState, } from './storage.js';
15
+ export { loadConsentGatedAnalytics, resetAnalyticsLoadStateForTests } from './analytics.js';
16
+ export { ConsentBanner } from './ConsentBanner.js';
17
+ export { ConsentRoot } from './ConsentRoot.js';
18
+ export { useConsent } from './useConsent.js';
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,qBAAqB,CAAA;AASzE;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,SAA8B,EAAE;IAC5D,KAAK,MAAM,CAAA;IACX,OAAO,YAAY,CAAC;QAClB,IAAI,EAAE,gBAAgB;KACvB,CAAC,CAAA;AACJ,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACvF,OAAO,EACL,oBAAoB,EACpB,SAAS,EACT,UAAU,EACV,oBAAoB,EACpB,cAAc,EACd,mBAAmB,GACpB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,yBAAyB,EACzB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,GAClB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,yBAAyB,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAA;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA"}
@@ -0,0 +1,25 @@
1
+ import type { ConsentCategory, ConsentLevel, ConsentState } from './types.js';
2
+ /** The category set implied by a level (`custom` carries its own set). */
3
+ export declare function categoriesForLevel(level: ConsentLevel): ConsentCategory[];
4
+ /**
5
+ * Canonicalize a category selection: the full set is `'all'`, the empty set
6
+ * is `'essential'`, anything else is `'custom'` with the (deduplicated,
7
+ * validated) categories.
8
+ */
9
+ export declare function normalizeConsentSelection(categories: readonly ConsentCategory[]): ConsentState;
10
+ /** Read the full persisted consent state. Returns `null` when unset or unavailable. */
11
+ export declare function readConsentState(): ConsentState | null;
12
+ /** Read persisted consent level from `localStorage`. Returns `null` when unset or unavailable. */
13
+ export declare function readConsent(): ConsentLevel | null;
14
+ /** Persist a full consent state and return it. */
15
+ export declare function writeConsentState(state: ConsentState): ConsentState;
16
+ /** Persist consent and return the stored level. */
17
+ export declare function writeConsent(level: ConsentLevel): ConsentLevel;
18
+ /**
19
+ * True when a specific optional category is granted (by `'all'` or by a
20
+ * custom selection that includes it).
21
+ */
22
+ export declare function hasCategoryConsent(state: ConsentState | ConsentLevel | null, category: ConsentCategory): boolean;
23
+ /** True when analytics scripts may load (`'all'` or a custom grant including `analytics`). */
24
+ export declare function hasAnalyticsConsent(state: ConsentState | ConsentLevel | null): boolean;
25
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAgB7E,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,eAAe,EAAE,CAGzE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,SAAS,eAAe,EAAE,GAAG,YAAY,CAS9F;AAmBD,uFAAuF;AACvF,wBAAgB,gBAAgB,IAAI,YAAY,GAAG,IAAI,CAStD;AAED,kGAAkG;AAClG,wBAAgB,WAAW,IAAI,YAAY,GAAG,IAAI,CAEjD;AAED,kDAAkD;AAClD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY,CAanE;AAED,mDAAmD;AACnD,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY,CAE9D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI,EACzC,QAAQ,EAAE,eAAe,GACxB,OAAO,CAMT;AAED,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI,GAAG,OAAO,CAEtF"}
@@ -0,0 +1,110 @@
1
+ import { CONSENT_CATEGORIES, CONSENT_STORAGE_KEY } from './constants.js';
2
+ /**
3
+ * Storage format (key `am_cookie_consent`):
4
+ *
5
+ * - `'all'` / `'essential'` — legacy plain strings, still written for those
6
+ * two levels so cached pages carrying the older consent-gate wrapper (which
7
+ * string-compares the raw value) keep working.
8
+ * - `'{"level":"custom","categories":[...]}'` — JSON, written only for
9
+ * custom per-category selections.
10
+ */
11
+ function isConsentCategory(value) {
12
+ return CONSENT_CATEGORIES.includes(value);
13
+ }
14
+ /** The category set implied by a level (`custom` carries its own set). */
15
+ export function categoriesForLevel(level) {
16
+ if (level === 'all')
17
+ return [...CONSENT_CATEGORIES];
18
+ return [];
19
+ }
20
+ /**
21
+ * Canonicalize a category selection: the full set is `'all'`, the empty set
22
+ * is `'essential'`, anything else is `'custom'` with the (deduplicated,
23
+ * validated) categories.
24
+ */
25
+ export function normalizeConsentSelection(categories) {
26
+ const granted = CONSENT_CATEGORIES.filter((c) => categories.includes(c));
27
+ if (granted.length === CONSENT_CATEGORIES.length) {
28
+ return { level: 'all', categories: granted };
29
+ }
30
+ if (granted.length === 0) {
31
+ return { level: 'essential', categories: [] };
32
+ }
33
+ return { level: 'custom', categories: granted };
34
+ }
35
+ function parseStoredValue(raw) {
36
+ if (raw === 'all')
37
+ return { level: 'all', categories: [...CONSENT_CATEGORIES] };
38
+ if (raw === 'essential')
39
+ return { level: 'essential', categories: [] };
40
+ if (!raw.startsWith('{'))
41
+ return null;
42
+ try {
43
+ const parsed = JSON.parse(raw);
44
+ if (!parsed || typeof parsed !== 'object')
45
+ return null;
46
+ const categories = parsed.categories;
47
+ if (!Array.isArray(categories))
48
+ return null;
49
+ // Re-normalize so a tampered/hand-edited value still yields a canonical
50
+ // state (e.g. all four categories in JSON form → level 'all').
51
+ return normalizeConsentSelection(categories.filter(isConsentCategory));
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ }
57
+ /** Read the full persisted consent state. Returns `null` when unset or unavailable. */
58
+ export function readConsentState() {
59
+ if (typeof window === 'undefined')
60
+ return null;
61
+ try {
62
+ const raw = window.localStorage.getItem(CONSENT_STORAGE_KEY);
63
+ if (!raw)
64
+ return null;
65
+ return parseStoredValue(raw);
66
+ }
67
+ catch {
68
+ return null;
69
+ }
70
+ }
71
+ /** Read persisted consent level from `localStorage`. Returns `null` when unset or unavailable. */
72
+ export function readConsent() {
73
+ return readConsentState()?.level ?? null;
74
+ }
75
+ /** Persist a full consent state and return it. */
76
+ export function writeConsentState(state) {
77
+ if (typeof window !== 'undefined') {
78
+ try {
79
+ const raw = state.level === 'custom'
80
+ ? JSON.stringify({ level: 'custom', categories: state.categories })
81
+ : state.level;
82
+ window.localStorage.setItem(CONSENT_STORAGE_KEY, raw);
83
+ }
84
+ catch {
85
+ // Private browsing / blocked storage — still dispatch so in-memory listeners work.
86
+ }
87
+ }
88
+ return state;
89
+ }
90
+ /** Persist consent and return the stored level. */
91
+ export function writeConsent(level) {
92
+ return writeConsentState({ level, categories: categoriesForLevel(level) }).level;
93
+ }
94
+ /**
95
+ * True when a specific optional category is granted (by `'all'` or by a
96
+ * custom selection that includes it).
97
+ */
98
+ export function hasCategoryConsent(state, category) {
99
+ if (state === null)
100
+ return false;
101
+ if (typeof state === 'string') {
102
+ return state === 'all';
103
+ }
104
+ return state.level === 'all' || state.categories.includes(category);
105
+ }
106
+ /** True when analytics scripts may load (`'all'` or a custom grant including `analytics`). */
107
+ export function hasAnalyticsConsent(state) {
108
+ return hasCategoryConsent(state, 'analytics');
109
+ }
110
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAGxE;;;;;;;;GAQG;AAEH,SAAS,iBAAiB,CAAC,KAAc;IACvC,OAAQ,kBAAwC,CAAC,QAAQ,CAAC,KAAe,CAAC,CAAA;AAC5E,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,kBAAkB,CAAC,KAAmB;IACpD,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,CAAC,GAAG,kBAAkB,CAAC,CAAA;IACnD,OAAO,EAAE,CAAA;AACX,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAsC;IAC9E,MAAM,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IACxE,IAAI,OAAO,CAAC,MAAM,KAAK,kBAAkB,CAAC,MAAM,EAAE,CAAC;QACjD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,CAAA;IAC9C,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,KAAK,EAAE,WAAW,EAA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,mBAAmB,CAAC,KAAyC;IAC3E,OAAO,kBAAkB,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;AAC/C,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Visitor consent level.
3
+ *
4
+ * - `'all'` — every category granted.
5
+ * - `'essential'` — only strictly-necessary cookies; no optional categories.
6
+ * - `'custom'` — the visitor picked individual categories via "Manage
7
+ * preferences"; the granted set travels alongside as `ConsentCategory[]`.
8
+ */
9
+ export type ConsentLevel = 'all' | 'essential' | 'custom';
10
+ /**
11
+ * Optional cookie categories a visitor can grant individually. Mirrors
12
+ * `SCRIPT_TAG_CONSENT_CATEGORIES` in cms-core (minus `none`, which means
13
+ * "no gate").
14
+ */
15
+ export type ConsentCategory = 'analytics' | 'marketing' | 'functional' | 'preferences';
16
+ /** Full consent decision: level plus the granted category set. */
17
+ export interface ConsentState {
18
+ level: ConsentLevel;
19
+ categories: ConsentCategory[];
20
+ }
21
+ export interface ConsentEventDetail {
22
+ level: ConsentLevel;
23
+ /** Granted categories — present since the granular-consent release. */
24
+ categories?: ConsentCategory[];
25
+ }
26
+ export interface ConsentAnalyticsConfig {
27
+ /** GA4 measurement ID (e.g. `G-XXXXXXXX`). Requires the `analytics` category. */
28
+ ga4MeasurementId?: string;
29
+ /** Google Ads conversion/tag ID (e.g. `AW-XXXXXXXX`). Requires the `analytics` category. */
30
+ googleAdsId?: string;
31
+ /** Meta Pixel ID. Requires the `marketing` category. */
32
+ metaPixelId?: string;
33
+ }
34
+ export interface ConsentLinks {
35
+ privacyUrl: string;
36
+ termsUrl?: string;
37
+ }
38
+ export interface ConsentRootProps extends ConsentLinks {
39
+ analytics?: ConsentAnalyticsConfig;
40
+ /** Override banner copy (first paragraph). */
41
+ message?: string;
42
+ className?: string;
43
+ }
44
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,WAAW,GAAG,QAAQ,CAAA;AAEzD;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,WAAW,GAAG,YAAY,GAAG,aAAa,CAAA;AAEtF,kEAAkE;AAClE,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,YAAY,CAAA;IACnB,UAAU,EAAE,eAAe,EAAE,CAAA;CAC9B;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,YAAY,CAAA;IACnB,uEAAuE;IACvE,UAAU,CAAC,EAAE,eAAe,EAAE,CAAA;CAC/B;AAED,MAAM,WAAW,sBAAsB;IACrC,iFAAiF;IACjF,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,4FAA4F;IAC5F,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IACpD,SAAS,CAAC,EAAE,sBAAsB,CAAA;IAClC,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { ConsentCategory, ConsentLevel } from './types.js';
2
+ /** React hook for sticky CTAs, modals, or custom widgets that must wait for consent. */
3
+ export declare function useConsent(): {
4
+ level: ConsentLevel | null;
5
+ categories: ConsentCategory[];
6
+ ready: boolean;
7
+ allowsAnalytics: boolean;
8
+ allows: (category: ConsentCategory) => boolean;
9
+ };
10
+ //# sourceMappingURL=useConsent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConsent.d.ts","sourceRoot":"","sources":["../src/useConsent.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAgB,MAAM,YAAY,CAAA;AAE7E,wFAAwF;AACxF,wBAAgB,UAAU,IAAI;IAC5B,KAAK,EAAE,YAAY,GAAG,IAAI,CAAA;IAC1B,UAAU,EAAE,eAAe,EAAE,CAAA;IAC7B,KAAK,EAAE,OAAO,CAAA;IACd,eAAe,EAAE,OAAO,CAAA;IACxB,MAAM,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAA;CAC/C,CAsBA"}
@@ -0,0 +1,23 @@
1
+ 'use client';
2
+ import { useCallback, useEffect, useState } from 'react';
3
+ import { onConsent } from './events.js';
4
+ import { hasCategoryConsent, readConsentState } from './storage.js';
5
+ /** React hook for sticky CTAs, modals, or custom widgets that must wait for consent. */
6
+ export function useConsent() {
7
+ const [state, setState] = useState(null);
8
+ const [ready, setReady] = useState(false);
9
+ useEffect(() => {
10
+ setState(readConsentState());
11
+ setReady(true);
12
+ return onConsent((level, categories) => setState({ level, categories }));
13
+ }, []);
14
+ const allows = useCallback((category) => hasCategoryConsent(state, category), [state]);
15
+ return {
16
+ level: state?.level ?? null,
17
+ categories: state?.categories ?? [],
18
+ ready,
19
+ allowsAnalytics: hasCategoryConsent(state, 'analytics'),
20
+ allows,
21
+ };
22
+ }
23
+ //# sourceMappingURL=useConsent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConsent.js","sourceRoot":"","sources":["../src/useConsent.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAGnE,wFAAwF;AACxF,MAAM,UAAU,UAAU;IAOxB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAsB,IAAI,CAAC,CAAA;IAC7D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAEzC,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,gBAAgB,EAAE,CAAC,CAAA;QAC5B,QAAQ,CAAC,IAAI,CAAC,CAAA;QACd,OAAO,SAAS,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;IAC1E,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,MAAM,GAAG,WAAW,CACxB,CAAC,QAAyB,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,EAClE,CAAC,KAAK,CAAC,CACR,CAAA;IAED,OAAO;QACL,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI,IAAI;QAC3B,UAAU,EAAE,KAAK,EAAE,UAAU,IAAI,EAAE;QACnC,KAAK;QACL,eAAe,EAAE,kBAAkB,CAAC,KAAK,EAAE,WAAW,CAAC;QACvD,MAAM;KACP,CAAA;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@prenta/plugin-consent",
3
+ "version": "0.4.0",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/actuate-media/prenta.git",
8
+ "directory": "packages/plugin-consent"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "main": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "files": [
24
+ "dist",
25
+ "CHANGELOG.md",
26
+ "README.md"
27
+ ],
28
+ "peerDependencies": {
29
+ "@prenta/core": ">=0.1.0",
30
+ "react": "^18.0.0 || ^19.0.0",
31
+ "react-dom": "^18.0.0 || ^19.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/react": "^19.0.0",
35
+ "@types/react-dom": "^19.0.0",
36
+ "react": "^19.2.0",
37
+ "react-dom": "^19.2.0",
38
+ "typescript": "^5.7.0",
39
+ "vitest": "^4.1.0",
40
+ "@prenta/core": "0.118.0"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc --project tsconfig.json",
44
+ "type-check": "tsc --noEmit",
45
+ "test": "vitest run",
46
+ "clean": "rm -rf dist .turbo"
47
+ }
48
+ }