@meghjs/core 0.5.5 → 0.6.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 +85 -141
- package/dist/common/container.js +0 -1
- package/dist/common/container.js.map +1 -1
- package/dist/common/exceptions/system-exception.d.ts +0 -10
- package/dist/common/exceptions/system-exception.js +7 -12
- package/dist/common/exceptions/system-exception.js.map +1 -1
- package/dist/common/utils/compiled-validation.js +2 -1
- package/dist/common/utils/compiled-validation.js.map +1 -1
- package/dist/config/environment-variables.js +2 -1
- package/dist/config/environment-variables.js.map +1 -1
- package/dist/core/application.d.ts +53 -8
- package/dist/core/application.js +130 -36
- package/dist/core/application.js.map +1 -1
- package/dist/core/interfaces.d.ts +10 -3
- package/dist/core/router.d.ts +28 -4
- package/dist/core/router.js +32 -21
- package/dist/core/router.js.map +1 -1
- package/dist/core/types.d.ts +3 -0
- package/dist/events/event-subscriber.js.map +1 -1
- package/dist/events/socket-dispatcher.d.ts +0 -2
- package/dist/events/socket-dispatcher.js +1 -9
- package/dist/events/socket-dispatcher.js.map +1 -1
- package/dist/http/multipart.js.map +1 -1
- package/dist/http/route-methods.js.map +1 -1
- package/dist/http/validator-extend.js +1 -1
- package/dist/http/validator-extend.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/mail/config.d.ts +141 -0
- package/dist/mail/config.js +199 -0
- package/dist/mail/config.js.map +1 -0
- package/dist/mail/errors.d.ts +4 -0
- package/dist/mail/errors.js +12 -0
- package/dist/mail/errors.js.map +1 -0
- package/dist/mail/http-transports.d.ts +44 -0
- package/dist/mail/http-transports.js +319 -0
- package/dist/mail/http-transports.js.map +1 -0
- package/dist/mail/index.d.ts +8 -0
- package/dist/mail/index.js +46 -0
- package/dist/mail/index.js.map +1 -0
- package/dist/mail/mailable.d.ts +34 -0
- package/dist/mail/mailable.js +38 -0
- package/dist/mail/mailable.js.map +1 -0
- package/dist/mail/mailer.d.ts +208 -0
- package/dist/mail/mailer.js +502 -0
- package/dist/mail/mailer.js.map +1 -0
- package/dist/mail/queue.d.ts +32 -0
- package/dist/mail/queue.js +59 -0
- package/dist/mail/queue.js.map +1 -0
- package/dist/mail/transports.d.ts +37 -0
- package/dist/mail/transports.js +152 -0
- package/dist/mail/transports.js.map +1 -0
- package/dist/mail/types.d.ts +95 -0
- package/dist/mail/types.js +3 -0
- package/dist/mail/types.js.map +1 -0
- package/dist/openapi/swagger-schema.d.ts +0 -2
- package/dist/openapi/swagger-schema.js +0 -3
- package/dist/openapi/swagger-schema.js.map +1 -1
- package/dist/realtime/websocket.d.ts +1 -7
- package/dist/realtime/websocket.js +2 -18
- package/dist/realtime/websocket.js.map +1 -1
- package/dist/security/headers.d.ts +65 -0
- package/dist/security/headers.js +148 -0
- package/dist/security/headers.js.map +1 -0
- package/dist/security/index.d.ts +3 -0
- package/dist/security/index.js +5 -0
- package/dist/security/index.js.map +1 -1
- package/dist/security/rate-limit.d.ts +129 -0
- package/dist/security/rate-limit.js +260 -0
- package/dist/security/rate-limit.js.map +1 -0
- package/dist/storage/file-storage.js +6 -4
- package/dist/storage/file-storage.js.map +1 -1
- package/package.json +10 -13
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ Megh is a TypeScript-first web framework built on top of [Fastify](https://fasti
|
|
|
38
38
|
- [Pagination](#pagination)
|
|
39
39
|
- [Events](#events)
|
|
40
40
|
- [Queues & Workers](#queues--workers)
|
|
41
|
+
- [Mail](#mail)
|
|
41
42
|
- [Task Scheduling](#task-scheduling)
|
|
42
43
|
- [Caching](#caching)
|
|
43
44
|
- [File Uploads](#file-uploads)
|
|
@@ -69,6 +70,7 @@ Megh is a TypeScript-first web framework built on top of [Fastify](https://fasti
|
|
|
69
70
|
- ⚙️ **Config** — typed, environment-aware config classes
|
|
70
71
|
- 📣 **Events** — typed events with queued delivery and Socket.IO broadcast
|
|
71
72
|
- 📬 **Queues & workers** — background jobs on [BullMQ](https://docs.bullmq.io), with in-memory drivers for tests
|
|
73
|
+
- ✉️ **Mail** — mailable classes over SMTP, SendGrid, Mailgun, Postmark or Resend, sent now or queued, with a test fake
|
|
72
74
|
- ⏰ **Task scheduling** — cron, interval and timeout jobs
|
|
73
75
|
- 🗃️ **Caching** — in-memory or Redis, with TTL and tag-based invalidation
|
|
74
76
|
- 📝 **Logging** — structured JSON logs via [pino](https://getpino.io)
|
|
@@ -117,21 +119,22 @@ Megh keeps integrations out of the core install. Add only what you use. The
|
|
|
117
119
|
package imports fine without any of them, and you get a clear error the moment a
|
|
118
120
|
feature needs one:
|
|
119
121
|
|
|
120
|
-
| Feature | Install
|
|
121
|
-
| -------------------------------------------- |
|
|
122
|
-
| CORS (`useCors`) | `npm i @fastify/cors`
|
|
123
|
-
| File uploads (`useMultipart`, `@UploadFile`) | `npm i @fastify/multipart`
|
|
124
|
-
| Static files (`useStaticFiles`) | `npm i @fastify/static`
|
|
125
|
-
| OpenAPI with Swagger UI | `npm i @fastify/swagger @fastify/swagger-ui`
|
|
126
|
-
| OpenAPI with Scalar | `npm i @fastify/swagger @scalar/fastify-api-reference`
|
|
127
|
-
| MeghORM (`useMeghORM`) | a driver (`pg`, `mysql2`, `better-sqlite3`, or `tedious tarn`)
|
|
128
|
-
| TypeORM | `npm i typeorm` + a driver (`pg`, `mysql2`, `sqlite3`, `better-sqlite3`, `mssql`)
|
|
129
|
-
| Knex | `npm i knex` + a driver
|
|
130
|
-
| Queues & workers | `npm i bullmq ioredis` (not needed with the `memory`/`sync` drivers)
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
|
|
|
122
|
+
| Feature | Install |
|
|
123
|
+
| -------------------------------------------- | ------------------------------------------------------------------------------------ |
|
|
124
|
+
| CORS (`useCors`) | `npm i @fastify/cors` |
|
|
125
|
+
| File uploads (`useMultipart`, `@UploadFile`) | `npm i @fastify/multipart` |
|
|
126
|
+
| Static files (`useStaticFiles`) | `npm i @fastify/static` |
|
|
127
|
+
| OpenAPI with Swagger UI | `npm i @fastify/swagger @fastify/swagger-ui` |
|
|
128
|
+
| OpenAPI with Scalar | `npm i @fastify/swagger @scalar/fastify-api-reference` |
|
|
129
|
+
| MeghORM (`useMeghORM`) | a driver (`pg`, `mysql2`, `better-sqlite3`, or `tedious tarn`) |
|
|
130
|
+
| TypeORM | `npm i typeorm` + a driver (`pg`, `mysql2`, `sqlite3`, `better-sqlite3`, `mssql`) |
|
|
131
|
+
| Knex | `npm i knex` + a driver |
|
|
132
|
+
| Queues & workers | `npm i bullmq ioredis` (not needed with the `memory`/`sync` drivers) |
|
|
133
|
+
| Mail over SMTP | `npm i nodemailer` (the SendGrid, Mailgun, Postmark and Resend mailers need nothing) |
|
|
134
|
+
| Redis cache | `npm i ioredis` |
|
|
135
|
+
| WebSocket | `npm i socket.io fastify-socket.io` |
|
|
136
|
+
| Image transforms in `FileStorage` | `npm i sharp` |
|
|
137
|
+
| Pretty dev logs | `npm i -D pino-pretty` |
|
|
135
138
|
|
|
136
139
|
### Module format
|
|
137
140
|
|
|
@@ -920,6 +923,48 @@ await waitForMemoryQueues(); // wait until all jobs finish
|
|
|
920
923
|
resetMemoryQueues();
|
|
921
924
|
```
|
|
922
925
|
|
|
926
|
+
### Mail
|
|
927
|
+
|
|
928
|
+
Send email from **mailable** classes over SMTP ([Nodemailer](https://nodemailer.com)) or the SendGrid, Mailgun, Postmark and Resend APIs, straight away or from a queue.
|
|
929
|
+
|
|
930
|
+
```ts
|
|
931
|
+
// app.ts — settings come from MEGH_MAIL_* in .env
|
|
932
|
+
app.useMail({ queue: true });
|
|
933
|
+
|
|
934
|
+
// mail/welcome.mail.ts — npx megh make:mail Welcome
|
|
935
|
+
export class WelcomeMail extends Mailable {
|
|
936
|
+
constructor(private readonly user: User) {
|
|
937
|
+
super();
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
envelope() {
|
|
941
|
+
return { subject: `Welcome, ${this.user.name}` };
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
content() {
|
|
945
|
+
return { html: `<p>Hi ${this.user.name}!</p>`, text: `Hi ${this.user.name}!` };
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
// any service
|
|
950
|
+
constructor(private readonly mailer: Mailer) {}
|
|
951
|
+
|
|
952
|
+
await this.mailer.to(user.email).send(new WelcomeMail(user));
|
|
953
|
+
await this.mailer.to(user.email).later(60_000, new WelcomeMail(user)); // queued
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
```ini
|
|
957
|
+
MEGH_MAIL_MAILER=smtp # or sendgrid, mailgun, postmark, resend, failover, log
|
|
958
|
+
MEGH_MAIL_HOST=smtp.example.com
|
|
959
|
+
MEGH_MAIL_FROM_ADDRESS=hello@example.com
|
|
960
|
+
```
|
|
961
|
+
|
|
962
|
+
- With no mailer set, mail goes to the log in development; in production the app refuses to start.
|
|
963
|
+
- `failover` tries mailers in order: `MEGH_MAIL_FAILOVER=sendgrid,smtp`.
|
|
964
|
+
- `Mailer.fake()` records mail in tests: `mail.assertSent(WelcomeMail, (sent) => sent.hasTo(user.email))`.
|
|
965
|
+
|
|
966
|
+
See the [Mail guide](https://meghjs.github.io/advanced/mail) for every option.
|
|
967
|
+
|
|
923
968
|
---
|
|
924
969
|
|
|
925
970
|
### Task Scheduling
|
|
@@ -1015,8 +1060,20 @@ app.useMultipart({
|
|
|
1015
1060
|
});
|
|
1016
1061
|
```
|
|
1017
1062
|
|
|
1063
|
+
`useMultipart()` passes its options to `@fastify/multipart`. Megh sets
|
|
1064
|
+
`attachFieldsToBody: true` (needed by `@UploadFile`) and a **10 MB** per-file
|
|
1065
|
+
limit unless you pass your own `limits`. The smaller of this limit and
|
|
1066
|
+
`FileStorage`'s `maxFileSize` (50 MB) wins, so raise both for bigger files.
|
|
1067
|
+
|
|
1018
1068
|
```typescript
|
|
1019
|
-
import {
|
|
1069
|
+
import {
|
|
1070
|
+
ApiController,
|
|
1071
|
+
Post,
|
|
1072
|
+
FileStorage,
|
|
1073
|
+
UploadFile,
|
|
1074
|
+
MultipartFile,
|
|
1075
|
+
OpenApi,
|
|
1076
|
+
} from "@meghjs/core";
|
|
1020
1077
|
|
|
1021
1078
|
@ApiController("/files")
|
|
1022
1079
|
class FileController {
|
|
@@ -1078,7 +1135,7 @@ import path from "path";
|
|
|
1078
1135
|
|
|
1079
1136
|
// requires @fastify/static
|
|
1080
1137
|
app.useStaticFiles({
|
|
1081
|
-
|
|
1138
|
+
root: path.join(process.cwd(), "public"),
|
|
1082
1139
|
prefix: "/static/",
|
|
1083
1140
|
});
|
|
1084
1141
|
```
|
|
@@ -1216,10 +1273,12 @@ dispatches jobs without Redis.
|
|
|
1216
1273
|
- Set `NODE_ENV=production`. Unset also counts as production, but be explicit.
|
|
1217
1274
|
Production mode hides 5xx details, writes JSON logs, and makes
|
|
1218
1275
|
`app.isDevelopment()` false.
|
|
1219
|
-
- `app.run(port)` defaults to
|
|
1276
|
+
- `app.run(port)` defaults to `PORT`, else 4000, and listens on `HOST` or `0.0.0.0`
|
|
1220
1277
|
(`app.run(port, { host })` to change it). It handles `SIGTERM`/`SIGINT` by
|
|
1221
1278
|
stopping the scheduler, closing registered workers and the cache, and gives
|
|
1222
1279
|
up after `shutdownTimeout`.
|
|
1280
|
+
- Add `app.useSecurityHeaders()` and `app.useRateLimit()`. See
|
|
1281
|
+
[Security Hardening](https://meghjs.github.io/production/security).
|
|
1223
1282
|
- Add `app.useHealth()` for `/health` and `/ready` probes. See
|
|
1224
1283
|
[Health Checks](https://meghjs.github.io/advanced/health).
|
|
1225
1284
|
- Register an authorizer if you use `@Authorized`; without one those routes
|
|
@@ -1267,129 +1326,14 @@ These are regressions or gaps in 0.3.0 that are expected to be fixed in a patch
|
|
|
1267
1326
|
|
|
1268
1327
|
## Roadmap to 1.0.0
|
|
1269
1328
|
|
|
1270
|
-
1.0.0 is the first release with a stable API
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
- [x] Handlers receive the validated DTO; unknown properties are rejected (mass-assignment protection)
|
|
1279
|
-
- [x] File storage confines every read, write and delete to `baseDir`, including sibling-prefix and symlink escapes
|
|
1280
|
-
- [x] Uploads get random names, don't overwrite, and are checked against an extension allowlist and a size limit
|
|
1281
|
-
- [x] Path traversal in `UploadFileFromRequest` closed
|
|
1282
|
-
- [x] `Content-Disposition` header injection closed
|
|
1283
|
-
- [x] Credentials are no longer logged, and production hides 5xx details and requires `NODE_ENV=development` for dev mode
|
|
1284
|
-
- [x] Concurrent requests no longer share `FileStorage` transform settings
|
|
1285
|
-
|
|
1286
|
-
**Correctness**
|
|
1287
|
-
|
|
1288
|
-
- [x] Built-in `Validator` accepts `0` and enforces `min` / `max` / `exact` / `optional`
|
|
1289
|
-
- [x] Missing decorator metadata (tsx, esbuild, SWC) no longer crashes; `@Body({ type })` supplies the type
|
|
1290
|
-
- [x] TypeORM query operators work at runtime
|
|
1291
|
-
- [x] `MeghRepository.transaction()` runs inside the transaction, and `@InjectRepository` works after `useTypeORM()`
|
|
1292
|
-
- [x] Collection fixes: `paginate`, `min`, `findAsync`
|
|
1293
|
-
- [x] One pagination shape across Collection, TypeORM and Knex
|
|
1294
|
-
- [x] Events keyed by class, exactly-once `once` listeners, `delay` honoured when queued, failed jobs kept
|
|
1295
|
-
- [x] Scheduler decorators no longer leak into parent classes
|
|
1296
|
-
- [x] In-memory cache enforces TTL; Redis tag sets expire
|
|
1297
|
-
- [x] JSON logs in production; framework logs go through `LoggerService`
|
|
1298
|
-
- [x] OpenAPI component schemas generated without instantiating classes
|
|
1299
|
-
|
|
1300
|
-
**Features**
|
|
1301
|
-
|
|
1302
|
-
- [x] Producer-only queues (`worker: false`) and workers that no longer start on import
|
|
1303
|
-
- [x] In-memory `memory` and `sync` queue drivers for tests
|
|
1304
|
-
- [x] `Results.Created` / `NoContent` / `OkStream` and `@HttpCode` APIs (not yet applied; see below)
|
|
1305
|
-
|
|
1306
|
-
**Packaging and tooling**
|
|
1307
|
-
|
|
1308
|
-
- [x] CommonJS-only build with an `exports` map and `sideEffects`
|
|
1309
|
-
- [x] Integrations moved to optional peer dependencies
|
|
1310
|
-
- [x] Replace typedi with Megh's own container behind `MeghContainer`
|
|
1311
|
-
- [x] MIT license file matches `package.json`
|
|
1312
|
-
- [x] Build without rimraf, ESLint/Jest configs fixed, husky 9, coverage off by default
|
|
1313
|
-
- [x] CI on Node 22 and 24 (typecheck, lint, test, build) and a tag-based publish workflow
|
|
1314
|
-
- [x] Request-pipeline integration tests
|
|
1315
|
-
|
|
1316
|
-
**Docs**
|
|
1317
|
-
|
|
1318
|
-
- [x] README and docs site rewritten for the current API, with an upgrade guide
|
|
1319
|
-
- [x] New pages: authentication, file uploads, caching, logging
|
|
1320
|
-
- [x] Docs site moved to VitePress, with template links removed and typos fixed
|
|
1321
|
-
|
|
1322
|
-
### Left for 1.0.0
|
|
1323
|
-
|
|
1324
|
-
**Regressions from 0.3.0** (see [Known Issues](#known-issues-in-030))
|
|
1325
|
-
|
|
1326
|
-
- [x] `@UseMiddleware(SomeClass)` crashes boot (fixed in 0.5.2)
|
|
1327
|
-
- [ ] `@Repository` / `@Queue` classes without a constructor break under DI
|
|
1328
|
-
- [ ] Apply status codes from `Results`, `HttpResponse.Created` and `@HttpCode`
|
|
1329
|
-
- [ ] Put `@Body()` / `@Query()` DTO schemas back into the OpenAPI document
|
|
1330
|
-
- [ ] Upload policy violations should return 400 / 413, not 500
|
|
1331
|
-
|
|
1332
|
-
**Core correctness**
|
|
1333
|
-
|
|
1334
|
-
- [ ] `useScheduler({ path })` crashes `run()` (wrong `require` path)
|
|
1335
|
-
- [ ] `@UploadFile` / `@UploadFiles` don't await `saveRequestFiles()`
|
|
1336
|
-
- [ ] `@All()` crashes at registration
|
|
1337
|
-
- [ ] Respect `error.statusCode` (401, 413, 415, 429, …) for non-HTTP-exception errors
|
|
1338
|
-
- [ ] One consistent middleware order; resolve `@UseMiddleware` through DI
|
|
1339
|
-
- [ ] Route metadata cache is keyed on `constructor.name`, so same-named classes collide
|
|
1340
|
-
- [ ] Controller discovery: `_resolveControllerDir` ignores its argument and rewrites the first `src` in the path; repeated `useControllers` calls overwrite each other
|
|
1341
|
-
- [ ] Functional routes: add `mapPatch`, and run authentication, DI and the standard error shape
|
|
1342
|
-
- [ ] `run()` `host` option (default `0.0.0.0` in containers)
|
|
1343
|
-
- [ ] Graceful shutdown: `app.close()` and close TypeORM, Knex, Redis and Socket.IO with a drain timeout instead of `process.exit(0)`
|
|
1344
|
-
- [ ] `PartialType` / `OmitType` / `PickType` don't carry class-validator rules correctly
|
|
1345
|
-
- [ ] Scalar `spec.content` returns the plugin module instead of the spec
|
|
1346
|
-
- [ ] `Environment` re-reads `.env` on every `get()`, and `dotenv` loads on import
|
|
1347
|
-
- [ ] Socket handler errors become unhandled rejections
|
|
1348
|
-
- [ ] `@MeghWorker` `autoStart` is not wired to app boot
|
|
1349
|
-
- [ ] `class-validator` / `class-transformer` are loaded at import time despite being optional peers
|
|
1350
|
-
|
|
1351
|
-
**Missing features**
|
|
1352
|
-
|
|
1353
|
-
- [ ] Security headers (helmet) and rate limiting as `use*` options
|
|
1354
|
-
- [ ] Health and readiness endpoints
|
|
1355
|
-
- [ ] Request IDs in logs, and the logger wired into Fastify
|
|
1356
|
-
- [ ] Redirects and response headers from handlers
|
|
1357
|
-
- [ ] Pluggable error handler / exception filters
|
|
1358
|
-
- [x] Lifecycle hooks (`onInit`, `onReady`, `onClose`, `app.close()`)
|
|
1359
|
-
- [ ] Config schema validation at boot
|
|
1360
|
-
- [ ] Global route prefix and API versioning
|
|
1361
|
-
- [ ] Compression
|
|
1362
|
-
- [ ] Socket.IO handshake authentication and per-channel authorization
|
|
1363
|
-
|
|
1364
|
-
**API cleanup** (a 1.0 surface is a promise)
|
|
1365
|
-
|
|
1366
|
-
- [ ] Finish or remove the no-ops `useHttps()`, `useSerialization()` and `mapFeatures()`
|
|
1367
|
-
- [x] Move TypeORM and Knex to the `@meghjs/data` plugin, and remove deprecated `useDatasource()`
|
|
1368
|
-
- [ ] Remove the `MeghSocketIo` stubs and unused adapter types
|
|
1369
|
-
- [ ] Remove `KnexHooks` / `KnexHooksFactory`, `DuplicateRouteException`, `mapRoute()` and `registerMiddleware()`
|
|
1370
|
-
- [x] Stop exporting `mock-db` from the public index, and build without Jest types
|
|
1371
|
-
- [ ] Replace remaining `console.log` calls with the logger
|
|
1372
|
-
|
|
1373
|
-
**Tests**
|
|
1374
|
-
|
|
1375
|
-
- [ ] `application.ts`: `run()`, shutdown, controller auto-discovery, `useScheduler({ path })`
|
|
1376
|
-
- [ ] Events, scheduler, workers, Redis cache, `testing.ts`, `map-types.ts`, config
|
|
1377
|
-
- [ ] Fix hollow tests and `MeghTest` (`from()` race, global container mutation)
|
|
1378
|
-
- [ ] Coverage thresholds
|
|
1379
|
-
|
|
1380
|
-
**CLI** (`@meghjs/cli`, rewrite in progress)
|
|
1381
|
-
|
|
1382
|
-
- [ ] Finish the commander-based rewrite: `--help` / `--version`, consistent flags and naming, refuse to overwrite existing projects
|
|
1383
|
-
- [ ] Generated code compiles against `@meghjs/core`
|
|
1384
|
-
- [ ] CLI tests (snapshots for every `make:*` command)
|
|
1385
|
-
- [ ] Release with versions matched to core
|
|
1386
|
-
|
|
1387
|
-
**Docs and release**
|
|
1388
|
-
|
|
1389
|
-
- [ ] Pages for configuration, scheduler, testing, dependency injection, responses, deployment and security hardening
|
|
1390
|
-
- [ ] API reference and FAQ
|
|
1391
|
-
- [ ] Contributor guide: project structure, and the exports that CLI-generated code relies on
|
|
1392
|
-
- [ ] Changelog and a versioning policy across core, CLI and docs
|
|
1329
|
+
1.0.0 is the first release with a stable API. Until then, minor releases
|
|
1330
|
+
(0.6, 0.7, …) can contain breaking changes, each with an upgrade guide.
|
|
1331
|
+
|
|
1332
|
+
Work left for 1.0.0 is tracked as issues in the
|
|
1333
|
+
[`1.0.0` milestone](https://github.com/meghjs/megh/milestone/1), with an
|
|
1334
|
+
overview in [`1.0-CHECKLIST.md`](https://github.com/meghjs/megh/blob/main/1.0-CHECKLIST.md).
|
|
1335
|
+
What's left is mainly core correctness fixes, security headers, rate limiting
|
|
1336
|
+
and compression, a global route prefix, tests, and trimming the public API.
|
|
1393
1337
|
|
|
1394
1338
|
---
|
|
1395
1339
|
|
package/dist/common/container.js
CHANGED
|
@@ -26,7 +26,6 @@ exports.DATASOURCE_META_KEY = Symbol("idatasource:options");
|
|
|
26
26
|
exports.AUTHORIZATION_META_KEY = Symbol("idatasource:authorization");
|
|
27
27
|
const controllerRegistry = new Set();
|
|
28
28
|
const serviceRegistry = new Set();
|
|
29
|
-
const optionsRegistry = new Map();
|
|
30
29
|
function registerController(controller) {
|
|
31
30
|
controllerRegistry.add(controller);
|
|
32
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/common/container.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/common/container.ts"],"names":[],"mappings":";;;AAsBA,gDAEC;AACD,0CAGC;AAED,sDAEC;AACD,4DAEC;AAID,0CAEC;AAzCD;;;;;GAKG;AACH,8BAAkC;AACrB,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpD,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,qBAAqB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACjD,QAAA,qBAAqB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACjD,QAAA,sBAAsB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAClD,QAAA,qBAAqB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AACjD,QAAA,uBAAuB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AACpD,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpD,QAAA,sBAAsB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAE1E,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAY,CAAC;AAC/C,MAAM,eAAe,GAAG,IAAI,GAAG,EAAY,CAAC;AAE5C,SAAgB,kBAAkB,CAAC,UAAoB;IACrD,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACrC,CAAC;AACD,SAAgB,eAAe,CAAC,OAAiB;IAC/C,cAAS,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC;AAED,SAAgB,qBAAqB;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AACrC,CAAC;AACD,SAAgB,wBAAwB;IACtC,OAAO,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AACxC,CAAC;AAEY,QAAA,2BAA2B,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAEnE,SAAgB,eAAe,CAAC,MAAgB;IAC9C,OAAO,OAAO,CAAC,WAAW,CAAC,mCAA2B,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;AAC3E,CAAC"}
|
|
@@ -4,19 +4,9 @@
|
|
|
4
4
|
* @email xtrinsic96@gmail.com
|
|
5
5
|
* @url https://github.com/xtareq
|
|
6
6
|
*/
|
|
7
|
-
export interface IRouteDuplicateErr {
|
|
8
|
-
path: string;
|
|
9
|
-
mpath: string;
|
|
10
|
-
method: string;
|
|
11
|
-
controller: string;
|
|
12
|
-
inverseController?: string;
|
|
13
|
-
}
|
|
14
7
|
export declare class SystemUseError extends Error {
|
|
15
8
|
constructor(message: string);
|
|
16
9
|
}
|
|
17
|
-
export declare class DuplicateRouteException extends Error {
|
|
18
|
-
constructor(params: IRouteDuplicateErr);
|
|
19
|
-
}
|
|
20
10
|
export declare class EnvironmentVariableNotFound extends Error {
|
|
21
11
|
constructor(key: string);
|
|
22
12
|
}
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnvironmentVariableNotFound = exports.
|
|
3
|
+
exports.EnvironmentVariableNotFound = exports.SystemUseError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @copyright 2024
|
|
6
|
+
* @author Tareq Hossain
|
|
7
|
+
* @email xtrinsic96@gmail.com
|
|
8
|
+
* @url https://github.com/xtareq
|
|
9
|
+
*/
|
|
4
10
|
class SystemUseError extends Error {
|
|
5
11
|
constructor(message) {
|
|
6
12
|
super(message);
|
|
7
13
|
}
|
|
8
14
|
}
|
|
9
15
|
exports.SystemUseError = SystemUseError;
|
|
10
|
-
class DuplicateRouteException extends Error {
|
|
11
|
-
constructor(params) {
|
|
12
|
-
let sameController = params.controller == params.inverseController;
|
|
13
|
-
let message = `Duplicate route found for method ${params.method.toUpperCase()}:${params.path == "" ? "'/'" : params.path} `;
|
|
14
|
-
message += sameController
|
|
15
|
-
? `in ${params.controller}`
|
|
16
|
-
: `both in ${params.controller} and ${params.inverseController}`;
|
|
17
|
-
super(message);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.DuplicateRouteException = DuplicateRouteException;
|
|
21
16
|
class EnvironmentVariableNotFound extends Error {
|
|
22
17
|
constructor(key) {
|
|
23
18
|
super(`${key} not found in environment variables.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-exception.js","sourceRoot":"","sources":["../../../src/common/exceptions/system-exception.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"system-exception.js","sourceRoot":"","sources":["../../../src/common/exceptions/system-exception.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,MAAa,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAJD,wCAIC;AACD,MAAa,2BAA4B,SAAQ,KAAK;IACpD,YAAY,GAAW;QACrB,KAAK,CAAC,GAAG,GAAG,sCAAsC,CAAC,CAAC;IACtD,CAAC;CACF;AAJD,kEAIC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.compileValidator = compileValidator;
|
|
4
|
+
const internal_logger_1 = require("../../observability/internal-logger");
|
|
4
5
|
const schema_properties_1 = require("../../openapi/schema-properties");
|
|
5
6
|
const messages_1 = require("../../validator/messages");
|
|
6
7
|
const IS_DEFINED = "isDefined";
|
|
@@ -30,7 +31,7 @@ function compileValidator(target) {
|
|
|
30
31
|
catch (error) {
|
|
31
32
|
if (!warnedUnavailable) {
|
|
32
33
|
warnedUnavailable = true;
|
|
33
|
-
|
|
34
|
+
(0, internal_logger_1.internalLogger)("validation").warn({ err: error }, "Compiled validation is unavailable, using class-validator");
|
|
34
35
|
}
|
|
35
36
|
compiled = null;
|
|
36
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiled-validation.js","sourceRoot":"","sources":["../../../src/common/utils/compiled-validation.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"compiled-validation.js","sourceRoot":"","sources":["../../../src/common/utils/compiled-validation.ts"],"names":[],"mappings":";;AAwFA,4CAsBC;AA5ED,yEAAqE;AACrE,uEAAwE;AACxE,uDAAuE;AAWvE,MAAM,UAAU,GAAG,WAAW,CAAC;AAC/B,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AACvD,MAAM,SAAS,GAAG,qBAAqB,CAAC;AAExC,qEAAqE;AACrE,MAAM,IAAI,GAAG,MA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M,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3C,wEAAwE;IACxE,wEAAwE;IACxE,IAAI,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,MAAM,IAAI,CAAC;IAC7D,2EAA2E;IAC3E,gEAAgE;IAChE,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC;QAAE,MAAM,IAAI,CAAC;IAE3E,MAAM,GAAG,GAAwB,EAAE,CAAC;IACpC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,GAAG,KAAK,WAAW,IAAI,GAAG,KAAK,aAAa;YAAE,SAAS;QAC3D,mDAAmD;QACnD,IAAI,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAC3C,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -53,6 +53,7 @@ const dotenv_1 = __importDefault(require("dotenv"));
|
|
|
53
53
|
const path_1 = __importDefault(require("path"));
|
|
54
54
|
const fs_1 = __importStar(require("fs"));
|
|
55
55
|
const di_1 = require("../di");
|
|
56
|
+
const internal_logger_1 = require("../observability/internal-logger");
|
|
56
57
|
const system_exception_1 = require("../common/exceptions/system-exception");
|
|
57
58
|
// Load `.env` into process.env on import, so module-level code can read it.
|
|
58
59
|
// Set MEGH_DOTENV=false to skip this and manage the environment yourself.
|
|
@@ -84,7 +85,7 @@ let Environment = class Environment {
|
|
|
84
85
|
: {});
|
|
85
86
|
}
|
|
86
87
|
catch (error) {
|
|
87
|
-
|
|
88
|
+
(0, internal_logger_1.internalLogger)("config").error({ err: error, file: filePath }, "Error parsing .env file");
|
|
88
89
|
fileCache.set(filePath, null);
|
|
89
90
|
}
|
|
90
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment-variables.js","sourceRoot":"","sources":["../../src/config/environment-variables.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oDAA4B;AAC5B,gDAAwB;AACxB,yCAAoC;AACpC,8BAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"environment-variables.js","sourceRoot":"","sources":["../../src/config/environment-variables.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oDAA4B;AAC5B,gDAAwB;AACxB,yCAAoC;AACpC,8BAAmC;AACnC,sEAAkE;AAClE,4EAAoF;AAEpF,4EAA4E;AAC5E,0EAA0E;AAC1E,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,OAAO,EAAE,CAAC;IACxC,gBAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,0EAA0E;AAC1E,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyC,CAAC;AACnE;;;;;GAKG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAW;IACtB;;;;;;;OAOG;IACK,YAAY,CAAC,QAAgB;QACnC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,SAAS,CAAC,GAAG,CACX,QAAQ,EACR,IAAA,eAAU,EAAC,QAAQ,CAAC;oBAClB,CAAC,CAAC,gBAAM,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;oBACjD,CAAC,CAAC,EAAE,CACP,CAAC;Y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AAC,YAAY,CAAC,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;QACtE,OAAO,SAAc,CAAC;IACxB,CAAC;CACF,CAAA;AA5EY,kCAAW;sBAAX,WAAW;IADvB,IAAA,eAAU,GAAE;GACA,WAAW,CA4EvB"}
|
|
@@ -11,9 +11,12 @@ import { Constructor } from "../common/helpers";
|
|
|
11
11
|
import { OpenApiUiOptions } from "../openapi/openapi";
|
|
12
12
|
import { MeghMiddleware } from "../http/middleware";
|
|
13
13
|
import { AutoControllerOptions } from "./types";
|
|
14
|
+
import type { MailConfig } from "../mail/config";
|
|
14
15
|
import { HealthCheck, HealthOptions } from "../observability/health";
|
|
15
16
|
import { MeghConfig } from "../config/config";
|
|
16
17
|
import { MeghAuthentication } from "../security/authentication";
|
|
18
|
+
import { SecurityHeadersOptions } from "../security/headers";
|
|
19
|
+
import { RateLimitOptions } from "../security/rate-limit";
|
|
17
20
|
export declare class MeghApplication implements IMeghApplication {
|
|
18
21
|
app: FastifyInstance;
|
|
19
22
|
private router;
|
|
@@ -21,12 +24,10 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
21
24
|
private alreadyRun;
|
|
22
25
|
private hasSwagger;
|
|
23
26
|
private globalSwaggerOptions;
|
|
24
|
-
private isMapFeatures;
|
|
25
27
|
private registerControllerAuto;
|
|
26
28
|
private registerControllerPath;
|
|
27
29
|
private controllers;
|
|
28
30
|
private _hasWebsocket;
|
|
29
|
-
private io;
|
|
30
31
|
private scheduler;
|
|
31
32
|
private schedulerTasks;
|
|
32
33
|
private registerSchedulerAuto;
|
|
@@ -37,6 +38,11 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
37
38
|
private signalHandler;
|
|
38
39
|
private pluginNames;
|
|
39
40
|
private usesCache;
|
|
41
|
+
private usesMail;
|
|
42
|
+
private usesSecurityHeaders;
|
|
43
|
+
private rateLimitOptions;
|
|
44
|
+
/** The rate limit store Megh created, closed on shutdown. */
|
|
45
|
+
private ownedRateLimitStore;
|
|
40
46
|
private health;
|
|
41
47
|
private errorHandler;
|
|
42
48
|
private constructor();
|
|
@@ -46,7 +52,44 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
46
52
|
/** @deprecated Use `getApp` instead. This is internal. */
|
|
47
53
|
static getInternalApp(options?: MeghApplicationOptions): MeghApplication;
|
|
48
54
|
useCors(options: CorsOptions): this;
|
|
55
|
+
/**
|
|
56
|
+
* Send security headers on every response: a Content Security Policy,
|
|
57
|
+
* HSTS, `X-Frame-Options`, `X-Content-Type-Options: nosniff` and more.
|
|
58
|
+
* Pass `false` for a header to leave it out. The API docs page from
|
|
59
|
+
* `useOpenApi()` keeps its own CSP.
|
|
60
|
+
*
|
|
61
|
+
* app.useSecurityHeaders()
|
|
62
|
+
* app.useSecurityHeaders({ contentSecurityPolicy: false })
|
|
63
|
+
* app.useSecurityHeaders({
|
|
64
|
+
* contentSecurityPolicy: { directives: { imgSrc: ["'self'", 'https://cdn.example.com'] } },
|
|
65
|
+
* })
|
|
66
|
+
*/
|
|
67
|
+
useSecurityHeaders(options?: SecurityHeadersOptions): this;
|
|
68
|
+
/**
|
|
69
|
+
* Limit how many requests each client can make per window, answering 429
|
|
70
|
+
* with `Retry-After` when it is over. Defaults to 100 a minute per IP,
|
|
71
|
+
* counted in memory. Give a route its own limit with `@RateLimit()`.
|
|
72
|
+
*
|
|
73
|
+
* app.useRateLimit()
|
|
74
|
+
* app.useRateLimit({ max: 300, window: '5m' })
|
|
75
|
+
* app.useRateLimit({ redis }) // share counts between replicas
|
|
76
|
+
*/
|
|
77
|
+
useRateLimit(options?: RateLimitOptions): this;
|
|
78
|
+
/** Install the rate limiter once routes are known. */
|
|
79
|
+
private installRateLimiting;
|
|
49
80
|
useCache(options?: CacheOptions): this;
|
|
81
|
+
/**
|
|
82
|
+
* Turn on mail: inject `Mailer` to send `Mailable`s. Settings come from
|
|
83
|
+
* `MEGH_MAIL_*` in `.env`; anything passed here overrides them.
|
|
84
|
+
*
|
|
85
|
+
* app.useMail()
|
|
86
|
+
* app.useMail({ from: 'hello@x.io', mailers: { audit: myTransport } })
|
|
87
|
+
* app.useMail(MailSettings) // an @AppConfig class returning MailConfig
|
|
88
|
+
*
|
|
89
|
+
* Throws at startup when the settings are invalid, e.g. in production with
|
|
90
|
+
* no mailer set.
|
|
91
|
+
*/
|
|
92
|
+
useMail(options?: MailConfig | Constructor<MeghConfig<MailConfig>>): this;
|
|
50
93
|
useMultipart(options?: any): this;
|
|
51
94
|
useOpenApi(options?: OpenApiUiOptions | Constructor<MeghConfig<OpenApiUiOptions>>): this;
|
|
52
95
|
private initSwagger;
|
|
@@ -122,7 +165,6 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
122
165
|
* It passes unless it throws, rejects or returns `false`.
|
|
123
166
|
*/
|
|
124
167
|
addHealthCheck(name: string, check: HealthCheck): this;
|
|
125
|
-
useSerialization(): this;
|
|
126
168
|
/**
|
|
127
169
|
* Register scheduled task classes.
|
|
128
170
|
*
|
|
@@ -137,7 +179,6 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
137
179
|
}): this;
|
|
138
180
|
useControllers(controllers: Constructor[] | AutoControllerOptions): this;
|
|
139
181
|
useStaticFiles(options?: any): this;
|
|
140
|
-
useHttps(options?: any): this;
|
|
141
182
|
useGlobal(options: GlobalOptions): this;
|
|
142
183
|
useSocketIo(options?: any): this;
|
|
143
184
|
/**
|
|
@@ -154,7 +195,6 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
154
195
|
useWorker(workers: Constructor<any>[]): this;
|
|
155
196
|
/** Close every registered worker, releasing their Redis connections. */
|
|
156
197
|
private _closeWorkers;
|
|
157
|
-
mapFeatures(): this;
|
|
158
198
|
/**
|
|
159
199
|
* True only when `NODE_ENV` is exactly `"development"`. An unset
|
|
160
200
|
* `NODE_ENV` counts as production, so dev-only features (API docs,
|
|
@@ -164,7 +204,6 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
164
204
|
private _mapControllers;
|
|
165
205
|
private _resolveControllerDir;
|
|
166
206
|
private autoControllers;
|
|
167
|
-
private _mapFeatures;
|
|
168
207
|
private handleSocket;
|
|
169
208
|
mapGet<T extends (...args: any[]) => any>(path: string | undefined, fn: T): {
|
|
170
209
|
useMiddleware: (middlewares: MeghMiddleware | Constructor<MeghMiddleware> | (MeghMiddleware | Constructor<MeghMiddleware>)[]) => /*elided*/ any;
|
|
@@ -172,6 +211,7 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
172
211
|
[key: string]: unknown;
|
|
173
212
|
name?: string;
|
|
174
213
|
} | undefined) => /*elided*/ any;
|
|
214
|
+
rateLimit: (options: import("../security/rate-limit").RouteRateLimitOptions | false) => /*elided*/ any;
|
|
175
215
|
useOpenApi: (options: import("../openapi/openapi").OpenApiOptions) => /*elided*/ any;
|
|
176
216
|
};
|
|
177
217
|
mapPost<T extends (...args: any[]) => any>(path: string | undefined, fn: T): {
|
|
@@ -180,6 +220,7 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
180
220
|
[key: string]: unknown;
|
|
181
221
|
name?: string;
|
|
182
222
|
} | undefined) => /*elided*/ any;
|
|
223
|
+
rateLimit: (options: import("../security/rate-limit").RouteRateLimitOptions | false) => /*elided*/ any;
|
|
183
224
|
useOpenApi: (options: import("../openapi/openapi").OpenApiOptions) => /*elided*/ any;
|
|
184
225
|
};
|
|
185
226
|
mapPut<T extends (...args: any[]) => any>(path: string | undefined, fn: T): {
|
|
@@ -188,6 +229,7 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
188
229
|
[key: string]: unknown;
|
|
189
230
|
name?: string;
|
|
190
231
|
} | undefined) => /*elided*/ any;
|
|
232
|
+
rateLimit: (options: import("../security/rate-limit").RouteRateLimitOptions | false) => /*elided*/ any;
|
|
191
233
|
useOpenApi: (options: import("../openapi/openapi").OpenApiOptions) => /*elided*/ any;
|
|
192
234
|
};
|
|
193
235
|
mapPatch<T extends (...args: any[]) => any>(path: string | undefined, fn: T): {
|
|
@@ -196,6 +238,7 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
196
238
|
[key: string]: unknown;
|
|
197
239
|
name?: string;
|
|
198
240
|
} | undefined) => /*elided*/ any;
|
|
241
|
+
rateLimit: (options: import("../security/rate-limit").RouteRateLimitOptions | false) => /*elided*/ any;
|
|
199
242
|
useOpenApi: (options: import("../openapi/openapi").OpenApiOptions) => /*elided*/ any;
|
|
200
243
|
};
|
|
201
244
|
mapDelete<T extends (...args: any[]) => any>(path: string | undefined, fn: T): {
|
|
@@ -204,6 +247,7 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
204
247
|
[key: string]: unknown;
|
|
205
248
|
name?: string;
|
|
206
249
|
} | undefined) => /*elided*/ any;
|
|
250
|
+
rateLimit: (options: import("../security/rate-limit").RouteRateLimitOptions | false) => /*elided*/ any;
|
|
207
251
|
useOpenApi: (options: import("../openapi/openapi").OpenApiOptions) => /*elided*/ any;
|
|
208
252
|
};
|
|
209
253
|
/**
|
|
@@ -235,8 +279,9 @@ export declare class MeghApplication implements IMeghApplication {
|
|
|
235
279
|
* await app.run(3000)
|
|
236
280
|
* await app.run(3000, { host: "127.0.0.1" })
|
|
237
281
|
*
|
|
238
|
-
* The
|
|
239
|
-
*
|
|
282
|
+
* The port defaults to the `PORT` environment variable, else `4000`. The
|
|
283
|
+
* host defaults to the `HOST` environment variable, else `0.0.0.0` so the
|
|
284
|
+
* app is reachable inside containers.
|
|
240
285
|
*/
|
|
241
286
|
run(port?: number, options?: RunOptions | CallableFunction): Promise<void>;
|
|
242
287
|
}
|