Initial team BPM workspace with managed connections, scanning and mail templates
This commit is contained in:
commit
34770ed338
101 files changed
+6499
No files matched your search
@@ -0,0 +1,32 @@
|
||||
// Regression/import entry point for offline captures. Never contacts BPM.
|
||||
const fs = require('node:fs/promises');
|
||||
const path = require('node:path');
|
||||
const { renderSnapshot } = require('../src/exporter.cjs');
|
||||
|
||||
async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
const value = flag => { const index=args.indexOf(flag); return index < 0 ? undefined : args[index+1]; };
|
||||
const input = value('--snapshot');
|
||||
if (!input) throw new Error('用法:node scripts/export-snapshot.cjs --snapshot <snapshot.json> [--assets <assets.json>] [--output <directory>]');
|
||||
const captured = JSON.parse(await fs.readFile(input,'utf8'));
|
||||
const snapshot = { ...captured, metadata: captured.metadata || { order:captured.order,project:captured.project,model:captured.model,serial:captured.serial }, images:[], warnings:[] };
|
||||
if (value('--assets')) {
|
||||
const assets = JSON.parse(await fs.readFile(value('--assets'),'utf8'));
|
||||
const external = [];
|
||||
for (const asset of assets.assets || []) {
|
||||
if (asset.kind === 'stylesheet') external.push(await fs.readFile(asset.path,'utf8'));
|
||||
if (asset.kind === 'image') {
|
||||
const bytes = await fs.readFile(asset.path);
|
||||
const data = `data:${asset.contentType || 'image/gif'};base64,${bytes.toString('base64')}`;
|
||||
snapshot.images.push({url:asset.url,data});
|
||||
const url = new URL(asset.url);
|
||||
snapshot.images.push({url:url.pathname+url.search,data});
|
||||
}
|
||||
}
|
||||
snapshot.styles = [...external,...(snapshot.styles || [])];
|
||||
}
|
||||
// Legacy capture used by the original probe already contains visible-value spans.
|
||||
const result = await renderSnapshot(snapshot,{outputDir:value('--output') && path.resolve(value('--output'))});
|
||||
console.log(JSON.stringify(result,null,2));
|
||||
}
|
||||
main().catch(error=>{console.error(error.message);process.exitCode=1;});
|
||||
@@ -0,0 +1,43 @@
|
||||
// Explicit, loopback-only demonstration space. Never opens BPM or sends messages.
|
||||
const crypto=require('node:crypto');
|
||||
const fs=require('node:fs');
|
||||
const os=require('node:os');
|
||||
const path=require('node:path');
|
||||
const {Store}=require('../src/dashboard-store.cjs');
|
||||
const {WorkspaceStore}=require('../src/workspace-store.cjs');
|
||||
const {createDashboard}=require('../src/dashboard.cjs');
|
||||
|
||||
async function startPreview({stateDir=path.join(process.env.LOCALAPPDATA || os.homedir(),'OrderNotificationAutomation','preview'),port=18776}={}) {
|
||||
fs.mkdirSync(stateDir,{recursive:true});
|
||||
const store=new Store(path.join(stateDir,'accounts'));
|
||||
if(!store.users().length) {
|
||||
store.bootstrap('preview',crypto.randomBytes(32).toString('hex'));
|
||||
store.addUser({username:'colleague',password:crypto.randomBytes(32).toString('hex'),role:'operator'},'演示初始化');
|
||||
}
|
||||
const admin=store.users().find(user=>user.role==='admin');
|
||||
if(!admin)throw Error('演示空间缺少管理员,请检查独立演示数据目录。');
|
||||
const workspace=new WorkspaceStore(path.join(stateDir,'workspace'));
|
||||
try {
|
||||
const snapshot=workspace.snapshot(store.users());
|
||||
if(!snapshot.exceptions.length) {
|
||||
for(const item of [
|
||||
{title:'演示:BPM 连接等待人工登录',component:'bpm',priority:'high',description:'这是虚构的续登待办,用于体验认领、转交和验证。没有检查或使用真实 BPM 登录态。',owner:''},
|
||||
{title:'演示:归档目录待确认',component:'archive',priority:'normal',description:'这是虚构的接入任务。可转交给演示同事,并查看责任流转记录。',owner:'colleague'},
|
||||
{title:'演示:PDF 排版等待核验',component:'pdf',priority:'normal',description:'这是虚构的人工核验任务。提交验证后填写核验依据即可体验关闭流程。',owner:admin.username}
|
||||
])workspace.createException(item,admin,store.users());
|
||||
}
|
||||
if(!snapshot.connections.length)workspace.createConnection({name:'演示 BPM 连接',owner:admin.username},admin,store.users());
|
||||
const server=createDashboard({store,workspace,outputDir:path.join(stateDir,'pdf'),previewUserId:admin.id});
|
||||
await new Promise((resolve,reject)=>{server.once('error',reject);server.listen(port,'127.0.0.1',resolve);});
|
||||
let closed=false;
|
||||
return {server,store,workspace,async close(){if(closed)return;closed=true;await new Promise(resolve=>server.close(resolve));workspace.close();}};
|
||||
} catch(error) { workspace.close();throw error; }
|
||||
}
|
||||
|
||||
if(require.main===module)startPreview().then(runtime=>{
|
||||
console.log(`订单通知中心演示空间:http://127.0.0.1:${runtime.server.address().port}\n页面点击“进入演示空间”,数据与正式空间独立。\n此服务仅监听本机,不访问 BPM,不发送通知。`);
|
||||
const stop=()=>runtime.close().then(()=>process.exit(0));
|
||||
process.once('SIGINT',stop);process.once('SIGTERM',stop);
|
||||
}).catch(error=>{console.error('预览启动失败:'+error.message);process.exitCode=1;});
|
||||
|
||||
module.exports={startPreview};
|
||||
Reference in new issue
Block a user