npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@policer-io/pdp-ts

v1.0.10

Published

The Policer PDP SDKs allow to control access within your application based the Policer Access Control Policy.

Downloads

11

Readme

logo-light-long-2

Policy Decision Point — Typescript/Javascript

The policer.io Policy Decision Point (PDP) client library for typescript and javascript projects.

Pipeline npm embrio.tech

:star: Give us a Star!

Support the project by giving it a GitHub Star!

GitHub Repo stars

:gem: Why @policer-io/pdp-ts?

Advanced access control with one line of code with policy as data:

const {
  grant, // allow or deny access
  filter, // generate DB query filters
  projection, // show or hide document properties
  setter, // set document properties
} = pdp.can(
  ['editor', 'publisher'], // the user's roles
  'article:publish', // the operation to check
  {
    user: { _id: 'some-user-id-003' },
    document: {
      published: false,
      createdBy: 'other-user-id-007',
    },
  } // attributes of user, document or context
)

Learn more about the benefits and features of policer.io!

:floppy_disk: Installation

Prerequisites

  • Node >= v20.x is required
  • policer.io Policy Center instance (learn more)
    • self-hosted
    • https://cloud.policer.io (coming soon)

Install

Use yarn command

yarn add @policer-io/pdp-ts

or npm command

npm install --save @policer-io/pdp-ts

:orange_book: Usage

Connect to Policy Center

The PDP connects to a policer.io Center Instance to load the policy (roles and permissions) for a given application. Therefore create and connect a PDP instance with:

import PDP from '@policer-io/pdp-ts'

type RoleName = 'reader' | 'editor' | 'publisher'

const pdp = await PDP.create<RoleName>({
  applicationId: '65f0674f39d8a1a5ef805ca7',
  hostname: 'cloud.policer.io',
})

Make Policy Decisions

//// 1. prepare policy decision inputs

/** the user's roles */
const roles: RoleName[] = ['editor', 'publisher']
/** the operation to check */
const operation: string = 'article:publishBatch'
/** attributes of user, document or context */
const attributes: Record<string, unknown> = {
  user: {
    _id: 'some-user-id-003',
    magazine: 'The New Yorker',
  },
  document: {
    published: false,
    createdBy: 'other-user-id-007',
  },
}

//// 2. perform policy decision/check

const { grant, filter, projection, setter } = pdp.can(roles, operation, attributes)

//// 3. use policy decision result

if (grant) {
  // if authorized

  // query documents and document properties based on policy decision result (`filter` & `projection`)
  const articles = await db.articles.find({ $and: [{ status: 'ready' }, filter] }, projection).exec()

  // set or overwrite some document fields based on policy decision result (`setter`), for example `article.magazine`
  articles.forEach((article) => {
    publish({ ...article, ...setter })
  })
} else {
  // if not authorized

  throw new Error('403 Forbidden')
}

:bug: Bugs

Please report bugs by creating a bug issue.

:construction_worker_man: Contribute

You can contribute to policer.io by

  • improving typescript PDP (this package)
  • implementing policer.io PDP for other programming languages
  • developing on the policer.io ecosystem in general

Either way, let's talk!

Development

Prerequisites

Install

yarn install

Test

yarn test

or

yarn test:watch

Commit

This repository uses commitlint to enforce commit message conventions. You have to specify the type of the commit in your commit message. Use one of the supported types.

git commit -m "[type]: my perfect commit message"

:speech_balloon: Contact

Talk to us via policer.io

:lock_with_ink_pen: License

The code is licensed under the MIT License