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

hapi-acl-auth-taglib

v0.0.2

Published

Taglib for Marko to be used in concert with hapi-acl-auth

Downloads

2

Readme

hapi-acl-auth-taglib

Taglib for Marko to be used in concert with hapi-acl-auth, or not. If you have an array of roles that a user possesses, and an array of roles the are necessary, you can use this taglib.

Installation

npm install --save hapi-acl-auth-taglib

Tags

haa:if

Used to render, or not, the body of the tab based on which roles a user possesses and which are allowed, or not allowed.

Attributes

userRoles

Required. An array of roles that the user possesses.

roles

An array of roles required by the user needed to display the body of the tag.

mode

A string. Can be any or all, any by default. If any is specified the body will be rendered if the user has any of the roles listed in roles. If all the specified body will only be rendered if the user has all of the roles in roles

not

An array of roles. The body of the tag will only be displayed if the user does not have one of the roles specified here.

Example

server.js
'use strict'

// allowing Marko template requires
require('marko/node-require')
require('marko/compiler').defaultOptions.writeToDisk = false

const Hapi = require('hapi')

const server = new Hapi.Server()

const plugins = [
  {
    register: require('hapi-auth-basic')
  },
  {
    register: require('hapi-acl-auth'),
    options: {
      handler: function (request, callback) {
        // callback(err, obj) takes an error object and an arbitrary object, although
        // this object must contain a `roles` attribute that contains an array of
        // roles, or a function that returns an array of roles or returns a promise
        // that resolves an array of roles, that are possessed by the user
        callback(null, request.auth.credentials)
      }
    }
  }
]

const validateFunc = function (request, username, password, callback) {
  callback(null, true, {id: username, username: username, roles: ['admin']})
}

server.connection({
  host: 'localhost',
  port: 8000
})

server.register(
  plugins,
  function (err) {
    if (err) {
      throw err
    }
    server.auth.strategy('simple', 'basic', {validateFunc: validateFunc})
    server.route({
      method: 'GET',
      path: '/',
      config: {
        auth: 'simple',
        plugins: {
          hapiAclAuth: {
            roles: ['user', 'admin']
          }
        }
      },
      handler: function (request, reply) {
        const page = require('./index.marko')
        return reply(page.stream(
          {
            userRoles: request.auth.credentials.roles
          }
        ))
      }
    })


    server.start((err) => {
      if (err) {
        throw err
      }
      console.log('Server running at:', server.info.uri)
    })

  }
)
index.marko
<html>
<head>
    <title>
        /
    </title>
</head>
<body>
<h1>
    /
</h1>
<haa:if roles=['admin'] userRoles=input.userRoles>
    some content
</haa:if>
</body>
</html>