@gabrielerandelli/minus-tracker 0.5.7 → 0.6.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.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/rates/index.ts","../src/parser/warnings.ts","../src/parser/index.ts","../src/calculator/index.ts"],"sourcesContent":["export class ParseError extends Error {\n readonly code: \"INVALID_CSV\" | \"MISSING_COLUMN\";\n readonly columnName?: string;\n\n constructor(code: \"INVALID_CSV\");\n constructor(code: \"MISSING_COLUMN\", columnName: string);\n constructor(code: ParseError[\"code\"], columnName?: string) {\n const msg =\n code === \"INVALID_CSV\"\n ? \"Invalid CSV: unable to parse\"\n : `Missing required column: ${columnName}`;\n super(msg);\n this.name = \"ParseError\";\n this.code = code;\n this.columnName = columnName;\n }\n}\n\nexport class CalculationError extends Error {\n readonly isin: string;\n readonly date: string;\n\n constructor(isin: string, date: string) {\n super(`No open lots for ISIN ${isin} on ${date}`);\n this.name = \"CalculationError\";\n this.isin = isin;\n this.date = date;\n }\n}\n","import { fileURLToPath } from \"node:url\";\nimport * as path from \"node:path\";\nimport * as fs from \"node:fs\";\n\nexport type RatesSnapshot = Record<string, Record<string, number>>;\n\n// Load the bundled snapshot lazily; returns null if the file is absent (e.g. broken install)\nlet _bundled: RatesSnapshot | null | undefined = undefined;\n\nfunction getBundledSnapshot(): RatesSnapshot | null {\n if (_bundled !== undefined) return _bundled;\n const __dirname = path.dirname(fileURLToPath(import.meta.url));\n const bundledPath = path.join(__dirname, \"../data/ecb-rates.json\");\n try {\n _bundled = JSON.parse(\n fs.readFileSync(bundledPath, \"utf8\"),\n ) as RatesSnapshot;\n } catch {\n _bundled = null;\n }\n return _bundled;\n}\n\nfunction getUserSnapshot(): RatesSnapshot | null {\n const platform = process.platform;\n let configDir: string;\n if (platform === \"win32\") {\n configDir =\n process.env.APPDATA ??\n path.join(process.env.USERPROFILE ?? \"~\", \"AppData\", \"Roaming\");\n } else {\n configDir =\n process.env.XDG_CONFIG_HOME ??\n path.join(process.env.HOME ?? \"~\", \".config\");\n }\n const userPath = path.join(configDir, \"minus-tracker\", \"ecb-rates.json\");\n try {\n return JSON.parse(fs.readFileSync(userPath, \"utf8\")) as RatesSnapshot;\n } catch {\n return null;\n }\n}\n\nexport function getActiveSnapshot(): RatesSnapshot {\n const bundled = getBundledSnapshot();\n const user = getUserSnapshot();\n if (!bundled && !user) {\n throw new Error(\n \"No ECB rates snapshot available. Run `minus-tracker rates --update` to fetch rates.\",\n );\n }\n if (!bundled) return user!;\n if (!user) return bundled;\n // Merge: user entries override bundled for same date keys\n const merged: RatesSnapshot = {};\n for (const ccy of new Set([...Object.keys(bundled), ...Object.keys(user)])) {\n merged[ccy] = { ...(bundled[ccy] ?? {}), ...(user[ccy] ?? {}) };\n }\n return merged;\n}\n\nexport function isSnapshotStale(\n snapshot: RatesSnapshot,\n today?: string,\n): boolean {\n const todayStr = today ?? new Date().toISOString().slice(0, 10);\n let maxDate = \"0000-01-01\";\n for (const dates of Object.values(snapshot)) {\n for (const d of Object.keys(dates)) {\n if (d > maxDate) maxDate = d;\n }\n }\n if (maxDate === \"0000-01-01\") return true;\n const diffDays =\n (new Date(todayStr).getTime() - new Date(maxDate).getTime()) /\n (1000 * 60 * 60 * 24);\n return diffDays >= 7;\n}\n\nfunction subtractDays(isoDate: string, days: number): string {\n const d = new Date(isoDate + \"T00:00:00Z\");\n d.setUTCDate(d.getUTCDate() - days);\n return d.toISOString().slice(0, 10);\n}\n\n/**\n * Look up ECB rate for a currency on a given date.\n * Returns 1.0 for EUR. Walks back up to 3 calendar days for weekend/holiday gaps.\n * Returns null if not found within the window.\n *\n * @param currency ISO 4217 currency code\n * @param date YYYY-MM-DD trade date\n * @param snapshot Optional override (used in tests to inject stub data)\n */\nexport function lookupRate(\n currency: string,\n date: string,\n snapshot?: RatesSnapshot,\n): number | null {\n if (currency === \"EUR\") return 1.0;\n\n const s = snapshot ?? getActiveSnapshot();\n const currencyRates = s[currency];\n if (!currencyRates) return null; // unsupported currency\n\n for (let i = 0; i <= 3; i++) {\n const d = i === 0 ? date : subtractDays(date, i);\n if (currencyRates[d] !== undefined) {\n return currencyRates[d];\n }\n }\n return null;\n}\n","export type WarningEntry =\n | { code: \"MISSING_ISIN\"; row: number }\n | { code: \"UNSUPPORTED_CURRENCY\"; row: number; currency: string }\n | { code: \"NO_ECB_RATE\"; row: number; currency: string; date: string }\n | { code: \"QUANTITY_ZERO\"; row: number };\n\nexport function warningToEnglish(w: WarningEntry): string {\n switch (w.code) {\n case \"MISSING_ISIN\":\n return `Row ${w.row}: missing ISIN — skipped`;\n case \"UNSUPPORTED_CURRENCY\":\n return `Row ${w.row}: unsupported currency ${w.currency} — skipped`;\n case \"NO_ECB_RATE\":\n return `Row ${w.row}: no ECB rate for ${w.currency} on ${w.date} — skipped`;\n case \"QUANTITY_ZERO\":\n return `Row ${w.row}: quantity is 0 — skipped`;\n }\n}\n","import { Transaction } from \"../types.js\";\nimport { ParseError } from \"../errors.js\";\nimport {\n lookupRate,\n getActiveSnapshot,\n RatesSnapshot,\n} from \"../rates/index.js\";\nimport { WarningEntry, warningToEnglish } from \"./warnings.js\";\n\nconst REQUIRED_COLUMNS = [\n \"ISIN\",\n \"Quantity\",\n \"Price\",\n \"Date\",\n \"Local value\",\n \"Local value currency\",\n \"Transaction costs\",\n \"Transaction costs currency\",\n \"Product\",\n] as const;\n\n/**\n * Parse a single CSV line, respecting RFC-4180-style double-quote escaping.\n * Does not support embedded newlines in fields (not needed for DEGIRO exports).\n */\nfunction parseCSVRow(line: string): string[] {\n const fields: string[] = [];\n let i = 0;\n\n while (i <= line.length) {\n // End of line — stop (handles trailing comma by not emitting extra empty field)\n if (i === line.length) break;\n\n if (line[i] === '\"') {\n // Quoted field\n let field = \"\";\n i++; // skip opening quote\n while (i < line.length) {\n if (line[i] === '\"' && i + 1 < line.length && line[i + 1] === '\"') {\n // Escaped double-quote\n field += '\"';\n i += 2;\n } else if (line[i] === '\"') {\n i++; // skip closing quote\n break;\n } else {\n field += line[i++];\n }\n }\n fields.push(field);\n if (i < line.length && line[i] === \",\") i++; // skip delimiter\n } else {\n // Unquoted field\n const start = i;\n while (i < line.length && line[i] !== \",\") i++;\n fields.push(line.slice(start, i));\n if (i < line.length) i++; // skip delimiter\n }\n }\n\n return fields;\n}\n\n/**\n * Parse a full CSV string (CRLF or LF line endings) into a 2-D array of strings.\n */\nfunction parseCSV(input: string): string[][] {\n const normalized = input.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n return normalized.split(\"\\n\").map(parseCSVRow);\n}\n\n/**\n * Convert a DEGIRO date \"DD-MM-YYYY\" to ISO format \"YYYY-MM-DD\".\n */\nfunction parseDate(ddmmyyyy: string): string {\n const [dd, mm, yyyy] = ddmmyyyy.split(\"-\");\n return `${yyyy}-${mm}-${dd}`;\n}\n\nexport class DEGIROParser {\n private _warningEntries: WarningEntry[] = [];\n private _snapshot?: RatesSnapshot;\n\n constructor(snapshot?: RatesSnapshot) {\n this._snapshot = snapshot;\n }\n\n parse(csv: string): Transaction[] {\n this._warningEntries = [];\n\n // Binary content (null bytes) is not valid CSV\n if (typeof csv !== \"string\" || csv.includes(\"\\x00\")) {\n throw new ParseError(\"INVALID_CSV\");\n }\n\n let rows: string[][];\n try {\n rows = parseCSV(csv);\n } catch {\n throw new ParseError(\"INVALID_CSV\");\n }\n\n if (rows.length === 0) {\n throw new ParseError(\"INVALID_CSV\");\n }\n\n // Build column-name → index map from the header row\n const header = rows[0];\n const colIndex: Record<string, number> = {};\n for (let i = 0; i < header.length; i++) {\n colIndex[header[i].trim()] = i;\n }\n\n // Validate that every required column is present\n for (const col of REQUIRED_COLUMNS) {\n if (colIndex[col] === undefined) {\n throw new ParseError(\"MISSING_COLUMN\", col);\n }\n }\n\n // Resolve the rates snapshot once for the whole parse run\n const snapshot: RatesSnapshot = this._snapshot ?? getActiveSnapshot();\n\n const transactions: Transaction[] = [];\n\n for (let r = 1; r < rows.length; r++) {\n const row = rows[r];\n // 1-indexed row number: header = 1, first data row = 2\n const rowIndex = r + 1;\n\n // Skip completely empty rows (including the trailing empty line after a\n // final newline, and rows that are all whitespace)\n if (row.every((cell) => cell.trim() === \"\")) continue;\n\n const get = (col: string): string => (row[colIndex[col]] ?? \"\").trim();\n\n // --- ISIN ---\n const isin = get(\"ISIN\");\n if (!isin) {\n this._warningEntries.push({ code: \"MISSING_ISIN\", row: rowIndex });\n continue;\n }\n\n // --- Quantity ---\n const rawQty = parseFloat(get(\"Quantity\"));\n if (isNaN(rawQty) || rawQty === 0) {\n this._warningEntries.push({ code: \"QUANTITY_ZERO\", row: rowIndex });\n continue;\n }\n\n const type: \"BUY\" | \"SELL\" = rawQty > 0 ? \"BUY\" : \"SELL\";\n const quantity = Math.abs(rawQty);\n\n // --- Date ---\n const isoDate = parseDate(get(\"Date\"));\n\n // --- Currency & FX ---\n const currency = get(\"Local value currency\");\n const rawTotalLocal = parseFloat(get(\"Local value\"));\n const totalLocal = isNaN(rawTotalLocal) ? 0 : rawTotalLocal;\n\n let totalEUR: number;\n let fxRate: number | undefined;\n\n if (currency === \"EUR\") {\n totalEUR = Math.abs(totalLocal);\n fxRate = undefined;\n } else {\n const rate = lookupRate(currency, isoDate, snapshot);\n if (rate === null) {\n if (snapshot[currency] === undefined) {\n this._warningEntries.push({\n code: \"UNSUPPORTED_CURRENCY\",\n row: rowIndex,\n currency,\n });\n } else {\n this._warningEntries.push({\n code: \"NO_ECB_RATE\",\n row: rowIndex,\n currency,\n date: isoDate,\n });\n }\n continue;\n }\n totalEUR = Math.abs(totalLocal) / rate;\n fxRate = rate;\n }\n\n // --- Fees ---\n const rawFees = parseFloat(get(\"Transaction costs\"));\n const feesEUR = Math.abs(isNaN(rawFees) ? 0 : rawFees);\n\n // --- Remaining fields ---\n const pricePerUnit = parseFloat(get(\"Price\"));\n const product = get(\"Product\");\n\n transactions.push({\n isin,\n product,\n date: isoDate,\n type,\n quantity,\n pricePerUnit,\n currency,\n totalLocal,\n totalEUR,\n feesEUR,\n fxRate,\n });\n }\n\n return transactions;\n }\n\n get warnings(): string[] {\n return this._warningEntries.map(warningToEnglish);\n }\n\n get warningEntries(): WarningEntry[] {\n return this._warningEntries;\n }\n}\n","import type {\n Transaction,\n MatchedLot,\n GainsReport,\n LotMethod,\n} from \"../types.js\";\nimport { CalculationError } from \"../errors.js\";\n\ninterface Lot {\n date: string;\n quantity: number;\n pricePerUnitEUR: number;\n feesEUR: number;\n originalQty: number;\n fxRate?: number;\n}\n\nfunction roundHalfUp(x: number): number {\n return (Math.sign(x) * Math.round(Math.abs(x) * 100)) / 100;\n}\n\nfunction inferTaxYear(transactions: Transaction[]): {\n year: number;\n multipleYears: boolean;\n} {\n const counts: Record<string, number> = {};\n for (const t of transactions) {\n const y = t.date.slice(0, 4);\n counts[y] = (counts[y] ?? 0) + 1;\n }\n const years = Object.keys(counts);\n if (years.length === 0)\n return { year: new Date().getFullYear(), multipleYears: false };\n const year = parseInt(\n years.reduce((a, b) => (counts[a] >= counts[b] ? a : b)),\n );\n return { year, multipleYears: years.length > 1 };\n}\n\nexport class Calculator {\n private readonly _transactions: Transaction[];\n private readonly _parseWarnings: string[];\n\n constructor(transactions: Transaction[], parseWarnings?: string[]) {\n this._transactions = transactions;\n this._parseWarnings = parseWarnings ?? [];\n }\n\n calculateGains(method: LotMethod): GainsReport {\n const warnings: string[] = [...this._parseWarnings];\n\n // 1. Sort ascending by date; BUY before SELL on same date\n const sorted = [...this._transactions].sort((a, b) => {\n if (a.date < b.date) return -1;\n if (a.date > b.date) return 1;\n // Same date: BUY before SELL\n if (a.type === \"BUY\" && b.type === \"SELL\") return -1;\n if (a.type === \"SELL\" && b.type === \"BUY\") return 1;\n return 0;\n });\n\n // 2. Tax year inference\n const { year: taxYear, multipleYears } = inferTaxYear(sorted);\n if (multipleYears) {\n warnings.push(\n \"CSV contains transactions from multiple years — filter to a single year for accurate reporting.\",\n );\n }\n\n // 3. Lot matching\n const openLots = new Map<string, Lot[]>();\n const matchedLots: MatchedLot[] = [];\n const ratesUsed: Record<string, number> = {};\n\n for (const tx of sorted) {\n // Collect rates used\n if (tx.fxRate !== undefined) {\n ratesUsed[`${tx.currency}:${tx.date}`] = tx.fxRate;\n }\n\n if (tx.type === \"BUY\") {\n const lot: Lot = {\n date: tx.date,\n quantity: tx.quantity,\n pricePerUnitEUR: tx.totalEUR / tx.quantity,\n feesEUR: tx.feesEUR,\n originalQty: tx.quantity,\n fxRate: tx.fxRate,\n };\n if (!openLots.has(tx.isin)) openLots.set(tx.isin, []);\n openLots.get(tx.isin)!.push(lot);\n } else {\n // SELL\n const lots = openLots.get(tx.isin);\n if (!lots || lots.length === 0) {\n throw new CalculationError(tx.isin, tx.date);\n }\n\n const sellPricePerUnitEUR = tx.totalEUR / tx.quantity;\n let remainingSellQty = tx.quantity;\n\n while (remainingSellQty > 0) {\n if (!lots || lots.length === 0) {\n throw new CalculationError(tx.isin, tx.date);\n }\n\n const lot = method === \"LIFO\" ? lots[lots.length - 1] : lots[0];\n const matchedQty = Math.min(lot.quantity, remainingSellQty);\n\n // Fee allocation\n const allocatedBuyFeesEUR =\n lot.feesEUR * (matchedQty / lot.originalQty);\n const allocatedSellFeesEUR = tx.feesEUR * (matchedQty / tx.quantity);\n\n const buyCostEUR =\n lot.pricePerUnitEUR * matchedQty + allocatedBuyFeesEUR;\n const sellProceedsEUR =\n sellPricePerUnitEUR * matchedQty - allocatedSellFeesEUR;\n const gainLossEUR = sellProceedsEUR - buyCostEUR;\n\n matchedLots.push({\n isin: tx.isin,\n product: tx.product,\n quantity: matchedQty,\n buyDate: lot.date,\n sellDate: tx.date,\n buyPriceEUR: lot.pricePerUnitEUR,\n sellPriceEUR: sellPricePerUnitEUR,\n buyCostEUR: roundHalfUp(buyCostEUR),\n sellProceedsEUR: roundHalfUp(sellProceedsEUR),\n gainLossEUR: roundHalfUp(gainLossEUR),\n buyFxRate: lot.fxRate,\n sellFxRate: tx.fxRate,\n });\n\n lot.quantity -= matchedQty;\n remainingSellQty -= matchedQty;\n\n if (lot.quantity <= 0) {\n if (method === \"LIFO\") {\n lots.pop();\n } else {\n lots.shift();\n }\n }\n }\n }\n }\n\n // 4. Aggregate\n let plusvalenze = 0;\n let minusvalenze = 0;\n for (const lot of matchedLots) {\n if (lot.gainLossEUR > 0) plusvalenze += lot.gainLossEUR;\n else minusvalenze += Math.abs(lot.gainLossEUR);\n }\n\n return {\n method,\n taxYear,\n plusvalenze: roundHalfUp(plusvalenze),\n minusvalenze: roundHalfUp(minusvalenze),\n netResult: roundHalfUp(plusvalenze - minusvalenze),\n lots: matchedLots,\n ratesUsed,\n warnings,\n generatedAt: new Date().toISOString(),\n };\n }\n}\n"],"mappings":";AAAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAC3B;AAAA,EACA;AAAA,EAIT,YAAY,MAA0B,YAAqB;AACzD,UAAM,MACJ,SAAS,gBACL,iCACA,4BAA4B,UAAU;AAC5C,UAAM,GAAG;AACT,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EACjC;AAAA,EACA;AAAA,EAET,YAAY,MAAc,MAAc;AACtC,UAAM,yBAAyB,IAAI,OAAO,IAAI,EAAE;AAChD,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;;;AC5BA,SAAS,qBAAqB;AAC9B,YAAY,UAAU;AACtB,YAAY,QAAQ;AAKpB,IAAI,WAA6C;AAEjD,SAAS,qBAA2C;AAClD,MAAI,aAAa,OAAW,QAAO;AACnC,QAAM,YAAiB,aAAQ,cAAc,YAAY,GAAG,CAAC;AAC7D,QAAM,cAAmB,UAAK,WAAW,wBAAwB;AACjE,MAAI;AACF,eAAW,KAAK;AAAA,MACX,gBAAa,aAAa,MAAM;AAAA,IACrC;AAAA,EACF,QAAQ;AACN,eAAW;AAAA,EACb;AACA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nB,eAAW,OAAO,aAAa;AAC7B,UAAI,IAAI,cAAc,EAAG,gBAAe,IAAI;AAAA,UACvC,iBAAgB,KAAK,IAAI,IAAI,WAAW;AAAA,IAC/C;AAEA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,aAAa,YAAY,WAAW;AAAA,MACpC,cAAc,YAAY,YAAY;AAAA,MACtC,WAAW,YAAY,cAAc,YAAY;AAAA,MACjD,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,IACtC;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/rates/index.ts","../src/parser/warnings.ts","../src/parser/index.ts","../src/calculator/index.ts","../src/classifier/index.ts"],"sourcesContent":["export class ParseError extends Error {\n readonly code: \"INVALID_CSV\" | \"MISSING_COLUMN\";\n readonly columnName?: string;\n\n constructor(code: \"INVALID_CSV\");\n constructor(code: \"MISSING_COLUMN\", columnName: string);\n constructor(code: ParseError[\"code\"], columnName?: string) {\n const msg =\n code === \"INVALID_CSV\"\n ? \"Invalid CSV: unable to parse\"\n : `Missing required column: ${columnName}`;\n super(msg);\n this.name = \"ParseError\";\n this.code = code;\n this.columnName = columnName;\n }\n}\n\nexport class CalculationError extends Error {\n readonly isin: string;\n readonly date: string;\n\n constructor(isin: string, date: string) {\n super(`No open lots for ISIN ${isin} on ${date}`);\n this.name = \"CalculationError\";\n this.isin = isin;\n this.date = date;\n }\n}\n\nexport class ClassificationError extends Error {\n readonly code:\n | \"NETWORK_ERROR\"\n | \"SIDECAR_NOT_FOUND\"\n | \"SIDECAR_VERSION\"\n | \"SIDECAR_MALFORMED\"\n | \"WRITE_ERROR\";\n\n constructor(code: ClassificationError[\"code\"], message?: string) {\n super(\n message ??\n (code === \"SIDECAR_NOT_FOUND\"\n ? \"Sidecar file not found\"\n : code === \"SIDECAR_VERSION\"\n ? \"Sidecar version mismatch\"\n : code === \"SIDECAR_MALFORMED\"\n ? \"Sidecar file is malformed JSON\"\n : code === \"NETWORK_ERROR\"\n ? \"Network error contacting OpenFIGI\"\n : \"Failed to write sidecar file\"),\n );\n this.name = \"ClassificationError\";\n this.code = code;\n }\n}\n","import { fileURLToPath } from \"node:url\";\nimport * as path from \"node:path\";\nimport * as fs from \"node:fs\";\n\nexport type RatesSnapshot = Record<string, Record<string, number>>;\n\n// Load the bundled snapshot lazily; returns null if the file is absent (e.g. broken install)\nlet _bundled: RatesSnapshot | null | undefined = undefined;\n\nfunction getBundledSnapshot(): RatesSnapshot | null {\n if (_bundled !== undefined) return _bundled;\n const __dirname = path.dirname(fileURLToPath(import.meta.url));\n const bundledPath = path.join(__dirname, \"../data/ecb-rates.json\");\n try {\n _bundled = JSON.parse(\n fs.readFileSync(bundledPath, \"utf8\"),\n ) as RatesSnapshot;\n } catch {\n _bundled = null;\n }\n return _bundled;\n}\n\nfunction getUserSnapshot(): RatesSnapshot | null {\n const platform = process.platform;\n let configDir: string;\n if (platform === \"win32\") {\n configDir =\n process.env.APPDATA ??\n path.join(process.env.USERPROFILE ?? \"~\", \"AppData\", \"Roaming\");\n } else {\n configDir =\n process.env.XDG_CONFIG_HOME ??\n path.join(process.env.HOME ?? \"~\", \".config\");\n }\n const userPath = path.join(configDir, \"minus-tracker\", \"ecb-rates.json\");\n try {\n return JSON.parse(fs.readFileSync(userPath, \"utf8\")) as RatesSnapshot;\n } catch {\n return null;\n }\n}\n\nexport function getActiveSnapshot(): RatesSnapshot {\n const bundled = getBundledSnapshot();\n const user = getUserSnapshot();\n if (!bundled && !user) {\n throw new Error(\n \"No ECB rates snapshot available. Run `minus-tracker rates --update` to fetch rates.\",\n );\n }\n if (!bundled) return user!;\n if (!user) return bundled;\n // Merge: user entries override bundled for same date keys\n const merged: RatesSnapshot = {};\n for (const ccy of new Set([...Object.keys(bundled), ...Object.keys(user)])) {\n merged[ccy] = { ...(bundled[ccy] ?? {}), ...(user[ccy] ?? {}) };\n }\n return merged;\n}\n\nexport function isSnapshotStale(\n snapshot: RatesSnapshot,\n today?: string,\n): boolean {\n const todayStr = today ?? new Date().toISOString().slice(0, 10);\n let maxDate = \"0000-01-01\";\n for (const dates of Object.values(snapshot)) {\n for (const d of Object.keys(dates)) {\n if (d > maxDate) maxDate = d;\n }\n }\n if (maxDate === \"0000-01-01\") return true;\n const diffDays =\n (new Date(todayStr).getTime() - new Date(maxDate).getTime()) /\n (1000 * 60 * 60 * 24);\n return diffDays >= 7;\n}\n\nfunction subtractDays(isoDate: string, days: number): string {\n const d = new Date(isoDate + \"T00:00:00Z\");\n d.setUTCDate(d.getUTCDate() - days);\n return d.toISOString().slice(0, 10);\n}\n\n/**\n * Look up ECB rate for a currency on a given date.\n * Returns 1.0 for EUR. Walks back up to 3 calendar days for weekend/holiday gaps.\n * Returns null if not found within the window.\n *\n * @param currency ISO 4217 currency code\n * @param date YYYY-MM-DD trade date\n * @param snapshot Optional override (used in tests to inject stub data)\n */\nexport function lookupRate(\n currency: string,\n date: string,\n snapshot?: RatesSnapshot,\n): number | null {\n if (currency === \"EUR\") return 1.0;\n\n const s = snapshot ?? getActiveSnapshot();\n const currencyRates = s[currency];\n if (!currencyRates) return null; // unsupported currency\n\n for (let i = 0; i <= 3; i++) {\n const d = i === 0 ? date : subtractDays(date, i);\n if (currencyRates[d] !== undefined) {\n return currencyRates[d];\n }\n }\n return null;\n}\n","export type WarningEntry =\n | { code: \"MISSING_ISIN\"; row: number }\n | { code: \"UNSUPPORTED_CURRENCY\"; row: number; currency: string }\n | { code: \"NO_ECB_RATE\"; row: number; currency: string; date: string }\n | { code: \"QUANTITY_ZERO\"; row: number };\n\nexport function warningToEnglish(w: WarningEntry): string {\n switch (w.code) {\n case \"MISSING_ISIN\":\n return `Row ${w.row}: missing ISIN — skipped`;\n case \"UNSUPPORTED_CURRENCY\":\n return `Row ${w.row}: unsupported currency ${w.currency} — skipped`;\n case \"NO_ECB_RATE\":\n return `Row ${w.row}: no ECB rate for ${w.currency} on ${w.date} — skipped`;\n case \"QUANTITY_ZERO\":\n return `Row ${w.row}: quantity is 0 — skipped`;\n }\n}\n","import { Transaction } from \"../types.js\";\nimport { ParseError } from \"../errors.js\";\nimport {\n lookupRate,\n getActiveSnapshot,\n RatesSnapshot,\n} from \"../rates/index.js\";\nimport { WarningEntry, warningToEnglish } from \"./warnings.js\";\n\nconst REQUIRED_COLUMNS = [\n \"ISIN\",\n \"Quantity\",\n \"Price\",\n \"Date\",\n \"Local value\",\n \"Local value currency\",\n \"Transaction costs\",\n \"Transaction costs currency\",\n \"Product\",\n] as const;\n\n/**\n * Parse a single CSV line, respecting RFC-4180-style double-quote escaping.\n * Does not support embedded newlines in fields (not needed for DEGIRO exports).\n */\nfunction parseCSVRow(line: string): string[] {\n const fields: string[] = [];\n let i = 0;\n\n while (i <= line.length) {\n // End of line — stop (handles trailing comma by not emitting extra empty field)\n if (i === line.length) break;\n\n if (line[i] === '\"') {\n // Quoted field\n let field = \"\";\n i++; // skip opening quote\n while (i < line.length) {\n if (line[i] === '\"' && i + 1 < line.length && line[i + 1] === '\"') {\n // Escaped double-quote\n field += '\"';\n i += 2;\n } else if (line[i] === '\"') {\n i++; // skip closing quote\n break;\n } else {\n field += line[i++];\n }\n }\n fields.push(field);\n if (i < line.length && line[i] === \",\") i++; // skip delimiter\n } else {\n // Unquoted field\n const start = i;\n while (i < line.length && line[i] !== \",\") i++;\n fields.push(line.slice(start, i));\n if (i < line.length) i++; // skip delimiter\n }\n }\n\n return fields;\n}\n\n/**\n * Parse a full CSV string (CRLF or LF line endings) into a 2-D array of strings.\n */\nfunction parseCSV(input: string): string[][] {\n const normalized = input.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n return normalized.split(\"\\n\").map(parseCSVRow);\n}\n\n/**\n * Convert a DEGIRO date \"DD-MM-YYYY\" to ISO format \"YYYY-MM-DD\".\n */\nfunction parseDate(ddmmyyyy: string): string {\n const [dd, mm, yyyy] = ddmmyyyy.split(\"-\");\n return `${yyyy}-${mm}-${dd}`;\n}\n\n/**\n * Parses a DEGIRO Transactions CSV export into normalised Transaction objects.\n *\n * Export from Activity → Transactions in the DEGIRO UI (not the Account Statement).\n * Supported currencies: EUR, USD, GBP, CHF. ECB historical rates are used for conversion.\n */\nexport class DEGIROParser {\n private _warningEntries: WarningEntry[] = [];\n private _snapshot?: RatesSnapshot;\n\n constructor(snapshot?: RatesSnapshot) {\n this._snapshot = snapshot;\n }\n\n /**\n * Parse a DEGIRO Transactions CSV export string.\n *\n * @param csv - Raw UTF-8 string from the DEGIRO Transactions export.\n * @returns Array of normalised Transaction objects. Empty if no data rows are found.\n * @throws {ParseError} code `\"INVALID_CSV\"` — malformed CSV or binary content.\n * @throws {ParseError} code `\"MISSING_COLUMN\"` (+ `columnName`) — required column absent.\n *\n * Rows with missing ISIN, unsupported currency, zero quantity, or no ECB rate within\n * 3 trading days are skipped silently. Inspect `parser.warnings` for details.\n */\n parse(csv: string): Transaction[] {\n this._warningEntries = [];\n\n // Binary content (null bytes) is not valid CSV\n if (typeof csv !== \"string\" || csv.includes(\"\\x00\")) {\n throw new ParseError(\"INVALID_CSV\");\n }\n\n let rows: string[][];\n try {\n rows = parseCSV(csv);\n } catch {\n throw new ParseError(\"INVALID_CSV\");\n }\n\n if (rows.length === 0) {\n throw new ParseError(\"INVALID_CSV\");\n }\n\n // Build column-name → index map from the header row\n const header = rows[0];\n const colIndex: Record<string, number> = {};\n for (let i = 0; i < header.length; i++) {\n colIndex[header[i].trim()] = i;\n }\n\n // Validate that every required column is present\n for (const col of REQUIRED_COLUMNS) {\n if (colIndex[col] === undefined) {\n throw new ParseError(\"MISSING_COLUMN\", col);\n }\n }\n\n // Resolve the rates snapshot once for the whole parse run\n const snapshot: RatesSnapshot = this._snapshot ?? getActiveSnapshot();\n\n const transactions: Transaction[] = [];\n\n for (let r = 1; r < rows.length; r++) {\n const row = rows[r];\n // 1-indexed row number: header = 1, first data row = 2\n const rowIndex = r + 1;\n\n // Skip completely empty rows (including the trailing empty line after a\n // final newline, and rows that are all whitespace)\n if (row.every((cell) => cell.trim() === \"\")) continue;\n\n const get = (col: string): string => (row[colIndex[col]] ?? \"\").trim();\n\n // --- ISIN ---\n const isin = get(\"ISIN\");\n if (!isin) {\n this._warningEntries.push({ code: \"MISSING_ISIN\", row: rowIndex });\n continue;\n }\n\n // --- Quantity ---\n const rawQty = parseFloat(get(\"Quantity\"));\n if (isNaN(rawQty) || rawQty === 0) {\n this._warningEntries.push({ code: \"QUANTITY_ZERO\", row: rowIndex });\n continue;\n }\n\n const type: \"BUY\" | \"SELL\" = rawQty > 0 ? \"BUY\" : \"SELL\";\n const quantity = Math.abs(rawQty);\n\n // --- Date ---\n const isoDate = parseDate(get(\"Date\"));\n\n // --- Currency & FX ---\n const currency = get(\"Local value currency\");\n const rawTotalLocal = parseFloat(get(\"Local value\"));\n const totalLocal = isNaN(rawTotalLocal) ? 0 : rawTotalLocal;\n\n let totalEUR: number;\n let fxRate: number | undefined;\n\n if (currency === \"EUR\") {\n totalEUR = Math.abs(totalLocal);\n fxRate = undefined;\n } else {\n const rate = lookupRate(currency, isoDate, snapshot);\n if (rate === null) {\n if (snapshot[currency] === undefined) {\n this._warningEntries.push({\n code: \"UNSUPPORTED_CURRENCY\",\n row: rowIndex,\n currency,\n });\n } else {\n this._warningEntries.push({\n code: \"NO_ECB_RATE\",\n row: rowIndex,\n currency,\n date: isoDate,\n });\n }\n continue;\n }\n totalEUR = Math.abs(totalLocal) / rate;\n fxRate = rate;\n }\n\n // --- Fees ---\n const rawFees = parseFloat(get(\"Transaction costs\"));\n const feesEUR = Math.abs(isNaN(rawFees) ? 0 : rawFees);\n\n // --- Remaining fields ---\n const pricePerUnit = parseFloat(get(\"Price\"));\n const product = get(\"Product\");\n\n transactions.push({\n isin,\n product,\n date: isoDate,\n type,\n quantity,\n pricePerUnit,\n currency,\n totalLocal,\n totalEUR,\n feesEUR,\n fxRate,\n });\n }\n\n return transactions;\n }\n\n get warnings(): string[] {\n return this._warningEntries.map(warningToEnglish);\n }\n\n get warningEntries(): WarningEntry[] {\n return this._warningEntries;\n }\n}\n","import type {\n Transaction,\n MatchedLot,\n GainsReport,\n LotMethod,\n CalculatorOptions,\n AssetClass,\n BucketAReport,\n BucketBReport,\n} from \"../types.js\";\nimport { CalculationError } from \"../errors.js\";\n\ninterface Lot {\n date: string;\n quantity: number;\n pricePerUnitEUR: number;\n feesEUR: number;\n originalQty: number;\n fxRate?: number;\n}\n\nfunction roundHalfUp(x: number): number {\n return (Math.sign(x) * Math.round(Math.abs(x) * 100)) / 100;\n}\n\nfunction inferTaxYear(transactions: Transaction[]): {\n year: number;\n multipleYears: boolean;\n} {\n const counts: Record<string, number> = {};\n for (const t of transactions) {\n const y = t.date.slice(0, 4);\n counts[y] = (counts[y] ?? 0) + 1;\n }\n const years = Object.keys(counts);\n if (years.length === 0)\n return { year: new Date().getFullYear(), multipleYears: false };\n const year = parseInt(\n years.reduce((a, b) => (counts[a] >= counts[b] ? a : b)),\n );\n return { year, multipleYears: years.length > 1 };\n}\n\n/**\n * Computes Italian capital gains and losses from a list of parsed transactions.\n *\n * Uses LIFO or FIFO lot matching and converts all amounts to EUR via ECB rates.\n */\nexport class Calculator {\n private readonly _transactions: Transaction[];\n private readonly _parseWarnings: string[];\n private readonly _options: CalculatorOptions;\n\n constructor(\n transactions: Transaction[],\n parseWarnings?: string[],\n options?: CalculatorOptions,\n ) {\n this._transactions = transactions;\n this._parseWarnings = parseWarnings ?? [];\n this._options = options ?? {};\n }\n\n /**\n * Run LIFO or FIFO lot-matching over the transaction list.\n *\n * @param method - `\"LIFO\"` or `\"FIFO\"`.\n * @returns GainsReport with `plusvalenze`, `minusvalenze`, `netResult`, per-lot breakdown,\n * ECB rates used, and any accumulated warnings.\n * @throws {CalculationError} when a SELL has no matching open buy lots.\n * `error.isin` and `error.date` identify the problematic transaction.\n */\n calculateGains(method: LotMethod): GainsReport {\n const warnings: string[] = [...this._parseWarnings];\n\n // 1. Sort ascending by date; BUY before SELL on same date\n const sorted = [...this._transactions].sort((a, b) => {\n if (a.date < b.date) return -1;\n if (a.date > b.date) return 1;\n // Same date: BUY before SELL\n if (a.type === \"BUY\" && b.type === \"SELL\") return -1;\n if (a.type === \"SELL\" && b.type === \"BUY\") return 1;\n return 0;\n });\n\n // 2. Tax year inference\n const { year: taxYear, multipleYears } = inferTaxYear(sorted);\n if (multipleYears) {\n warnings.push(\n \"CSV contains transactions from multiple years — filter to a single year for accurate reporting.\",\n );\n }\n\n // 3. Lot matching\n const openLots = new Map<string, Lot[]>();\n const matchedLots: MatchedLot[] = [];\n const ratesUsed: Record<string, number> = {};\n\n for (const tx of sorted) {\n // Collect rates used\n if (tx.fxRate !== undefined) {\n ratesUsed[`${tx.currency}:${tx.date}`] = tx.fxRate;\n }\n\n if (tx.type === \"BUY\") {\n const lot: Lot = {\n date: tx.date,\n quantity: tx.quantity,\n pricePerUnitEUR: tx.totalEUR / tx.quantity,\n feesEUR: tx.feesEUR,\n originalQty: tx.quantity,\n fxRate: tx.fxRate,\n };\n if (!openLots.has(tx.isin)) openLots.set(tx.isin, []);\n openLots.get(tx.isin)!.push(lot);\n } else {\n // SELL\n const lots = openLots.get(tx.isin);\n if (!lots || lots.length === 0) {\n throw new CalculationError(tx.isin, tx.date);\n }\n\n const sellPricePerUnitEUR = tx.totalEUR / tx.quantity;\n let remainingSellQty = tx.quantity;\n\n while (remainingSellQty > 0) {\n if (!lots || lots.length === 0) {\n throw new CalculationError(tx.isin, tx.date);\n }\n\n const lot = method === \"LIFO\" ? lots[lots.length - 1] : lots[0];\n const matchedQty = Math.min(lot.quantity, remainingSellQty);\n\n // Fee allocation\n const allocatedBuyFeesEUR =\n lot.feesEUR * (matchedQty / lot.originalQty);\n const allocatedSellFeesEUR = tx.feesEUR * (matchedQty / tx.quantity);\n\n const buyCostEUR =\n lot.pricePerUnitEUR * matchedQty + allocatedBuyFeesEUR;\n const sellProceedsEUR =\n sellPricePerUnitEUR * matchedQty - allocatedSellFeesEUR;\n const gainLossEUR = sellProceedsEUR - buyCostEUR;\n\n matchedLots.push({\n isin: tx.isin,\n product: tx.product,\n quantity: matchedQty,\n buyDate: lot.date,\n sellDate: tx.date,\n buyPriceEUR: lot.pricePerUnitEUR,\n sellPriceEUR: sellPricePerUnitEUR,\n buyCostEUR: roundHalfUp(buyCostEUR),\n sellProceedsEUR: roundHalfUp(sellProceedsEUR),\n gainLossEUR: roundHalfUp(gainLossEUR),\n buyFxRate: lot.fxRate,\n sellFxRate: tx.fxRate,\n });\n\n lot.quantity -= matchedQty;\n remainingSellQty -= matchedQty;\n\n if (lot.quantity <= 0) {\n if (method === \"LIFO\") {\n lots.pop();\n } else {\n lots.shift();\n }\n }\n }\n }\n }\n\n // 4. Aggregate\n let plusvalenze = 0;\n let minusvalenze = 0;\n for (const lot of matchedLots) {\n if (lot.gainLossEUR > 0) plusvalenze += lot.gainLossEUR;\n else minusvalenze += Math.abs(lot.gainLossEUR);\n }\n\n // Two-bucket routing (only when classification map provided)\n if (this._options.classification) {\n const classification = this._options.classification;\n const unclassifiedIsins = new Set<string>();\n\n for (const lot of matchedLots) {\n const entry = classification[lot.isin];\n if (!entry) {\n lot.bucket = \"B\";\n unclassifiedIsins.add(lot.isin);\n } else if (entry.bucketGain === \"A\" && lot.gainLossEUR >= 0) {\n lot.bucket = \"A\";\n } else {\n lot.bucket = \"B\";\n }\n }\n\n for (const isin of unclassifiedIsins) {\n warnings.push(\n `ISIN ${isin} not found in classification map — assigned to Bucket B.`,\n );\n }\n\n // Bucket A computation\n const bucketALots = matchedLots.filter((l) => l.bucket === \"A\");\n const groupsByRate = new Map<\n number,\n { assetClasses: Set<string>; plusvalenze: number }\n >();\n for (const lot of bucketALots) {\n const entry = classification[lot.isin]!;\n const rate = entry.taxRate;\n if (!groupsByRate.has(rate))\n groupsByRate.set(rate, { assetClasses: new Set(), plusvalenze: 0 });\n const g = groupsByRate.get(rate)!;\n g.assetClasses.add(entry.assetClass);\n g.plusvalenze += lot.gainLossEUR;\n }\n const bucketAGroups = [...groupsByRate.entries()].map(([taxRate, g]) => ({\n taxRate,\n assetClasses: [...g.assetClasses] as AssetClass[],\n plusvalenze: roundHalfUp(g.plusvalenze),\n imposta: roundHalfUp(g.plusvalenze * taxRate),\n }));\n const bucketAReport: BucketAReport = {\n groups: bucketAGroups,\n totalImposta: roundHalfUp(\n bucketAGroups.reduce((s, g) => s + g.imposta, 0),\n ),\n };\n\n // Bucket B computation\n const bucketBLots = matchedLots.filter((l) => l.bucket === \"B\");\n let bPlusvalenze = 0;\n let bMinusvalenze = 0;\n for (const lot of bucketBLots) {\n if (lot.gainLossEUR >= 0) bPlusvalenze += lot.gainLossEUR;\n else bMinusvalenze += Math.abs(lot.gainLossEUR);\n }\n bPlusvalenze = roundHalfUp(bPlusvalenze);\n bMinusvalenze = roundHalfUp(bMinusvalenze);\n\n const carryForwards = [...(this._options.carryForward ?? [])].sort(\n (a, b) => a.year - b.year,\n );\n let remaining = bPlusvalenze - bMinusvalenze;\n let carryForwardApplied = 0;\n for (const entry of carryForwards) {\n if (taxYear - entry.year > 4) continue;\n if (remaining <= 0) break;\n const consumed = Math.min(entry.amount, remaining);\n carryForwardApplied += consumed;\n remaining -= consumed;\n }\n carryForwardApplied = roundHalfUp(carryForwardApplied);\n const bNetResult = roundHalfUp(\n bPlusvalenze - bMinusvalenze - carryForwardApplied,\n );\n const carryForwardRemaining = roundHalfUp(Math.max(0, -bNetResult));\n\n const bucketBReport: BucketBReport = {\n plusvalenze: bPlusvalenze,\n minusvalenze: bMinusvalenze,\n carryForwardApplied,\n carryForwardRemaining,\n netResult: bNetResult,\n };\n\n return {\n method,\n taxYear,\n plusvalenze: roundHalfUp(plusvalenze),\n minusvalenze: roundHalfUp(minusvalenze),\n netResult: roundHalfUp(plusvalenze - minusvalenze),\n lots: matchedLots,\n ratesUsed,\n warnings,\n generatedAt: new Date().toISOString(),\n bucketA: bucketAGroups.length > 0 ? bucketAReport : undefined,\n bucketB: bucketBReport,\n };\n } else {\n // Mixed-asset heuristic (no classification map)\n const allIsins = [...new Set(this._transactions.map((t) => t.isin))];\n const hasIePrefix = allIsins.some((isin) => isin.startsWith(\"IE\"));\n const hasOther = allIsins.some((isin) => !isin.startsWith(\"IE\"));\n if (hasIePrefix && hasOther) {\n warnings.push(\n \"AVVISO: CSV contiene tipi di strumenti misti (es. ETF + Azioni).\\n\" +\n \" Il calcolo a bucket unico può non essere fiscalmente corretto.\\n\" +\n \" Esegui: minus-tracker classify trades.csv\",\n );\n }\n }\n\n return {\n method,\n taxYear,\n plusvalenze: roundHalfUp(plusvalenze),\n minusvalenze: roundHalfUp(minusvalenze),\n netResult: roundHalfUp(plusvalenze - minusvalenze),\n lots: matchedLots,\n ratesUsed,\n warnings,\n generatedAt: new Date().toISOString(),\n };\n }\n}\n","import { ClassificationError } from \"../errors.js\";\nimport type {\n AssetClass,\n ClassificationEntry,\n ClassificationMap,\n Transaction,\n} from \"../types.js\";\nimport * as fs from \"node:fs\";\nimport * as https from \"node:https\";\n\ntype HttpPost = (\n url: string,\n body: string,\n timeoutMs: number,\n) => Promise<{ status: number; data: string }>;\n\nfunction httpsPost(\n url: string,\n body: string,\n timeoutMs: number,\n): Promise<{ status: number; data: string }> {\n return new Promise((resolve, reject) => {\n const u = new URL(url);\n const req = https.request(\n {\n hostname: u.hostname,\n path: u.pathname + u.search,\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Content-Length\": Buffer.byteLength(body),\n },\n },\n (res) => {\n let data = \"\";\n res.on(\"data\", (chunk) => {\n data += chunk;\n });\n res.on(\"end\", () => resolve({ status: res.statusCode ?? 0, data }));\n },\n );\n req.setTimeout(timeoutMs, () => {\n req.destroy();\n reject(new Error(\"timeout\"));\n });\n req.on(\"error\", reject);\n req.write(body);\n req.end();\n });\n}\n\nconst GOVT_BOND_WHITELIST = new Set([\n \"IT\",\n \"DE\",\n \"FR\",\n \"AT\",\n \"BE\",\n \"NL\",\n \"ES\",\n \"PT\",\n \"FI\",\n \"IE\",\n \"LU\",\n \"GR\",\n \"SK\",\n \"SI\",\n \"LT\",\n \"LV\",\n \"EE\",\n \"MT\",\n \"CY\",\n \"US\",\n \"GB\",\n \"CH\",\n \"NO\",\n \"SE\",\n \"DK\",\n \"JP\",\n \"CA\",\n \"AU\",\n \"NZ\",\n \"SG\",\n \"HK\",\n \"KR\",\n]);\n\ntype TypeMapping = {\n assetClass: AssetClass;\n bucketGain: \"A\" | \"B\";\n bucketLoss: \"A\" | \"B\";\n taxRate: number;\n whiteListed: boolean | null;\n};\n\nconst SECURITY_TYPE_MAP: Record<string, TypeMapping> = {\n ETP: {\n assetClass: \"ETF\",\n bucketGain: \"A\",\n bucketLoss: \"B\",\n taxRate: 0.26,\n whiteListed: null,\n },\n ETF: {\n assetClass: \"ETF\",\n bucketGain: \"A\",\n bucketLoss: \"B\",\n taxRate: 0.26,\n whiteListed: null,\n },\n \"Mutual Fund\": {\n assetClass: \"ETF\",\n bucketGain: \"A\",\n bucketLoss: \"B\",\n taxRate: 0.26,\n whiteListed: null,\n },\n \"Open-End Fund\": {\n assetClass: \"ETF\",\n bucketGain: \"A\",\n bucketLoss: \"B\",\n taxRate: 0.26,\n whiteListed: null,\n },\n \"Common Stock\": {\n assetClass: \"Stock\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n Equity: {\n assetClass: \"Stock\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n \"Exchange Traded Commodity\": {\n assetClass: \"ETC\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n \"Corporate Bond\": {\n assetClass: \"CorpBond\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n Option: {\n assetClass: \"Derivative\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n Future: {\n assetClass: \"Derivative\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n Warrant: {\n assetClass: \"Derivative\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n CFD: {\n assetClass: \"Derivative\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n Swap: {\n assetClass: \"Derivative\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n \"Leverage Certificate\": {\n assetClass: \"LeverageCert\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n \"Turbo Certificate\": {\n assetClass: \"LeverageCert\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n },\n \"Capital Protected Certificate\": {\n assetClass: \"CapProtectedCert\",\n bucketGain: \"A\",\n bucketLoss: \"B\",\n taxRate: 0.26,\n whiteListed: null,\n },\n};\n\nfunction isKnownType(t: string): boolean {\n return t === \"Government Bond\" || t in SECURITY_TYPE_MAP;\n}\n\nfunction classifyByType(\n isin: string,\n securityType: string,\n product: string,\n warnings: string[],\n): ClassificationEntry {\n if (securityType === \"Government Bond\") {\n const prefix = isin.slice(0, 2).toUpperCase();\n const whiteListed = GOVT_BOND_WHITELIST.has(prefix);\n return {\n product,\n assetClass: whiteListed ? \"GovtBondWL\" : \"GovtBondOther\",\n bucketGain: \"A\",\n bucketLoss: \"B\",\n taxRate: whiteListed ? 0.125 : 0.26,\n whiteListed,\n confirmedByUser: false,\n source: \"openfigi\",\n };\n }\n\n const mapped = SECURITY_TYPE_MAP[securityType];\n if (mapped) {\n return {\n product,\n assetClass: mapped.assetClass,\n bucketGain: mapped.bucketGain,\n bucketLoss: mapped.bucketLoss,\n taxRate: mapped.taxRate,\n whiteListed: mapped.whiteListed,\n confirmedByUser: false,\n source: \"openfigi\",\n };\n }\n\n // Unknown type — flag for manual review\n warnings.push(\n `Unrecognized type: ${securityType}. Please classify manually.`,\n );\n return {\n product,\n assetClass: \"Stock\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n confirmedByUser: false,\n source: \"user\",\n };\n}\n\ntype OpenFIGIItem = { securityType?: string; securityType2?: string };\ntype OpenFIGIResult = { data?: OpenFIGIItem[]; error?: string };\n\nexport class Classifier {\n private readonly interactive: boolean;\n\n constructor(options?: { interactive?: boolean }) {\n this.interactive = options?.interactive ?? true;\n }\n\n async load(sidecarPath: string): Promise<ClassificationMap> {\n if (!fs.existsSync(sidecarPath)) {\n throw new ClassificationError(\"SIDECAR_NOT_FOUND\");\n }\n\n let parsed: unknown;\n try {\n const raw = fs.readFileSync(sidecarPath, \"utf-8\");\n parsed = JSON.parse(raw);\n } catch {\n throw new ClassificationError(\"SIDECAR_MALFORMED\");\n }\n\n if (\n typeof parsed !== \"object\" ||\n parsed === null ||\n (parsed as Record<string, unknown>)[\"version\"] !== 1\n ) {\n throw new ClassificationError(\"SIDECAR_VERSION\");\n }\n\n return (parsed as { classifications: ClassificationMap }).classifications;\n }\n\n async classify(\n transactions: Transaction[],\n sidecarPath: string,\n _httpPost: HttpPost = httpsPost,\n ): Promise<ClassificationMap> {\n // 1. Deduplicate ISINs; track first product name seen per ISIN\n const isinToProduct = new Map<string, string>();\n for (const tx of transactions) {\n if (tx.isin && !isinToProduct.has(tx.isin)) {\n isinToProduct.set(tx.isin, tx.product);\n }\n }\n\n // 2. Load existing sidecar; separate confirmed from to-process\n const confirmed: ClassificationMap = {};\n\n if (fs.existsSync(sidecarPath)) {\n const existingMap = await this.load(sidecarPath);\n for (const [isin, entry] of Object.entries(existingMap)) {\n if (entry.confirmedByUser) {\n confirmed[isin] = entry;\n }\n }\n }\n\n // 3. ISINs that need (re-)processing: not user-confirmed\n const toProcess: string[] = [];\n for (const isin of isinToProduct.keys()) {\n if (!(isin in confirmed)) {\n toProcess.push(isin);\n }\n }\n\n // 4. Batch-query OpenFIGI\n const warnings: string[] = [];\n const newEntries: ClassificationMap = {};\n const BATCH_SIZE = 10;\n\n for (let i = 0; i < toProcess.length; i += BATCH_SIZE) {\n // Wait 6 s between consecutive batch requests\n if (i > 0) {\n await new Promise<void>((resolve) => setTimeout(resolve, 6000));\n }\n\n const batch = toProcess.slice(i, i + BATCH_SIZE);\n const requestBody = JSON.stringify(\n batch.map((isin) => ({ idType: \"ID_ISIN\", idValue: isin })),\n );\n\n let response: { status: number; data: string } | null = null;\n\n // Try once; retry once on 5xx\n for (let attempt = 0; attempt < 2; attempt++) {\n try {\n const r = await _httpPost(\n \"https://api.openfigi.com/v3/mapping\",\n requestBody,\n 10_000,\n );\n if (r.status < 500) {\n response = r;\n break;\n }\n // 5xx — loop will retry once\n } catch {\n // Network-level error — no retry\n throw new ClassificationError(\"NETWORK_ERROR\");\n }\n }\n\n if (response === null) {\n throw new ClassificationError(\"NETWORK_ERROR\");\n }\n\n const results = JSON.parse(response.data) as OpenFIGIResult[];\n\n for (let j = 0; j < batch.length; j++) {\n const isin = batch[j]!;\n const result = results[j];\n const product = isinToProduct.get(isin) ?? isin;\n\n if (\n !result ||\n result.error ||\n !result.data ||\n result.data.length === 0\n ) {\n warnings.push(\n `Unrecognized type: unknown. Please classify manually.`,\n );\n newEntries[isin] = {\n product,\n assetClass: \"Stock\",\n bucketGain: \"B\",\n bucketLoss: \"B\",\n taxRate: 0,\n whiteListed: null,\n confirmedByUser: false,\n source: \"user\",\n };\n continue;\n }\n\n const st = result.data[0]?.securityType;\n const st2 = result.data[0]?.securityType2;\n\n // Prefer the type that resolves to a known mapping\n const typeToUse =\n st && isKnownType(st)\n ? st\n : st2 && isKnownType(st2)\n ? st2\n : (st ?? st2 ?? \"Unknown\");\n\n newEntries[isin] = classifyByType(isin, typeToUse, product, warnings);\n }\n }\n\n // 5. Merge: confirmed entries take precedence and remain untouched\n const mergedMap: ClassificationMap = { ...newEntries, ...confirmed };\n\n // 6. Write sidecar\n const sidecarContent = JSON.stringify(\n {\n version: 1,\n generatedAt: new Date().toISOString(),\n classifications: mergedMap,\n warnings,\n },\n null,\n 2,\n );\n\n try {\n fs.writeFileSync(sidecarPath, sidecarContent, \"utf-8\");\n } catch {\n throw new ClassificationError(\"WRITE_ERROR\");\n }\n\n return mergedMap;\n }\n}\n"],"mappings":";AAAO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAC3B;AAAA,EACA;AAAA,EAIT,YAAY,MAA0B,YAAqB;AACzD,UAAM,MACJ,SAAS,gBACL,iCACA,4BAA4B,UAAU;AAC5C,UAAM,GAAG;AACT,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EACjC;AAAA,EACA;AAAA,EAET,YAAY,MAAc,MAAc;AACtC,UAAM,yBAAyB,IAAI,OAAO,IAAI,EAAE;AAChD,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EACpC;AAAA,EAOT,YAAY,MAAmC,SAAkB;AAC/D;AAAA,MACE,YACG,SAAS,sBACN,2BACA,SAAS,oBACP,6BACA,SAAS,sBACP,mCACA,SAAS,kBACP,sCACA;AAAA,IACd;AACA,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;;;ACtDA,SAAS,qBAAqB;AAC9B,YAAY,UAAU;AACtB,YAAY,QAAQ;AAKpB,IAAI,WAA6C;AAEjD,SAAS,qBAA2C;AAClD,MAAI,aAAa,OAAW,QAAO;AACnC,QAAM,YAAiB,aAAQ,cAAc,YAAY,GAAG,CAAC;AAC7D,QAAM,cAAmB,UAAK,WAAW,wBAAwB;AACjE,MAAI;AACF,eAAW,KAAK;AAAA,MACX,gBAAa,aAAa,MAAM;AAAA,IACrC;AAAA,EACF,QAAQ;AACN,eAAW;AAAA,EACb;AACA,SAAO;AACT;AAEA,SAAS,kBAAwC;AAC/C,QAAM,WAAW,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UAAM,iBAAiB,KAAK;AAAA,MAC1B;AAAA,QACE,SAAS;AAAA,QACT,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,QACpC,iBAAiB;AAAA,QACjB;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,QAAI;AACF,MAAG,kBAAc,aAAa,gBAAgB,OAAO;AAAA,IACvD,QAAQ;AACN,YAAM,IAAI,oBAAoB,aAAa;AAAA,IAC7C;AAEA,WAAO;AAAA,EACT;AACF;","names":["fs"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gabrielerandelli/minus-tracker",
3
- "version": "0.5.7",
3
+ "version": "0.6.0",
4
4
  "description": "Italian capital-gains/loss calculator for the Regime Dichiarativo",
5
5
  "type": "module",
6
6
  "exports": {
@@ -28,6 +28,23 @@
28
28
  "vitest": "^2.0.0"
29
29
  },
30
30
  "license": "MIT",
31
+ "keywords": [
32
+ "capital-gains",
33
+ "plusvalenze",
34
+ "minusvalenze",
35
+ "regime-dichiarativo",
36
+ "degiro",
37
+ "tax",
38
+ "italy",
39
+ "csv",
40
+ "lifo",
41
+ "fifo",
42
+ "typescript"
43
+ ],
44
+ "homepage": "https://github.com/gabrielerandelli/minus-tracker#readme",
45
+ "bugs": {
46
+ "url": "https://github.com/gabrielerandelli/minus-tracker/issues"
47
+ },
31
48
  "engines": {
32
49
  "node": ">=24.0.0"
33
50
  },