🚀 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
compose
function
🔧 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/channels
with 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/:channelId
with 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/:channelId
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/channels
with 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
- PATCH/channels/:channelId
with update handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.updateChannelFeature, [{ dataStores: db }])));
API Endpoint: PATCH /api/channels/:channelId
deleteChannelFeature
Deletes channels with proper authorization.
Purpose: Removes channels with access control
Composition:
- Schema:
deleteChatChannelSchema
- validates path parameters - Route:
deleteChatChannelRoute
- DELETE/channels/:channelId
with 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/:channelId
💬 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/messages
with 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/:messageId
with 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/:messageId
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/messages
with 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
- PATCH/messages/:messageId
with update handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.updateChatMessageFeature, [{ dataStores: db }])));
API Endpoint: PATCH /api/messages/:messageId
deleteChatMessageFeature
Deletes messages with proper authorization.
Purpose: Removes messages with access control
Composition:
- Schema:
deleteChatMessageSchema
- validates path parameters - Route:
deleteChatMessageRoute
- DELETE/messages/:messageId
with 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/:messageId
🔔 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/subscriptions
with 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/:subscriptionId
with 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/:subscriptionId
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/subscriptions
with 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/:subscriptionId
with 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/:subscriptionId