Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 2.26 KB

README.md

File metadata and controls

71 lines (52 loc) · 2.26 KB

cross-policy

Cross-Policy is a TypeScript library designed to simplify policy evaluation by providing a unified interface for multiple policy target runtimes. With support for defining policies in Open Policy Agent (OPA), Common Expression Language (CEL), and more, Cross-Policy streamlines policy evaluation and decision-making in applications.

Key Features:

  • Single Interface: Interact with different policy engines through one consistent API.
  • Flexible and Extensible: Add support for additional policy targets or customize behavior as needed.

Getting Started

cross-policy is split into several packages, but to get started, you only need to install the @cross-policy/core package.

Installation

To install the library, run the following command:

yarn add cross-policy

For our usage examples, we will use the OPA WASM policy target. To install the OPA WASM target, run the following command:

yarn add @cross-policy/target-opa-wasm

Usage

To create a callable policy, you need to create a CrossPolicy instance. This instance provides a evaluate method that takes an input and returns a promise that resolves to a boolean indicating whether the policy is allowed or not.

import { createCrossPolicy } from "@cross-policy/core";
import { opaWasmPolicyTarget } from "@cross-policy/target-opa-wasm";

const crossPolicy = createCrossPolicy({
  target: opaWasmPolicyTarget({
    // The path to the WASM policy file.
    policyPath: "path/to/policy.wasm",
  }),
  schema: z.object({ input: z.string() }),
});

const result = await crossPolicy.evaluate({ input: "test" });

This example demonstrates how to create a callable policy using the OPA WASM policy target. The policy is defined in a WASM file and loaded at runtime.

Available Policy Targets

This is just a collection of policy targets which are included in this repository: