@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
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BudgetService = void 0;
4
+ const error_1 = require("../error");
5
+ const budget_schema_1 = require("../types/schemas/budget.schema");
6
+ const entity_service_1 = require("./entity.service");
7
+ class BudgetService extends entity_service_1.EntityService {
8
+ constructor(host, entityPath = "/api/budget") {
9
+ super(host, entityPath, {
10
+ getAll: budget_schema_1.GetAllBudgetsResponse,
11
+ get: budget_schema_1.GetBudgetResponse,
12
+ create: budget_schema_1.CreateBudgetResponse,
13
+ update: budget_schema_1.UpdateBudgetResponse,
14
+ delete: budget_schema_1.DeleteBudgetResponse,
15
+ });
16
+ }
17
+ async getEstimatedBudget(requestConfig) {
18
+ var _a;
19
+ try {
20
+ const response = await fetch(`${this.getBaseRequestPath()}/estimated`, this.mergeRequestConfig({
21
+ method: "GET",
22
+ credentials: "include",
23
+ headers: new Headers((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.headers) || {}),
24
+ }, requestConfig));
25
+ if (!response.ok) {
26
+ throw new error_1.BackendError(response.status, response.statusText);
27
+ }
28
+ if (!this.isJsonResponse(response)) {
29
+ throw new error_1.ResponseNotJsonError();
30
+ }
31
+ const data = await response.json();
32
+ const parsingResult = budget_schema_1.EstimatedBudgetResponse.safeParse(data);
33
+ if (!parsingResult.success) {
34
+ return this.handleZodError(parsingResult.error);
35
+ }
36
+ return [(_a = parsingResult.data.data) !== null && _a !== void 0 ? _a : [], null];
37
+ }
38
+ catch (error) {
39
+ return this.handleError(error);
40
+ }
41
+ }
42
+ }
43
+ exports.BudgetService = BudgetService;
@@ -0,0 +1,24 @@
1
+ import type { TCategory, TCategoryStats, TCategoryVH, TCreateOrUpdateCategoryPayload } from "../types/category.type";
2
+ import type { TResult } from "../types/common";
3
+ import { CreateCategoryResponse, DeleteCategoryResponse, GetAllCategoriesResponse, GetCategoryResponse, UpdateCategoryResponse } from "../types/schemas/category.schema";
4
+ import { EntityService } from "./entity.service";
5
+ export declare class CategoryService extends EntityService<TCreateOrUpdateCategoryPayload, Partial<TCreateOrUpdateCategoryPayload>, typeof GetAllCategoriesResponse, typeof GetCategoryResponse, typeof CreateCategoryResponse, typeof UpdateCategoryResponse, typeof DeleteCategoryResponse> {
6
+ constructor(host: string, entityPath?: string);
7
+ getValueHelp(requestConfig?: RequestInit): Promise<TResult<TCategoryVH[]>>;
8
+ /**
9
+ * Retrieves the statistics for categories within a specific date range.
10
+ * @param param0 - The start and end dates for the statistics.
11
+ * @returns A promise that resolves to an array of expanded category statistics.
12
+ */
13
+ getCategoryStats({ from, to, }: {
14
+ from: Date;
15
+ to: Date;
16
+ }, requestConfig?: RequestInit): Promise<TResult<TCategoryStats>>;
17
+ merge({ source, target, }: {
18
+ source: TCategory["id"][];
19
+ target: TCategory["id"];
20
+ }, requestConfig?: RequestInit): Promise<TResult<{
21
+ source: Set<TCategory["id"]>;
22
+ target: TCategory["id"];
23
+ }>>;
24
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CategoryService = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const error_1 = require("../error");
9
+ const category_schema_1 = require("../types/schemas/category.schema");
10
+ const entity_service_1 = require("./entity.service");
11
+ class CategoryService extends entity_service_1.EntityService {
12
+ constructor(host, entityPath = "/api/category") {
13
+ super(host, entityPath, {
14
+ getAll: category_schema_1.GetAllCategoriesResponse,
15
+ get: category_schema_1.GetCategoryResponse,
16
+ create: category_schema_1.CreateCategoryResponse,
17
+ update: category_schema_1.UpdateCategoryResponse,
18
+ delete: category_schema_1.DeleteCategoryResponse,
19
+ });
20
+ }
21
+ async getValueHelp(requestConfig) {
22
+ var _a;
23
+ const [categories, error] = await this.getAll(undefined, requestConfig);
24
+ if (error) {
25
+ this.handleError(error);
26
+ }
27
+ const valueHelpValues = zod_1.default
28
+ .array(category_schema_1.CategoryVH)
29
+ .safeParse((_a = categories === null || categories === void 0 ? void 0 : categories.data) !== null && _a !== void 0 ? _a : []);
30
+ if (!valueHelpValues.success) {
31
+ return this.handleZodError(valueHelpValues.error);
32
+ }
33
+ return [valueHelpValues.data, null];
34
+ }
35
+ /**
36
+ * Retrieves the statistics for categories within a specific date range.
37
+ * @param param0 - The start and end dates for the statistics.
38
+ * @returns A promise that resolves to an array of expanded category statistics.
39
+ */
40
+ async getCategoryStats({ from, to, }, requestConfig) {
41
+ var _a;
42
+ try {
43
+ const query = new URLSearchParams();
44
+ // en-CA format yields YYYY-MM-DD which is ISO 8601 compliant
45
+ query.append("from", from.toLocaleDateString("en-CA"));
46
+ query.append("to", to.toLocaleDateString("en-CA"));
47
+ const response = await fetch(`${this.getBaseRequestPath()}/stats?${query.toString()}`, this.mergeRequestConfig({
48
+ method: "GET",
49
+ credentials: "include",
50
+ headers: new Headers((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.headers) || {}),
51
+ }, requestConfig));
52
+ if (!response.ok) {
53
+ throw new error_1.BackendError(response.status, response.statusText);
54
+ }
55
+ if (!this.isJsonResponse(response)) {
56
+ throw new error_1.ResponseNotJsonError();
57
+ }
58
+ const data = await response.json();
59
+ const parsingResult = category_schema_1.CategoryStatsResponse.safeParse(data);
60
+ if (!parsingResult.success) {
61
+ return this.handleZodError(parsingResult.error);
62
+ }
63
+ return [(_a = parsingResult.data.data) !== null && _a !== void 0 ? _a : [], null];
64
+ }
65
+ catch (error) {
66
+ return this.handleError(error);
67
+ }
68
+ }
69
+ async merge({ source, target, }, requestConfig) {
70
+ try {
71
+ const response = await fetch(`${this.getBaseRequestPath()}/merge`, this.mergeRequestConfig({
72
+ method: "POST",
73
+ credentials: "include",
74
+ headers: new Headers({
75
+ "Content-Type": "application/json",
76
+ ...((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.headers) || {}),
77
+ }),
78
+ body: JSON.stringify({ source, target }),
79
+ }, requestConfig));
80
+ if (!response.ok) {
81
+ throw new error_1.BackendError(response.status, response.statusText);
82
+ }
83
+ if (!this.isJsonResponse(response)) {
84
+ throw new error_1.ResponseNotJsonError();
85
+ }
86
+ const data = await response.json();
87
+ const parsingResult = category_schema_1.MergeCategoriesResponse.safeParse(data);
88
+ if (!parsingResult.success) {
89
+ return this.handleZodError(parsingResult.error);
90
+ }
91
+ return [parsingResult.data.data, null];
92
+ }
93
+ catch (error) {
94
+ return this.handleError(error);
95
+ }
96
+ }
97
+ }
98
+ exports.CategoryService = CategoryService;
@@ -0,0 +1,31 @@
1
+ import type { ZodType, z } from "zod";
2
+ import type { TResult } from "../types/common";
3
+ import type { IBaseGetAllQuery } from "../types/interfaces/query.interface";
4
+ type TEntitySchemas<GetAll extends z.ZodType, Get extends z.ZodType, Create extends z.ZodType, Update extends z.ZodType, Delete extends z.ZodType> = {
5
+ getAll: GetAll;
6
+ get: Get;
7
+ create: Create;
8
+ update: Update;
9
+ delete: Delete;
10
+ };
11
+ export declare class EntityService<CreatePayload, UpdatePayload, GetAllResult extends ZodType, GetResult extends ZodType, CreateResult extends ZodType, UpdateResult extends ZodType, DeleteResult extends ZodType> {
12
+ protected host: string;
13
+ protected basePath: string;
14
+ protected schemas: TEntitySchemas<GetAllResult, GetResult, CreateResult, UpdateResult, DeleteResult>;
15
+ constructor(host: string, basePath: string, schemas: TEntitySchemas<GetAllResult, GetResult, CreateResult, UpdateResult, DeleteResult>);
16
+ protected getBaseRequestPath(): string;
17
+ protected handleError<T>(e: unknown): TResult<T>;
18
+ protected handleZodError<T, S>(errors: z.ZodError<S>[] | z.ZodError<S>): TResult<T>;
19
+ protected mergeRequestConfig(config1: RequestInit, config2?: RequestInit): RequestInit;
20
+ getAll<Q extends IBaseGetAllQuery>(query?: Q, requestConfig?: RequestInit): Promise<TResult<z.output<GetAllResult>>>;
21
+ getById(entityId: string, requestConfig?: RequestInit): Promise<TResult<z.output<GetResult>>>;
22
+ create(payload: CreatePayload, requestConfig?: RequestInit): Promise<TResult<z.output<CreateResult>>>;
23
+ updateById(entityId: string, payload: UpdatePayload, requestConfig?: RequestInit): Promise<TResult<z.output<UpdateResult>>>;
24
+ deleteById(entityId: string, requestConfig?: RequestInit): Promise<TResult<z.output<DeleteResult>>>;
25
+ /**
26
+ * Checks if the response has a JSON content type.
27
+ * This method does not verify that the actually content is valid JSON.
28
+ */
29
+ protected isJsonResponse(response: Response): boolean;
30
+ }
31
+ export {};
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityService = void 0;
4
+ const error_1 = require("../error");
5
+ class EntityService {
6
+ constructor(host, basePath, schemas) {
7
+ this.host = host;
8
+ this.basePath = basePath;
9
+ this.schemas = schemas;
10
+ }
11
+ getBaseRequestPath() {
12
+ return `${this.host}${this.basePath}`;
13
+ }
14
+ handleError(e) {
15
+ const msg = e instanceof Error ? e.message : String(e);
16
+ return [null, e instanceof Error ? e : new Error(msg)];
17
+ }
18
+ handleZodError(errors) {
19
+ const msg = Array.isArray(errors)
20
+ ? errors.map((e) => e.message).join(", ")
21
+ : errors.message;
22
+ console.error(`ZodError in ${this.constructor.name}: %s`, msg);
23
+ return [null, new Error(msg)];
24
+ }
25
+ mergeRequestConfig(config1, config2) {
26
+ return {
27
+ ...config1,
28
+ ...config2,
29
+ headers: new Headers({
30
+ ...(config1.headers instanceof Headers
31
+ ? Object.fromEntries(config1.headers)
32
+ : config1.headers),
33
+ ...((config2 === null || config2 === void 0 ? void 0 : config2.headers) instanceof Headers
34
+ ? Object.fromEntries(config2.headers)
35
+ : config2 === null || config2 === void 0 ? void 0 : config2.headers),
36
+ }),
37
+ };
38
+ }
39
+ async getAll(query, requestConfig) {
40
+ try {
41
+ const queryParams = new URLSearchParams();
42
+ if (query !== undefined) {
43
+ Object.entries(query).forEach(([key, value]) => {
44
+ const isDate = value instanceof Date;
45
+ queryParams.append(key, isDate
46
+ ? // en-CA format yields YYYY-MM-DD which is ISO 8601 compliant
47
+ // new Intl.DateTimeFormat("en-CA").format(value)
48
+ value.toLocaleDateString("en-CA")
49
+ : String(value));
50
+ });
51
+ }
52
+ const response = await fetch(`${this.getBaseRequestPath()}?${queryParams.toString()}`, this.mergeRequestConfig({
53
+ method: "GET",
54
+ headers: new Headers((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.headers) || {}),
55
+ credentials: "include",
56
+ }, requestConfig));
57
+ if (!response.ok) {
58
+ throw new error_1.BackendError(response.status, response.statusText);
59
+ }
60
+ if (!this.isJsonResponse(response)) {
61
+ throw new error_1.ResponseNotJsonError();
62
+ }
63
+ const data = await response.json();
64
+ const parsingResult = this.schemas.getAll.safeParse(data);
65
+ if (!parsingResult.success) {
66
+ return this.handleZodError(parsingResult.error);
67
+ }
68
+ return [parsingResult.data, null];
69
+ }
70
+ catch (error) {
71
+ return this.handleError(error);
72
+ }
73
+ }
74
+ async getById(entityId, requestConfig) {
75
+ try {
76
+ const response = await fetch(`${this.getBaseRequestPath()}/${entityId}`, this.mergeRequestConfig({
77
+ method: "GET",
78
+ headers: new Headers((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.headers) || {}),
79
+ credentials: "include",
80
+ }, requestConfig));
81
+ if (!response.ok) {
82
+ throw new error_1.BackendError(response.status, response.statusText);
83
+ }
84
+ if (!this.isJsonResponse(response)) {
85
+ throw new error_1.ResponseNotJsonError();
86
+ }
87
+ const data = await response.json();
88
+ const parsingResult = this.schemas.get.safeParse(data);
89
+ if (!parsingResult.success) {
90
+ return this.handleZodError(parsingResult.error);
91
+ }
92
+ return [parsingResult.data, null];
93
+ }
94
+ catch (error) {
95
+ return this.handleError(error);
96
+ }
97
+ }
98
+ async create(payload, requestConfig) {
99
+ try {
100
+ const response = await fetch(`${this.getBaseRequestPath()}`, this.mergeRequestConfig({
101
+ method: "POST",
102
+ headers: new Headers((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.headers) || {
103
+ "Content-Type": "application/json",
104
+ }),
105
+ credentials: "include",
106
+ body: JSON.stringify(payload),
107
+ }, requestConfig));
108
+ if (!response.ok) {
109
+ throw new error_1.BackendError(response.status, response.statusText);
110
+ }
111
+ if (!this.isJsonResponse(response)) {
112
+ throw new error_1.ResponseNotJsonError();
113
+ }
114
+ const data = await response.json();
115
+ const parsingResult = this.schemas.create.safeParse(data);
116
+ if (!parsingResult.success) {
117
+ return this.handleZodError(parsingResult.error);
118
+ }
119
+ return [parsingResult.data, null];
120
+ }
121
+ catch (error) {
122
+ return this.handleError(error);
123
+ }
124
+ }
125
+ async updateById(entityId, payload, requestConfig) {
126
+ try {
127
+ const response = await fetch(`${this.getBaseRequestPath()}/${entityId}`, this.mergeRequestConfig({
128
+ method: "PUT",
129
+ headers: new Headers((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.headers) || {
130
+ "Content-Type": "application/json",
131
+ }),
132
+ credentials: "include",
133
+ body: JSON.stringify(payload),
134
+ }, requestConfig));
135
+ if (!response.ok) {
136
+ throw new error_1.BackendError(response.status, response.statusText);
137
+ }
138
+ if (!this.isJsonResponse(response)) {
139
+ throw new error_1.ResponseNotJsonError();
140
+ }
141
+ const data = await response.json();
142
+ const parsingResult = this.schemas.update.safeParse(data);
143
+ if (!parsingResult.success) {
144
+ return this.handleZodError(parsingResult.error);
145
+ }
146
+ return [parsingResult.data, null];
147
+ }
148
+ catch (error) {
149
+ return this.handleError(error);
150
+ }
151
+ }
152
+ async deleteById(entityId, requestConfig) {
153
+ try {
154
+ const response = await fetch(`${this.getBaseRequestPath()}/${entityId}`, this.mergeRequestConfig({
155
+ method: "DELETE",
156
+ headers: new Headers((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.headers) || {}),
157
+ credentials: "include",
158
+ }, requestConfig));
159
+ if (!response.ok) {
160
+ throw new error_1.BackendError(response.status, response.statusText);
161
+ }
162
+ if (!this.isJsonResponse(response)) {
163
+ throw new error_1.ResponseNotJsonError();
164
+ }
165
+ const data = await response.json();
166
+ const parsingResult = this.schemas.delete.safeParse(data);
167
+ if (!parsingResult.success) {
168
+ return this.handleZodError(parsingResult.error);
169
+ }
170
+ return [parsingResult.data, null];
171
+ }
172
+ catch (error) {
173
+ return this.handleError(error);
174
+ }
175
+ }
176
+ /**
177
+ * Checks if the response has a JSON content type.
178
+ * This method does not verify that the actually content is valid JSON.
179
+ */
180
+ isJsonResponse(response) {
181
+ const contentType = response.headers.get("content-type");
182
+ return (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) || false;
183
+ }
184
+ }
185
+ exports.EntityService = EntityService;
@@ -0,0 +1,15 @@
1
+ import type { TResult } from "../types/common";
2
+ import type { TCreateOrUpdatePaymentMethodPayload, TPaymentMethod, TPaymentMethodVH } from "../types/paymentMethod.type";
3
+ import { CreatePaymentMethodResponse, DeletePaymentMethodResponse, GetAllPaymentMethodsResponse, GetPaymentMethodResponse, UpdatePaymentMethodResponse } from "../types/schemas/paymentMethod.schema";
4
+ import { EntityService } from "./entity.service";
5
+ export declare class PaymentMethodService extends EntityService<TCreateOrUpdatePaymentMethodPayload, Partial<TCreateOrUpdatePaymentMethodPayload>, typeof GetAllPaymentMethodsResponse, typeof GetPaymentMethodResponse, typeof CreatePaymentMethodResponse, typeof UpdatePaymentMethodResponse, typeof DeletePaymentMethodResponse> {
6
+ constructor(host: string, entityPath?: string);
7
+ getValueHelp(requestConfig?: RequestInit): Promise<TResult<TPaymentMethodVH[]>>;
8
+ merge({ source, target, }: {
9
+ source: TPaymentMethod["id"][];
10
+ target: TPaymentMethod["id"];
11
+ }, requestConfig?: RequestInit): Promise<TResult<{
12
+ source: Set<TPaymentMethod["id"]>;
13
+ target: TPaymentMethod["id"];
14
+ }>>;
15
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PaymentMethodService = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const error_1 = require("../error");
9
+ const paymentMethod_schema_1 = require("../types/schemas/paymentMethod.schema");
10
+ const entity_service_1 = require("./entity.service");
11
+ class PaymentMethodService extends entity_service_1.EntityService {
12
+ constructor(host, entityPath = "/api/paymentMethod") {
13
+ super(host, entityPath, {
14
+ getAll: paymentMethod_schema_1.GetAllPaymentMethodsResponse,
15
+ get: paymentMethod_schema_1.GetPaymentMethodResponse,
16
+ create: paymentMethod_schema_1.CreatePaymentMethodResponse,
17
+ update: paymentMethod_schema_1.UpdatePaymentMethodResponse,
18
+ delete: paymentMethod_schema_1.DeletePaymentMethodResponse,
19
+ });
20
+ }
21
+ async getValueHelp(requestConfig) {
22
+ var _a;
23
+ const [paymentMethods, error] = await this.getAll(undefined, requestConfig);
24
+ if (error) {
25
+ this.handleError(error);
26
+ }
27
+ const valueHelpValues = zod_1.default
28
+ .array(paymentMethod_schema_1.PaymentMethodVH)
29
+ .safeParse((_a = paymentMethods === null || paymentMethods === void 0 ? void 0 : paymentMethods.data) !== null && _a !== void 0 ? _a : []);
30
+ if (!valueHelpValues.success) {
31
+ return this.handleZodError(valueHelpValues.error);
32
+ }
33
+ return [valueHelpValues.data, null];
34
+ }
35
+ async merge({ source, target, }, requestConfig) {
36
+ try {
37
+ const response = await fetch(`${this.getBaseRequestPath()}/merge`, this.mergeRequestConfig({
38
+ method: "POST",
39
+ credentials: "include",
40
+ headers: new Headers({
41
+ "Content-Type": "application/json",
42
+ ...((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.headers) || {}),
43
+ }),
44
+ body: JSON.stringify({ source, target }),
45
+ }, requestConfig));
46
+ if (!response.ok) {
47
+ throw new error_1.BackendError(response.status, response.statusText);
48
+ }
49
+ if (!this.isJsonResponse(response)) {
50
+ throw new error_1.ResponseNotJsonError();
51
+ }
52
+ const data = await response.json();
53
+ const parsingResult = paymentMethod_schema_1.MergePaymentMethodsResponse.safeParse(data);
54
+ if (!parsingResult.success) {
55
+ return this.handleZodError(parsingResult.error);
56
+ }
57
+ return [parsingResult.data.data, null];
58
+ }
59
+ catch (error) {
60
+ return this.handleError(error);
61
+ }
62
+ }
63
+ }
64
+ exports.PaymentMethodService = PaymentMethodService;
@@ -0,0 +1,43 @@
1
+ import type { IGetAllRecurringPaymentsQuery } from "../types/interfaces/recurringPayment.interface";
2
+ import type { TCreateOrUpdateRecurringPaymentPayload, TExpandedRecurringPayment } from "../types/recurringPayment.type";
3
+ import { CreateRecurringPaymentResponse, DeleteRecurringPaymentResponse, GetAllRecurringPaymentsResponse, GetRecurringPaymentResponse, UpdateRecurringPaymentResponse } from "../types/schemas/recurringPayment.schema";
4
+ import { EntityService } from "./entity.service";
5
+ export declare class RecurringPaymentService extends EntityService<TCreateOrUpdateRecurringPaymentPayload, Partial<TCreateOrUpdateRecurringPaymentPayload>, typeof GetAllRecurringPaymentsResponse, typeof GetRecurringPaymentResponse, typeof CreateRecurringPaymentResponse, typeof UpdateRecurringPaymentResponse, typeof DeleteRecurringPaymentResponse> {
6
+ constructor(host: string, entityPath?: string);
7
+ getAll(query?: IGetAllRecurringPaymentsQuery, requestConfig?: RequestInit): Promise<import("..").TResult<{
8
+ status: number;
9
+ data: {
10
+ id: string & import("zod").$brand<"TransactionID">;
11
+ ownerId: string & import("zod").$brand<"UserID">;
12
+ createdAt: string;
13
+ updatedAt: string;
14
+ category: {
15
+ id: string & import("zod").$brand<"CategoryID">;
16
+ ownerId: string & import("zod").$brand<"UserID">;
17
+ name: string;
18
+ description: string | null;
19
+ createdAt: string;
20
+ updatedAt: string;
21
+ };
22
+ receiver: string;
23
+ transferAmount: number;
24
+ information: string | null;
25
+ paymentMethod: {
26
+ id: string & import("zod").$brand<"PaymentMethodID">;
27
+ ownerId: string & import("zod").$brand<"UserID">;
28
+ name: string;
29
+ provider: string;
30
+ address: string;
31
+ description: string | null;
32
+ createdAt: string;
33
+ updatedAt: string;
34
+ };
35
+ paused: boolean;
36
+ executeAt: number;
37
+ }[] | null;
38
+ message?: string | undefined;
39
+ totalCount?: number | undefined;
40
+ from?: "db" | "cache" | "external" | undefined;
41
+ }>>;
42
+ determineNextExecutionDate(executeAt: TExpandedRecurringPayment["executeAt"]): Date;
43
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecurringPaymentService = void 0;
4
+ const recurringPayment_schema_1 = require("../types/schemas/recurringPayment.schema");
5
+ const entity_service_1 = require("./entity.service");
6
+ class RecurringPaymentService extends entity_service_1.EntityService {
7
+ constructor(host, entityPath = "/api/recurringPayment") {
8
+ super(host, entityPath, {
9
+ getAll: recurringPayment_schema_1.GetAllRecurringPaymentsResponse,
10
+ get: recurringPayment_schema_1.GetRecurringPaymentResponse,
11
+ create: recurringPayment_schema_1.CreateRecurringPaymentResponse,
12
+ update: recurringPayment_schema_1.UpdateRecurringPaymentResponse,
13
+ delete: recurringPayment_schema_1.DeleteRecurringPaymentResponse,
14
+ });
15
+ }
16
+ async getAll(query, requestConfig) {
17
+ return super.getAll(query, requestConfig);
18
+ }
19
+ determineNextExecutionDate(executeAt) {
20
+ const today = new Date();
21
+ return today.getDate() < executeAt
22
+ ? new Date(today.getFullYear(), today.getMonth(), executeAt)
23
+ : new Date(today.getFullYear(), today.getMonth() + 1, executeAt);
24
+ }
25
+ }
26
+ exports.RecurringPaymentService = RecurringPaymentService;
@@ -0,0 +1,43 @@
1
+ import type { TResult } from "../types/common";
2
+ import type { IGetAllTransactionsQuery } from "../types/interfaces/transaction.interface";
3
+ import { CreateTransactionResponse, DeleteTransactionResponse, GetAllTransactionsResponse, GetTransactionResponse, UpdateTransactionResponse } from "../types/schemas/transaction.schema";
4
+ import type { TCreateOrUpdateTransactionPayload, TReceiverVH } from "../types/transaction.type";
5
+ import { EntityService } from "./entity.service";
6
+ export declare class TransactionService extends EntityService<TCreateOrUpdateTransactionPayload, Partial<TCreateOrUpdateTransactionPayload>, typeof GetAllTransactionsResponse, typeof GetTransactionResponse, typeof CreateTransactionResponse, typeof UpdateTransactionResponse, typeof DeleteTransactionResponse> {
7
+ constructor(host: string, entityPath?: string);
8
+ getAll(query?: IGetAllTransactionsQuery, requestConfig?: RequestInit): Promise<TResult<{
9
+ status: number;
10
+ data: {
11
+ id: string & import("zod").$brand<"TransactionID">;
12
+ ownerId: string & import("zod").$brand<"UserID">;
13
+ createdAt: string;
14
+ updatedAt: string;
15
+ processedAt: string | Date;
16
+ receiver: string;
17
+ transferAmount: number;
18
+ information: string | null;
19
+ category: {
20
+ id: string & import("zod").$brand<"CategoryID">;
21
+ ownerId: string & import("zod").$brand<"UserID">;
22
+ name: string;
23
+ description: string | null;
24
+ createdAt: string;
25
+ updatedAt: string;
26
+ };
27
+ paymentMethod: {
28
+ id: string & import("zod").$brand<"PaymentMethodID">;
29
+ ownerId: string & import("zod").$brand<"UserID">;
30
+ name: string;
31
+ provider: string;
32
+ address: string;
33
+ description: string | null;
34
+ createdAt: string;
35
+ updatedAt: string;
36
+ };
37
+ }[] | null;
38
+ message?: string | undefined;
39
+ totalCount?: number | undefined;
40
+ from?: "db" | "cache" | "external" | undefined;
41
+ }>>;
42
+ getReceiverVH(requestConfig?: RequestInit): Promise<TResult<TReceiverVH[]>>;
43
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionService = void 0;
4
+ const error_1 = require("../error");
5
+ const transaction_schema_1 = require("../types/schemas/transaction.schema");
6
+ const entity_service_1 = require("./entity.service");
7
+ class TransactionService extends entity_service_1.EntityService {
8
+ constructor(host, entityPath = "/api/transaction") {
9
+ super(host, entityPath, {
10
+ getAll: transaction_schema_1.GetAllTransactionsResponse,
11
+ get: transaction_schema_1.GetTransactionResponse,
12
+ create: transaction_schema_1.CreateTransactionResponse,
13
+ update: transaction_schema_1.UpdateTransactionResponse,
14
+ delete: transaction_schema_1.DeleteTransactionResponse,
15
+ });
16
+ }
17
+ async getAll(query, requestConfig) {
18
+ return super.getAll(query, requestConfig);
19
+ }
20
+ async getReceiverVH(requestConfig) {
21
+ var _a;
22
+ try {
23
+ const response = await fetch(`${this.getBaseRequestPath()}/receiver`, this.mergeRequestConfig({
24
+ method: "GET",
25
+ headers: new Headers((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.headers) || {}),
26
+ credentials: "include",
27
+ }, requestConfig));
28
+ if (!response.ok) {
29
+ throw new error_1.BackendError(response.status, response.statusText);
30
+ }
31
+ if (!this.isJsonResponse(response)) {
32
+ throw new error_1.ResponseNotJsonError();
33
+ }
34
+ const data = await response.json();
35
+ const parsingResult = transaction_schema_1.ReceiverVHResponse.safeParse(data);
36
+ if (!parsingResult.success) {
37
+ return this.handleZodError(parsingResult.error);
38
+ }
39
+ return [(_a = parsingResult.data.data) !== null && _a !== void 0 ? _a : [], null];
40
+ }
41
+ catch (error) {
42
+ return this.handleError(error);
43
+ }
44
+ }
45
+ }
46
+ exports.TransactionService = TransactionService;
@@ -0,0 +1,4 @@
1
+ export * from "./services/transaction.service";
2
+ export * from "./types/interfaces/transaction.interface";
3
+ export * from "./types/schemas/transaction.schema";
4
+ export * from "./types/transaction.type";
@@ -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/transaction.service"), exports);
18
+ __exportStar(require("./types/interfaces/transaction.interface"), exports);
19
+ __exportStar(require("./types/schemas/transaction.schema"), exports);
20
+ __exportStar(require("./types/transaction.type"), exports);
@@ -0,0 +1,5 @@
1
+ import type { TypeOfSchema } from "./common";
2
+ import type * as schema from "./schemas/budget.schema";
3
+ export type TBudget = TypeOfSchema<typeof schema.Budget>;
4
+ export type TCreateOrUpdateBudgetPayload = TypeOfSchema<typeof schema.CreateOrUpdateBudgetPayload>;
5
+ export type TEstimatedBudget = TypeOfSchema<typeof schema.EstimatedBudget>;