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

@ams-pro/scope-utils

v0.0.5

Published

Scope utils for AMS-Pro

Downloads

8

Readme

AMS-Scope Utilities

Dieses Package dient dazu Scopes, welche innerhalb von AMS-Pro genutzt werden, nutzbar zu machen, sodass innerhalb von Front- und Backend die Möglichkeit besteht zu überprüfen, ob ein User Zugriff (auf Basis der ihm zugewiesenen Scopes) auf eine bestimmte Ressource besitzt.

Installation

yarn add @ams-pro/scope-utils

oder

npm i @ams-pro/scope-utils

Nutzung im Frontend (VueJs)

Hauptanwendungsfall im Frontend wird sein, herauszufinden, wie bestimmte Elemente gerendert werden sollen, auf Basis der dem User zur Verfügung stehenden Scopes. Dazu kann, nachdem der User sich eingeloggt hat, eine Instanz des AccessController's erstellt werden. Dieser nimmt als Parameter die aktuellen User-Scopes entgegen:

Beispiel:

let accessController: AccessController;

export function useScopes() {
  const init = (scopes: string | string[]) => {
    if (!accessController) {
      accessController = new AccessController(scopes);
    }
  };

  return {
    can: accessController.can,
    update: accessController.updateUserScopes,
    init,
  };
}

Nach dem einloggen muss nun einmal die Funktion useScopes().init() aufgerufen werden, damit eine AccessController-Instanz zur Verfügung steht.

Innerhalb einer Komponente kann nun mithilfe von

<template>
  <div>
    <button :disabled="!can('ams:betriebsmittel:write')">Speichern</button>
  </div>
</template>

<script>
export default {
  setup() {
    const { can } = useScopes();

    return { can };
  },
};
</script>

Abgefragt werden, ob der User Zugriff hat oder nicht. Sollten sich die Scopes eines Users im Verlaufe einer Sitzung ändern (durch einloggen in eine andere Unit, o.ä.) können mithilfe von AccessController.updateUserScopes alle Scopes überschrieben werden.

Nutzung im Backend

Coming Soon