koa-micro-ts 4.1.1 → 5.2.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/LICENSE +1 -1
- package/README.md +66 -2
- package/dist/apiDoc.d.ts +5 -1
- package/dist/apiDoc.js +219 -160
- package/dist/apiDoc.js.map +1 -1
- package/dist/app.interface.d.ts +13 -3
- package/dist/args.js +2 -1
- package/dist/args.js.map +1 -1
- package/dist/autoRoute.d.ts +4 -0
- package/dist/autoRoute.js +67 -111
- package/dist/autoRoute.js.map +1 -1
- package/dist/cors.js +13 -3
- package/dist/cors.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +47 -23
- package/dist/index.js.map +1 -1
- package/dist/jwt.js +12 -22
- package/dist/jwt.js.map +1 -1
- package/dist/log.d.ts +1 -2
- package/dist/log.js +78 -72
- package/dist/log.js.map +1 -1
- package/dist/requestStats.d.ts +1 -1
- package/dist/requestStats.js +9 -3
- package/dist/requestStats.js.map +1 -1
- package/dist/static.d.ts +1 -1
- package/dist/static.js +7 -7
- package/dist/static.js.map +1 -1
- package/dist/validators.d.ts +2 -2
- package/dist/validators.js +9 -6
- package/dist/validators.js.map +1 -1
- package/package.json +20 -12
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -44,12 +44,76 @@ Included middleware/libs:
|
|
|
44
44
|
- dev/production mode detection - see below in this README.md
|
|
45
45
|
- catch errors - detailed docs [CATCHERRORS.md](docs/CATCHERRORS.md)
|
|
46
46
|
- request stats - detailed docs [REQUESTSTATS.md](docs/REQUESTSTATS.md)
|
|
47
|
-
- integrated API doc - detailed docs [APIDOC.md](docs/APIDOC.md)
|
|
47
|
+
- integrated API doc - auto-generated for all `autoRoute` endpoints - detailed docs [APIDOC.md](docs/APIDOC.md)
|
|
48
48
|
|
|
49
49
|
Most of these modules can be enabled with just **one line of code**.
|
|
50
50
|
Configuration is super simple and lets you create your micro service within
|
|
51
51
|
minutes.
|
|
52
52
|
|
|
53
|
+
## New Release 5
|
|
54
|
+
|
|
55
|
+
Version 5 is a security-hardening release. Based on a full security audit,
|
|
56
|
+
several unsafe defaults were fixed: the built-in CORS middleware no longer
|
|
57
|
+
reflects arbitrary request origins, error responses no longer leak internal
|
|
58
|
+
details in production, the JWT middleware only exposes verified token
|
|
59
|
+
payloads, the generated API doc page is HTML-escaped and request stats can no
|
|
60
|
+
longer grow memory unbounded. It also moves to koa 3 and Node 18+. Most apps
|
|
61
|
+
run unchanged — see the breaking changes and the upgrade path below.
|
|
62
|
+
|
|
63
|
+
## Version 5 - Breaking Changes
|
|
64
|
+
|
|
65
|
+
- Dependencies: koa 3
|
|
66
|
+
- minimal node version: node V18
|
|
67
|
+
- CORS: default `credentials: true` → `false`
|
|
68
|
+
- CORS: the default `origin` is now `*` instead of reflecting the request
|
|
69
|
+
origin. `origin` additionally accepts an array (allowlist) or a function
|
|
70
|
+
`(ctx) => origin`
|
|
71
|
+
- CORS: `credentials: true` now requires an explicitly configured `origin`
|
|
72
|
+
(string, allowlist array or function). Without it, CORS headers are omitted
|
|
73
|
+
instead of reflecting the request origin — see [CORS.md](docs/CORS.md)
|
|
74
|
+
- `catchErrors()`: 5xx responses only contain a generic `Internal Server Error`
|
|
75
|
+
in production. Full details are still logged and returned in development
|
|
76
|
+
mode (`app.development`) or when the error sets `expose: true`
|
|
77
|
+
(Koa convention, e.g. `ctx.throw`) — see [CATCHERRORS.md](docs/CATCHERRORS.md)
|
|
78
|
+
- JWT middleware: `ctx.jwt` now contains only the **verified** token payload
|
|
79
|
+
(previously the unverified decoded token was set before verification).
|
|
80
|
+
The payload is also available as `ctx.state.user`
|
|
81
|
+
- SPA fallback (`apiHistoryFallback()`): the Accept header check was fixed —
|
|
82
|
+
requests accepting `text/html` **or** `*/*` get the fallback (previously
|
|
83
|
+
both were required, so plain browser requests could miss the fallback)
|
|
84
|
+
- request stats: `pathCounts` is capped at 1000 distinct paths, further paths
|
|
85
|
+
are aggregated under `(other)`
|
|
86
|
+
- `validators.sanitize()` and `validators.stripAll()` are deprecated — they
|
|
87
|
+
are not a reliable defense against injection, use parameterized queries and
|
|
88
|
+
output encoding instead
|
|
89
|
+
|
|
90
|
+
### Upgrading from v4
|
|
91
|
+
|
|
92
|
+
1. Make sure you run Node 18 or later, then update the package:
|
|
93
|
+
`npm install koa-micro-ts@5`.
|
|
94
|
+
2. **CORS with cookies/credentials:** if you call `app.cors({ credentials: true })`
|
|
95
|
+
without an explicit `origin`, browsers will now be denied. Configure your
|
|
96
|
+
allowed origins explicitly:
|
|
97
|
+
```ts
|
|
98
|
+
app.cors({
|
|
99
|
+
origin: ["https://app.example.com"],
|
|
100
|
+
credentials: true,
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
If you relied on the old reflect-any-origin behavior and really want it
|
|
104
|
+
(not recommended), pass `origin: (ctx) => ctx.get('Origin')`.
|
|
105
|
+
3. **Error responses:** if clients parse error details from 5xx responses,
|
|
106
|
+
either throw with `expose: true` / use `ctx.throw(...)`, or handle those
|
|
107
|
+
errors in your own middleware before `catchErrors()`.
|
|
108
|
+
4. **JWT:** if you read `ctx.jwt` for tokens that fail verification — that is
|
|
109
|
+
no longer possible; handlers behind `jwt.middleware()` only ever see
|
|
110
|
+
verified payloads. `ctx.state.user` now works as documented.
|
|
111
|
+
5. **Optional hardening:** protect the stats and API doc endpoints with JWT
|
|
112
|
+
(`app.stats('/stats', true)`, `app.apiDocAuth = true`) and set body parser
|
|
113
|
+
limits (`jsonLimit`, `formLimit`, `formidable.maxFileSize`) — see
|
|
114
|
+
[REQUESTSTATS.md](docs/REQUESTSTATS.md), [APIDOC.md](docs/APIDOC.md),
|
|
115
|
+
[BODYPARSER.md](docs/BODYPARSER.md).
|
|
116
|
+
|
|
53
117
|
## Version 4 - Breaking Change
|
|
54
118
|
|
|
55
119
|
`app.autoRoute()` is now an async function.
|
|
@@ -221,7 +285,7 @@ documentation of the used packages to see their options:
|
|
|
221
285
|
|
|
222
286
|
> The [`MIT`][license-url] License (MIT)
|
|
223
287
|
>
|
|
224
|
-
> Copyright ©
|
|
288
|
+
> Copyright © 2026 Sebastian Hildebrandt,
|
|
225
289
|
> [+innovations](http://www.plus-innovations.com).
|
|
226
290
|
>
|
|
227
291
|
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
package/dist/apiDoc.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
declare const mergeDeep: (target: any, source: any) => any;
|
|
2
2
|
declare const parseFileApiDoc: (fileName: string, secure: boolean) => any;
|
|
3
|
+
declare const parseReducedDocs: (fileName: string) => {
|
|
4
|
+
[name: string]: string;
|
|
5
|
+
};
|
|
6
|
+
declare const autoDocEntry: (docObj: any, group: string, method: string, path: string, secure: boolean, meta?: any) => void;
|
|
3
7
|
declare const healthDocObj: (healthPath: string, livePath: string) => {
|
|
4
8
|
Health: {
|
|
5
9
|
method: string;
|
|
@@ -27,4 +31,4 @@ declare const statsDocObj: (statsPath: string) => {
|
|
|
27
31
|
}[];
|
|
28
32
|
};
|
|
29
33
|
declare const createHtml: (apiDocObj: any) => string;
|
|
30
|
-
export { createHtml, healthDocObj, mergeDeep, parseFileApiDoc, statsDocObj };
|
|
34
|
+
export { autoDocEntry, createHtml, healthDocObj, mergeDeep, parseFileApiDoc, parseReducedDocs, statsDocObj };
|