This directory contains utility functions, business logic, and service modules.
lib/
├── config.ts # Configuration management
├── constants.ts # Application constants and limits
├── feature-flags.ts # Feature flag system
├── utils.ts # General utility functions (cn, etc.)
├── config.test.ts # Configuration tests
├── constants.test.ts # Constants tests
└── [future modules will be added here]
- Type-safe access to Cloudflare environment variables
- Feature flags based on available services
- Environment detection (development/production)
- Application URL helpers
- File size limits (500KB/file, 5MB/gist, 20 files)
- Expiry durations for gists
- HTTP status codes
- Validation helpers for files, PINs, and expiry options
- Binary format constants
- Cache control headers
- Advanced feature flag system with gradual rollout
- Percentage-based feature rollouts
- User-specific feature targeting
- Runtime feature toggling without deployments
crypto.ts- Encryption/decryption utilities using Web Crypto APIstorage.ts- Cloudflare R2 storage client wrapperbinary.ts- Binary format encoding/decoding for file storageauth.ts- PIN hashing and validation
logger.ts- Structured logging utilityerrors.ts- Custom error classes and handlingvalidation.ts- Input validation helpers
- All modules must be edge runtime compatible (no Node.js APIs)
- Use Web Crypto API for cryptographic operations
- Export functions and constants as named exports
- Write pure functions where possible
- Include comprehensive error handling
- Add JSDoc comments for public APIs
All code in this directory must work in Cloudflare Workers:
- No
fs,path, or other Node.js modules - Use Web APIs (fetch, crypto, etc.)
- Keep bundle sizes small
- Consider CPU time limits (50ms)
- Handle streaming for large data