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

we0-cms-api

v0.1.0

Published

A CMS API package for Next.js applications with dynamic table management

Readme

we0-cms-api

A powerful CMS API package for Next.js applications with dynamic table management and PostgreSQL support.

Features

  • 🚀 Dynamic table creation and management
  • 📊 RESTful API for models and data operations
  • 🔧 TypeScript support with full type definitions
  • 💾 PostgreSQL database with Sequelize ORM
  • 🎯 Easy integration with Next.js API routes
  • 📝 Comprehensive CRUD operations

Installation

npm install we0-cms-api
# or
yarn add we0-cms-api
# or
pnpm add we0-cms-api

Peer Dependencies

Make sure you have the following peer dependencies installed:

npm install next sequelize pg pg-hstore

Quick Start

1. Database Configuration

First, initialize the database connection in your Next.js app:

// lib/cms-config.ts
import { initializeDatabase, DatabaseConfig } from 'we0-cms-api'

const dbConfig: DatabaseConfig = {
  host: process.env.DB_HOST || 'localhost',
  port: parseInt(process.env.DB_PORT || '5432'),
  database: process.env.DB_NAME || 'cms_db',
  username: process.env.DB_USER || 'postgres',
  password: process.env.DB_PASSWORD || 'password',
  logging: process.env.NODE_ENV === 'development'
}

// Initialize database connection
initializeDatabase(dbConfig)

2. Create API Routes

Models Management API

Create app/api/cms/models/route.ts:

import { createModelRoute } from 'we0-cms-api'

export const { GET, POST, PUT, DELETE } = createModelRoute()

Dynamic Data Management API

Create app/api/cms/data/[tableName]/route.ts:

import { createDynamicDataRoute } from 'we0-cms-api'

export const { GET, POST, PUT, DELETE } = createDynamicDataRoute()

Alternative: One-liner Setup

Use the convenience function to create all routes at once:

// app/api/cms/models/route.ts
import { createCmsRoutes } from 'we0-cms-api'

const routes = createCmsRoutes()
export const { GET, POST, PUT, DELETE } = routes.models
// app/api/cms/data/[tableName]/route.ts  
import { createCmsRoutes } from 'we0-cms-api'

const routes = createCmsRoutes()
export const { GET, POST, PUT, DELETE } = routes.data

API Usage

Models API

GET /api/cms/models - Get all models

curl "http://localhost:3000/api/cms/models?page=1&limit=10&name=user"

POST /api/cms/models - Create a new model

curl -X POST "http://localhost:3000/api/cms/models" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "用户模型",
    "table_name": "users",
    "json_schema": {
      "fields": [
        {
          "name": "name",
          "type": "string",
          "required": true,
          "maxLength": 100,
          "comment": "用户姓名"
        },
        {
          "name": "email",
          "type": "email",
          "unique": true,
          "required": true,
          "comment": "用户邮箱"
        },
        {
          "name": "age",
          "type": "integer",
          "comment": "年龄"
        }
      ]
    }
  }'

PUT /api/cms/models - Update a model

curl -X PUT "http://localhost:3000/api/cms/models" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 1,
    "name": "更新的用户模型"
  }'

DELETE /api/cms/models?id=1 - Delete a model

curl -X DELETE "http://localhost:3000/api/cms/models?id=1"

Data API

GET /api/cms/data/users - Get table data

curl "http://localhost:3000/api/cms/data/users?page=1&limit=10&search=john"

POST /api/cms/data/users - Create new data

curl -X POST "http://localhost:3000/api/cms/data/users" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "[email protected]",
    "age": 30
  }'

PUT /api/cms/data/users - Update data

curl -X PUT "http://localhost:3000/api/cms/data/users" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 1,
    "name": "John Smith",
    "age": 31
  }'

DELETE /api/cms/data/users?id=1 - Delete data

curl -X DELETE "http://localhost:3000/api/cms/data/users?id=1"

Advanced Usage

Custom Service Usage

import { 
  initializeDatabase, 
  getDynamicTableService, 
  initializeCmsModel,
  DatabaseConfig 
} from 'we0-cms-api'

// Initialize database
const dbConfig: DatabaseConfig = { /* your config */ }
initializeDatabase(dbConfig)

// Use the dynamic table service directly
const tableService = getDynamicTableService()

// Create a custom table
await tableService.createTable('custom_table', {
  fields: [
    { name: 'title', type: 'string', required: true },
    { name: 'content', type: 'text' }
  ]
})

// Use the CMS model directly
const CmsModel = initializeCmsModel()
const models = await CmsModel.findAll()

Type Definitions

import type { 
  JsonSchema, 
  SchemaField, 
  CmsModelAttributes,
  ApiResponse,
  PaginatedResponse 
} from 'we0-cms-api'

// Define your schema
const userSchema: JsonSchema = {
  fields: [
    {
      name: 'username',
      type: 'string',
      required: true,
      unique: true,
      maxLength: 50
    },
    {
      name: 'profile',
      type: 'json'
    }
  ]
}

Environment Variables

Create a .env.local file in your project root:

DB_HOST=localhost
DB_PORT=5432
DB_NAME=cms_db
DB_USER=postgres
DB_PASSWORD=your_password

Field Types

Supported field types for JSON schema:

  • string - Variable length string
  • text - Long text
  • integer - Integer number
  • float - Floating point number
  • boolean - True/false value
  • date - Date only
  • datetime - Date and time
  • json - JSON object
  • email - Email string (validated as string)

Error Handling

All API responses follow a consistent format:

interface ApiResponse<T = any> {
  success: boolean
  message?: string
  data?: T
  error?: string
}

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT

Support

For support, please open an issue on the GitHub repository or contact the maintainers.