Lane Campbell 068dc5c194 fix: add timeout to logout helper for cookie clearing
Add 500ms timeout after logout to ensure cookies are properly cleared
before subsequent authentication checks.

Note: E2E tests have 27 failures that need investigation:
- Logout authentication check (cookies not clearing properly)
- Various timeout issues in collections, content, media, and plugin tests
- These appear to be timing/flakiness issues that need deeper investigation

๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 17:56:26 -07:00
2025-07-09 11:41:13 -04:00
2025-06-24 07:19:59 -07:00
2025-07-14 17:48:15 -04:00
2025-10-03 17:46:35 -07:00
2025-06-26 13:14:08 -07:00

SonicJS AI

A modern, TypeScript-first headless CMS built for Cloudflare's edge platform with Hono.js.

๐Ÿš€ Features

Core Platform

  • โšก Edge-First: Built specifically for Cloudflare Workers with global performance
  • ๐Ÿ”ง Developer-Centric: Configuration over UI, TypeScript-first approach
  • ๐Ÿค– AI-Friendly: Structured codebase designed for AI-assisted development
  • ๐Ÿ”Œ Plugin System: Extensible architecture without core modifications
  • ๐Ÿ“ฑ Modern Stack: Hono.js, TypeScript, D1, R2, and HTMX

Advanced Content Management (Stage 5)

  • ๐Ÿ“ Rich Text Editor: TinyMCE integration with customizable toolbars
  • ๐ŸŽ›๏ธ Dynamic Fields: Custom field types (text, number, date, boolean, select, media)
  • ๐Ÿ“š Content Versioning: Complete revision history with restore functionality
  • โฐ Content Scheduling: Publish/unpublish automation with date controls
  • ๐Ÿ”„ Workflow System: Draft โ†’ Review โ†’ Published โ†’ Archived with role-based permissions
  • ๐Ÿ’พ Auto-Save: Automatic content saving every 30 seconds
  • ๐Ÿ‘๏ธ Live Preview: Real-time content preview before publishing
  • ๐Ÿ“‹ Content Duplication: One-click content copying and templates
  • ๐Ÿ›ก๏ธ XSS Protection: Comprehensive input validation and HTML escaping

๐Ÿ›  Technology Stack

Core Framework

  • Hono.js - Ultrafast web framework for Cloudflare Workers
  • TypeScript - Strict type safety throughout
  • HTMX - Enhanced HTML for dynamic interfaces

Cloudflare Services

  • D1 - SQLite database at the edge
  • R2 - Object storage for media
  • Workers - Serverless compute runtime
  • KV - Key-value storage for caching
  • Images API - Image optimization and transformation

Development Tools

  • Vitest - Fast unit testing
  • Playwright - End-to-end testing
  • Wrangler - Local development and deployment
  • Drizzle ORM - Type-safe database queries

๐Ÿ Quick Start

Prerequisites

  • Node.js 20+
  • Cloudflare account
  • Wrangler CLI

Installation

# Clone the repository
git clone https://github.com/lane711/sonicjs-ai.git
cd sonicjs-ai

# Install dependencies
npm install

# Set up local development database
npm run db:migrate

# Start development server
npm run dev

Development Commands

# Start development server
npm run dev

# Run tests
npm test

# Run E2E tests
npm run test:e2e

# Build for production
npm run build

# Deploy to Cloudflare
npm run deploy

# Database operations
npm run db:generate    # Generate migrations
npm run db:migrate     # Apply migrations
npm run db:studio      # Open database studio

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ routes/           # Hono.js route handlers
โ”‚   โ”œโ”€โ”€ admin*.ts     # Admin interface routes
โ”‚   โ”œโ”€โ”€ api*.ts       # REST API endpoints
โ”‚   โ””โ”€โ”€ auth.ts       # Authentication routes
โ”œโ”€โ”€ templates/        # HTML templates & components
โ”‚   โ”œโ”€โ”€ layouts/      # Page layouts (admin, public)
โ”‚   โ”œโ”€โ”€ pages/        # Full page templates
โ”‚   โ””โ”€โ”€ components/   # Reusable UI components
โ”œโ”€โ”€ middleware/       # Hono.js middleware
โ”‚   โ””โ”€โ”€ auth.ts       # Authentication & authorization
โ”œโ”€โ”€ utils/           # Utility functions
โ”œโ”€โ”€ scripts/         # Database & deployment scripts
โ”œโ”€โ”€ migrations/      # Database migration files
โ””โ”€โ”€ tests/           # Unit & integration tests
    โ””โ”€โ”€ e2e/         # End-to-end test suites

