feat: add verified offline recovery and retire legacy send assembly
This commit is contained in:
1 parent
84e2f0d9ba
commit
1148aa6f14
19 files changed
+235
-24
No files matched your search
@@ -23,6 +23,7 @@ class ScanDeliveries{
|
||||
return ready;
|
||||
}
|
||||
acknowledge(id){const at=new Date().toISOString();this.db.prepare("UPDATE execution_deliveries SET status='delivered',payload=NULL,next_at=0,updated_at=?,delivered_at=? WHERE run_id=?").run(at,at,id);}
|
||||
pendingSources(){return this.db.prepare("SELECT DISTINCT connection_id AS id FROM execution_deliveries WHERE status IN ('pending','error')").all().map(row=>row.id);}
|
||||
failed(id,nextAt){const at=new Date().toISOString();this.db.prepare("UPDATE execution_deliveries SET status='error',attempts=attempts+1,next_at=?,updated_at=?,failed_at=? WHERE run_id=? AND status!='delivered'").run(nextAt,at,at,id);}
|
||||
summary(connectionId){
|
||||
const pending=this.db.prepare("SELECT COUNT(*) AS n,MIN(next_at) AS due,SUM(CASE WHEN status='error' THEN 1 ELSE 0 END) AS errors FROM execution_deliveries WHERE connection_id=? AND status!='delivered'").get(connectionId),history=this.db.prepare('SELECT MAX(failed_at) AS failed,MAX(delivered_at) AS delivered FROM execution_deliveries WHERE connection_id=?').get(connectionId);
|
||||
|
||||
@@ -8,7 +8,7 @@ async function mailApi({mail,workspace,user,route,method,body,request,response,r
|
||||
const audit=(action,detail)=>workspace?.record(user,action,detail);
|
||||
if(route==='/api/mail/templates/categories'){
|
||||
if(method==='GET'){reply(200,{categories:require('../order-rules/catalog.cjs').seedRules().map(({id,name})=>({id,name})),bindings:store.categoryBindings()});return true;}
|
||||
if(method==='POST'){if(mail.historyOnly)fail('只读邮件空间不能修改类别关联。',409);const saved=store.bindCategory(body);audit('mail.category.bind',saved.categoryId);reply(200,saved);return true;}
|
||||
if(method==='POST')fail('旧类别模板关联已改为只读,请在分类通知规则选择模板。',410);
|
||||
}
|
||||
if(route==='/api/mail/channels'&&method==='POST'){
|
||||
if(!secureBpmTransport(request,trustedProxy))fail('请在部署机本地或 HTTPS 页面维护邮箱账号。',403);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
const fs=require('node:fs'),path=require('node:path'),{DatabaseSync}=require('node:sqlite'),{BpmVault}=require('../../platform/security/vault.cjs');
|
||||
// Legacy evidence is readable, but never recovered, scheduled, or mutated by the application.
|
||||
class NotificationHistory{
|
||||
constructor(dir){this.dir=dir;const file=path.join(dir,'notifications.sqlite');if(fs.existsSync(file))this.db=new DatabaseSync(file,{readOnly:true});}
|
||||
settings(){if(!this.db)return {enabled:false,historyOnly:true};const row=this.db.prepare('SELECT value FROM settings WHERE id=1').get();const {sourceKey,...settings}=row?JSON.parse(row.value):{};return {...settings,enabled:false,historyOnly:true};}
|
||||
decode(row){const {payload,...metadata}=row;this.vault||=new BpmVault({stateDir:path.join(this.dir,'secrets')});return {...this.vault.decode(row.id,payload),...metadata};}
|
||||
items(){return this.db?this.db.prepare('SELECT * FROM items ORDER BY rowid DESC LIMIT 100').all().map(row=>this.decode(row)):[];}
|
||||
batches(){return this.db?this.db.prepare("SELECT * FROM batches ORDER BY CASE status WHEN 'unknown' THEN 0 ELSE 1 END,rowid DESC LIMIT 100").all().map(row=>this.decode(row)):[];}
|
||||
close(){this.db?.close();this.db=null;this.vault?.destroy();this.vault=null;}
|
||||
}
|
||||
module.exports={NotificationHistory};
|
||||
@@ -69,9 +69,10 @@ class RuleStore{
|
||||
const processingEnabled=input.processingEnabled??old.processingEnabled;const processingSince=processingEnabled&&!old.processingEnabled?this.now():old.processingSince;
|
||||
this.put('settings',{...input,processingEnabled,processingSince,id:'main',version:old.version+1});this.audit(actor,'保存分类通知设置',input.enabled?'已启用':'已暂停');return this.settings();
|
||||
});}
|
||||
snapshot(){
|
||||
const rules=this.all('rules').map(record=>({...record.draft,status:record.published?.status||'draft',activationVersion:record.activationVersion||0,hasDraft:!record.published||record.draft.version!==record.published.version,publishedVersion:record.published?.version||null,trialVersion:record.trialVersion,mappingIssue:record.mappingIssue||null,explanation:describeRule(record.draft),validationIssues:publicationIssues(record.draft,this.adapters())}));
|
||||
return {rules,adapters:this.adapters(),orders:this.all('orders').reverse(),batches:this.all('batches').reverse(),settings:this.settings(),audit:this.all('audit').slice(-100).reverse(),capabilities:copy(this.capabilities),window:upcomingWindow(this.clock(),this.schedule(),this.calendar())};
|
||||
queryRevision(){return Number(this.db.prepare('SELECT total_changes() AS revision').get().revision);}
|
||||
snapshot({includeRecords=true}={}){
|
||||
const adapters=this.adapters(),rules=this.all('rules').map(record=>({...record.draft,status:record.published?.status||'draft',activationVersion:record.activationVersion||0,hasDraft:!record.published||record.draft.version!==record.published.version,publishedVersion:record.published?.version||null,trialVersion:record.trialVersion,mappingIssue:record.mappingIssue||null,explanation:describeRule(record.draft),validationIssues:publicationIssues(record.draft,adapters)}));
|
||||
return {rules,adapters,orders:includeRecords?this.all('orders').reverse():[],batches:includeRecords?this.all('batches').reverse():[],settings:this.settings(),audit:includeRecords?this.all('audit').slice(-100).reverse():[],capabilities:copy(this.capabilities),window:upcomingWindow(this.clock(),this.schedule(),this.calendar())};
|
||||
}
|
||||
saveRule(input,actor){return this.transaction(()=>{
|
||||
const record=this.get('rules',input?.id);if(!record)fail('规则不存在。',404);
|
||||
@@ -172,8 +173,8 @@ class RuleStore{
|
||||
this.put('orders',order);this.audit(actor,'应用当前规则重新识别',id+':'+input.note.trim());return order;
|
||||
});}
|
||||
discoveryBlockers(cutoff,allowed=()=>true){
|
||||
if(!this.executionSources)return [];
|
||||
const blockers=[];
|
||||
const blockers=(this.deliveryBlockers?.(allowed)||[]).map(id=>'连接 '+id+' 本地执行线索尚未交付。');
|
||||
if(!this.executionSources)return blockers;
|
||||
const pendingSources=new Set([...this.all('execution-discoveries'),...this.all('execution-discovery-runs')].filter(hint=>hint.status==='pending'&&allowed(hint.connectionId)).map(hint=>hint.connectionId));
|
||||
for(const id of pendingSources)blockers.push('连接 '+id+' 完整对账线索尚未处理。');
|
||||
if(this.activeDiscoveries>0)blockers.push('待办扫描尚未完成,不能冻结或发送不完整类别。');
|
||||
@@ -207,7 +208,7 @@ class RuleStore{
|
||||
recordIssue(id,input){
|
||||
const old=this.get('business-issues',id);
|
||||
const owners=this.issueOwners(input);
|
||||
const status=old?.status==='resolved'?'awaiting_verification':old?.status||'open';
|
||||
const status=['resolved','awaiting_verification'].includes(old?.status)?'open':old?.status||'open';
|
||||
return this.put('business-issues',{
|
||||
...old,...input,id,status,owners,
|
||||
ownerStatus:owners.length?'assigned':'unassigned',
|
||||
|
||||
Reference in new issue
Block a user