From ad4ad55e357913545e75fb3721567c516a88f2fa Mon Sep 17 00:00:00 2001 From: vakabunga Date: Mon, 2 Mar 2026 00:34:40 +0300 Subject: [PATCH] feat: adds TS types --- shared/package.json | 14 ++++++++ shared/src/index.ts | 1 + shared/src/types/account.ts | 11 +++++++ shared/src/types/analytics.ts | 53 +++++++++++++++++++++++++++++++ shared/src/types/auth.ts | 8 +++++ shared/src/types/category-rule.ts | 39 +++++++++++++++++++++++ shared/src/types/category.ts | 12 +++++++ shared/src/types/common.ts | 24 ++++++++++++++ shared/src/types/import.ts | 31 ++++++++++++++++++ shared/src/types/index.ts | 50 +++++++++++++++++++++++++++++ shared/src/types/transaction.ts | 37 +++++++++++++++++++++ shared/tsconfig.json | 19 +++++++++++ 12 files changed, 299 insertions(+) create mode 100644 shared/package.json create mode 100644 shared/src/index.ts create mode 100644 shared/src/types/account.ts create mode 100644 shared/src/types/analytics.ts create mode 100644 shared/src/types/auth.ts create mode 100644 shared/src/types/category-rule.ts create mode 100644 shared/src/types/category.ts create mode 100644 shared/src/types/common.ts create mode 100644 shared/src/types/import.ts create mode 100644 shared/src/types/index.ts create mode 100644 shared/src/types/transaction.ts create mode 100644 shared/tsconfig.json diff --git a/shared/package.json b/shared/package.json new file mode 100644 index 0000000..44a32de --- /dev/null +++ b/shared/package.json @@ -0,0 +1,14 @@ +{ + "name": "@family-budget/shared", + "version": "0.1.0", + "private": true, + "main": "dist/index.js", + "types": "dist/index.d.ts", + "scripts": { + "build": "tsc", + "dev": "tsc --watch" + }, + "devDependencies": { + "typescript": "^5.7.0" + } +} diff --git a/shared/src/index.ts b/shared/src/index.ts new file mode 100644 index 0000000..fcb073f --- /dev/null +++ b/shared/src/index.ts @@ -0,0 +1 @@ +export * from './types'; diff --git a/shared/src/types/account.ts b/shared/src/types/account.ts new file mode 100644 index 0000000..723f204 --- /dev/null +++ b/shared/src/types/account.ts @@ -0,0 +1,11 @@ +export interface Account { + id: number; + bank: string; + accountNumberMasked: string; + currency: string; + alias: string | null; +} + +export interface UpdateAccountRequest { + alias: string; +} diff --git a/shared/src/types/analytics.ts b/shared/src/types/analytics.ts new file mode 100644 index 0000000..82b92cf --- /dev/null +++ b/shared/src/types/analytics.ts @@ -0,0 +1,53 @@ +import type { Granularity } from './common'; + +export interface AnalyticsSummaryParams { + from: string; + to: string; + accountId?: number; + onlyConfirmed?: boolean; +} + +export interface TopCategory { + categoryId: number; + categoryName: string; + amount: number; + share: number; +} + +export interface AnalyticsSummaryResponse { + totalExpense: number; + totalIncome: number; + net: number; + topCategories: TopCategory[]; +} + +export interface ByCategoryParams { + from: string; + to: string; + accountId?: number; + onlyConfirmed?: boolean; +} + +export interface ByCategoryItem { + categoryId: number; + categoryName: string; + amount: number; + txCount: number; + share: number; +} + +export interface TimeseriesParams { + from: string; + to: string; + accountId?: number; + categoryId?: number; + onlyConfirmed?: boolean; + granularity: Granularity; +} + +export interface TimeseriesItem { + periodStart: string; + periodEnd: string; + expenseAmount: number; + incomeAmount: number; +} diff --git a/shared/src/types/auth.ts b/shared/src/types/auth.ts new file mode 100644 index 0000000..e7a5d37 --- /dev/null +++ b/shared/src/types/auth.ts @@ -0,0 +1,8 @@ +export interface LoginRequest { + login: string; + password: string; +} + +export interface MeResponse { + login: string; +} diff --git a/shared/src/types/category-rule.ts b/shared/src/types/category-rule.ts new file mode 100644 index 0000000..14d3e19 --- /dev/null +++ b/shared/src/types/category-rule.ts @@ -0,0 +1,39 @@ +import type { MatchType } from './common'; + +export interface CategoryRule { + id: number; + pattern: string; + matchType: MatchType; + categoryId: number; + categoryName: string; + priority: number; + requiresConfirmation: boolean; + isActive: boolean; + createdAt: string; +} + +export interface GetCategoryRulesParams { + isActive?: boolean; + categoryId?: number; + search?: string; +} + +export interface CreateCategoryRuleRequest { + pattern: string; + matchType?: MatchType; + categoryId: number; + priority?: number; + requiresConfirmation?: boolean; +} + +export interface UpdateCategoryRuleRequest { + pattern?: string; + categoryId?: number; + priority?: number; + requiresConfirmation?: boolean; + isActive?: boolean; +} + +export interface ApplyRuleResponse { + applied: number; +} diff --git a/shared/src/types/category.ts b/shared/src/types/category.ts new file mode 100644 index 0000000..7498c1e --- /dev/null +++ b/shared/src/types/category.ts @@ -0,0 +1,12 @@ +import type { CategoryType } from './common'; + +export interface Category { + id: number; + name: string; + type: CategoryType; + isActive: boolean; +} + +export interface GetCategoriesParams { + isActive?: boolean; +} diff --git a/shared/src/types/common.ts b/shared/src/types/common.ts new file mode 100644 index 0000000..4b04a3b --- /dev/null +++ b/shared/src/types/common.ts @@ -0,0 +1,24 @@ +export type Direction = 'income' | 'expense' | 'transfer'; + +export type CategoryType = 'expense' | 'income' | 'transfer'; + +export type MatchType = 'contains' | 'starts_with' | 'regex'; + +export type SortOrder = 'asc' | 'desc'; + +export type TransactionSortBy = 'date' | 'amount'; + +export type Granularity = 'day' | 'week' | 'month'; + +export interface PaginatedResponse { + items: T[]; + page: number; + pageSize: number; + totalItems: number; + totalPages: number; +} + +export interface ApiError { + error: string; + message: string; +} diff --git a/shared/src/types/import.ts b/shared/src/types/import.ts new file mode 100644 index 0000000..23e9cbf --- /dev/null +++ b/shared/src/types/import.ts @@ -0,0 +1,31 @@ +/** JSON 1.0 statement file — the shape accepted by POST /api/import/statement */ +export interface StatementFile { + schemaVersion: '1.0'; + bank: string; + statement: StatementHeader; + transactions: StatementTransaction[]; +} + +export interface StatementHeader { + accountNumber: string; + currency: string; + openingBalance: number; + closingBalance: number; + exportedAt: string; +} + +export interface StatementTransaction { + operationAt: string; + amountSigned: number; + commission: number; + description: string; +} + +export interface ImportStatementResponse { + accountId: number; + isNewAccount: boolean; + accountNumberMasked: string; + imported: number; + duplicatesSkipped: number; + totalInFile: number; +} diff --git a/shared/src/types/index.ts b/shared/src/types/index.ts new file mode 100644 index 0000000..3794c73 --- /dev/null +++ b/shared/src/types/index.ts @@ -0,0 +1,50 @@ +export type { + Direction, + CategoryType, + MatchType, + SortOrder, + TransactionSortBy, + Granularity, + PaginatedResponse, + ApiError, +} from './common'; + +export type { Account, UpdateAccountRequest } from './account'; + +export type { + Category, + GetCategoriesParams, +} from './category'; + +export type { + Transaction, + GetTransactionsParams, + UpdateTransactionRequest, +} from './transaction'; + +export type { + CategoryRule, + GetCategoryRulesParams, + CreateCategoryRuleRequest, + UpdateCategoryRuleRequest, + ApplyRuleResponse, +} from './category-rule'; + +export type { LoginRequest, MeResponse } from './auth'; + +export type { + StatementFile, + StatementHeader, + StatementTransaction, + ImportStatementResponse, +} from './import'; + +export type { + AnalyticsSummaryParams, + TopCategory, + AnalyticsSummaryResponse, + ByCategoryParams, + ByCategoryItem, + TimeseriesParams, + TimeseriesItem, +} from './analytics'; diff --git a/shared/src/types/transaction.ts b/shared/src/types/transaction.ts new file mode 100644 index 0000000..866289b --- /dev/null +++ b/shared/src/types/transaction.ts @@ -0,0 +1,37 @@ +import type { Direction, SortOrder, TransactionSortBy } from './common'; + +export interface Transaction { + id: number; + operationAt: string; + accountId: number; + accountAlias: string | null; + amountSigned: number; + commission: number; + description: string; + direction: Direction; + categoryId: number | null; + categoryName: string | null; + isCategoryConfirmed: boolean; + comment: string | null; +} + +export interface GetTransactionsParams { + accountId?: number; + from?: string; + to?: string; + direction?: string; + categoryId?: number; + search?: string; + amountMin?: number; + amountMax?: number; + onlyUnconfirmed?: boolean; + sortBy?: TransactionSortBy; + sortOrder?: SortOrder; + page?: number; + pageSize?: number; +} + +export interface UpdateTransactionRequest { + categoryId?: number | null; + comment?: string | null; +} diff --git a/shared/tsconfig.json b/shared/tsconfig.json new file mode 100644 index 0000000..f276bad --- /dev/null +++ b/shared/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "commonjs", + "lib": ["ES2022"], + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "outDir": "dist", + "rootDir": "src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true + }, + "include": ["src"], + "exclude": ["node_modules", "dist"] +}