opa-compile-response-parser
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

opa-compile-response-parser

GitHub stars npm version unpkg npm bundle size (minified + gzip) Build Status

An Open Policy Agent Compile Response Parser

Open Policy Agent provides a compile API that allows you partially evaluate your policy.

This library can parse the compile JSON response and allow you to access the Rego AST (Abstract Syntax Tree) in the response body by Rego language structure.

Moreover, it further processes the AST to:

  • eliminate tautological rules
    • e.g. r { x; false } => false
  • replace rule reference with inline value
    • e.g. r1 { r2 } r2 { true } => r1 { true } => true

API document

https://t83714.github.io/opa-compile-response-parser/

Examples

import OpaCompileResponseParser from "opa-compile-response-parser";

const parser = new OpaCompileResponseParser();
parser.parse(jsonResponse);

const result = parser.evaluate();
/**
 returned evaluate result:
    interface CompleteRuleResult {
        fullName: string;
        name: string;
        value: RegoValue;
        isCompleteEvaluated: boolean;
        residualRules?: RegoRule[];
    }
*/

// --- Print residual rules as human readable string
console.log(parser.evaluateAsHumanReadableString());

More Examples

Todo

  • replace rule reference with inline rules

Compatibility

Tested with Open Policy Agent version 0.37.2

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.0
    549
    • latest

Version History

Package Sidebar

Install

npm i opa-compile-response-parser

Weekly Downloads

494

Version

2.0.0

License

MIT

Unpacked Size

6.67 MB

Total Files

18

Last publish

Collaborators

  • t83714