メインコンテンツまでスキップ
バージョン: 🚧 Canary

🚀 User Features

User features provide complete, pre-composed functionality for user 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

User features are designed to:

  • Provide complete API endpoints for user 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

📋 Feature Structure

Each user 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 User Features

createUserFeature

Creates a new user account with validation and routing.

Purpose: Handles user registration with complete validation

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database configuration
app.use('/api', defService(partial(features.createUserFeature, [{ dataStores: db }])));

API Endpoint: POST /api/users


getUserFeatures

Retrieves individual user data with access control.

Purpose: Fetches user profile data with proper authorization

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database configuration
app.use('/api', defService(partial(features.getUserFeatures, [{ dataStores: db }])));

API Endpoint: GET /api/users/:profileId


findUsersFeatures

Searches and lists users with filtering and pagination.

Purpose: Provides user listing with search capabilities

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database configuration
app.use('/api', defService(partial(features.findUsersFeatures, [{ dataStores: db }])));

API Endpoint: GET /api/users


editUserFeatures

Updates user profile data with validation and access control.

Purpose: Modifies user data with proper authorization

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database configuration
app.use('/api', defService(partial(features.editUserFeatures, [{ dataStores: db }])));

API Endpoint: PATCH /api/users/:profileId


deleteUserFeatures

Deletes user accounts with proper authorization.

Purpose: Removes user accounts with access control

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With database configuration
app.use('/api', defService(partial(features.deleteUserFeatures, [{ dataStores: db }])));

API Endpoint: DELETE /api/users/:profileId


getAvatarUploadUrlFeature

User avatar upload URL generation feature with schema validation and routing.

Purpose: Generates pre-signed URLs for secure avatar file uploads with automatic UUID filename generation

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';


// With file storage service in configuration:
app.use('/api', defService(partial(features.getAvatarUploadUrlFeature, [{ configuration: { fileStorageDriver } }])));

API Endpoint: GET /api/user-profiles/:profileId/avatar-upload-url


findProfilesByIdentityIdFeature

User profile retrieval by identity ID feature with schema validation and routing.

Purpose: Retrieves paginated user profiles associated with a specific identity ID with avatar normalization and self-access control

Composition:

Usage:

import { features } from '@nodeblocks/backend-sdk';

// Direct usage:
app.use('/api', defService(findProfilesByIdentityIdFeature));

// With database configuration
app.use('/api', defService(partial(findProfilesByIdentityIdFeature, [{ dataStores: db }])));

API Endpoint: GET /api/profiles/identities/:identityId

Response Format:

{
"data": [
{
"id": "profile-123",
"name": "John Doe",
"avatar": {
"url": "https://cdn.example.com/avatars/profile-123.jpg",
"type": "image/jpeg"
},
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
],
"metadata": {
"pagination": {
"hasNext": false,
"hasPrev": false,
"limit": 10,
"page": 1,
"total": 1,
"totalPages": 1
}
}
}

Authorization: Requires authentication and self-access (users can only view their own profiles by identity)