feat: adds TS types
This commit is contained in:
14
shared/package.json
Normal file
14
shared/package.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
1
shared/src/index.ts
Normal file
1
shared/src/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './types';
|
||||
11
shared/src/types/account.ts
Normal file
11
shared/src/types/account.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export interface Account {
|
||||
id: number;
|
||||
bank: string;
|
||||
accountNumberMasked: string;
|
||||
currency: string;
|
||||
alias: string | null;
|
||||
}
|
||||
|
||||
export interface UpdateAccountRequest {
|
||||
alias: string;
|
||||
}
|
||||
53
shared/src/types/analytics.ts
Normal file
53
shared/src/types/analytics.ts
Normal file
@@ -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;
|
||||
}
|
||||
8
shared/src/types/auth.ts
Normal file
8
shared/src/types/auth.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export interface LoginRequest {
|
||||
login: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface MeResponse {
|
||||
login: string;
|
||||
}
|
||||
39
shared/src/types/category-rule.ts
Normal file
39
shared/src/types/category-rule.ts
Normal file
@@ -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;
|
||||
}
|
||||
12
shared/src/types/category.ts
Normal file
12
shared/src/types/category.ts
Normal file
@@ -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;
|
||||
}
|
||||
24
shared/src/types/common.ts
Normal file
24
shared/src/types/common.ts
Normal file
@@ -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<T> {
|
||||
items: T[];
|
||||
page: number;
|
||||
pageSize: number;
|
||||
totalItems: number;
|
||||
totalPages: number;
|
||||
}
|
||||
|
||||
export interface ApiError {
|
||||
error: string;
|
||||
message: string;
|
||||
}
|
||||
31
shared/src/types/import.ts
Normal file
31
shared/src/types/import.ts
Normal file
@@ -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;
|
||||
}
|
||||
50
shared/src/types/index.ts
Normal file
50
shared/src/types/index.ts
Normal file
@@ -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';
|
||||
37
shared/src/types/transaction.ts
Normal file
37
shared/src/types/transaction.ts
Normal file
@@ -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;
|
||||
}
|
||||
19
shared/tsconfig.json
Normal file
19
shared/tsconfig.json
Normal file
@@ -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"]
|
||||
}
|
||||
Reference in New Issue
Block a user