forked from unimatrix/web
40 lines
2.9 KiB
JavaScript
40 lines
2.9 KiB
JavaScript
// New recognition domain policy. Pure, side-effect-free decisions for API handlers.
|
|
// Payment verification and database transactions belong to the caller.
|
|
export const SHOP_SEALS=Object.freeze({
|
|
vip:'supporter-vip-v1',patron_caravan:'supporter-patron-caravan-v1',
|
|
patron_guild:'supporter-patron-guild-v1',patron_grand:'supporter-patron-grand-v1',
|
|
council_member:'supporter-council-member-v1'
|
|
});
|
|
export const MANUAL_SEALS=Object.freeze(new Set([
|
|
'alpha-tester','beta-tester','launch-contributor','dedicated-tester',
|
|
'season-tavren-ii','builder-award','dunegit-owner'
|
|
]));
|
|
export const NEVER_SHOWCASE=Object.freeze(new Set(['order-crysknife-v1','crysknife']));
|
|
export function sealForPurchasedTier(tier){return Object.hasOwn(SHOP_SEALS,tier)?SHOP_SEALS[tier]:null;}
|
|
export function purchaseSealDecision({tier,paymentStatus,verified,accountId,orderId}){
|
|
const seal=sealForPurchasedTier(tier);
|
|
if(!seal||paymentStatus!=='completed'||verified!==true||typeof accountId!=='string'||!accountId.trim()||typeof orderId!=='string'||!orderId.trim())return null;
|
|
return Object.freeze({accountId,seal,source:'purchase',sourceId:orderId,idempotencyKey:`purchase:${orderId}:${seal}`});
|
|
}
|
|
export function manualSealDecision({seal,actorAuthorized,targetId,actorId,action}){
|
|
if(!MANUAL_SEALS.has(seal)||actorAuthorized!==true||!['grant','revoke'].includes(action)||!targetId||!actorId||targetId===actorId)return null;
|
|
return Object.freeze({seal,targetId,actorId,action,source:'staff'});
|
|
}
|
|
export function isShowcaseSeal(key,{personal=false}={}){
|
|
return typeof key==='string'&&!personal&&!NEVER_SHOWCASE.has(key)&&!/^(owner-|personal-|network-staff-mr_|main-network-admin-|corestaff-)/i.test(key)&&!/crysknife|crissknife/i.test(key);
|
|
}
|
|
|
|
// Account identities must come from authenticated CP sessions and database rank lookups.
|
|
// Usernames supplied by clients are never sufficient proof of authority.
|
|
// Founder grant authority is separate from actual Crysknife membership.
|
|
export const CRYSKNIFE_FOUNDERS=Object.freeze(new Set(['unimatrix','unimatrix999','grmacken']));
|
|
// Historical recipients: confirm against persisted account rank assignments during migration.
|
|
export const CRYSKNIFE_LEGACY_RECIPIENTS=Object.freeze(new Set(['mr_blueray','patrick steward']));
|
|
export function crysknifeGrantDecision({actorId,actorUsername,actorRanks=[],recipientId,recipientUsername,recipientHasOrder=false}){
|
|
if(typeof actorId!=='string'||!actorId.trim()||typeof recipientId!=='string'||!recipientId.trim()||actorId===recipientId)return null;
|
|
if(typeof actorUsername!=='string'||typeof recipientUsername!=='string'||actorUsername.toLowerCase()===recipientUsername.toLowerCase())return null;
|
|
const founder=CRYSKNIFE_FOUNDERS.has(actorUsername.toLowerCase());
|
|
const holder=Array.isArray(actorRanks)&&actorRanks.includes('crysknife');
|
|
if(!founder&&!holder)return null;
|
|
return Object.freeze({actorId,recipientId,order:'crysknife',action:recipientHasOrder?'already-member':'grant',source:'order-recipient'});
|
|
}
|

Staff