BaasixBaasix
Reference

Additional Features Documentation

← Back to Documentation Home

Table of Contents

  1. Email Templates
  2. Logo Customization
  3. Storage Services
  4. Cache Management
  5. TasksService
  6. Log Cleanup

Email Templates

BAASIX includes a powerful visual email template designer for creating and managing system email templates.

Template Designer Features

The email template designer provides:

  • Visual Email Editor — Intuitive HTML editor with live preview
  • Responsive Preview — Desktop, tablet, and mobile device previews
  • Variable Blocks — Pre-built blocks for template variables (user info, tenant details, auth links)
  • Code Editor — Direct HTML/CSS editing with CodeMirror syntax highlighting and Prettier formatting
  • Real-time Preview — See changes instantly as you design

Template Types

BAASIX supports various email template types:

  • magic_link — Magic link authentication emails
  • invite — User invitation emails
  • password_reset — Password reset emails
  • welcome — Welcome emails for new users
  • verification — Email verification emails
  • Custom templates for your application needs

Available Template Variables

Template variables are automatically replaced when sending emails:

User Variables:

VariableDescription
{{user.firstName}}User's first name
{{user.lastName}}User's last name
{{user.fullName}}User's full name
{{user.email}}User's email address
{{user.phone}}User's phone number

Tenant Variables:

VariableDescription
{{tenant.name}}Company/organization name
{{tenant.logo}}Company logo URL
{{tenant.website}}Company website
{{tenant.address}}Company address
{{tenant.phone}}Company phone
{{tenant.email}}Company email

Authentication Variables:

VariableDescription
{{magicLink}}Magic link URL
{{magicCode}}Magic code for authentication
{{resetPasswordLink}}Password reset link
{{verificationLink}}Email verification link
{{inviteLink}}User invitation link
{{loginLink}}Login page link

Date/Time Variables:

VariableDescription
{{currentDate}}Current date
{{currentTime}}Current time
{{currentYear}}Current year

Managing Templates via API

List Templates

GET /items/baasix_Template

Get Template

GET /items/baasix_Template/:id

Update Template

PATCH /items/baasix_Template/:id
Content-Type: application/json

{
  "subject": "Welcome to {{tenant.name}}",
  "body": "<HTML email template content>"
}

Template Storage Format

Templates are stored in the baasix_Template collection with:

  • type — Template type identifier (e.g., magic_link, invite)
  • subject — Email subject line (supports variables)
  • description — Template description
  • body — HTML email template content with Liquid variables
  • isActive — Whether the template is active

Using Templates Programmatically

import { MailService } from '@baasix/baasix';

// Send email using a template
await mailService.sendMail({
  to: 'user@example.com',
  templateType: 'welcome',
  context: {
    user: {
      firstName: 'John',
      lastName: 'Doe',
      email: 'john@example.com',
    },
    tenant: {
      name: 'Acme Corp',
      website: 'https://acme.com',
    },
  },
});

Admin Dashboard

The admin dashboard provides a full-featured template management interface:

  1. Template List — View all templates with type, subject, and status
  2. Quick Edit — Edit template subject and description via side panel
  3. Visual Designer — Full-page visual editor for template design
  4. Code Editor — Side-by-side HTML and CSS editing with formatting

Best Practices

  1. Use Inline CSS — Email clients have limited CSS support; use inline styles
  2. Test Across Clients — Preview templates in multiple email clients
  3. Keep It Simple — Complex layouts may not render correctly in all clients
  4. Use Tables for Layout — Many email clients still require table-based layouts
  5. Provide Fallbacks — Include alt text for images and plain text versions

Logo Customization

You can customize the logo used in email templates and potentially other parts of the application.

Default Logo Location

The default logo is located at:

baasix/templates/logo/logo.png

To use a custom logo, place your logo file at:

extensions/baasix-templates/logo/logo.png

The system will automatically use the custom logo if it exists, falling back to the default logo otherwise.

Storage Services

BAASIX supports multiple storage services for file handling.

Configuring Storage Services

Storage services are configured through environment variables:

STORAGE_SERVICES_ENABLED=local,s3
STORAGE_DEFAULT_SERVICE=local

Local Storage Configuration

LOCAL_STORAGE_PATH=/path/to/local/storage

S3 Storage Configuration

S3_STORAGE_ACCESS_KEY_ID=your_access_key
S3_STORAGE_SECRET_ACCESS_KEY=your_secret_key
S3_STORAGE_REGION=your_region
S3_STORAGE_BUCKET=your_bucket_name
S3_STORAGE_ENDPOINT=your_s3_endpoint

