# creditu-common-library

> Librería de cálculos financieros y matemáticos de Creditú (oferta hipotecaria, deuda, ratios)

Latest version **3.0.1** (published 2026-09-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install creditu-common-library
pnpm add creditu-common-library
yarn add creditu-common-library
bun add creditu-common-library
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2026-09-08 |
| First published | 2021-07-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 333.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ti_tecnologia_creditu |

## Links

- npm: https://www.npmjs.com/package/creditu-common-library
- Repository: https://github.com/creditu-org/creditu-common-library
- Homepage: https://github.com/creditu-org/creditu-common-library#readme
- Issues: https://github.com/creditu-org/creditu-common-library/issues
- npm.io page: https://npm.io/package/creditu-common-library

## Dependencies (7)

- [rxjs](https://npm.io/package/rxjs.md) ^7.8.2
- [xlsx](https://npm.io/package/xlsx.md) https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz
- [express](https://npm.io/package/express.md) ^4.21.2
- [dinero.js](https://npm.io/package/dinero.js.md) ^1.9.1
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^10.4.18
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.2.2
- [creditu-date-model](https://npm.io/package/creditu-date-model.md) ^2.9.1

## Recent versions

- 3.0.1 (latest) — 2026-09-08
- 2.3.19-beta.1 (beta) — 2026-03-06
- 3.0.0 — 2026-09-08
- 2.3.19 — 2026-03-06
- 2.3.19-beta.0 — 2026-03-06
- 2.3.18 — 2025-06-05
- 2.3.17 — 2025-06-04
- 2.3.16 — 2025-06-04
- 2.3.15 — 2025-04-03
- 2.3.14 — 2025-04-03
- 2.3.13 — 2025-03-15
- 2.3.12 — 2025-03-15
- 2.3.11 — 2025-03-12
- 2.3.10 — 2025-03-12
- 2.3.9 — 2024-12-27
- … 125 more at https://npm.io/package/creditu-common-library/versions

## README

# Creditú Common Library

Librería TypeScript con los módulos y funciones matemáticas y financieras que usan las aplicaciones de Creditú: cálculo de oferta hipotecaria, deuda/amortización y ratios de endeudamiento.

- **Repositorio:** https://github.com/creditu-org/creditu-common-library (la copia en GitLab está archivada)
- **Paquete:** [`creditu-common-library`](https://www.npmjs.com/package/creditu-common-library), publicado desde GitHub Actions con npm Trusted Publishing al pushear un tag `v*`

## Instalar

```shell
npm i creditu-common-library
```

## Módulos

- **`math`** — `MathService`: aritmética de precisión sobre `dinero.js` (`add`, `subtract`, `multiply`, `divide`, `round`). Todos los demás servicios reciben una instancia en su constructor: `new MathService(useRound = true, precision = 6)`.
- **`offer`** — cálculo de oferta (flujo de originación). `OfferService.calculateCreditAmountToOffer(inputs, params) → OfferResponse` orquesta los sub-servicios `ConstantsService`, `CreditInsuranceService`, `FinanceService`, `InstallmentService`, `LoanToValueService`, `MaximumLocalService` y `OperationalExpensesService`.
- **`debt`** — deuda activa y amortización (flujo de servicing): `AmortizationService`, `BalanceService`, `InflationService`, `InstallmentService`, `InsuranceService`, `InterestService`, `LateService`, `MonthlyPaymentService`.
- **`shared/models`** — value objects (validan en el constructor) y enums compartidos.
- **`middlewares`** — `AppLoggerMiddleware` (logger HTTP para NestJS).

Cada función lleva en su JSDoc el enlace a la definición matemática en la wiki de Oferta.

## Uso

```ts
import { MathService } from 'creditu-common-library/math';
import { OfferService } from 'creditu-common-library/offer/services';
import { OfferInputs, OfferParams } from 'creditu-common-library/offer/models/dto';

const offerService = new OfferService(new MathService(true, 10));
const offer = offerService.calculateCreditAmountToOffer(inputs, params);
```

## Ratios de endeudamiento (desde 3.0.0)

Regla de Riesgo (24-ago-2026): la deuda de largo plazo (`longTermMonthlyFee`, p. ej. un hipotecario con otro banco) afecta **solo** la Carga Financiera.

| Ratio | Campo | Fórmula |
|---|---|---|
| Dividendo Renta (DR) | `frontEndRatio` | `cuota del crédito / ingreso` |
| Carga Financiera (CF) | `backEndRatio` | `(cuota del crédito + LP + CP) / ingreso` |

El máximo local por DR (`approvedAmountIncomeDividend`) es el inverso del DR y ya no descuenta la cuota LP; el máximo local por CF sí. Detalle en `openspec/specs/offer-debt-ratios/spec.md`.

**Breaking en 3.0.0:** `OfferService.getFrontEndRatio(creditInstallment, monthlyIncome, creditInsuranceFeeTermDefinition, creditInsuranceInstallment?)` y `MaximumLocalService.incomeDividend(params)` perdieron el parámetro de cuota de largo plazo.

## Desarrollo

```shell
npm run build            # compila a lib/
npm run lint             # tsc --noEmit + eslint
npm run test:unit        # unit (.spec.ts en src/)
npm run test:cov         # unit con cobertura (umbral 80 %)
npm run test:functional  # suite funcional en test/
```

Para probar en un consumidor sin publicar: `npm link` aquí y `npm link creditu-common-library` en el otro repo.

## Publicar

1. Mergear a `master` con la versión ya subida en `package.json` (`npm version <major|minor|patch> --no-git-tag-version`).
2. `git tag -a vX.Y.Z -m "..." && git push origin vX.Y.Z` → `publish.yml` compila y publica vía OIDC (sin tokens).

---
_Source: https://npm.io/package/creditu-common-library · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
