Skip to main content
Version: 0.5.0 (Previous)

🔧 Common Blocks

Common blocks provide reusable building blocks that can be used across domains. This page documents utility blocks that are not specific to a single entity domain.


🎯 Overview

Common blocks are designed to:

  • Encapsulate reusable logic used across multiple flows
  • Standardize behavior (e.g., redirects, password generation)
  • Improve composability in route and feature chains

📋 Available Common Blocks

redirectTo

Redirects HTTP response to specified URL with optional status code.

Purpose: Finalizes flows by issuing an HTTP redirect.

Parameters:

  • response: Response — Express response object for HTTP redirection
  • url: string — Target URL to redirect to
  • statusCode?: number — Optional HTTP status code (defaults to 302)

Returns: Result<void, Error>

Handler Process:

  • Input: Express response object, target URL, and optional status code
  • Process: Calls Express response.redirect(statusCode, url)
  • Output: Result<void, Error> indicating redirect completion
  • Errors: Propagates errors from Express redirect if any occur

Example Usage:

// Used in route composition (inject response and URL from context/data):
const redirectRoute = withRoute({
handler: compose(
applyPayloadArgs(redirectTo, [
['context', 'response'],
['context', 'data', 'redirectUrl'],
// optional: provide status code if needed
// ['params', 'requestQuery', 'statusCode']
])
)
});

generateRandomPassword

Generates cryptographically secure random password with specified length.

Purpose: Produce secure random passwords for initial credentials or resets.

Parameters:

  • length?: number — Optional password length (defaults to 16)

Returns: string

Handler Process:

  • Input: Optional password length (defaults to 16 characters)
  • Process: Uses crypto.randomBytes and maps output to a mixed character set
  • Output: String containing a random password of the specified length
  • Errors: None (uses cryptographically secure random generation)

Example Usage:

// Generate default 16-character password:
const password = generateRandomPassword();

// Generate custom length password:
const longPassword = generateRandomPassword(32);