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

seneca-badge

v0.5.2

Published

Permissions for seneca

Downloads

1

Readme

Seneca Badge

An authorization plugin for seneca. An action/command should be responsible for knowing the the requester/actor is allowed do the thing it can do. With badge when you authenticate a requester they get a badge which travels with them throughout the service mesh. A seneca action can describe an authorization policy within its pattern. If the policy is met, then the action will run. This achieves keeping the authorization code out of the action yet still requiring the action to dictate it's policy.

Example

To use badge, you simply need to add the transport extention to the service.

srv.js

const seneca = require('seneca')
const { Badge } = require('seneca-badge')
const src = require('./src)

seneca()
  .use(Badge())
  .use(src)

src.js

module.exports = function example(options) {
  const seneca = this
  const {add} = seneca

  /**
  * To be greeted you need to have the role admin
  * and have an attribute test.
  **/
  add(
    {
      role: 'example',
      cmd: 'hello',
      policy$: {
        roles: ['admin'],
        attrs: ['test']
      }
    },
    cmdHello
  )

  /**
  * To retrieve this entity we require the request
  * to either be an admin or an owner of resource
  * with a given id.
  **/
  add(
    {
      role: 'example',
      cmd: 'get',
      policy$: {
        // Unlike badge, in policies, resources is a single object not array
        resources:{
          id: 'id',
          roles: ['owner']
        }
        roles: ['admin']
      }
    },
    cmdGet
  )

  function cmdHello(msg, reply) {
    reply(null, {
      ok: true,
      greeting: 'Hello admin'
    })
  }

  function cmdGet(msg, reply) {
    reply(null, {
      ok: true,
      ...retrievedEntity
    })
  }
}

Policies

A policy discribes the ACL's that need to be satisfied in order for an action to run.

roles

attrs

resources Often you need to be able to insure that a users policy is scoped to that of a resource. This is done by adding a resources property to the policy. resources is an array with a scoped resource policy. A resource policy has an id whose value should be the path to the id of the resource on the msg object where the parent msg is implied. For example, say the resource id in question has a path of msg.id. Well, then you would add id: 'id' to the policy. The resource policy carries the same controls as the main policy.

example

{
  ...
  policy$: {
    resource: [{
      id: 'id', // Path to value on msg object.
      roles: ['admin'],
      attrs: ['billing', 'spawn_accounts', 'spawn_admin']
    }],
    roles: ['admin'],
    attrs: ['cool_attr']
  }
}

Note Don't forget that the parent policy will override and win over any resource. In the above example, if a badge has global role of admin and an attribute of cool_attr, then the action will process the message regardless of the resource policy.