Cache Management

BAASIX includes a caching system to improve performance.

Cache Initialization

The cache is initialized in the server.js file:

await initializeCache({ ttl: process.env.CACHE_TTL * 1000 || 30000 });

Cache Configuration

Cache settings can be configured through environment variables:

CACHE_TTL=30000

Using the Cache

The cache can be used in various parts of the application to store and retrieve frequently accessed data:

const cache = getCache();
await cache.set('key', value, expiresIn);
const cachedValue = await cache.get('key');

TasksService

BAASIX includes a built-in TasksService for managing background tasks efficiently.

Overview

The TasksService manages background tasks from the baasix_Tasks table by:

  • Caching "Not started" tasks scheduled within 4 hours to reduce database calls and memory usage
  • Coordinating task execution to prevent concurrent processing
  • Automatically refreshing cache when tasks change (max refresh interval: 3 hours)
  • Providing graceful shutdown with task completion waiting

Quick Start

import tasksService from '../../baasix/services/TasksService';

// Check if a task is running
if (await tasksService.isTaskRunning()) {
  return; // Skip if already running
}

// Mark task as running
await tasksService.setTaskRunning(true);

try {
  // Get available tasks
  const tasks = await tasksService.getNotStartedTasks();
  // Process tasks...
} finally {
  await tasksService.setTaskRunning(false);
}

Environment Configuration

# Cache refresh interval in seconds (default: 600, maximum: 10800 = 3 hours)
TASK_LIST_REFRESH_INTERVAL=600

# Shutdown wait time in seconds (default: 30)
TASK_SHUTDOWN_WAIT_TIME=30

Note: Only tasks with scheduled_time within 4 hours are cached to optimize memory usage.

For Complete Documentation

See the dedicated TasksService Documentation for comprehensive usage examples, API reference, and best practices.


Log Cleanup

BAASIX includes automatic cleanup for audit logs and email logs to prevent unbounded database growth. By default, log cleanup is disabled and must be explicitly enabled via environment variables.

Environment Configuration

# =============================================================================
# AUDIT LOG CLEANUP
# =============================================================================

# Enable automatic audit log cleanup (default: false)
AUDIT_LOG_CLEANUP_ENABLED=true

# Audit log retention period in days (default: 90)
# Records older than this will be automatically deleted
AUDIT_LOG_RETENTION_DAYS=90

# =============================================================================
# EMAIL LOG CLEANUP
# =============================================================================

# Enable automatic email log cleanup (default: false)
EMAIL_LOG_CLEANUP_ENABLED=true

# Email log retention period in days (default: 30)
# Records older than this will be automatically deleted
EMAIL_LOG_RETENTION_DAYS=30

How It Works

When enabled, the log cleanup service:

  1. Starts automatically when the server starts
  2. Runs daily to delete old log entries
  3. Runs an initial cleanup 10 seconds after server startup
  4. Logs the number of deleted records to the console

Log Tables

TableDescriptionDefault Retention
baasix_AuditLogTracks all CRUD operations and authentication events90 days
baasix_EmailLogTracks all sent emails with status and metadata30 days

Manual Cleanup (Programmatic)

You can also trigger log cleanup programmatically from extensions or custom endpoints:

import { triggerLogCleanup } from '@baasix/baasix';

// Use environment configuration
const result = await triggerLogCleanup();
console.log(`Deleted ${result.auditLogs} audit logs, ${result.emailLogs} email logs`);

// Override configuration
const result = await triggerLogCleanup({
  auditLogs: true,
  emailLogs: true,
  auditLogRetentionDays: 30, // Custom retention
  emailLogRetentionDays: 7, // Custom retention
});

Best Practices

  1. Enable cleanup in production to prevent unbounded database growth
  2. Set appropriate retention periods based on compliance requirements
  3. Monitor disk space if cleanup is disabled
  4. Back up logs before enabling cleanup if you need historical data
  5. Consider compliance (GDPR, HIPAA) when setting retention periods

Disabling Cleanup

To disable automatic cleanup (default behavior):

AUDIT_LOG_CLEANUP_ENABLED=false
EMAIL_LOG_CLEANUP_ENABLED=false

When disabled, logs will accumulate indefinitely. You can still perform manual cleanup via the programmatic API or by directly deleting records from the database.


These additional features enhance the functionality and customization options of the BAASIX system. Proper utilization of email templates, logo customization, storage services, caching, task management, and log cleanup can significantly improve the user experience and performance of your application.

← Back to Documentation Home

On this page