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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@memberjunction/api-keys-base

v5.4.1

Published

MemberJunction: Base API Keys Engine Package - provides metadata caching for API scopes, applications, and key bindings. Can be used anywhere (client or server).

Downloads

2,464

Readme

@memberjunction/api-keys-base

Metadata caching engine for MemberJunction's API key authorization system. This package provides cached, read-only access to API scopes, applications, and key bindings. It can be used on both client and server.

Architecture

graph TD
    subgraph "@memberjunction/api-keys-base"
        A[APIKeysEngineBase] --> B[Scope Cache]
        A --> C[Application Cache]
        A --> D[Key Binding Cache]
        B --> E["Lookup Maps<br/>(by path, by ID)"]
        C --> F["Lookup Maps<br/>(by name, by ID)"]
    end

    subgraph "Data Sources"
        G["MJ: API Scopes"]
        H["MJ: API Applications"]
        I["MJ: API Application Scopes"]
        J["MJ: API Key Applications"]
        K["MJ: API Key Scopes"]
    end

    G --> A
    H --> A
    I --> A
    J --> A
    K --> A

    style A fill:#2d6a9f,stroke:#1a4971,color:#fff
    style B fill:#2d8659,stroke:#1a5c3a,color:#fff
    style C fill:#2d8659,stroke:#1a5c3a,color:#fff
    style D fill:#2d8659,stroke:#1a5c3a,color:#fff
    style E fill:#7c5295,stroke:#563a6b,color:#fff
    style F fill:#7c5295,stroke:#563a6b,color:#fff

Overview

The APIKeysEngineBase class extends MemberJunction's BaseEngine pattern to load and cache all API key-related metadata in memory. It is designed for fast, synchronous lookups after an initial asynchronous load.

Key capabilities:

  • Cached access to API scopes, applications, application scopes, key applications, and key scopes
  • Fast lookup maps for scopes (by path and ID) and applications (by name and ID)
  • Hierarchical scope path resolution (e.g., entity:read, agent:execute)
  • Application authorization checks for API keys
  • UI configuration parsing for scope display

Installation

npm install @memberjunction/api-keys-base

Usage

Initializing the Engine

import { APIKeysEngineBase } from '@memberjunction/api-keys-base';

// Initialize with metadata load
await APIKeysEngineBase.Instance.Config(false, contextUser);

// Force refresh of cached data
await APIKeysEngineBase.Instance.Config(true, contextUser);

Accessing Cached Data

const engine = APIKeysEngineBase.Instance;

// All scopes
const allScopes = engine.Scopes;
const activeScopes = engine.ActiveScopes;

// All applications
const apps = engine.Applications;

// Scope lookups
const scope = engine.GetScopeByPath('entity:read');
const scopeById = engine.GetScopeById('scope-guid');

// Application lookups
const app = engine.GetApplicationByName('MCP Server');
const appById = engine.GetApplicationById('app-guid');

Checking Key Authorization

// Check if a key is authorized for a specific application
const isAuthorized = engine.IsKeyAuthorizedForApplication(apiKeyId, applicationId);

// Get all scope rules for a key
const keyScopes = engine.GetKeyScopesByKeyId(apiKeyId);

// Get application ceiling rules
const appScopes = engine.GetApplicationScopesByApplicationId(applicationId);

Parsing Scope UI Configuration

import { parseAPIScopeUIConfig } from '@memberjunction/api-keys-base';

const uiConfig = parseAPIScopeUIConfig(scope);
console.log(uiConfig.icon);  // e.g., 'fa-solid fa-database'
console.log(uiConfig.color); // e.g., '#6366f1'

API Reference

APIKeysEngineBase

| Member | Type | Description | |--------|------|-------------| | Instance | static getter | Singleton instance | | Config() | method | Load/refresh all metadata | | Scopes | getter | All API scopes | | ActiveScopes | getter | Only active scopes | | Applications | getter | All API applications | | ApplicationScopes | getter | All application scope ceilings | | KeyApplications | getter | All key-to-application bindings | | KeyScopes | getter | All key-level scope rules | | GetScopeByPath() | method | Look up active scope by full path | | GetScopeById() | method | Look up scope by ID | | GetApplicationByName() | method | Look up application by name (case-insensitive) | | GetApplicationById() | method | Look up application by ID | | GetApplicationScopesByApplicationId() | method | Get scope ceilings for an application | | GetApplicationScopeRules() | method | Get scope rules for an application + scope | | GetKeyApplicationsByKeyId() | method | Get application bindings for a key | | GetKeyScopesByKeyId() | method | Get scope rules for a key | | GetKeyScopeRules() | method | Get scope rules for a key + scope | | KeyHasApplicationBindings() | method | Check if a key has any application bindings | | IsKeyAuthorizedForApplication() | method | Check if a key is authorized for an application |

APIScopeUIConfig

interface APIScopeUIConfig {
    icon?: string;  // Font Awesome icon class
    color?: string; // Hex color code
}

Relationship to @memberjunction/api-keys

This package provides the metadata caching layer that can be used anywhere (client or server). The @memberjunction/api-keys package builds on top of this with server-side operations including key generation, validation, scope evaluation, and usage logging.

graph LR
    A["@memberjunction/api-keys-base<br/>(Metadata Caching)"] --> B["@memberjunction/api-keys<br/>(Server-side Engine)"]
    C["Client Code<br/>(Angular, etc.)"] --> A
    D["Server Code<br/>(MJAPI, MCP)"] --> B

    style A fill:#2d6a9f,stroke:#1a4971,color:#fff
    style B fill:#2d8659,stroke:#1a5c3a,color:#fff
    style C fill:#b8762f,stroke:#8a5722,color:#fff
    style D fill:#b8762f,stroke:#8a5722,color:#fff

Dependencies

| Package | Purpose | |---------|---------| | @memberjunction/core | BaseEngine, UserInfo, IMetadataProvider | | @memberjunction/core-entities | Entity types (APIScopeEntity, etc.) | | @memberjunction/global | RegisterForStartup decorator |

License

ISC