// @requirements REQ-PRODUCT-PROCESSING-CHOICES REQ-PRODUCT-PRIVACY-SIGNALS REQ-PRODUCT-CF-ADMIN const $=id=>document.getElementById(id),node=(tag,text)=>{const el=document.createElement(tag);if(text!==undefined)el.textContent=text;return el;}; async function post(path,input={}){const response=await fetch(path,{method:'POST',credentials:'same-origin',cache:'no-store',headers:{'Content-Type':'application/json','X-Notabenda-Request':'1'},body:JSON.stringify(input)});if(!response.ok)throw Error();return response.json();} async function refresh(){ try{const response=await fetch('/backoffice/data',{cache:'no-store'});if(!response.ok)throw Error();const data=await response.json();$('workspace-state').textContent=data.boundary;$('jobs').replaceChildren();$('deliveries').replaceChildren(); for(const job of data.jobs){const card=node('article');card.className='record';const header=node('header');header.append(node('h3',job.channel+' · '+job.state),node('span',job.attempts+' admitted attempt'+(job.attempts===1?'':'s')));card.append(header,node('p',job.reason??'Waiting for dispatch'),node('code',job.deliveryId));if(!['delivered','suppressed'].includes(job.state)){const button=node('button',job.attempts?'Recheck and retry':'Check and dispatch');button.type='button';button.addEventListener('click',async()=>{button.disabled=true;try{await post('/backoffice/dispatch',{deliveryId:job.deliveryId});await refresh();}catch{$('workspace-state').textContent='Dispatch could not be confirmed. Refresh before trying again.';button.disabled=false;}});card.append(node('p'),button);} $('jobs').append(card);} if(!data.jobs.length)$('jobs').append(node('p','No covered jobs are stored.')); for(const event of data.deliveries){const card=node('article');card.className='record';card.append(node('h3',event.serviceId+' · '+event.channel),node('p',event.attempts+' received attempt'+(event.attempts===1?'':'s')+' · one committed payload'),node('code',event.deliveryId));$('deliveries').append(card);}if(!data.deliveries.length)$('deliveries').append(node('p','The sink has received no sample calls.')); }catch{$('workspace-state').textContent='Observations unavailable. This does not establish that no delivery occurred.';} } $('register').addEventListener('click',async()=>{try{const value=await post('/backoffice/register');$('register-result').textContent=value.created?'Notice registered. Existing restrictions remain.':'This exact notice is already registered.';}catch{$('register-result').textContent='Registration could not be confirmed.';}});$('refresh').addEventListener('click',()=>void refresh());void refresh();