@cerbos/embedded-client
v0.4.0
Published
Client library for interacting with embedded Cerbos policy decision points from server-side Node.js and browser-based applications
Readme
@cerbos/embedded-client
Client library for interacting with embedded Cerbos policy decision points (PDPs) from server-side Node.js and browser-based applications. Policy bundles are loaded from Cerbos Hub and executed by a WebAssembly module (@cerbos/embedded-server).
Prerequisites
- Node.js 20+
- A Cerbos Hub account
Installation
$ npm install @cerbos/embedded-clientExample usage
With Vite:
import { fileURLToPath } from "node:url";
import { Embedded } from "@cerbos/embedded-client";
import wasm from "@cerbos/embedded-server/server.wasm?init";
const cerbos = new Embedded({
policies: { ruleId: "B5LU9EVYN1MD" },
wasm,
});
await cerbos.isAllowed({
principal: {
id: "[email protected]",
roles: ["USER"],
attr: { tier: "PREMIUM" },
},
resource: {
kind: "document",
id: "1",
attr: { owner: "[email protected]" },
},
action: "view",
}); // => trueFor more details, see the Embedded class documentation.
CommonJS support
This package is ESM-only, but may be required from CommonJS modules in Node.js versions 20.19.5+, 22.15+, and 24+.
