# @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.

> [!NOTE]
> This client library is for use with legacy Cerbos Hub workspaces.
> If you are using the new Cerbos Hub, with deployments and policy stores, you should use [@cerbos/embedded-client](../embedded-client/README.md).

## 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](https://cerbos.github.io/cerbos-sdk-javascript/classes/_cerbos_embedded.Embedded.html).

## CommonJS support

This package is ESM-only, but may be `require`d from CommonJS modules in Node.js versions 20.19.5+, 22.15+, and 24+.

## Further reading

- [API reference](https://cerbos.github.io/cerbos-sdk-javascript/modules/_cerbos_embedded.html)
- [Cerbos documentation](https://docs.cerbos.dev)
- [Cerbos Hub documentation](https://docs.cerbos.dev/cerbos-hub/)

## Get help

- [Join the Cerbos community on Slack](https://go.cerbos.io/slack)
- [Email us at help@cerbos.dev](mailto:help@cerbos.dev)
