Best Practices
Code Organization
Security
1. Environment Variables
# .env.example
LOMI_API_KEY=
LOMI_WEBHOOK_SECRET=
NODE_ENV=development
# .gitignore
.env
.env.local
*.log
2. Sensitive Data
// Redact sensitive information in logs
const sanitizeData = (data: any) => {
const masked = { ...data };
if (masked.apiKey) masked.apiKey = '[REDACTED]';
if (masked.phoneNumber) masked.phoneNumber = '[REDACTED]';
return masked;
};
Testing
Git Workflow
1. Branch Management
# Keep branches focused and short-lived
git checkout -b feature/add-wave-provider
git commit -m "feat(payments): implement Wave provider"
git push origin feature/add-wave-provider
2. Commit Messages
# Format: <type>(<scope>): <description>
feat(auth): add API key rotation
fix(webhook): handle timeout errors
docs(api): update authentication guide
Documentation
1. Code Comments
/**
* Process a payment request
* @param request - Payment request details
* @returns Promise resolving to payment result
* @throws {ValidationError} If request is invalid
*/
async function processPayment(
request: PaymentRequest
): Promise<PaymentResult> {
// Implementation
}
2. README Files
# Component Name
## Overview
Brief description of the component's purpose
## Usage
Code examples and usage instructions
## Configuration
Available configuration options
## Testing
How to run and write tests
Deployment
1. CI/CD
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm ci
- run: npm test
2. Version Control
{
"name": "@lomi/api",
"version": "1.2.3",
"engines": {
"node": ">=14"
}
}