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

@egdesk/next-api-plugin

v1.5.0

Published

Next.js plugin for EGDesk database proxy integration

Readme

@egdesk/next-api-plugin

Next.js plugin for EGDesk database proxy integration. Provides middleware-based CORS-free database access for Next.js applications.

Features

  • 🔒 CORS-free database access via Next.js middleware (or proxy.ts on Next.js 16+)
  • 🌐 Works in both local and tunneled environments
  • 📝 Type-safe table definitions and helper functions (user data, FinanceHub, internal knowledge / business identity / company research, browser recording)
  • 🚀 Auto-discovery of database tables
  • 🔧 Zero configuration after setup

Installation

npm install @egdesk/next-api-plugin
# or
yarn add @egdesk/next-api-plugin
# or
pnpm add @egdesk/next-api-plugin

Quick Start

  1. Run the setup command in your Next.js project:
npx egdesk-next-setup

This will generate:

  • middleware.ts - Database proxy middleware
  • egdesk.config.ts - Type-safe table definitions
  • egdesk-helpers.ts - Helper functions for database access
  • .env.local - Environment variables
  1. Add .env.local to your .gitignore (if not already there)

  2. Restart your Next.js dev server

  3. Use the helpers in your components:

import { queryTable } from './egdesk-helpers';
import { TABLES } from './egdesk.config';

export default async function MyPage() {
  const data = await queryTable(TABLES.table1.name, { limit: 10 });

  return (
    <div>
      <pre>{JSON.stringify(data, null, 2)}</pre>
    </div>
  );
}

Configuration

Environment Variables

The plugin uses Next.js environment variables:

NEXT_PUBLIC_EGDESK_API_URL=http://localhost:8080
NEXT_PUBLIC_EGDESK_API_KEY=your-api-key-here

Custom Setup

You can programmatically run the setup:

import { setupNextApiPlugin } from '@egdesk/next-api-plugin';

await setupNextApiPlugin('/path/to/project', {
  egdeskUrl: 'http://localhost:8080',
  apiKey: 'optional-api-key'
});

How It Works

The plugin generates middleware.ts or proxy.ts that intercepts special paths and forwards them to your EGDesk HTTP MCP server so the browser never talks to another origin directly.

Proxied paths (examples):

| Path | Forwards to | |------|-------------| | __user_data_proxy | POST /user-data/tools/call | | __browser_recording_proxy | POST /browser-recording/tools/call | | __internal_knowledge_proxy | POST /internal-knowledge/tools/call (knowledge docs, business identity snapshots, company research) |

User-data request flow:

  1. Your code calls queryTable() or another helper
  2. Helper fetches __user_data_proxy
  3. Middleware/proxy forwards to http://<EGDESK>/user-data/tools/call
  4. Parsed JSON is returned to your component

API Reference

Helper Functions

// Query table data
queryTable(tableName: string, options?: {
  filters?: Record<string, string>;
  limit?: number;
  offset?: number;
  orderBy?: string;
  orderDirection?: 'ASC' | 'DESC';
})

// Search table
searchTable(tableName: string, searchQuery: string, limit?: number)

// Aggregate data
aggregateTable(tableName: string, column: string, aggregateFunction: 'SUM' | 'AVG' | 'MIN' | 'MAX' | 'COUNT', options?: {
  filters?: Record<string, string>;
  groupBy?: string;
})

// Execute raw SQL
executeSQL(query: string)

// List all tables
listTables()

// Get table schema
getTableSchema(tableName: string)

// Internal Knowledge / Business Identity / Company Research (MCP)
callInternalKnowledgeTool(toolName: string, args?: Record<string, any>)
listKnowledgeDocuments(snapshotId: string, category?: 'hierarchy' | 'process' | 'policy' | 'note')
getKnowledgeDocument(documentId: string)
searchKnowledgeContent(snapshotId: string, searchText: string, category?: ...)
getKnowledgeByCategory(snapshotId: string, category: ...)
listBusinessIdentitySnapshots(brandKey?: string)
getBusinessIdentitySnapshot(snapshotId: string)
getBusinessIdentityCompanyInfo(snapshotId: string)
getBusinessIdentityServicesProducts(snapshotId: string)
listCompanyResearch(status?: 'completed' | 'failed' | 'in_progress')
getCompanyResearchById(researchId: string)
getCompanyResearchByDomain(domain: string)
searchCompanyResearch(searchText: string)

Configuration Types

interface TableDefinition {
  name: string;
  displayName: string;
  description?: string;
  rowCount: number;
  columnCount: number;
  columns: string[];
}

const TABLES = {
  table1: TableDefinition,
  table2: TableDefinition,
  // ...
}

const TABLE_NAMES = {
  table1: 'actual_table_name',
  table2: 'another_table_name',
  // ...
}

Troubleshooting

Middleware not working

Make sure:

  • middleware.ts is in your project root (not in src/ or app/)
  • Your Next.js version is 13.0.0 or higher
  • You've restarted your dev server after setup

CORS errors

If you're still seeing CORS errors:

  • Check that middleware.ts was generated correctly
  • Verify environment variables are set in .env.local
  • Make sure you're using the relative URL __user_data_proxy (no leading slash)

Table discovery fails

Ensure:

  • EGDesk MCP server is running on localhost:8080
  • You have tables imported in EGDesk
  • API key is correct (if required)

License

MIT