0.2.2 • Published 7 months ago
@shoraheadless/nextjs v0.2.2
@shoraheadless/nextjs
Enterprise-grade headless CMS framework for Next.js applications.
Features
🚀 Core Features
- Next.js 14 Support: Full support for App Router and Server Components
- TypeScript First: Complete type safety and IntelliSense support
- Edge Computing: Global edge network with automatic routing
- Enterprise Security: RBAC, audit logging, and security best practices
💪 Performance
- Edge Caching: Intelligent caching at the edge
- Asset Optimization: Automatic image optimization and CDN delivery
- Smart Prefetching: Predictive loading for faster navigation
- Adaptive Delivery: Content delivery optimized for user's device and network
🛡️ Security
- Role-Based Access Control: Fine-grained access control
- Audit Logging: Comprehensive activity tracking
- Rate Limiting: Protection against abuse
- CORS & Security Headers: Secure by default
🎨 Developer Experience
- React Hooks: Intuitive hooks for common operations
- TypeScript Support: Full type safety and autocompletion
- Error Handling: Detailed error messages and stack traces
- Monitoring: Built-in performance monitoring
Installation
npm install @shoraheadless/nextjs
# or
yarn add @shoraheadless/nextjs
# or
pnpm add @shoraheadless/nextjs
Quick Start
// app/providers.tsx
import { ShoraProvider } from '@shoraheadless/nextjs'
export function Providers({ children }) {
return (
<ShoraProvider
config={{
projectId: 'your-project-id',
apiKey: 'your-api-key',
}}
>
{children}
</ShoraProvider>
)
}
// app/page.tsx
import { useShora } from '@shoraheadless/nextjs'
export default function Page() {
const { client } = useShora()
// Use client methods...
}
Advanced Usage
Edge Computing
import { useShora } from '@shoraheadless/nextjs'
export default function Page() {
const { edge } = useShora()
const data = await edge.process(async (context) => {
// Access edge context (region, country, etc.)
console.log(context.region)
// Return data that will be cached at the edge
return {
products: await fetchProducts(),
}
})
}
Image Optimization
import { useShoraImage } from '@shoraheadless/nextjs'
export default function Image() {
const { src, blur, width, height } = useShoraImage('https://example.com/image.jpg', {
width: 800,
quality: 80,
format: 'webp',
preload: true,
})
return (
<img
src={src}
width={width}
height={height}
loading="lazy"
style={{ backgroundImage: blur }}
/>
)
}
Role-Based Access Control
import { useShora } from '@shoraheadless/nextjs'
export default function AdminPanel() {
const { client } = useShora()
// Check permissions
await client.rbac.enforce({
roles: ['admin'],
resource: 'admin-panel',
action: 'view',
})
return <div>Admin Panel Content</div>
}
Audit Logging
import { useShora } from '@shoraheadless/nextjs'
export default function UserActions() {
const { client } = useShora()
const handleAction = async () => {
await client.audit.log({
type: 'data',
severity: 'info',
action: 'user.update',
resource: {
type: 'user',
id: '123',
},
changes: {
before: { name: 'Old Name' },
after: { name: 'New Name' },
},
})
}
}
Configuration
Full Configuration Options
interface ShoraConfig {
// Core
projectId: string
apiKey: string
environment?: 'development' | 'production'
// Edge Computing
edge?: {
enabled: boolean
regions?: string[]
cachingEnabled?: boolean
cacheTtl?: number
}
// Asset Optimization
assets?: {
cdnUrl?: string
defaultImageOptions?: {
quality?: number
format?: 'webp' | 'avif'
}
imageDomains?: string[]
}
// Security
rbac?: {
rules: RBACRule[]
defaultAllow?: boolean
}
// Monitoring
monitoring?: {
enabled: boolean
sampleRate?: number
metricsEndpoint?: string
}
// Audit Logging
audit?: {
enabled: boolean
destination?: 'console' | 'file' | 'remote'
logLevel?: 'info' | 'warning' | 'error'
}
}
Contributing
We welcome contributions! Please see our Contributing Guide for details.
License
MIT License - see LICENSE for details.