Skip to content

Latest commit

 

History

History
57 lines (41 loc) · 1.5 KB

File metadata and controls

57 lines (41 loc) · 1.5 KB

@cerbos/embedded

npm

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

Prerequisites

Installation

$ 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.

import { AutoUpdatingLoader, Embedded } from "@cerbos/embedded";

const cerbos = new Embedded(
  new AutoUpdatingLoader(
    "https://lite.cerbos.cloud/bundle?workspace=...&label=...",
  ),
);

await cerbos.isAllowed({
  principal: {
    id: "[email protected]",
    roles: ["USER"],
    attr: { tier: "PREMIUM" },
  },
  resource: {
    kind: "document",
    id: "1",
    attr: { owner: "[email protected]" },
  },
  action: "view",
}); // => true

For more details, see the Embedded class documentation.

Further reading

Get help