JA
ベータ版の翻訳

@core / consent

1.1.1 ▾
認証済みMIT
GitHub

GDPR クッキー同意:拒否と同意を同等に扱うバナー、カテゴリ、同意記録、ConsentGate、Consent Mode v2

コード9 ファイルコンテキスト約 743 トークンスキャン合格

インストール

$genpm add @core/consent

含まれるもの

  • src/lib/consent/ にソースコード(9 ファイル)。 (22.3 KB)
  • src/lib/consent/AGENTS.md に AI ルール、加えて IDE 用のルールファイル。
  • .env.example に追加される環境変数: CONSENT_POLICY_VERSION, SITE_URL, CONSENT_COOKIE_DOMAIN。
  • @core/db を自動で解決します。

README

genpm license

GDPR cookie consent: banner with equal reject/accept, categories, proof records, ConsentGate and Google Consent Mode v2

A GenPM module: source code + AI rules + MCP config, injected into your project instead of hidden in node_modules. The code lands in src/lib/consent, pinned to a verified commit, and you own it.

Install

genpm add @core/consent

No genpm yet? curl -fsSL https://genpm.net/install.sh | sh (macOS/Linux), irm https://genpm.net/install.ps1 | iex (Windows), or one-off with npx @genpm-net/cli add @core/consent.

Or let your AI agent do it: run genpm mcp setup once, then ask "add @core/consent with genpm" in Claude Code, Cursor, VS Code, Windsurf, Codex or Gemini CLI. It shows you a dry-run plan before writing anything.

What it does

Cookie consent that meets GDPR/ePrivacy: categories (necessary always on; analytics, marketing, preferences off by default), a banner where "Reject all" is as prominent as "Accept all", a preferences center, proof of each decision (consent_records: choices, policy version, date; no IP), server checks (hasConsent), a client ConsentGate and Google Consent Mode v2 values. Changing CONSENT_POLICY_VERSION asks everyone again.

Setup

After genpm add, follow these steps (your AI agent finds the same steps in src/lib/consent/AGENTS.md and can do them for you):

  1. Env: CONSENT_POLICY_VERSION (bump it when the cookie policy changes), SITE_URL (its host gives the registrable domain where third-party tags set their cookies: the last two labels) and, when that guess is wrong (e.g. .co.uk), CONSENT_COOKIE_DOMAIN=example.co.uk. Migrations as in src/lib/db/AGENTS.md.
  2. Mount /api/consent (pass cookiesByCategory, e.g. { analytics: ['_ga'], marketing: ['_fbp', '_ttp'] }, so withdrawing deletes them, host-only and on the registrable domain). The endpoint only accepts same-origin JSON POSTs (CSRF): a cross-site Origin/Sec-Fetch-Site gets 403 and other content types 415; the banner already posts that way.
  3. Root layout: <ConsentBanner policyVersion={policyVersion()} policyHref="/cookies" labels={translated} /> and in the footer <CookieSettingsButton /> (a button that calls openConsentPreferences()). The banner also renders <meta name="consent-policy-version">: client checks treat a decision made under another version as undecided (everything off) until the visitor decides again.
  4. Wrap every analytics/marketing script: <ConsentGate category="marketing" policyVersion={policyVersion()}>…</ConsentGate> (policyVersion is optional when the banner is on the page); on the server use hasConsent(cookieHeader, 'analytics').
  5. With Google tags, render consentModeDefaultsScript(getConsent(cookieHeader)) inline before them.
  6. Verify (browser devtools): before deciding, no request goes to third-party analytics or ad domains.

What's inside

Paths are relative to src/lib/consent.

  • index.ts — server API: getConsent, hasConsent, recordConsent, consentModeDefaultsScript, consentHistory, cookieDomain.
  • react.ts — client: ConsentBanner, ConsentGate, CookieSettingsButton, openConsentPreferences, readClientConsent, currentPolicyVersion.
  • adapters/hono.ts — consentRoutes(). adapters/next.ts — consentRoute() → { GET, POST }.

At a glance

  • GenPM dependencies (installed with it): @core/db
  • npm dependencies (proposed, never installed without asking): zod, react
  • Environment variables (added to .env.example): CONSENT_POLICY_VERSION, SITE_URL, CONSENT_COOKIE_DOMAIN
  • AI rules: AGENTS.md, loaded by your agent only when it works in src/lib/consent

Security

GenPM installs a 40-character commit SHA (never a branch), verifies an Ed25519-signed manifest, never runs install scripts and scans AI rules for prompt injection. Details: genpm.net/docs/security.

License

MIT — see LICENSE. Browse the full catalog at genpm.net.

@core/consent を報告

パッケージを報告するには GitHub でログインしてください。

GitHub で続ける