@budgetbuddyde/api
About
A type-safe, Zod-validated API client for BudgetBuddy backend services. This package provides a unified interface for communicating with all backend endpoints and offers runtime validation as well as full TypeScript support.
The package can be installed via NPM:
Getting Started
Basic Usage
CRUD Operations
All entity services provide standard CRUD operations:
Query Parameters
Many endpoints support query parameters for filtering and pagination:
Error Handling
The package uses a TResult<T, E> pattern for type-safe error handling:
Custom Request Configuration
For advanced usage, request options can be passed:
Development
Build
Compiles TypeScript to JavaScript in the lib/ folder.
Tests
Code Quality
API Reference
Available Services
| Service | Description | Endpoint |
|---|---|---|
api.backend.category | Category management | /api/category |
api.backend.paymentMethod | Payment methods | /api/paymentMethod |
api.backend.transaction | Transactions | /api/transaction |
api.backend.recurringPayment | Recurring payments | /api/recurringPayment |
api.backend.budget | Budget management | /api/budget |
Common Methods
All services inherit from EntityService and provide:
Type Safety
The package leverages Zod for runtime validation combined with TypeScript for compile-time safety:
Project Structure
Architecture Components
1. API Class (api.ts)
The central entry point that aggregates all service instances:
2. Entity Service (services/entity.service.ts)
Abstract base class for all entity services with generic CRUD operations:
getAll(query?, config?)- Fetch all entitiesgetById(id, config?)- Fetch single entitycreate(payload, config?)- Create new entityupdateById(id, payload, config?)- Update entitydeleteById(id, config?)- Delete entity
Features:
- Automatic Zod validation of all responses
- Type-safe request/response handling
- Query parameter serialization
- Error handling and error types
- Request config merging
3. Specialized Services (services/*.service.ts)
Extend EntityService with domain-specific methods:
4. Type System (types/)
Schemas (types/schemas/)
Zod schemas for runtime validation:
Types (types/*.type.ts)
TypeScript types, often derived from Zod schemas:
Common Types (types/common.ts)
Shared type helpers:
TResult<T, E>- Result type for error handlingTApiResponse<Schema>- API response helperTypeOfSchema<Schema>- Schema-to-type converter
Interfaces (types/interfaces/)
TypeScript interfaces for structure definitions:
5. Error Handling (error.ts)
Custom error classes for various error scenarios:
CustomError- Base error classApiError- General API errorsBackendError- HTTP status errors from backendResponseNotJsonError- Response is not valid JSON
BudgetBuddyDE