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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@a5it/permission-types

v1.0.21

Published

Shared TypeScript types for permissions in A5IT projects

Downloads

309

Readme

🛡️ @a5it/permission-types

A shared TypeScript-only package that defines and exports strongly-typed permission constants and utility types for use across A5IT's applications (reseller platform, customer organization portal, internal tools, etc.).

📦 Installation

npm install @a5it/permission-types

🚀 Usage

import {
  RESELLER_PERMISSIONS,
  ResellerPermissionKeys,
  ResellerPermissionValues,
} from "@a5it/permission-types";

📚 API Documentation

Reseller Permission Utilities

This package provides a collection of utility functions designed to handle RESELLER_PERMISSIONS logic, including group-wise lookups, flat lists, schema generation, and more.

1. List All Permissions Per Group

Returns a list of permission strings for a given group.

function getPermissionListByGroup<K extends ResellerPermissionKeys>(
  group: K
): `${K}.${ResellerPermissionValues<K>}`[] {
  return Object.keys(RESELLER_PERMISSIONS[group]).map(
    (action) => `${group}.${action}` as `${K}.${ResellerPermissionValues<K>}`
  );
}

// Usage
const teamPerms = getPermissionListByGroup("TEAMS");
// → ["TEAMS.ALL", "TEAMS.VIEW", ...]

2. Create a Flat List of All Reseller Permissions

Useful for dropdowns, seeding roles, or exporting all permissions.

function getAllResellerPermissions(): ResellerPermission[] {
  return Object.values(RESELLER_PERMISSIONS).flatMap((group) =>
    Object.values(group)
  );
}

3. Check If a Permission Belongs to a Group

function getPermissionGroup(
  permission: ResellerPermission
): ResellerPermissionKeys | undefined {
  const [group] = permission.split(".") as [ResellerPermissionKeys, string];
  return group in RESELLER_PERMISSIONS ? group : undefined;
}

4. Build a Map of Groups → Permissions (for form UI)

function groupPermissionsByModule(): Record<
  ResellerPermissionKeys,
  ResellerPermission[]
> {
  const map = {} as Record<ResellerPermissionKeys, ResellerPermission[]>;
  for (const key in RESELLER_PERMISSIONS) {
    const group = key as ResellerPermissionKeys;
    map[group] = Object.values(RESELLER_PERMISSIONS[group]);
  }
  return map;
}

5. Build a Role Editor Schema

Generate a permission schema for a role creation/edit form:

type RolePermissionOption = {
  label: string;
  value: ResellerPermission;
  group: ResellerPermissionKeys;
};

function getRolePermissionOptions(): RolePermissionOption[] {
  return Object.entries(RESELLER_PERMISSIONS).flatMap(([group, perms]) =>
    Object.entries(perms).map(([key, value]) => ({
      label: `${group} → ${key}`,
      value: value as ResellerPermission,
      group: group as ResellerPermissionKeys,
    }))
  );
}

6. Generate a Zod Schema for Permissions Array

import { z } from "zod";

const resellerPermissionSchema = z.enum(
  getAllResellerPermissions() as [ResellerPermission, ...ResellerPermission[]]
);

const resellerRoleInputSchema = z.object({
  name: z.string(),
  permissions: z.array(resellerPermissionSchema),
});

7. Find Missing Permissions (for auditing)

function findMissingPermissions(
  granted: ResellerPermission[]
): ResellerPermission[] {
  const all = getAllResellerPermissions();
  return all.filter((p) => !granted.includes(p));
}

8. List Action Keys of Resource

function getActionKeys<K extends ResellerPermissionKeys>(
  group: K
): ResellerPermissionValues<K>[] {
  return Object.keys(RESELLER_PERMISSIONS[group]) as ResellerPermissionValues<K>[];
}

// Usage
getActionKeys("ORDERS"); // ["VIEW", "UPDATE"]

🔧 Development

# Install dependencies
npm install

# Build the package
npm run build

# Clean build artifacts
npm run clean

📝 License

ISC © A5IT