@consenti/ui 0.2.0 → 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/README.md +512 -138
- package/dist/angular.d.cts +610 -151
- package/dist/angular.d.ts +610 -151
- package/dist/angular.js +1 -1
- package/dist/angular.js.map +1 -1
- package/dist/angular.mjs +1 -1
- package/dist/angular.mjs.map +1 -1
- package/dist/chunk-3EXCD24H.mjs +2 -0
- package/dist/{chunk-K2UN3O67.mjs.map → chunk-3EXCD24H.mjs.map} +1 -1
- package/dist/chunk-RDE7CM6T.mjs +2 -0
- package/dist/chunk-RDE7CM6T.mjs.map +1 -0
- package/dist/http-AQVVUCX6.mjs +2 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +971 -125
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/profiles-5ZLWWN2L.mjs +2 -0
- package/dist/profiles-5ZLWWN2L.mjs.map +1 -0
- package/dist/react.d.cts +589 -129
- package/dist/react.d.ts +589 -129
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +1 -1
- package/dist/react.mjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/dist/testing.mjs.map +1 -1
- package/dist/vue.d.cts +562 -79
- package/dist/vue.d.ts +562 -79
- package/dist/vue.js +1 -1
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +1 -1
- package/dist/vue.mjs.map +1 -1
- package/package.json +13 -8
- package/dist/chunk-K2UN3O67.mjs +0 -2
- package/dist/http-UU2NIW6M.mjs +0 -2
- /package/dist/{http-UU2NIW6M.mjs.map → http-AQVVUCX6.mjs.map} +0 -0
package/dist/react.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var V=(s,o)=>{for(var l in o)d(s,l,{get:o[l],enumerable:!0})},p=(s,o,l,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of w(o))!v.call(s,i)&&i!==l&&d(s,i,{get:()=>o[i],enumerable:!(r=y(o,i))||r.enumerable});return s};var h=s=>p(d({},"__esModule",{value:!0}),s);var _={};V(_,{setConsentiWidget:()=>I,useConsent:()=>P});module.exports=h(_);var t=require("react"),n=null;function I(s){n=s}function P(){let s=typeof window>"u",[o,l]=(0,t.useState)(()=>s?!1:n?.hasConsent()??!1),[r,i]=(0,t.useState)(()=>s?null:n?.getConsent()??null),[c,b]=(0,t.useState)(()=>s?!1:n?.getConsentDate()??!1),[f,C]=(0,t.useState)(!1),[m,g]=(0,t.useState)(!1);return(0,t.useEffect)(()=>{if(!n)return;let e=()=>{l(n?.hasConsent()??!1),i(n?.getConsent()??null),b(n?.getConsentDate()??!1)},a=()=>C(n?.bannerVisibility()??!1),u=()=>g(n?.modalVisibility()??!1);return window.addEventListener("consenti:consentSubmitted",e),window.addEventListener("consenti:bannerVisibility",a),window.addEventListener("consenti:modalVisibility",u),()=>{window.removeEventListener("consenti:consentSubmitted",e),window.removeEventListener("consenti:bannerVisibility",a),window.removeEventListener("consenti:modalVisibility",u)}},[]),s?{hasConsent:!1,consent:null,consentDate:!1,bannerVisible:!1,modalVisible:!1,showBanner:e=>{},hideBanner:()=>{},showModal:()=>{},hideModal:()=>{},grantAll:e=>Promise.resolve(),denyAll:e=>Promise.resolve(),submitConsent:e=>Promise.resolve(),reConsent:e=>Promise.resolve(),isCookieGranted:e=>!1,isCategoryGranted:e=>!1,switchLocale:e=>{},getUserId:()=>null,setUserId:(e,a)=>Promise.resolve(),getVisitor:()=>({visitorId:null,type:"anonymous",userId:null})}:{hasConsent:o,consent:r,consentDate:c,bannerVisible:f,modalVisible:m,showBanner:e=>n?.showBanner(e),hideBanner:()=>n?.hideBanner(),showModal:()=>n?.showModal(),hideModal:()=>n?.hideModal(),grantAll:e=>n?.grantAll(e)??Promise.resolve(),denyAll:e=>n?.denyAll(e)??Promise.resolve(),submitConsent:e=>n?.submitConsent(e)??Promise.resolve(),reConsent:e=>n?.reConsent(e)??Promise.resolve(),isCookieGranted:e=>n?.isCookieGranted(e)??!1,isCategoryGranted:e=>n?.isCategoryGranted(e)??!1,switchLocale:e=>n?.switchLocale(e),getUserId:()=>n?.getUserId()??null,setUserId:(e,a)=>n?.setUserId(e,a)??Promise.resolve(),getVisitor:()=>n?.getVisitor()??{visitorId:null,type:"anonymous",userId:null}}}
|
|
2
2
|
//# sourceMappingURL=react.js.map
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.ts"],"sourcesContent":["/**\n * React integration for `@consenti/ui`.\n *\n * Import from the `@consenti/ui/react` subpath to keep this module\n * tree-shaken out of vanilla JS or Vue bundles.\n *\n * Intended for **Next.js** (App Router and Pages Router) and any other React 18+\n * project where you manage the `ConsentiSetup` instance yourself and want the\n * `useConsent()` hook to re-render when consent or UI state changes.\n *\n * @example\n * ```tsx\n * // app/providers.tsx (Next.js App Router)\n * 'use client'\n * import { useEffect } from 'react'\n * import { ConsentiSetup } from '@consenti/ui'\n * import { setConsentiWidget } from '@consenti/ui/react'\n *\n * export function ConsentiProvider({ children }: { children: React.ReactNode }) {\n * useEffect(() => {\n * const widget = new ConsentiSetup({\n * api: { enabled: true, baseUrl: process.env.NEXT_PUBLIC_API_URL },\n * })\n * setConsentiWidget(widget)\n * }, [])\n * return <>{children}</>\n * }\n *\n * // Any component\n * import { useConsent } from '@consenti/ui/react'\n *\n * function CookieStatus() {\n * const { hasConsent, consent, showModal } = useConsent()\n * if (!hasConsent) return <button onClick={showModal}>Manage Cookies</button>\n * return <span>{consent?.analytics === 'granted' ? 'Analytics on' : 'Analytics off'}</span>\n * }\n * ```\n */\n\nimport { useState, useEffect } from 'react'\nimport type { ConsentValue } from './types'\nimport type { ConsentiSetup } from './core/consenti-setup'\n\n/**\n * Module-level singleton — the active `ConsentiSetup` instance.\n * Using a module-level variable (rather than React context) keeps the integration\n * zero-configuration: no `<ConsentiProvider>` wrapper is required.\n */\nlet _widget: ConsentiSetup | null = null\n\n/**\n * Registers the active `ConsentiSetup` instance so `useConsent()` can read from it.\n * Call this once after creating your widget, typically inside a `useEffect`.\n *\n * @param widget - The `ConsentiSetup` instance to register.\n */\nexport function setConsentiWidget(widget: ConsentiSetup): void {\n _widget = widget\n}\n\n/**\n * React hook that exposes consent state, banner/modal visibility, and widget actions.\n *\n * Subscribes to `consenti:consentSubmitted`, `consenti:bannerVisibility`, and\n * `consenti:modalVisibility` on `window` and triggers re-renders on each event.\n * Returns SSR-safe initial values during server render.\n *\n * Destructure only what you need — unused values do not cause extra renders.\n *\n * @returns Consent state values and widget action functions.\n */\nexport function useConsent() {\n const isServer = typeof window === 'undefined'\n\n const [hasConsent, setHasConsent] = useState<boolean>(() =>\n !isServer ? (_widget?.hasConsent() ?? false) : false,\n )\n const [consent, setConsent] = useState<ConsentValue | null>(() =>\n !isServer ? (_widget?.getConsent() ?? null) : null,\n )\n const [consentDate, setConsentDate] = useState<Date | false>(() =>\n !isServer ? (_widget?.getConsentDate() ?? false) : false,\n )\n const [bannerVisible, setBannerVisible] = useState<'main' | 'gpc' | false>(false)\n const [modalVisible, setModalVisible] = useState<'preference' | false>(false)\n\n useEffect(() => {\n if (!_widget) return\n\n const onConsent = () => {\n setHasConsent(_widget?.hasConsent() ?? false)\n setConsent(_widget?.getConsent() ?? null)\n setConsentDate(_widget?.getConsentDate() ?? false)\n }\n const onBanner = () => setBannerVisible(_widget?.bannerVisibility() ?? false)\n const onModal = () => setModalVisible(_widget?.modalVisibility() ?? false)\n\n window.addEventListener('consenti:consentSubmitted', onConsent)\n window.addEventListener('consenti:bannerVisibility', onBanner)\n window.addEventListener('consenti:modalVisibility', onModal)\n\n return () => {\n window.removeEventListener('consenti:consentSubmitted', onConsent)\n window.removeEventListener('consenti:bannerVisibility', onBanner)\n window.removeEventListener('consenti:modalVisibility', onModal)\n }\n }, [])\n\n // ── SSR-safe fallback ──────────────────────────────────────────────────────\n if (isServer) {\n return {\n hasConsent: false as boolean,\n consent: null as ConsentValue | null,\n consentDate: false as Date | false,\n bannerVisible: false as 'main' | 'gpc' | false,\n modalVisible: false as 'preference' | false,\n showBanner: (_gpc?: boolean) => {},\n hideBanner: () => {},\n showModal: () => {},\n hideModal: () => {},\n grantAll: (_onlyMandatory?: boolean) => Promise.resolve(),\n denyAll: (_includingMandatory?: boolean) => Promise.resolve(),\n submitConsent: (_c: Partial<ConsentValue>) => Promise.resolve(),\n reConsent: () => Promise.resolve(),\n isCookieGranted: (_id: string) => false as boolean,\n isCategoryGranted: (_id: string) => false as boolean,\n switchLocale: (_locale: string) => {},\n }\n }\n\n // ── Client ────────────────────────────────────────────────────────────────\n return {\n /** `true` if the visitor has saved a valid consent record. */\n hasConsent,\n /** The stored consent map (`Record<cookieId, status>`), or `null` before first submission. */\n consent,\n /** `Date` of the last consent submission, or `false` if no consent exists. */\n consentDate,\n /** Current banner state: `'main'`, `'gpc'`, or `false` (hidden). */\n bannerVisible,\n /** Current modal state: `'preference'` or `false` (hidden). */\n modalVisible,\n\n /** Shows the consent banner. Pass `true` to force the GPC variant. */\n showBanner: (gpc?: boolean) => _widget?.showBanner(gpc),\n /** Hides the consent banner. */\n hideBanner: () => _widget?.hideBanner(),\n /** Opens the preference modal. */\n showModal: () => _widget?.showModal(),\n /** Closes the preference modal. */\n hideModal: () => _widget?.hideModal(),\n\n /** Grants all non-mandatory cookies. Pass `true` to grant only mandatory ones and deny the rest. */\n grantAll: (onlyMandatory?: boolean) => _widget?.grantAll(onlyMandatory) ?? Promise.resolve(),\n /** Denies all non-mandatory cookies. Pass `true` to deny mandatory ones too (use with care). */\n denyAll: (includingMandatory?: boolean) => _widget?.denyAll(includingMandatory) ?? Promise.resolve(),\n /** Saves the given partial consent map. */\n submitConsent: (c: Partial<ConsentValue>) => _widget?.submitConsent(c) ?? Promise.resolve(),\n /** Deletes the current consent record and re-shows the banner. */\n reConsent: () => _widget?.reConsent() ?? Promise.resolve(),\n\n /** Returns `true` if the given cookie ID is `'granted'`. */\n isCookieGranted: (id: string) => (_widget?.isCookieGranted(id) ?? false) as boolean,\n /** Returns `true` if every cookie in the given category is `'granted'`. */\n isCategoryGranted: (id: string) => (_widget?.isCategoryGranted(id) ?? false) as boolean,\n /** Switches the active locale and re-renders the banner and modal. */\n switchLocale: (locale: string) => _widget?.switchLocale(locale),\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,eAAAC,IAAA,eAAAC,EAAAJ,GAuCA,IAAAK,EAAoC,iBAShCC,EAAgC,KAQ7B,SAASJ,EAAkBK,EAA6B,CAC7DD,EAAUC,CACZ,CAaO,SAASJ,GAAa,CAC3B,IAAMK,EAAW,OAAO,OAAW,IAE7B,CAACC,EAAYC,CAAa,KAAI,YAAkB,IACnDF,EAA8C,GAAlCF,GAAS,WAAW,GAAK,EACxC,EACM,CAACK,EAASC,CAAU,KAAI,YAA8B,IACzDJ,EAA6C,KAAjCF,GAAS,WAAW,GAAK,IACxC,EACM,CAACO,EAAaC,CAAc,KAAI,YAAuB,IAC1DN,EAAkD,GAAtCF,GAAS,eAAe,GAAK,EAC5C,EACM,CAACS,EAAeC,CAAgB,KAAI,YAAiC,EAAK,EAC1E,CAACC,EAAcC,CAAe,KAAI,YAA+B,EAAK,EAyB5E,SAvBA,aAAU,IAAM,CACd,GAAI,CAACZ,EAAS,OAEd,IAAMa,EAAY,IAAM,CACtBT,EAAcJ,GAAS,WAAW,GAAK,EAAK,EAC5CM,EAAWN,GAAS,WAAW,GAAK,IAAI,EACxCQ,EAAeR,GAAS,eAAe,GAAK,EAAK,CACnD,EACMc,EAAW,IAAMJ,EAAiB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gBAAgB0B,CAAE,GAAK,GAElE,kBAAoBA,GAAgB1B,GAAS,kBAAkB0B,CAAE,GAAK,GAEtE,aAAeC,GAAmB3B,GAAS,aAAa2B,CAAM,CAChE,CACF","names":["react_exports","__export","setConsentiWidget","useConsent","__toCommonJS","import_react","_widget","widget","isServer","hasConsent","setHasConsent","consent","setConsent","consentDate","setConsentDate","bannerVisible","setBannerVisible","modalVisible","setModalVisible","onConsent","onBanner","onModal","_gpc","_onlyMandatory","_includingMandatory","_c","_id","_locale","gpc","onlyMandatory","includingMandatory","c","id","locale"]}
|
|
1
|
+
{"version":3,"sources":["../src/react.ts"],"sourcesContent":["/**\n * React integration for `@consenti/ui`.\n *\n * Import from the `@consenti/ui/react` subpath to keep this module\n * tree-shaken out of vanilla JS or Vue bundles.\n *\n * Intended for **Next.js** (App Router and Pages Router) and any other React 18+\n * project where you manage the `ConsentiSetup` instance yourself and want the\n * `useConsent()` hook to re-render when consent or UI state changes.\n *\n * @example\n * ```tsx\n * // app/providers.tsx (Next.js App Router)\n * 'use client'\n * import { useEffect } from 'react'\n * import { ConsentiSetup } from '@consenti/ui'\n * import { setConsentiWidget } from '@consenti/ui/react'\n *\n * export function ConsentiProvider({ children }: { children: React.ReactNode }) {\n * useEffect(() => {\n * const widget = new ConsentiSetup({\n * api: { enabled: true, baseUrl: process.env.NEXT_PUBLIC_API_URL },\n * })\n * setConsentiWidget(widget)\n * }, [])\n * return <>{children}</>\n * }\n *\n * // Any component\n * import { useConsent } from '@consenti/ui/react'\n *\n * function CookieStatus() {\n * const { hasConsent, consent, showModal } = useConsent()\n * if (!hasConsent) return <button onClick={showModal}>Manage Cookies</button>\n * return <span>{consent?.analytics === 'granted' ? 'Analytics on' : 'Analytics off'}</span>\n * }\n * ```\n */\n\nimport { useState, useEffect } from 'react'\nimport type { ConsentValue, VisitorIdentity } from './types'\nimport type { ConsentiSetup } from './core/consenti-setup'\n\n/**\n * Module-level singleton — the active `ConsentiSetup` instance.\n * Using a module-level variable (rather than React context) keeps the integration\n * zero-configuration: no `<ConsentiProvider>` wrapper is required.\n */\nlet _widget: ConsentiSetup | null = null\n\n/**\n * Registers the active `ConsentiSetup` instance so `useConsent()` can read from it.\n * Call this once after creating your widget, typically inside a `useEffect`.\n *\n * @param widget - The `ConsentiSetup` instance to register.\n */\nexport function setConsentiWidget(widget: ConsentiSetup): void {\n _widget = widget\n}\n\n/**\n * React hook that exposes consent state, banner/modal visibility, and widget actions.\n *\n * Subscribes to `consenti:consentSubmitted`, `consenti:bannerVisibility`, and\n * `consenti:modalVisibility` on `window` and triggers re-renders on each event.\n * Returns SSR-safe initial values during server render.\n *\n * Destructure only what you need — unused values do not cause extra renders.\n *\n * @returns Consent state values and widget action functions.\n */\nexport function useConsent() {\n const isServer = typeof window === 'undefined'\n\n const [hasConsent, setHasConsent] = useState<boolean>(() =>\n !isServer ? (_widget?.hasConsent() ?? false) : false,\n )\n const [consent, setConsent] = useState<ConsentValue | null>(() =>\n !isServer ? (_widget?.getConsent() ?? null) : null,\n )\n const [consentDate, setConsentDate] = useState<Date | false>(() =>\n !isServer ? (_widget?.getConsentDate() ?? false) : false,\n )\n const [bannerVisible, setBannerVisible] = useState<'main' | 'gpc' | false>(false)\n const [modalVisible, setModalVisible] = useState<'preference' | false>(false)\n\n useEffect(() => {\n if (!_widget) return\n\n const onConsent = () => {\n setHasConsent(_widget?.hasConsent() ?? false)\n setConsent(_widget?.getConsent() ?? null)\n setConsentDate(_widget?.getConsentDate() ?? false)\n }\n const onBanner = () => setBannerVisible(_widget?.bannerVisibility() ?? false)\n const onModal = () => setModalVisible(_widget?.modalVisibility() ?? false)\n\n window.addEventListener('consenti:consentSubmitted', onConsent)\n window.addEventListener('consenti:bannerVisibility', onBanner)\n window.addEventListener('consenti:modalVisibility', onModal)\n\n return () => {\n window.removeEventListener('consenti:consentSubmitted', onConsent)\n window.removeEventListener('consenti:bannerVisibility', onBanner)\n window.removeEventListener('consenti:modalVisibility', onModal)\n }\n }, [])\n\n // ── SSR-safe fallback ──────────────────────────────────────────────────────\n if (isServer) {\n return {\n hasConsent: false as boolean,\n consent: null as ConsentValue | null,\n consentDate: false as Date | false,\n bannerVisible: false as 'main' | 'gpc' | false,\n modalVisible: false as 'preference' | false,\n showBanner: (_gpc?: boolean) => {},\n hideBanner: () => {},\n showModal: () => {},\n hideModal: () => {},\n grantAll: (_onlyMandatory?: boolean) => Promise.resolve(),\n denyAll: (_includingMandatory?: boolean) => Promise.resolve(),\n submitConsent: (_c: Partial<ConsentValue>) => Promise.resolve(),\n reConsent: (_resetAgeGate?: boolean) => Promise.resolve(),\n isCookieGranted: (_id: string) => false as boolean,\n isCategoryGranted: (_id: string) => false as boolean,\n switchLocale: (_locale: string) => {},\n getUserId: () => null as string | null,\n setUserId: (_userId: string | null, _reConsent?: boolean) => Promise.resolve(),\n getVisitor: () => ({ visitorId: null, type: 'anonymous', userId: null }) as VisitorIdentity,\n }\n }\n\n // ── Client ────────────────────────────────────────────────────────────────\n return {\n /** `true` if the visitor has saved a valid consent record. */\n hasConsent,\n /** The stored consent map (`Record<cookieId, status>`), or `null` before first submission. */\n consent,\n /** `Date` of the last consent submission, or `false` if no consent exists. */\n consentDate,\n /** Current banner state: `'main'`, `'gpc'`, or `false` (hidden). */\n bannerVisible,\n /** Current modal state: `'preference'` or `false` (hidden). */\n modalVisible,\n\n /** Shows the consent banner. Pass `true` to force the GPC variant. */\n showBanner: (gpc?: boolean) => _widget?.showBanner(gpc),\n /** Hides the consent banner. */\n hideBanner: () => _widget?.hideBanner(),\n /** Opens the preference modal. */\n showModal: () => _widget?.showModal(),\n /** Closes the preference modal. */\n hideModal: () => _widget?.hideModal(),\n\n /** Grants all non-mandatory cookies. Pass `true` to grant only mandatory ones and deny the rest. */\n grantAll: (onlyMandatory?: boolean) => _widget?.grantAll(onlyMandatory) ?? Promise.resolve(),\n /** Denies all non-mandatory cookies. Pass `true` to deny mandatory ones too (use with care). */\n denyAll: (includingMandatory?: boolean) => _widget?.denyAll(includingMandatory) ?? Promise.resolve(),\n /** Saves the given partial consent map. */\n submitConsent: (c: Partial<ConsentValue>) => _widget?.submitConsent(c) ?? Promise.resolve(),\n /** Deletes the current consent record and re-shows the banner. Pass `false` to skip\n * re-showing the age-gate prompt (if the profile has one) and go straight to the banner. */\n reConsent: (resetAgeGate?: boolean) => _widget?.reConsent(resetAgeGate) ?? Promise.resolve(),\n\n /** Returns `true` if the given cookie ID is `'granted'`. */\n isCookieGranted: (id: string) => (_widget?.isCookieGranted(id) ?? false) as boolean,\n /** Returns `true` if every cookie in the given category is `'granted'`. */\n isCategoryGranted: (id: string) => (_widget?.isCategoryGranted(id) ?? false) as boolean,\n /** Switches the active locale and re-renders the banner and modal. */\n switchLocale: (locale: string) => _widget?.switchLocale(locale),\n /** Returns the current logged-in application user ID, or `null` if anonymous. */\n getUserId: () => _widget?.getUserId() ?? null,\n /** Sets the logged-in application user ID; reconsents by default when it changes. */\n setUserId: (userId: string | null, reConsent?: boolean) => _widget?.setUserId(userId, reConsent) ?? Promise.resolve(),\n /** Snapshot of the current visitor's identity (`visitorId`, `type`, `userId`). */\n getVisitor: () => _widget?.getVisitor() ?? ({ visitorId: null, type: 'anonymous', userId: null } as VisitorIdentity),\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,eAAAC,IAAA,eAAAC,EAAAJ,GAuCA,IAAAK,EAAoC,iBAShCC,EAAgC,KAQ7B,SAASJ,EAAkBK,EAA6B,CAC7DD,EAAUC,CACZ,CAaO,SAASJ,GAAa,CAC3B,IAAMK,EAAW,OAAO,OAAW,IAE7B,CAACC,EAAYC,CAAa,KAAI,YAAkB,IACnDF,EAA8C,GAAlCF,GAAS,WAAW,GAAK,EACxC,EACM,CAACK,EAASC,CAAU,KAAI,YAA8B,IACzDJ,EAA6C,KAAjCF,GAAS,WAAW,GAAK,IACxC,EACM,CAACO,EAAaC,CAAc,KAAI,YAAuB,IAC1DN,EAAkD,GAAtCF,GAAS,e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,EAEA,YAAAE,EAEA,cAAAE,EAEA,aAAAE,EAGA,WAAac,GAAkBzB,GAAS,WAAWyB,CAAG,EAEtD,WAAY,IAAMzB,GAAS,WAAW,EAEtC,UAAW,IAAMA,GAAS,UAAU,EAEpC,UAAW,IAAMA,GAAS,UAAU,EAGpC,SAAW0B,GAA4B1B,GAAS,SAAS0B,CAAa,GAAK,QAAQ,QAAQ,EAE3F,QAAUC,GAAiC3B,GAAS,QAAQ2B,CAAkB,GAAK,QAAQ,QAAQ,EAEnG,cAAgBC,GAA6B5B,GAAS,cAAc4B,CAAC,GAAK,QAAQ,QAAQ,EAG1F,UAAYC,GAA2B7B,GAAS,UAAU6B,CAAY,GAAK,QAAQ,QAAQ,EAG3F,gBAAkBC,GAAgB9B,GAAS,gBAAgB8B,CAAE,GAAK,GAElE,kBAAoBA,GAAgB9B,GAAS,kBAAkB8B,CAAE,GAAK,GAEtE,aAAeC,GAAmB/B,GAAS,aAAa+B,CAAM,EAE9D,UAAW,IAAM/B,GAAS,UAAU,GAAK,KAEzC,UAAW,CAACgC,EAAuBC,IAAwBjC,GAAS,UAAUgC,EAAQC,CAAS,GAAK,QAAQ,QAAQ,EAEpH,WAAY,IAAMjC,GAAS,WAAW,GAAM,CAAE,UAAW,KAAM,KAAM,YAAa,OAAQ,IAAK,CACjG,CACF","names":["react_exports","__export","setConsentiWidget","useConsent","__toCommonJS","import_react","_widget","widget","isServer","hasConsent","setHasConsent","consent","setConsent","consentDate","setConsentDate","bannerVisible","setBannerVisible","modalVisible","setModalVisible","onConsent","onBanner","onModal","_gpc","_onlyMandatory","_includingMandatory","_c","_resetAgeGate","_id","_locale","_userId","_reConsent","gpc","onlyMandatory","includingMandatory","c","resetAgeGate","id","locale","userId","reConsent"]}
|
package/dist/react.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useState as
|
|
1
|
+
import{useState as t,useEffect as g}from"react";var n=null;function w(s){n=s}function v(){let s=typeof window>"u",[l,a]=t(()=>s?!1:n?.hasConsent()??!1),[r,d]=t(()=>s?null:n?.getConsent()??null),[u,c]=t(()=>s?!1:n?.getConsentDate()??!1),[b,f]=t(!1),[C,m]=t(!1);return g(()=>{if(!n)return;let e=()=>{a(n?.hasConsent()??!1),d(n?.getConsent()??null),c(n?.getConsentDate()??!1)},o=()=>f(n?.bannerVisibility()??!1),i=()=>m(n?.modalVisibility()??!1);return window.addEventListener("consenti:consentSubmitted",e),window.addEventListener("consenti:bannerVisibility",o),window.addEventListener("consenti:modalVisibility",i),()=>{window.removeEventListener("consenti:consentSubmitted",e),window.removeEventListener("consenti:bannerVisibility",o),window.removeEventListener("consenti:modalVisibility",i)}},[]),s?{hasConsent:!1,consent:null,consentDate:!1,bannerVisible:!1,modalVisible:!1,showBanner:e=>{},hideBanner:()=>{},showModal:()=>{},hideModal:()=>{},grantAll:e=>Promise.resolve(),denyAll:e=>Promise.resolve(),submitConsent:e=>Promise.resolve(),reConsent:e=>Promise.resolve(),isCookieGranted:e=>!1,isCategoryGranted:e=>!1,switchLocale:e=>{},getUserId:()=>null,setUserId:(e,o)=>Promise.resolve(),getVisitor:()=>({visitorId:null,type:"anonymous",userId:null})}:{hasConsent:l,consent:r,consentDate:u,bannerVisible:b,modalVisible:C,showBanner:e=>n?.showBanner(e),hideBanner:()=>n?.hideBanner(),showModal:()=>n?.showModal(),hideModal:()=>n?.hideModal(),grantAll:e=>n?.grantAll(e)??Promise.resolve(),denyAll:e=>n?.denyAll(e)??Promise.resolve(),submitConsent:e=>n?.submitConsent(e)??Promise.resolve(),reConsent:e=>n?.reConsent(e)??Promise.resolve(),isCookieGranted:e=>n?.isCookieGranted(e)??!1,isCategoryGranted:e=>n?.isCategoryGranted(e)??!1,switchLocale:e=>n?.switchLocale(e),getUserId:()=>n?.getUserId()??null,setUserId:(e,o)=>n?.setUserId(e,o)??Promise.resolve(),getVisitor:()=>n?.getVisitor()??{visitorId:null,type:"anonymous",userId:null}}}export{w as setConsentiWidget,v as useConsent};
|
|
2
2
|
//# sourceMappingURL=react.mjs.map
|
package/dist/react.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.ts"],"sourcesContent":["/**\n * React integration for `@consenti/ui`.\n *\n * Import from the `@consenti/ui/react` subpath to keep this module\n * tree-shaken out of vanilla JS or Vue bundles.\n *\n * Intended for **Next.js** (App Router and Pages Router) and any other React 18+\n * project where you manage the `ConsentiSetup` instance yourself and want the\n * `useConsent()` hook to re-render when consent or UI state changes.\n *\n * @example\n * ```tsx\n * // app/providers.tsx (Next.js App Router)\n * 'use client'\n * import { useEffect } from 'react'\n * import { ConsentiSetup } from '@consenti/ui'\n * import { setConsentiWidget } from '@consenti/ui/react'\n *\n * export function ConsentiProvider({ children }: { children: React.ReactNode }) {\n * useEffect(() => {\n * const widget = new ConsentiSetup({\n * api: { enabled: true, baseUrl: process.env.NEXT_PUBLIC_API_URL },\n * })\n * setConsentiWidget(widget)\n * }, [])\n * return <>{children}</>\n * }\n *\n * // Any component\n * import { useConsent } from '@consenti/ui/react'\n *\n * function CookieStatus() {\n * const { hasConsent, consent, showModal } = useConsent()\n * if (!hasConsent) return <button onClick={showModal}>Manage Cookies</button>\n * return <span>{consent?.analytics === 'granted' ? 'Analytics on' : 'Analytics off'}</span>\n * }\n * ```\n */\n\nimport { useState, useEffect } from 'react'\nimport type { ConsentValue } from './types'\nimport type { ConsentiSetup } from './core/consenti-setup'\n\n/**\n * Module-level singleton — the active `ConsentiSetup` instance.\n * Using a module-level variable (rather than React context) keeps the integration\n * zero-configuration: no `<ConsentiProvider>` wrapper is required.\n */\nlet _widget: ConsentiSetup | null = null\n\n/**\n * Registers the active `ConsentiSetup` instance so `useConsent()` can read from it.\n * Call this once after creating your widget, typically inside a `useEffect`.\n *\n * @param widget - The `ConsentiSetup` instance to register.\n */\nexport function setConsentiWidget(widget: ConsentiSetup): void {\n _widget = widget\n}\n\n/**\n * React hook that exposes consent state, banner/modal visibility, and widget actions.\n *\n * Subscribes to `consenti:consentSubmitted`, `consenti:bannerVisibility`, and\n * `consenti:modalVisibility` on `window` and triggers re-renders on each event.\n * Returns SSR-safe initial values during server render.\n *\n * Destructure only what you need — unused values do not cause extra renders.\n *\n * @returns Consent state values and widget action functions.\n */\nexport function useConsent() {\n const isServer = typeof window === 'undefined'\n\n const [hasConsent, setHasConsent] = useState<boolean>(() =>\n !isServer ? (_widget?.hasConsent() ?? false) : false,\n )\n const [consent, setConsent] = useState<ConsentValue | null>(() =>\n !isServer ? (_widget?.getConsent() ?? null) : null,\n )\n const [consentDate, setConsentDate] = useState<Date | false>(() =>\n !isServer ? (_widget?.getConsentDate() ?? false) : false,\n )\n const [bannerVisible, setBannerVisible] = useState<'main' | 'gpc' | false>(false)\n const [modalVisible, setModalVisible] = useState<'preference' | false>(false)\n\n useEffect(() => {\n if (!_widget) return\n\n const onConsent = () => {\n setHasConsent(_widget?.hasConsent() ?? false)\n setConsent(_widget?.getConsent() ?? null)\n setConsentDate(_widget?.getConsentDate() ?? false)\n }\n const onBanner = () => setBannerVisible(_widget?.bannerVisibility() ?? false)\n const onModal = () => setModalVisible(_widget?.modalVisibility() ?? false)\n\n window.addEventListener('consenti:consentSubmitted', onConsent)\n window.addEventListener('consenti:bannerVisibility', onBanner)\n window.addEventListener('consenti:modalVisibility', onModal)\n\n return () => {\n window.removeEventListener('consenti:consentSubmitted', onConsent)\n window.removeEventListener('consenti:bannerVisibility', onBanner)\n window.removeEventListener('consenti:modalVisibility', onModal)\n }\n }, [])\n\n // ── SSR-safe fallback ──────────────────────────────────────────────────────\n if (isServer) {\n return {\n hasConsent: false as boolean,\n consent: null as ConsentValue | null,\n consentDate: false as Date | false,\n bannerVisible: false as 'main' | 'gpc' | false,\n modalVisible: false as 'preference' | false,\n showBanner: (_gpc?: boolean) => {},\n hideBanner: () => {},\n showModal: () => {},\n hideModal: () => {},\n grantAll: (_onlyMandatory?: boolean) => Promise.resolve(),\n denyAll: (_includingMandatory?: boolean) => Promise.resolve(),\n submitConsent: (_c: Partial<ConsentValue>) => Promise.resolve(),\n reConsent: () => Promise.resolve(),\n isCookieGranted: (_id: string) => false as boolean,\n isCategoryGranted: (_id: string) => false as boolean,\n switchLocale: (_locale: string) => {},\n }\n }\n\n // ── Client ────────────────────────────────────────────────────────────────\n return {\n /** `true` if the visitor has saved a valid consent record. */\n hasConsent,\n /** The stored consent map (`Record<cookieId, status>`), or `null` before first submission. */\n consent,\n /** `Date` of the last consent submission, or `false` if no consent exists. */\n consentDate,\n /** Current banner state: `'main'`, `'gpc'`, or `false` (hidden). */\n bannerVisible,\n /** Current modal state: `'preference'` or `false` (hidden). */\n modalVisible,\n\n /** Shows the consent banner. Pass `true` to force the GPC variant. */\n showBanner: (gpc?: boolean) => _widget?.showBanner(gpc),\n /** Hides the consent banner. */\n hideBanner: () => _widget?.hideBanner(),\n /** Opens the preference modal. */\n showModal: () => _widget?.showModal(),\n /** Closes the preference modal. */\n hideModal: () => _widget?.hideModal(),\n\n /** Grants all non-mandatory cookies. Pass `true` to grant only mandatory ones and deny the rest. */\n grantAll: (onlyMandatory?: boolean) => _widget?.grantAll(onlyMandatory) ?? Promise.resolve(),\n /** Denies all non-mandatory cookies. Pass `true` to deny mandatory ones too (use with care). */\n denyAll: (includingMandatory?: boolean) => _widget?.denyAll(includingMandatory) ?? Promise.resolve(),\n /** Saves the given partial consent map. */\n submitConsent: (c: Partial<ConsentValue>) => _widget?.submitConsent(c) ?? Promise.resolve(),\n /** Deletes the current consent record and re-shows the banner. */\n reConsent: () => _widget?.reConsent() ?? Promise.resolve(),\n\n /** Returns `true` if the given cookie ID is `'granted'`. */\n isCookieGranted: (id: string) => (_widget?.isCookieGranted(id) ?? false) as boolean,\n /** Returns `true` if every cookie in the given category is `'granted'`. */\n isCategoryGranted: (id: string) => (_widget?.isCategoryGranted(id) ?? false) as boolean,\n /** Switches the active locale and re-renders the banner and modal. */\n switchLocale: (locale: string) => _widget?.switchLocale(locale),\n }\n}\n"],"mappings":"AAuCA,OAAS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UAAc,IAAM,CAAC,EACrB,SAAeC,GAA6B,QAAQ,QAAQ,EAC5D,QAAeC,GAAkC,QAAQ,QAAQ,EACjE,cAAgBC,GAA8B,QAAQ,QAAQ,EAC9D,UAAc,IAAM,QAAQ,QAAQ,EACpC,gBAAoBC,GAAgB,GACpC,kBAAoBA,GAAgB,GACpC,aAAeC,GAAoB,CAAC,CACtC,EAIK,CAEL,WAAAlB,EAEA,QAAAE,EAEA,YAAAE,EAEA,cAAAE,EAEA,aAAAE,EAGA,WAAaW,GAAkBxB,GAAS,WAAWwB,CAAG,EAEtD,WAAY,IAAMxB,GAAS,WAAW,EAEtC,UAAW,IAAMA,GAAS,UAAU,EAEpC,UAAW,IAAMA,GAAS,UAAU,EAGpC,SAAWyB,GAA4BzB,GAAS,SAASyB,CAAa,GAAK,QAAQ,QAAQ,EAE3F,QAAUC,GAAiC1B,GAAS,QAAQ0B,CAAkB,GAAK,QAAQ,QAAQ,EAEnG,cAAgBC,GAA6B3B,GAAS,cAAc2B,CAAC,GAAK,QAAQ,QAAQ,EAE1F,UAAW,IAAM3B,GAAS,UAAU,GAAK,QAAQ,QAAQ,EAGzD,gBAAkB4B,GAAgB5B,GAAS,gBAAgB4B,CAAE,GAAK,GAElE,kBAAoBA,GAAgB5B,GAAS,kBAAkB4B,CAAE,GAAK,GAEtE,aAAeC,GAAmB7B,GAAS,aAAa6B,CAAM,CAChE,CACF","names":["useState","useEffect","_widget","setConsentiWidget","widget","useConsent","isServer","hasConsent","setHasConsent","consent","setConsent","consentDate","setConsentDate","bannerVisible","setBannerVisible","modalVisible","setModalVisible","onConsent","onBanner","onModal","_gpc","_onlyMandatory","_includingMandatory","_c","_id","_locale","gpc","onlyMandatory","includingMandatory","c","id","locale"]}
|
|
1
|
+
{"version":3,"sources":["../src/react.ts"],"sourcesContent":["/**\n * React integration for `@consenti/ui`.\n *\n * Import from the `@consenti/ui/react` subpath to keep this module\n * tree-shaken out of vanilla JS or Vue bundles.\n *\n * Intended for **Next.js** (App Router and Pages Router) and any other React 18+\n * project where you manage the `ConsentiSetup` instance yourself and want the\n * `useConsent()` hook to re-render when consent or UI state changes.\n *\n * @example\n * ```tsx\n * // app/providers.tsx (Next.js App Router)\n * 'use client'\n * import { useEffect } from 'react'\n * import { ConsentiSetup } from '@consenti/ui'\n * import { setConsentiWidget } from '@consenti/ui/react'\n *\n * export function ConsentiProvider({ children }: { children: React.ReactNode }) {\n * useEffect(() => {\n * const widget = new ConsentiSetup({\n * api: { enabled: true, baseUrl: process.env.NEXT_PUBLIC_API_URL },\n * })\n * setConsentiWidget(widget)\n * }, [])\n * return <>{children}</>\n * }\n *\n * // Any component\n * import { useConsent } from '@consenti/ui/react'\n *\n * function CookieStatus() {\n * const { hasConsent, consent, showModal } = useConsent()\n * if (!hasConsent) return <button onClick={showModal}>Manage Cookies</button>\n * return <span>{consent?.analytics === 'granted' ? 'Analytics on' : 'Analytics off'}</span>\n * }\n * ```\n */\n\nimport { useState, useEffect } from 'react'\nimport type { ConsentValue, VisitorIdentity } from './types'\nimport type { ConsentiSetup } from './core/consenti-setup'\n\n/**\n * Module-level singleton — the active `ConsentiSetup` instance.\n * Using a module-level variable (rather than React context) keeps the integration\n * zero-configuration: no `<ConsentiProvider>` wrapper is required.\n */\nlet _widget: ConsentiSetup | null = null\n\n/**\n * Registers the active `ConsentiSetup` instance so `useConsent()` can read from it.\n * Call this once after creating your widget, typically inside a `useEffect`.\n *\n * @param widget - The `ConsentiSetup` instance to register.\n */\nexport function setConsentiWidget(widget: ConsentiSetup): void {\n _widget = widget\n}\n\n/**\n * React hook that exposes consent state, banner/modal visibility, and widget actions.\n *\n * Subscribes to `consenti:consentSubmitted`, `consenti:bannerVisibility`, and\n * `consenti:modalVisibility` on `window` and triggers re-renders on each event.\n * Returns SSR-safe initial values during server render.\n *\n * Destructure only what you need — unused values do not cause extra renders.\n *\n * @returns Consent state values and widget action functions.\n */\nexport function useConsent() {\n const isServer = typeof window === 'undefined'\n\n const [hasConsent, setHasConsent] = useState<boolean>(() =>\n !isServer ? (_widget?.hasConsent() ?? false) : false,\n )\n const [consent, setConsent] = useState<ConsentValue | null>(() =>\n !isServer ? (_widget?.getConsent() ?? null) : null,\n )\n const [consentDate, setConsentDate] = useState<Date | false>(() =>\n !isServer ? (_widget?.getConsentDate() ?? false) : false,\n )\n const [bannerVisible, setBannerVisible] = useState<'main' | 'gpc' | false>(false)\n const [modalVisible, setModalVisible] = useState<'preference' | false>(false)\n\n useEffect(() => {\n if (!_widget) return\n\n const onConsent = () => {\n setHasConsent(_widget?.hasConsent() ?? false)\n setConsent(_widget?.getConsent() ?? null)\n setConsentDate(_widget?.getConsentDate() ?? false)\n }\n const onBanner = () => setBannerVisible(_widget?.bannerVisibility() ?? false)\n const onModal = () => setModalVisible(_widget?.modalVisibility() ?? false)\n\n window.addEventListener('consenti:consentSubmitted', onConsent)\n window.addEventListener('consenti:bannerVisibility', onBanner)\n window.addEventListener('consenti:modalVisibility', onModal)\n\n return () => {\n window.removeEventListener('consenti:consentSubmitted', onConsent)\n window.removeEventListener('consenti:bannerVisibility', onBanner)\n window.removeEventListener('consenti:modalVisibility', onModal)\n }\n }, [])\n\n // ── SSR-safe fallback ──────────────────────────────────────────────────────\n if (isServer) {\n return {\n hasConsent: false as boolean,\n consent: null as ConsentValue | null,\n consentDate: false as Date | false,\n bannerVisible: false as 'main' | 'gpc' | false,\n modalVisible: false as 'preference' | false,\n showBanner: (_gpc?: boolean) => {},\n hideBanner: () => {},\n showModal: () => {},\n hideModal: () => {},\n grantAll: (_onlyMandatory?: boolean) => Promise.resolve(),\n denyAll: (_includingMandatory?: boolean) => Promise.resolve(),\n submitConsent: (_c: Partial<ConsentValue>) => Promise.resolve(),\n reConsent: (_resetAgeGate?: boolean) => Promise.resolve(),\n isCookieGranted: (_id: string) => false as boolean,\n isCategoryGranted: (_id: string) => false as boolean,\n switchLocale: (_locale: string) => {},\n getUserId: () => null as string | null,\n setUserId: (_userId: string | null, _reConsent?: boolean) => Promise.resolve(),\n getVisitor: () => ({ visitorId: null, type: 'anonymous', userId: null }) as VisitorIdentity,\n }\n }\n\n // ── Client ────────────────────────────────────────────────────────────────\n return {\n /** `true` if the visitor has saved a valid consent record. */\n hasConsent,\n /** The stored consent map (`Record<cookieId, status>`), or `null` before first submission. */\n consent,\n /** `Date` of the last consent submission, or `false` if no consent exists. */\n consentDate,\n /** Current banner state: `'main'`, `'gpc'`, or `false` (hidden). */\n bannerVisible,\n /** Current modal state: `'preference'` or `false` (hidden). */\n modalVisible,\n\n /** Shows the consent banner. Pass `true` to force the GPC variant. */\n showBanner: (gpc?: boolean) => _widget?.showBanner(gpc),\n /** Hides the consent banner. */\n hideBanner: () => _widget?.hideBanner(),\n /** Opens the preference modal. */\n showModal: () => _widget?.showModal(),\n /** Closes the preference modal. */\n hideModal: () => _widget?.hideModal(),\n\n /** Grants all non-mandatory cookies. Pass `true` to grant only mandatory ones and deny the rest. */\n grantAll: (onlyMandatory?: boolean) => _widget?.grantAll(onlyMandatory) ?? Promise.resolve(),\n /** Denies all non-mandatory cookies. Pass `true` to deny mandatory ones too (use with care). */\n denyAll: (includingMandatory?: boolean) => _widget?.denyAll(includingMandatory) ?? Promise.resolve(),\n /** Saves the given partial consent map. */\n submitConsent: (c: Partial<ConsentValue>) => _widget?.submitConsent(c) ?? Promise.resolve(),\n /** Deletes the current consent record and re-shows the banner. Pass `false` to skip\n * re-showing the age-gate prompt (if the profile has one) and go straight to the banner. */\n reConsent: (resetAgeGate?: boolean) => _widget?.reConsent(resetAgeGate) ?? Promise.resolve(),\n\n /** Returns `true` if the given cookie ID is `'granted'`. */\n isCookieGranted: (id: string) => (_widget?.isCookieGranted(id) ?? false) as boolean,\n /** Returns `true` if every cookie in the given category is `'granted'`. */\n isCategoryGranted: (id: string) => (_widget?.isCategoryGranted(id) ?? false) as boolean,\n /** Switches the active locale and re-renders the banner and modal. */\n switchLocale: (locale: string) => _widget?.switchLocale(locale),\n /** Returns the current logged-in application user ID, or `null` if anonymous. */\n getUserId: () => _widget?.getUserId() ?? null,\n /** Sets the logged-in application user ID; reconsents by default when it changes. */\n setUserId: (userId: string | null, reConsent?: boolean) => _widget?.setUserId(userId, reConsent) ?? Promise.resolve(),\n /** Snapshot of the current visitor's identity (`visitorId`, `type`, `userId`). */\n getVisitor: () => _widget?.getVisitor() ?? ({ visitorId: null, type: 'anonymous', userId: null } as VisitorIdentity),\n }\n}\n"],"mappings":"AAuCA,OAAS,YAAAA,EAAU,aAAAC,MAAiB,QASpC,IAAIC,EAAgC,KAQ7B,SAASC,EAAkBC,EAA6B,CAC7DF,EAAUE,CACZ,CAaO,SAASC,GAAa,CAC3B,IAAMC,EAAW,OAAO,OAAW,IAE7B,CAACC,EAAYC,CAAa,EAAIR,EAAkB,IACnDM,EAA8C,GAAlCJ,GAAS,WAAW,GAAK,EACxC,EACM,CAACO,EAASC,CAAU,EAAIV,EAA8B,IACzDM,EAA6C,KAAjCJ,GAAS,WAAW,GAAK,IACxC,EACM,CAACS,EAAaC,CAAc,EAAIZ,EAAuB,IAC1DM,EAAkD,GAAtCJ,GAAS,eAAe,GAAK,EAC5C,EACM,CAACW,EAAeC,CAAgB,EAAId,EAAiC,EAAK,EAC1E,CAACe,EAAcC,CAAe,EAAIhB,EAA+B,EAAK,EAyB5E,OAvBAC,EAAU,IAAM,CACd,GAAI,CAACC,EAAS,OAEd,IAAMe,EAAY,IAAM,CACtBT,EAAcN,GAAS,WAAW,GAAK,EAAK,EAC5CQ,EAAWR,GAAS,WAAW,GAAK,IAAI,EACxCU,EAAeV,GAAS,eAAe,GAAK,EAAK,CACnD,EACMgB,EAAW,IAAMJ,EAAiBZ,GAAS,iBAAiB,GAAK,EAAK,EACtEiB,EAAW,IAAMH,EAAgBd,GAAS,gBAAgB,GAAK,EAAK,EAE1E,cAAO,iBAAiB,4BAA6Be,CAAS,EAC9D,OAAO,iBAAiB,4BAA8BC,CAAQ,EAC9D,OAAO,iBAAiB,2BAA8BC,CAAO,EAEtD,IAAM,CACX,OAAO,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E,aAAeC,GAAmBjC,GAAS,aAAaiC,CAAM,EAE9D,UAAW,IAAMjC,GAAS,UAAU,GAAK,KAEzC,UAAW,CAACkC,EAAuBC,IAAwBnC,GAAS,UAAUkC,EAAQC,CAAS,GAAK,QAAQ,QAAQ,EAEpH,WAAY,IAAMnC,GAAS,WAAW,GAAM,CAAE,UAAW,KAAM,KAAM,YAAa,OAAQ,IAAK,CACjG,CACF","names":["useState","useEffect","_widget","setConsentiWidget","widget","useConsent","isServer","hasConsent","setHasConsent","consent","setConsent","consentDate","setConsentDate","bannerVisible","setBannerVisible","modalVisible","setModalVisible","onConsent","onBanner","onModal","_gpc","_onlyMandatory","_includingMandatory","_c","_resetAgeGate","_id","_locale","_userId","_reConsent","gpc","onlyMandatory","includingMandatory","c","resetAgeGate","id","locale","userId","reConsent"]}
|
package/dist/testing.d.cts
CHANGED
|
@@ -80,7 +80,7 @@ interface MockConsentiSetup {
|
|
|
80
80
|
onReady: (cb: () => void) => void;
|
|
81
81
|
readonly ready: Promise<void>;
|
|
82
82
|
destroy: () => void;
|
|
83
|
-
reConsent: () => Promise<void>;
|
|
83
|
+
reConsent: (resetAgeGate?: boolean) => Promise<void>;
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* Creates a minimal in-memory mock of `ConsentiSetup` for use in unit tests.
|
package/dist/testing.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ interface MockConsentiSetup {
|
|
|
80
80
|
onReady: (cb: () => void) => void;
|
|
81
81
|
readonly ready: Promise<void>;
|
|
82
82
|
destroy: () => void;
|
|
83
|
-
reConsent: () => Promise<void>;
|
|
83
|
+
reConsent: (resetAgeGate?: boolean) => Promise<void>;
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* Creates a minimal in-memory mock of `ConsentiSetup` for use in unit tests.
|
package/dist/testing.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var c=(e,n)=>{for(var t in n)i(e,t,{get:n[t],enumerable:!0})},C=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of d(n))!u.call(e,s)&&s!==t&&i(e,s,{get:()=>n[s],enumerable:!(o=r(n,s))||o.enumerable});return e};var b=e=>C(i({},"__esModule",{value:!0}),e);var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var c=(e,n)=>{for(var t in n)i(e,t,{get:n[t],enumerable:!0})},C=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of d(n))!u.call(e,s)&&s!==t&&i(e,s,{get:()=>n[s],enumerable:!(o=r(n,s))||o.enumerable});return e};var b=e=>C(i({},"__esModule",{value:!0}),e);var V={};c(V,{createMockConsenti:()=>g,mockAllDenied:()=>v,mockAllGranted:()=>m,mockConsent:()=>a,simulateBannerInitialized:()=>f,simulateConsentBeingSubmitted:()=>p,simulateConsentSubmitted:()=>l});module.exports=b(V);function a(e=[],n=[]){let t={};for(let o of e)t[o]="granted";for(let o of n)t[o]="denied";return t}function m(e){return a(e,[])}function v(e){return a([],e)}function l(e){window.dispatchEvent(new CustomEvent("consenti:consentSubmitted",{detail:{consent:e},bubbles:!0}))}function f(e=!1){window.dispatchEvent(new CustomEvent("consenti:bannerInitialized",{detail:{hasExistingConsent:e},bubbles:!0}))}function p(e){window.dispatchEvent(new CustomEvent("consenti:consentBeingSubmitted",{detail:{consent:e},bubbles:!0}))}function g(e=null){let n=e;return{hasConsent:()=>n!==null,getConsent:()=>n,getConsentDate:()=>n!==null?new Date:!1,getGTMConsent:()=>null,submitConsent:async t=>{n={...n??{},...t},l(n)},deleteConsent:async()=>{n=null},showBanner:()=>{},hideBanner:()=>{},showModal:()=>{},hideModal:()=>{},bannerVisibility:()=>!1,modalVisibility:()=>!1,onReady:t=>t(),ready:Promise.resolve(),destroy:()=>{},reConsent:async t=>{n=null}}}
|
|
2
2
|
//# sourceMappingURL=testing.js.map
|
package/dist/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/testing.ts"],"sourcesContent":["/**\n * Test utilities for `@consenti/ui`.\n *\n * Import via the `/testing` subpath export so these helpers are never bundled\n * into production code:\n *\n * ```ts\n * import {\n * createMockConsenti,\n * mockConsent,\n * simulateConsentSubmitted,\n * } from '@consenti/ui/testing'\n * ```\n *\n * The helpers work in any JavaScript environment that provides a DOM\n * (browsers, jsdom, happy-dom). They carry no runtime dependencies and\n * do not import any Consenti internals — safe to use in unit tests without\n * initialising the full widget.\n */\n\nimport type { ConsentValue } from './types'\n\n// ─── Consent builders ─────────────────────────────────────────────────────────\n\n/**\n * Builds a `ConsentValue` map from explicit grant/deny lists.\n *\n * @example\n * ```ts\n * const consent = mockConsent(\n * ['analytics_storage'], // granted\n * ['ad_storage', 'ad_user_data'], // denied\n * )\n * // → { analytics_storage: 'granted', ad_storage: 'denied', ad_user_data: 'denied' }\n * ```\n */\nexport function mockConsent(granted: string[] = [], denied: string[] = []): ConsentValue {\n const result: ConsentValue = {}\n for (const id of granted) result[id] = 'granted'\n for (const id of denied) result[id] = 'denied'\n return result\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'granted'`.\n * Shorthand for the common \"user accepted everything\" test scenario.\n */\nexport function mockAllGranted(cookieIds: string[]): ConsentValue {\n return mockConsent(cookieIds, [])\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'denied'`.\n * Shorthand for the common \"user rejected everything\" test scenario.\n */\nexport function mockAllDenied(cookieIds: string[]): ConsentValue {\n return mockConsent([], cookieIds)\n}\n\n// ─── Event simulators ─────────────────────────────────────────────────────────\n\n/**\n * Dispatches `consenti:consentSubmitted` on `window` with the supplied consent\n * map. Use this to trigger code paths that listen to consent changes without\n * going through the full widget initialisation flow.\n */\nexport function simulateConsentSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n/**\n * Dispatches `consenti:bannerInitialized` on `window`.\n * Use this to simulate widget initialisation in tests that gate on the event.\n */\nexport function simulateBannerInitialized(hasExistingConsent = false): void {\n window.dispatchEvent(\n new CustomEvent('consenti:bannerInitialized', {\n detail: { hasExistingConsent },\n bubbles: true,\n }),\n )\n}\n\n/**\n * Dispatches `consenti:consentBeingSubmitted` on `window` before a simulated\n * consent submission. Use in tests that capture both events.\n */\nexport function simulateConsentBeingSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentBeingSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n// ─── Mock widget ──────────────────────────────────────────────────────────────\n\n/**\n * Shape returned by {@link createMockConsenti}.\n * Mirrors the public API of `ConsentiSetup` for use in unit tests.\n */\nexport interface MockConsentiSetup {\n hasConsent: () => boolean\n getConsent: () => ConsentValue | null\n getConsentDate: () => Date | false\n getGTMConsent: () => Record<string, string> | null\n submitConsent: (consent: Partial<ConsentValue>) => Promise<void>\n deleteConsent: () => Promise<void>\n showBanner: (useGpcVariant?: boolean) => void\n hideBanner: () => void\n showModal: () => void\n hideModal: () => void\n bannerVisibility: () => 'main' | 'gpc' | false\n modalVisibility: () => 'preference' | false\n onReady: (cb: () => void) => void\n readonly ready: Promise<void>\n destroy: () => void\n reConsent: () => Promise<void>\n}\n\n/**\n * Creates a minimal in-memory mock of `ConsentiSetup` for use in unit tests.\n *\n * All methods are no-ops or return sensible defaults. Pass an initial `consent`\n * map to simulate a returning visitor who has already given consent.\n *\n * The mock's `submitConsent` updates internal state and fires\n * `simulateConsentSubmitted` so event listeners in the component under test\n * are triggered exactly as in production.\n *\n * @example\n * ```ts\n * const widget = createMockConsenti(\n * mockConsent(['analytics_storage'], ['ad_storage'])\n * )\n * expect(widget.hasConsent()).toBe(true)\n * expect(widget.getConsent()?.analytics_storage).toBe('granted')\n *\n * await widget.submitConsent({ ad_storage: 'granted' })\n * expect(widget.getConsent()?.ad_storage).toBe('granted')\n * ```\n */\nexport function createMockConsenti(consent: ConsentValue | null = null): MockConsentiSetup {\n let currentConsent = consent\n\n return {\n hasConsent: () => currentConsent !== null,\n getConsent: () => currentConsent,\n getConsentDate: () => (currentConsent !== null ? new Date() : false),\n getGTMConsent: () => null,\n\n submitConsent: async (partial: Partial<ConsentValue>) => {\n currentConsent = { ...(currentConsent ?? {}), ...partial } as ConsentValue\n simulateConsentSubmitted(currentConsent)\n },\n\n deleteConsent: async () => {\n currentConsent = null\n },\n\n showBanner: () => {},\n hideBanner: () => {},\n showModal: () => {},\n hideModal: () => {},\n bannerVisibility: () => false as const,\n modalVisibility: () => false as const,\n\n onReady: (cb: () => void) => cb(),\n ready: Promise.resolve(),\n\n destroy: () => {},\n\n reConsent: async () => {\n currentConsent = null\n },\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,8BAAAC,EAAA,kCAAAC,EAAA,6BAAAC,IAAA,eAAAC,EAAAT,GAoCO,SAASK,EAAYK,EAAoB,CAAC,EAAGC,EAAmB,CAAC,EAAiB,CACvF,IAAMC,EAAuB,CAAC,EAC9B,QAAWC,KAAMH,EAASE,EAAOC,CAAE,EAAI,UACvC,QAAWA,KAAMF,EAAQC,EAAOC,CAAE,EAAI,SACtC,OAAOD,CACT,CAMO,SAASR,EAAeU,EAAmC,CAChE,OAAOT,EAAYS,EAAW,CAAC,CAAC,CAClC,CAMO,SAASX,EAAcW,EAAmC,CAC/D,OAAOT,EAAY,CAAC,EAAGS,CAAS,CAClC,CASO,SAASN,EAAyBO,EAA6B,CACpE,OAAO,cACL,IAAI,YAAY,4BAA6B,CAAE,OAAQ,CAAE,QAAAA,CAAQ,EAAG,QAAS,EAAK,CAAC,CACrF,CACF,CAMO,SAAST,EAA0BU,EAAqB,GAAa,CAC1E,OAAO,cACL,IAAI,YAAY,6BAA8B,CAC5C,OAAQ,CAAE,mBAAAA,CAAmB,EAC7B,QAAS,EACX,CAAC,CACH,CACF,CAMO,SAAST,EAA8BQ,EAA6B,CACzE,OAAO,cACL,IAAI,YAAY,iCAAkC,CAAE,OAAQ,CAAE,QAAAA,CAAQ,EAAG,QAAS,EAAK,CAAC,CAC1F,CACF,CAiDO,SAASb,EAAmBa,EAA+B,KAAyB,CACzF,IAAIE,EAAiBF,EAErB,MAAO,CACL,WAAY,IAAME,IAAmB,KACrC,WAAY,IAAMA,EAClB,eAAgB,IAAOA,IAAmB,KAAO,IAAI,KAAS,GAC9D,cAAe,IAAM,KAErB,cAAe,MAAOC,GAAmC,CACvDD,EAAiB,CAAE,GAAIA,GAAkB,CAAC,EAAI,GAAGC,CAAQ,EACzDV,EAAyBS,CAAc,CACzC,EAEA,cAAe,SAAY,CACzBA,EAAiB,IACnB,EAEA,WAAY,IAAM,CAAC,EACnB,WAAY,IAAM,CAAC,EACnB,UAAW,IAAM,CAAC,EAClB,UAAW,IAAM,CAAC,EAClB,iBAAkB,IAAM,GACxB,gBAAiB,IAAM,GAEvB,QAAUE,GAAmBA,EAAG,EAChC,MAAO,QAAQ,QAAQ,EAEvB,QAAS,IAAM,CAAC,EAEhB,UAAW,
|
|
1
|
+
{"version":3,"sources":["../src/testing.ts"],"sourcesContent":["/**\n * Test utilities for `@consenti/ui`.\n *\n * Import via the `/testing` subpath export so these helpers are never bundled\n * into production code:\n *\n * ```ts\n * import {\n * createMockConsenti,\n * mockConsent,\n * simulateConsentSubmitted,\n * } from '@consenti/ui/testing'\n * ```\n *\n * The helpers work in any JavaScript environment that provides a DOM\n * (browsers, jsdom, happy-dom). They carry no runtime dependencies and\n * do not import any Consenti internals — safe to use in unit tests without\n * initialising the full widget.\n */\n\nimport type { ConsentValue } from './types'\n\n// ─── Consent builders ─────────────────────────────────────────────────────────\n\n/**\n * Builds a `ConsentValue` map from explicit grant/deny lists.\n *\n * @example\n * ```ts\n * const consent = mockConsent(\n * ['analytics_storage'], // granted\n * ['ad_storage', 'ad_user_data'], // denied\n * )\n * // → { analytics_storage: 'granted', ad_storage: 'denied', ad_user_data: 'denied' }\n * ```\n */\nexport function mockConsent(granted: string[] = [], denied: string[] = []): ConsentValue {\n const result: ConsentValue = {}\n for (const id of granted) result[id] = 'granted'\n for (const id of denied) result[id] = 'denied'\n return result\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'granted'`.\n * Shorthand for the common \"user accepted everything\" test scenario.\n */\nexport function mockAllGranted(cookieIds: string[]): ConsentValue {\n return mockConsent(cookieIds, [])\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'denied'`.\n * Shorthand for the common \"user rejected everything\" test scenario.\n */\nexport function mockAllDenied(cookieIds: string[]): ConsentValue {\n return mockConsent([], cookieIds)\n}\n\n// ─── Event simulators ─────────────────────────────────────────────────────────\n\n/**\n * Dispatches `consenti:consentSubmitted` on `window` with the supplied consent\n * map. Use this to trigger code paths that listen to consent changes without\n * going through the full widget initialisation flow.\n */\nexport function simulateConsentSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n/**\n * Dispatches `consenti:bannerInitialized` on `window`.\n * Use this to simulate widget initialisation in tests that gate on the event.\n */\nexport function simulateBannerInitialized(hasExistingConsent = false): void {\n window.dispatchEvent(\n new CustomEvent('consenti:bannerInitialized', {\n detail: { hasExistingConsent },\n bubbles: true,\n }),\n )\n}\n\n/**\n * Dispatches `consenti:consentBeingSubmitted` on `window` before a simulated\n * consent submission. Use in tests that capture both events.\n */\nexport function simulateConsentBeingSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentBeingSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n// ─── Mock widget ──────────────────────────────────────────────────────────────\n\n/**\n * Shape returned by {@link createMockConsenti}.\n * Mirrors the public API of `ConsentiSetup` for use in unit tests.\n */\nexport interface MockConsentiSetup {\n hasConsent: () => boolean\n getConsent: () => ConsentValue | null\n getConsentDate: () => Date | false\n getGTMConsent: () => Record<string, string> | null\n submitConsent: (consent: Partial<ConsentValue>) => Promise<void>\n deleteConsent: () => Promise<void>\n showBanner: (useGpcVariant?: boolean) => void\n hideBanner: () => void\n showModal: () => void\n hideModal: () => void\n bannerVisibility: () => 'main' | 'gpc' | false\n modalVisibility: () => 'preference' | false\n onReady: (cb: () => void) => void\n readonly ready: Promise<void>\n destroy: () => void\n reConsent: (resetAgeGate?: boolean) => Promise<void>\n}\n\n/**\n * Creates a minimal in-memory mock of `ConsentiSetup` for use in unit tests.\n *\n * All methods are no-ops or return sensible defaults. Pass an initial `consent`\n * map to simulate a returning visitor who has already given consent.\n *\n * The mock's `submitConsent` updates internal state and fires\n * `simulateConsentSubmitted` so event listeners in the component under test\n * are triggered exactly as in production.\n *\n * @example\n * ```ts\n * const widget = createMockConsenti(\n * mockConsent(['analytics_storage'], ['ad_storage'])\n * )\n * expect(widget.hasConsent()).toBe(true)\n * expect(widget.getConsent()?.analytics_storage).toBe('granted')\n *\n * await widget.submitConsent({ ad_storage: 'granted' })\n * expect(widget.getConsent()?.ad_storage).toBe('granted')\n * ```\n */\nexport function createMockConsenti(consent: ConsentValue | null = null): MockConsentiSetup {\n let currentConsent = consent\n\n return {\n hasConsent: () => currentConsent !== null,\n getConsent: () => currentConsent,\n getConsentDate: () => (currentConsent !== null ? new Date() : false),\n getGTMConsent: () => null,\n\n submitConsent: async (partial: Partial<ConsentValue>) => {\n currentConsent = { ...(currentConsent ?? {}), ...partial } as ConsentValue\n simulateConsentSubmitted(currentConsent)\n },\n\n deleteConsent: async () => {\n currentConsent = null\n },\n\n showBanner: () => {},\n hideBanner: () => {},\n showModal: () => {},\n hideModal: () => {},\n bannerVisibility: () => false as const,\n modalVisibility: () => false as const,\n\n onReady: (cb: () => void) => cb(),\n ready: Promise.resolve(),\n\n destroy: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GAAGC,CAAQ,EACzDV,EAAyBS,CAAc,CACzC,EAEA,cAAe,SAAY,CACzBA,EAAiB,IACnB,EAEA,WAAY,IAAM,CAAC,EACnB,WAAY,IAAM,CAAC,EACnB,UAAW,IAAM,CAAC,EAClB,UAAW,IAAM,CAAC,EAClB,iBAAkB,IAAM,GACxB,gBAAiB,IAAM,GAEvB,QAAUE,GAAmBA,EAAG,EAChC,MAAO,QAAQ,QAAQ,EAEvB,QAAS,IAAM,CAAC,EAEhB,UAAW,MAAOC,GAA4B,CAC5CH,EAAiB,IACnB,CACF,CACF","names":["testing_exports","__export","createMockConsenti","mockAllDenied","mockAllGranted","mockConsent","simulateBannerInitialized","simulateConsentBeingSubmitted","simulateConsentSubmitted","__toCommonJS","granted","denied","result","id","cookieIds","consent","hasExistingConsent","currentConsent","partial","cb","_resetAgeGate"]}
|
package/dist/testing.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function s(e=[],n=[]){let t={};for(let o of e)t[o]="granted";for(let o of n)t[o]="denied";return t}function a(e){return s(e,[])}function l(e){return s([],e)}function i(e){window.dispatchEvent(new CustomEvent("consenti:consentSubmitted",{detail:{consent:e},bubbles:!0}))}function r(e=!1){window.dispatchEvent(new CustomEvent("consenti:bannerInitialized",{detail:{hasExistingConsent:e},bubbles:!0}))}function d(e){window.dispatchEvent(new CustomEvent("consenti:consentBeingSubmitted",{detail:{consent:e},bubbles:!0}))}function u(e=null){let n=e;return{hasConsent:()=>n!==null,getConsent:()=>n,getConsentDate:()=>n!==null?new Date:!1,getGTMConsent:()=>null,submitConsent:async t=>{n={...n??{},...t},i(n)},deleteConsent:async()=>{n=null},showBanner:()=>{},hideBanner:()=>{},showModal:()=>{},hideModal:()=>{},bannerVisibility:()=>!1,modalVisibility:()=>!1,onReady:t=>t(),ready:Promise.resolve(),destroy:()=>{},reConsent:async
|
|
1
|
+
function s(e=[],n=[]){let t={};for(let o of e)t[o]="granted";for(let o of n)t[o]="denied";return t}function a(e){return s(e,[])}function l(e){return s([],e)}function i(e){window.dispatchEvent(new CustomEvent("consenti:consentSubmitted",{detail:{consent:e},bubbles:!0}))}function r(e=!1){window.dispatchEvent(new CustomEvent("consenti:bannerInitialized",{detail:{hasExistingConsent:e},bubbles:!0}))}function d(e){window.dispatchEvent(new CustomEvent("consenti:consentBeingSubmitted",{detail:{consent:e},bubbles:!0}))}function u(e=null){let n=e;return{hasConsent:()=>n!==null,getConsent:()=>n,getConsentDate:()=>n!==null?new Date:!1,getGTMConsent:()=>null,submitConsent:async t=>{n={...n??{},...t},i(n)},deleteConsent:async()=>{n=null},showBanner:()=>{},hideBanner:()=>{},showModal:()=>{},hideModal:()=>{},bannerVisibility:()=>!1,modalVisibility:()=>!1,onReady:t=>t(),ready:Promise.resolve(),destroy:()=>{},reConsent:async t=>{n=null}}}export{u as createMockConsenti,l as mockAllDenied,a as mockAllGranted,s as mockConsent,r as simulateBannerInitialized,d as simulateConsentBeingSubmitted,i as simulateConsentSubmitted};
|
|
2
2
|
//# sourceMappingURL=testing.mjs.map
|
package/dist/testing.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/testing.ts"],"sourcesContent":["/**\n * Test utilities for `@consenti/ui`.\n *\n * Import via the `/testing` subpath export so these helpers are never bundled\n * into production code:\n *\n * ```ts\n * import {\n * createMockConsenti,\n * mockConsent,\n * simulateConsentSubmitted,\n * } from '@consenti/ui/testing'\n * ```\n *\n * The helpers work in any JavaScript environment that provides a DOM\n * (browsers, jsdom, happy-dom). They carry no runtime dependencies and\n * do not import any Consenti internals — safe to use in unit tests without\n * initialising the full widget.\n */\n\nimport type { ConsentValue } from './types'\n\n// ─── Consent builders ─────────────────────────────────────────────────────────\n\n/**\n * Builds a `ConsentValue` map from explicit grant/deny lists.\n *\n * @example\n * ```ts\n * const consent = mockConsent(\n * ['analytics_storage'], // granted\n * ['ad_storage', 'ad_user_data'], // denied\n * )\n * // → { analytics_storage: 'granted', ad_storage: 'denied', ad_user_data: 'denied' }\n * ```\n */\nexport function mockConsent(granted: string[] = [], denied: string[] = []): ConsentValue {\n const result: ConsentValue = {}\n for (const id of granted) result[id] = 'granted'\n for (const id of denied) result[id] = 'denied'\n return result\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'granted'`.\n * Shorthand for the common \"user accepted everything\" test scenario.\n */\nexport function mockAllGranted(cookieIds: string[]): ConsentValue {\n return mockConsent(cookieIds, [])\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'denied'`.\n * Shorthand for the common \"user rejected everything\" test scenario.\n */\nexport function mockAllDenied(cookieIds: string[]): ConsentValue {\n return mockConsent([], cookieIds)\n}\n\n// ─── Event simulators ─────────────────────────────────────────────────────────\n\n/**\n * Dispatches `consenti:consentSubmitted` on `window` with the supplied consent\n * map. Use this to trigger code paths that listen to consent changes without\n * going through the full widget initialisation flow.\n */\nexport function simulateConsentSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n/**\n * Dispatches `consenti:bannerInitialized` on `window`.\n * Use this to simulate widget initialisation in tests that gate on the event.\n */\nexport function simulateBannerInitialized(hasExistingConsent = false): void {\n window.dispatchEvent(\n new CustomEvent('consenti:bannerInitialized', {\n detail: { hasExistingConsent },\n bubbles: true,\n }),\n )\n}\n\n/**\n * Dispatches `consenti:consentBeingSubmitted` on `window` before a simulated\n * consent submission. Use in tests that capture both events.\n */\nexport function simulateConsentBeingSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentBeingSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n// ─── Mock widget ──────────────────────────────────────────────────────────────\n\n/**\n * Shape returned by {@link createMockConsenti}.\n * Mirrors the public API of `ConsentiSetup` for use in unit tests.\n */\nexport interface MockConsentiSetup {\n hasConsent: () => boolean\n getConsent: () => ConsentValue | null\n getConsentDate: () => Date | false\n getGTMConsent: () => Record<string, string> | null\n submitConsent: (consent: Partial<ConsentValue>) => Promise<void>\n deleteConsent: () => Promise<void>\n showBanner: (useGpcVariant?: boolean) => void\n hideBanner: () => void\n showModal: () => void\n hideModal: () => void\n bannerVisibility: () => 'main' | 'gpc' | false\n modalVisibility: () => 'preference' | false\n onReady: (cb: () => void) => void\n readonly ready: Promise<void>\n destroy: () => void\n reConsent: () => Promise<void>\n}\n\n/**\n * Creates a minimal in-memory mock of `ConsentiSetup` for use in unit tests.\n *\n * All methods are no-ops or return sensible defaults. Pass an initial `consent`\n * map to simulate a returning visitor who has already given consent.\n *\n * The mock's `submitConsent` updates internal state and fires\n * `simulateConsentSubmitted` so event listeners in the component under test\n * are triggered exactly as in production.\n *\n * @example\n * ```ts\n * const widget = createMockConsenti(\n * mockConsent(['analytics_storage'], ['ad_storage'])\n * )\n * expect(widget.hasConsent()).toBe(true)\n * expect(widget.getConsent()?.analytics_storage).toBe('granted')\n *\n * await widget.submitConsent({ ad_storage: 'granted' })\n * expect(widget.getConsent()?.ad_storage).toBe('granted')\n * ```\n */\nexport function createMockConsenti(consent: ConsentValue | null = null): MockConsentiSetup {\n let currentConsent = consent\n\n return {\n hasConsent: () => currentConsent !== null,\n getConsent: () => currentConsent,\n getConsentDate: () => (currentConsent !== null ? new Date() : false),\n getGTMConsent: () => null,\n\n submitConsent: async (partial: Partial<ConsentValue>) => {\n currentConsent = { ...(currentConsent ?? {}), ...partial } as ConsentValue\n simulateConsentSubmitted(currentConsent)\n },\n\n deleteConsent: async () => {\n currentConsent = null\n },\n\n showBanner: () => {},\n hideBanner: () => {},\n showModal: () => {},\n hideModal: () => {},\n bannerVisibility: () => false as const,\n modalVisibility: () => false as const,\n\n onReady: (cb: () => void) => cb(),\n ready: Promise.resolve(),\n\n destroy: () => {},\n\n reConsent: async () => {\n currentConsent = null\n },\n }\n}\n"],"mappings":"AAoCO,SAASA,EAAYC,EAAoB,CAAC,EAAGC,EAAmB,CAAC,EAAiB,CACvF,IAAMC,EAAuB,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,
|
|
1
|
+
{"version":3,"sources":["../src/testing.ts"],"sourcesContent":["/**\n * Test utilities for `@consenti/ui`.\n *\n * Import via the `/testing` subpath export so these helpers are never bundled\n * into production code:\n *\n * ```ts\n * import {\n * createMockConsenti,\n * mockConsent,\n * simulateConsentSubmitted,\n * } from '@consenti/ui/testing'\n * ```\n *\n * The helpers work in any JavaScript environment that provides a DOM\n * (browsers, jsdom, happy-dom). They carry no runtime dependencies and\n * do not import any Consenti internals — safe to use in unit tests without\n * initialising the full widget.\n */\n\nimport type { ConsentValue } from './types'\n\n// ─── Consent builders ─────────────────────────────────────────────────────────\n\n/**\n * Builds a `ConsentValue` map from explicit grant/deny lists.\n *\n * @example\n * ```ts\n * const consent = mockConsent(\n * ['analytics_storage'], // granted\n * ['ad_storage', 'ad_user_data'], // denied\n * )\n * // → { analytics_storage: 'granted', ad_storage: 'denied', ad_user_data: 'denied' }\n * ```\n */\nexport function mockConsent(granted: string[] = [], denied: string[] = []): ConsentValue {\n const result: ConsentValue = {}\n for (const id of granted) result[id] = 'granted'\n for (const id of denied) result[id] = 'denied'\n return result\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'granted'`.\n * Shorthand for the common \"user accepted everything\" test scenario.\n */\nexport function mockAllGranted(cookieIds: string[]): ConsentValue {\n return mockConsent(cookieIds, [])\n}\n\n/**\n * Returns a `ConsentValue` with every listed cookie set to `'denied'`.\n * Shorthand for the common \"user rejected everything\" test scenario.\n */\nexport function mockAllDenied(cookieIds: string[]): ConsentValue {\n return mockConsent([], cookieIds)\n}\n\n// ─── Event simulators ─────────────────────────────────────────────────────────\n\n/**\n * Dispatches `consenti:consentSubmitted` on `window` with the supplied consent\n * map. Use this to trigger code paths that listen to consent changes without\n * going through the full widget initialisation flow.\n */\nexport function simulateConsentSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n/**\n * Dispatches `consenti:bannerInitialized` on `window`.\n * Use this to simulate widget initialisation in tests that gate on the event.\n */\nexport function simulateBannerInitialized(hasExistingConsent = false): void {\n window.dispatchEvent(\n new CustomEvent('consenti:bannerInitialized', {\n detail: { hasExistingConsent },\n bubbles: true,\n }),\n )\n}\n\n/**\n * Dispatches `consenti:consentBeingSubmitted` on `window` before a simulated\n * consent submission. Use in tests that capture both events.\n */\nexport function simulateConsentBeingSubmitted(consent: ConsentValue): void {\n window.dispatchEvent(\n new CustomEvent('consenti:consentBeingSubmitted', { detail: { consent }, bubbles: true }),\n )\n}\n\n// ─── Mock widget ──────────────────────────────────────────────────────────────\n\n/**\n * Shape returned by {@link createMockConsenti}.\n * Mirrors the public API of `ConsentiSetup` for use in unit tests.\n */\nexport interface MockConsentiSetup {\n hasConsent: () => boolean\n getConsent: () => ConsentValue | null\n getConsentDate: () => Date | false\n getGTMConsent: () => Record<string, string> | null\n submitConsent: (consent: Partial<ConsentValue>) => Promise<void>\n deleteConsent: () => Promise<void>\n showBanner: (useGpcVariant?: boolean) => void\n hideBanner: () => void\n showModal: () => void\n hideModal: () => void\n bannerVisibility: () => 'main' | 'gpc' | false\n modalVisibility: () => 'preference' | false\n onReady: (cb: () => void) => void\n readonly ready: Promise<void>\n destroy: () => void\n reConsent: (resetAgeGate?: boolean) => Promise<void>\n}\n\n/**\n * Creates a minimal in-memory mock of `ConsentiSetup` for use in unit tests.\n *\n * All methods are no-ops or return sensible defaults. Pass an initial `consent`\n * map to simulate a returning visitor who has already given consent.\n *\n * The mock's `submitConsent` updates internal state and fires\n * `simulateConsentSubmitted` so event listeners in the component under test\n * are triggered exactly as in production.\n *\n * @example\n * ```ts\n * const widget = createMockConsenti(\n * mockConsent(['analytics_storage'], ['ad_storage'])\n * )\n * expect(widget.hasConsent()).toBe(true)\n * expect(widget.getConsent()?.analytics_storage).toBe('granted')\n *\n * await widget.submitConsent({ ad_storage: 'granted' })\n * expect(widget.getConsent()?.ad_storage).toBe('granted')\n * ```\n */\nexport function createMockConsenti(consent: ConsentValue | null = null): MockConsentiSetup {\n let currentConsent = consent\n\n return {\n hasConsent: () => currentConsent !== null,\n getConsent: () => currentConsent,\n getConsentDate: () => (currentConsent !== null ? new Date() : false),\n getGTMConsent: () => null,\n\n submitConsent: async (partial: Partial<ConsentValue>) => {\n currentConsent = { ...(currentConsent ?? {}), ...partial } as ConsentValue\n simulateConsentSubmitted(currentConsent)\n },\n\n deleteConsent: async () => {\n currentConsent = null\n },\n\n showBanner: () => {},\n hideBanner: () => {},\n showModal: () => {},\n hideModal: () => {},\n bannerVisibility: () => false as const,\n modalVisibility: () => false as const,\n\n onReady: (cb: () => void) => cb(),\n ready: Promise.resolve(),\n\n destroy: () => {},\n\n reConsent: async (_resetAgeGate?: boolean) => {\n currentConsent = null\n },\n }\n}\n"],"mappings":"AAoCO,SAASA,EAAYC,EAAoB,CAAC,EAAGC,EAAmB,CAAC,EAAiB,CACvF,IAAMC,EAAuB,CAAC,EAC9B,QAAWC,KAAMH,EAASE,EAAOC,CAAE,EAAI,UACvC,QAAWA,KAAMF,EAAQC,EAAOC,CAAE,EAAI,SACtC,OAAOD,CACT,CAMO,SAASE,EAAeC,EAAmC,CAChE,OAAON,EAAYM,EAAW,CAAC,CAAC,CAClC,CAMO,SAASC,EAAcD,EAAmC,CAC/D,OAAON,EAAY,CAAC,EAAGM,CAAS,CAClC,CASO,SAASE,EAAyBC,EAA6B,CACpE,OAAO,cACL,IAAI,YAAY,4BAA6B,CAAE,OAAQ,CAAE,QAAAA,CAAQ,EAAG,QAAS,EAAK,CAAC,CACrF,CACF,CAMO,SAASC,EAA0BC,EAAqB,GAAa,CAC1E,OAAO,cACL,IAAI,YAAY,6BAA8B,CAC5C,OAAQ,CAAE,mBAAAA,CAAmB,EAC7B,QAAS,EACX,CAAC,CACH,CACF,CAMO,SAASC,EAA8BH,EAA6B,CACzE,OAAO,cACL,IAAI,YAAY,iCAAkC,CAAE,OAAQ,CAAE,QAAAA,CAAQ,EAAG,QAAS,EAAK,CAAC,CAC1F,CACF,CAiDO,SAASI,EAAmBJ,EAA+B,KAAyB,CACzF,IAAIK,EAAiBL,EAErB,MAAO,CACL,WAAY,IAAMK,IAAmB,KACrC,WAAY,IAAMA,EAClB,eAAgB,IAAOA,IAAmB,KAAO,IAAI,KAAS,GAC9D,cAAe,IAAM,KAErB,cAAe,MAAOC,GAAmC,CACvDD,EAAiB,CAAE,GAAIA,GAAkB,CAAC,EAAI,GAAGC,CAAQ,EACzDP,EAAyBM,CAAc,CACzC,EAEA,cAAe,SAAY,CACzBA,EAAiB,IACnB,EAEA,WAAY,IAAM,CAAC,EACnB,WAAY,IAAM,CAAC,EACnB,UAAW,IAAM,CAAC,EAClB,UAAW,IAAM,CAAC,EAClB,iBAAkB,IAAM,GACxB,gBAAiB,IAAM,GAEvB,QAAUE,GAAmBA,EAAG,EAChC,MAAO,QAAQ,QAAQ,EAEvB,QAAS,IAAM,CAAC,EAEhB,UAAW,MAAOC,GAA4B,CAC5CH,EAAiB,IACnB,CACF,CACF","names":["mockConsent","granted","denied","result","id","mockAllGranted","cookieIds","mockAllDenied","simulateConsentSubmitted","consent","simulateBannerInitialized","hasExistingConsent","simulateConsentBeingSubmitted","createMockConsenti","currentConsent","partial","cb","_resetAgeGate"]}
|