🚀 Chat Feature Blocks
Chat feature blocks provide complete, pre-composed functionality for chat management operations in Nodeblocks applications. These features combine schemas, routes, and handlers to create ready-to-use API endpoints with proper validation, authentication, and error handling.
🎯 Overview
Chat feature blocks are designed to:
- Provide complete API endpoints for chat management operations
- Combine schemas with routes for validated operations
- Include authentication and authorization checks automatically
- Support functional composition patterns
- Handle logging and error management seamlessly
This documentation is organized into three main subsections:
- 📺 Channel Features: Manage chat channels (create, read, update, delete, search)
- 💬 Message Features: Handle chat messages (create, read, update, delete, search)
- 🔔 Subscription Features: Manage user subscriptions to channels (create, read, delete, search)
📋 Feature Structure
Each chat feature follows a consistent composition pattern:
- Schema: Validates input data and parameters
- Route: Provides HTTP endpoint with handlers
- Composition: Combines schema and route using
composefunction
🔧 Available Chat Features
📺 Channel Features
createChannelFeature
Creates a new chat channel with validation and routing.
Purpose: Handles channel creation with complete validation
Composition:
- Schema:
createChatChannelSchema- validates name and ownerId - Route:
createChatChannelRoute- POST/channelswith creation handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.createChannelFeature, [{ dataStores: db }])));
API Endpoint: POST /api/channels
getChannelFeature
Retrieves individual channel data with access control.
Purpose: Fetches channel details with proper authorization
Composition:
- Schema:
getChatChannelSchema- validates path parameters - Route:
getChatChannelRoute- GET/channels/:idwith retrieval handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.getChannelFeature, [{ dataStores: db }])));
API Endpoint: GET /api/channels/:id
findChannelsFeature
Searches and lists channels with filtering and pagination.
Purpose: Provides channel listing with search capabilities
Composition:
- Schema:
findChatChannelsSchema- validates query parameters for filtering - Route:
findChatChannelsRoute- GET/channelswith search and pagination
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.findChannelsFeature, [{ dataStores: db }])));
API Endpoint: GET /api/channels
updateChannelFeature
Updates channel information with validation and access control.
Purpose: Modifies channel data with proper authorization
Composition:
- Schema:
updateChatChannelSchema- validates optional name and ownerId - Route:
updateChatChannelRoute- PUT/channels/:idwith update handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.updateChannelFeature, [{ dataStores: db }])));
API Endpoint: PUT /api/channels/:id
deleteChannelFeature
Deletes channels with proper authorization.
Purpose: Removes channels with access control
Composition:
- Schema:
deleteChatChannelSchema- validates path parameters - Route:
deleteChatChannelRoute- DELETE/channels/:idwith deletion handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.deleteChannelFeature, [{ dataStores: db }])));
API Endpoint: DELETE /api/channels/:id
💬 Message Features
createChatMessageFeature
Creates a new chat message with validation and routing.
Purpose: Handles message creation with complete validation
Composition:
- Schema:
createChatMessageSchema- validates content, senderId, and channelId - Route:
createChatMessageRoute- POST/messageswith creation handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.createChatMessageFeature, [{ dataStores: db }])));
API Endpoint: POST /api/messages
getChatMessageFeature
Retrieves individual message data with access control.
Purpose: Fetches message details with proper authorization
Composition:
- Schema:
getChatMessageSchema- validates path parameters - Route:
getChatMessageRoute- GET/messages/:idwith retrieval handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.getChatMessageFeature, [{ dataStores: db }])));
API Endpoint: GET /api/messages/:id
findChatMessagesFeature
Searches and lists messages with filtering and pagination.
Purpose: Provides message listing with search capabilities
Composition:
- Schema:
findChatMessagesSchema- validates query parameters for filtering - Route:
findChatMessagesRoute- GET/messageswith search and pagination
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.findChatMessagesFeature, [{ dataStores: db }])));
API Endpoint: GET /api/messages
updateChatMessageFeature
Updates message content with validation and access control.
Purpose: Modifies message data with proper authorization
Composition:
- Schema:
updateChatMessageSchema- validates optional content and metadata - Route:
updateChatMessageRoute- PUT/messages/:idwith update handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.updateChatMessageFeature, [{ dataStores: db }])));
API Endpoint: PUT /api/messages/:id
deleteChatMessageFeature
Deletes messages with proper authorization.
Purpose: Removes messages with access control
Composition:
- Schema:
deleteChatMessageSchema- validates path parameters - Route:
deleteChatMessageRoute- DELETE/messages/:idwith deletion handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.deleteChatMessageFeature, [{ dataStores: db }])));
API Endpoint: DELETE /api/messages/:id
🔔 Subscription Features
createChatSubscriptionFeature
Creates a new chat subscription with validation and routing.
Purpose: Handles subscription creation with complete validation
Composition:
- Schema:
createChatSubscriptionSchema- validates channelId and optional fields - Route:
createChatSubscriptionRoute- POST/subscriptionswith creation handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.createChatSubscriptionFeature, [{ dataStores: db }])));
API Endpoint: POST /api/subscriptions
getChatSubscriptionFeature
Retrieves individual subscription data with access control.
Purpose: Fetches subscription details with proper authorization
Composition:
- Schema:
getChatSubscriptionSchema- validates path parameters - Route:
getChatSubscriptionRoute- GET/subscriptions/:idwith retrieval handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.getChatSubscriptionFeature, [{ dataStores: db }])));
API Endpoint: GET /api/subscriptions/:id
findChatSubscriptionsFeature
Searches and lists subscriptions with filtering and pagination.
Purpose: Provides subscription listing with search capabilities
Composition:
- Schema:
findChatSubscriptionsSchema- validates query parameters for filtering - Route:
findChatSubscriptionsRoute- GET/subscriptionswith search and pagination
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.findChatSubscriptionsFeature, [{ dataStores: db }])));
API Endpoint: GET /api/subscriptions
deleteChatSubscriptionFeature
Deletes subscriptions with proper authorization.
Purpose: Removes subscriptions with access control
Composition:
- Schema:
deleteChatSubscriptionSchema- validates path parameters - Route:
deleteChatSubscriptionRoute- DELETE/subscriptions/:idwith deletion handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.deleteChatSubscriptionFeature, [{ dataStores: db }])));
API Endpoint: DELETE /api/subscriptions/:id