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

@anyfin/acl

v1.1.13

Published

Access control utilities for nodejs services

Downloads

44

Readme

🛡 Anyfin ACL

Access control utilities for nodejs services. These can be used with/without graphql.

This is required for all services that are contributing to the client facing apollo federation graph.

Why dont we just implement this in the apollo federation gateway ?

  1. Because apollo federation is a gateway. Its only job is to route the requests. It doesnt allow any modification of schema. Hence we cant add any directives at the gateway level that can be used by upstream services.

  2. Since the roles and permissions for each field in the schema is controlled by the respective services the logic needs to live within these services itself.

Hence this npm module aims to share the common acl code that is required for these services and aims to keep all the services in sync.

Installation

yarn add @anyfin/acl

Make sure you have installed these peer dependencies on your services

  "graphql": ">=15.0.0",
  "apollo-server-express": ">=2.16.0"

GraphQL Usage

import { authDirectiveTypeDef, AuthDirective } from '@anyfin/acl';
.
.
.
// Register the schema directive
SchemaDirectiveVisitor.visitSchemaDirectives(schema, {
  auth: AuthDirective,
});
.
.
.
// Make sure to add authDirectiveTypeDef to your typedefs
const schema = makeExecutableSchema({
  typeDefs:[...yourTypeDefs, authDirectiveTypeDef],
  resolvers
});

This will add the following directive on your graphql schema

@auth(permissions: [String!], roles: [String!]) on FIELD_DEFINITION

Also, the directive expects that the graphql context has user object from the decoded jwt present in it.

So make sure you decode the jwt from the request header and add it to the context.

export default new ApolloServer({
  schema,
  context: ({ req }: Params) => ({
    .
    .
    user: req.user,
    .
    .
    .
  })
});

Non GraphQL usage:

import { hasUserAccess, Roles, Permissions } from '@anyfin/acl';

const user = {
  roles: [Roles.customer.key],
  permissions: [Permissions.Application.LIST],
};

// Check if user has a permission
hasUserAccess(user, [Permissions.Aml.LIST]); // ---> false
hasUserAccess(user, [Permissions.Application.LIST]); // ---> true
hasUserAccess(user, [Customer.Read.SELF]); // ---> true

// check if user matches a complete role
hasUserAccess(user, [], [Roles.employee.key]); // ---> false
hasUserAccess(user, [Roles.customer.key]); // ---> true

Getting started

  1. git clone this repo.
  2. yarn install installs dependencies
  3. yarn test for test mode.
  4. yarn lint for linting.
  5. yarn build for building the library.

Deploy/Publish

In order to deploy new versions, simply bump the version in package.json and create a new github release.

Github action should automagically deploy it to npm. ✨

Ownership/Audit

Repo ownership: @a7ul
Last audit: 2021-01-28 by @msegers