Merge pull request 'Imperial code desk: review and confirm redemption' (#354) from release/imperial-code-desk into main

This commit is contained in:
unimatrix 2026-11-16 19:33:24 +00:00
commit 4b00063d67
5 changed files with 93 additions and 14 deletions

View file

@ -0,0 +1,31 @@
# Imperial redemption desk
Shared presentation: `website/control-panel/public/cp-v2/cp-v2-code-redemption.mjs`.
The existing Codes page owns loading, identity and real redemption requests.
Two tabs: Your codes and Redeem a code. No separate kit receipts tab; stored kit
delivery/order data remains unchanged.
The desk recognises the format, explains the effect and requires fresh explicit
consent. Editing a code invalidates its preview and confirmation. Recognition
does not establish ownership. The existing service verifies it when submitted.
CLAN/COM/POL previews are disabled until their actual adapters are connected.
DRU routes to Imperial Tailor; DRK/DRQ retain their existing handlers.
Codes are not placed in URLs, browser storage or analytics.
Agreed implementation sequence:
1. Finish Basic clan pages and working behaviour.
2. Reuse/save that shared basis with the necessary Company and Politics adapters.
3. Add original/mother-house capability: create a Basic clan first, then consume
the account's single CLAN founding right to upgrade that same clan.
4. Add Royal House through an authorised political decision which issues a new
POL code using the shared generator. Redeeming it applies that appointment.
Preserve the clan UUID, members, emblem, claims and banking relationships during
upgrades. A founding key never itself confers a Royal title. Clan settings will
display status and link to the central desk rather than duplicate redemption.
Keep PR337 open. These future upgrades do not activate in the design batch.
Validation: existing receipt/redemption unit tests plus descriptor tests; local
browser preview at 1200, 760 and 390 pixels verifies artwork, no overflow,
explicit consent and disabled unfinished routes.

View file

@ -0,0 +1,30 @@
import {element as el} from './cp-v2-page-template.mjs';
// Presentation only. Recognising a format never verifies ownership or grants a right.
export function describeRedemption(value){
const code=String(value||'').trim().toUpperCase();
const types=[
[/^DRK-[A-Z2-7]{32}$/,'kit','Kit delivery','Requests your kit delivery. The game confirms arrival.','Redeem kit',true],
[/^DRQ-[A-F0-9]{40}$/,'discovery','Discovery reward','Claims your earned discovery reward. The service checks eligibility before crediting.','Claim reward',true],
[/^(?:DRU|UP)-[A-F0-9]{48}$/,'token','Upgrade Token','Apply this token to a saved kit in Imperial Tailor.','Open Imperial Tailor',false,'#realm/kits-exchange'],
[/^CLAN-[A-F0-9]{48}$/,'clan','Clan founding right','Upgrades your existing Basic clan to an Original House that can become a mother house. A Royal House requires a separate political appointment.','Clan upgrades coming soon',false],
[/^COM-[A-F0-9]{48}$/,'company','Company founding right','Upgrades your existing Basic company using its separate original founding right.','Company upgrades coming soon',false],
[/^POL-[A-F0-9]{48}$/,'politics','Political appointment','Applies the specific appointment recorded by a political decision. The decision determines the organisation and title.','Political appointments coming soon',false]
];
for(const [pattern,kind,title,description,action,available,href] of types)if(pattern.test(code))return {code,kind,title,description,action,available,href};
throw Error('Enter a complete private code. Community commands are used in game.');
}
export function createCodeRedemption(){
let reviewed=null,locked=false;
const root=el('section',undefined,'code-redemption'),hero=el('header',undefined,'reward-code-banner'),art=el('img');art.src='https://www.dunerealms.com/assets/imperial-seal-128.png';art.alt='';const heading=el('div');heading.append(el('small','THE IMPERIAL CODE OFFICE'),el('h4','Present your code. Open your next chapter.'),el('p','One counter for rewards, founding rights and political appointments.'));hero.append(art,heading);
const layout=el('div',undefined,'code-redemption-layout'),form=el('form',undefined,'code-redemption-card'),entry=el('fieldset'),legend=el('legend','1 · Enter your private code'),label=el('label','Code'),input=el('input');input.type='text';input.autocomplete='off';input.spellcheck=false;input.autocapitalize='characters';input.required=true;input.maxLength=80;input.placeholder='Paste your complete code';input.setAttribute('aria-describedby','redemption-code-help');const help=el('p','Keep your code private. Checking its format does not use it.','code-redemption-muted');help.id='redemption-code-help';label.append(input);const inspect=el('button','Review code');inspect.type='button';entry.append(legend,label,help,inspect);
const preview=el('fieldset',undefined,'code-redemption-preview');preview.hidden=true;preview.append(el('legend','2 · Review & confirm'));const badge=el('span',undefined,'reward-kind'),title=el('h5'),effect=el('p'),verification=el('p','Format recognised. Ownership and eligibility are checked when you submit.','code-redemption-muted'),check=el('input');check.type='checkbox';const consent=el('label',undefined,'code-redemption-consent');consent.append(check,el('span','I understand this action and want to use my code.'));const submit=el('button','Confirm redemption');submit.type='submit';submit.disabled=true;const destination=el('a');destination.hidden=true;preview.append(badge,title,effect,verification,consent,submit,destination);const result=el('p',undefined,'code-redemption-result');result.setAttribute('role','status');result.setAttribute('aria-live','polite');form.append(entry,preview,result);
const guide=el('aside',undefined,'code-redemption-card code-redemption-guide');guide.append(el('small','WHAT CAN YOU PRESENT?'),el('h5','Your code chooses the route.'));
for(const [kind,name,copy] of [['kit','Kits & discoveries','Existing DRK and DRQ codes can be redeemed here.'],['clan','House & company charters','Create your Basic clan first. CLAN and COM codes will unlock the later mother-house and company upgrades.'],['politics','Political appointments','POL codes come from an approved decision. Founding alone does not confer a Royal title.'],['token','Upgrade Tokens','DRU tokens are applied to a saved kit in Imperial Tailor.']]){const card=el('div',undefined,'code-redemption-guide-item');card.append(el('span',name,'reward-kind reward-kind-'+kind),el('p',copy));guide.append(card);}const register=el('a','← View your codes');register.href='#';register.onclick=e=>{e.preventDefault();root.dispatchEvent(new CustomEvent('show-code-register',{bubbles:true}));};guide.append(register);layout.append(form,guide);root.append(hero,layout);
function sync(){submit.disabled=locked||!reviewed?.available||!check.checked;inspect.disabled=locked;input.disabled=locked;check.disabled=locked;}
function invalidate(){reviewed=null;check.checked=false;preview.hidden=true;result.textContent='';sync();}
input.oninput=invalidate;check.onchange=sync;
inspect.onclick=()=>{if(locked)return;try{reviewed=describeRedemption(input.value);check.checked=false;badge.className='reward-kind reward-kind-'+reviewed.kind;badge.textContent=reviewed.available?'Ready to submit':'Dedicated route';title.textContent=reviewed.title;effect.textContent=reviewed.description;submit.textContent=reviewed.action;submit.hidden=!reviewed.available;consent.hidden=!reviewed.available;destination.hidden=!reviewed.href;if(reviewed.href){destination.href=reviewed.href;destination.textContent=reviewed.action;}verification.textContent=reviewed.available?'Format recognised. Ownership and eligibility are checked when you submit.':reviewed.href?'Continue in the dedicated workshop to choose your kit.':'This route is being connected. Your code has not been used.';preview.hidden=false;result.textContent='';sync();}catch(error){invalidate();result.textContent=error.message;input.focus();}};
return {root,form,input,check,submit,result,setLocked(value){locked=!!value;sync();},reset(){form.reset();invalidate();},reviewedCode(){if(!reviewed?.available||describeRedemption(input.value).code!==reviewed.code||!check.checked)throw Error('Review your code and confirm the action first.');return reviewed.code;}};
}

View file

@ -1,4 +1,5 @@
import {createCPV2Page,element as el} from './cp-v2-page-template.mjs';
import {createCodeRedemption} from './cp-v2-code-redemption.mjs';
import {createUserAPI} from './cp-v2-user-api.mjs';
import {kitReceiptStatus,groupKitReceipts} from '../kit-receipt-status.mjs';
@ -13,28 +14,25 @@ export function redemptionRequest(value,confirmed){
}
function table(target,head,rows){const wrap=el('div',undefined,'cp-v2-company-table-wrap'),t=el('table',undefined,'cp-v2-company-table'),thead=el('thead'),heading=el('tr'),tbody=el('tbody');for(const label of head){const th=el('th',label);th.scope='col';heading.append(th);}thead.append(heading);for(const values of rows){const tr=el('tr');for(const value of values){const td=el('td');if(typeof value==='object'&&value!==null)td.append(value);else td.textContent=String(value??'—');tr.append(td);}tbody.append(tr);}if(!rows.length){const tr=el('tr'),td=el('td','No records in this view.');td.colSpan=head.length;tr.append(td);tbody.append(tr);}t.append(thead,tbody);wrap.append(t);target.replaceChildren(wrap);}
export function mountRewards(host,{fetcher=fetch,initialTab}={}){
let active=true,busy=false,uncertain=false,orders=[],page=1;const controller=new AbortController(),{request}=createUserAPI(fetcher,controller.signal);
const codes=el('section'),receipts=el('section'),redemption=el('section',undefined,'cp-v2-personal-box'),community=el('section'),tokens=el('section'),codeTable=el('div'),receiptTable=el('div'),tools=el('div',undefined,'cp-v2-company-actions'),refresh=el('button','Refresh codes & receipts'),search=el('input'),nav=el('nav',undefined,'cp-v2-company-actions'),status=el('p','Opening your private rewards register…');status.setAttribute('role','status');refresh.type='button';search.type='search';search.placeholder='Search your kit receipts';search.setAttribute('aria-label','Search kit receipts');nav.setAttribute('aria-label','Kit receipt pages');tools.append(search,refresh);receipts.append(tools,receiptTable,nav);
const directory=el('section',undefined,'reward-code-directory'),filter=el('input'),typeFilter=el('select'),listing=el('div'),groups=new Map();filter.type='search';filter.placeholder='Search codes, rewards or references';filter.setAttribute('aria-label','Search your codes');typeFilter.setAttribute('aria-label','Filter code type');for(const [value,label] of [['all','All code types'],['kit','Kits'],['token','Upgrade Tokens'],['clan','Clan founding'],['company','Company founding'],['community','Community rewards']]){const option=el('option',label);option.value=value;typeFilter.append(option);}const controls=el('div',undefined,'reward-code-controls');controls.append(filter,typeFilter);const banner=el('header',undefined,'reward-code-banner'),crest=el('img');crest.src='https://www.dunerealms.com/assets/clans/vaerkring-v1.png';crest.alt='';const copy=el('div');copy.append(el('small','THE PRIVATE ENTITLEMENT REGISTER'),el('h4','Your codes. Your next chapter.'),el('p','Kits KIT-… · Upgrades UP-… · Clans CLAN-… · Companies COM-…'));banner.append(crest,copy);directory.append(banner,controls,listing);codes.append(status,directory);
let active=true,busy=false,uncertain=false,orders=[];const controller=new AbortController(),{request}=createUserAPI(fetcher,controller.signal);
const codes=el('section'),community=el('section'),tokens=el('section'),refresh=el('button','Refresh codes'),status=el('p','Opening your private rewards register…');status.setAttribute('role','status');refresh.type='button';codes.append(refresh);
const directory=el('section',undefined,'reward-code-directory'),filter=el('input'),typeFilter=el('select'),listing=el('div'),groups=new Map();filter.type='search';filter.placeholder='Search codes, rewards or references';filter.setAttribute('aria-label','Search your codes');typeFilter.setAttribute('aria-label','Filter code type');for(const [value,label] of [['all','All code types'],['kit','Kits'],['token','Upgrade Tokens'],['clan','Clan founding'],['company','Company founding'],['community','Community rewards']]){const option=el('option',label);option.value=value;typeFilter.append(option);}const controls=el('div',undefined,'reward-code-controls');controls.append(filter,typeFilter);const banner=el('header',undefined,'reward-code-banner'),crest=el('img');crest.src='https://www.dunerealms.com/assets/imperial-seal-128.png';crest.alt='';const copy=el('div');copy.append(el('small','THE PRIVATE ENTITLEMENT REGISTER'),el('h4','Your codes. Your next chapter.'),el('p','Kits KIT-… · Upgrades UP-… · Clans CLAN-… · Companies COM-…'));banner.append(crest,copy);directory.append(banner,controls,listing);codes.append(status,directory);
function paintCodes(){const q=filter.value.trim().toLowerCase(),rows=[];for(const [kind,group] of groups){if(typeFilter.value!=='all'&&typeFilter.value!==kind)continue;for(const row of group.rows){if(q&&!([group.title,...row.map(v=>typeof v==='object'?v.textContent:v)].join(' ').toLowerCase().includes(q)))continue;rows.push([el('span',group.title,'reward-kind reward-kind-'+kind),...row]);}}table(listing,['Type','Reward / entitlement','Reference / amount','Status','Private code / action'],rows);}
function setCodes(kind,title,rows){groups.set(kind,{title,rows:rows.length?rows:[[title+' register','—','No records','—']]});paintCodes();}
for(const [kind,title] of [['clan','Clan founding'],['company','Company founding']]){const action=el('button','Use founding code — coming soon');action.type='button';action.disabled=true;setCodes(kind,title,[[title+' code · '+(kind==='clan'?'CLAN-…':'COM-…'),'Once per account','Not issued — preview',action]]);}for(const [kind,title] of [['kit','Kit'],['token','Upgrade Token'],['community','Community reward']])setCodes(kind,title,[[title+' register','—','Loading…','—']]);filter.oninput=typeFilter.onchange=paintCodes;const tailor=el('a','Apply Upgrade Tokens in Imperial Tailor →');tailor.href='#realm/kits-exchange';directory.append(tailor);directory.append(el('p','Founding codes are coming soon. New formats: KIT-…, UP-…, CLAN-… and COM-…. Existing DRK/DRU codes remain valid.','reward-code-note'));
const form=el('form'),label=el('label','Private code'),input=el('input');input.type='text';input.autocomplete='off';input.spellcheck=false;input.required=true;input.maxLength=64;input.placeholder='DRK-… or DRQ-…';label.append(input);const check=el('input');check.type='checkbox';check.required=true;const consent=el('label',' I confirm redeeming this private code.');consent.prepend(check);const submit=el('button','Redeem code');submit.type='submit';const result=el('p');result.setAttribute('role','status');form.append(label,consent,submit,result);redemption.append(el('h4','Present your sealed entitlement'),el('p','Kit codes request delivery; the game confirms arrival. Discovery codes claim their earned reward. Upgrade Tokens are applied inside the kit workshop.'),form);
const {root,activate}=createCPV2Page({shellHost:host,title:'Codes & founding rights',description:'Kits, rewards and the planned clan and company founding codes in one private register.',artwork:'nav-manual-v2.webp',tabs:[{id:'unclaimed-codes',label:'All codes & rights',content:codes},{id:'receipts',label:'Kit receipts',content:receipts},{id:'redeem',label:'Redeem a code',content:redemption}]});host.replaceChildren(root);if(['unclaimed-codes','receipts','redeem'].includes(initialTab))activate(initialTab);
const desk=createCodeRedemption(),{form,input,check,result}=desk,redemption=desk.root;
const {root,activate}=createCPV2Page({shellHost:host,title:'Codes & founding rights',description:'Your private rewards, founding rights and political appointments.',artwork:'imperial-seal-128.png',tabs:[{id:'unclaimed-codes',label:'Your codes',content:codes},{id:'redeem',label:'Redeem a code',content:redemption}]});host.replaceChildren(root);redemption.addEventListener('show-code-register',()=>activate('unclaimed-codes'));if(initialTab==='redeem')activate(initialTab);
function codeCell(code,command=false){const details=el('details');details.append(el('summary',command?'Show private command':'Show private code'),el('code',code));const copy=el('button','Copy');copy.type='button';copy.onclick=async()=>{try{await navigator.clipboard.writeText(code);if(active)copy.textContent='Copied';}catch{if(active)copy.textContent='Select and copy the code above';}};details.append(copy);return details;}
function render(){setCodes('kit','Kit',privateKitCodes(orders).map(row=>[row.name,row.orderId,kitReceiptStatus(row).label,codeCell(row.code)]));
const q=search.value.trim().toLowerCase(),rows=orders.filter(row=>[row.name,row.orderId,row.side,row.status].join(' ').toLowerCase().includes(q)).sort((a,b)=>Date.parse(b.createdAt||0)-Date.parse(a.createdAt||0)),pages=Math.max(1,Math.ceil(rows.length/15));page=Math.min(page,pages);
table(receiptTable,['Reference','Item','Side','Date','Dunemarks','Delivery'],rows.slice((page-1)*15,page*15).map(row=>[row.orderId,row.name,['buyer','buy','purchase'].includes(row.side)?'Purchase':'Sale',row.createdAt?new Date(row.createdAt).toLocaleString():'—',Number.isSafeInteger(row.grossDunemarks)?row.grossDunemarks+' DM':'—',kitReceiptStatus(row).label]));nav.replaceChildren();const previous=el('button','← Previous'),next=el('button','Next →');previous.type=next.type='button';previous.disabled=page<=1;next.disabled=page>=pages;previous.onclick=()=>{page--;render();};next.onclick=()=>{page++;render();};nav.append(previous,el('span','Page '+page+' of '+pages),next);
}
async function load(){if(busy)return;busy=true;refresh.disabled=submit.disabled=true;status.textContent='Loading current private entitlements…';
function render(){setCodes('kit','Kit',privateKitCodes(orders).map(row=>[row.name,row.orderId,kitReceiptStatus(row).label,codeCell(row.code)]));}
async function load(){if(busy)return;busy=true;refresh.disabled=true;desk.setLocked(true);status.textContent='Loading current private entitlements…';
try{const session=await request('/api/auth/session');if(!session.authenticated)throw Error('Sign in to open your private rewards.');if(session.user?.username?.toLowerCase()==='dev')throw Error('The Dev service exemption does not receive player rewards.');
const data=await Promise.allSettled([request('/api/kits/orders'),request('/api/community/rewards'),request('/api/kits/upgrade-tokens')]);if(!active)return;
if(data[0].status==='fulfilled'){orders=data[0].value.orders;groupKitReceipts(orders);render();uncertain=false;}else{orders=[];setCodes('kit','Kit',[['Kit register','—',data[0].reason.message,'—']]);receiptTable.replaceChildren(el('p',data[0].reason.message));}
if(data[0].status==='fulfilled'){orders=data[0].value.orders;groupKitReceipts(orders);render();uncertain=false;}else{orders=[];setCodes('kit','Kit',[['Kit register','—',data[0].reason.message,'—']]);}
community.replaceChildren();if(data[1].status==='fulfilled'){const d=data[1].value;if(!Array.isArray(d.available)||!Array.isArray(d.history))setCodes('community','Community reward',[['Community register','—','Community reward records could not be confirmed.','—']]);else{setCodes('community','Community reward',[...d.available,...d.history].map(row=>[row.month==='season-tavren-ii'?'Tavren II Aedrecht':row.month,row.reward_amount+' DM',row.delivered_at?'Delivered':row.delivery_ready===false?'Delivery not available':'Available',row.personal_code&&row.delivery_ready!==false&&/^[a-z0-9-]{8,128}$/i.test(row.personal_code)?codeCell('/communitycode '+row.personal_code,true):'—']));if(!d.linked)community.append(el('p','Link your Minecraft identity to see earned community rewards.'));}}else setCodes('community','Community reward',[['Community register','—',data[1].reason.message,'—']]);
tokens.replaceChildren();if(data[2].status==='fulfilled'&&Array.isArray(data[2].value.tokens)){setCodes('token','Upgrade Token',data[2].value.tokens.map(row=>['Upgrade Token',new Date(row.createdAt).toLocaleString(),row.usedAt?'Used':'Available',!row.usedAt&&/^DRU-[A-F0-9]{48}$/.test(row.code||'')?codeCell(row.code):'—']));const workshop=el('a','Apply tokens in Imperial Tailor →');workshop.href='#realm/kits-exchange';tokens.append(workshop);}else setCodes('token','Upgrade Token',[['Token register','—',data[2].reason?.message||'Upgrade Token records could not be confirmed.','—']]);
status.textContent=data.every(row=>row.status==='fulfilled')?'Your private reward records are loaded.':'Some reward services are unavailable. Other records remain visible.';
}catch(error){if(active){status.textContent=error.message;groups.clear();paintCodes();orders=[];codeTable.replaceChildren();receiptTable.replaceChildren();community.replaceChildren();tokens.replaceChildren();uncertain=true;}}finally{busy=false;if(active){refresh.disabled=false;submit.disabled=uncertain;}}
}catch(error){if(active){status.textContent=error.message;groups.clear();paintCodes();orders=[];community.replaceChildren();tokens.replaceChildren();uncertain=true;}}finally{busy=false;if(active){refresh.disabled=false;desk.setLocked(uncertain);}}
}
form.onsubmit=async event=>{event.preventDefault();if(busy||uncertain)return;let payload;try{payload=redemptionRequest(input.value,check.checked);}catch(error){result.textContent=error.message;return;}busy=true;refresh.disabled=submit.disabled=true;result.textContent='Presenting your code…';try{const d=await request(payload.path,payload.body);if(!active)return;if(payload.kind==='discovery'&&(d.ok!==true||typeof d.credited!=='boolean'||d.amount!==1000))throw Object.assign(Error('Discovery credit was not confirmed.'),{uncertain:true});if(payload.kind==='kit'&&!['queued','delivered','pending','claimed','redeemed','pending_delivery'].includes(d.status))throw Object.assign(Error('The delivery result was not confirmed.'),{uncertain:true});form.reset();busy=false;await load();if(active)result.textContent=payload.kind==='kit'?(d.status==='delivered'?'Delivery is already confirmed by the game.':'Delivery requested. Join a planetary server with four empty inventory slots; the game confirms arrival.'):(d.credited?'Your earned 1,000 DM reward was credited.':'This reward was already redeemed; no duplicate credit was made.');}catch(error){if(active){uncertain=!!error.uncertain;result.textContent=error.message+(uncertain?' Refresh your receipts and check the result before retrying.':'');}}finally{busy=false;if(active){refresh.disabled=false;submit.disabled=uncertain;}}};
search.oninput=()=>{page=1;render();};refresh.onclick=()=>void load();void load();return()=>{active=false;controller.abort();input.value='';orders=[];root.remove();};
form.onsubmit=async event=>{event.preventDefault();if(busy||uncertain)return;let payload;try{payload=redemptionRequest(desk.reviewedCode(),check.checked);}catch(error){result.textContent=error.message;return;}busy=true;refresh.disabled=true;desk.setLocked(true);result.textContent='Presenting your code…';try{const d=await request(payload.path,payload.body);if(!active)return;if(payload.kind==='discovery'&&(d.ok!==true||typeof d.credited!=='boolean'||d.amount!==1000))throw Object.assign(Error('Discovery credit was not confirmed.'),{uncertain:true});if(payload.kind==='kit'&&!['queued','delivered','pending','claimed','redeemed','pending_delivery'].includes(d.status))throw Object.assign(Error('The delivery result was not confirmed.'),{uncertain:true});desk.reset();busy=false;await load();if(active)result.textContent=payload.kind==='kit'?(d.status==='delivered'?'Delivery is already confirmed by the game.':'Delivery requested. Join a planetary server with four empty inventory slots; the game confirms arrival.'):(d.credited?'Your earned 1,000 DM reward was credited.':'This reward was already redeemed; no duplicate credit was made.');}catch(error){if(active){uncertain=!!error.uncertain;result.textContent=error.message+(uncertain?' Refresh your codes and check the result before retrying.':'');}}finally{busy=false;if(active){refresh.disabled=false;desk.setLocked(uncertain);}}};
refresh.onclick=()=>void load();void load();return()=>{active=false;controller.abort();input.value='';orders=[];root.remove();};
}

View file

@ -250,3 +250,6 @@
.mb-nav-item>.dune-new-overlay{position:absolute!important;top:auto!important;left:auto!important;bottom:2px!important;right:2px!important;transform:none!important;padding:2px 4px!important;border:1px solid #ba5b555c!important;border-radius:3px!important;background:linear-gradient(135deg,#361b19ed,#211311eb)!important;color:#ffaaa3!important;font:700 7px/1 Arial,sans-serif!important;text-shadow:none!important;letter-spacing:.06em}.mb-nav-item>.dune-new-overlay:before{content:'✦';margin-right:2px}.mb-nav-item>.dune-update-overlay{color:#b1d3e5!important;border-color:#739db75c!important;background:linear-gradient(135deg,#192c38ed,#101c27eb)!important}.mb-nav-item>.dune-update-overlay:before{content:'↻'}.mb-portal>.dune-new-overlay{position:absolute!important;top:5px!important;right:5px!important;bottom:auto!important;left:auto!important;transform:none!important;background:#bba05c!important;color:#10251f!important;border:1px solid #c7a65c;border-radius:12px;padding:3px 7px;font:700 9px/1.2 Arial,sans-serif!important;text-shadow:none!important}.mb-portal>.dune-update-overlay{background:#1b4d43!important;color:#bfe4d3!important;border-color:#6ba58e}
.reward-code-controls{display:flex;gap:12px;flex-wrap:wrap}.reward-code-controls input{flex:1;min-width:190px;padding:13px}.reward-code-controls select{padding:13px}.reward-code-banner{display:flex;align-items:center;gap:24px;padding:24px;border:1px solid #b59a58;border-radius:14px;background:linear-gradient(100deg,#102d27f5,#102d27b0),url('https://www.dunerealms.com/assets/political-imperial-chamber-v1.png') center/cover}.reward-code-banner img{width:86px;height:86px;object-fit:contain}.reward-code-banner h4{font-size:25px;margin:8px 0;color:#efd28b}.reward-code-banner small{letter-spacing:.15em;color:#ccb16f}.reward-code-banner p,.reward-code-note{color:#c2d0c7;line-height:1.6}.reward-kind{display:inline-block;border:1px solid currentColor;border-radius:20px;padding:5px 10px;white-space:nowrap;font-size:12px}.reward-kind-kit{color:#8fceb5}.reward-kind-token{color:#c9b3ef}.reward-kind-clan{color:#edbf76}.reward-kind-company{color:#8dcad9}.reward-kind-community{color:#c1d895}.reward-code-directory table td{vertical-align:middle}.reward-code-directory button:disabled{opacity:.6;cursor:not-allowed}@media(max-width:600px){.reward-code-banner{padding:16px;gap:14px}.reward-code-banner img{width:58px;height:58px}.reward-code-banner h4{font-size:20px}}
.clan-bank-tabs{display:grid!important;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px;padding:16px!important;margin:0 0 22px!important;border:1px solid #b49a55;border-radius:13px;background:linear-gradient(120deg,#1c3e31,#102b24)}.clan-bank-tabs button{display:flex;align-items:center;justify-content:center;min-height:52px;padding:12px 16px;margin:0;border:1px solid #728367;border-radius:9px;background:#143127;color:#e7d5a4;font:600 14px Georgia,serif;cursor:pointer;transition:background .15s,border-color .15s}.clan-bank-tabs button:hover{background:#294b39;border-color:#d5b86a}.clan-bank-tabs button[aria-pressed=true]{background:linear-gradient(#c8ac62,#9b8040);border-color:#f1d185;color:#12271c;box-shadow:inset 0 0 0 2px #f0d99422}.clan-bank-tabs button:focus-visible{outline:2px solid #f3d58b;outline-offset:3px}@media(max-width:720px){.clan-bank-tabs{grid-template-columns:repeat(2,minmax(0,1fr));padding:12px!important;gap:10px}}
.code-redemption{display:grid;gap:24px;min-width:0}.code-redemption-layout{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(240px,1fr);gap:24px;align-items:start}.code-redemption-card{min-width:0;padding:26px;border:1px solid #9e8b53;border-radius:16px;background:linear-gradient(135deg,#193c31f5,#102820f5)}.code-redemption fieldset{min-width:0;margin:0;padding:0;border:0}.code-redemption legend{font-size:20px;font-weight:700;color:#efd28b;margin-bottom:20px}.code-redemption label{display:grid;gap:10px}.code-redemption input[type=text]{box-sizing:border-box;width:100%;min-width:0;padding:16px;font-family:monospace;font-size:16px;letter-spacing:.04em;border:1px solid #b59a58;border-radius:8px;background:#0c241e;color:#f5e5bb}.code-redemption input:focus-visible,.code-redemption button:focus-visible,.code-redemption a:focus-visible{outline:2px solid #f0cc74;outline-offset:4px}.code-redemption p{line-height:1.65;overflow-wrap:anywhere}.code-redemption h5{font-size:23px;line-height:1.3;color:#efd28b;margin:16px 0}.code-redemption-muted{color:#bdcfc2;font-size:14px}.code-redemption .code-redemption-preview{margin-top:28px;padding-top:24px;border-top:1px solid #776b42}.code-redemption .code-redemption-consent{display:flex;align-items:flex-start;gap:12px;margin:24px 0}.code-redemption-consent input{flex:0 0 auto;margin-top:5px}.code-redemption button{min-height:44px;padding:12px 20px;border:1px solid #d8ba6d;border-radius:8px;background:linear-gradient(#c5a653,#9d813e);color:#10271f;font-weight:700;cursor:pointer}.code-redemption button:disabled{opacity:.5;cursor:not-allowed}.code-redemption-guide>small{letter-spacing:.12em;color:#d7bb76}.code-redemption-guide-item{padding:18px 0;border-bottom:1px solid #6a684249}.code-redemption-guide-item:last-of-type{margin-bottom:20px}.code-redemption-guide-item p{margin-bottom:0;font-size:14px}.code-redemption-result:empty{display:none}.code-redemption-result{padding:14px;border-left:3px solid #d7bb76;background:#0c241e}.reward-kind-politics{color:#dcb9e7}.code-redemption [hidden]{display:none!important}@media(max-width:850px){.code-redemption-layout{grid-template-columns:minmax(0,1fr)}.code-redemption-card{padding:20px}}@media(max-width:450px){.code-redemption-card{padding:16px}.code-redemption .reward-code-banner{align-items:flex-start}.code-redemption input[type=text]{font-size:16px;padding:12px}.code-redemption button{width:100%}}
.code-redemption a{color:#efd28b;text-underline-offset:3px}

View file

@ -0,0 +1,17 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {describeRedemption} from '../control-panel/public/cp-v2/cp-v2-code-redemption.mjs';
test('existing deliverable codes describe their real route',()=>{
assert.equal(describeRedemption(' drk-'+ 'a'.repeat(32)+' ').kind,'kit');
assert.equal(describeRedemption('DRQ-'+ 'A'.repeat(40)).available,true);
assert.equal(describeRedemption('DRU-'+ 'A'.repeat(48)).href,'#realm/kits-exchange');
});
test('founding and political previews do not claim working redemption or royal status',()=>{
for(const prefix of ['CLAN','COM','POL'])assert.equal(describeRedemption(prefix+'-'+ 'A'.repeat(48)).available,false);
assert.match(describeRedemption('CLAN-'+ 'A'.repeat(48)).description,/separate political appointment/);
assert.match(describeRedemption('POL-'+ 'A'.repeat(48)).description,/recorded by a political decision/);
});
test('partial, malformed and unsupported codes cannot advance to confirmation',()=>{
for(const code of ['', 'CLAN-123', 'DRK-'+ '0'.repeat(32), '/communitycode test','<script>','POL-'+ 'A'.repeat(47)])assert.throws(()=>describeRedemption(code));
});