Common Package¶
Overview¶
The @delta/common package provides shared utilities, types, and functionality used across all other packages in the Delta monorepo. This package serves as the foundation for consistent logging, environment handling, and common enums throughout the application.
Purpose¶
- Centralized logging functionality with Winston and Loki integration
- Shared enums and constants
- Common utility functions for environment detection
- Type definitions used across multiple packages
Key Components¶
Logger¶
- Location:
src/logger/index.ts - Purpose: Provides a unified logging interface with environment-aware configuration
- Features:
- Winston-based logging with Loki integration
- Environment-specific log levels
- Structured logging format
- Async log flushing capability
Enums¶
- Location:
src/enums/ - Components:
Environment: Defines different logging environments (development, staging, production)
Utilities¶
- Location:
src/utils/ - Components:
environment.ts: Environment detection and configuration utilities
Installation¶
This package is automatically installed as a dependency when setting up the monorepo. It's managed through the workspace configuration.
Usage¶
import { Environment, createLogger, getEnvironment } from '@delta/common';
// Create a logger
const logger = createLogger('my-app');
logger.info('Application started');
logger.error('Something went wrong', error);
logger.warn('This is a warning');
logger.debug('Debug information');
// Flush logs (if Loki transport is available)
if (logger.flushLogs) {
await logger.flushLogs();
}
// Use environment utilities
const env = getEnvironment();
if (env === Environment.PRODUCTION) {
// Production-specific logic
}
Environment Variables¶
The logger supports the following environment variables:
NODE_ENV: Environment detection (development, staging, production)LOKI_URL: Loki server URL for log aggregationLOKI_USER: Loki authentication usernameLOKI_PASSWORD: Loki authentication passwordSEND_DEV_LOGS_TO_LOKI: Set to 'true' to send development logs to Loki
Testing¶
The package includes comprehensive unit tests for all components:
- Jest configuration:
jest.config.js - Test setup:
jest.setup.js - Test files:
*.test.tsfiles alongside source code
Running Tests¶
# From the package directory
yarn test
# Run tests in watch mode
yarn run test:watch
# Run tests with coverage
yarn run test:coverage
Dependencies¶
- Runtime: Winston, Winston-Loki
- Development: Jest, TypeScript, ts-jest
Build¶
The package is built using TypeScript compiler with configuration in tsconfig.json.
# Build the package
yarn run build
# Development mode with watch
yarn run dev
Exports¶
The package provides multiple export paths:
.- Main exports (all functionality)./enums- Enum definitions only./logger- Logger functionality only./utils/environment- Environment utilities only
Integration¶
This package is consumed by:
@delta/app- For client-side logging and utilities, backend apis and Sana@delta/aiHub- For server-side logging- Lambda functions - For consistent logging across serverless functions