31 lines
12 KiB
JavaScript
31 lines
12 KiB
JavaScript
import {createKeyGeneratorDesign} from './cp-v2-key-generator.mjs';
|
|
import {showInvalidKey} from './cp-v2-key-validation.mjs';
|
|
import {createJarvisRegister} from './cp-v2-jarvis-register.mjs';
|
|
import {organisationTabs} from '../organisation-tabs.mjs';
|
|
const assets='https://www.dunerealms.com/assets/';
|
|
const make=(tag,text,className)=>{const node=document.createElement(tag);if(text!==undefined)node.textContent=text;if(className)node.className=className;return node;};
|
|
function image(name){const img=make('img');img.src=assets+name;img.alt='';img.loading='lazy';return img;}
|
|
function field(label,options){const wrapper=make('label',undefined,'codex-field');wrapper.append(make('span',label));let input;if(Array.isArray(options)){input=make('select');for(const option of options){const node=make('option',option);input.append(node);}}else{input=make(options==='message'?'textarea':'input');input.type='text';input.placeholder=options||'';}wrapper.append(input);return wrapper;}
|
|
function locked(label){const button=make('button',label);button.type='button';button.disabled=true;button.title='Design preview: service connection pending';return button;}
|
|
function table(headers,rows){const wrap=make('div',undefined,'codex-table-scroll'),table=make('table'),thead=make('thead'),head=make('tr'),body=make('tbody');for(const text of headers){const cell=make('th',text);cell.scope='col';head.append(cell);}thead.append(head);for(const cells of rows){const row=make('tr');for(const value of cells)row.append(make('td',value));body.append(row);}table.append(thead,body);wrap.append(table);return wrap;}
|
|
function empty(headers,copy){const wrapper=table(headers,[]),row=make('tr'),cell=make('td',copy);cell.colSpan=headers.length;row.append(cell);wrapper.querySelector('tbody').append(row);return wrapper;}
|
|
function box(title,copy){const node=make('article',undefined,'codex-management-box');node.append(make('h3',title));if(copy)node.append(make('p',copy));return node;}
|
|
export function mountCodexManagement(host,{initial='keys',fetcher=fetch}={}){
|
|
if(!document.querySelector('link[data-codex-management]')){const css=make('link');css.rel='stylesheet';css.href=new URL('./cp-v2-codex-management.css',import.meta.url).href;css.dataset.codexManagement='';document.head.append(css);}
|
|
const root=make('section',undefined,'codex-management'),hero=make('header',undefined,'codex-management-hero');hero.append(image('exchange-quests-v1.png'));const heading=make('div');heading.append(make('small','IMPERIAL BUREAU · MANAGEMENT'),make('h2','J.A.R.V.I.S.'),make('p','Issue, register and deliver the instruments of the realm.'));hero.append(heading);root.append(hero,make('p','Live registers are connected where available. Issuing, replacing, transferring and delivery controls are enabled only when their service supports the action.','codex-preview-notice'));
|
|
const disposers=[];let mounted=true;const groups=[];
|
|
function retained(content,label,path,name,args=[]){const node=make('details',undefined,'codex-retained-service'),summary=make('summary',label),host=make('div');let started=false;summary.onclick=()=>{if(started)return;started=true;import(path).then(module=>{if(mounted)disposers.push(module[name](host,...args));}).catch(()=>{if(mounted)host.textContent='Existing service unavailable. Reload to retry.';});};node.append(summary,host);content.append(node);}
|
|
|
|
const keys=make('div',undefined,'codex-management-grid'),matrix=make('article',undefined,'codex-management-box codex-instrument-artwork');matrix.style.gridColumn='1 / -1';matrix.style.padding='8px';const artwork=make('img');artwork.src='https://cp.dunerealms.com/assets/jarvis-keys-deeds-screen-v1.png';artwork.alt='J.A.R.V.I.S. catalogue artwork showing all key and deed types, their icons and purposes.';artwork.width=1536;artwork.height=1024;artwork.decoding='async';artwork.style.cssText='display:block;width:100%;height:auto;border-radius:8px';matrix.append(artwork);keys.append(matrix);const provenance=box('The mark of origin','Original keys carry an original seal. Authorised staff issues carry a staff seal.');for(const [title,copy] of [['Original seal','An original key may replace a staff-issued upgrade without granting duplicate rights.'],['Staff seal','Each issue records the issuer, reason and a server-signed issue proof.'],['Replacement','A replacement invalidates the unused predecessor and retains its original provenance.']]){const row=make('section',undefined,'codex-seal-note');row.append(make('strong',title),make('p',copy));provenance.append(row);}keys.append(provenance);groups.push({id:'keys',title:'Keys & deeds',content:keys});
|
|
const issuance=createKeyGeneratorDesign({fetcher});disposers.push(()=>issuance.dispose());const replace=box('Replace or revoke','Select an existing unused instance. No second entitlement is created.');replace.append(field('Instance ID','Unique J.A.R.V.I.S. instance'),field('Reason','Required audit reason'),locked('Replace key'),locked('Revoke unused key'));issuance.append(replace);groups.push({id:'issuance',title:'Issuance',content:issuance});
|
|
const definitions=box('Items & definitions','Definitions describe a type; every issued item receives its own unique instance ID.');definitions.append(field('Search definitions','Name, type or definition ID'),empty(['Artwork','Definition','Type','Quality','Revision','State'],'Definition service not connected.'),locked('Create definition'));retained(definitions,'Open existing item catalogue','./cp-v2-item-register.mjs','mountItemRegister');groups.push({id:'items',title:'Items & definitions',content:definitions});
|
|
const kits=box('Kits','Kit definitions, equipment and redeemable kit instances share the J.A.R.V.I.S. catalogue.');kits.append(empty(['Kit','Revision','Contents','Availability'],'Kit catalogue adapter pending.'),locked('Define kit'));retained(kits,'Open existing kit service','./cp-v2-kit-directorate.mjs','mountKitDirectorate',['server-kits']);groups.push({id:'kits',title:'Kits',content:kits});
|
|
const publication=box('Publication','Review versions and their distribution channels before publication.');publication.append(empty(['Definition','Revision','Approval','Channels','State'],'Publication queue is not connected.'),locked('Publish approved revision'));retained(publication,'Open existing publication service','./cp-v2-kit-directorate.mjs','mountKitDirectorate',['kit-publishing']);groups.push({id:'publication',title:'Publication',content:publication});
|
|
const delivery=box('Deliveries & claims','Track each delivery attempt against one instance. Retries retain the same delivery identity.');delivery.append(field('Delivery state',['All states','Queued','Processing','Delivered','Failed','Redeemed','Revoked']),empty(['Instance','Recipient','Method','State','Last attempt','Action'],'Delivery service not connected. No delivery totals are inferred.'),locked('Retry selected delivery'));groups.push({id:'delivery',title:'Delivery',content:delivery});
|
|
const listings=box('Listings & distribution','One exchange for goods and eligible J.A.R.V.I.S. instruments. Listings retain the record owner and instance reference.');listings.append(empty(['Listing','Type','Owner','Audience','State'],'Listing administration adapter pending.'),locked('Manage listing · service adapter pending'));retained(listings,'Open existing exchange controls','./cp-v2-exchange-authority.mjs','mountExchangeAuthority');groups.push({id:'listings',title:'Listings',content:listings});
|
|
const history=box('History','Issuance, replacements, transfers, redemption and delivery attempts are recorded without exposing private key material.');history.append(field('Search history','Instance, issuer, recipient or decision'),empty(['Time','Instrument','Action','Actor','Reason','Result'],'Audit service not connected.'));groups.push({id:'history',title:'History',content:history});
|
|
const seasons=box('Seasons & signing keys','Each season or isolated test run has its own signing-key version. Existing deeds and historical items retain their origin.');seasons.append(table(['Policy','Behaviour'],[['Origin','Season, Alpha/Beta/Live stage, release version and issue date stay attached to the instance.'],['Historical originals','Staff regeneration creates a new current-version instance; it never relabels the historical original.'],['Quality','Common, Uncommon, Rare, Very Rare and Legendary describe quality independently from edition age and actual scarcity.'],['Carry-over','Deeds persist. Unused older-season keys and rare items remain valid and transferable when their type permits.'],['Key rotation','New issues use the active signing key; historical signatures remain verifiable.'],['Test isolation','Test-run instances belong to their own namespace and cannot be redeemed in production.'],['Duplicate protection','Validate on use, redemption or transfer; atomic processing accepts an instance only once.']]),locked('Rotate active signing key'),locked('Create isolated test run'));groups.push({id:'seasons',title:'Seasons',content:seasons});
|
|
const validator=box('Check a key','Read-only inspection. Checking never activates or consumes a key.'),checkForm=make('form'),checkInput=make('input'),checkButton=make('button','Check key'),checkResult=make('div');checkInput.type='password';checkInput.autocomplete='off';checkInput.maxLength=300;checkInput.required=true;checkInput.setAttribute('aria-label','Private key to validate');checkButton.type='submit';checkForm.append(checkInput,checkButton);validator.classList.add('codex-header-validator');validator.append(checkForm);hero.append(validator);checkResult.className='codex-header-validation-result';checkResult.setAttribute('role','status');hero.after(checkResult);checkForm.onsubmit=async event=>{event.preventDefault();if(checkButton.disabled)return;checkButton.disabled=true;try{const r=await fetcher('/api/jarvis/validate',{method:'POST',credentials:'same-origin',headers:{'Content-Type':'application/json'},body:JSON.stringify({code:checkInput.value,staff:true})}),data=await r.json();if(!r.ok)throw Error(data.message||'Validation unavailable');if(data.state==='invalid')showInvalidKey(checkResult,'Key rejected. Dev support: '+(data.ticketNumber||data.caseId||'pending'));else checkResult.textContent=data.valid?'Recognised · '+data.state+' · no key consumed.':'This key type cannot be checked by the connected service.';}catch(e){checkResult.textContent=e.message;}finally{checkInput.value='';checkButton.disabled=false;}};
|
|
const states=box('Entity State Keys','Verified entity events. One ESK can support independent quests, contracts and deed actions; recording an event never grants a reward or changes ownership by itself.');const stateArt=image('esk-key-v1.png');stateArt.width=stateArt.height=64;stateArt.style.objectFit='contain';states.prepend(stateArt);groups.push({id:'states',title:'Entity state',content:states});
|
|
const registers=new Map();for(const [tab,section] of [['states','states'],['keys','keys'],['keys','deeds'],['listings','listings'],['history','history'],['delivery','delivery'],['seasons','seasons']]){const register=createJarvisRegister(section,{fetcher}),group=groups.find(g=>g.id===tab);if(['listings','history','delivery'].includes(tab))group.content.querySelector('.codex-table-scroll')?.remove();if(tab==='history')group.content.querySelector('.codex-field')?.remove();if(tab==='delivery'){const filter=group.content.querySelector('select');if(filter)filter.disabled=true;}const frame=box(section==='deeds'?'Office deeds':'Live '+section+' register');frame.classList.add('codex-register-frame');frame.append(register.root);group.content.append(frame);if(!registers.has(tab))registers.set(tab,[]);registers.get(tab).push(register);disposers.push(register.dispose);}const tabs=organisationTabs(groups,{label:'J.A.R.V.I.S. Management sections',initial});tabs.addEventListener('organisation-tab-change',event=>{for(const item of registers.get(event.detail.id)||[])item.load();});root.append(tabs);for(const item of registers.get(initial)||[])item.load();host.replaceChildren(root);return()=>{mounted=false;for(const dispose of disposers)if(typeof dispose==='function')dispose();root.remove();};
|
|
}
|

Staff