Refine error hint for unbound corps in replay-test

This commit is contained in:
gitea committed 2026-09-12 23:01:06 +08:00
1 parent 35720fa36a
commit 35a3374d27
2 files changed
+4 -2

No files matched your search

+2 -1
View File
@@ -330,7 +330,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
`;if(I.outputFile){IG1(I.outputFile,z),console.log(JSON.stringify({outputFile:I.outputFile,bytes:Buffer.byteLength(z,"utf-8")},null,2));return}console.log(z.trimEnd())}function YG1($,I={}){if(I.allowFull||I.outputFile)return;let z=Buffer.byteLength(JSON.stringify($),"utf-8");if(z>UG1)throw new XD(`Output is large (${z} bytes). Use --summary, --fields, --count, or --output-file; pass --full only when you really need the full response.`)}function pZ0($,I){if(I)return;let z=$&&typeof $==="object"?$:{},q=typeof z.count==="number"?z.count:void 0,U=Array.isArray(z.rules)?z.rules.length:void 0,Y=Buffer.byteLength(JSON.stringify($),"utf-8"),J=q??U??0;if(J>zG1||Y>qG1)throw new XD(`Rule list is large (${J} rules, ${Y} bytes). Use "seal-use rules list --summary" or "seal-use rules count"; pass --full only when you really need full descriptions.`,"seal-use rules list --summary")}function W0($){return{allowFull:D0($.full)===!0,outputFile:j($.outputFile)??j($["output-file"])}}function cZ0($=[]){console.log(bZ0($))}function O1($){let I=q$(),z=Y4();return v7(I,{stateful:z.stateful,defaultCorpId:z.defaultCorpId,corpId:$},o5())}function MI($=Y4()){return{mode:$.stateful?"stateful":"stateless",stateful:$.stateful,...$.stateful&&$.defaultCorpId?{defaultCorpId:$.defaultCorpId}:{},...$.testEnterprisesDir?{testEnterprisesDir:$.testEnterprisesDir}:{},lint:$.lint,configFile:WI()}}async function O0($,I,z,q,U={}){E0(await AI($,I,z,q),U)}async function AI($,I,z,q){let U=vw.find((Q)=>Q.name===$);if(!U)throw Error(`Unknown Seal tool: ${$}`);let Y=Object.fromEntries(Object.entries(q).filter(([,Q])=>Q!==void 0)),J=U.handler;return J(I,Y,{corp:z})}import{existsSync as dZ0}from"node:fs";async function mZ0($,I){if(!dZ0($))throw Error(`File not found: ${$}`);let z=FI($);console.log(JSON.stringify(await DI(z.fileBuffer,z.fileName,I),null,2))}async function oD($,I,z,q,U){if($==="ready"||$==="status"){let Y=I??j(U.options.file)??j(U.options.input),J=await fD(z,q,{filePath:Y,webhook:j(U.options.webhook)??j(U.options.selector)});if(console.error(`[webhook-ready] 企业环境: ${J.corp.name} (${J.corp.id}) [${J.stateMode}]`),J.corp.tenant?.name)console.error(`[webhook-ready] 租户信息: ${J.corp.tenant.name} (${J.corp.tenant.id})`);console.error(`[webhook-ready] 凭证状态: ${J.authStatus==="ok"?"OK":`异常 (${J.authError})`}`),console.error(`[webhook-ready] Webhook 通道: ${J.activeWebhooks.length} 个可用`);for(let Q of J.activeWebhooks){let w=Q.isDefault?" [默认通道]":"";console.error(` - ${Q.name} (${Q.id}) mode=${Q.mode}${w}`)}if(J.materialPack)console.error(`[webhook-ready] 材料包预检: ${J.materialPack.valid?`通过 (${J.materialPack.documentCount} 单)`:`失败 (${J.materialPack.errors?.join("; ")})`}`);if(J.ready)console.error(`\uD83D\uDFE2 ${J.statusMessage}`),console.error(`\uD83D\uDC49 Next action: ${J.nextAction}`);else console.error(`\uD83D\uDD34 准备阶段未通过: ${J.statusMessage}`),console.error(`\uD83D\uDC49 Next action: ${J.nextAction}`);console.log(JSON.stringify(J,null,2));return}if($==="replay"){let Y=I??j(U.options.recordId)??j(U.options["record-id"])??j(U.options.id),J=j(U.options.recordIds)??j(U.options["record-ids"]),Q=J?J.split(",").map((b)=>b.trim()).filter(Boolean):void 0,w=j(U.options.sn)??j(U.options.documentSn)??j(U.options["document-sn"]),K=j(U.options.sns)??j(U.options["document-sns"]),H=K?K.split(",").map((b)=>b.trim()).filter(Boolean):void 0,G=k0(U.options.limit),W=j(U.options.status),V=j(U.options.startDate)??j(U.options["start-date"]),X=j(U.options.endDate)??j(U.options["end-date"]);if(!Y&&!Q&&!w&&!H&&G===void 0)throw Error("Usage: seal-use webhook replay <recordId> [--sn <documentSN>] [--limit <n>] [--status <status>] [--webhook <idOrName>] [--source-corp <corpId>] [--target-corp <corpId>] [--dry-run]");let L=j(U.options.sourceCorp)??j(U.options["source-corp"])??j(U.options.prodCorp)??j(U.options["prod-corp"]),D=j(U.options.targetCorp)??j(U.options["target-corp"])??j(U.options.testCorp)??j(U.options["test-corp"]),F=D0(U.options.force)===!0,{sourceCorp:T,targetCorp:P}=DD({sourceCorpId:L,targetCorpId:D,activeCorp:q,force:F},O1),M=T.id===q.id?z:await G1(T),B=P.id===q.id?z:await G1(P),u=j(U.options.webhook)??j(U.options.selector),C=j(U.options.snSuffix)??j(U.options["sn-suffix"]),x=j(U.options.snPrefix)??j(U.options["sn-prefix"]),v=j(U.options.docIdSuffix)??j(U.options["doc-id-suffix"]),p=j(U.options.docIdPrefix)??j(U.options["doc-id-prefix"]),i=D0(U.options.dryRun)??D0(U.options["dry-run"]),f=await RU({query:{recordId:Y,recordIds:Q,sn:w,sns:H,limit:G,status:W,startDate:V,endDate:X},sourceClient:M,targetClient:B,sourceCorp:T,targetCorp:P,webhookSelector:u,snPrefix:x,snSuffix:C,docIdPrefix:p,docIdSuffix:v,dryRun:i});if(i){console.error(`[webhook-replay] 预览模式:已成功从 ${T.name} 提取单据并转换为 Webhook Payload(未实际推送)。`),console.log(JSON.stringify(f,null,2));return}if(f.success)if(f.totalCount===1&&f.replayedDocument)console.error(`\uD83D\uDFE2 成功重放Line truncated
or: seal-use corps bind-test <testCorpId> --corp <prodCorpId> [--confirm] [--force]`);let Y=O1(q),J=O1(U);if(Y.id===J.id)throw X4(`Cannot bind enterprise '${Y.id}' to itself.`);if(Y.prodCorpId&&Y.prodCorpId!==J.id)throw X4(`Cannot use '${Y.id}' as a production enterprise because it is already registered as a test enterprise for '${Y.prodCorpId}'. Multi-tier chaining is not permitted.`);if(J.testCorpId&&J.testCorpId!==Y.id)throw X4(`Cannot bind '${J.id}' as a test enterprise because it already has a bound test enterprise '${J.testCorpId}'. Multi-tier chaining is not permitted.`);let Q=D0(z.options.force)===!0;if(Y.testCorpId&&Y.testCorpId!==J.id||J.prodCorpId&&J.prodCorpId!==Y.id){if(!Q)throw $5(`Enterprise binding conflict: production enterprise '${Y.id}' is bound to '${Y.testCorpId??"none"}', and test enterprise '${J.id}' is bound to '${J.prodCorpId??"none"}'. Overwriting an existing binding requires --force and --confirm.`,`seal-use corps bind-test ${Y.id} ${J.id} --confirm --force`)}if(!(D0(z.options.confirm)===!0||D0(z.options.yes)===!0)){let G=Q?" --force":"";throw $5(`Refusing to bind test enterprise '${J.name}' (${J.id}) to production enterprise '${Y.name}' (${Y.id}) without --confirm. Enterprise binding establishes 1-to-1 sync pairing and marks '${J.id}' as a test environment.`,`seal-use corps bind-test ${Y.id} ${J.id} --confirm${G}`)}if(Y.testCorpId&&Y.testCorpId!==J.id)try{j7(Y.testCorpId,{prodCorpId:void 0})}catch{}if(J.prodCorpId&&J.prodCorpId!==Y.id)try{j7(J.prodCorpId,{testCorpId:void 0})}catch{}let K=j7(Y.id,{environment:"production",testCorpId:J.id}),H=j7(J.id,{environment:"test",prodCorpId:Y.id});E0({success:!0,productionEnterprise:{id:K.id,name:K.name,environment:K.environment,testCorpId:K.testCorpId},testEnterprise:{id:H.id,name:H.name,environment:H.environment,prodCorpId:H.prodCorpId}});return}if($==="unbind-test"){let q=I??j(z.options.corp),U=O1(q);if(!U.testCorpId&&!U.prodCorpId){E0({unbound:!1,message:`Enterprise '${U.name}' (${U.id}) does not have an active test enterprise binding.`});return}let Y=U.testCorpId?U.id:U.prodCorpId,J=U.testCorpId?U.testCorpId:U.id;if(!(D0(z.options.confirm)===!0||D0(z.options.yes)===!0))throw $5(`Refusing to unbind production enterprise '${Y}' and test enterprise '${J}' without --confirm.`,`seal-use corps unbind-test ${U.id} --confirm`);j7(Y,{testCorpId:void 0});try{j7(J,{prodCorpId:void 0})}catch{}E0({success:!0,unboundProduction:Y,unboundTest:J});return}if($==="sync-test"){let q=I??j(z.options.corp),U=O1(q);if(!U.testCorpId)throw X4(`Production enterprise '${U.name}' (${U.id}) has no bound test enterprise.
Run 'seal-use corps bind-test ${U.id} <testCorpId> --confirm' first to establish a verified 1-to-1 association.`);let Y=O1(U.testCorpId);if(Y.environment!=="test")throw Error(`Target enterprise '${Y.name}' (${Y.id}) is marked as '${Y.environment}', NOT 'test'. Aborting sync to protect non-test environments.`);let J=await G1(U),Q=await G1(Y),[w,K,H,G,W,V,X,L]=await Promise.all([P1(J,U.seal.endpoints.approvalStylePreferences).catch(()=>({})),P1(Q,Y.seal.endpoints.approvalStylePreferences).catch(()=>({})),C6(J),C6(Q),S$(J).catch(()=>[]),S$(Q).catch(()=>[]),j9(J,{limit:100}).catch(()=>({articles:[]})),j9(Q,{limit:100}).catch(()=>({articles:[]}))]),D=(X.articles||[]).filter((Y0)=>!Y0.isDeleted),F=(L.articles||[]).filter((Y0)=>!Y0.isDeleted),T=new Map(F.map((Y0)=>[Y0.title.trim(),Y0])),P=[],M=[],B=new Set(D.map((Y0)=>Y0.title.trim()));for(let Y0 of D){let v0=Y0.title.trim(),q1=T.get(v0);if(!q1)P.push(Y0);else{let N1=q1.content!==Y0.content,b4=(q1.purpose??"")!==(Y0.purpose??""),n6=q1.enabled!==Y0.enabled,E$=q1.contentType!==Y0.contentType,b6=(q1.status??"")!==(Y0.status??""),T6=JSON.stringify([...q1.scenarios??[]].sort())!==JSON.stringify([...Y0.scenarios??[]].sort()),B$=JSON.stringify([...q1.tags??[]].sort())!==JSON.stringify([...Y0.tags??[]].sort());if(N1||b4||n6||E$||b6||T6||B$)M.push({testId:q1.id,prodDoc:Y0,reasons:[...N1?["content"]:[],...b4?["purpose"]:[],...n6?["enabled"]:[],...E$?["contentType"]:[],...b6?["status"]:[],...T6?["scenarios"]:[],...B$?["tags"]:[]]})}}let u=F.filter((Y0)=>!B.has(Y0.title.trim())),x=[...W].sort((Y0,v0)=>v0.versionNumber-Y0.versionNumber)[0],v=x?.versionNumber,i=([...V].sort((Y0,v0)=>v0.versionNumber-Y0.versionNumber)[0]?.versionNumber??0)+1,S=HL0(U.name,v,V),b=j(z.options["version-name"])??j(z.options.versionName)??GL0(U.name,v,S,i),z0={...K,tone:w.tone,language:w.language,detailLevel:w.detailLevel,outputFormat:w.outputFormat,examples:w.examples??[],prohibitedPhrases:w.prohibitedPhrases??[],customInstructions:w.customInstructions,decisionPreferences:w.decisionPreferences,thinkingDepthPreference:w.thinkingDepthPreference};if(D0(z.options["dry-run"])===!0||D0(z.options.dryRun)===!0){E0({dryRun:!0,source:{id:U.id,name:U.name,environment:U.environment,latestPublishedVersion:x?{versionNumber:x.versionNumber,versionName:x.versionName}:null,documentsCount:D.length},target:{id:Y.id,name:Y.name,environment:Y.environment},versionMappingPlan:{sourceProdVersionNumber:v??null,sourceProdVersionName:x?.versionName??null,targetTestExpectedVersionNumber:i,targetTestPublishVersionName:b,iteration:S},preferencesDiff:{decisionPreferences:{before:K.decisionPreferences,after:w.decisionPreferences},thinkingDepthPreference:{before:K.thinkingDepthPreference,after:w.thinkingDepthPreference}},rulesPlan:{sourceDraftRuleCount:H.rules.length,targetExistingDraftRuleCount:G.rules.length,toDeleteCount:G.rules.length,toCreateCount:H.rules.length,rulesToSync:H.rules.map((Y0,v0)=>({index:v0+1,sourceRuleId:Y0.id,sourceRuleCode:Y0.code??v0+1,expectedTargetCode:`rule-${v0+1}`,description:Y0.description,scope:Y0.scope,strictness:Y0.strictness}))},documentsPlan:{sourceDocumentCount:D.length,targetExistingDocumentCount:F.length,toCreateCount:P.length,toCreate:P.map((Y0)=>({title:Y0.title,purpose:Y0.purpose,contentType:Y0.contentType,scenarios:Y0.scenarios})),toUpdateCount:M.length,toUpdate:M.map((Y0)=>({targetDocumentId:Y0.testId,title:Y0.prodDoc.title,reasons:Y0.reasons})),toDeleteCount:u.length,toDelete:u.map((Y0)=>({targetDocumentId:Y0.id,title:Y0.title}))},publishingPlan:{targetCorpId:Y.id,publishVersionName:b,publishTarget:"test"},hosecloudSyncPlan:(()=>{if(U.source.type!=="hose")return{sourceType:U.source.type,skipped:!0,reason:"prod source is not hose; no hosecloud credentials available"};let Y0=(w.integrations??[]).filter((N1)=>N1.type==="hosecloud"),v0=new Set,q1=Y0.filter((N1)=>{let b4=N1.corporationId??U.id;if(v0.has(b4))return!1;return v0.add(b4),!0});return{sourceType:"hose",outboundName:DL0(U.name),targetMode:"assisted",integrationsCount:q1.length,integrations:q1.map((N1)=>({corporationId:N1.corporationId,apiOrigin:N1.apiOrigin,customApiUrl:N1.customApiUrl}))}})(),productionGuarantees:{prodRulesStayDraft:!0,prodVersionPublished:!1}});return}if(!(D0(z.options.yes)===!0||D0(z.options.confirm)===!0))throw $5(`Refusing to overwrite test enterprise '${Y.name}' (${Y.id}) with preferences, ${H.rules.length} draft rules, and ${D.length} knowledge documents from production enterprise '${U.name}' (${U.id}) without --yes. This will replace test draft rules, synchronize knowledge documents, and publish a new version on the test enterprise.`,`seal-use corps sync-test ${U.id} --yes`);await j8(Q,z0,Y.seal.endpoints.approvalStylePreferences);let c=[];for(let Y0 of u)await HW(Q,Y0.id),c.push({id:Y0.id,title:Y0.title});let r=[];for(let Y0 of M)await KW(Q,Y0.testId,{title:Y0.prodDoc.title,purpose:Y0.prodDoc.purpose,content:Y0.prodDoc.content,contentType:Y0.prodDoc.contentType,status:Y0.prodDoc.status,enabled:Y0.prodDoc.ena Line truncated
Run 'seal-use corps bind-test ${U.id} <testCorpId> --confirm' first to establish a verified 1-to-1 association.`);let Y=O1(U.testCorpId);if(Y.environment!=="test")throw Error(`Target enterprise '${Y.name}' (${Y.id}) is marked as '${Y.environment}', NOT 'test'. Aborting replay to protect non-test environments.`);let J=j(z.options.recordId)??j(z.options["record-id"])??j(z.options.id),Q=j(z.options.recordIds)??j(z.options["record-ids"]),w=Q?Q.split(",").map((p)=>p.trim()).filter(Boolean):void 0,K=j(z.options.sn)??j(z.options.documentSn)??j(z.options["document-sn"]),H=j(z.options.sns)??j(z.options["document-sns"]),G=H?H.split(",").map((p)=>p.trim()).filter(Boolean):void 0,W=k0(z.options.limit)??(!J&&!w&&!K&&!G?1:void 0),V=j(z.options.status),X=j(z.options.startDate)??j(z.options["start-date"]),L=j(z.options.endDate)??j(z.options["end-date"]),D=await G1(U),F=await G1(Y),T=j(z.options.webhook)??j(z.options.selector),P=j(z.options.snSuffix)??j(z.options["sn-suffix"]),M=j(z.options.snPrefix)??j(z.options["sn-prefix"]),B=j(z.options.docIdSuffix)??j(z.options["doc-id-suffix"]),u=j(z.options.docIdPrefix)??j(z.options["doc-id-prefix"]),C=D0(z.options.dryRun)??D0(z.options["dry-run"]),x={recordId:J,recordIds:w,sn:K,sns:G,limit:W,status:V,startDate:X,endDate:L};console.error(`[corps-replay-test] 正式企业「${U.name}」(${U.id}) -> 测试企业「${Y.name}」(${Y.id})`);let v=await RU({query:x,sourceClient:D,targetClient:F,sourceCorp:U,targetCorp:Y,webhookSelector:T,snPrefix:M,snSuffix:P,docIdPrefix:u,docIdSuffix:B,dryRun:C});if(C){console.error(`[corps-replay-test] 预览模式:已成功从 ${U.name} 提取单据并转换为 Webhook Payload(未实际推送)。`),console.log(JSON.stringify(v,null,2));return}if(v.success)if(v.totalCount===1&&v.replayedDocument)console.error(`\uD83D\uDFE2 成功重放单据「${v.replayedDocument.documentSN}」至 ${Y.name} (${v.targetWebhook?.name??"Webhook 通道"})`);else console.error(`\uD83D\uDFE2 成功重放 ${v.successCount} 条单据(来自「${U.name}」)至「${Y.name}」(${v.targetWebhook?.name??"Webhook 通道"})`);else console.error(`\uD83D\uDD34 单据重放部分或全部失败(成功 ${v.successCount} 条,失败 ${v.failureCount} 条)至「${Y.name}」`);if(console.error(`\uD83D\uDC49 Next action: seal-use approval-runs list --corp ${Y.id} --limit ${v.totalCount}`),console.log(JSON.stringify(v,null,2)),!v.success)process.exitCode=1;return}if($==="switch"){let q=I;if(!q)throw Error("Usage: seal-use corps switch <corpId>");let U=Y4();if(!U.stateful)throw Error("Cannot switch the default enterprise while stateless mode is enabled. Use `seal-use config mode stateful` first.");let Y=O1(q);VI({...U,stateful:!0,defaultCorpId:Y.id}),E0({current:!0,id:Y.id,name:Y.name});return}if($==="probe-hose"){await fG1(J$(z.json));return}if($==="hose-staffs"){await nG1(J$(z.json));return}if($==="add-hose"){await bG1(J$(z.json));return}if($==="add-seal"){await iG1(J$(z.json));return}if($==="add-link"){let q=I??j(z.options.link)??j(z.options.url);if(!q)throw Error("Usage: seal-use corps add-link <https://.../web/thirdparty.html?...> [--name <customName>] [--overwrite]");await pG1(q,j(z.options.name),D0(z.options.overwrite)===!0);return}throw Error(`Unknown corps command: ${$??""}. Run 'seal-use help' for available commands.`)}function DL0($){return[...$].slice(0,6).join("")+"(Seal测)"}async function kG1($,I,z,q){if($.source.type!=="hose")return{skipped:!0,reason:"prod source is not hose; no hosecloud credentials available"};let U=($.source.appKey??$.source.key)?.trim(),Y=($.source.appSecurity??$.source.password)?.trim();if(!U||!Y)return{skipped:!0,reason:"prod hose source missing appKey/appSecurity (or key/password)"};let[J,Q]=await Promise.all([P1(z,$.seal.endpoints.approvalStylePreferences).catch(()=>({})),P1(q,I.seal.endpoints.approvalStylePreferences).catch(()=>({}))]),w=(J.integrations??[]).filter((T)=>T.type==="hosecloud");if(w.length===0)return{skipped:!0,reason:"prod Seal enterprise has no hosecloud integrations configured"};let K=new Set,H=[];for(let T of w){let P=T.corporationId??$.id;if(!K.has(P))K.add(P),H.push(T)}let G=Q.integrations??[],W=new Map(G.filter((T)=>T.type==="hosecloud").map((T)=>[T.corporationId,T])),V=DL0($.name),X=[],L=H.map((T)=>{let P=W.get(T.corporationId),M=P?.signKey??yG1(6).toString("hex");return X.push({signKey:M,outboundName:V,corporationId:T.corporationId,action:P?"updated":"created"}),{type:"hosecloud",signKey:M,outboundName:V,mode:"assisted",apiKey:U,apiSecret:Y,apiOrigin:T.apiOrigin,...T.customApiUrl?{customApiUrl:T.customApiUrl}:{},corporationId:T.corporationId}}),D=G.filter((T)=>T.type!=="hosecloud"),F={...Q,integrations:[...D,...L]};return await j8(q,F,I.seal.endpoints.approvalStylePreferences),{skipped:!1,synced:X}}async function fG1($){let I=_7($,"appKey"),z=_7($,"appSecurity"),q=m1($,"domain"),U=await _z(I,z,q),Y=await aG(U.domain,U.openapiToken).catch(()=>[]),J=Y.reduce((Q,w)=>Q+w.roleDefs.length,0);E0({domain:U.domain,corpId:U. Line truncated
Run 'seal-use corps bind-test ${U.id} <testCorpId> --confirm' first to establish a verified 1-to-1 association,
or use 'seal-use webhook replay <recordId> --force' if you explicitly intend to replay directly within production.`);let Y=O1(U.testCorpId);if(Y.environment!=="test")throw Error(`Target enterprise '${Y.name}' (${Y.id}) is marked as '${Y.environment}', NOT 'test'. Aborting replay to protect non-test environments.`);let J=j(z.options.recordId)??j(z.options["record-id"])??j(z.options.id),Q=j(z.options.recordIds)??j(z.options["record-ids"]),w=Q?Q.split(",").map((p)=>p.trim()).filter(Boolean):void 0,K=j(z.options.sn)??j(z.options.documentSn)??j(z.options["document-sn"]),H=j(z.options.sns)??j(z.options["document-sns"]),G=H?H.split(",").map((p)=>p.trim()).filter(Boolean):void 0,W=k0(z.options.limit)??(!J&&!w&&!K&&!G?1:void 0),V=j(z.options.status),X=j(z.options.startDate)??j(z.options["start-date"]),L=j(z.options.endDate)??j(z.options["end-date"]),D=await G1(U),F=await G1(Y),T=j(z.options.webhook)??j(z.options.selector),P=j(z.options.snSuffix)??j(z.options["sn-suffix"]),M=j(z.options.snPrefix)??j(z.options["sn-prefix"]),B=j(z.options.docIdSuffix)??j(z.options["doc-id-suffix"]),u=j(z.options.docIdPrefix)??j(z.options["doc-id-prefix"]),C=D0(z.options.dryRun)??D0(z.options["dry-run"]),x={recordId:J,recordIds:w,sn:K,sns:G,limit:W,status:V,startDate:X,endDate:L};console.error(`[corps-replay-test] 正式企业「${U.name}」(${U.id}) -> 测试企业「${Y.name}」(${Y.id})`);let v=await RU({query:x,sourceClient:D,targetClient:F,sourceCorp:U,targetCorp:Y,webhookSelector:T,snPrefix:M,snSuffix:P,docIdPrefix:u,docIdSuffix:B,dryRun:C});if(C){console.error(`[corps-replay-test] 预览模式:已成功从 ${U.name} 提取单据并转换为 Webhook Payload(未实际推送)。`),console.log(JSON.stringify(v,null,2));return}if(v.success)if(v.totalCount===1&&v.replayedDocument)console.error(`\uD83D\uDFE2 成功重放单据「${v.replayedDocument.documentSN}」至 ${Y.name} (${v.targetWebhook?.name??"Webhook 通道"})`);else console.error(`\uD83D\uDFE2 成功重放 ${v.successCount} 条单据(来自「${U.name}」)至「${Y.name}」(${v.targetWebhook?.name??"Webhook 通道"})`);else console.error(`\uD83D\uDD34 单据重放部分或全部失败(成功 ${v.successCount} 条,失败 ${v.failureCount} 条)至「${Y.name}」`);if(console.error(`\uD83D\uDC49 Next action: seal-use approval-runs list --corp ${Y.id} --limit ${v.totalCount}`),console.log(JSON.stringify(v,null,2)),!v.success)process.exitCode=1;return}if($==="switch"){let q=I;if(!q)throw Error("Usage: seal-use corps switch <corpId>");let U=Y4();if(!U.stateful)throw Error("Cannot switch the default enterprise while stateless mode is enabled. Use `seal-use config mode stateful` first.");let Y=O1(q);VI({...U,stateful:!0,defaultCorpId:Y.id}),E0({current:!0,id:Y.id,name:Y.name});return}if($==="probe-hose"){await fG1(J$(z.json));return}if($==="hose-staffs"){await nG1(J$(z.json));return}if($==="add-hose"){await bG1(J$(z.json));return}if($==="add-seal"){await iG1(J$(z.json));return}if($==="add-link"){let q=I??j(z.options.link)??j(z.options.url);if(!q)throw Error("Usage: seal-use corps add-link <https://.../web/thirdparty.html?...> [--name <customName>] [--overwrite]");await pG1(q,j(z.options.name),D0(z.options.overwrite)===!0);return}throw Error(`Unknown corps command: ${$??""}. Run 'seal-use help' for available commands.`)}function DL0($){return[...$].slice(0,6).join("")+"(Seal测)"}async function kG1($,I,z,q){if($.source.type!=="hose")return{skipped:!0,reason:"prod source is not hose; no hosecloud credentials available"};let U=($.source.appKey??$.source.key)?.trim(),Y=($.source.appSecurity??$.source.password)?.trim();if(!U||!Y)return{skipped:!0,reason:"prod hose source missing appKey/appSecurity (or key/password)"};let[J,Q]=await Promise.all([P1(z,$.seal.endpoints.approvalStylePreferences).catch(()=>({})),P1(q,I.seal.endpoints.approvalStylePreferences).catch(()=>({}))]),w=(J.integrations??[]).filter((T)=>T.type==="hosecloud");if(w.length===0)return{skipped:!0,reason:"prod Seal enterprise has no hosecloud integrations configured"};let K=new Set,H=[];for(let T of w){let P=T.corporationId??$.id;if(!K.has(P))K.add(P),H.push(T)}let G=Q.integrations??[],W=new Map(G.filter((T)=>T.type==="hosecloud").map((T)=>[T.corporationId,T])),V=DL0($.name),X=[],L=H.map((T)=>{let P=W.get(T.corporationId),M=P?.signKey??yG1(6).toString("hex");return X.push({signKey:M,outboundName:V,corporationId:T.corporationId,action:P?"updated":"created"}),{type:"hosecloud",signKey:M,outboundName:V,mode:"assisted",apiKey:U,apiSecret:Y,apiOrigin:T.apiOrigin,...T.customApiUrl?{customApiUrl:T.customApiUrl}:{},corporationId:T.corporationId}}),D=G.filter((T)=>T.type!=="hosecloud"),F={...Q,integrations:[...D,...L]};return await j8(q,F,I.seal.endpoints.approvalStylePreferences),{skipped:!1,synced:X}}async function fG1($){let I=_7($,"appKey"),z=_7($,"appSecurity"),q=m1($,"domain"),U=await _z(I,z,q),Y=await aG(U.domain,U.openapiToken).catch(()=>[]),J=Y.reduce((Q,w)=>Q+w.roleDefs.length,0);E0({domain:U.domain,corpId Line truncated
- `);throw Error(`Missing required parameter: staffId. Found ${v.length} candidate administrators:
- ${p}
Please specify 'staffId', 'staffName', or 'staffPhone' to explicitly select an account (or pass force:true to bypass).`)}}}if(!L)if(!H&&Y)L=Y;else throw Error("Missing required parameter: staffId (or proxyStaffBizId). Run 'seal-use corps hose-staffs' to discover available administrators.");let D=m1($,"id")??W,F=V??W,T=m1($,"sealUrl")??`https://${W.toLowerCase()}.sealai.cc`,P={id:D,name:F,environment:"production",seal:{url:T,endpoints:{approvalStylePreferences:"api/v1/agent/ai-approval/config"}},source:{type:"hose",domain:G,appKey:z,appSecurity:q,corpId:W,staffId:L},auth:{refreshTtl:300}};if(H)dG(D),await pU(P);let M=by();VL0(M,{recursive:!0,mode:448});let B=XL0(M,`${su(D)}.json`);if(WL0(B)&&$.overwrite!==!0)throw Error(`Enterprise config already exists: ${B}. Pass "overwrite": true to replace it.`);ZL0(B,`${JSON.stringify(P,null,2)}
+2 -1
View File
@@ -792,7 +792,8 @@ export async function handleCorpsCommand(action: string | undefined, maybeName:
if (!prodCorp.testCorpId) {
throw usageError(
`Production enterprise '${prodCorp.name}' (${prodCorp.id}) has no bound test enterprise.\n` +
`Run 'seal-use corps bind-test ${prodCorp.id} <testCorpId> --confirm' first to establish a verified 1-to-1 association.`
`Run 'seal-use corps bind-test ${prodCorp.id} <testCorpId> --confirm' first to establish a verified 1-to-1 association,\n` +
`or use 'seal-use webhook replay <recordId> --force' if you explicitly intend to replay directly within production.`
);
}