Files
seal-use/src/probe.ts
T

52 lines
1.8 KiB
TypeScript

import { getEnterprisesDirCandidates, loadCorpConfigs, loadGlobalConfig } from "./core/config/loader.js";
import { resolveCorpConfig } from "./core/config/manager.js";
import { createSealClient } from "./core/http/factory.js";
import { resolveLiveSealEnterpriseConfig } from "./domains/seal/source.js";
import { getApprovalContext } from "./domains/seal/api.js";
export async function runProbe(options: { corpId?: string } = {}) {
const corps = loadCorpConfigs();
const globalConfig = loadGlobalConfig();
const corp = resolveCorpConfig(
corps,
{
stateful: globalConfig.stateful,
defaultCorpId: globalConfig.defaultCorpId,
corpId: options.corpId
},
getEnterprisesDirCandidates()
);
console.log(`[probe] corp=${corp.id} source=${corp.source.type}`);
const enterprise = await resolveLiveSealEnterpriseConfig(corp);
console.log("[probe] seal enterprise");
console.log(JSON.stringify(enterprise, null, 2));
const client = await createSealClient(corp);
const context = await getApprovalContext(client, {
documentLimit: 20,
stylePreferencesEndpoint: corp.seal.endpoints.approvalStylePreferences
});
console.log("[probe] approval context summary");
console.log(JSON.stringify({
rules: context.rules.rules.length,
hasPendingRuleDeletes: context.rules.hasPendingDeletes,
documents: context.documents.articles.length,
documentsTotal: context.documents.total,
stylePreferences: context.stylePreferences.ok
? "ok"
: `error: ${context.stylePreferences.error}`
}, null, 2));
}
if (import.meta.main) {
const args = process.argv.slice(2);
const corpId = args[0] === "--corp" ? args[1] : args[0];
runProbe({ corpId }).catch((error) => {
console.error(error instanceof Error ? error.message : error);
process.exit(1);
});
}