๐Ÿ”ง Content Management

Creating Collections

SonicJS uses a dynamic field system. Create collections through the admin interface or define them in the database:

-- Example: Blog Posts collection with custom fields
INSERT INTO collections (id, name, display_name, description, schema) VALUES (
  'blog-posts', 'blog_posts', 'Blog Posts', 'Article content collection',
  '{"type":"object","properties":{"title":{"type":"string","required":true}}}'
);

-- Add dynamic fields
INSERT INTO content_fields (collection_id, field_name, field_type, field_label, field_options) VALUES
  ('blog-posts', 'title', 'text', 'Title', '{"maxLength": 200, "required": true}'),
  ('blog-posts', 'content', 'richtext', 'Content', '{"toolbar": "full", "height": 400}'),
  ('blog-posts', 'excerpt', 'text', 'Excerpt', '{"maxLength": 500, "rows": 3}'),
  ('blog-posts', 'featured_image', 'media', 'Featured Image', '{"accept": "image/*"}'),
  ('blog-posts', 'publish_date', 'date', 'Publish Date', '{"defaultToday": true}'),
  ('blog-posts', 'is_featured', 'boolean', 'Featured Post', '{"default": false}');

Field Types

  • text: Single-line text with validation
  • richtext: WYSIWYG editor with TinyMCE
  • number: Numeric input with min/max constraints
  • boolean: Checkbox with custom labels
  • date: Date picker with format options
  • select: Dropdown with single/multi-select
  • media: File picker with preview

๐ŸŒ API Endpoints

Content Management

  • GET /admin/content/new?collection=id - Create new content form
  • GET /admin/content/:id/edit - Edit content form
  • POST /admin/content/ - Create content with validation
  • PUT /admin/content/:id - Update content with versioning
  • DELETE /admin/content/:id - Delete content

Advanced Features

  • POST /admin/content/preview - Preview content before publishing
  • POST /admin/content/duplicate - Duplicate existing content
  • GET /admin/content/:id/versions - Get version history
  • POST /admin/content/:id/restore/:version - Restore specific version
  • GET /admin/content/:id/version/:version/preview - Preview historical version

Public API

  • GET /api/content - Get published content (paginated)
  • GET /api/collections/:collection/content - Get content by collection
  • GET /api/collections - List all collections

๐Ÿš€ Deployment

Development Setup

# Run database migrations (includes Stage 5 enhancements)
npm run db:migrate

# Apply Stage 5 schema updates
wrangler d1 migrations apply sonicjs-ai --local

Production Deployment

# Deploy to production
npm run deploy

# Deploy with custom environment
wrangler deploy --env production

# Apply migrations to production database
wrangler d1 migrations apply sonicjs-ai --remote

๐Ÿงช Testing

# Run unit tests
npm test

# Run tests in watch mode
npm run test:watch

# Run E2E tests
npm run test:e2e

# Run E2E tests with UI
npm run test:e2e:ui

๐Ÿ“š Documentation

๐Ÿ”Œ Plugin Development

Create plugins for extending SonicJS functionality:

// src/plugins/my-plugin/index.ts
import { Plugin } from '@sonicjs/core'

export default {
  name: 'my-plugin',
  hooks: {
    'content:beforeCreate': async (content) => {
      // Plugin logic here
      return content
    }
  }
} as Plugin

๐ŸŒŸ Why SonicJS AI?

Edge Performance

  • Global distribution via Cloudflare's network
  • Sub-100ms response times worldwide
  • Automatic scaling and DDoS protection

Developer Experience

  • TypeScript-first with full type safety
  • Hot reload development environment
  • Comprehensive CLI tools and generators

AI-Friendly Architecture

  • Clean, structured codebase
  • Comprehensive documentation
  • Clear conventions and patterns

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

We welcome contributions! Please see our contributing guidelines for more details.

๐Ÿ“ž Support


Built with โค๏ธ for the Cloudflare ecosystem

Description
SonicJS - The edge-native headless CMS for Cloudflare Workers. Sub-100ms response times, zero cold starts, TypeScript-first. Built on D1, R2, and Hono.
Readme MIT 210 MiB
Languages
TypeScript 75.8%
MDX 15.3%
HTML 6.6%
JavaScript 2.2%