@cravern/smart-app
v1.3.40
Published
Production-ready backend modules: MessageLog (webhook delivery), Authentication (MS OAuth + local), RBAC (multi-tenant access control), Dynamic Navigation, AI Chat (n8n webhook integration with conversational AI and dynamic form rendering) for enterprise
Downloads
176
Readme
@cravern/smart-app
Production-ready backend modules for enterprise applications: MessageLog, Authentication, RBAC, and Dynamic Navigation.
🎯 Overview
The Cravern Smart App package provides four independent, production-ready backend modules that can be used together or separately in your Node.js/Express applications:
- MessageLog Module - Webhook delivery with Kafka/n8n integration and retry logic
- Authentication Module - Microsoft OAuth + local login with session management
- RBAC Module - Multi-tenant role-based access control
- Dynamic Navigation Module - Database-driven responsive navigation
📦 Installation
npm install @cravern/smart-appPeer Dependencies
npm install express react react-dom drizzle-orm @neondatabase/serverless🚀 Quick Start
Using All Modules
import express from 'express';
import * as CravernSmartApp from '@cravern/smart-app';
const app = express();
// Register all module routes
CravernSmartApp.MessageLog.registerRoutes(app);
CravernSmartApp.Auth.registerAuthRoutes(app);
CravernSmartApp.RBAC.registerRBACRoutes(app);
CravernSmartApp.Navigation.registerNavigationRoutes(app);
app.listen(5000);Using Individual Modules
MessageLog Module
import { MessageLog } from '@cravern/smart-app';
// Start the message delivery daemon
MessageLog.messageLogDaemon.start();
// Register message routes
MessageLog.registerRoutes(app);
// Send a webhook message
const message = await storage.createMessage({
eventType: "order.created",
payload: { orderId: "123", total: 99.99 }
});Authentication Module
import { Auth } from '@cravern/smart-app';
// Register authentication routes
Auth.registerAuthRoutes(app);
// Protect routes
app.get('/api/protected', Auth.requireAuth, (req, res) => {
res.json({ user: req.user });
});
// Admin-only routes
app.get('/api/admin', Auth.requireAdmin, (req, res) => {
res.json({ message: 'Admin access granted' });
});RBAC Module
import { RBAC } from '@cravern/smart-app';
// Register RBAC routes
RBAC.registerRBACRoutes(app);
// Protect with permissions
app.get('/api/users',
RBAC.requirePermission('users', 'read'),
(req, res) => {
// Handle request
}
);
// Protect with roles
app.get('/api/system-settings',
RBAC.requireRole('system_admin'),
(req, res) => {
// Handle request
}
);Navigation Module
import { Navigation } from '@cravern/smart-app';
// Register navigation routes
Navigation.registerNavigationRoutes(app);
// Seed navigation data on startup
await Navigation.seedNavigationData();📚 Module Documentation
MessageLog Module
Handles webhook message delivery with intelligent retry logic:
Features:
- ✅ 90-day message retention with automatic cleanup
- ✅ Intelligent retry logic (30s → 5min → 30min intervals)
- ✅ Kafka and n8n integration support
- ✅ Background daemon for queue processing
- ✅ Monotonic attempt tracking across retries
API Endpoints:
POST /api/messages- Create messageGET /api/messages- List messagesGET /api/messages/:id- Get message detailsPOST /api/messages/:id/retry- Retry failed message
Example:
const message = await storage.createMessage({
eventType: "order.created",
payload: { orderId: "ORD-123", customerId: "CUST-456", total: 99.99 }
});Authentication Module
Complete authentication system with Microsoft OAuth and local login:
Features:
- ✅ Microsoft OAuth (Azure AD) integration
- ✅ Local username/password authentication
- ✅ Configurable registration flows
- ✅ Email verification system
- ✅ Session management with bcrypt hashing
- ✅ Multi-layer authentication (session, JWT cookies, Bearer tokens)
API Endpoints:
POST /api/auth/register- User registrationPOST /api/auth/login- Local loginGET /auth/microsoft- Microsoft OAuth loginPOST /api/auth/logout- LogoutGET /api/auth/me- Get current user
Environment Variables:
MICROSOFT_CLIENT_ID=your_client_id
MICROSOFT_CLIENT_SECRET=your_client_secret
SESSION_SECRET=your_session_secretRBAC Module
Enterprise-grade role-based access control with multi-tenant support:
Features:
- ✅ Multi-tenant organization isolation
- ✅ Custom roles and permissions
- ✅ Business units for department organization
- ✅ Security clearance levels (public to top_secret)
- ✅ Row-level security (ScopedStorage)
- ✅ Automatic permission creation for transactions
API Endpoints:
GET /api/organizations- List organizationsGET /api/roles- List rolesGET /api/permissions- List permissionsPOST /api/user-roles- Assign roles to usersGET /api/business-units- List business units
Example:
// Check user permission
if (req.securityContext?.hasPermission('users', 'delete')) {
// User has permission
}
// Check user role
if (req.securityContext?.hasRole('admin')) {
// User is admin
}Navigation Module
Database-driven responsive navigation with permission filtering:
Features:
- ✅ Database-stored navigation structure
- ✅ Permission-based menu filtering
- ✅ Responsive layouts (Desktop, Tablet, Mobile)
- ✅ Independent menu controls (sidebar vs bottom menu)
- ✅ Icon management with 80+ Lucide icons
- ✅ Transaction-based routing
API Endpoints:
GET /api/navigation/menu- Get side menu itemsGET /api/navigation/bottom-menu- Get bottom menu itemsGET /api/transactions- List all transactionsPATCH /api/transactions/:id- Update transaction settings
🗄️ Database Setup
The package uses PostgreSQL with Drizzle ORM:
# Set database URL
export DATABASE_URL=postgresql://user:password@host:port/database
# Push schema to database
npm run db:pushThe package automatically:
- Creates all required tables
- Seeds initial RBAC data
- Seeds navigation structure
- Sets up default permissions
🔧 Configuration
Environment Variables
# Database (required for production)
DATABASE_URL=postgresql://...
# Authentication
SESSION_SECRET=your_random_secret
MICROSOFT_CLIENT_ID=your_azure_client_id
MICROSOFT_CLIENT_SECRET=your_azure_secret
# MessageLog Webhooks
WEBHOOK_URL_KAFKA=https://kafka.example.com
WEBHOOK_URL_N8N=https://n8n.example.com/webhookTypeScript Configuration
{
"compilerOptions": {
"types": ["@cravern/smart-app"]
}
}🎨 Frontend Components
The package also includes React frontend components:
// Using namespace import
import { Client } from '@cravern/smart-app';
function App() {
return (
<Client.DesktopLayout>
<YourContent />
</Client.DesktopLayout>
);
}
// Or using direct subpath imports
import { Settings, UserManagement, IconPicker } from '@cravern/smart-app/client';
import { DesktopLayout } from '@cravern/smart-app/client';Available components:
DesktopLayout- Persistent sidebar layoutTabletLayout- Slide-out sidebar with footerMobileLayout- Bottom navigation with "More" sheetSettings- Complete settings page with tabsUserManagement- User management interfaceIconPicker- Icon selection componentHelpDialog- Context-sensitive helpAuthProvider,useAuth- Authentication context and hooksuseMenuItems,useBottomMenuItems- Navigation hooks
🔄 Updating
To get the latest version:
npm update @cravern/smart-appCheck the CHANGELOG for breaking changes and new features.
📖 Full Documentation
For detailed documentation on each module, see:
- MessageLog Module Documentation
- Authentication Module Documentation
- RBAC Module Documentation
- Navigation Module Documentation
- NPM Publishing Guide
🤝 Contributing
This package is maintained by Cravern. For issues or feature requests, please open an issue on GitHub.
📄 License
MIT License - see LICENSE for details.
🏗️ Built With
- Express.js - Web framework
- TypeScript - Type-safe development
- Drizzle ORM - Database ORM
- PostgreSQL - Database
- React - Frontend framework
- Passport.js - Authentication
- Lucide React - Icons
- Shadcn/ui - UI components
🔗 Links
Made with ❤️ by Cravern
