UNPKG

@c15t/react

Version:

Developer-first CMP for React: cookie banner, consent manager, preferences centre. GDPR ready with minimal setup and rich customization

1 lines 3.18 kB
"use strict";let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,n)=>{for(var r in n)__webpack_require__.o(n,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},__webpack_require__.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{setupMocks:()=>setupMocks,TestConsumer:()=>TestConsumer});let jsx_runtime_namespaceObject=require("react/jsx-runtime"),external_vitest_namespaceObject=require("vitest"),external_index_cjs_namespaceObject=require("../../index.cjs");function setupMocks(){let e=external_vitest_namespaceObject.vi.fn();window.fetch=e;let n=external_vitest_namespaceObject.vi.fn(),r=new Map;return(0,external_vitest_namespaceObject.beforeEach)(()=>{r.clear()}),external_vitest_namespaceObject.vi.mock("c15t",async()=>({...await external_vitest_namespaceObject.vi.importActual("c15t"),configureConsentManager:s=>{n(s);let t=s.backendURL||"";if("c15t"===s.mode)return{getCallbacks:()=>s.callbacks,showConsentBanner:async()=>(r.has(t)||(e(`${t}/show-consent-banner`,{headers:{"Content-Type":"application/json"}}),r.set(t,!0)),{ok:!0,data:{showConsentBanner:!0},error:null,response:null}),setConsent:async()=>({ok:!0,data:{success:!0},error:null,response:null}),verifyConsent:async()=>({ok:!0,data:{valid:!0},error:null,response:null})};if("offline"===s.mode)return{getCallbacks:()=>s.callbacks,showConsentBanner:async()=>({ok:!0,data:{showConsentBanner:!0},error:null,response:null}),setConsent:async()=>({ok:!0,data:{success:!0},error:null,response:null}),verifyConsent:async()=>({ok:!0,data:{valid:!0},error:null,response:null})};if("custom"===s.mode&&"endpointHandlers"in s){let e=s.endpointHandlers;return{getCallbacks:()=>s.callbacks,showConsentBanner:async()=>e.showConsentBanner({}),setConsent:async n=>e.setConsent({body:n}),verifyConsent:async n=>e.verifyConsent({body:n})}}return{getCallbacks:()=>s.callbacks,showConsentBanner:async()=>({ok:!0,data:{showConsentBanner:!0},error:null,response:null}),setConsent:async()=>({ok:!0,data:{success:!0},error:null,response:null}),verifyConsent:async()=>({ok:!0,data:{valid:!0},error:null,response:null})}}})),{mockFetch:e,mockConfigureConsentManager:n}}let TestConsumer=()=>{let e=(0,external_index_cjs_namespaceObject.useConsentManager)();return(0,jsx_runtime_namespaceObject.jsx)("div",{"data-testid":"consumer",children:e.showPopup?"Show":"Hide"})};for(var __webpack_i__ in exports.TestConsumer=__webpack_exports__.TestConsumer,exports.setupMocks=__webpack_exports__.setupMocks,__webpack_exports__)-1===["TestConsumer","setupMocks"].indexOf(__webpack_i__)&&(exports[__webpack_i__]=__webpack_exports__[__webpack_i__]);Object.defineProperty(exports,"__esModule",{value:!0});