@loan-risk/http-api 1.0.0 → 1.0.1
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/README.md +31 -321
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,270 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @loan-risk/http-api
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Express HTTP API for the Loan Risk Analyzer ecosystem.
|
|
4
4
|
|
|
5
|
-

|
|
8
|
-
|
|
9
|
-

|
|
10
|
-
|
|
11
|
-
A modern TypeScript-based loan risk analysis engine with plugin architecture, hooks system, HTTP API support, and extensible rule processing.
|
|
12
|
-
|
|
13
|
-
Built with:
|
|
14
|
-
|
|
15
|
-
- TypeScript
|
|
16
|
-
- Node.js
|
|
17
|
-
- PNPM Workspace
|
|
18
|
-
- Vitest
|
|
19
|
-
- Express
|
|
5
|
+

|
|
20
6
|
|
|
21
7
|
---
|
|
22
8
|
|
|
23
9
|
# Features
|
|
24
10
|
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
- Hook system
|
|
28
|
-
- Fraud detection support
|
|
29
|
-
- Parallel rule execution
|
|
30
|
-
- HTTP API package
|
|
31
|
-
- Logger package
|
|
32
|
-
- Automated testing
|
|
33
|
-
- Monorepo architecture
|
|
34
|
-
- Fully typed with TypeScript
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
# Quick Start
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
pnpm install
|
|
41
|
-
pnpm build
|
|
42
|
-
pnpm test
|
|
43
|
-
|
|
44
|
-
# Architecture
|
|
45
|
-
|
|
46
|
-
This repository follows a modular monorepo architecture using TurboRepo and PNPM workspaces.
|
|
47
|
-
|
|
48
|
-
Each package is independently buildable, type-safe, and publishable to npm.
|
|
49
|
-
|
|
50
|
-
The system is designed for:
|
|
51
|
-
- extensibility
|
|
52
|
-
- plugin-based rule processing
|
|
53
|
-
- scalable risk evaluation
|
|
54
|
-
- enterprise TypeScript development workflows
|
|
55
|
-
|
|
56
|
-
# Project Structure
|
|
57
|
-
|
|
58
|
-
```txt
|
|
59
|
-
loan-risk-analyzer/
|
|
60
|
-
│
|
|
61
|
-
├── packages/
|
|
62
|
-
│ ├── core/
|
|
63
|
-
│ │ ├── src/
|
|
64
|
-
│ │ ├── tests/
|
|
65
|
-
│ │ └── package.json
|
|
66
|
-
│ │
|
|
67
|
-
│ ├── logger/
|
|
68
|
-
│ │ ├── src/
|
|
69
|
-
│ │ └── package.json
|
|
70
|
-
│ │
|
|
71
|
-
│ └── http-api/
|
|
72
|
-
│ ├── src/
|
|
73
|
-
│ └── package.json
|
|
74
|
-
│
|
|
75
|
-
├── .github/
|
|
76
|
-
│ └── workflows/
|
|
77
|
-
│
|
|
78
|
-
├── package.json
|
|
79
|
-
├── pnpm-workspace.yaml
|
|
80
|
-
├── tsconfig.base.json
|
|
81
|
-
└── README.md
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
# Packages
|
|
87
|
-
|
|
88
|
-
## `@loan-risk/core`
|
|
89
|
-
|
|
90
|
-
Core loan risk analysis engine.
|
|
91
|
-
|
|
92
|
-
Features:
|
|
93
|
-
|
|
94
|
-
- Rule engine
|
|
95
|
-
- Risk scoring
|
|
96
|
-
- Plugin support
|
|
97
|
-
- Hooks system
|
|
98
|
-
- Fraud detection
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## `@loan-risk/logger`
|
|
103
|
-
|
|
104
|
-
Reusable logger package.
|
|
105
|
-
|
|
106
|
-
Features:
|
|
107
|
-
|
|
108
|
-
- Info logs
|
|
109
|
-
- Warning logs
|
|
110
|
-
- Error logs
|
|
111
|
-
- Debug logs
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## `@loan-risk/http-api`
|
|
116
|
-
|
|
117
|
-
Express-based HTTP API for exposing the analyzer.
|
|
118
|
-
|
|
119
|
-
Features:
|
|
120
|
-
|
|
121
|
-
- REST API
|
|
11
|
+
- Express server
|
|
12
|
+
- Loan risk analysis endpoint
|
|
122
13
|
- Health endpoint
|
|
123
|
-
-
|
|
14
|
+
- Swagger documentation
|
|
15
|
+
- TypeScript support
|
|
124
16
|
|
|
125
17
|
---
|
|
126
18
|
|
|
127
19
|
# Installation
|
|
128
20
|
|
|
129
|
-
## Clone Repository
|
|
130
|
-
|
|
131
21
|
```bash
|
|
132
|
-
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
---
|
|
136
|
-
|
|
137
|
-
## Install Dependencies
|
|
138
|
-
|
|
139
|
-
```bash
|
|
140
|
-
pnpm install
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
---
|
|
144
|
-
|
|
145
|
-
# Build Project
|
|
146
|
-
|
|
147
|
-
```bash
|
|
148
|
-
pnpm -r build
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
---
|
|
152
|
-
|
|
153
|
-
# Run Type Check
|
|
154
|
-
|
|
155
|
-
```bash
|
|
156
|
-
pnpm -r exec tsc --noEmit
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
---
|
|
160
|
-
|
|
161
|
-
# Run Tests
|
|
162
|
-
|
|
163
|
-
```bash
|
|
164
|
-
pnpm test
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
---
|
|
168
|
-
|
|
169
|
-
# Coverage Report
|
|
170
|
-
|
|
171
|
-
```bash
|
|
172
|
-
pnpm coverage
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
---
|
|
176
|
-
|
|
177
|
-
# Usage Example
|
|
178
|
-
|
|
179
|
-
## Basic Usage
|
|
180
|
-
|
|
181
|
-
```ts
|
|
182
|
-
import { calculateRisk } from "@loan-risk/core";
|
|
183
|
-
|
|
184
|
-
const result = await calculateRisk({
|
|
185
|
-
fullName: "full name",
|
|
186
|
-
|
|
187
|
-
age: 28,
|
|
188
|
-
|
|
189
|
-
monthlyIncome: 90000,
|
|
190
|
-
|
|
191
|
-
monthlyEMI: 15000,
|
|
192
|
-
|
|
193
|
-
requestedLoanAmount: 500000,
|
|
194
|
-
|
|
195
|
-
creditScore: 760,
|
|
196
|
-
|
|
197
|
-
employmentType: "SALARIED",
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
console.log(result);
|
|
22
|
+
pnpm add @loan-risk/http-api
|
|
201
23
|
```
|
|
202
24
|
|
|
203
25
|
---
|
|
204
26
|
|
|
205
|
-
#
|
|
206
|
-
|
|
207
|
-
```json
|
|
208
|
-
{
|
|
209
|
-
"score": 85,
|
|
210
|
-
"riskLevel": "LOW",
|
|
211
|
-
"approved": true,
|
|
212
|
-
"reasons": [],
|
|
213
|
-
"explanations": []
|
|
214
|
-
}
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
# Hooks Example
|
|
220
|
-
|
|
221
|
-
```ts
|
|
222
|
-
import { calculateRisk } from "@loan-risk/core";
|
|
223
|
-
|
|
224
|
-
await calculateRisk(applicant, undefined, {
|
|
225
|
-
hooks: {
|
|
226
|
-
beforeCalculate: async (ctx) => {
|
|
227
|
-
console.log("Started");
|
|
228
|
-
},
|
|
229
|
-
|
|
230
|
-
afterCalculate: async (ctx) => {
|
|
231
|
-
console.log(ctx.result);
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
---
|
|
238
|
-
|
|
239
|
-
# Plugin Example
|
|
240
|
-
|
|
241
|
-
```ts
|
|
242
|
-
import { createRiskEngine } from "@loan-risk/core";
|
|
243
|
-
|
|
244
|
-
const engine = createRiskEngine();
|
|
245
|
-
|
|
246
|
-
engine.use({
|
|
247
|
-
name: "CUSTOM_PLUGIN",
|
|
248
|
-
|
|
249
|
-
rules: [
|
|
250
|
-
{
|
|
251
|
-
name: "CUSTOM_RULE",
|
|
252
|
-
|
|
253
|
-
async execute() {
|
|
254
|
-
return {
|
|
255
|
-
scoreImpact: -5,
|
|
256
|
-
};
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
],
|
|
260
|
-
});
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
---
|
|
264
|
-
|
|
265
|
-
# HTTP API
|
|
266
|
-
|
|
267
|
-
## Start API
|
|
27
|
+
# Development
|
|
268
28
|
|
|
269
29
|
```bash
|
|
270
30
|
pnpm --filter @loan-risk/http-api dev
|
|
@@ -272,7 +32,9 @@ pnpm --filter @loan-risk/http-api dev
|
|
|
272
32
|
|
|
273
33
|
---
|
|
274
34
|
|
|
275
|
-
|
|
35
|
+
# API Endpoints
|
|
36
|
+
|
|
37
|
+
## Health Check
|
|
276
38
|
|
|
277
39
|
```http
|
|
278
40
|
GET /health
|
|
@@ -280,13 +42,15 @@ GET /health
|
|
|
280
42
|
|
|
281
43
|
---
|
|
282
44
|
|
|
283
|
-
## Analyze
|
|
45
|
+
## Analyze Loan Risk
|
|
284
46
|
|
|
285
47
|
```http
|
|
286
48
|
POST /analyze
|
|
287
49
|
```
|
|
288
50
|
|
|
289
|
-
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
# Example Request
|
|
290
54
|
|
|
291
55
|
```json
|
|
292
56
|
{
|
|
@@ -302,83 +66,29 @@ POST /analyze
|
|
|
302
66
|
|
|
303
67
|
---
|
|
304
68
|
|
|
305
|
-
#
|
|
306
|
-
|
|
307
|
-
## Build
|
|
69
|
+
# Example Response
|
|
308
70
|
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
## Coverage
|
|
320
|
-
|
|
321
|
-
```bash
|
|
322
|
-
pnpm coverage
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
## Type Check
|
|
326
|
-
|
|
327
|
-
```bash
|
|
328
|
-
pnpm -r exec tsc --noEmit
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"success": true,
|
|
74
|
+
"data": {
|
|
75
|
+
"score": 85,
|
|
76
|
+
"riskLevel": "LOW",
|
|
77
|
+
"approved": true
|
|
78
|
+
}
|
|
79
|
+
}
|
|
329
80
|
```
|
|
330
81
|
|
|
331
82
|
---
|
|
332
83
|
|
|
333
|
-
#
|
|
334
|
-
|
|
335
|
-
This project uses:
|
|
336
|
-
|
|
337
|
-
- Vitest
|
|
338
|
-
- TypeScript
|
|
339
|
-
- Workspace testing
|
|
340
|
-
|
|
341
|
-
Current tests:
|
|
342
|
-
|
|
343
|
-
- Core engine tests
|
|
344
|
-
- Hooks tests
|
|
345
|
-
- Plugin tests
|
|
346
|
-
- Fraud detection tests
|
|
347
|
-
- Performance tests
|
|
348
|
-
|
|
349
|
-
---
|
|
350
|
-
|
|
351
|
-
# CI/CD
|
|
352
|
-
|
|
353
|
-
GitHub Actions workflow included.
|
|
354
|
-
|
|
355
|
-
Automatically runs:
|
|
356
|
-
|
|
357
|
-
- Install
|
|
358
|
-
- Type checking
|
|
359
|
-
- Build
|
|
360
|
-
- Tests
|
|
361
|
-
|
|
362
|
-
On every push and pull request.
|
|
363
|
-
|
|
364
|
-
---
|
|
365
|
-
|
|
366
|
-
# Open Source
|
|
84
|
+
# Swagger Docs
|
|
367
85
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
86
|
+
```txt
|
|
87
|
+
http://localhost:4000/docs
|
|
88
|
+
```
|
|
371
89
|
|
|
372
90
|
---
|
|
373
91
|
|
|
374
92
|
# License
|
|
375
93
|
|
|
376
|
-
MIT
|
|
377
|
-
|
|
378
|
-
Copyright (c) 2026 Aparna Nikam
|
|
379
|
-
|
|
380
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
381
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
382
|
-
in the Software without restriction.
|
|
383
|
-
|
|
384
|
-
See the LICENSE file for full details.
|
|
94
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loan-risk/http-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Express HTTP API for loan risk analysis engine",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Aparna Nikam",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"swagger-jsdoc": "^6.2.8",
|
|
28
28
|
"swagger-ui-express": "^5.0.1",
|
|
29
29
|
"zod": "^4.4.3",
|
|
30
|
-
"@loan-risk/core": "1.0.
|
|
31
|
-
"@loan-risk/logger": "1.0.
|
|
30
|
+
"@loan-risk/core": "1.0.1",
|
|
31
|
+
"@loan-risk/logger": "1.0.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/cors": "^2.8.19",
|