@budgetbuddyde/api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +366 -0
  3. package/lib/api.d.ts +17 -0
  4. package/lib/api.js +22 -0
  5. package/lib/budget.d.ts +3 -0
  6. package/lib/budget.js +19 -0
  7. package/lib/category.d.ts +3 -0
  8. package/lib/category.js +19 -0
  9. package/lib/error.d.ts +33 -0
  10. package/lib/error.js +55 -0
  11. package/lib/index.d.ts +6 -0
  12. package/lib/index.js +22 -0
  13. package/lib/paymentMethod.d.ts +3 -0
  14. package/lib/paymentMethod.js +19 -0
  15. package/lib/recurringPayment.d.ts +4 -0
  16. package/lib/recurringPayment.js +20 -0
  17. package/lib/services/budget.service.d.ts +8 -0
  18. package/lib/services/budget.service.js +43 -0
  19. package/lib/services/category.service.d.ts +24 -0
  20. package/lib/services/category.service.js +98 -0
  21. package/lib/services/entity.service.d.ts +31 -0
  22. package/lib/services/entity.service.js +185 -0
  23. package/lib/services/paymentMethod.service.d.ts +15 -0
  24. package/lib/services/paymentMethod.service.js +64 -0
  25. package/lib/services/recurringPayment.service.d.ts +43 -0
  26. package/lib/services/recurringPayment.service.js +26 -0
  27. package/lib/services/transaction.service.d.ts +43 -0
  28. package/lib/services/transaction.service.js +46 -0
  29. package/lib/transaction.d.ts +4 -0
  30. package/lib/transaction.js +20 -0
  31. package/lib/types/budget.type.d.ts +5 -0
  32. package/lib/types/budget.type.js +2 -0
  33. package/lib/types/category.type.d.ts +6 -0
  34. package/lib/types/category.type.js +2 -0
  35. package/lib/types/common.d.ts +15 -0
  36. package/lib/types/common.js +2 -0
  37. package/lib/types/index.d.ts +6 -0
  38. package/lib/types/index.js +22 -0
  39. package/lib/types/interfaces/index.d.ts +3 -0
  40. package/lib/types/interfaces/index.js +19 -0
  41. package/lib/types/interfaces/query.interface.d.ts +14 -0
  42. package/lib/types/interfaces/query.interface.js +2 -0
  43. package/lib/types/interfaces/recurringPayment.interface.d.ts +5 -0
  44. package/lib/types/interfaces/recurringPayment.interface.js +2 -0
  45. package/lib/types/interfaces/transaction.interface.d.ts +5 -0
  46. package/lib/types/interfaces/transaction.interface.js +2 -0
  47. package/lib/types/paymentMethod.type.d.ts +5 -0
  48. package/lib/types/paymentMethod.type.js +2 -0
  49. package/lib/types/recurringPayment.type.d.ts +5 -0
  50. package/lib/types/recurringPayment.type.js +2 -0
  51. package/lib/types/schemas/budget.schema.d.ts +228 -0
  52. package/lib/types/schemas/budget.schema.js +77 -0
  53. package/lib/types/schemas/category.schema.d.ts +160 -0
  54. package/lib/types/schemas/category.schema.js +69 -0
  55. package/lib/types/schemas/common.schema.d.ts +25 -0
  56. package/lib/types/schemas/common.schema.js +27 -0
  57. package/lib/types/schemas/index.d.ts +6 -0
  58. package/lib/types/schemas/index.js +22 -0
  59. package/lib/types/schemas/paymentMethod.schema.d.ts +138 -0
  60. package/lib/types/schemas/paymentMethod.schema.js +59 -0
  61. package/lib/types/schemas/recurringPayment.schema.d.ts +199 -0
  62. package/lib/types/schemas/recurringPayment.schema.js +62 -0
  63. package/lib/types/schemas/transaction.schema.d.ts +207 -0
  64. package/lib/types/schemas/transaction.schema.js +76 -0
  65. package/lib/types/transaction.type.d.ts +6 -0
  66. package/lib/types/transaction.type.js +2 -0
  67. package/package.json +144 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thorben Klein
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,366 @@
1
+ # `@budgetbuddyde/api`
2
+
3
+ ## About
4
+
5
+ ![CI](https://ci.tklein.it/api/v1/teams/budgetbuddyde/pipelines/api/jobs/build-api/badge)
6
+ ![NPM Version](https://img.shields.io/npm/v/%40budgetbuddyde%2Fapi)
7
+ ![NPM License](https://img.shields.io/npm/l/%40budgetbuddyde%2Fapi)
8
+ ![NPM Last Update](https://img.shields.io/npm/last-update/%40budgetbuddyde%2Fapi)
9
+
10
+ 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.
11
+
12
+ The package can be installed via NPM:
13
+
14
+ ```bash
15
+ npm install @budgetbuddyde/api
16
+ ```
17
+
18
+ ### Peer Dependencies
19
+
20
+ > [!NOTE]
21
+ > The package uses Zod for schema validation, therefore `zod` must be installed as a peer dependency.
22
+ > ```bash
23
+ > npm install zod
24
+ > ```
25
+
26
+
27
+ ## Getting Started
28
+
29
+ ### Basic Usage
30
+
31
+ ```typescript
32
+ import { Api } from '@budgetbuddyde/api';
33
+
34
+ // Initialize API client
35
+ const api = new Api('https://backend.budgetbuddy.de');
36
+
37
+ // Fetch transactions
38
+ const [transactions, error] = await api.backend.transaction.getAll();
39
+
40
+ if (error) {
41
+ console.error('Error loading transactions:', error);
42
+ return;
43
+ }
44
+
45
+ console.log('Transactions:', transactions);
46
+ ```
47
+
48
+ ### CRUD Operations
49
+
50
+ All entity services provide standard CRUD operations:
51
+
52
+ ```typescript
53
+ // Create - Create new category
54
+ const [newCategory, createError] = await api.backend.category.create({
55
+ name: 'Groceries',
56
+ description: 'Supermarket purchases',
57
+ });
58
+
59
+ // Read - Fetch all categories
60
+ const [categories, getAllError] = await api.backend.category.getAll();
61
+
62
+ // Read - Fetch single category
63
+ const [category, getError] = await api.backend.category.getById('category-id');
64
+
65
+ // Update - Update category
66
+ const [updated, updateError] = await api.backend.category.updateById(
67
+ 'category-id',
68
+ { name: 'Groceries & Beverages' }
69
+ );
70
+
71
+ // Delete - Delete category
72
+ const [deleted, deleteError] = await api.backend.category.deleteById('category-id');
73
+ ```
74
+
75
+ ### Query Parameters
76
+
77
+ Many endpoints support query parameters for filtering and pagination:
78
+
79
+ ```typescript
80
+ // Fetch transactions with date filter
81
+ const [transactions, error] = await api.backend.transaction.getAll({
82
+ startDate: new Date('2024-01-01'),
83
+ endDate: new Date('2024-12-31'),
84
+ limit: 50,
85
+ offset: 0,
86
+ });
87
+ ```
88
+
89
+ ### Error Handling
90
+
91
+ The package uses a `TResult<T, E>` pattern for type-safe error handling:
92
+
93
+ ```typescript
94
+ import type { TResult } from '@budgetbuddyde/api';
95
+
96
+ async function loadBudgets() {
97
+ const [budgets, error] = await api.backend.budget.getAll();
98
+
99
+ // Check for errors
100
+ if (error) {
101
+ // TypeScript knows that 'budgets' is null here
102
+ if (error instanceof BackendError) {
103
+ console.error('Backend error:', error.statusCode, error.message);
104
+ } else if (error instanceof NetworkError) {
105
+ console.error('Network error:', error.message);
106
+ }
107
+ return;
108
+ }
109
+
110
+ // TypeScript knows that 'budgets' is not null here
111
+ console.log('Budgets loaded:', budgets);
112
+ }
113
+ ```
114
+
115
+ ### Custom Request Configuration
116
+
117
+ For advanced usage, request options can be passed:
118
+
119
+ ```typescript
120
+ // With custom headers
121
+ const [data, error] = await api.backend.transaction.getAll(
122
+ undefined,
123
+ {
124
+ headers: {
125
+ 'X-Custom-Header': 'value',
126
+ },
127
+ signal: abortController.signal, // AbortController for cancellation
128
+ }
129
+ );
130
+ ```
131
+
132
+ ## Development
133
+
134
+ ### Build
135
+
136
+ ```bash
137
+ npm run build
138
+ ```
139
+
140
+ Compiles TypeScript to JavaScript in the `lib/` folder.
141
+
142
+ ### Tests
143
+
144
+ ```bash
145
+ # Run tests once
146
+ npm test
147
+
148
+ # Run tests in watch mode
149
+ npm run test:watch
150
+ ```
151
+
152
+ ### Code Quality
153
+
154
+ ```bash
155
+ # Biome Check (Linting + Formatting)
156
+ npm run check
157
+
158
+ # Auto-fix
159
+ npm run check:write
160
+
161
+ # Linting only
162
+ npm run lint
163
+
164
+ # Formatting only
165
+ npm run format
166
+ ```
167
+
168
+ ## API Reference
169
+
170
+ ### Available Services
171
+
172
+ | Service | Description | Endpoint |
173
+ |---------|-------------|----------|
174
+ | `api.backend.category` | Category management | `/api/category` |
175
+ | `api.backend.paymentMethod` | Payment methods | `/api/paymentMethod` |
176
+ | `api.backend.transaction` | Transactions | `/api/transaction` |
177
+ | `api.backend.recurringPayment` | Recurring payments | `/api/recurringPayment` |
178
+ | `api.backend.budget` | Budget management | `/api/budget` |
179
+
180
+ ### Common Methods
181
+
182
+ All services inherit from `EntityService` and provide:
183
+
184
+ ```typescript
185
+ // Type signature simplified
186
+ class EntityService<CreatePayload, UpdatePayload, ...> {
187
+ getAll<Q>(query?: Q, config?: RequestInit): Promise<TResult<GetAllResult>>;
188
+ getById(id: string, config?: RequestInit): Promise<TResult<GetResult>>;
189
+ create(payload: CreatePayload, config?: RequestInit): Promise<TResult<CreateResult>>;
190
+ updateById(id: string, payload: UpdatePayload, config?: RequestInit): Promise<TResult<UpdateResult>>;
191
+ deleteById(id: string, config?: RequestInit): Promise<TResult<DeleteResult>>;
192
+ }
193
+ ```
194
+
195
+ ## Type Safety
196
+
197
+ The package leverages Zod for runtime validation combined with TypeScript for compile-time safety:
198
+
199
+ ```typescript
200
+ // Schema defines both runtime and compile-time types
201
+ const CategorySchema = z.object({
202
+ id: z.string(),
203
+ name: z.string(),
204
+ });
205
+
206
+ // TypeScript type is derived from schema
207
+ type TCategory = z.infer<typeof CategorySchema>;
208
+
209
+ // Runtime validation in services
210
+ const parsingResult = CategorySchema.safeParse(apiResponse);
211
+ if (!parsingResult.success) {
212
+ // Handle validation errors
213
+ }
214
+ ```
215
+
216
+ ## Project Structure
217
+
218
+ ```
219
+ packages/api/
220
+ ├── src/ # Source code
221
+ │ ├── api.ts # Main API class
222
+ │ ├── client.ts # Re-export of API
223
+ │ ├── error.ts # Custom error classes
224
+ │ ├── index.ts # Main export
225
+ │ │
226
+ │ ├── services/ # Service layer for backend communication
227
+ │ │ ├── entity.service.ts # Base service with CRUD operations
228
+ │ │ └── <name>.service.ts # Entity-specific operations
229
+ │ │
230
+ │ └── types/ # TypeScript types and schemas
231
+ │ ├── common.ts # Common type helpers (TResult, etc.)
232
+ │ ├── <name>.type.ts # Entity-specific operations
233
+ │ │
234
+ │ ├── interfaces/ # TypeScript interfaces
235
+ │ │ ├── query.interface.ts # Base query interfaces
236
+ │ │ └── <name>.interface.ts # Entity-specific interfaces
237
+ │ │
238
+ │ └── schemas/ # Zod validation schemas
239
+ │ ├── common.schema.ts # Common schemas
240
+ │ └── <name>.schema.ts # Entity-specific schemas
241
+
242
+ ├── lib/ # Compiled JavaScript files (generated)
243
+ ├── package.json
244
+ ├── tsconfig.json
245
+ ├── vitest.config.ts
246
+ └── README.md
247
+ ```
248
+
249
+ ### Architecture Components
250
+
251
+ #### 1. **API Class** (`api.ts`)
252
+ The central entry point that aggregates all service instances:
253
+
254
+ ```typescript
255
+ const api = new Api('https://backend-url');
256
+ // Access all services:
257
+ // - api.backend.category
258
+ // - api.backend.paymentMethod
259
+ // - api.backend.transaction
260
+ // - api.backend.recurringPayment
261
+ // - api.backend.budget
262
+ ```
263
+
264
+ #### 2. **Entity Service** (`services/entity.service.ts`)
265
+ Abstract base class for all entity services with generic CRUD operations:
266
+
267
+ - `getAll(query?, config?)` - Fetch all entities
268
+ - `getById(id, config?)` - Fetch single entity
269
+ - `create(payload, config?)` - Create new entity
270
+ - `updateById(id, payload, config?)` - Update entity
271
+ - `deleteById(id, config?)` - Delete entity
272
+
273
+ **Features:**
274
+ - Automatic Zod validation of all responses
275
+ - Type-safe request/response handling
276
+ - Query parameter serialization
277
+ - Error handling and error types
278
+ - Request config merging
279
+
280
+ #### 3. **Specialized Services** (`services/*.service.ts`)
281
+ Extend `EntityService` with domain-specific methods:
282
+
283
+ ```typescript
284
+ // Example: BudgetService with additional method
285
+ class BudgetService extends EntityService {
286
+ async getEstimatedBudget(): Promise<TResult<TEstimatedBudget>> {
287
+ // Budget-specific logic
288
+ }
289
+ }
290
+ ```
291
+
292
+ #### 4. **Type System** (`types/`)
293
+
294
+ ##### **Schemas** (`types/schemas/`)
295
+ Zod schemas for runtime validation:
296
+
297
+ ```typescript
298
+ import { z } from 'zod';
299
+
300
+ export const CategorySchema = z.object({
301
+ id: z.string(),
302
+ name: z.string(),
303
+ description: z.string().optional(),
304
+ createdAt: z.string().datetime(),
305
+ });
306
+
307
+ export const GetAllCategoriesResponse = z.object({
308
+ data: z.array(CategorySchema),
309
+ total: z.number(),
310
+ });
311
+ ```
312
+
313
+ ##### **Types** (`types/*.type.ts`)
314
+ TypeScript types, often derived from Zod schemas:
315
+
316
+ ```typescript
317
+ import type { z } from 'zod';
318
+ import { CategorySchema } from './schemas/category.schema';
319
+
320
+ export type TCategory = z.infer<typeof CategorySchema>;
321
+ ```
322
+
323
+ ##### **Common Types** (`types/common.ts`)
324
+ Shared type helpers:
325
+
326
+ - `TResult<T, E>` - Result type for error handling
327
+ - `TApiResponse<Schema>` - API response helper
328
+ - `TypeOfSchema<Schema>` - Schema-to-type converter
329
+
330
+ ##### **Interfaces** (`types/interfaces/`)
331
+ TypeScript interfaces for structure definitions:
332
+
333
+ ```typescript
334
+ export interface IBaseGetAllQuery {
335
+ limit?: number;
336
+ offset?: number;
337
+ sortBy?: string;
338
+ sortOrder?: 'asc' | 'desc';
339
+ }
340
+ ```
341
+
342
+ #### 5. **Error Handling** (`error.ts`)
343
+ Custom error classes for various error scenarios:
344
+
345
+ - `CustomError` - Base error class
346
+ - `ApiError` - General API errors
347
+ - `BackendError` - HTTP status errors from backend
348
+ - `ResponseNotJsonError` - Response is not valid JSON
349
+
350
+ ```typescript
351
+ try {
352
+ const response = await fetch(url);
353
+ if (!response.ok) {
354
+ throw new BackendError(response.status, response.statusText);
355
+ }
356
+ } catch (error) {
357
+ if (error instanceof BackendError) {
358
+ console.error('Backend returned:', error.statusCode);
359
+ }
360
+ }
361
+ ```
362
+
363
+
364
+ ## Contributing
365
+
366
+ See [the documentation for contribution guidelines](https://docs.budget-buddy.de/docs/introduction/contribution).
package/lib/api.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /** biome-ignore-all lint/complexity/noStaticOnlyClass: This class is used as as a wrapper */
2
+ import { BudgetService } from "./services/budget.service";
3
+ import { CategoryService } from "./services/category.service";
4
+ import { PaymentMethodService } from "./services/paymentMethod.service";
5
+ import { RecurringPaymentService } from "./services/recurringPayment.service";
6
+ import { TransactionService } from "./services/transaction.service";
7
+ export declare class Api {
8
+ protected backendHost: string;
9
+ backend: {
10
+ category: CategoryService;
11
+ paymentMethod: PaymentMethodService;
12
+ transaction: TransactionService;
13
+ recurringPayment: RecurringPaymentService;
14
+ budget: BudgetService;
15
+ };
16
+ constructor(backendHost: string);
17
+ }
package/lib/api.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /** biome-ignore-all lint/complexity/noStaticOnlyClass: This class is used as as a wrapper */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Api = void 0;
5
+ const budget_service_1 = require("./services/budget.service");
6
+ const category_service_1 = require("./services/category.service");
7
+ const paymentMethod_service_1 = require("./services/paymentMethod.service");
8
+ const recurringPayment_service_1 = require("./services/recurringPayment.service");
9
+ const transaction_service_1 = require("./services/transaction.service");
10
+ class Api {
11
+ constructor(backendHost) {
12
+ this.backendHost = backendHost;
13
+ this.backend = {
14
+ category: new category_service_1.CategoryService(backendHost),
15
+ paymentMethod: new paymentMethod_service_1.PaymentMethodService(backendHost),
16
+ transaction: new transaction_service_1.TransactionService(backendHost),
17
+ recurringPayment: new recurringPayment_service_1.RecurringPaymentService(backendHost),
18
+ budget: new budget_service_1.BudgetService(backendHost),
19
+ };
20
+ }
21
+ }
22
+ exports.Api = Api;
@@ -0,0 +1,3 @@
1
+ export * from "./services/budget.service";
2
+ export * from "./types/budget.type";
3
+ export * from "./types/schemas/budget.schema";
package/lib/budget.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./services/budget.service"), exports);
18
+ __exportStar(require("./types/budget.type"), exports);
19
+ __exportStar(require("./types/schemas/budget.schema"), exports);
@@ -0,0 +1,3 @@
1
+ export * from "./services/category.service";
2
+ export * from "./types/category.type";
3
+ export * from "./types/schemas/category.schema";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./services/category.service"), exports);
18
+ __exportStar(require("./types/category.type"), exports);
19
+ __exportStar(require("./types/schemas/category.schema"), exports);
package/lib/error.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Gerneric custom error class that extends the built-in Error class.
3
+ * @author developer.mozilla.org
4
+ * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#custom_error_types
5
+ */
6
+ export declare class CustomError extends Error {
7
+ constructor(...params: any[]);
8
+ }
9
+ /**
10
+ * Error class representing an error occurring in the API layer.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * throw new ApiError("Failed to fetch data from API");
15
+ * ```
16
+ */
17
+ export declare class ApiError extends CustomError {
18
+ }
19
+ /**
20
+ * Error class representing a response that is not in JSON format.
21
+ */
22
+ export declare class ResponseNotJsonError extends ApiError {
23
+ constructor();
24
+ }
25
+ /**
26
+ * Error class representing an HTTP response containing an error from the backend.
27
+ */
28
+ export declare class BackendError extends CustomError {
29
+ protected statusCode: number;
30
+ protected backendResponseText: string;
31
+ constructor(statusCode: number, backendResponseText: string);
32
+ getMessage(): string;
33
+ }
package/lib/error.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BackendError = exports.ResponseNotJsonError = exports.ApiError = exports.CustomError = void 0;
4
+ /**
5
+ * Gerneric custom error class that extends the built-in Error class.
6
+ * @author developer.mozilla.org
7
+ * @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#custom_error_types
8
+ */
9
+ class CustomError extends Error {
10
+ // biome-ignore lint/suspicious/noExplicitAny: Params can be any
11
+ constructor(...params) {
12
+ // Pass remaining arguments (including vendor specific ones) to parent constructor
13
+ super(...params);
14
+ // Maintains proper stack trace for where our error was thrown (non-standard)
15
+ if (Error.captureStackTrace) {
16
+ Error.captureStackTrace(this, CustomError);
17
+ }
18
+ this.name = this.constructor.name;
19
+ }
20
+ }
21
+ exports.CustomError = CustomError;
22
+ /**
23
+ * Error class representing an error occurring in the API layer.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * throw new ApiError("Failed to fetch data from API");
28
+ * ```
29
+ */
30
+ class ApiError extends CustomError {
31
+ }
32
+ exports.ApiError = ApiError;
33
+ /**
34
+ * Error class representing a response that is not in JSON format.
35
+ */
36
+ class ResponseNotJsonError extends ApiError {
37
+ constructor() {
38
+ super("Response is not JSON");
39
+ }
40
+ }
41
+ exports.ResponseNotJsonError = ResponseNotJsonError;
42
+ /**
43
+ * Error class representing an HTTP response containing an error from the backend.
44
+ */
45
+ class BackendError extends CustomError {
46
+ constructor(statusCode, backendResponseText) {
47
+ super(backendResponseText);
48
+ this.statusCode = statusCode;
49
+ this.backendResponseText = backendResponseText;
50
+ }
51
+ getMessage() {
52
+ return `Backend failed the request with status ${this.statusCode}: ${this.backendResponseText}`;
53
+ }
54
+ }
55
+ exports.BackendError = BackendError;
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./api";
2
+ export * from "./error";
3
+ export * from "./services/entity.service";
4
+ export * from "./types/common";
5
+ export * from "./types/interfaces/query.interface";
6
+ export * from "./types/schemas/common.schema";
package/lib/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api"), exports);
18
+ __exportStar(require("./error"), exports);
19
+ __exportStar(require("./services/entity.service"), exports);
20
+ __exportStar(require("./types/common"), exports);
21
+ __exportStar(require("./types/interfaces/query.interface"), exports);
22
+ __exportStar(require("./types/schemas/common.schema"), exports);
@@ -0,0 +1,3 @@
1
+ export * from "./services/paymentMethod.service";
2
+ export * from "./types/paymentMethod.type";
3
+ export * from "./types/schemas/paymentMethod.schema";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./services/paymentMethod.service"), exports);
18
+ __exportStar(require("./types/paymentMethod.type"), exports);
19
+ __exportStar(require("./types/schemas/paymentMethod.schema"), exports);
@@ -0,0 +1,4 @@
1
+ export * from "./services/recurringPayment.service";
2
+ export * from "./types/interfaces/recurringPayment.interface";
3
+ export * from "./types/recurringPayment.type";
4
+ export * from "./types/schemas/recurringPayment.schema";
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./services/recurringPayment.service"), exports);
18
+ __exportStar(require("./types/interfaces/recurringPayment.interface"), exports);
19
+ __exportStar(require("./types/recurringPayment.type"), exports);
20
+ __exportStar(require("./types/schemas/recurringPayment.schema"), exports);
@@ -0,0 +1,8 @@
1
+ import type { TCreateOrUpdateBudgetPayload, TEstimatedBudget } from "../types/budget.type";
2
+ import type { TResult } from "../types/common";
3
+ import { CreateBudgetResponse, DeleteBudgetResponse, GetAllBudgetsResponse, GetBudgetResponse, UpdateBudgetResponse } from "../types/schemas/budget.schema";
4
+ import { EntityService } from "./entity.service";
5
+ export declare class BudgetService extends EntityService<TCreateOrUpdateBudgetPayload, Partial<TCreateOrUpdateBudgetPayload>, typeof GetAllBudgetsResponse, typeof GetBudgetResponse, typeof CreateBudgetResponse, typeof UpdateBudgetResponse, typeof DeleteBudgetResponse> {
6
+ constructor(host: string, entityPath?: string);
7
+ getEstimatedBudget(requestConfig?: RequestInit): Promise<TResult<TEstimatedBudget>>;
8
+ }