{"_id":"@dengdeng0324/cookie-consent-sdk","name":"@dengdeng0324/cookie-consent-sdk","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.2":{"name":"@dengdeng0324/cookie-consent-sdk","version":"1.0.2","description":"Framework-agnostic cookie consent state machine and Lit Web Components UI","repository":{"type":"git","url":"git+https://github.com/Pubfree-Labs/cookie-consent-sdk.git"},"homepage":"https://github.com/Pubfree-Labs/cookie-consent-sdk#readme","bugs":{"url":"https://github.com/Pubfree-Labs/cookie-consent-sdk/issues"},"type":"module","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"sideEffects":true,"scripts":{"build":"tsup src/index.ts --format esm --dts --clean","prepare":"npm run build","dev":"vite demo","test":"vitest run","test:watch":"vitest","typecheck":"tsc --noEmit"},"dependencies":{"i18next":"^25.3.0","js-cookie":"^3.0.5","lit":"^3.3.0"},"devDependencies":{"@types/js-cookie":"^3.0.6","happy-dom":"^18.0.1","tsup":"^8.5.0","typescript":"^5.8.3","vite":"^7.0.0","vitest":"^3.2.4"},"engines":{"node":">=20"},"packageManager":"pnpm@10.15.0","gitHead":"e3bfdb4b9fbe957fad95ef79eecf75a5533ecfbb","_id":"@dengdeng0324/cookie-consent-sdk@1.0.2","_nodeVersion":"24.20.0","_npmVersion":"11.19.0","dist":{"integrity":"sha512-wfUmnebWayvONn+dLwIdgBzHAxb0xyZ5et+UY/NeQ4JwUTUNj08Ya6I457yF3jPCxvxN/aE46y6n/qm12VJwWQ==","shasum":"50fc756a957148b79ebe95d0ee0a95a4707c2021","tarball":"https://registry.npmjs.org/@dengdeng0324/cookie-consent-sdk/-/cookie-consent-sdk-1.0.2.tgz","fileCount":4,"unpackedSize":36585,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIF7YmSjczdM593XIAAVrASy3LjRIdrRifhPXgTmM2d+fAiA08inZemi9rFWoi1+0/KkOXBLdtIOY57jI0+ZGrGn6IQ=="}]},"_npmUser":{"name":"dengdeng0324","email":"dengd0324@gmail.com"},"directories":{},"maintainers":[{"name":"dengdeng0324","email":"dengd0324@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cookie-consent-sdk_1.0.2_1788536228398_0.1444820433465548"},"_hasShrinkwrap":false}},"time":{"created":"2026-09-04T15:37:08.253Z","1.0.2":"2026-09-04T15:37:08.528Z","modified":"2026-09-04T15:37:08.721Z"},"maintainers":[{"name":"dengdeng0324","email":"dengd0324@gmail.com"}],"description":"Framework-agnostic cookie consent state machine and Lit Web Components UI","homepage":"https://github.com/Pubfree-Labs/cookie-consent-sdk#readme","repository":{"type":"git","url":"git+https://github.com/Pubfree-Labs/cookie-consent-sdk.git"},"bugs":{"url":"https://github.com/Pubfree-Labs/cookie-consent-sdk/issues"},"readme":"# @dengdeng0324/cookie-consent-sdk\n\n一个使用 TypeScript、Lit 3 和 Shadow DOM 构建的框架无关 Cookie 同意 SDK。它负责地区模式、UI、状态持久化和明确选择上报；宿主应用根据最终状态自行控制 GA/GTM。\n\n## 快速开始\n\n```bash\npnpm add @dengdeng0324/cookie-consent-sdk\n```\n\n```ts\nimport cookieManager from '@dengdeng0324/cookie-consent-sdk';\n\nconst unsubscribe = cookieManager.onDataChange((data) => {\n  if (data.preference.analytics) {\n    // 宿主在这里加载 Analytics。\n  }\n});\n\nawait cookieManager.init({\n  language: 'zh',\n  privacyPolicyUrl: '/privacy',\n  regionEndpoint: '/api/user/region',\n  reportEndpoint: '/api/consent/report',\n});\n```\n\n可选后端契约：\n\n- `GET regionEndpoint`，5 秒超时，失败时回退 `{ countryCode: '', mode: 'opt_in' }`。\n- `POST reportEndpoint`，仅为 `accept_all` 和 `reject_all` 上报 `{ site, mode, country, choice }`。\n\nSDK 不内置任何公司域名。端点由宿主通过 `regionEndpoint`、`reportEndpoint` 传入，也可通过 `fetch` 注入 Mock；不传端点时不会发起对应网络请求。\n\n## 公共 API\n\n- `init(options)`：初始化并返回首个 `ConsentData`。\n- `onDataChange(listener)`：订阅状态，返回取消订阅函数。\n- `getData()`：获取不可变状态快照。\n- `openPreferences()`：由宿主重新打开偏好中心。\n- `update(options)`：更新语言、主题和政策链接，不重新判断地区。\n- `destroy()`：卸载 UI 并清理订阅。\n- `reset()`：删除本地同意 Cookie 并销毁实例，主要用于 QA。\n\n测试地区可传 `qaRegion: 'DE' | 'US' | 'EU' | 'notice_only'`，或使用页面参数 `?cookie_region=DE`。\n\n## 本地开发\n\n```bash\npnpm install\npnpm test\npnpm build\npnpm dev\n```\n\n自定义偏好和关闭 Notice 只写本地 Cookie，不调用上报接口。SDK 不会加载任何分析脚本。\n","readmeFilename":"README.md","_rev":"1-c18faeef1f24681ccf9616b7821a74e4"}