@phygitallabs/phygital-consent 1.0.4 → 1.0.6

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,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.5] - 2026-02-02
9
+
10
+ ### Added
11
+ - **Optional auto banner** – `PhygitalConsentProvider` accepts `showBannerWhenNoPreference` (default `true`). When `true`, `CookieConsentBanner` is rendered automatically when the user has no stored preference. Set to `false` to render the banner yourself (e.g. in a layout) via `usePhygitalConsent()`.
12
+
13
+ ### Changed
14
+ - **Consent payload** – Reject and accept actions now send `selected_preferences: []` when no preferences are selected, instead of defaulting to `["essential"]`.
package/dist/index.cjs CHANGED
@@ -1,3 +1,5 @@
1
1
  'use client'
2
- "use strict";var oe=Object.create;var A=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var ae=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of re(t))!ce.call(e,s)&&s!==n&&A(e,s,{get:()=>t[s],enumerable:!(o=se(t,s))||o.enumerable});return e};var de=(e,t,n)=>(n=e!=null?oe(ie(e)):{},F(t||!e||!e.__esModule?A(n,"default",{value:e,enumerable:!0}):n,e)),le=e=>F(A({},"__esModule",{value:!0}),e);var we={};ae(we,{COOKIE_CONSENT_NAME:()=>G,CookieConsentBanner:()=>Se,EntityStatus:()=>W,MediaType:()=>z,PhygitalConsentProvider:()=>pe,consentQueryKeys:()=>C,consentService:()=>v,getConsentPreferenceCookie:()=>L,getCookie:()=>$,setConsentPreferenceCookie:()=>q,setCookie:()=>j,sha256:()=>S,useConsentById:()=>Re,useCreateDeviceCookieConsent:()=>H,useCreateUserConsent:()=>Ie,useHealth:()=>xe,useLatestConsentByUserId:()=>Pe,useLatestCookieConsentByDeviceId:()=>ke,useManyConsents:()=>ve,usePhygitalConsent:()=>M});module.exports=le(we);var z=(n=>(n.IMAGE="image",n.VIDEO="video",n))(z||{}),W=(n=>(n.ACTIVE="Active",n.INACTIVE="Inactive",n))(W||{});var b=require("react");var G="phygital_cookie_consent";function $(e){if(typeof document>"u")return null;let t=document.cookie.match(new RegExp("(?:^|; )"+encodeURIComponent(e)+"=([^;]*)"));return t?decodeURIComponent(t[1]):null}function j(e,t,n={}){if(typeof document>"u")return;let{maxAge:o=31536e3,path:s="/",sameSite:a="Lax",secure:d=!1}=n,l=`${encodeURIComponent(e)}=${encodeURIComponent(t)}; path=${s}; max-age=${o}; SameSite=${a}`;d&&(l+="; Secure"),document.cookie=l}function L(){let e=$(G);if(!e)return null;try{let t=JSON.parse(e);if(t&&typeof t=="object"&&"deviceId"in t&&"selected_preferences"in t&&typeof t.deviceId=="string"&&Array.isArray(t.selected_preferences))return t}catch{}return null}function q(e,t,n){j(G,JSON.stringify({deviceId:e,selected_preferences:t}),{maxAge:31536e3,path:"/",sameSite:"Lax",...n})}var E=require("@tanstack/react-query"),Y=de(require("axios")),I=require("react"),V=require("react/jsx-runtime"),J=(0,I.createContext)(void 0),ue=({baseURL:e="",axiosConfig:t={},requestInterceptors:n={},responseInterceptors:o={}})=>{let s=Y.default.create({baseURL:e,...t});return s.interceptors.request.use(n.onFulfilled,n.onRejected),s.interceptors.response.use(o.onFulfilled,o.onRejected),{consentApi:s,updateHeaders:d=>{Object.entries(d).forEach(([l,u])=>{s.defaults.headers.common[l]=u})}}},X=({children:e,baseURL:t="",axiosConfig:n={},queryClient:o,queryClientConfig:s={},requestInterceptors:a={},responseInterceptors:d={}})=>{let l=(0,I.useMemo)(()=>o||new E.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,...s?.defaultOptions?.queries},mutations:{...s?.defaultOptions?.mutations}},queryCache:s?.queryCache,mutationCache:s?.mutationCache}),[o]),u=(0,I.useMemo)(()=>{let c=ue({baseURL:t,axiosConfig:n,requestInterceptors:a,responseInterceptors:d});return{consentApi:c.consentApi,updateHeaders:c.updateHeaders,queryClient:l}},[t,l,n,a,d]);return(0,V.jsx)(J.Provider,{value:u,children:(0,V.jsx)(E.QueryClientProvider,{client:l,children:e})})},R=()=>{let e=(0,I.useContext)(J);if(!e)throw new Error("useConsentService must be used within a ConsentServiceProvider");return e};var K=require("react/jsx-runtime"),Z=(0,b.createContext)(void 0);function pe(e){let{children:t,deviceId:n,...o}=e,[s,a]=(0,b.useState)(!1),d=(0,b.useCallback)(()=>{let u=L();a(!!u)},[]);(0,b.useEffect)(()=>{d()},[d]);let l={deviceId:n,hasConsentPreference:s,refreshConsentPreference:d};return(0,K.jsx)(X,{...o,children:(0,K.jsx)(Z.Provider,{value:l,children:t})})}function M(){let e=(0,b.useContext)(Z);if(!e)throw new Error("usePhygitalConsent must be used within a PhygitalConsentProvider");return e}var _="",v=e=>({getHealth:async()=>{let{data:t}=await e.get("/health");return t},getManyConsents:async t=>{let{data:n}=await e.get(`${_}/consent`,{params:t?{type:t.type}:void 0});return n},getConsentById:async({id:t})=>{let{data:n}=await e.get(`${_}/consent/${t}`);return n},getLatestConsentByUserId:async({user_id:t})=>{let{data:n}=await e.get(`${_}/user-id`,{params:{user_id:t}});return n},createUserConsent:async t=>{let{data:n}=await e.post(`${_}/user-id`,t);return n},getLatestCookieConsentByDeviceId:async({device_id:t})=>{let{data:n}=await e.get(`${_}/cookies/device-id`,{params:{device_id:t}});return n},createDeviceCookieConsent:async t=>{let{data:n}=await e.post(`${_}/cookies/device-id`,t);return n}});var m=require("@tanstack/react-query");function fe(e){return Array.from(new Uint8Array(e)).map(t=>t.toString(16).padStart(2,"0")).join("").toLowerCase()}async function Ce(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return fe(n)}function me(e){let t=ge(e),n=he(),o=ye(),s=new Uint32Array(64),a=t.length>>6;for(let l=0;l<a;l++){let u=l<<6;for(let p=0;p<16;p++){let i=u+(p<<2);s[p]=t[i]<<24|t[i+1]<<16|t[i+2]<<8|t[i+3]}for(let p=16;p<64;p++){let i=x(s[p-15],7)^x(s[p-15],18)^s[p-15]>>>3,f=x(s[p-2],17)^x(s[p-2],19)^s[p-2]>>>10;s[p]=s[p-16]+i+s[p-7]+f>>>0}let c=o[0],P=o[1],h=o[2],g=o[3],y=o[4],w=o[5],U=o[6],B=o[7];for(let p=0;p<64;p++){let i=x(y,6)^x(y,11)^x(y,25),f=y&w^~y&U,k=B+i+f+n[p]+s[p]>>>0,D=x(c,2)^x(c,13)^x(c,22),T=c&P^c&h^P&h,ne=D+T>>>0;B=U,U=w,w=y,y=g+k>>>0,g=h,h=P,P=c,c=k+ne>>>0}o[0]=o[0]+c>>>0,o[1]=o[1]+P>>>0,o[2]=o[2]+h>>>0,o[3]=o[3]+g>>>0,o[4]=o[4]+y>>>0,o[5]=o[5]+w>>>0,o[6]=o[6]+U>>>0,o[7]=o[7]+B>>>0}let d="";for(let l=0;l<8;l++){let u=o[l];d+=(u>>>28).toString(16)+(u>>>24&15).toString(16)+(u>>>20&15).toString(16)+(u>>>16&15).toString(16)+(u>>>12&15).toString(16)+(u>>>8&15).toString(16)+(u>>>4&15).toString(16)+(u&15).toString(16)}return d.toLowerCase()}function x(e,t){return e>>>t|e<<32-t}function ge(e){let t=e.length,n=[];for(let u=0;u<t;u++){let c=e.charCodeAt(u);c<128?n.push(c):c<2048?n.push(192|c>>6,128|c&63):c<55296||c>=57344?n.push(224|c>>12,128|c>>6&63,128|c&63):(c=65536+((c&1023)<<10|e.charCodeAt(++u)&1023),n.push(240|c>>18,128|c>>12&63,128|c>>6&63,128|c&63))}let o=n.length,s=(64-(o+9)%64)%64,a=o+9+s,d=new Uint8Array(a);d.set(n),d[o]=128;let l=new DataView(d.buffer,d.byteOffset,d.byteLength);return l.setUint32(a-8,0,!1),l.setUint32(a-4,o*8>>>0,!1),d}function he(){let e=[];return"428a2f98 71374491 b5c0fbcf e9b5dba5 3956c25b 59f111f1 923f82a4 ab1c5ed5 d807aa98 12835b01 243185be 550c7dc3 72be5d74 80deb1fe 9bdc06a7 c19bf174 e49b69c1 efbe4786 0fc19dc6 240ca1cc 2de92c6f 4a7484aa 5cb0a9dc 76f988da 983e5152 a831c66d b00327c8 bf597fc7 c6e00bf3 d5a79147 06ca6351 14292967 27b70a85 2e1b2138 4d2c6dfc 53380d13 650a7354 766a0abb 81c2c92e 92722c85 a2bfe8a1 a81a664b c24b8b70 c76c51a3 d192e819 d6990624 f40e3585 106aa070 19a4c116 1e376c08 2748774c 34b0bcb5 391c0cb3 4ed8aa4a 5b9cca4f 682e6ff3 748f82ee 78a5636f 84c87814 8cc70208 90befffa a4506ceb bef9a3f7 c67178f2".split(" ").forEach(n=>e.push(parseInt(n,16))),e}function ye(){return[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]}function be(){return!(typeof crypto>"u"||!crypto.subtle)}async function S(e){return typeof e!="string"||e.length===0?e:be()?Ce(e):Promise.resolve(me(e))}var C={all:["consent"],health:()=>[...C.all,"health"],list:e=>[...C.all,"list",e],detail:e=>[...C.all,"detail",e],latestByUserId:e=>[...C.all,"user-id",e],latestCookieByDeviceId:e=>[...C.all,"cookies","device-id",e]},xe=e=>{let{consentApi:t}=R(),n=v(t);return(0,m.useQuery)({queryKey:C.health(),queryFn:()=>n.getHealth(),...e})},ve=(e,t)=>{let{consentApi:n}=R(),o=v(n);return(0,m.useQuery)({queryKey:C.list(e),queryFn:()=>o.getManyConsents(e),...t})},Re=(e,t)=>{let{consentApi:n}=R(),o=v(n);return(0,m.useQuery)({queryKey:C.detail(e.id),queryFn:()=>o.getConsentById(e),enabled:!!e.id,...t})},Pe=(e,t)=>{let{consentApi:n}=R(),o=v(n);return(0,m.useQuery)({queryKey:C.latestByUserId(e.user_id),queryFn:async()=>{let s=await S(e.user_id);return o.getLatestConsentByUserId({user_id:s})},enabled:!!e.user_id,...t})},ke=(e,t)=>{let{consentApi:n}=R(),o=v(n);return(0,m.useQuery)({queryKey:C.latestCookieByDeviceId(e.device_id),queryFn:async()=>{let s=await S(e.device_id);return o.getLatestCookieConsentByDeviceId({device_id:s})},enabled:!!e.device_id,...t})},Ie=e=>{let{consentApi:t}=R(),n=(0,m.useQueryClient)(),o=v(t);return(0,m.useMutation)({mutationFn:async s=>{let a={...s};return s.user_id!=null&&s.user_id!==""&&(a.user_id=await S(s.user_id)),s.device_id!=null&&s.device_id!==""&&(a.device_id=await S(s.device_id)),o.createUserConsent(a)},onSuccess:(s,a)=>{a.user_id&&n.invalidateQueries({queryKey:C.latestByUserId(a.user_id)}),n.invalidateQueries({queryKey:C.list()})},...e})},H=e=>{let{consentApi:t}=R(),n=(0,m.useQueryClient)(),o=v(t);return(0,m.useMutation)({mutationFn:async s=>{let a={...s,device_id:await S(s.device_id)};return o.createDeviceCookieConsent(a)},onSuccess:(s,a)=>{n.invalidateQueries({queryKey:C.latestCookieByDeviceId(a.device_id)}),n.invalidateQueries({queryKey:C.list()})},...e})};var O=require("react");var r=require("react/jsx-runtime"),N=["essential","analytics","advertising"],Q={essential:{label:"Essential",description:"Required for the site to work (e.g. security, preferences).",labelVi:"C\u1EA7n thi\u1EBFt",descriptionVi:"C\u1EA7n thi\u1EBFt cho ho\u1EA1t \u0111\u1ED9ng c\u1EE7a trang (b\u1EA3o m\u1EADt, t\xF9y ch\u1ECDn)."},analytics:{label:"Analytics",description:"Help us improve by collecting anonymous usage data.",labelVi:"Ph\xE2n t\xEDch",descriptionVi:"Gi\xFAp ch\xFAng t\xF4i c\u1EA3i thi\u1EC7n b\u1EB1ng c\xE1ch thu th\u1EADp d\u1EEF li\u1EC7u s\u1EED d\u1EE5ng \u1EA9n danh."},advertising:{label:"Advertising",description:"Used to show you relevant ads and measure campaigns.",labelVi:"Qu\u1EA3ng c\xE1o",descriptionVi:"D\xF9ng \u0111\u1EC3 hi\u1EC3n th\u1ECB qu\u1EA3ng c\xE1o ph\xF9 h\u1EE3p v\xE0 \u0111o l\u01B0\u1EDDng chi\u1EBFn d\u1ECBch."}};function Se({onSubmitted:e,onDismiss:t,className:n=""}){let[o,s]=(0,O.useState)(!1),[a,d]=(0,O.useState)(!1),[l,u]=(0,O.useState)(null),[c,P]=(0,O.useState)({essential:!0,analytics:!0,advertising:!0}),{deviceId:h}=M(),g=H({onSuccess:(i,f)=>{q(h,f.selected_preferences??[]),e?.(),t?.(),s(!0),d(!1)}}),y=()=>N.filter(i=>c[i]),w=i=>{Q[i].disabled||P(f=>({...f,[i]:!f[i]}))},U=()=>{g.mutate({device_id:h,status:"REJECTED",selected_preferences:["essential"]})},B=()=>{g.mutate({device_id:h,status:"ACCEPTED",selected_preferences:[...N]})},p=()=>{let i=y();g.mutate({device_id:h,status:"ACCEPTED",selected_preferences:i.length>0?i:["essential"]})};return o?null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{role:"dialog","aria-label":"Th\xF4ng b\xE1o v\u1EC1 cookie",className:`consent:fixed consent:bottom-0 consent:left-0 consent:right-0 consent:z-50 consent:flex consent:flex-col consent:gap-4 consent:rounded-t-xl consent:border consent:border-b-0 consent:border-gray-200 consent:bg-white consent:p-4 consent:shadow-lg consent:md:left-4 consent:md:right-auto consent:md:bottom-4 consent:md:max-w-md consent:md:rounded-xl consent:md:border consent:md:border-gray-200 ${n}`,style:{position:"fixed",bottom:0,left:0,right:0,zIndex:50,display:"flex",flexDirection:"column",gap:"1rem",borderRadius:"0.75rem 0.75rem 0 0",borderWidth:"1px 1px 0 1px",borderColor:"#e5e7eb",backgroundColor:"#fff",padding:"1rem",boxShadow:"0 -4px 6px -1px rgb(0 0 0 / 0.1)"},children:[(0,r.jsx)("h2",{className:"consent:text-lg consent:font-semibold consent:text-gray-900",style:{fontSize:"1.125rem",fontWeight:600,color:"#111827"},children:"Th\xF4ng b\xE1o v\u1EC1 cookie"}),(0,r.jsxs)("div",{className:"consent:text-sm consent:text-gray-600",style:{fontSize:"0.875rem",color:"#4b5563",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[(0,r.jsx)("p",{children:"TapQuest s\u1EED d\u1EE5ng tr\xECnh theo d\xF5i (nh\u01B0 Cookie ho\u1EB7c SDK) cho:"}),(0,r.jsx)("ul",{style:{margin:0,paddingLeft:"1.25rem"},children:N.map(i=>(0,r.jsx)("li",{children:Q[i].labelVi},i))}),(0,r.jsx)("p",{children:"Tr\u01B0\u1EDBc khi b\u1EA1n \u0111\u1ED3ng \xFD, ch\u1EC9 nh\u1EEFng tr\xECnh theo d\xF5i ho\xE0n to\xE0n c\u1EA7n thi\u1EBFt m\u1EDBi \u0111\u01B0\u1EE3c tri\u1EC3n khai."}),(0,r.jsx)("p",{children:"N\u1EBFu b\u1EA1n ch\u1ECDn Ch\u1EA5p nh\u1EADn t\u1EA5t c\u1EA3, b\u1EA1n \u0111\u1ED3ng \xFD s\u1EED d\u1EE5ng t\u1EA5t c\u1EA3 tr\xECnh theo d\xF5i c\u1EE7a ch\xFAng t\xF4i."}),(0,r.jsx)("p",{children:"N\u1EBFu b\u1EA1n ch\u1ECDn T\u1EEB ch\u1ED1i t\u1EA5t c\u1EA3, b\u1EA1n t\u1EEB ch\u1ED1i nh\u1EEFng tr\xECnh theo d\xF5i y\xEAu c\u1EA7u s\u1EF1 \u0111\u1ED3ng \xFD c\u1EE7a b\u1EA1n v\xE0 s\u1EBD kh\xF4ng c\xF3 quy\u1EC1n truy c\u1EADp v\xE0o c\xE1c \u0111\u1EC1 ngh\u1ECB ho\u1EB7c n\u1ED9i dung \u0111\u01B0\u1EE3c c\xE1 nh\xE2n h\xF3a."}),(0,r.jsx)("p",{children:"N\u1EBFu b\u1EA1n ch\u1ECDn T\xF9y ch\u1ECDn, b\u1EA1n c\xF3 th\u1EC3 ch\u1ECDn xem b\u1EA1n c\xF3 \u0111\u1ED3ng \xFD s\u1EED d\u1EE5ng tr\xECnh theo d\xF5i tr\xEAn \u1EE9ng d\u1EE5ng c\u1EE7a ch\xFAng t\xF4i hay kh\xF4ng v\xE0 \u1EDF m\u1EE9c \u0111\u1ED9 n\xE0o."}),(0,r.jsxs)("p",{children:["B\u1EA1n c\xF3 th\u1EC3 r\xFAt l\u1EA1i s\u1EF1 \u0111\u1ED3ng \xFD c\u1EE7a m\xECnh b\u1EA5t k\u1EF3 l\xFAc n\xE0o b\u1EB1ng c\xE1ch nh\u1EA5p v\xE0o li\xEAn k\u1EBFt trong"," ","Ch\xEDnh s\xE1ch cookie"," ","c\u1EE7a ch\xFAng t\xF4i."]})]}),(0,r.jsxs)("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:[(0,r.jsx)("button",{type:"button",onClick:()=>d(!0),className:"consent:rounded-lg consent:border consent:border-gray-300 consent:bg-white consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-gray-700 consent:shadow-sm hover:consent:bg-gray-50 disabled:consent:opacity-50",style:{borderRadius:"0.5rem",border:"1px solid #111827",background:"#fff",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:"#111827",cursor:"pointer"},children:"T\xF9y ch\u1ECDn"}),(0,r.jsx)("button",{type:"button",onClick:U,disabled:g.isPending,className:"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50",style:{borderRadius:"0.5rem",background:"#111827",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:"#fff",border:"none",cursor:"pointer"},children:"T\u1EEB ch\u1ED1i t\u1EA5t c\u1EA3"}),(0,r.jsx)("button",{type:"button",onClick:B,disabled:g.isPending,className:"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50",style:{borderRadius:"0.5rem",background:"#111827",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:"#fff",border:"none",cursor:"pointer"},children:"Ch\u1EA5p nh\u1EADn t\u1EA5t c\u1EA3"})]}),g.isError&&(0,r.jsx)("p",{className:"consent:text-sm consent:text-red-600",style:{fontSize:"0.875rem",color:"#dc2626"},children:"\u0110\xE3 x\u1EA3y ra l\u1ED7i. Vui l\xF2ng th\u1EED l\u1EA1i."})]}),a&&(0,r.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Trung t\xE2m tu\u1EF3 ch\u1ECDn b\u1EA3o m\u1EADt",style:{position:"fixed",inset:0,zIndex:60,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)",padding:"1rem"},onClick:i=>i.target===i.currentTarget&&d(!1),children:(0,r.jsxs)("div",{className:"consent:bg-white consent:rounded-xl consent:border consent:border-gray-200 consent:shadow-lg consent:max-h-[90vh] consent:overflow-y-auto",style:{backgroundColor:"#fff",borderRadius:"0.75rem",border:"1px solid #e5e7eb",boxShadow:"0 10px 15px -3px rgb(0 0 0 / 0.1)",maxWidth:"28rem",width:"100%",maxHeight:"90vh",overflowY:"auto",padding:"1.25rem",position:"relative"},onClick:i=>i.stopPropagation(),children:[(0,r.jsx)("button",{type:"button",onClick:()=>d(!1),"aria-label":"\u0110\xF3ng",style:{position:"absolute",top:"1rem",right:"1rem",width:"2rem",height:"2rem",borderRadius:"0.25rem",border:"none",background:"transparent",cursor:"pointer",fontSize:"1.25rem",lineHeight:1,color:"#6b7280"},children:"\xD7"}),(0,r.jsx)("h2",{className:"consent:text-lg consent:font-semibold consent:text-gray-900",style:{fontSize:"1.125rem",fontWeight:600,color:"#111827",marginBottom:"0.75rem",paddingRight:"2rem"},children:"Trung t\xE2m tu\u1EF3 ch\u1ECDn b\u1EA3o m\u1EADt"}),(0,r.jsxs)("div",{className:"consent:text-sm consent:text-gray-600",style:{fontSize:"0.875rem",color:"#4b5563",marginBottom:"1rem"},children:[(0,r.jsx)("p",{style:{marginBottom:"0.5rem"},children:"Khi b\u1EA1n truy c\u1EADp b\u1EA5t k\u1EF3 trang web n\xE0o, trang web \u0111\xF3 c\xF3 th\u1EC3 l\u01B0u tr\u1EEF ho\u1EB7c truy xu\u1EA5t th\xF4ng tin tr\xEAn tr\xECnh duy\u1EC7t c\u1EE7a b\u1EA1n, ch\u1EE7 y\u1EBFu d\u01B0\u1EDBi d\u1EA1ng cookie. Th\xF4ng tin n\xE0y c\xF3 th\u1EC3 li\xEAn quan \u0111\u1EBFn b\u1EA1n, t\xF9y ch\u1ECDn c\u1EE7a b\u1EA1n ho\u1EB7c thi\u1EBFt b\u1ECB c\u1EE7a b\u1EA1n, v\xE0 ch\u1EE7 y\u1EBFu \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng \u0111\u1EC3 trang web ho\u1EA1t \u0111\u1ED9ng nh\u01B0 mong \u0111\u1EE3i."}),(0,r.jsx)("p",{style:{marginBottom:"0.5rem"},children:"Th\xF4ng tin n\xE0y th\u01B0\u1EDDng kh\xF4ng tr\u1EF1c ti\u1EBFp x\xE1c \u0111\u1ECBnh b\u1EA1n nh\u01B0ng c\xF3 th\u1EC3 mang l\u1EA1i tr\u1EA3i nghi\u1EC7m web \u0111\u01B0\u1EE3c c\xE1 nh\xE2n h\xF3a h\u01A1n. Ch\xFAng t\xF4i t\xF4n tr\u1ECDng quy\u1EC1n ri\xEAng t\u01B0 c\u1EE7a b\u1EA1n; b\u1EA1n c\xF3 th\u1EC3 ch\u1ECDn kh\xF4ng cho ph\xE9p m\u1ED9t s\u1ED1 lo\u1EA1i cookie. Nh\u1EA5p v\xE0o ti\xEAu \u0111\u1EC1 t\u1EEBng danh m\u1EE5c \u0111\u1EC3 t\xECm hi\u1EC3u th\xEAm v\xE0 thay \u0111\u1ED5i c\xE0i \u0111\u1EB7t m\u1EB7c \u0111\u1ECBnh. Vi\u1EC7c ch\u1EB7n m\u1ED9t s\u1ED1 cookie c\xF3 th\u1EC3 \u1EA3nh h\u01B0\u1EDFng \u0111\u1EBFn tr\u1EA3i nghi\u1EC7m c\u1EE7a b\u1EA1n v\u1EDBi trang web v\xE0 c\xE1c d\u1ECBch v\u1EE5 \u0111\u01B0\u1EE3c cung c\u1EA5p."}),(0,r.jsx)("p",{style:{marginBottom:"0.5rem"},children:'N\u1EBFu ch\u1ECDn "Kh\xF4ng theo d\xF5i" khi l\u1EA7n \u0111\u1EA7u s\u1EED d\u1EE5ng TapQuest, ch\u1EC9 cookie ho\xE0n to\xE0n c\u1EA7n thi\u1EBFt m\u1EDBi \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng.'}),(0,r.jsx)("span",{style:{color:"#2563eb",textDecoration:"underline"},children:"Th\xF4ng tin kh\xE1c"})]}),(0,r.jsx)("h3",{className:"consent:text-sm consent:font-semibold consent:text-gray-900",style:{fontSize:"0.875rem",fontWeight:600,color:"#111827",marginBottom:"0.75rem"},children:"Qu\u1EA3n l\xFD tu\u1EF3 ch\u1ECDn \u0111\u1ED3ng \xFD"}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",marginBottom:"1.25rem"},children:N.map(i=>{let f=Q[i],k=c[i],D=l===i;return(0,r.jsxs)("div",{style:{border:"1px solid #e5e7eb",borderRadius:"0.5rem",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.75rem",cursor:"pointer",backgroundColor:D?"#f9fafb":"transparent"},onClick:()=>u(D?null:i),children:[(0,r.jsx)("span",{style:{flexShrink:0,width:"1.25rem",height:"1.25rem",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1rem",color:"#6b7280",transform:D?"rotate(45deg)":"none",transition:"transform 0.2s"},children:"+"}),(0,r.jsx)("span",{className:"consent:font-medium consent:text-gray-900",style:{flex:1,fontSize:"0.875rem",fontWeight:500,color:"#111827"},children:f.labelVi}),(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":k,"aria-label":`${f.labelVi} ${k?"b\u1EADt":"t\u1EAFt"}`,disabled:f.disabled,onClick:T=>{T.stopPropagation(),w(i)},style:{flexShrink:0,width:44,height:24,borderRadius:12,border:"none",padding:0,cursor:f.disabled?"default":"pointer",backgroundColor:f.disabled?"#e5e7eb":k?"#111827":"#d1d5db",opacity:f.disabled?.7:1,transition:"background-color 0.2s"},children:(0,r.jsx)("span",{style:{display:"block",width:20,height:20,borderRadius:"50%",backgroundColor:"#fff",marginLeft:k?22:2,marginTop:2,transition:"margin-left 0.2s",boxShadow:"0 1px 2px rgb(0 0 0 / 0.2)"}})})]}),D&&(0,r.jsx)("div",{className:"consent:text-sm consent:text-gray-600",style:{fontSize:"0.875rem",color:"#4b5563",padding:"0 0.75rem 0.75rem 2.5rem",borderTop:"1px solid #e5e7eb"},children:f.descriptionVi})]},i)})}),(0,r.jsx)("button",{type:"button",onClick:p,disabled:g.isPending,className:"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50 consent:w-full",style:{borderRadius:"0.5rem",background:"#111827",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:"#fff",border:"none",cursor:"pointer",width:"100%"},children:"X\xE1c nh\u1EADn l\u1EF1a ch\u1ECDn c\u1EE7a t\xF4i"})]})})]})}0&&(module.exports={COOKIE_CONSENT_NAME,CookieConsentBanner,EntityStatus,MediaType,PhygitalConsentProvider,consentQueryKeys,consentService,getConsentPreferenceCookie,getCookie,setConsentPreferenceCookie,setCookie,sha256,useConsentById,useCreateDeviceCookieConsent,useCreateUserConsent,useHealth,useLatestConsentByUserId,useLatestCookieConsentByDeviceId,useManyConsents,usePhygitalConsent});
2
+ "use strict";var de=Object.create;var N=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var pe=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty;var fe=(e,t)=>{for(var n in t)N(e,n,{get:t[n],enumerable:!0})},J=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ue(t))!me.call(e,s)&&s!==n&&N(e,s,{get:()=>t[s],enumerable:!(o=le(t,s))||o.enumerable});return e};var ge=(e,t,n)=>(n=e!=null?de(pe(e)):{},J(t||!e||!e.__esModule?N(n,"default",{value:e,enumerable:!0}):n,e)),he=e=>J(N({},"__esModule",{value:!0}),e);var Ae={};fe(Ae,{COOKIE_CONSENT_NAME:()=>q,CookieConsentBanner:()=>F,EntityStatus:()=>Z,MediaType:()=>X,PhygitalConsentProvider:()=>_e,PolicyPopup:()=>Y,consentQueryKeys:()=>y,consentService:()=>S,getConsentPreferenceCookie:()=>V,getCookie:()=>ee,setConsentPreferenceCookie:()=>H,setCookie:()=>te,sha256:()=>D,useConsentById:()=>Ie,useCreateDeviceCookieConsent:()=>K,useCreateUserConsent:()=>M,useHealth:()=>Se,useLatestConsentByUserId:()=>Q,useLatestCookieConsentByDeviceId:()=>Ue,useManyConsents:()=>we,usePhygitalConsent:()=>$});module.exports=he(Ae);var X=(n=>(n.IMAGE="image",n.VIDEO="video",n))(X||{}),Z=(n=>(n.ACTIVE="Active",n.INACTIVE="Inactive",n))(Z||{});var b=require("react");var O=require("react");var q="phygital_cookie_consent";function ee(e){if(typeof document>"u")return null;let t=document.cookie.match(new RegExp("(?:^|; )"+encodeURIComponent(e)+"=([^;]*)"));return t?decodeURIComponent(t[1]):null}function te(e,t,n={}){if(typeof document>"u")return;let{maxAge:o=31536e3,path:s="/",sameSite:a="Lax",secure:u=!1}=n,d=`${encodeURIComponent(e)}=${encodeURIComponent(t)}; path=${s}; max-age=${o}; SameSite=${a}`;u&&(d+="; Secure"),document.cookie=d}function V(){let e=ee(q);if(!e)return null;try{let t=JSON.parse(e);if(t&&typeof t=="object"&&"deviceId"in t&&"selected_preferences"in t&&typeof t.deviceId=="string"&&Array.isArray(t.selected_preferences))return t}catch{}return null}function H(e,t,n){te(q,JSON.stringify({deviceId:e,selected_preferences:t}),{maxAge:31536e3,path:"/",sameSite:"Lax",...n})}var v=require("@tanstack/react-query");var A="",S=e=>({getHealth:async()=>{let{data:t}=await e.get("/health");return t},getManyConsents:async t=>{let{data:n}=await e.get(`${A}/consent`,{params:t?{type:t.type}:void 0});return n},getConsentById:async({id:t})=>{let{data:n}=await e.get(`${A}/consent/${t}`);return n},getLatestConsentByUserId:async({user_id:t})=>{let{data:n}=await e.get(`${A}/user-id`,{params:{user_id:t}});return n},createUserConsent:async t=>{let{data:n}=await e.post(`${A}/user-id`,t);return n},getLatestCookieConsentByDeviceId:async({device_id:t})=>{let{data:n}=await e.get(`${A}/cookies/device-id`,{params:{device_id:t}});return n},createDeviceCookieConsent:async t=>{let{data:n}=await e.post(`${A}/cookies/device-id`,t);return n}});function Ce(e){return Array.from(new Uint8Array(e)).map(t=>t.toString(16).padStart(2,"0")).join("").toLowerCase()}async function be(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",t);return Ce(n)}function ye(e){let t=xe(e),n=ve(),o=Pe(),s=new Uint32Array(64),a=t.length>>6;for(let d=0;d<a;d++){let l=d<<6;for(let m=0;m<16;m++){let c=l+(m<<2);s[m]=t[c]<<24|t[c+1]<<16|t[c+2]<<8|t[c+3]}for(let m=16;m<64;m++){let c=k(s[m-15],7)^k(s[m-15],18)^s[m-15]>>>3,g=k(s[m-2],17)^k(s[m-2],19)^s[m-2]>>>10;s[m]=s[m-16]+c+s[m-7]+g>>>0}let i=o[0],x=o[1],h=o[2],C=o[3],p=o[4],R=o[5],P=o[6],I=o[7];for(let m=0;m<64;m++){let c=k(p,6)^k(p,11)^k(p,25),g=p&R^~p&P,U=I+c+g+n[m]+s[m]>>>0,_=k(i,2)^k(i,13)^k(i,22),G=i&x^i&h^x&h,ae=_+G>>>0;I=P,P=R,R=p,p=C+U>>>0,C=h,h=x,x=i,i=U+ae>>>0}o[0]=o[0]+i>>>0,o[1]=o[1]+x>>>0,o[2]=o[2]+h>>>0,o[3]=o[3]+C>>>0,o[4]=o[4]+p>>>0,o[5]=o[5]+R>>>0,o[6]=o[6]+P>>>0,o[7]=o[7]+I>>>0}let u="";for(let d=0;d<8;d++){let l=o[d];u+=(l>>>28).toString(16)+(l>>>24&15).toString(16)+(l>>>20&15).toString(16)+(l>>>16&15).toString(16)+(l>>>12&15).toString(16)+(l>>>8&15).toString(16)+(l>>>4&15).toString(16)+(l&15).toString(16)}return u.toLowerCase()}function k(e,t){return e>>>t|e<<32-t}function xe(e){let t=e.length,n=[];for(let l=0;l<t;l++){let i=e.charCodeAt(l);i<128?n.push(i):i<2048?n.push(192|i>>6,128|i&63):i<55296||i>=57344?n.push(224|i>>12,128|i>>6&63,128|i&63):(i=65536+((i&1023)<<10|e.charCodeAt(++l)&1023),n.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63))}let o=n.length,s=(64-(o+9)%64)%64,a=o+9+s,u=new Uint8Array(a);u.set(n),u[o]=128;let d=new DataView(u.buffer,u.byteOffset,u.byteLength);return d.setUint32(a-8,0,!1),d.setUint32(a-4,o*8>>>0,!1),u}function ve(){let e=[];return"428a2f98 71374491 b5c0fbcf e9b5dba5 3956c25b 59f111f1 923f82a4 ab1c5ed5 d807aa98 12835b01 243185be 550c7dc3 72be5d74 80deb1fe 9bdc06a7 c19bf174 e49b69c1 efbe4786 0fc19dc6 240ca1cc 2de92c6f 4a7484aa 5cb0a9dc 76f988da 983e5152 a831c66d b00327c8 bf597fc7 c6e00bf3 d5a79147 06ca6351 14292967 27b70a85 2e1b2138 4d2c6dfc 53380d13 650a7354 766a0abb 81c2c92e 92722c85 a2bfe8a1 a81a664b c24b8b70 c76c51a3 d192e819 d6990624 f40e3585 106aa070 19a4c116 1e376c08 2748774c 34b0bcb5 391c0cb3 4ed8aa4a 5b9cca4f 682e6ff3 748f82ee 78a5636f 84c87814 8cc70208 90befffa a4506ceb bef9a3f7 c67178f2".split(" ").forEach(n=>e.push(parseInt(n,16))),e}function Pe(){return[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]}function ke(){return!(typeof crypto>"u"||!crypto.subtle)}async function D(e){return typeof e!="string"||e.length===0?e:ke()?be(e):Promise.resolve(ye(e))}var T=require("@tanstack/react-query"),ne=ge(require("axios")),B=require("react"),z=require("react/jsx-runtime"),oe=(0,B.createContext)(void 0),Re=({baseURL:e="",axiosConfig:t={},requestInterceptors:n={},responseInterceptors:o={}})=>{let s=ne.default.create({baseURL:e,...t});return s.interceptors.request.use(n.onFulfilled,n.onRejected),s.interceptors.response.use(o.onFulfilled,o.onRejected),{consentApi:s,updateHeaders:u=>{Object.entries(u).forEach(([d,l])=>{s.defaults.headers.common[d]=l})}}},se=({children:e,baseURL:t="",axiosConfig:n={},queryClient:o,queryClientConfig:s={},requestInterceptors:a={},responseInterceptors:u={}})=>{let d=(0,B.useMemo)(()=>o||new T.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,...s?.defaultOptions?.queries},mutations:{...s?.defaultOptions?.mutations}},queryCache:s?.queryCache,mutationCache:s?.mutationCache}),[o]),l=(0,B.useMemo)(()=>{let i=Re({baseURL:t,axiosConfig:n,requestInterceptors:a,responseInterceptors:u});return{consentApi:i.consentApi,updateHeaders:i.updateHeaders,queryClient:d}},[t,d,n,a,u]);return(0,z.jsx)(oe.Provider,{value:l,children:(0,z.jsx)(T.QueryClientProvider,{client:d,children:e})})},w=()=>{let e=(0,B.useContext)(oe);if(!e)throw new Error("useConsentService must be used within a ConsentServiceProvider");return e};var y={all:["consent"],health:()=>[...y.all,"health"],list:e=>[...y.all,"list",e],detail:e=>[...y.all,"detail",e],latestByUserId:e=>[...y.all,"user-id",e],latestCookieByDeviceId:e=>[...y.all,"cookies","device-id",e]},Se=e=>{let{consentApi:t}=w(),n=S(t);return(0,v.useQuery)({queryKey:y.health(),queryFn:()=>n.getHealth(),...e})},we=(e,t)=>{let{consentApi:n}=w(),o=S(n);return(0,v.useQuery)({queryKey:y.list(e),queryFn:()=>o.getManyConsents(e),...t})},Ie=(e,t)=>{let{consentApi:n}=w(),o=S(n);return(0,v.useQuery)({queryKey:y.detail(e.id),queryFn:()=>o.getConsentById(e),enabled:!!e.id,...t})},Q=(e,t)=>{let{consentApi:n}=w(),o=S(n);return(0,v.useQuery)({queryKey:y.latestByUserId(e.user_id),queryFn:async()=>{let s=await D(e.user_id);return o.getLatestConsentByUserId({user_id:s})},enabled:!!e.user_id,...t})},Ue=(e,t)=>{let{consentApi:n}=w(),o=S(n);return(0,v.useQuery)({queryKey:y.latestCookieByDeviceId(e.device_id),queryFn:async()=>{let s=await D(e.device_id);return o.getLatestCookieConsentByDeviceId({device_id:s})},enabled:!!e.device_id,...t})},M=e=>{let{consentApi:t}=w(),n=(0,v.useQueryClient)(),o=S(t);return(0,v.useMutation)({mutationFn:async s=>{let a={...s};return s.user_id!=null&&s.user_id!==""&&(a.user_id=await D(s.user_id)),s.device_id!=null&&s.device_id!==""&&(a.device_id=await D(s.device_id)),o.createUserConsent(a)},onSuccess:(s,a)=>{a.user_id&&n.invalidateQueries({queryKey:y.latestByUserId(a.user_id)}),n.invalidateQueries({queryKey:y.list()})},...e})},K=e=>{let{consentApi:t}=w(),n=(0,v.useQueryClient)(),o=S(t);return(0,v.useMutation)({mutationFn:async s=>{let a={...s,device_id:await D(s.device_id)};return o.createDeviceCookieConsent(a)},onSuccess:(s,a)=>{n.invalidateQueries({queryKey:y.latestCookieByDeviceId(a.device_id)}),n.invalidateQueries({queryKey:y.list()})},...e})};var r=require("react/jsx-runtime"),L=["essential","analytics","advertising"],W={essential:{label:"Essential",description:"Required for the site to work (e.g. security, preferences).",labelVi:"C\u1EA7n thi\u1EBFt",descriptionVi:"C\u1EA7n thi\u1EBFt cho ho\u1EA1t \u0111\u1ED9ng c\u1EE7a trang (b\u1EA3o m\u1EADt, t\xF9y ch\u1ECDn)."},analytics:{label:"Analytics",description:"Help us improve by collecting anonymous usage data.",labelVi:"Ph\xE2n t\xEDch",descriptionVi:"Gi\xFAp ch\xFAng t\xF4i c\u1EA3i thi\u1EC7n b\u1EB1ng c\xE1ch thu th\u1EADp d\u1EEF li\u1EC7u s\u1EED d\u1EE5ng \u1EA9n danh."},advertising:{label:"Advertising",description:"Used to show you relevant ads and measure campaigns.",labelVi:"Qu\u1EA3ng c\xE1o",descriptionVi:"D\xF9ng \u0111\u1EC3 hi\u1EC3n th\u1ECB qu\u1EA3ng c\xE1o ph\xF9 h\u1EE3p v\xE0 \u0111o l\u01B0\u1EDDng chi\u1EBFn d\u1ECBch."}};function F({onSubmitted:e,onDismiss:t,className:n=""}){let[o,s]=(0,O.useState)(!1),[a,u]=(0,O.useState)(!1),[d,l]=(0,O.useState)(null),[i,x]=(0,O.useState)({essential:!0,analytics:!0,advertising:!0}),{deviceId:h}=$(),C=K({onSuccess:(c,g)=>{H(h,g.selected_preferences??[]),e?.(),t?.(),s(!0),u(!1)}}),p=()=>L.filter(c=>i[c]),R=c=>{W[c].disabled||x(g=>({...g,[c]:!g[c]}))},P=()=>{C.mutate({device_id:h,status:"REJECTED",selected_preferences:[]})},I=()=>{C.mutate({device_id:h,status:"ACCEPTED",selected_preferences:[...L]})},m=()=>{let c=p();C.mutate({device_id:h,status:"ACCEPTED",selected_preferences:c.length>0?c:[]})};return o?null:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{role:"dialog","aria-label":"Th\xF4ng b\xE1o v\u1EC1 cookie",className:`consent:fixed consent:bottom-0 consent:left-0 consent:right-0 consent:z-50 consent:flex consent:flex-col consent:gap-4 consent:rounded-t-xl consent:border consent:border-b-0 consent:border-gray-200 consent:bg-white consent:p-4 consent:shadow-lg consent:md:left-4 consent:md:right-auto consent:md:bottom-4 consent:md:max-w-md consent:md:rounded-xl consent:md:border consent:md:border-gray-200 ${n}`,style:{position:"fixed",bottom:0,left:0,right:0,zIndex:50,display:"flex",flexDirection:"column",gap:"1rem",borderRadius:"0.75rem 0.75rem 0 0",borderWidth:"1px 1px 0 1px",borderColor:"#e5e7eb",backgroundColor:"#fff",padding:"1rem",boxShadow:"0 -4px 6px -1px rgb(0 0 0 / 0.1)"},children:[(0,r.jsx)("h2",{className:"consent:text-lg consent:font-semibold consent:text-gray-900",style:{fontSize:"1.125rem",fontWeight:600,color:"#111827"},children:"Th\xF4ng b\xE1o v\u1EC1 cookie"}),(0,r.jsxs)("div",{className:"consent:text-sm consent:text-gray-600",style:{fontSize:"0.875rem",color:"#4b5563",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[(0,r.jsx)("p",{children:"TapQuest s\u1EED d\u1EE5ng tr\xECnh theo d\xF5i (nh\u01B0 Cookie ho\u1EB7c SDK) cho:"}),(0,r.jsx)("ul",{style:{margin:0,paddingLeft:"1.25rem"},children:L.map(c=>(0,r.jsx)("li",{children:W[c].labelVi},c))}),(0,r.jsx)("p",{children:"Tr\u01B0\u1EDBc khi b\u1EA1n \u0111\u1ED3ng \xFD, ch\u1EC9 nh\u1EEFng tr\xECnh theo d\xF5i ho\xE0n to\xE0n c\u1EA7n thi\u1EBFt m\u1EDBi \u0111\u01B0\u1EE3c tri\u1EC3n khai."}),(0,r.jsx)("p",{children:"N\u1EBFu b\u1EA1n ch\u1ECDn Ch\u1EA5p nh\u1EADn t\u1EA5t c\u1EA3, b\u1EA1n \u0111\u1ED3ng \xFD s\u1EED d\u1EE5ng t\u1EA5t c\u1EA3 tr\xECnh theo d\xF5i c\u1EE7a ch\xFAng t\xF4i."}),(0,r.jsx)("p",{children:"N\u1EBFu b\u1EA1n ch\u1ECDn T\u1EEB ch\u1ED1i t\u1EA5t c\u1EA3, b\u1EA1n t\u1EEB ch\u1ED1i nh\u1EEFng tr\xECnh theo d\xF5i y\xEAu c\u1EA7u s\u1EF1 \u0111\u1ED3ng \xFD c\u1EE7a b\u1EA1n v\xE0 s\u1EBD kh\xF4ng c\xF3 quy\u1EC1n truy c\u1EADp v\xE0o c\xE1c \u0111\u1EC1 ngh\u1ECB ho\u1EB7c n\u1ED9i dung \u0111\u01B0\u1EE3c c\xE1 nh\xE2n h\xF3a."}),(0,r.jsx)("p",{children:"N\u1EBFu b\u1EA1n ch\u1ECDn T\xF9y ch\u1ECDn, b\u1EA1n c\xF3 th\u1EC3 ch\u1ECDn xem b\u1EA1n c\xF3 \u0111\u1ED3ng \xFD s\u1EED d\u1EE5ng tr\xECnh theo d\xF5i tr\xEAn \u1EE9ng d\u1EE5ng c\u1EE7a ch\xFAng t\xF4i hay kh\xF4ng v\xE0 \u1EDF m\u1EE9c \u0111\u1ED9 n\xE0o."}),(0,r.jsxs)("p",{children:["B\u1EA1n c\xF3 th\u1EC3 r\xFAt l\u1EA1i s\u1EF1 \u0111\u1ED3ng \xFD c\u1EE7a m\xECnh b\u1EA5t k\u1EF3 l\xFAc n\xE0o b\u1EB1ng c\xE1ch nh\u1EA5p v\xE0o li\xEAn k\u1EBFt trong"," ","Ch\xEDnh s\xE1ch cookie"," ","c\u1EE7a ch\xFAng t\xF4i."]})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-2 flex-wrap",children:[(0,r.jsx)("button",{type:"button",onClick:()=>u(!0),className:"consent:rounded-lg consent:border consent:border-gray-300 consent:bg-white consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-gray-700 consent:shadow-sm hover:consent:bg-gray-50 disabled:consent:opacity-50",style:{borderRadius:"0.5rem",border:"1px solid #111827",background:"#fff",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:"#111827",cursor:"pointer"},children:"T\xF9y ch\u1ECDn"}),(0,r.jsx)("button",{type:"button",onClick:P,disabled:C.isPending,className:"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50",style:{borderRadius:"0.5rem",background:"#111827",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:"#fff",border:"none",cursor:"pointer"},children:"T\u1EEB ch\u1ED1i t\u1EA5t c\u1EA3"}),(0,r.jsx)("button",{type:"button",onClick:I,disabled:C.isPending,className:"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50",style:{borderRadius:"0.5rem",background:"#111827",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:"#fff",border:"none",cursor:"pointer"},children:"Ch\u1EA5p nh\u1EADn t\u1EA5t c\u1EA3"})]}),C.isError&&(0,r.jsx)("p",{className:"consent:text-sm consent:text-red-600",style:{fontSize:"0.875rem",color:"#dc2626"},children:"\u0110\xE3 x\u1EA3y ra l\u1ED7i. Vui l\xF2ng th\u1EED l\u1EA1i."})]}),a&&(0,r.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Trung t\xE2m tu\u1EF3 ch\u1ECDn b\u1EA3o m\u1EADt",style:{position:"fixed",inset:0,zIndex:60,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)",padding:"1rem"},onClick:c=>c.target===c.currentTarget&&u(!1),children:(0,r.jsxs)("div",{className:"consent:bg-white consent:rounded-xl consent:border consent:border-gray-200 consent:shadow-lg consent:max-h-[90vh] consent:overflow-y-auto",style:{backgroundColor:"#fff",borderRadius:"0.75rem",border:"1px solid #e5e7eb",boxShadow:"0 10px 15px -3px rgb(0 0 0 / 0.1)",maxWidth:"28rem",width:"100%",maxHeight:"90vh",overflowY:"auto",padding:"1.25rem",position:"relative"},onClick:c=>c.stopPropagation(),children:[(0,r.jsx)("button",{type:"button",onClick:()=>u(!1),"aria-label":"\u0110\xF3ng",style:{position:"absolute",top:"1rem",right:"1rem",width:"2rem",height:"2rem",borderRadius:"0.25rem",border:"none",background:"transparent",cursor:"pointer",fontSize:"1.25rem",lineHeight:1,color:"#6b7280"},children:"\xD7"}),(0,r.jsx)("h2",{className:"consent:text-lg consent:font-semibold consent:text-gray-900",style:{fontSize:"1.125rem",fontWeight:600,color:"#111827",marginBottom:"0.75rem",paddingRight:"2rem"},children:"Trung t\xE2m tu\u1EF3 ch\u1ECDn b\u1EA3o m\u1EADt"}),(0,r.jsxs)("div",{className:"consent:text-sm consent:text-gray-600",style:{fontSize:"0.875rem",color:"#4b5563",marginBottom:"1rem"},children:[(0,r.jsx)("p",{style:{marginBottom:"0.5rem"},children:"Khi b\u1EA1n truy c\u1EADp b\u1EA5t k\u1EF3 trang web n\xE0o, trang web \u0111\xF3 c\xF3 th\u1EC3 l\u01B0u tr\u1EEF ho\u1EB7c truy xu\u1EA5t th\xF4ng tin tr\xEAn tr\xECnh duy\u1EC7t c\u1EE7a b\u1EA1n, ch\u1EE7 y\u1EBFu d\u01B0\u1EDBi d\u1EA1ng cookie. Th\xF4ng tin n\xE0y c\xF3 th\u1EC3 li\xEAn quan \u0111\u1EBFn b\u1EA1n, t\xF9y ch\u1ECDn c\u1EE7a b\u1EA1n ho\u1EB7c thi\u1EBFt b\u1ECB c\u1EE7a b\u1EA1n, v\xE0 ch\u1EE7 y\u1EBFu \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng \u0111\u1EC3 trang web ho\u1EA1t \u0111\u1ED9ng nh\u01B0 mong \u0111\u1EE3i."}),(0,r.jsx)("p",{style:{marginBottom:"0.5rem"},children:"Th\xF4ng tin n\xE0y th\u01B0\u1EDDng kh\xF4ng tr\u1EF1c ti\u1EBFp x\xE1c \u0111\u1ECBnh b\u1EA1n nh\u01B0ng c\xF3 th\u1EC3 mang l\u1EA1i tr\u1EA3i nghi\u1EC7m web \u0111\u01B0\u1EE3c c\xE1 nh\xE2n h\xF3a h\u01A1n. Ch\xFAng t\xF4i t\xF4n tr\u1ECDng quy\u1EC1n ri\xEAng t\u01B0 c\u1EE7a b\u1EA1n; b\u1EA1n c\xF3 th\u1EC3 ch\u1ECDn kh\xF4ng cho ph\xE9p m\u1ED9t s\u1ED1 lo\u1EA1i cookie. Nh\u1EA5p v\xE0o ti\xEAu \u0111\u1EC1 t\u1EEBng danh m\u1EE5c \u0111\u1EC3 t\xECm hi\u1EC3u th\xEAm v\xE0 thay \u0111\u1ED5i c\xE0i \u0111\u1EB7t m\u1EB7c \u0111\u1ECBnh. Vi\u1EC7c ch\u1EB7n m\u1ED9t s\u1ED1 cookie c\xF3 th\u1EC3 \u1EA3nh h\u01B0\u1EDFng \u0111\u1EBFn tr\u1EA3i nghi\u1EC7m c\u1EE7a b\u1EA1n v\u1EDBi trang web v\xE0 c\xE1c d\u1ECBch v\u1EE5 \u0111\u01B0\u1EE3c cung c\u1EA5p."}),(0,r.jsx)("p",{style:{marginBottom:"0.5rem"},children:'N\u1EBFu ch\u1ECDn "Kh\xF4ng theo d\xF5i" khi l\u1EA7n \u0111\u1EA7u s\u1EED d\u1EE5ng TapQuest, ch\u1EC9 cookie ho\xE0n to\xE0n c\u1EA7n thi\u1EBFt m\u1EDBi \u0111\u01B0\u1EE3c s\u1EED d\u1EE5ng.'}),(0,r.jsx)("span",{style:{color:"#2563eb",textDecoration:"underline"},children:"Th\xF4ng tin kh\xE1c"})]}),(0,r.jsx)("h3",{className:"consent:text-sm consent:font-semibold consent:text-gray-900",style:{fontSize:"0.875rem",fontWeight:600,color:"#111827",marginBottom:"0.75rem"},children:"Qu\u1EA3n l\xFD tu\u1EF3 ch\u1ECDn \u0111\u1ED3ng \xFD"}),(0,r.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",marginBottom:"1.25rem"},children:L.map(c=>{let g=W[c],U=i[c],_=d===c;return(0,r.jsxs)("div",{style:{border:"1px solid #e5e7eb",borderRadius:"0.5rem",overflow:"hidden"},children:[(0,r.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.75rem",cursor:"pointer",backgroundColor:_?"#f9fafb":"transparent"},onClick:()=>l(_?null:c),children:[(0,r.jsx)("span",{style:{flexShrink:0,width:"1.25rem",height:"1.25rem",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"1rem",color:"#6b7280",transform:_?"rotate(45deg)":"none",transition:"transform 0.2s"},children:"+"}),(0,r.jsx)("span",{className:"consent:font-medium consent:text-gray-900",style:{flex:1,fontSize:"0.875rem",fontWeight:500,color:"#111827"},children:g.labelVi}),(0,r.jsx)("button",{type:"button",role:"switch","aria-checked":U,"aria-label":`${g.labelVi} ${U?"b\u1EADt":"t\u1EAFt"}`,disabled:g.disabled,onClick:G=>{G.stopPropagation(),R(c)},style:{flexShrink:0,width:44,height:24,borderRadius:12,border:"none",padding:0,cursor:g.disabled?"default":"pointer",backgroundColor:g.disabled?"#e5e7eb":U?"#111827":"#d1d5db",opacity:g.disabled?.7:1,transition:"background-color 0.2s"},children:(0,r.jsx)("span",{style:{display:"block",width:20,height:20,borderRadius:"50%",backgroundColor:"#fff",marginLeft:U?22:2,marginTop:2,transition:"margin-left 0.2s",boxShadow:"0 1px 2px rgb(0 0 0 / 0.2)"}})})]}),_&&(0,r.jsx)("div",{className:"consent:text-sm consent:text-gray-600",style:{fontSize:"0.875rem",color:"#4b5563",padding:"0 0.75rem 0.75rem 2.5rem",borderTop:"1px solid #e5e7eb"},children:g.descriptionVi})]},c)})}),(0,r.jsx)("button",{type:"button",onClick:m,disabled:C.isPending,className:"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50 consent:w-full",style:{borderRadius:"0.5rem",background:"#111827",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:"#fff",border:"none",cursor:"pointer",width:"100%"},children:"X\xE1c nh\u1EADn l\u1EF1a ch\u1ECDn c\u1EE7a t\xF4i"})]})})]})}var j=require("react");var f=require("react/jsx-runtime"),De=`
3
+ Tanta petere igitur et tam longe abesse non opus est. Quodsi haberent magnalia inter potentiam et divitias, et tamen ista philosophia et disciplina vivendi. Quam ob rem ut illi superiores, nos usque ad hanc aetatem. Sed ut iis bonis erudiamur, quae gignuntur ex tempore. Et tamen rerum necessitatibus saepe vincimur. Quam ob rem ut illi superiores, nos usque ad hanc aetatem.
4
+ `.trim(),Be="V\xEC b\u1EA1n kh\xF4ng \u0111\u1ED3ng \xFD v\u1EDBi th\u1ECFa thu\u1EADn n\xE0y. Ch\xFAng t\xF4i s\u1EBD x\xF3a t\xE0i kho\u1EA3n trong v\xF2ng x ng\xE0y";function Y({open:e,onClose:t,userId:n,onAgreeSuccess:o}){let[s,a]=(0,j.useState)(!1),[u,d]=(0,j.useState)(!1),l=M({onSuccess:()=>{o?.(),i()}}),i=()=>{a(!1),d(!1),t()},x=()=>{d(!0)},h=()=>{d(!1),t()},C=()=>{s&&l.mutate({user_id:n,status:"ACCEPTED"})};return e?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)("div",{role:"dialog","aria-modal":"true","aria-label":"Ch\xEDnh s\xE1ch b\u1EA3o m\u1EADt",style:{position:"fixed",inset:0,zIndex:60,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)",padding:"1rem"},onClick:p=>p.target===p.currentTarget&&i(),children:(0,f.jsxs)("div",{className:"consent:bg-white consent:rounded-xl consent:border consent:border-gray-200 consent:shadow-lg consent:max-h-[90vh] consent:overflow-hidden consent:flex consent:flex-col",style:{backgroundColor:"#fff",borderRadius:"0.75rem",border:"1px solid #e5e7eb",boxShadow:"0 10px 15px -3px rgb(0 0 0 / 0.1)",maxWidth:"28rem",width:"100%",maxHeight:"90vh",overflow:"hidden",display:"flex",flexDirection:"column"},onClick:p=>p.stopPropagation(),children:[(0,f.jsx)("h2",{className:"consent:text-lg consent:font-semibold consent:text-gray-900",style:{fontSize:"1.125rem",fontWeight:600,color:"#2563eb",padding:"1rem 1.25rem",borderBottom:"1px solid #e5e7eb"},children:"Ch\xEDnh s\xE1ch b\u1EA3o m\u1EADt"}),(0,f.jsx)("div",{style:{flex:1,overflowY:"auto",padding:"1rem 1.25rem",fontSize:"0.875rem",color:"#111827",lineHeight:1.6},children:(0,f.jsx)("p",{style:{margin:0,whiteSpace:"pre-wrap"},children:De})}),(0,f.jsxs)("div",{style:{padding:"1rem 1.25rem",borderTop:"1px solid #e5e7eb",display:"flex",flexDirection:"column",gap:"1rem"},children:[(0,f.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.875rem",color:"#111827",cursor:"pointer"},children:[(0,f.jsx)("input",{type:"checkbox",checked:s,onChange:p=>a(p.target.checked),style:{width:"1rem",height:"1rem",accentColor:"#111827"},"aria-label":"T\xF4i \u0111\u1ED3ng \xFD v\u1EDBi ch\xEDnh s\xE1ch b\u1EA3o m\u1EADt tr\xEAn"}),(0,f.jsx)("span",{children:"T\xF4i \u0111\u1ED3ng \xFD v\u1EDBi ch\xEDnh s\xE1ch b\u1EA3o m\u1EADt tr\xEAn"})]}),(0,f.jsxs)("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap"},children:[(0,f.jsx)("button",{type:"button",onClick:x,disabled:l.isPending,className:"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50",style:{flex:1,minWidth:0,borderRadius:"0.5rem",background:"#111827",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:"#fff",border:"none",cursor:"pointer"},children:"B\u1ECF qua"}),(0,f.jsx)("button",{type:"button",onClick:C,disabled:!s||l.isPending,className:"consent:rounded-lg consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:shadow-sm disabled:consent:opacity-50 disabled:consent:cursor-not-allowed",style:{flex:1,minWidth:0,borderRadius:"0.5rem",background:s?"#111827":"#e5e7eb",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:s?"#fff":"#9ca3af",border:"none",cursor:s?"pointer":"not-allowed"},children:"Ti\u1EBFp t\u1EE5c"})]}),l.isError&&(0,f.jsx)("p",{className:"consent:text-sm consent:text-red-600",style:{fontSize:"0.875rem",color:"#dc2626",margin:0},children:"\u0110\xE3 x\u1EA3y ra l\u1ED7i. Vui l\xF2ng th\u1EED l\u1EA1i."})]})]})}),u&&(0,f.jsx)("div",{role:"alertdialog","aria-modal":"true","aria-label":"Th\xF4ng b\xE1o t\u1EEB ch\u1ED1i",style:{position:"fixed",inset:0,zIndex:70,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.5)",padding:"1rem"},onClick:p=>p.target===p.currentTarget&&h(),children:(0,f.jsxs)("div",{className:"consent:bg-white consent:rounded-xl consent:border consent:border-gray-200 consent:shadow-lg",style:{backgroundColor:"#fff",borderRadius:"0.75rem",border:"1px solid #e5e7eb",boxShadow:"0 10px 15px -3px rgb(0 0 0 / 0.1)",maxWidth:"22rem",width:"100%",padding:"1.25rem"},onClick:p=>p.stopPropagation(),children:[(0,f.jsx)("p",{className:"consent:text-sm consent:text-gray-700",style:{fontSize:"0.875rem",color:"#374151",margin:"0 0 1rem 0",lineHeight:1.5},children:Be}),(0,f.jsx)("button",{type:"button",onClick:h,className:"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:w-full",style:{borderRadius:"0.5rem",background:"#111827",padding:"0.5rem 1rem",fontSize:"0.875rem",fontWeight:500,color:"#fff",border:"none",cursor:"pointer",width:"100%"},children:"T\xF4i \u0111\xE3 hi\u1EC3u"})]})})]}):null}var E=require("react/jsx-runtime"),ce=(0,b.createContext)(void 0);function _e(e){let{children:t,deviceId:n,showBannerWhenNoPreference:o=!0,...s}=e,[a,u]=(0,b.useState)(!1),[d,l]=(0,b.useState)(null),[i,x]=(0,b.useState)(!1),[h,C]=(0,b.useState)(null),{data:p,isFetched:R}=Q({user_id:d??""});(0,b.useEffect)(()=>{if(!(!d||!R)){if(p!=null){l(null);return}C(d),x(!0),l(null)}},[d,R,p]);let P=(0,b.useCallback)(()=>{let g=V();u(!!g)},[]),I=(0,b.useCallback)(g=>{g&&l(g)},[]),m=(0,b.useCallback)(()=>{x(!1),C(null)},[]);(0,b.useEffect)(()=>{P()},[P]);let c={deviceId:n,hasConsentPreference:a,refreshConsentPreference:P,openPolicyPopup:I};return(0,E.jsx)(se,{...s,children:(0,E.jsxs)(ce.Provider,{value:c,children:[t,o&&!a&&(0,E.jsx)(F,{onSubmitted:P}),i&&h&&(0,E.jsx)(Y,{open:i,onClose:m,userId:h})]})})}function $(){let e=(0,b.useContext)(ce);if(!e)throw new Error("usePhygitalConsent must be used within a PhygitalConsentProvider");return e}0&&(module.exports={COOKIE_CONSENT_NAME,CookieConsentBanner,EntityStatus,MediaType,PhygitalConsentProvider,PolicyPopup,consentQueryKeys,consentService,getConsentPreferenceCookie,getCookie,setConsentPreferenceCookie,setCookie,sha256,useConsentById,useCreateDeviceCookieConsent,useCreateUserConsent,useHealth,useLatestConsentByUserId,useLatestCookieConsentByDeviceId,useManyConsents,usePhygitalConsent});
3
5
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../src/types/common.ts","../src/provider/PhygitalConsentProvider.tsx","../src/helpers/cookie.ts","../src/provider/ConsentServiceProvider.tsx","../src/api/consent.ts","../src/hooks/useConsent.ts","../src/helpers/sha256.ts","../src/components/CookieConsentBanner.tsx"],"sourcesContent":["export * from \"./src\";\n","export enum MediaType {\n IMAGE = \"image\",\n VIDEO = \"video\",\n}\n\nexport type DateTimeNumber = number;\n\nexport interface Media {\n url: string;\n type: MediaType | string;\n thumbnail_url?: string;\n}\n\nexport enum EntityStatus {\n ACTIVE = \"Active\",\n INACTIVE = \"Inactive\",\n}\n\nexport interface CommonModel {\n id: string;\n status: EntityStatus;\n created_at: DateTimeNumber;\n updated_at: DateTimeNumber;\n created_by?: string;\n updated_by?: string;\n}\n","\"use client\";\n\nimport React, { createContext, useCallback, useContext, useEffect, useState } from \"react\";\nimport { getConsentPreferenceCookie } from \"../helpers/cookie\";\nimport { ConsentServiceProvider, ConsentServiceProviderProps } from \"./ConsentServiceProvider\";\n\nexport interface PhygitalConsentContextValue {\n deviceId: string;\n /** True when cookie phygital_cookie_consent exists and has valid deviceId + selected_preferences. Use to show/hide cookie banner. */\n hasConsentPreference: boolean;\n /** Re-read cookie and update hasConsentPreference. Call after storing preference (e.g. from CookieConsentBanner onSuccess). */\n refreshConsentPreference: () => void;\n}\n\nconst PhygitalConsentContext = createContext<PhygitalConsentContextValue | undefined>(undefined);\n\nexport interface PhygitalConsentProviderProps extends ConsentServiceProviderProps {\n deviceId: string;\n children: React.ReactNode;\n}\n\n/**\n * Main provider for consumer apps. Wraps ConsentServiceProvider and exposes\n * hasConsentPreference + refreshConsentPreference so the app can show/hide\n * the cookie banner based on whether the user has already chosen a preference.\n */\nexport function PhygitalConsentProvider(props: PhygitalConsentProviderProps) {\n const { children, deviceId, ...consentServiceProps } = props;\n const [hasConsentPreference, setHasConsentPreference] = useState(false);\n\n const refreshConsentPreference = useCallback(() => {\n const stored = getConsentPreferenceCookie();\n setHasConsentPreference(!!stored);\n }, []);\n\n useEffect(() => {\n refreshConsentPreference();\n }, [refreshConsentPreference]);\n\n const value: PhygitalConsentContextValue = {\n deviceId,\n hasConsentPreference,\n refreshConsentPreference,\n };\n\n return (\n <ConsentServiceProvider {...consentServiceProps}>\n <PhygitalConsentContext.Provider value={value}>\n {children}\n </PhygitalConsentContext.Provider>\n </ConsentServiceProvider>\n );\n}\n\nexport function usePhygitalConsent() {\n const context = useContext(PhygitalConsentContext);\n if (!context) {\n throw new Error(\"usePhygitalConsent must be used within a PhygitalConsentProvider\");\n }\n return context;\n}\n","/**\n * Browser cookie helpers for phygital-consent.\n * Cookie name for consent preference: phygital_cookie_consent.\n * Stored value: { deviceId: string, selected_preferences: string[] } (JSON).\n * Default: 1 year, path /, SameSite Lax.\n */\n\nexport const COOKIE_CONSENT_NAME = \"phygital_cookie_consent\";\n\nconst ONE_YEAR_SECONDS = 365 * 24 * 60 * 60;\n\nexport interface SetCookieOptions {\n maxAge?: number;\n path?: string;\n sameSite?: \"Strict\" | \"Lax\" | \"None\";\n secure?: boolean;\n}\n\n/**\n * Get a cookie value by name.\n */\nexport function getCookie(name: string): string | null {\n if (typeof document === \"undefined\") return null;\n const match = document.cookie.match(new RegExp(\"(?:^|; )\" + encodeURIComponent(name) + \"=([^;]*)\"));\n return match ? decodeURIComponent(match[1]) : null;\n}\n\n/**\n * Set a cookie.\n */\nexport function setCookie(\n name: string,\n value: string,\n options: SetCookieOptions = {}\n): void {\n if (typeof document === \"undefined\") return;\n const {\n maxAge = ONE_YEAR_SECONDS,\n path = \"/\",\n sameSite = \"Lax\",\n secure = false,\n } = options;\n let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; path=${path}; max-age=${maxAge}; SameSite=${sameSite}`;\n if (secure) cookie += \"; Secure\";\n document.cookie = cookie;\n}\n\nexport interface ConsentPreferenceValue {\n deviceId: string;\n selected_preferences: string[];\n}\n\n/**\n * Read consent preference from cookie. Returns null if missing or invalid.\n */\nexport function getConsentPreferenceCookie(): ConsentPreferenceValue | null {\n const raw = getCookie(COOKIE_CONSENT_NAME);\n if (!raw) return null;\n try {\n const parsed = JSON.parse(raw) as unknown;\n if (\n parsed &&\n typeof parsed === \"object\" &&\n \"deviceId\" in parsed &&\n \"selected_preferences\" in parsed &&\n typeof (parsed as ConsentPreferenceValue).deviceId === \"string\" &&\n Array.isArray((parsed as ConsentPreferenceValue).selected_preferences)\n ) {\n return parsed as ConsentPreferenceValue;\n }\n } catch {\n // ignore\n }\n return null;\n}\n\n/**\n * Store consent preference in cookie (hashed device id + selected_preferences).\n * Uses 1 year max-age and SameSite Lax.\n */\nexport function setConsentPreferenceCookie(\n deviceId: string,\n selected_preferences: string[],\n options?: Partial<SetCookieOptions>\n): void {\n const value: ConsentPreferenceValue = { deviceId, selected_preferences };\n setCookie(COOKIE_CONSENT_NAME, JSON.stringify(value), {\n maxAge: ONE_YEAR_SECONDS,\n path: \"/\",\n sameSite: \"Lax\",\n ...options,\n });\n}\n","\"use client\";\n\nimport { QueryClient, QueryClientConfig, QueryClientProvider } from \"@tanstack/react-query\";\nimport axios, {\n AxiosInstance,\n AxiosRequestConfig,\n AxiosResponse,\n InternalAxiosRequestConfig,\n} from \"axios\";\nimport React, { createContext, useContext, useMemo } from \"react\";\n\nexport interface ConsentService {\n consentApi: AxiosInstance;\n queryClient: QueryClient;\n updateHeaders: (headers: Record<string, string>) => void;\n}\n\nconst ConsentServiceContext = createContext<ConsentService | undefined>(undefined);\n\ninterface RequestInterceptor {\n onFulfilled?: (\n config: InternalAxiosRequestConfig\n ) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>;\n onRejected?: (error: unknown) => unknown;\n}\n\ninterface ResponseInterceptor {\n onFulfilled?: (\n response: AxiosResponse\n ) => AxiosResponse | Promise<AxiosResponse>;\n onRejected?: (error: unknown) => unknown;\n}\n\nexport interface ConsentServiceProviderProps {\n children: React.ReactNode;\n baseURL?: string;\n axiosConfig?: AxiosRequestConfig;\n queryClient?: QueryClient;\n queryClientConfig?: Partial<QueryClientConfig>;\n requestInterceptors?: RequestInterceptor;\n responseInterceptors?: ResponseInterceptor;\n}\n\ninterface CreateConsentServiceParams {\n baseURL?: string;\n axiosConfig?: AxiosRequestConfig;\n requestInterceptors?: RequestInterceptor;\n responseInterceptors?: ResponseInterceptor;\n}\n\nexport const createConsentService = ({\n baseURL = \"\",\n axiosConfig = {},\n requestInterceptors = {},\n responseInterceptors = {},\n}: CreateConsentServiceParams) => {\n const instance = axios.create({\n baseURL,\n ...axiosConfig,\n });\n\n instance.interceptors.request.use(\n requestInterceptors.onFulfilled,\n requestInterceptors.onRejected\n );\n\n instance.interceptors.response.use(\n responseInterceptors.onFulfilled,\n responseInterceptors.onRejected\n );\n\n const updateHeaders = (headers: Record<string, string>) => {\n Object.entries(headers).forEach(([key, value]) => {\n instance.defaults.headers.common[key] = value;\n });\n };\n\n return {\n consentApi: instance,\n updateHeaders,\n };\n};\n\nexport const ConsentServiceProvider: React.FC<ConsentServiceProviderProps> = ({\n children,\n baseURL = \"\",\n axiosConfig = {},\n queryClient,\n queryClientConfig = {},\n requestInterceptors = {},\n responseInterceptors = {},\n}) => {\n const queryClientInstance = useMemo(\n () =>\n queryClient ||\n new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n ...queryClientConfig?.defaultOptions?.queries,\n },\n mutations: {\n ...queryClientConfig?.defaultOptions?.mutations,\n },\n },\n queryCache: queryClientConfig?.queryCache,\n mutationCache: queryClientConfig?.mutationCache,\n }),\n [queryClient]\n );\n\n const consentService = useMemo(() => {\n const service = createConsentService({\n baseURL,\n axiosConfig,\n requestInterceptors,\n responseInterceptors,\n });\n\n return {\n consentApi: service.consentApi,\n updateHeaders: service.updateHeaders,\n queryClient: queryClientInstance,\n };\n }, [baseURL, queryClientInstance, axiosConfig, requestInterceptors, responseInterceptors]);\n\n return (\n <ConsentServiceContext.Provider value={consentService}>\n <QueryClientProvider client={queryClientInstance}>\n {children}\n </QueryClientProvider>\n </ConsentServiceContext.Provider>\n );\n};\n\nexport const useConsentService = () => {\n const context = useContext(ConsentServiceContext);\n if (!context) {\n throw new Error(\"useConsentService must be used within a ConsentServiceProvider\");\n }\n return context;\n};\n","import { AxiosInstance } from \"axios\";\nimport type {\n GetManyConsentParams,\n GetManyConsentResponse,\n GetConsentByIdParams,\n GetConsentByIdResponse,\n GetLatestConsentByUserIdParams,\n GetLatestConsentByUserIdResponse,\n GetLatestCookieConsentByDeviceIdParams,\n GetLatestCookieConsentByDeviceIdResponse,\n CreateUserConsentUpsertDTO,\n CreateUserConsentResponse,\n CreateDeviceCookieConsentUpsertDTO,\n CreateDeviceCookieConsentResponse,\n HealthResponse,\n} from \"../types\";\n\nconst baseUrl = \"\";\n\nexport const consentService = (axiosInstance: AxiosInstance) => {\n return {\n /**\n * Health check – GET /health\n */\n getHealth: async (): Promise<HealthResponse> => {\n const { data } = await axiosInstance.get<HealthResponse>(\"/health\");\n return data;\n },\n\n /**\n * Get all consent logs – GET /consent/v1/consent\n * @param params - Optional filter by policy type (ACCOUNT_REGISTER | COOKIE_PREFERENCE)\n */\n getManyConsents: async (\n params?: GetManyConsentParams\n ): Promise<GetManyConsentResponse> => {\n const { data } = await axiosInstance.get<GetManyConsentResponse>(\n `${baseUrl}/consent`,\n { params: params ? { type: params.type } : undefined }\n );\n return data;\n },\n\n /**\n * Get consent log by ID – GET /consent/v1/consent/{id}\n */\n getConsentById: async ({\n id,\n }: GetConsentByIdParams): Promise<GetConsentByIdResponse> => {\n const { data } = await axiosInstance.get<GetConsentByIdResponse>(\n `${baseUrl}/consent/${id}`\n );\n return data;\n },\n\n /**\n * Get latest consent for a user – GET /consent/v1/user-id?user_id=\n */\n getLatestConsentByUserId: async ({\n user_id,\n }: GetLatestConsentByUserIdParams): Promise<GetLatestConsentByUserIdResponse> => {\n const { data } = await axiosInstance.get<GetLatestConsentByUserIdResponse>(\n `${baseUrl}/user-id`,\n { params: { user_id } }\n );\n return data;\n },\n\n /**\n * Create user consent (account register) – POST /consent/v1/user-id\n * Consumer app must hash user_id/device_id (e.g. SHA-256) before passing.\n */\n createUserConsent: async (\n body: CreateUserConsentUpsertDTO\n ): Promise<CreateUserConsentResponse> => {\n const { data } = await axiosInstance.post<CreateUserConsentResponse>(\n `${baseUrl}/user-id`,\n body\n );\n return data;\n },\n\n /**\n * Get latest cookie consent for a device – GET /consent/v1/cookies/device-id?device_id=\n */\n getLatestCookieConsentByDeviceId: async ({\n device_id,\n }: GetLatestCookieConsentByDeviceIdParams): Promise<GetLatestCookieConsentByDeviceIdResponse> => {\n const { data } =\n await axiosInstance.get<GetLatestCookieConsentByDeviceIdResponse>(\n `${baseUrl}/cookies/device-id`,\n { params: { device_id } }\n );\n return data;\n },\n\n /**\n * Create device cookie consent – POST /consent/v1/cookies/device-id\n * Consumer app must hash device_id (e.g. SHA-256) before passing.\n */\n createDeviceCookieConsent: async (\n body: CreateDeviceCookieConsentUpsertDTO\n ): Promise<CreateDeviceCookieConsentResponse> => {\n const { data } =\n await axiosInstance.post<CreateDeviceCookieConsentResponse>(\n `${baseUrl}/cookies/device-id`,\n body\n );\n return data;\n },\n };\n};\n","import {\n useQuery,\n useMutation,\n useQueryClient,\n UseQueryOptions,\n UseMutationOptions,\n} from \"@tanstack/react-query\";\nimport { consentService } from \"../api/consent\";\nimport { sha256 } from \"../helpers/sha256\";\nimport { useConsentService } from \"../provider/ConsentServiceProvider\";\nimport type {\n GetManyConsentParams,\n GetManyConsentResponse,\n GetConsentByIdParams,\n GetConsentByIdResponse,\n GetLatestConsentByUserIdParams,\n GetLatestConsentByUserIdResponse,\n GetLatestCookieConsentByDeviceIdParams,\n GetLatestCookieConsentByDeviceIdResponse,\n CreateUserConsentUpsertDTO,\n CreateUserConsentResponse,\n CreateDeviceCookieConsentUpsertDTO,\n CreateDeviceCookieConsentResponse,\n HealthResponse,\n} from \"../types\";\n\n/** Query keys for consent API */\nexport const consentQueryKeys = {\n all: [\"consent\"] as const,\n health: () => [...consentQueryKeys.all, \"health\"] as const,\n list: (params?: GetManyConsentParams) =>\n [...consentQueryKeys.all, \"list\", params] as const,\n detail: (id: string) => [...consentQueryKeys.all, \"detail\", id] as const,\n latestByUserId: (user_id: string) =>\n [...consentQueryKeys.all, \"user-id\", user_id] as const,\n latestCookieByDeviceId: (device_id: string) =>\n [...consentQueryKeys.all, \"cookies\", \"device-id\", device_id] as const,\n};\n\n// --- Queries ---\n\n/** Health check – GET /health */\nexport const useHealth = (\n options?: UseQueryOptions<HealthResponse>\n) => {\n const { consentApi } = useConsentService();\n const service = consentService(consentApi);\n\n return useQuery<HealthResponse>({\n queryKey: consentQueryKeys.health(),\n queryFn: () => service.getHealth(),\n ...options,\n });\n};\n\n/** Get all consent logs – GET /consent/v1/consent */\nexport const useManyConsents = (\n params?: GetManyConsentParams,\n options?: UseQueryOptions<GetManyConsentResponse>\n) => {\n const { consentApi } = useConsentService();\n const service = consentService(consentApi);\n\n return useQuery<GetManyConsentResponse>({\n queryKey: consentQueryKeys.list(params),\n queryFn: () => service.getManyConsents(params),\n ...options,\n });\n};\n\n/** Get consent log by ID – GET /consent/v1/consent/{id} */\nexport const useConsentById = (\n params: GetConsentByIdParams,\n options?: UseQueryOptions<GetConsentByIdResponse>\n) => {\n const { consentApi } = useConsentService();\n const service = consentService(consentApi);\n\n return useQuery<GetConsentByIdResponse>({\n queryKey: consentQueryKeys.detail(params.id),\n queryFn: () => service.getConsentById(params),\n enabled: !!params.id,\n ...options,\n });\n};\n\n/** Get latest consent for a user – GET /consent/v1/user-id (user_id hashed before send) */\nexport const useLatestConsentByUserId = (\n params: GetLatestConsentByUserIdParams,\n options?: UseQueryOptions<GetLatestConsentByUserIdResponse>\n) => {\n const { consentApi } = useConsentService();\n const service = consentService(consentApi);\n\n return useQuery<GetLatestConsentByUserIdResponse>({\n queryKey: consentQueryKeys.latestByUserId(params.user_id),\n queryFn: async () => {\n const user_id = await sha256(params.user_id);\n return service.getLatestConsentByUserId({ user_id });\n },\n enabled: !!params.user_id,\n ...options,\n });\n};\n\n/** Get latest cookie consent for a device – GET /consent/v1/cookies/device-id (device_id hashed before send) */\nexport const useLatestCookieConsentByDeviceId = (\n params: GetLatestCookieConsentByDeviceIdParams,\n options?: UseQueryOptions<GetLatestCookieConsentByDeviceIdResponse>\n) => {\n const { consentApi } = useConsentService();\n const service = consentService(consentApi);\n\n return useQuery<GetLatestCookieConsentByDeviceIdResponse>({\n queryKey: consentQueryKeys.latestCookieByDeviceId(params.device_id),\n queryFn: async () => {\n const device_id = await sha256(params.device_id);\n return service.getLatestCookieConsentByDeviceId({ device_id });\n },\n enabled: !!params.device_id,\n ...options,\n });\n};\n\n// --- Mutations ---\n\n/** Create user consent (account register) – POST /consent/v1/user-id */\nexport const useCreateUserConsent = (\n options?: UseMutationOptions<\n CreateUserConsentResponse,\n Error,\n CreateUserConsentUpsertDTO\n >\n) => {\n const { consentApi } = useConsentService();\n const queryClient = useQueryClient();\n const service = consentService(consentApi);\n\n return useMutation<CreateUserConsentResponse, Error, CreateUserConsentUpsertDTO>({\n mutationFn: async (body: CreateUserConsentUpsertDTO) => {\n const payload = { ...body };\n if (body.user_id != null && body.user_id !== \"\") {\n payload.user_id = await sha256(body.user_id);\n }\n if (body.device_id != null && body.device_id !== \"\") {\n payload.device_id = await sha256(body.device_id);\n }\n return service.createUserConsent(payload);\n },\n onSuccess: (\n _data: CreateUserConsentResponse,\n variables: CreateUserConsentUpsertDTO\n ) => {\n if (variables.user_id) {\n queryClient.invalidateQueries({\n queryKey: consentQueryKeys.latestByUserId(variables.user_id),\n });\n }\n queryClient.invalidateQueries({ queryKey: consentQueryKeys.list() });\n },\n ...options,\n });\n};\n\n/** Create device cookie consent – POST /consent/v1/cookies/device-id */\nexport const useCreateDeviceCookieConsent = (\n options?: UseMutationOptions<\n CreateDeviceCookieConsentResponse,\n Error,\n CreateDeviceCookieConsentUpsertDTO\n >\n) => {\n const { consentApi } = useConsentService();\n const queryClient = useQueryClient();\n const service = consentService(consentApi);\n\n return useMutation<\n CreateDeviceCookieConsentResponse,\n Error,\n CreateDeviceCookieConsentUpsertDTO\n >({\n mutationFn: async (body: CreateDeviceCookieConsentUpsertDTO) => {\n const payload = {\n ...body,\n device_id: await sha256(body.device_id),\n };\n return service.createDeviceCookieConsent(payload);\n },\n onSuccess: (\n _data: CreateDeviceCookieConsentResponse,\n variables: CreateDeviceCookieConsentUpsertDTO\n ) => {\n queryClient.invalidateQueries({\n queryKey: consentQueryKeys.latestCookieByDeviceId(variables.device_id),\n });\n queryClient.invalidateQueries({ queryKey: consentQueryKeys.list() });\n },\n ...options,\n });\n};\n","/**\n * Hash user_id or device_id with SHA-256 for the two POST consent hooks\n * (createUserConsent, createDeviceCookieConsent).\n * Input: string, encoded as UTF-8 before hashing.\n * Output: lowercase hex string.\n * Uses Web Crypto when available; falls back to pure-JS SHA-256 for old devices.\n */\n\n/** Encode hash digest bytes as lowercase hex string. */\nfunction arrayBufferToHex(buffer: ArrayBuffer): string {\n return Array.from(new Uint8Array(buffer))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\")\n .toLowerCase();\n}\n\n/**\n * SHA-256 via Web Crypto (modern browsers, Node 19+).\n * Input encoded as UTF-8; output lowercase hex.\n */\nasync function sha256WebCrypto(value: string): Promise<string> {\n const utf8 = new TextEncoder().encode(value);\n const hashBuffer = await crypto.subtle.digest(\"SHA-256\", utf8);\n return arrayBufferToHex(hashBuffer);\n}\n\n/**\n * Pure-JS SHA-256 fallback for environments without crypto.subtle\n * (e.g. old browsers, insecure context, Node < 19).\n * Input encoded as UTF-8; output lowercase hex.\n */\nfunction sha256Fallback(value: string): string {\n const bytes = utf8Encode(value);\n const K = getK();\n const H = getH();\n const W = new Uint32Array(64);\n const numBlocks = bytes.length >> 6;\n\n for (let block = 0; block < numBlocks; block++) {\n const start = block << 6;\n for (let i = 0; i < 16; i++) {\n const o = start + (i << 2);\n W[i] =\n (bytes[o]! << 24) |\n (bytes[o + 1]! << 16) |\n (bytes[o + 2]! << 8) |\n bytes[o + 3]!;\n }\n for (let i = 16; i < 64; i++) {\n const s0 = rotr(W[i - 15]!, 7) ^ rotr(W[i - 15]!, 18) ^ (W[i - 15]! >>> 3);\n const s1 = rotr(W[i - 2]!, 17) ^ rotr(W[i - 2]!, 19) ^ (W[i - 2]! >>> 10);\n W[i] = (W[i - 16]! + s0 + W[i - 7]! + s1) >>> 0;\n }\n let a = H[0]!,\n b = H[1]!,\n c = H[2]!,\n d = H[3]!,\n e = H[4]!,\n f = H[5]!,\n g = H[6]!,\n h = H[7]!;\n for (let i = 0; i < 64; i++) {\n const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);\n const ch = (e & f) ^ (~e & g);\n const t1 = (h + S1 + ch + K[i]! + W[i]!) >>> 0;\n const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);\n const maj = (a & b) ^ (a & c) ^ (b & c);\n const t2 = (S0 + maj) >>> 0;\n h = g;\n g = f;\n f = e;\n e = (d + t1) >>> 0;\n d = c;\n c = b;\n b = a;\n a = (t1 + t2) >>> 0;\n }\n H[0] = (H[0]! + a) >>> 0;\n H[1] = (H[1]! + b) >>> 0;\n H[2] = (H[2]! + c) >>> 0;\n H[3] = (H[3]! + d) >>> 0;\n H[4] = (H[4]! + e) >>> 0;\n H[5] = (H[5]! + f) >>> 0;\n H[6] = (H[6]! + g) >>> 0;\n H[7] = (H[7]! + h) >>> 0;\n }\n\n let out = \"\";\n for (let i = 0; i < 8; i++) {\n const v = H[i]!;\n out +=\n (v >>> 28).toString(16) +\n ((v >>> 24) & 0xf).toString(16) +\n ((v >>> 20) & 0xf).toString(16) +\n ((v >>> 16) & 0xf).toString(16) +\n ((v >>> 12) & 0xf).toString(16) +\n ((v >>> 8) & 0xf).toString(16) +\n ((v >>> 4) & 0xf).toString(16) +\n (v & 0xf).toString(16);\n }\n return out.toLowerCase();\n}\n\nfunction rotr(n: number, b: number): number {\n return (n >>> b) | (n << (32 - b));\n}\n\n/** Encode string to UTF-8 bytes (with SHA-256 padding for block processing). */\nfunction utf8Encode(s: string): Uint8Array {\n const n = s.length;\n const bytes: number[] = [];\n for (let i = 0; i < n; i++) {\n let c = s.charCodeAt(i);\n if (c < 0x80) {\n bytes.push(c);\n } else if (c < 0x800) {\n bytes.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));\n } else if (c < 0xd800 || c >= 0xe000) {\n bytes.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));\n } else {\n c = 0x10000 + (((c & 0x3ff) << 10) | (s.charCodeAt(++i) & 0x3ff));\n bytes.push(\n 0xf0 | (c >> 18),\n 0x80 | ((c >> 12) & 0x3f),\n 0x80 | ((c >> 6) & 0x3f),\n 0x80 | (c & 0x3f)\n );\n }\n }\n const len = bytes.length;\n const pad = (64 - ((len + 9) % 64)) % 64;\n const total = len + 9 + pad;\n const out = new Uint8Array(total);\n out.set(bytes);\n out[len] = 0x80;\n const view = new DataView(out.buffer, out.byteOffset, out.byteLength);\n view.setUint32(total - 8, 0, false);\n view.setUint32(total - 4, (len * 8) >>> 0, false);\n return out;\n}\n\nfunction getK(): number[] {\n const k: number[] = [];\n const hex =\n \"428a2f98 71374491 b5c0fbcf e9b5dba5 3956c25b 59f111f1 923f82a4 ab1c5ed5 d807aa98 12835b01 243185be 550c7dc3 72be5d74 80deb1fe 9bdc06a7 c19bf174 e49b69c1 efbe4786 0fc19dc6 240ca1cc 2de92c6f 4a7484aa 5cb0a9dc 76f988da 983e5152 a831c66d b00327c8 bf597fc7 c6e00bf3 d5a79147 06ca6351 14292967 27b70a85 2e1b2138 4d2c6dfc 53380d13 650a7354 766a0abb 81c2c92e 92722c85 a2bfe8a1 a81a664b c24b8b70 c76c51a3 d192e819 d6990624 f40e3585 106aa070 19a4c116 1e376c08 2748774c 34b0bcb5 391c0cb3 4ed8aa4a 5b9cca4f 682e6ff3 748f82ee 78a5636f 84c87814 8cc70208 90befffa a4506ceb bef9a3f7 c67178f2\";\n hex.split(\" \").forEach((h) => k.push(parseInt(h, 16)));\n return k;\n}\n\nfunction getH(): number[] {\n return [\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c,\n 0x1f83d9ab, 0x5be0cd19,\n ];\n}\n\nfunction hasWebCrypto(): boolean {\n if (typeof crypto === \"undefined\" || !crypto.subtle) return false;\n return true;\n}\n\n/**\n * Hash a string with SHA-256.\n * Input: encoded as UTF-8. Output: lowercase hex string.\n * Use for user_id and device_id before calling createUserConsent / createDeviceCookieConsent.\n * Uses Web Crypto when available; falls back to pure-JS for old devices (no crypto.subtle).\n */\nexport async function sha256(value: string): Promise<string> {\n if (typeof value !== \"string\" || value.length === 0) {\n return value;\n }\n if (hasWebCrypto()) {\n return sha256WebCrypto(value);\n }\n return Promise.resolve(sha256Fallback(value));\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport { COOKIE_POLICY_URL, OTHER_INFO_URL } from \"../env/constant\";\nimport { setConsentPreferenceCookie } from \"../helpers/cookie\";\nimport { useCreateDeviceCookieConsent } from \"../hooks/useConsent\";\n\nimport { usePhygitalConsent } from \"../provider/PhygitalConsentProvider\";\n\nconst PREFERENCES = [\"essential\", \"analytics\", \"advertising\"] as const;\ntype PreferenceKey = (typeof PREFERENCES)[number];\n\nconst PREFERENCE_CONFIG: Record<\n PreferenceKey,\n { label: string; description: string; labelVi: string; descriptionVi: string; disabled?: boolean }\n> = {\n essential: {\n label: \"Essential\",\n description: \"Required for the site to work (e.g. security, preferences).\",\n labelVi: \"Cần thiết\",\n descriptionVi: \"Cần thiết cho hoạt động của trang (bảo mật, tùy chọn).\",\n },\n analytics: {\n label: \"Analytics\",\n description: \"Help us improve by collecting anonymous usage data.\",\n labelVi: \"Phân tích\",\n descriptionVi: \"Giúp chúng tôi cải thiện bằng cách thu thập dữ liệu sử dụng ẩn danh.\",\n },\n advertising: {\n label: \"Advertising\",\n description: \"Used to show you relevant ads and measure campaigns.\",\n labelVi: \"Quảng cáo\",\n descriptionVi: \"Dùng để hiển thị quảng cáo phù hợp và đo lường chiến dịch.\",\n },\n};\n\nexport interface CookieConsentBannerProps {\n /** Called after consent is submitted successfully (Reject or Accept). */\n onSubmitted?: () => void;\n /** Called when the banner is dismissed (e.g. hide from UI). */\n onDismiss?: () => void;\n /** Optional class name for the root container. */\n className?: string;\n}\n\nexport function CookieConsentBanner({\n onSubmitted,\n onDismiss,\n className = \"\",\n}: CookieConsentBannerProps) {\n const [dismissed, setDismissed] = useState(false);\n const [showCustomModal, setShowCustomModal] = useState(false);\n const [expandedKey, setExpandedKey] = useState<PreferenceKey | null>(null);\n const [preferences, setPreferences] = useState<Record<PreferenceKey, boolean>>({\n essential: true,\n analytics: true,\n advertising: true,\n });\n\n const { deviceId } = usePhygitalConsent();\n\n const createConsent = useCreateDeviceCookieConsent({\n onSuccess: (_data, variables) => {\n setConsentPreferenceCookie(deviceId, variables.selected_preferences ?? []);\n onSubmitted?.();\n onDismiss?.();\n setDismissed(true);\n setShowCustomModal(false);\n },\n });\n\n const getSelectedPreferences = (): string[] =>\n PREFERENCES.filter((key) => preferences[key]);\n\n const togglePreference = (key: PreferenceKey) => {\n if (PREFERENCE_CONFIG[key].disabled) return;\n setPreferences((prev) => ({ ...prev, [key]: !prev[key] }));\n };\n\n const handleReject = () => {\n createConsent.mutate({\n device_id: deviceId,\n status: \"REJECTED\",\n selected_preferences: [\"essential\"],\n });\n };\n\n const handleAcceptAll = () => {\n createConsent.mutate({\n device_id: deviceId,\n status: \"ACCEPTED\",\n selected_preferences: [...PREFERENCES],\n });\n };\n\n const handleSaveCustom = () => {\n const selected = getSelectedPreferences();\n createConsent.mutate({\n device_id: deviceId,\n status: \"ACCEPTED\",\n selected_preferences: selected.length > 0 ? selected : [\"essential\"],\n });\n };\n\n if (dismissed) return null;\n\n return (\n <>\n {/* Screen 1: Bottom banner */}\n <div\n role=\"dialog\"\n aria-label=\"Thông báo về cookie\"\n className={`consent:fixed consent:bottom-0 consent:left-0 consent:right-0 consent:z-50 consent:flex consent:flex-col consent:gap-4 consent:rounded-t-xl consent:border consent:border-b-0 consent:border-gray-200 consent:bg-white consent:p-4 consent:shadow-lg consent:md:left-4 consent:md:right-auto consent:md:bottom-4 consent:md:max-w-md consent:md:rounded-xl consent:md:border consent:md:border-gray-200 ${className}`}\n style={{\n position: \"fixed\",\n bottom: 0,\n left: 0,\n right: 0,\n zIndex: 50,\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"1rem\",\n borderRadius: \"0.75rem 0.75rem 0 0\",\n borderWidth: \"1px 1px 0 1px\",\n borderColor: \"#e5e7eb\",\n backgroundColor: \"#fff\",\n padding: \"1rem\",\n boxShadow: \"0 -4px 6px -1px rgb(0 0 0 / 0.1)\",\n }}\n >\n <h2\n className=\"consent:text-lg consent:font-semibold consent:text-gray-900\"\n style={{ fontSize: \"1.125rem\", fontWeight: 600, color: \"#111827\" }}\n >\n Thông báo về cookie\n </h2>\n <div\n className=\"consent:text-sm consent:text-gray-600\"\n style={{ fontSize: \"0.875rem\", color: \"#4b5563\", display: \"flex\", flexDirection: \"column\", gap: \"0.5rem\" }}\n >\n <p>\n TapQuest sử dụng trình theo dõi (như Cookie hoặc SDK) cho:\n </p>\n <ul style={{ margin: 0, paddingLeft: \"1.25rem\" }}>\n {PREFERENCES.map((key) => (\n <li key={key}>{PREFERENCE_CONFIG[key].labelVi}</li>\n ))}\n </ul>\n <p>\n Trước khi bạn đồng ý, chỉ những trình theo dõi hoàn toàn cần thiết mới được triển khai.\n </p>\n <p>\n Nếu bạn chọn Chấp nhận tất cả, bạn đồng ý sử dụng tất cả trình theo dõi của chúng tôi.\n </p>\n <p>\n Nếu bạn chọn Từ chối tất cả, bạn từ chối những trình theo dõi yêu cầu sự đồng ý của bạn và sẽ không có quyền truy cập vào các đề nghị hoặc nội dung được cá nhân hóa.\n </p>\n <p>\n Nếu bạn chọn Tùy chọn, bạn có thể chọn xem bạn có đồng ý sử dụng trình theo dõi trên ứng dụng của chúng tôi hay không và ở mức độ nào.\n </p>\n <p>\n Bạn có thể rút lại sự đồng ý của mình bất kỳ lúc nào bằng cách nhấp vào liên kết trong{\" \"}\n {COOKIE_POLICY_URL ? (\n <a\n href={COOKIE_POLICY_URL}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"consent:text-blue-600 consent:underline\"\n style={{ color: \"#2563eb\", textDecoration: \"underline\" }}\n >\n Chính sách cookie\n </a>\n ) : (\n \"Chính sách cookie\"\n )}{\" \"}\n của chúng tôi.\n </p>\n </div>\n <div style={{ display: \"flex\", gap: \"0.5rem\", flexWrap: \"wrap\" }}>\n <button\n type=\"button\"\n onClick={() => setShowCustomModal(true)}\n className=\"consent:rounded-lg consent:border consent:border-gray-300 consent:bg-white consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-gray-700 consent:shadow-sm hover:consent:bg-gray-50 disabled:consent:opacity-50\"\n style={{\n borderRadius: \"0.5rem\",\n border: \"1px solid #111827\",\n background: \"#fff\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: \"#111827\",\n cursor: \"pointer\",\n }}\n >\n Tùy chọn\n </button>\n <button\n type=\"button\"\n onClick={handleReject}\n disabled={createConsent.isPending}\n className=\"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50\"\n style={{\n borderRadius: \"0.5rem\",\n background: \"#111827\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: \"#fff\",\n border: \"none\",\n cursor: \"pointer\",\n }}\n >\n Từ chối tất cả\n </button>\n <button\n type=\"button\"\n onClick={handleAcceptAll}\n disabled={createConsent.isPending}\n className=\"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50\"\n style={{\n borderRadius: \"0.5rem\",\n background: \"#111827\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: \"#fff\",\n border: \"none\",\n cursor: \"pointer\",\n }}\n >\n Chấp nhận tất cả\n </button>\n </div>\n {createConsent.isError && (\n <p\n className=\"consent:text-sm consent:text-red-600\"\n style={{ fontSize: \"0.875rem\", color: \"#dc2626\" }}\n >\n Đã xảy ra lỗi. Vui lòng thử lại.\n </p>\n )}\n </div>\n\n {/* Screen 2: Custom preferences modal */}\n {showCustomModal && (\n <div\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Trung tâm tuỳ chọn bảo mật\"\n style={{\n position: \"fixed\",\n inset: 0,\n zIndex: 60,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: \"rgba(0,0,0,0.5)\",\n padding: \"1rem\",\n }}\n onClick={(e) => e.target === e.currentTarget && setShowCustomModal(false)}\n >\n <div\n className=\"consent:bg-white consent:rounded-xl consent:border consent:border-gray-200 consent:shadow-lg consent:max-h-[90vh] consent:overflow-y-auto\"\n style={{\n backgroundColor: \"#fff\",\n borderRadius: \"0.75rem\",\n border: \"1px solid #e5e7eb\",\n boxShadow: \"0 10px 15px -3px rgb(0 0 0 / 0.1)\",\n maxWidth: \"28rem\",\n width: \"100%\",\n maxHeight: \"90vh\",\n overflowY: \"auto\",\n padding: \"1.25rem\",\n position: \"relative\",\n }}\n onClick={(e) => e.stopPropagation()}\n >\n <button\n type=\"button\"\n onClick={() => setShowCustomModal(false)}\n aria-label=\"Đóng\"\n style={{\n position: \"absolute\",\n top: \"1rem\",\n right: \"1rem\",\n width: \"2rem\",\n height: \"2rem\",\n borderRadius: \"0.25rem\",\n border: \"none\",\n background: \"transparent\",\n cursor: \"pointer\",\n fontSize: \"1.25rem\",\n lineHeight: 1,\n color: \"#6b7280\",\n }}\n >\n ×\n </button>\n <h2\n className=\"consent:text-lg consent:font-semibold consent:text-gray-900\"\n style={{ fontSize: \"1.125rem\", fontWeight: 600, color: \"#111827\", marginBottom: \"0.75rem\", paddingRight: \"2rem\" }}\n >\n Trung tâm tuỳ chọn bảo mật\n </h2>\n <div\n className=\"consent:text-sm consent:text-gray-600\"\n style={{ fontSize: \"0.875rem\", color: \"#4b5563\", marginBottom: \"1rem\" }}\n >\n <p style={{ marginBottom: \"0.5rem\" }}>\n Khi bạn truy cập bất kỳ trang web nào, trang web đó có thể lưu trữ hoặc truy xuất thông tin trên trình duyệt của bạn, chủ yếu dưới dạng cookie. Thông tin này có thể liên quan đến bạn, tùy chọn của bạn hoặc thiết bị của bạn, và chủ yếu được sử dụng để trang web hoạt động như mong đợi.\n </p>\n <p style={{ marginBottom: \"0.5rem\" }}>\n Thông tin này thường không trực tiếp xác định bạn nhưng có thể mang lại trải nghiệm web được cá nhân hóa hơn. Chúng tôi tôn trọng quyền riêng tư của bạn; bạn có thể chọn không cho phép một số loại cookie. Nhấp vào tiêu đề từng danh mục để tìm hiểu thêm và thay đổi cài đặt mặc định. Việc chặn một số cookie có thể ảnh hưởng đến trải nghiệm của bạn với trang web và các dịch vụ được cung cấp.\n </p>\n <p style={{ marginBottom: \"0.5rem\" }}>\n Nếu chọn \"Không theo dõi\" khi lần đầu sử dụng TapQuest, chỉ cookie hoàn toàn cần thiết mới được sử dụng.\n </p>\n {OTHER_INFO_URL ? (\n <a\n href={OTHER_INFO_URL}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"consent:text-blue-600 consent:underline\"\n style={{ color: \"#2563eb\", textDecoration: \"underline\" }}\n >\n Thông tin khác\n </a>\n ) : (\n <span style={{ color: \"#2563eb\", textDecoration: \"underline\" }}>Thông tin khác</span>\n )}\n </div>\n <h3\n className=\"consent:text-sm consent:font-semibold consent:text-gray-900\"\n style={{ fontSize: \"0.875rem\", fontWeight: 600, color: \"#111827\", marginBottom: \"0.75rem\" }}\n >\n Quản lý tuỳ chọn đồng ý\n </h3>\n <div style={{ display: \"flex\", flexDirection: \"column\", gap: \"0.25rem\", marginBottom: \"1.25rem\" }}>\n {PREFERENCES.map((key) => {\n const config = PREFERENCE_CONFIG[key];\n const checked = preferences[key];\n const isExpanded = expandedKey === key;\n return (\n <div\n key={key}\n style={{\n border: \"1px solid #e5e7eb\",\n borderRadius: \"0.5rem\",\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n gap: \"0.5rem\",\n padding: \"0.75rem\",\n cursor: \"pointer\",\n backgroundColor: isExpanded ? \"#f9fafb\" : \"transparent\",\n }}\n onClick={() => setExpandedKey(isExpanded ? null : key)}\n >\n <span\n style={{\n flexShrink: 0,\n width: \"1.25rem\",\n height: \"1.25rem\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n fontSize: \"1rem\",\n color: \"#6b7280\",\n transform: isExpanded ? \"rotate(45deg)\" : \"none\",\n transition: \"transform 0.2s\",\n }}\n >\n +\n </span>\n <span\n className=\"consent:font-medium consent:text-gray-900\"\n style={{ flex: 1, fontSize: \"0.875rem\", fontWeight: 500, color: \"#111827\" }}\n >\n {config.labelVi}\n </span>\n <button\n type=\"button\"\n role=\"switch\"\n aria-checked={checked}\n aria-label={`${config.labelVi} ${checked ? \"bật\" : \"tắt\"}`}\n disabled={config.disabled}\n onClick={(e) => {\n e.stopPropagation();\n togglePreference(key);\n }}\n style={{\n flexShrink: 0,\n width: 44,\n height: 24,\n borderRadius: 12,\n border: \"none\",\n padding: 0,\n cursor: config.disabled ? \"default\" : \"pointer\",\n backgroundColor: config.disabled ? \"#e5e7eb\" : checked ? \"#111827\" : \"#d1d5db\",\n opacity: config.disabled ? 0.7 : 1,\n transition: \"background-color 0.2s\",\n }}\n >\n <span\n style={{\n display: \"block\",\n width: 20,\n height: 20,\n borderRadius: \"50%\",\n backgroundColor: \"#fff\",\n marginLeft: checked ? 22 : 2,\n marginTop: 2,\n transition: \"margin-left 0.2s\",\n boxShadow: \"0 1px 2px rgb(0 0 0 / 0.2)\",\n }}\n />\n </button>\n </div>\n {isExpanded && (\n <div\n className=\"consent:text-sm consent:text-gray-600\"\n style={{\n fontSize: \"0.875rem\",\n color: \"#4b5563\",\n padding: \"0 0.75rem 0.75rem 2.5rem\",\n borderTop: \"1px solid #e5e7eb\",\n }}\n >\n {config.descriptionVi}\n </div>\n )}\n </div>\n );\n })}\n </div>\n <button\n type=\"button\"\n onClick={handleSaveCustom}\n disabled={createConsent.isPending}\n className=\"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50 consent:w-full\"\n style={{\n borderRadius: \"0.5rem\",\n background: \"#111827\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: \"#fff\",\n border: \"none\",\n cursor: \"pointer\",\n width: \"100%\",\n }}\n >\n Xác nhận lựa chọn của tôi\n </button>\n </div>\n </div>\n )}\n </>\n );\n}\n"],"mappings":";ukBAAA,I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AQQ,EAAO,SAAW,UAAY,UACtC,gBAAiBA,EAAO,SAAW,UAAYC,EAAU,UAAY,UACrE,QAASD,EAAO,SAAW,GAAM,EACjC,WAAY,uBACd,EAEA,mBAAC,QACC,MAAO,CACL,QAAS,QACT,MAAO,GACP,OAAQ,GACR,aAAc,MACd,gBAAiB,OACjB,WAAYC,EAAU,GAAK,EAC3B,UAAW,EACX,WAAY,mBACZ,UAAW,4BACb,EACF,EACF,GACF,EACCC,MACC,OAAC,OACC,UAAU,wCACV,MAAO,CACL,SAAU,WACV,MAAO,UACP,QAAS,2BACT,UAAW,mBACb,EAEC,SAAAF,EAAO,cACV,IAzFGR,CA2FP,CAEJ,CAAC,EACH,KACA,OAAC,UACC,KAAK,SACL,QAASK,EACT,SAAUX,EAAc,UACxB,UAAU,iNACV,MAAO,CACL,aAAc,SACd,WAAY,UACZ,QAAS,cACT,SAAU,WACV,WAAY,IACZ,MAAO,OACP,OAAQ,OACR,OAAQ,UACR,MAAO,MACT,EACD,+DAED,GACF,EACF,GAEJ,CAEJ","names":["index_exports","__export","COOKIE_CONSENT_NAME","CookieConsentBanner","EntityStatus","MediaType","PhygitalConsentProvider","consentQueryKeys","consentService","getConsentPreferenceCookie","getCookie","setConsentPreferenceCookie","setCookie","sha256","useConsentById","useCreateDeviceCookieConsent","useCreateUserConsent","useHealth","useLatestConsentByUserId","useLatestCookieConsentByDeviceId","useManyConsents","usePhygitalConsent","__toCommonJS","MediaType","EntityStatus","import_react","COOKIE_CONSENT_NAME","getCookie","name","match","setCookie","value","options","maxAge","path","sameSite","secure","cookie","getConsentPreferenceCookie","raw","COOKIE_CONSENT_NAME","parsed","setConsentPreferenceCookie","deviceId","selected_preferences","import_react_query","import_axios","import_react","import_jsx_runtime","ConsentServiceContext","createConsentService","baseURL","axiosConfig","requestInterceptors","responseInterceptors","instance","axios","headers","key","value","ConsentServiceProvider","children","queryClient","queryClientConfig","queryClientInstance","consentService","service","useConsentService","context","import_jsx_runtime","PhygitalConsentContext","PhygitalConsentProvider","props","children","deviceId","consentServiceProps","hasConsentPreference","setHasConsentPreference","refreshConsentPreference","stored","getConsentPreferenceCookie","value","ConsentServiceProvider","usePhygitalConsent","context","baseUrl","consentService","axiosInstance","data","params","id","user_id","body","device_id","import_react_query","arrayBufferToHex","buffer","b","sha256WebCrypto","value","utf8","hashBuffer","sha256Fallback","bytes","utf8Encode","K","getK","H","getH","W","numBlocks","block","start","i","o","s0","rotr","s1","a","c","d","e","f","g","h","S1","ch","t1","S0","maj","t2","out","v","n","s","len","pad","total","view","k","hasWebCrypto","sha256","consentQueryKeys","params","id","user_id","device_id","useHealth","options","consentApi","useConsentService","service","consentService","useManyConsents","useConsentById","useLatestConsentByUserId","sha256","useLatestCookieConsentByDeviceId","useCreateUserConsent","queryClient","body","payload","_data","variables","useCreateDeviceCookieConsent","import_react","import_jsx_runtime","PREFERENCES","PREFERENCE_CONFIG","CookieConsentBanner","onSubmitted","onDismiss","className","dismissed","setDismissed","showCustomModal","setShowCustomModal","expandedKey","setExpandedKey","preferences","setPreferences","deviceId","usePhygitalConsent","createConsent","useCreateDeviceCookieConsent","_data","variables","setConsentPreferenceCookie","getSelectedPreferences","key","togglePreference","prev","handleReject","handleAcceptAll","handleSaveCustom","selected","e","config","checked","isExpanded"]}
1
+ {"version":3,"sources":["../index.ts","../src/types/common.ts","../src/provider/PhygitalConsentProvider.tsx","../src/components/CookieConsentBanner.tsx","../src/helpers/cookie.ts","../src/hooks/useConsent.ts","../src/api/consent.ts","../src/helpers/sha256.ts","../src/provider/ConsentServiceProvider.tsx","../src/components/PolicyPopup.tsx"],"sourcesContent":["export * from \"./src\";\n","export enum MediaType {\n IMAGE = \"image\",\n VIDEO = \"video\",\n}\n\nexport type DateTimeNumber = number;\n\nexport interface Media {\n url: string;\n type: MediaType | string;\n thumbnail_url?: string;\n}\n\nexport enum EntityStatus {\n ACTIVE = \"Active\",\n INACTIVE = \"Inactive\",\n}\n\nexport interface CommonModel {\n id: string;\n status: EntityStatus;\n created_at: DateTimeNumber;\n updated_at: DateTimeNumber;\n created_by?: string;\n updated_by?: string;\n}\n","\"use client\";\n\nimport React, { createContext, useCallback, useContext, useEffect, useState } from \"react\";\nimport { CookieConsentBanner } from \"../components/CookieConsentBanner\";\nimport { PolicyPopup } from \"../components/PolicyPopup\";\nimport { getConsentPreferenceCookie } from \"../helpers/cookie\";\nimport { useLatestConsentByUserId } from \"../hooks/useConsent\";\nimport { ConsentServiceProvider, ConsentServiceProviderProps } from \"./ConsentServiceProvider\";\n\nexport interface PhygitalConsentContextValue {\n deviceId: string;\n /** True when cookie phygital_cookie_consent exists and has valid deviceId + selected_preferences. Use to show/hide cookie banner. */\n hasConsentPreference: boolean;\n /** Re-read cookie and update hasConsentPreference. Call after storing preference (e.g. from CookieConsentBanner onSuccess). */\n refreshConsentPreference: () => void;\n /**\n * Open policy popup if user has no latest consent. Receives userId; calls useLatestConsentByUserId.\n * If data exists, popup is not shown. If no data, policy popup is shown.\n */\n openPolicyPopup: (userId: string) => void;\n}\n\nconst PhygitalConsentContext = createContext<PhygitalConsentContextValue | undefined>(undefined);\n\nexport interface PhygitalConsentProviderProps extends ConsentServiceProviderProps {\n deviceId: string;\n children: React.ReactNode;\n /**\n * When true (default), render CookieConsentBanner automatically when hasConsentPreference is false.\n * Set to false if you want to render the banner yourself (e.g. in a layout) using usePhygitalConsent().\n */\n showBannerWhenNoPreference?: boolean;\n}\n\n/**\n * Main provider for consumer apps. Wraps ConsentServiceProvider and exposes\n * hasConsentPreference + refreshConsentPreference so the app can show/hide\n * the cookie banner based on whether the user has already chosen a preference.\n * When showBannerWhenNoPreference is true (default), the consent banner is\n * rendered automatically on app start when the user has no stored preference.\n */\nexport function PhygitalConsentProvider(props: PhygitalConsentProviderProps) {\n const { children, deviceId, showBannerWhenNoPreference = true, ...consentServiceProps } = props;\n const [hasConsentPreference, setHasConsentPreference] = useState(false);\n const [pendingUserId, setPendingUserId] = useState<string | null>(null);\n const [showPolicyPopup, setShowPolicyPopup] = useState(false);\n const [policyUserId, setPolicyUserId] = useState<string | null>(null);\n\n const { data: latestConsent, isFetched } = useLatestConsentByUserId({\n user_id: pendingUserId ?? \"\",\n });\n\n useEffect(() => {\n if (!pendingUserId || !isFetched) return;\n if (latestConsent != null) {\n setPendingUserId(null);\n return;\n }\n setPolicyUserId(pendingUserId);\n setShowPolicyPopup(true);\n setPendingUserId(null);\n }, [pendingUserId, isFetched, latestConsent]);\n\n const refreshConsentPreference = useCallback(() => {\n const stored = getConsentPreferenceCookie();\n setHasConsentPreference(!!stored);\n }, []);\n\n const openPolicyPopup = useCallback((userId: string) => {\n if (!userId) return;\n setPendingUserId(userId);\n }, []);\n\n const closePolicyPopup = useCallback(() => {\n setShowPolicyPopup(false);\n setPolicyUserId(null);\n }, []);\n\n useEffect(() => {\n refreshConsentPreference();\n }, [refreshConsentPreference]);\n\n const value: PhygitalConsentContextValue = {\n deviceId,\n hasConsentPreference,\n refreshConsentPreference,\n openPolicyPopup,\n };\n\n return (\n <ConsentServiceProvider {...consentServiceProps}>\n <PhygitalConsentContext.Provider value={value}>\n {children}\n {showBannerWhenNoPreference && !hasConsentPreference && (\n <CookieConsentBanner onSubmitted={refreshConsentPreference} />\n )}\n {showPolicyPopup && policyUserId && (\n <PolicyPopup\n open={showPolicyPopup}\n onClose={closePolicyPopup}\n userId={policyUserId}\n />\n )}\n </PhygitalConsentContext.Provider>\n </ConsentServiceProvider>\n );\n}\n\nexport function usePhygitalConsent() {\n const context = useContext(PhygitalConsentContext);\n if (!context) {\n throw new Error(\"usePhygitalConsent must be used within a PhygitalConsentProvider\");\n }\n return context;\n}\n","\"use client\";\n\nimport { useState } from \"react\";\nimport { COOKIE_POLICY_URL, OTHER_INFO_URL } from \"../env/constant\";\nimport { setConsentPreferenceCookie } from \"../helpers/cookie\";\nimport { useCreateDeviceCookieConsent } from \"../hooks/useConsent\";\n\nimport { usePhygitalConsent } from \"../provider/PhygitalConsentProvider\";\n\nconst PREFERENCES = [\"essential\", \"analytics\", \"advertising\"] as const;\ntype PreferenceKey = (typeof PREFERENCES)[number];\n\nconst PREFERENCE_CONFIG: Record<\n PreferenceKey,\n { label: string; description: string; labelVi: string; descriptionVi: string; disabled?: boolean }\n> = {\n essential: {\n label: \"Essential\",\n description: \"Required for the site to work (e.g. security, preferences).\",\n labelVi: \"Cần thiết\",\n descriptionVi: \"Cần thiết cho hoạt động của trang (bảo mật, tùy chọn).\",\n },\n analytics: {\n label: \"Analytics\",\n description: \"Help us improve by collecting anonymous usage data.\",\n labelVi: \"Phân tích\",\n descriptionVi: \"Giúp chúng tôi cải thiện bằng cách thu thập dữ liệu sử dụng ẩn danh.\",\n },\n advertising: {\n label: \"Advertising\",\n description: \"Used to show you relevant ads and measure campaigns.\",\n labelVi: \"Quảng cáo\",\n descriptionVi: \"Dùng để hiển thị quảng cáo phù hợp và đo lường chiến dịch.\",\n },\n};\n\nexport interface CookieConsentBannerProps {\n /** Called after consent is submitted successfully (Reject or Accept). */\n onSubmitted?: () => void;\n /** Called when the banner is dismissed (e.g. hide from UI). */\n onDismiss?: () => void;\n /** Optional class name for the root container. */\n className?: string;\n}\n\nexport function CookieConsentBanner({\n onSubmitted,\n onDismiss,\n className = \"\",\n}: CookieConsentBannerProps) {\n const [dismissed, setDismissed] = useState(false);\n const [showCustomModal, setShowCustomModal] = useState(false);\n const [expandedKey, setExpandedKey] = useState<PreferenceKey | null>(null);\n const [preferences, setPreferences] = useState<Record<PreferenceKey, boolean>>({\n essential: true,\n analytics: true,\n advertising: true,\n });\n\n const { deviceId } = usePhygitalConsent();\n\n const createConsent = useCreateDeviceCookieConsent({\n onSuccess: (_data, variables) => {\n setConsentPreferenceCookie(deviceId, variables.selected_preferences ?? []);\n onSubmitted?.();\n onDismiss?.();\n setDismissed(true);\n setShowCustomModal(false);\n },\n });\n\n const getSelectedPreferences = (): string[] =>\n PREFERENCES.filter((key) => preferences[key]);\n\n const togglePreference = (key: PreferenceKey) => {\n if (PREFERENCE_CONFIG[key].disabled) return;\n setPreferences((prev) => ({ ...prev, [key]: !prev[key] }));\n };\n\n const handleReject = () => {\n createConsent.mutate({\n device_id: deviceId,\n status: \"REJECTED\",\n selected_preferences: [],\n });\n };\n\n const handleAcceptAll = () => {\n createConsent.mutate({\n device_id: deviceId,\n status: \"ACCEPTED\",\n selected_preferences: [...PREFERENCES],\n });\n };\n\n const handleSaveCustom = () => {\n const selected = getSelectedPreferences();\n createConsent.mutate({\n device_id: deviceId,\n status: \"ACCEPTED\",\n selected_preferences: selected.length > 0 ? selected : [],\n });\n };\n\n if (dismissed) return null;\n\n return (\n <>\n {/* Screen 1: Bottom banner */}\n <div\n role=\"dialog\"\n aria-label=\"Thông báo về cookie\"\n className={`consent:fixed consent:bottom-0 consent:left-0 consent:right-0 consent:z-50 consent:flex consent:flex-col consent:gap-4 consent:rounded-t-xl consent:border consent:border-b-0 consent:border-gray-200 consent:bg-white consent:p-4 consent:shadow-lg consent:md:left-4 consent:md:right-auto consent:md:bottom-4 consent:md:max-w-md consent:md:rounded-xl consent:md:border consent:md:border-gray-200 ${className}`}\n style={{\n position: \"fixed\",\n bottom: 0,\n left: 0,\n right: 0,\n zIndex: 50,\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"1rem\",\n borderRadius: \"0.75rem 0.75rem 0 0\",\n borderWidth: \"1px 1px 0 1px\",\n borderColor: \"#e5e7eb\",\n backgroundColor: \"#fff\",\n padding: \"1rem\",\n boxShadow: \"0 -4px 6px -1px rgb(0 0 0 / 0.1)\",\n }}\n >\n <h2\n className=\"consent:text-lg consent:font-semibold consent:text-gray-900\"\n style={{ fontSize: \"1.125rem\", fontWeight: 600, color: \"#111827\" }}\n >\n Thông báo về cookie\n </h2>\n <div\n className=\"consent:text-sm consent:text-gray-600\"\n style={{ fontSize: \"0.875rem\", color: \"#4b5563\", display: \"flex\", flexDirection: \"column\", gap: \"0.5rem\" }}\n >\n <p>\n TapQuest sử dụng trình theo dõi (như Cookie hoặc SDK) cho:\n </p>\n <ul style={{ margin: 0, paddingLeft: \"1.25rem\" }}>\n {PREFERENCES.map((key) => (\n <li key={key}>{PREFERENCE_CONFIG[key].labelVi}</li>\n ))}\n </ul>\n <p>\n Trước khi bạn đồng ý, chỉ những trình theo dõi hoàn toàn cần thiết mới được triển khai.\n </p>\n <p>\n Nếu bạn chọn Chấp nhận tất cả, bạn đồng ý sử dụng tất cả trình theo dõi của chúng tôi.\n </p>\n <p>\n Nếu bạn chọn Từ chối tất cả, bạn từ chối những trình theo dõi yêu cầu sự đồng ý của bạn và sẽ không có quyền truy cập vào các đề nghị hoặc nội dung được cá nhân hóa.\n </p>\n <p>\n Nếu bạn chọn Tùy chọn, bạn có thể chọn xem bạn có đồng ý sử dụng trình theo dõi trên ứng dụng của chúng tôi hay không và ở mức độ nào.\n </p>\n <p>\n Bạn có thể rút lại sự đồng ý của mình bất kỳ lúc nào bằng cách nhấp vào liên kết trong{\" \"}\n {COOKIE_POLICY_URL ? (\n <a\n href={COOKIE_POLICY_URL}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"consent:text-blue-600 consent:underline\"\n style={{ color: \"#2563eb\", textDecoration: \"underline\" }}\n >\n Chính sách cookie\n </a>\n ) : (\n \"Chính sách cookie\"\n )}{\" \"}\n của chúng tôi.\n </p>\n </div>\n <div className=\"flex justify-end gap-2 flex-wrap\">\n <button\n type=\"button\"\n onClick={() => setShowCustomModal(true)}\n className=\"consent:rounded-lg consent:border consent:border-gray-300 consent:bg-white consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-gray-700 consent:shadow-sm hover:consent:bg-gray-50 disabled:consent:opacity-50\"\n style={{\n borderRadius: \"0.5rem\",\n border: \"1px solid #111827\",\n background: \"#fff\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: \"#111827\",\n cursor: \"pointer\",\n }}\n >\n Tùy chọn\n </button>\n <button\n type=\"button\"\n onClick={handleReject}\n disabled={createConsent.isPending}\n className=\"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50\"\n style={{\n borderRadius: \"0.5rem\",\n background: \"#111827\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: \"#fff\",\n border: \"none\",\n cursor: \"pointer\",\n }}\n >\n Từ chối tất cả\n </button>\n <button\n type=\"button\"\n onClick={handleAcceptAll}\n disabled={createConsent.isPending}\n className=\"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50\"\n style={{\n borderRadius: \"0.5rem\",\n background: \"#111827\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: \"#fff\",\n border: \"none\",\n cursor: \"pointer\",\n }}\n >\n Chấp nhận tất cả\n </button>\n </div>\n {createConsent.isError && (\n <p\n className=\"consent:text-sm consent:text-red-600\"\n style={{ fontSize: \"0.875rem\", color: \"#dc2626\" }}\n >\n Đã xảy ra lỗi. Vui lòng thử lại.\n </p>\n )}\n </div>\n\n {/* Screen 2: Custom preferences modal */}\n {showCustomModal && (\n <div\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Trung tâm tuỳ chọn bảo mật\"\n style={{\n position: \"fixed\",\n inset: 0,\n zIndex: 60,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: \"rgba(0,0,0,0.5)\",\n padding: \"1rem\",\n }}\n onClick={(e) => e.target === e.currentTarget && setShowCustomModal(false)}\n >\n <div\n className=\"consent:bg-white consent:rounded-xl consent:border consent:border-gray-200 consent:shadow-lg consent:max-h-[90vh] consent:overflow-y-auto\"\n style={{\n backgroundColor: \"#fff\",\n borderRadius: \"0.75rem\",\n border: \"1px solid #e5e7eb\",\n boxShadow: \"0 10px 15px -3px rgb(0 0 0 / 0.1)\",\n maxWidth: \"28rem\",\n width: \"100%\",\n maxHeight: \"90vh\",\n overflowY: \"auto\",\n padding: \"1.25rem\",\n position: \"relative\",\n }}\n onClick={(e) => e.stopPropagation()}\n >\n <button\n type=\"button\"\n onClick={() => setShowCustomModal(false)}\n aria-label=\"Đóng\"\n style={{\n position: \"absolute\",\n top: \"1rem\",\n right: \"1rem\",\n width: \"2rem\",\n height: \"2rem\",\n borderRadius: \"0.25rem\",\n border: \"none\",\n background: \"transparent\",\n cursor: \"pointer\",\n fontSize: \"1.25rem\",\n lineHeight: 1,\n color: \"#6b7280\",\n }}\n >\n ×\n </button>\n <h2\n className=\"consent:text-lg consent:font-semibold consent:text-gray-900\"\n style={{ fontSize: \"1.125rem\", fontWeight: 600, color: \"#111827\", marginBottom: \"0.75rem\", paddingRight: \"2rem\" }}\n >\n Trung tâm tuỳ chọn bảo mật\n </h2>\n <div\n className=\"consent:text-sm consent:text-gray-600\"\n style={{ fontSize: \"0.875rem\", color: \"#4b5563\", marginBottom: \"1rem\" }}\n >\n <p style={{ marginBottom: \"0.5rem\" }}>\n Khi bạn truy cập bất kỳ trang web nào, trang web đó có thể lưu trữ hoặc truy xuất thông tin trên trình duyệt của bạn, chủ yếu dưới dạng cookie. Thông tin này có thể liên quan đến bạn, tùy chọn của bạn hoặc thiết bị của bạn, và chủ yếu được sử dụng để trang web hoạt động như mong đợi.\n </p>\n <p style={{ marginBottom: \"0.5rem\" }}>\n Thông tin này thường không trực tiếp xác định bạn nhưng có thể mang lại trải nghiệm web được cá nhân hóa hơn. Chúng tôi tôn trọng quyền riêng tư của bạn; bạn có thể chọn không cho phép một số loại cookie. Nhấp vào tiêu đề từng danh mục để tìm hiểu thêm và thay đổi cài đặt mặc định. Việc chặn một số cookie có thể ảnh hưởng đến trải nghiệm của bạn với trang web và các dịch vụ được cung cấp.\n </p>\n <p style={{ marginBottom: \"0.5rem\" }}>\n Nếu chọn \"Không theo dõi\" khi lần đầu sử dụng TapQuest, chỉ cookie hoàn toàn cần thiết mới được sử dụng.\n </p>\n {OTHER_INFO_URL ? (\n <a\n href={OTHER_INFO_URL}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className=\"consent:text-blue-600 consent:underline\"\n style={{ color: \"#2563eb\", textDecoration: \"underline\" }}\n >\n Thông tin khác\n </a>\n ) : (\n <span style={{ color: \"#2563eb\", textDecoration: \"underline\" }}>Thông tin khác</span>\n )}\n </div>\n <h3\n className=\"consent:text-sm consent:font-semibold consent:text-gray-900\"\n style={{ fontSize: \"0.875rem\", fontWeight: 600, color: \"#111827\", marginBottom: \"0.75rem\" }}\n >\n Quản lý tuỳ chọn đồng ý\n </h3>\n <div style={{ display: \"flex\", flexDirection: \"column\", gap: \"0.25rem\", marginBottom: \"1.25rem\" }}>\n {PREFERENCES.map((key) => {\n const config = PREFERENCE_CONFIG[key];\n const checked = preferences[key];\n const isExpanded = expandedKey === key;\n return (\n <div\n key={key}\n style={{\n border: \"1px solid #e5e7eb\",\n borderRadius: \"0.5rem\",\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n gap: \"0.5rem\",\n padding: \"0.75rem\",\n cursor: \"pointer\",\n backgroundColor: isExpanded ? \"#f9fafb\" : \"transparent\",\n }}\n onClick={() => setExpandedKey(isExpanded ? null : key)}\n >\n <span\n style={{\n flexShrink: 0,\n width: \"1.25rem\",\n height: \"1.25rem\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n fontSize: \"1rem\",\n color: \"#6b7280\",\n transform: isExpanded ? \"rotate(45deg)\" : \"none\",\n transition: \"transform 0.2s\",\n }}\n >\n +\n </span>\n <span\n className=\"consent:font-medium consent:text-gray-900\"\n style={{ flex: 1, fontSize: \"0.875rem\", fontWeight: 500, color: \"#111827\" }}\n >\n {config.labelVi}\n </span>\n <button\n type=\"button\"\n role=\"switch\"\n aria-checked={checked}\n aria-label={`${config.labelVi} ${checked ? \"bật\" : \"tắt\"}`}\n disabled={config.disabled}\n onClick={(e) => {\n e.stopPropagation();\n togglePreference(key);\n }}\n style={{\n flexShrink: 0,\n width: 44,\n height: 24,\n borderRadius: 12,\n border: \"none\",\n padding: 0,\n cursor: config.disabled ? \"default\" : \"pointer\",\n backgroundColor: config.disabled ? \"#e5e7eb\" : checked ? \"#111827\" : \"#d1d5db\",\n opacity: config.disabled ? 0.7 : 1,\n transition: \"background-color 0.2s\",\n }}\n >\n <span\n style={{\n display: \"block\",\n width: 20,\n height: 20,\n borderRadius: \"50%\",\n backgroundColor: \"#fff\",\n marginLeft: checked ? 22 : 2,\n marginTop: 2,\n transition: \"margin-left 0.2s\",\n boxShadow: \"0 1px 2px rgb(0 0 0 / 0.2)\",\n }}\n />\n </button>\n </div>\n {isExpanded && (\n <div\n className=\"consent:text-sm consent:text-gray-600\"\n style={{\n fontSize: \"0.875rem\",\n color: \"#4b5563\",\n padding: \"0 0.75rem 0.75rem 2.5rem\",\n borderTop: \"1px solid #e5e7eb\",\n }}\n >\n {config.descriptionVi}\n </div>\n )}\n </div>\n );\n })}\n </div>\n <button\n type=\"button\"\n onClick={handleSaveCustom}\n disabled={createConsent.isPending}\n className=\"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50 consent:w-full\"\n style={{\n borderRadius: \"0.5rem\",\n background: \"#111827\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: \"#fff\",\n border: \"none\",\n cursor: \"pointer\",\n width: \"100%\",\n }}\n >\n Xác nhận lựa chọn của tôi\n </button>\n </div>\n </div>\n )}\n </>\n );\n}\n","/**\n * Browser cookie helpers for phygital-consent.\n * Cookie name for consent preference: phygital_cookie_consent.\n * Stored value: { deviceId: string, selected_preferences: string[] } (JSON).\n * Default: 1 year, path /, SameSite Lax.\n */\n\nexport const COOKIE_CONSENT_NAME = \"phygital_cookie_consent\";\n\nconst ONE_YEAR_SECONDS = 365 * 24 * 60 * 60;\n\nexport interface SetCookieOptions {\n maxAge?: number;\n path?: string;\n sameSite?: \"Strict\" | \"Lax\" | \"None\";\n secure?: boolean;\n}\n\n/**\n * Get a cookie value by name.\n */\nexport function getCookie(name: string): string | null {\n if (typeof document === \"undefined\") return null;\n const match = document.cookie.match(new RegExp(\"(?:^|; )\" + encodeURIComponent(name) + \"=([^;]*)\"));\n return match ? decodeURIComponent(match[1]) : null;\n}\n\n/**\n * Set a cookie.\n */\nexport function setCookie(\n name: string,\n value: string,\n options: SetCookieOptions = {}\n): void {\n if (typeof document === \"undefined\") return;\n const {\n maxAge = ONE_YEAR_SECONDS,\n path = \"/\",\n sameSite = \"Lax\",\n secure = false,\n } = options;\n let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; path=${path}; max-age=${maxAge}; SameSite=${sameSite}`;\n if (secure) cookie += \"; Secure\";\n document.cookie = cookie;\n}\n\nexport interface ConsentPreferenceValue {\n deviceId: string;\n selected_preferences: string[];\n}\n\n/**\n * Read consent preference from cookie. Returns null if missing or invalid.\n */\nexport function getConsentPreferenceCookie(): ConsentPreferenceValue | null {\n const raw = getCookie(COOKIE_CONSENT_NAME);\n if (!raw) return null;\n try {\n const parsed = JSON.parse(raw) as unknown;\n if (\n parsed &&\n typeof parsed === \"object\" &&\n \"deviceId\" in parsed &&\n \"selected_preferences\" in parsed &&\n typeof (parsed as ConsentPreferenceValue).deviceId === \"string\" &&\n Array.isArray((parsed as ConsentPreferenceValue).selected_preferences)\n ) {\n return parsed as ConsentPreferenceValue;\n }\n } catch {\n // ignore\n }\n return null;\n}\n\n/**\n * Store consent preference in cookie (hashed device id + selected_preferences).\n * Uses 1 year max-age and SameSite Lax.\n */\nexport function setConsentPreferenceCookie(\n deviceId: string,\n selected_preferences: string[],\n options?: Partial<SetCookieOptions>\n): void {\n const value: ConsentPreferenceValue = { deviceId, selected_preferences };\n setCookie(COOKIE_CONSENT_NAME, JSON.stringify(value), {\n maxAge: ONE_YEAR_SECONDS,\n path: \"/\",\n sameSite: \"Lax\",\n ...options,\n });\n}\n","import {\n useQuery,\n useMutation,\n useQueryClient,\n UseQueryOptions,\n UseMutationOptions,\n} from \"@tanstack/react-query\";\nimport { consentService } from \"../api/consent\";\nimport { sha256 } from \"../helpers/sha256\";\nimport { useConsentService } from \"../provider/ConsentServiceProvider\";\nimport type {\n GetManyConsentParams,\n GetManyConsentResponse,\n GetConsentByIdParams,\n GetConsentByIdResponse,\n GetLatestConsentByUserIdParams,\n GetLatestConsentByUserIdResponse,\n GetLatestCookieConsentByDeviceIdParams,\n GetLatestCookieConsentByDeviceIdResponse,\n CreateUserConsentUpsertDTO,\n CreateUserConsentResponse,\n CreateDeviceCookieConsentUpsertDTO,\n CreateDeviceCookieConsentResponse,\n HealthResponse,\n} from \"../types\";\n\n/** Query keys for consent API */\nexport const consentQueryKeys = {\n all: [\"consent\"] as const,\n health: () => [...consentQueryKeys.all, \"health\"] as const,\n list: (params?: GetManyConsentParams) =>\n [...consentQueryKeys.all, \"list\", params] as const,\n detail: (id: string) => [...consentQueryKeys.all, \"detail\", id] as const,\n latestByUserId: (user_id: string) =>\n [...consentQueryKeys.all, \"user-id\", user_id] as const,\n latestCookieByDeviceId: (device_id: string) =>\n [...consentQueryKeys.all, \"cookies\", \"device-id\", device_id] as const,\n};\n\n// --- Queries ---\n\n/** Health check – GET /health */\nexport const useHealth = (\n options?: UseQueryOptions<HealthResponse>\n) => {\n const { consentApi } = useConsentService();\n const service = consentService(consentApi);\n\n return useQuery<HealthResponse>({\n queryKey: consentQueryKeys.health(),\n queryFn: () => service.getHealth(),\n ...options,\n });\n};\n\n/** Get all consent logs – GET /consent/v1/consent */\nexport const useManyConsents = (\n params?: GetManyConsentParams,\n options?: UseQueryOptions<GetManyConsentResponse>\n) => {\n const { consentApi } = useConsentService();\n const service = consentService(consentApi);\n\n return useQuery<GetManyConsentResponse>({\n queryKey: consentQueryKeys.list(params),\n queryFn: () => service.getManyConsents(params),\n ...options,\n });\n};\n\n/** Get consent log by ID – GET /consent/v1/consent/{id} */\nexport const useConsentById = (\n params: GetConsentByIdParams,\n options?: UseQueryOptions<GetConsentByIdResponse>\n) => {\n const { consentApi } = useConsentService();\n const service = consentService(consentApi);\n\n return useQuery<GetConsentByIdResponse>({\n queryKey: consentQueryKeys.detail(params.id),\n queryFn: () => service.getConsentById(params),\n enabled: !!params.id,\n ...options,\n });\n};\n\n/** Get latest consent for a user – GET /consent/v1/user-id (user_id hashed before send) */\nexport const useLatestConsentByUserId = (\n params: GetLatestConsentByUserIdParams,\n options?: UseQueryOptions<GetLatestConsentByUserIdResponse>\n) => {\n const { consentApi } = useConsentService();\n const service = consentService(consentApi);\n\n return useQuery<GetLatestConsentByUserIdResponse>({\n queryKey: consentQueryKeys.latestByUserId(params.user_id),\n queryFn: async () => {\n const user_id = await sha256(params.user_id);\n return service.getLatestConsentByUserId({ user_id });\n },\n enabled: !!params.user_id,\n ...options,\n });\n};\n\n/** Get latest cookie consent for a device – GET /consent/v1/cookies/device-id (device_id hashed before send) */\nexport const useLatestCookieConsentByDeviceId = (\n params: GetLatestCookieConsentByDeviceIdParams,\n options?: UseQueryOptions<GetLatestCookieConsentByDeviceIdResponse>\n) => {\n const { consentApi } = useConsentService();\n const service = consentService(consentApi);\n\n return useQuery<GetLatestCookieConsentByDeviceIdResponse>({\n queryKey: consentQueryKeys.latestCookieByDeviceId(params.device_id),\n queryFn: async () => {\n const device_id = await sha256(params.device_id);\n return service.getLatestCookieConsentByDeviceId({ device_id });\n },\n enabled: !!params.device_id,\n ...options,\n });\n};\n\n// --- Mutations ---\n\n/** Create user consent (account register) – POST /consent/v1/user-id */\nexport const useCreateUserConsent = (\n options?: UseMutationOptions<\n CreateUserConsentResponse,\n Error,\n CreateUserConsentUpsertDTO\n >\n) => {\n const { consentApi } = useConsentService();\n const queryClient = useQueryClient();\n const service = consentService(consentApi);\n\n return useMutation<CreateUserConsentResponse, Error, CreateUserConsentUpsertDTO>({\n mutationFn: async (body: CreateUserConsentUpsertDTO) => {\n const payload = { ...body };\n if (body.user_id != null && body.user_id !== \"\") {\n payload.user_id = await sha256(body.user_id);\n }\n if (body.device_id != null && body.device_id !== \"\") {\n payload.device_id = await sha256(body.device_id);\n }\n return service.createUserConsent(payload);\n },\n onSuccess: (\n _data: CreateUserConsentResponse,\n variables: CreateUserConsentUpsertDTO\n ) => {\n if (variables.user_id) {\n queryClient.invalidateQueries({\n queryKey: consentQueryKeys.latestByUserId(variables.user_id),\n });\n }\n queryClient.invalidateQueries({ queryKey: consentQueryKeys.list() });\n },\n ...options,\n });\n};\n\n/** Create device cookie consent – POST /consent/v1/cookies/device-id */\nexport const useCreateDeviceCookieConsent = (\n options?: UseMutationOptions<\n CreateDeviceCookieConsentResponse,\n Error,\n CreateDeviceCookieConsentUpsertDTO\n >\n) => {\n const { consentApi } = useConsentService();\n const queryClient = useQueryClient();\n const service = consentService(consentApi);\n\n return useMutation<\n CreateDeviceCookieConsentResponse,\n Error,\n CreateDeviceCookieConsentUpsertDTO\n >({\n mutationFn: async (body: CreateDeviceCookieConsentUpsertDTO) => {\n const payload = {\n ...body,\n device_id: await sha256(body.device_id),\n };\n return service.createDeviceCookieConsent(payload);\n },\n onSuccess: (\n _data: CreateDeviceCookieConsentResponse,\n variables: CreateDeviceCookieConsentUpsertDTO\n ) => {\n queryClient.invalidateQueries({\n queryKey: consentQueryKeys.latestCookieByDeviceId(variables.device_id),\n });\n queryClient.invalidateQueries({ queryKey: consentQueryKeys.list() });\n },\n ...options,\n });\n};\n","import { AxiosInstance } from \"axios\";\nimport type {\n GetManyConsentParams,\n GetManyConsentResponse,\n GetConsentByIdParams,\n GetConsentByIdResponse,\n GetLatestConsentByUserIdParams,\n GetLatestConsentByUserIdResponse,\n GetLatestCookieConsentByDeviceIdParams,\n GetLatestCookieConsentByDeviceIdResponse,\n CreateUserConsentUpsertDTO,\n CreateUserConsentResponse,\n CreateDeviceCookieConsentUpsertDTO,\n CreateDeviceCookieConsentResponse,\n HealthResponse,\n} from \"../types\";\n\nconst baseUrl = \"\";\n\nexport const consentService = (axiosInstance: AxiosInstance) => {\n return {\n /**\n * Health check – GET /health\n */\n getHealth: async (): Promise<HealthResponse> => {\n const { data } = await axiosInstance.get<HealthResponse>(\"/health\");\n return data;\n },\n\n /**\n * Get all consent logs – GET /consent/v1/consent\n * @param params - Optional filter by policy type (ACCOUNT_REGISTER | COOKIE_PREFERENCE)\n */\n getManyConsents: async (\n params?: GetManyConsentParams\n ): Promise<GetManyConsentResponse> => {\n const { data } = await axiosInstance.get<GetManyConsentResponse>(\n `${baseUrl}/consent`,\n { params: params ? { type: params.type } : undefined }\n );\n return data;\n },\n\n /**\n * Get consent log by ID – GET /consent/v1/consent/{id}\n */\n getConsentById: async ({\n id,\n }: GetConsentByIdParams): Promise<GetConsentByIdResponse> => {\n const { data } = await axiosInstance.get<GetConsentByIdResponse>(\n `${baseUrl}/consent/${id}`\n );\n return data;\n },\n\n /**\n * Get latest consent for a user – GET /consent/v1/user-id?user_id=\n */\n getLatestConsentByUserId: async ({\n user_id,\n }: GetLatestConsentByUserIdParams): Promise<GetLatestConsentByUserIdResponse> => {\n const { data } = await axiosInstance.get<GetLatestConsentByUserIdResponse>(\n `${baseUrl}/user-id`,\n { params: { user_id } }\n );\n return data;\n },\n\n /**\n * Create user consent (account register) – POST /consent/v1/user-id\n * Consumer app must hash user_id/device_id (e.g. SHA-256) before passing.\n */\n createUserConsent: async (\n body: CreateUserConsentUpsertDTO\n ): Promise<CreateUserConsentResponse> => {\n const { data } = await axiosInstance.post<CreateUserConsentResponse>(\n `${baseUrl}/user-id`,\n body\n );\n return data;\n },\n\n /**\n * Get latest cookie consent for a device – GET /consent/v1/cookies/device-id?device_id=\n */\n getLatestCookieConsentByDeviceId: async ({\n device_id,\n }: GetLatestCookieConsentByDeviceIdParams): Promise<GetLatestCookieConsentByDeviceIdResponse> => {\n const { data } =\n await axiosInstance.get<GetLatestCookieConsentByDeviceIdResponse>(\n `${baseUrl}/cookies/device-id`,\n { params: { device_id } }\n );\n return data;\n },\n\n /**\n * Create device cookie consent – POST /consent/v1/cookies/device-id\n * Consumer app must hash device_id (e.g. SHA-256) before passing.\n */\n createDeviceCookieConsent: async (\n body: CreateDeviceCookieConsentUpsertDTO\n ): Promise<CreateDeviceCookieConsentResponse> => {\n const { data } =\n await axiosInstance.post<CreateDeviceCookieConsentResponse>(\n `${baseUrl}/cookies/device-id`,\n body\n );\n return data;\n },\n };\n};\n","/**\n * Hash user_id or device_id with SHA-256 for the two POST consent hooks\n * (createUserConsent, createDeviceCookieConsent).\n * Input: string, encoded as UTF-8 before hashing.\n * Output: lowercase hex string.\n * Uses Web Crypto when available; falls back to pure-JS SHA-256 for old devices.\n */\n\n/** Encode hash digest bytes as lowercase hex string. */\nfunction arrayBufferToHex(buffer: ArrayBuffer): string {\n return Array.from(new Uint8Array(buffer))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\")\n .toLowerCase();\n}\n\n/**\n * SHA-256 via Web Crypto (modern browsers, Node 19+).\n * Input encoded as UTF-8; output lowercase hex.\n */\nasync function sha256WebCrypto(value: string): Promise<string> {\n const utf8 = new TextEncoder().encode(value);\n const hashBuffer = await crypto.subtle.digest(\"SHA-256\", utf8);\n return arrayBufferToHex(hashBuffer);\n}\n\n/**\n * Pure-JS SHA-256 fallback for environments without crypto.subtle\n * (e.g. old browsers, insecure context, Node < 19).\n * Input encoded as UTF-8; output lowercase hex.\n */\nfunction sha256Fallback(value: string): string {\n const bytes = utf8Encode(value);\n const K = getK();\n const H = getH();\n const W = new Uint32Array(64);\n const numBlocks = bytes.length >> 6;\n\n for (let block = 0; block < numBlocks; block++) {\n const start = block << 6;\n for (let i = 0; i < 16; i++) {\n const o = start + (i << 2);\n W[i] =\n (bytes[o]! << 24) |\n (bytes[o + 1]! << 16) |\n (bytes[o + 2]! << 8) |\n bytes[o + 3]!;\n }\n for (let i = 16; i < 64; i++) {\n const s0 = rotr(W[i - 15]!, 7) ^ rotr(W[i - 15]!, 18) ^ (W[i - 15]! >>> 3);\n const s1 = rotr(W[i - 2]!, 17) ^ rotr(W[i - 2]!, 19) ^ (W[i - 2]! >>> 10);\n W[i] = (W[i - 16]! + s0 + W[i - 7]! + s1) >>> 0;\n }\n let a = H[0]!,\n b = H[1]!,\n c = H[2]!,\n d = H[3]!,\n e = H[4]!,\n f = H[5]!,\n g = H[6]!,\n h = H[7]!;\n for (let i = 0; i < 64; i++) {\n const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);\n const ch = (e & f) ^ (~e & g);\n const t1 = (h + S1 + ch + K[i]! + W[i]!) >>> 0;\n const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);\n const maj = (a & b) ^ (a & c) ^ (b & c);\n const t2 = (S0 + maj) >>> 0;\n h = g;\n g = f;\n f = e;\n e = (d + t1) >>> 0;\n d = c;\n c = b;\n b = a;\n a = (t1 + t2) >>> 0;\n }\n H[0] = (H[0]! + a) >>> 0;\n H[1] = (H[1]! + b) >>> 0;\n H[2] = (H[2]! + c) >>> 0;\n H[3] = (H[3]! + d) >>> 0;\n H[4] = (H[4]! + e) >>> 0;\n H[5] = (H[5]! + f) >>> 0;\n H[6] = (H[6]! + g) >>> 0;\n H[7] = (H[7]! + h) >>> 0;\n }\n\n let out = \"\";\n for (let i = 0; i < 8; i++) {\n const v = H[i]!;\n out +=\n (v >>> 28).toString(16) +\n ((v >>> 24) & 0xf).toString(16) +\n ((v >>> 20) & 0xf).toString(16) +\n ((v >>> 16) & 0xf).toString(16) +\n ((v >>> 12) & 0xf).toString(16) +\n ((v >>> 8) & 0xf).toString(16) +\n ((v >>> 4) & 0xf).toString(16) +\n (v & 0xf).toString(16);\n }\n return out.toLowerCase();\n}\n\nfunction rotr(n: number, b: number): number {\n return (n >>> b) | (n << (32 - b));\n}\n\n/** Encode string to UTF-8 bytes (with SHA-256 padding for block processing). */\nfunction utf8Encode(s: string): Uint8Array {\n const n = s.length;\n const bytes: number[] = [];\n for (let i = 0; i < n; i++) {\n let c = s.charCodeAt(i);\n if (c < 0x80) {\n bytes.push(c);\n } else if (c < 0x800) {\n bytes.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));\n } else if (c < 0xd800 || c >= 0xe000) {\n bytes.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));\n } else {\n c = 0x10000 + (((c & 0x3ff) << 10) | (s.charCodeAt(++i) & 0x3ff));\n bytes.push(\n 0xf0 | (c >> 18),\n 0x80 | ((c >> 12) & 0x3f),\n 0x80 | ((c >> 6) & 0x3f),\n 0x80 | (c & 0x3f)\n );\n }\n }\n const len = bytes.length;\n const pad = (64 - ((len + 9) % 64)) % 64;\n const total = len + 9 + pad;\n const out = new Uint8Array(total);\n out.set(bytes);\n out[len] = 0x80;\n const view = new DataView(out.buffer, out.byteOffset, out.byteLength);\n view.setUint32(total - 8, 0, false);\n view.setUint32(total - 4, (len * 8) >>> 0, false);\n return out;\n}\n\nfunction getK(): number[] {\n const k: number[] = [];\n const hex =\n \"428a2f98 71374491 b5c0fbcf e9b5dba5 3956c25b 59f111f1 923f82a4 ab1c5ed5 d807aa98 12835b01 243185be 550c7dc3 72be5d74 80deb1fe 9bdc06a7 c19bf174 e49b69c1 efbe4786 0fc19dc6 240ca1cc 2de92c6f 4a7484aa 5cb0a9dc 76f988da 983e5152 a831c66d b00327c8 bf597fc7 c6e00bf3 d5a79147 06ca6351 14292967 27b70a85 2e1b2138 4d2c6dfc 53380d13 650a7354 766a0abb 81c2c92e 92722c85 a2bfe8a1 a81a664b c24b8b70 c76c51a3 d192e819 d6990624 f40e3585 106aa070 19a4c116 1e376c08 2748774c 34b0bcb5 391c0cb3 4ed8aa4a 5b9cca4f 682e6ff3 748f82ee 78a5636f 84c87814 8cc70208 90befffa a4506ceb bef9a3f7 c67178f2\";\n hex.split(\" \").forEach((h) => k.push(parseInt(h, 16)));\n return k;\n}\n\nfunction getH(): number[] {\n return [\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c,\n 0x1f83d9ab, 0x5be0cd19,\n ];\n}\n\nfunction hasWebCrypto(): boolean {\n if (typeof crypto === \"undefined\" || !crypto.subtle) return false;\n return true;\n}\n\n/**\n * Hash a string with SHA-256.\n * Input: encoded as UTF-8. Output: lowercase hex string.\n * Use for user_id and device_id before calling createUserConsent / createDeviceCookieConsent.\n * Uses Web Crypto when available; falls back to pure-JS for old devices (no crypto.subtle).\n */\nexport async function sha256(value: string): Promise<string> {\n if (typeof value !== \"string\" || value.length === 0) {\n return value;\n }\n if (hasWebCrypto()) {\n return sha256WebCrypto(value);\n }\n return Promise.resolve(sha256Fallback(value));\n}\n","\"use client\";\n\nimport { QueryClient, QueryClientConfig, QueryClientProvider } from \"@tanstack/react-query\";\nimport axios, {\n AxiosInstance,\n AxiosRequestConfig,\n AxiosResponse,\n InternalAxiosRequestConfig,\n} from \"axios\";\nimport React, { createContext, useContext, useMemo } from \"react\";\n\nexport interface ConsentService {\n consentApi: AxiosInstance;\n queryClient: QueryClient;\n updateHeaders: (headers: Record<string, string>) => void;\n}\n\nconst ConsentServiceContext = createContext<ConsentService | undefined>(undefined);\n\ninterface RequestInterceptor {\n onFulfilled?: (\n config: InternalAxiosRequestConfig\n ) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>;\n onRejected?: (error: unknown) => unknown;\n}\n\ninterface ResponseInterceptor {\n onFulfilled?: (\n response: AxiosResponse\n ) => AxiosResponse | Promise<AxiosResponse>;\n onRejected?: (error: unknown) => unknown;\n}\n\nexport interface ConsentServiceProviderProps {\n children: React.ReactNode;\n baseURL?: string;\n axiosConfig?: AxiosRequestConfig;\n queryClient?: QueryClient;\n queryClientConfig?: Partial<QueryClientConfig>;\n requestInterceptors?: RequestInterceptor;\n responseInterceptors?: ResponseInterceptor;\n}\n\ninterface CreateConsentServiceParams {\n baseURL?: string;\n axiosConfig?: AxiosRequestConfig;\n requestInterceptors?: RequestInterceptor;\n responseInterceptors?: ResponseInterceptor;\n}\n\nexport const createConsentService = ({\n baseURL = \"\",\n axiosConfig = {},\n requestInterceptors = {},\n responseInterceptors = {},\n}: CreateConsentServiceParams) => {\n const instance = axios.create({\n baseURL,\n ...axiosConfig,\n });\n\n instance.interceptors.request.use(\n requestInterceptors.onFulfilled,\n requestInterceptors.onRejected\n );\n\n instance.interceptors.response.use(\n responseInterceptors.onFulfilled,\n responseInterceptors.onRejected\n );\n\n const updateHeaders = (headers: Record<string, string>) => {\n Object.entries(headers).forEach(([key, value]) => {\n instance.defaults.headers.common[key] = value;\n });\n };\n\n return {\n consentApi: instance,\n updateHeaders,\n };\n};\n\nexport const ConsentServiceProvider: React.FC<ConsentServiceProviderProps> = ({\n children,\n baseURL = \"\",\n axiosConfig = {},\n queryClient,\n queryClientConfig = {},\n requestInterceptors = {},\n responseInterceptors = {},\n}) => {\n const queryClientInstance = useMemo(\n () =>\n queryClient ||\n new QueryClient({\n defaultOptions: {\n queries: {\n refetchOnWindowFocus: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n ...queryClientConfig?.defaultOptions?.queries,\n },\n mutations: {\n ...queryClientConfig?.defaultOptions?.mutations,\n },\n },\n queryCache: queryClientConfig?.queryCache,\n mutationCache: queryClientConfig?.mutationCache,\n }),\n [queryClient]\n );\n\n const consentService = useMemo(() => {\n const service = createConsentService({\n baseURL,\n axiosConfig,\n requestInterceptors,\n responseInterceptors,\n });\n\n return {\n consentApi: service.consentApi,\n updateHeaders: service.updateHeaders,\n queryClient: queryClientInstance,\n };\n }, [baseURL, queryClientInstance, axiosConfig, requestInterceptors, responseInterceptors]);\n\n return (\n <ConsentServiceContext.Provider value={consentService}>\n <QueryClientProvider client={queryClientInstance}>\n {children}\n </QueryClientProvider>\n </ConsentServiceContext.Provider>\n );\n};\n\nexport const useConsentService = () => {\n const context = useContext(ConsentServiceContext);\n if (!context) {\n throw new Error(\"useConsentService must be used within a ConsentServiceProvider\");\n }\n return context;\n};\n","\"use client\";\n\nimport { useState } from \"react\";\nimport { useCreateUserConsent } from \"../hooks/useConsent\";\n\nconst POLICY_PLACEHOLDER = `\nTanta petere igitur et tam longe abesse non opus est. Quodsi haberent magnalia inter potentiam et divitias, et tamen ista philosophia et disciplina vivendi. Quam ob rem ut illi superiores, nos usque ad hanc aetatem. Sed ut iis bonis erudiamur, quae gignuntur ex tempore. Et tamen rerum necessitatibus saepe vincimur. Quam ob rem ut illi superiores, nos usque ad hanc aetatem.\n`.trim();\n\nconst REFUSAL_MESSAGE =\n \"Vì bạn không đồng ý với thỏa thuận này. Chúng tôi sẽ xóa tài khoản trong vòng x ngày\";\n\nexport interface PolicyPopupProps {\n open: boolean;\n onClose: () => void;\n userId: string;\n /** Called after user agrees and consent is created successfully. */\n onAgreeSuccess?: () => void;\n}\n\nexport function PolicyPopup({\n open,\n onClose,\n userId,\n onAgreeSuccess,\n}: PolicyPopupProps) {\n const [agreed, setAgreed] = useState(false);\n const [showRefusalAlert, setShowRefusalAlert] = useState(false);\n\n const createUserConsent = useCreateUserConsent({\n onSuccess: () => {\n onAgreeSuccess?.();\n handleClose();\n },\n });\n\n const handleClose = () => {\n setAgreed(false);\n setShowRefusalAlert(false);\n onClose();\n };\n\n const handleRefuse = () => {\n setShowRefusalAlert(true);\n };\n\n const handleRefusalAck = () => {\n setShowRefusalAlert(false);\n onClose();\n };\n\n const handleAgree = () => {\n if (!agreed) return;\n createUserConsent.mutate({\n user_id: userId,\n status: \"ACCEPTED\"\n });\n };\n\n if (!open) return null;\n\n return (\n <>\n {/* Policy modal */}\n <div\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label=\"Chính sách bảo mật\"\n style={{\n position: \"fixed\",\n inset: 0,\n zIndex: 60,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: \"rgba(0,0,0,0.5)\",\n padding: \"1rem\",\n }}\n onClick={(e) => e.target === e.currentTarget && handleClose()}\n >\n <div\n className=\"consent:bg-white consent:rounded-xl consent:border consent:border-gray-200 consent:shadow-lg consent:max-h-[90vh] consent:overflow-hidden consent:flex consent:flex-col\"\n style={{\n backgroundColor: \"#fff\",\n borderRadius: \"0.75rem\",\n border: \"1px solid #e5e7eb\",\n boxShadow: \"0 10px 15px -3px rgb(0 0 0 / 0.1)\",\n maxWidth: \"28rem\",\n width: \"100%\",\n maxHeight: \"90vh\",\n overflow: \"hidden\",\n display: \"flex\",\n flexDirection: \"column\",\n }}\n onClick={(e) => e.stopPropagation()}\n >\n <h2\n className=\"consent:text-lg consent:font-semibold consent:text-gray-900\"\n style={{\n fontSize: \"1.125rem\",\n fontWeight: 600,\n color: \"#2563eb\",\n padding: \"1rem 1.25rem\",\n borderBottom: \"1px solid #e5e7eb\",\n }}\n >\n Chính sách bảo mật\n </h2>\n <div\n style={{\n flex: 1,\n overflowY: \"auto\",\n padding: \"1rem 1.25rem\",\n fontSize: \"0.875rem\",\n color: \"#111827\",\n lineHeight: 1.6,\n }}\n >\n <p style={{ margin: 0, whiteSpace: \"pre-wrap\" }}>\n {POLICY_PLACEHOLDER}\n </p>\n </div>\n <div\n style={{\n padding: \"1rem 1.25rem\",\n borderTop: \"1px solid #e5e7eb\",\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"1rem\",\n }}\n >\n <label\n style={{\n display: \"flex\",\n alignItems: \"center\",\n gap: \"0.5rem\",\n fontSize: \"0.875rem\",\n color: \"#111827\",\n cursor: \"pointer\",\n }}\n >\n <input\n type=\"checkbox\"\n checked={agreed}\n onChange={(e) => setAgreed(e.target.checked)}\n style={{ width: \"1rem\", height: \"1rem\", accentColor: \"#111827\" }}\n aria-label=\"Tôi đồng ý với chính sách bảo mật trên\"\n />\n <span>Tôi đồng ý với chính sách bảo mật trên</span>\n </label>\n <div\n style={{\n display: \"flex\",\n gap: \"0.5rem\",\n flexWrap: \"wrap\",\n }}\n >\n <button\n type=\"button\"\n onClick={handleRefuse}\n disabled={createUserConsent.isPending}\n className=\"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:shadow-sm hover:consent:bg-gray-800 disabled:consent:opacity-50\"\n style={{\n flex: 1,\n minWidth: 0,\n borderRadius: \"0.5rem\",\n background: \"#111827\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: \"#fff\",\n border: \"none\",\n cursor: \"pointer\",\n }}\n >\n Bỏ qua\n </button>\n <button\n type=\"button\"\n onClick={handleAgree}\n disabled={!agreed || createUserConsent.isPending}\n className=\"consent:rounded-lg consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:shadow-sm disabled:consent:opacity-50 disabled:consent:cursor-not-allowed\"\n style={{\n flex: 1,\n minWidth: 0,\n borderRadius: \"0.5rem\",\n background: agreed ? \"#111827\" : \"#e5e7eb\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: agreed ? \"#fff\" : \"#9ca3af\",\n border: \"none\",\n cursor: agreed ? \"pointer\" : \"not-allowed\",\n }}\n >\n Tiếp tục\n </button>\n </div>\n {createUserConsent.isError && (\n <p\n className=\"consent:text-sm consent:text-red-600\"\n style={{ fontSize: \"0.875rem\", color: \"#dc2626\", margin: 0 }}\n >\n Đã xảy ra lỗi. Vui lòng thử lại.\n </p>\n )}\n </div>\n </div>\n </div>\n\n {/* Refusal alert modal */}\n {showRefusalAlert && (\n <div\n role=\"alertdialog\"\n aria-modal=\"true\"\n aria-label=\"Thông báo từ chối\"\n style={{\n position: \"fixed\",\n inset: 0,\n zIndex: 70,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n backgroundColor: \"rgba(0,0,0,0.5)\",\n padding: \"1rem\",\n }}\n onClick={(e) => e.target === e.currentTarget && handleRefusalAck()}\n >\n <div\n className=\"consent:bg-white consent:rounded-xl consent:border consent:border-gray-200 consent:shadow-lg\"\n style={{\n backgroundColor: \"#fff\",\n borderRadius: \"0.75rem\",\n border: \"1px solid #e5e7eb\",\n boxShadow: \"0 10px 15px -3px rgb(0 0 0 / 0.1)\",\n maxWidth: \"22rem\",\n width: \"100%\",\n padding: \"1.25rem\",\n }}\n onClick={(e) => e.stopPropagation()}\n >\n <p\n className=\"consent:text-sm consent:text-gray-700\"\n style={{\n fontSize: \"0.875rem\",\n color: \"#374151\",\n margin: \"0 0 1rem 0\",\n lineHeight: 1.5,\n }}\n >\n {REFUSAL_MESSAGE}\n </p>\n <button\n type=\"button\"\n onClick={handleRefusalAck}\n className=\"consent:rounded-lg consent:bg-gray-900 consent:px-4 consent:py-2 consent:text-sm consent:font-medium consent:text-white consent:w-full\"\n style={{\n borderRadius: \"0.5rem\",\n background: \"#111827\",\n padding: \"0.5rem 1rem\",\n fontSize: \"0.875rem\",\n fontWeight: 500,\n color: \"#fff\",\n border: \"none\",\n cursor: \"pointer\",\n width: \"100%\",\n }}\n >\n Tôi đã hiểu\n </button>\n </div>\n </div>\n )}\n </>\n );\n}\n"],"mappings":";ukBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,yBAAAE,EAAA,wBAAAC,EAAA,iBAAAC,EAAA,cAAAC,EAAA,4BAAAC,GAAA,gBAAAC,EAAA,qBAAAC,EAAA,mBAAAC,EAAA,+BAAAC,EAAA,cAAAC,GAAA,+BAAAC,EAAA,cAAAC,GAAA,WAAAC,EAAA,mBAAAC,GAAA,iCAAAC,EAAA,yBAAAC,EAAA,cAAAC,GAAA,6BAAAC,EAAA,qCAAAC,GAAA,oBAAAC,GAAA,uBAAAC,IAAA,eAAAC,GAAAvB,ICAO,IAAKwB,OACVA,EAAA,MAAQ,QACRA,EAAA,MAAQ,QAFEA,OAAA,IAaAC,OACVA,EAAA,OAAS,SACTA,EAAA,SAAW,WAFDA,OAAA,ICXZ,IAAAC,EAAmF,iBCAnF,IAAAC,EAAyB,iBCKlB,IAAMC,EAAsB,0BAc5B,SAASC,GAAUC,EAA6B,CACrD,GAAI,OAAO,SAAa,IAAa,OAAO,KAC5C,IAAMC,EAAQ,SAAS,OA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GAEJ,EACF,CAEJ,CAEO,SAASe,GAAqB,CACnC,IAAMC,KAAU,cAAW7B,EAAsB,EACjD,GAAI,CAAC6B,EACH,MAAM,IAAI,MAAM,kEAAkE,EAEpF,OAAOA,CACT","names":["index_exports","__export","COOKIE_CONSENT_NAME","CookieConsentBanner","EntityStatus","MediaType","PhygitalConsentProvider","PolicyPopup","consentQueryKeys","consentService","getConsentPreferenceCookie","getCookie","setConsentPreferenceCookie","setCookie","sha256","useConsentById","useCreateDeviceCookieConsent","useCreateUserConsent","useHealth","useLatestConsentByUserId","useLatestCookieConsentByDeviceId","useManyConsents","usePhygitalConsent","__toCommonJS","MediaType","EntityStatus","import_react","import_react","COOKIE_CONSENT_NAME","getCookie","name","match","setCookie","value","options","maxAge","path","sameSite","secure","cookie","getConsentPreferenceCookie","raw","COOKIE_CONSENT_NAME","parsed","setConsentPreferenceCookie","deviceId","selected_preferences","import_react_query","baseUrl","consentService","axiosInstance","data","params","id","user_id","body","device_id","arrayBufferToHex","buffer","b","sha256WebCrypto","value","utf8","hashBuffer","sha256Fallback","bytes","utf8Encode","K","getK","H","getH","W","numBlocks","block","start","i","o","s0","rotr","s1","a","c","d","e","f","g","h","S1","ch","t1","S0","maj","t2","out","v","n","s","len","pad","total","view","k","hasWebCrypto","sha256","import_react_query","import_axios","import_react","import_jsx_runtime","ConsentServiceContext","createConsentService","baseURL","axiosConfig","requestInterceptors","responseInterceptors","instance","axios","headers","key","value","ConsentServiceProvider","children","queryClient","queryClientConfig","queryClientInstance","consentService","service","useConsentService","context","consentQueryKeys","params","id","user_id","device_id","useHealth","options","consentApi","useConsentService","service","consentService","useManyConsents","useConsentById","useLatestConsentByUserId","sha256","useLatestCookieConsentByDeviceId","useCreateUserConsent","queryClient","body","payload","_data","variables","useCreateDeviceCookieConsent","import_jsx_runtime","PREFERENCES","PREFERENCE_CONFIG","CookieConsentBanner","onSubmitted","onDismiss","className","dismissed","setDismissed","showCustomModal","setShowCustomModal","expandedKey","setExpandedKey","preferences","setPreferences","deviceId","usePhygitalConsent","createConsent","useCreateDeviceCookieConsent","_data","variables","setConsentPreferenceCookie","getSelectedPreferences","key","togglePreference","prev","handleReject","handleAcceptAll","handleSaveCustom","selected","e","config","checked","isExpanded","import_react","import_jsx_runtime","POLICY_PLACEHOLDER","REFUSAL_MESSAGE","PolicyPopup","open","onClose","userId","onAgreeSuccess","agreed","setAgreed","showRefusalAlert","setShowRefusalAlert","createUserConsent","useCreateUserConsent","handleClose","handleRefuse","handleRefusalAck","handleAgree","e","import_jsx_runtime","PhygitalConsentContext","PhygitalConsentProvider","props","children","deviceId","showBannerWhenNoPreference","consentServiceProps","hasConsentPreference","setHasConsentPreference","pendingUserId","setPendingUserId","showPolicyPopup","setShowPolicyPopup","policyUserId","setPolicyUserId","latestConsent","isFetched","useLatestConsentByUserId","refreshConsentPreference","stored","getConsentPreferenceCookie","openPolicyPopup","userId","closePolicyPopup","value","ConsentServiceProvider","CookieConsentBanner","PolicyPopup","usePhygitalConsent","context"]}
package/dist/index.d.mts CHANGED
@@ -159,15 +159,27 @@ interface PhygitalConsentContextValue {
159
159
  hasConsentPreference: boolean;
160
160
  /** Re-read cookie and update hasConsentPreference. Call after storing preference (e.g. from CookieConsentBanner onSuccess). */
161
161
  refreshConsentPreference: () => void;
162
+ /**
163
+ * Open policy popup if user has no latest consent. Receives userId; calls useLatestConsentByUserId.
164
+ * If data exists, popup is not shown. If no data, policy popup is shown.
165
+ */
166
+ openPolicyPopup: (userId: string) => void;
162
167
  }
163
168
  interface PhygitalConsentProviderProps extends ConsentServiceProviderProps {
164
169
  deviceId: string;
165
170
  children: React.ReactNode;
171
+ /**
172
+ * When true (default), render CookieConsentBanner automatically when hasConsentPreference is false.
173
+ * Set to false if you want to render the banner yourself (e.g. in a layout) using usePhygitalConsent().
174
+ */
175
+ showBannerWhenNoPreference?: boolean;
166
176
  }
167
177
  /**
168
178
  * Main provider for consumer apps. Wraps ConsentServiceProvider and exposes
169
179
  * hasConsentPreference + refreshConsentPreference so the app can show/hide
170
180
  * the cookie banner based on whether the user has already chosen a preference.
181
+ * When showBannerWhenNoPreference is true (default), the consent banner is
182
+ * rendered automatically on app start when the user has no stored preference.
171
183
  */
172
184
  declare function PhygitalConsentProvider(props: PhygitalConsentProviderProps): react_jsx_runtime.JSX.Element;
173
185
  declare function usePhygitalConsent(): PhygitalConsentContextValue;
@@ -290,4 +302,13 @@ interface CookieConsentBannerProps {
290
302
  }
291
303
  declare function CookieConsentBanner({ onSubmitted, onDismiss, className, }: CookieConsentBannerProps): react_jsx_runtime.JSX.Element | null;
292
304
 
293
- export { COOKIE_CONSENT_NAME, type CommonModel, type ConsentLogDetailDTO, type ConsentPreferenceValue, type ConsentStatus, CookieConsentBanner, type CookieConsentBannerProps, type CreateDeviceCookieConsentResponse, type CreateDeviceCookieConsentUpsertDTO, type CreateUserConsentResponse, type CreateUserConsentUpsertDTO, type DateTimeNumber, EntityStatus, type GetConsentByIdParams, type GetConsentByIdResponse, type GetLatestConsentByUserIdParams, type GetLatestConsentByUserIdResponse, type GetLatestCookieConsentByDeviceIdParams, type GetLatestCookieConsentByDeviceIdResponse, type GetManyConsentParams, type GetManyConsentResponse, type GetManyResponse, type GetOneResponse, type HealthResponse, type Media, MediaType, type PaginationRequest, type PaginationResponse, type PhygitalConsentContextValue, PhygitalConsentProvider, type PhygitalConsentProviderProps, type PolicyDetailDTO, type PolicyDocument, type PolicyPreference, type PolicyStatus, type PolicyType, type SetCookieOptions, consentQueryKeys, consentService, getConsentPreferenceCookie, getCookie, setConsentPreferenceCookie, setCookie, sha256, useConsentById, useCreateDeviceCookieConsent, useCreateUserConsent, useHealth, useLatestConsentByUserId, useLatestCookieConsentByDeviceId, useManyConsents, usePhygitalConsent };
305
+ interface PolicyPopupProps {
306
+ open: boolean;
307
+ onClose: () => void;
308
+ userId: string;
309
+ /** Called after user agrees and consent is created successfully. */
310
+ onAgreeSuccess?: () => void;
311
+ }
312
+ declare function PolicyPopup({ open, onClose, userId, onAgreeSuccess, }: PolicyPopupProps): react_jsx_runtime.JSX.Element | null;
313
+
314
+ export { COOKIE_CONSENT_NAME, type CommonModel, type ConsentLogDetailDTO, type ConsentPreferenceValue, type ConsentStatus, CookieConsentBanner, type CookieConsentBannerProps, type CreateDeviceCookieConsentResponse, type CreateDeviceCookieConsentUpsertDTO, type CreateUserConsentResponse, type CreateUserConsentUpsertDTO, type DateTimeNumber, EntityStatus, type GetConsentByIdParams, type GetConsentByIdResponse, type GetLatestConsentByUserIdParams, type GetLatestConsentByUserIdResponse, type GetLatestCookieConsentByDeviceIdParams, type GetLatestCookieConsentByDeviceIdResponse, type GetManyConsentParams, type GetManyConsentResponse, type GetManyResponse, type GetOneResponse, type HealthResponse, type Media, MediaType, type PaginationRequest, type PaginationResponse, type PhygitalConsentContextValue, PhygitalConsentProvider, type PhygitalConsentProviderProps, type PolicyDetailDTO, type PolicyDocument, PolicyPopup, type PolicyPopupProps, type PolicyPreference, type PolicyStatus, type PolicyType, type SetCookieOptions, consentQueryKeys, consentService, getConsentPreferenceCookie, getCookie, setConsentPreferenceCookie, setCookie, sha256, useConsentById, useCreateDeviceCookieConsent, useCreateUserConsent, useHealth, useLatestConsentByUserId, useLatestCookieConsentByDeviceId, useManyConsents, usePhygitalConsent };