type TokenResponse = { jwtToken: string }; type DecisionExecutionRequest = { decisionId: "AUTO-INS-011"; profileId: string; scenarioId: string; algorithm: "TOPSIS"; weightStrategy: "Expert"; runSensitivity: boolean; requestContext: { correlationId: string }; options: Array<{ optionId: string; name: string; values: Record; }>; }; const required = (name: string): string => { const value = process.env[name]; if (!value) throw new Error(`Set ${name} before running this example.`); return value; }; const identityUrl = process.env.DECISIOQ_IDENTITY_URL ?? "https://identity.vinquery.com/connect/token"; const catalogUrl = (process.env.DECISIOQ_DKS_URL ?? "https://dks.vinquery.com").replace(/\/$/, ""); const decisionServiceUrl = (process.env.DECISIOQ_DDE_URL ?? "https://dde.vinquery.com").replace(/\/$/, ""); const correlationId = `auto-ins-011-ts-${crypto.randomUUID()}`; const tokenResponse = await fetch(identityUrl, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ clientId: required("DECISIOQ_CLIENT_ID"), clientSecret: required("DECISIOQ_CLIENT_SECRET"), audience: process.env.DECISIOQ_AUDIENCE ?? "vinquery:api:decisioq" }) }); if (!tokenResponse.ok) throw new Error(await tokenResponse.text()); const token = (await tokenResponse.json()) as TokenResponse; const detailResponse = await fetch(`${catalogUrl}/decisioncatalog/decisions/AUTO-INS-011`, { headers: { Authorization: `Bearer ${token.jwtToken}`, "X-Correlation-Id": correlationId } }); if (!detailResponse.ok) throw new Error(`Decision detail failed: ${detailResponse.status}`); const decisionDetail = await detailResponse.json(); const constraints = decisionDetail.constraints ?? []; if (constraints.length === 0) { console.log("No catalog-defined hard constraints; all validated candidates proceed to criteria-based ranking."); } const request: DecisionExecutionRequest = { decisionId: "AUTO-INS-011", profileId: "balanced", scenarioId: "standard", algorithm: "TOPSIS", weightStrategy: "Expert", runSensitivity: false, requestContext: { correlationId }, options: [ { optionId: "CLAIM-011-01", name: "Claim CASE-001", values: { claim_severity_score: 83, customer_impact_score: 83, coverage_clarity_score: 83, fraud_risk_score: 78, estimated_loss_amount: 62500 } }, { optionId: "CLAIM-011-02", name: "Claim CASE-002", values: { claim_severity_score: 75, customer_impact_score: 75, coverage_clarity_score: 75, fraud_risk_score: 70, estimated_loss_amount: 107500 } } ] }; const executionResponse = await fetch(`${decisionServiceUrl}/api/v1/decide`, { method: "POST", headers: { Authorization: `Bearer ${token.jwtToken}`, "Content-Type": "application/json", "X-Correlation-Id": correlationId }, body: JSON.stringify(request) }); const responseText = await executionResponse.text(); console.log(responseText); try { const response = JSON.parse(responseText); console.log("Constraint summary:", response.constraintSummary ?? { excludedOptions: response.decisionResult?.excludedOptions ?? [] }); } catch { // Non-JSON errors are printed above. } if (!executionResponse.ok) process.exitCode = 1;