UNPKG

@cerbos/embedded

Version:

Client library for interacting with embedded Cerbos policy decision points generated by Cerbos Hub from server-side Node.js and browser-based applications

58 lines (41 loc) 1.53 kB
# @cerbos/embedded [![npm](https://img.shields.io/npm/v/@cerbos/embedded?style=flat-square)](https://www.npmjs.com/package/@cerbos/embedded) Client library for interacting with embedded Cerbos policy decision points (PDPs) generated by [Cerbos Hub](https://www.cerbos.dev/product-cerbos-hub) from server-side Node.js and browser-based applications. ## Prerequisites - Node.js 20+ - A [Cerbos Hub](https://hub.cerbos.cloud) account ## Installation ```console $ npm install @cerbos/embedded ``` ## Example usage URLs to download embedded PDP bundles are available from the "Embedded" section of the "Decision points" page of your Cerbos Hub workspace. ```typescript import { AutoUpdatingLoader, Embedded } from "@cerbos/embedded"; const cerbos = new Embedded( new AutoUpdatingLoader( "https://lite.cerbos.cloud/bundle?workspace=...&label=...", ), ); await cerbos.isAllowed({ principal: { id: "user@example.com", roles: ["USER"], attr: { tier: "PREMIUM" }, }, resource: { kind: "document", id: "1", attr: { owner: "user@example.com" }, }, action: "view", }); // => true ``` For more details, [see the `Embedded` class documentation](../../docs/embedded.embedded.md). ## Further reading - [API reference](../../docs/embedded.md) - [Cerbos documentation](https://docs.cerbos.dev) - [Cerbos Hub documentation](https://docs.cerbos.dev/cerbos-hub/) ## Get help - [Join the Cerbos community on Slack](http://go.cerbos.io/slack) - [Email us at help@cerbos.dev](mailto:help@cerbos.dev)