@adaptivestone/framework 5.4.1 → 5.5.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +42 -0
  3. package/dist/codegen/appTypes.d.ts +4 -5
  4. package/dist/codegen/appTypes.js +31 -22
  5. package/dist/codegen/appTypes.js.map +1 -1
  6. package/dist/codegen/index.d.ts +2 -2
  7. package/dist/codegen/index.js +3 -3
  8. package/dist/codegen/index.js.map +1 -1
  9. package/dist/commands/CreateEnv.d.ts +7 -0
  10. package/dist/commands/CreateEnv.js +36 -0
  11. package/dist/commands/CreateEnv.js.map +1 -0
  12. package/dist/commands/CreateUser.d.ts +5 -0
  13. package/dist/commands/CreateUser.js +13 -3
  14. package/dist/commands/CreateUser.js.map +1 -1
  15. package/dist/config/health.d.ts +4 -0
  16. package/dist/config/health.js +8 -0
  17. package/dist/config/health.js.map +1 -0
  18. package/dist/config/http.d.ts +1 -0
  19. package/dist/config/http.js +4 -0
  20. package/dist/config/http.js.map +1 -1
  21. package/dist/config/log.d.ts +2 -0
  22. package/dist/config/log.js +5 -0
  23. package/dist/config/log.js.map +1 -1
  24. package/dist/config/rateLimiter.js +1 -1
  25. package/dist/config/rateLimiter.js.map +1 -1
  26. package/dist/controllers/Auth.js +31 -34
  27. package/dist/controllers/Auth.js.map +1 -1
  28. package/dist/controllers/Health.d.ts +24 -0
  29. package/dist/controllers/Health.js +83 -0
  30. package/dist/controllers/Health.js.map +1 -0
  31. package/dist/controllers/Health.routes.gen.d.ts +13 -0
  32. package/dist/controllers/Health.routes.gen.js +10 -0
  33. package/dist/controllers/Health.routes.gen.js.map +1 -0
  34. package/dist/controllers/index.js +11 -7
  35. package/dist/controllers/index.js.map +1 -1
  36. package/dist/helpers/crypto.d.ts +19 -0
  37. package/dist/helpers/crypto.js +32 -1
  38. package/dist/helpers/crypto.js.map +1 -1
  39. package/dist/helpers/deprecation.d.ts +4 -3
  40. package/dist/helpers/deprecation.js +5 -4
  41. package/dist/helpers/deprecation.js.map +1 -1
  42. package/dist/helpers/files.d.ts +6 -1
  43. package/dist/helpers/files.js +2 -1
  44. package/dist/helpers/files.js.map +1 -1
  45. package/dist/helpers/objects.d.ts +5 -0
  46. package/dist/helpers/objects.js +12 -0
  47. package/dist/helpers/objects.js.map +1 -0
  48. package/dist/models/User.d.ts +4 -9
  49. package/dist/models/User.js +37 -10
  50. package/dist/models/User.js.map +1 -1
  51. package/dist/modules/AbstractController.d.ts +3 -3
  52. package/dist/modules/BaseModel.js.map +1 -1
  53. package/dist/server.d.ts +4 -0
  54. package/dist/server.js +19 -2
  55. package/dist/server.js.map +1 -1
  56. package/dist/services/cache/drivers/MemoryDriver.d.ts +5 -4
  57. package/dist/services/cache/drivers/MemoryDriver.js +41 -18
  58. package/dist/services/cache/drivers/MemoryDriver.js.map +1 -1
  59. package/dist/services/documentation/OpenApiGenerator.js +21 -3
  60. package/dist/services/documentation/OpenApiGenerator.js.map +1 -1
  61. package/dist/services/http/HttpServer.d.ts +19 -11
  62. package/dist/services/http/HttpServer.js +47 -27
  63. package/dist/services/http/HttpServer.js.map +1 -1
  64. package/dist/services/http/builtinErrorHandlers.d.ts +12 -2
  65. package/dist/services/http/builtinErrorHandlers.js +57 -9
  66. package/dist/services/http/builtinErrorHandlers.js.map +1 -1
  67. package/dist/services/http/httpErrors.d.ts +64 -11
  68. package/dist/services/http/httpErrors.js +42 -6
  69. package/dist/services/http/httpErrors.js.map +1 -1
  70. package/dist/services/http/middleware/AbstractMiddleware.d.ts +14 -6
  71. package/dist/services/http/middleware/AbstractMiddleware.js +20 -7
  72. package/dist/services/http/middleware/AbstractMiddleware.js.map +1 -1
  73. package/dist/services/http/middleware/Auth.d.ts +2 -1
  74. package/dist/services/http/middleware/Auth.js +9 -4
  75. package/dist/services/http/middleware/Auth.js.map +1 -1
  76. package/dist/services/http/middleware/Cors.d.ts +2 -0
  77. package/dist/services/http/middleware/Cors.js +9 -2
  78. package/dist/services/http/middleware/Cors.js.map +1 -1
  79. package/dist/services/http/middleware/GetUserByToken.d.ts +1 -1
  80. package/dist/services/http/middleware/GetUserByToken.js +2 -2
  81. package/dist/services/http/middleware/GetUserByToken.js.map +1 -1
  82. package/dist/services/http/middleware/I18n.js +11 -9
  83. package/dist/services/http/middleware/I18n.js.map +1 -1
  84. package/dist/services/http/middleware/Pagination.js +13 -11
  85. package/dist/services/http/middleware/Pagination.js.map +1 -1
  86. package/dist/services/http/middleware/RateLimiter.d.ts +2 -0
  87. package/dist/services/http/middleware/RateLimiter.js +42 -11
  88. package/dist/services/http/middleware/RateLimiter.js.map +1 -1
  89. package/dist/services/http/middleware/RequestLogger.js +10 -2
  90. package/dist/services/http/middleware/RequestLogger.js.map +1 -1
  91. package/dist/services/http/middleware/RequestParser.js +19 -5
  92. package/dist/services/http/middleware/RequestParser.js.map +1 -1
  93. package/dist/services/http/middleware/Role.d.ts +2 -1
  94. package/dist/services/http/middleware/Role.js +14 -5
  95. package/dist/services/http/middleware/Role.js.map +1 -1
  96. package/dist/services/http/routing/ExpressAdapter.js +7 -2
  97. package/dist/services/http/routing/ExpressAdapter.js.map +1 -1
  98. package/dist/services/http/routing/RouteNode.d.ts +7 -8
  99. package/dist/services/logging/redaction.d.ts +15 -0
  100. package/dist/services/logging/redaction.js +54 -0
  101. package/dist/services/logging/redaction.js.map +1 -0
  102. package/dist/services/validate/ValidateService.js +3 -27
  103. package/dist/services/validate/ValidateService.js.map +1 -1
  104. package/dist/services/validate/ValidationError.d.ts +10 -0
  105. package/dist/services/validate/ValidationError.js +28 -0
  106. package/dist/services/validate/ValidationError.js.map +1 -1
  107. package/dist/services/validate/mergeValidatedOutputs.d.ts +2 -6
  108. package/dist/services/validate/mergeValidatedOutputs.js +5 -12
  109. package/dist/services/validate/mergeValidatedOutputs.js.map +1 -1
  110. package/dist/tests/testHelpers.d.ts +111 -8
  111. package/package.json +9 -9
package/CHANGELOG.md CHANGED
@@ -6,6 +6,64 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [5.5.0] - 2026-10-03
10
+
11
+ ### Added
12
+
13
+ - **`hashSecret` / `verifySecret` for short codes.** E-mail login, SMS and reset codes are too short for `hashToken`: a leaked SHA-256 of a 6-digit code is reversed in under a second. `hashSecret(code, { purpose })` from `helpers/crypto.js` returns a base64url HMAC-SHA256 keyed from `AUTH_SALT`, so a leaked hash is useless without the secret, and `verifySecret(code, stored, { purpose })` checks a candidate in constant time. `purpose` names the feature; a hash made for one purpose never verifies under another. Rotating `AUTH_SALT` invalidates outstanding codes. Keep `hashToken` for long random tokens and `hashPassword` for passwords.
14
+ - **CORS can expose response headers to browser code.** Browsers hide every response header except a few basic ones from cross-origin JavaScript, so a web app could not read `Retry-After` on a 429. The new `http.corsExposedHeaders` config (and the `exposedHeaders` parameter of the `Cors` middleware) sends `Access-Control-Expose-Headers` on responses to allowed origins. It defaults to `['Retry-After']`; an app that sets its own array replaces the default, so keep `Retry-After` in it.
15
+ - **`HttpError` can carry an error code, a translation key and field errors.** Pass a details object instead of the message: `new ConflictError({ code: 'ALREADY_CONFIRMED', i18nKey: 'accounts.errors.alreadyConfirmed', message: 'Already confirmed.' })` answers `{ error: 'ALREADY_CONFIRMED', message }`, with the message translated from `i18nKey` when the request's locale has it and the English `message` otherwise. The `i18nKey` is never sent to the client, and the English text is used literally (never interpreted as i18next syntax). Field errors go in `errors` (`{ field: 'msg' | ['msg'] }`, or validation issues with `params`) and are answered exactly like request validation: `errors: { field: ['msg'] }`, with i18n-key messages translated. `code`, `i18nKey` and `errors` are optional and readable on the error (`err.code`, `err.i18nKey`, `err.issues`). For a fully custom response, pass `{ message, body }`: `body` is sent as-is, `message` only goes to the log, and `body` cannot be combined with `code`, `i18nKey` or `errors` (TypeScript rejects it; at runtime `body` wins and a one-time warning `ASF_HTTP_ERROR_BODY_MIXED` names the ignored fields). Handlers you register for `HttpError` classes still run first.
16
+ - **Built-in health endpoints.** `GET /health/live` answers `{ status: 'ok' }` whenever the process serves requests, and `GET /health/ready` also pings MongoDB (1 s timeout), answering 200 `{ status: 'ok', checks: { mongo: 'ok' } }` or 503 with `'error'` and no details. Point liveness probes at `/live` and readiness or deploy checks at `/ready`. Set `HEALTH_TOKEN` (`config/health.ts`) to require the token as an `X-Health-Token` header or `?token=` query parameter (for load balancers that cannot send headers); a missing or wrong token gets 401. Successful probes are no longer request-logged; failures are logged at `warn`. The endpoints come from a built-in `Health` controller: add your own `controllers/Health.ts` to extend or replace it. `GET /health` itself stays free, so an existing app route there keeps working.
17
+ - **`timingSafeEqualStrings(a, b)` compares secrets in constant time.** Exported from `helpers/crypto.js` for tokens, API keys or webhook secrets you check yourself: unlike `===`, its timing reveals neither where the strings differ nor the secret's length.
18
+ - **Log redaction, on by default.** Values of the log fields named in the new `redact` list of `config/log.ts` are replaced with `[REDACTED]` before any transport sees them (console, Sentry and custom transports), at any depth and in any letter case. The default list is `authorization`, `cookie`, `password`, `secret` and `token`, so `logger.info('Code sent', { email, token })` no longer writes the token. Message text is never rewritten, so pass sensitive values as fields rather than inside the message. Your own array replaces the default one, so keep these names when you add yours; `redact: []` turns redaction off. The caller's objects are not modified. The same `redact` setting carries over to the v6 logger.
19
+ - **`createEnv` CLI command.** `npm run cli createEnv` creates `.env` for a fresh clone: it copies `.env.example` and fills its `AUTH_SALT` line with a newly generated secret (or writes just `AUTH_SALT` when there is no example file). It does nothing when `.env` already exists, so it never overwrites secrets and is safe to run before every `dev` start. The secret is written to the file only, never printed or logged.
20
+ - **More framework responses can be translated.** The 404, 405 (`Method not allowed`), 415 (`Unsupported Content-Type`) and malformed-URL 400 texts now go through the request's translator, under `http.notFound`, `http.methodNotAllowed`, `http.unsupportedContentType` (with a `{{types}}` placeholder for the accepted content types) and `http.malformedUrl`. The built-in auth controller's messages also fall back to English when a request has no translator.
21
+ - **Unverified login has an error code.** The 400 for a correct password on an unverified account now carries `error: 'EMAIL_NOT_VERIFIED'`, so clients can branch on the code instead of a flag.
22
+ - **`HttpError` can set response headers.** Pass `headers` in the details object, for example `throw new HttpError(429, { message: 'Too Many Requests', headers: { 'Retry-After': '30' } })`. Your own error handlers can return `headers` next to `status` and `body` too.
23
+ - **Error codes on the role and rate-limit responses.** The `Role` 401 now carries `error: 'AUTH001'` (the same code as the `Auth` 401: the client has to log in), the `Role` 403 carries `error: 'NO_ACCESS'`, and the `RateLimiter` 429 carries `error: 'TOO_MANY_REQUESTS'`. Messages and status codes are unchanged.
24
+
25
+ ### Changed
26
+
27
+ - **Field-error responses always carry `message` and per-field arrays.** Request validation 400s and the Mongoose safety-net 400s now answer `{ message: 'Validation failed', errors: { field: ['msg'] } }`. Validation 400s gained `message` (translatable via `http.validationFailed`), and the safety nets also switched their values from a string to an array, matching validation. Clients reading `body.errors.<field>` as a string from a safety-net response must read the first array element; tests that compare whole bodies need the new `message`.
28
+ - **One text for every 500, and a readable 404.** Errors in a handler answered "Platform error. Please check later or contact support" while other server errors answered "Something broke!". Both now answer "Something went wrong. Please try again later." under the `http.serverError` key, so one translation covers every 500. The default 404 text is "Not found" instead of "404". Apps that translate `http.notFound` or `http.serverError` are unaffected.
29
+ - **Errors thrown in middleware go through the error-handler registry.** Before, any error from a middleware became a 500, even an `HttpError`. Now the final error handler resolves it the way it resolves handler errors: an `HttpError` answers with its own status and body, and handlers you register with `registerErrorHandler` apply. The built-in `Auth`, `Role` and `RateLimiter` middleware now throw `UnauthorizedError`, `ForbiddenError` and `HttpError(429)` instead of writing the response themselves. Clients get the same response (plus the new `error` codes above), and you can now reshape it, for example `registerErrorHandler(UnauthorizedError, …)` changes every 401 from `Auth`. If your tests call these middleware directly and inspect `res`, expect a thrown error instead.
30
+
31
+ ### Deprecated
32
+
33
+ - **Middleware `usedAuthParameters` is renamed to `authSchemes`.** The new name says what it declares: how requests send the credentials the middleware reads (a bearer token, an API-key header). The OpenAPI generator still reads a custom middleware that overrides only `usedAuthParameters`, with a one-time `DeprecationWarning` (`ASF_DEP_MW_USED_AUTH_PARAMETERS`), and `GetUserByToken.usedAuthParameters` still returns its schemes. The old name is removed in v6.
34
+ - **The positional `body` argument of `HttpError` and its subclasses.** Use the details object instead: `{ message, errors }` for field errors (`new HttpError(422, { message: 'Unprocessable', errors: { csv: 'row 17 malformed' } })`), or `{ message, body }` for a fully custom response. The old argument still works, logs a one-time `DeprecationWarning` per class (`ASF_DEP_HTTP_ERROR_BODY`), and is removed in v6. A plain message string (`new NotFoundError('Boat not found')`) is not deprecated.
35
+ - **`RateLimiter.gerenateConsumeKey` is renamed to `generateConsumeKey`.** The misspelled name still works and is removed in v6. A subclass that overrides the old name keeps its custom key and gets a one-time `DeprecationWarning` (`ASF_DEP_RATE_LIMITER_KEY_METHOD`).
36
+ - **`notVerified: true` in the unverified-login response.** Read `error === 'EMAIL_NOT_VERIFIED'` instead; the flag is removed in v6.
37
+
38
+ ### Fixed
39
+
40
+ - **OpenAPI no longer marks public routes as requiring a token.** Every route behind `GetUserByToken` was documented with a required `security`, including public ones such as login and register, so generated API clients demanded a token there. `GetUserByToken` only reads a token, so on its own it now documents auth as optional (`security: [{}, …]`, meaning anonymous requests are valid too). A route is documented as requiring auth when any middleware in its chain rejects requests without a user: the built-in `Auth` and `Role`, or your own middleware with the new `static get requiresAuth()` returning `true`. The schemes a middleware reads credentials from are now declared with `static get authSchemes()` (formerly `usedAuthParameters`).
41
+ - **Generated config types keep env keys that an app config spreads from a framework config.** An app `config/auth.ts` like `{ ...originalAuth, isAuthWithVerificationFlow: false }` lost `saltSecret` from its `getConfig('auth')` type whenever `AUTH_SALT` was unset during `generatetypes` (typically in CI), and kept it as `string` where it was set, so type checks passed locally and failed in CI. The generator now also reads the framework config file your config overrides and types such keys `string | undefined` in every environment; a key you give a value in your own file keeps that value's type. A `?? ''` fallback added only to keep the key in the type can be removed.
42
+ - **Spelling variants no longer get separate rate-limit budgets.** `consumeKeyComponents.request` keyed on the raw body, so with a per-e-mail limit (`ip: false, request: ['email']`) every variant such as `Foo@x.com`, `FOO@x.com` or ` foo@x.com` got a fresh budget while the app's lookup treated them as one account. Each configured field is now Unicode-normalized (NFKC), trimmed and lowercased; blank values and non-scalar values (objects, arrays) are ignored. Field names and values are hashed into the key, so values of different fields no longer share a bucket and request values (often e-mails) no longer appear in stored keys or the 429 log line. Upgrading resets existing counters for request-keyed limiters; finish the rollout across workers promptly. A normalizing middleware placed before `RateLimiter` for this purpose can be removed. For stricter rules (dots, `+tags`, accents), override `generateConsumeKey`.
43
+
44
+ ## [5.4.2] - 2026-10-01
45
+
46
+ ### Added
47
+
48
+ - **`createuser --token` prints a usable session token again.** Since 5.0.0 tokens are stored hashed and the command logs only identifiers, so the session it created on every run could never be used. Without the flag the command now creates no session; with `--token` it issues one and prints the raw token once to stdout, never to the logger.
49
+
50
+ ### Changed
51
+
52
+ - **Code generation now requires `oxc-parser` `^0.152.0`.** Projects that run `npm run gen` should update their optional development peer with `npm i -D oxc-parser@^0.152.0`. Runtime-only consumers do not need it.
53
+ - **Optional peers accept the new majors.** `@sentry/core` / `@sentry/node` accept `^10.34.0 || ^11.0.0` (Sentry 11 needs Node 20.19+), and `vitest` accepts `^4.0.0 || ^5.0.0` for the `setupVitest` helper. Existing installs keep working; no action needed.
54
+
55
+ ### Fixed
56
+
57
+ - **A login racing a password reset no longer gets a session.** `generateToken` now saves on the condition that the stored password hash is still the one on the document, so a login whose password check started before a reset answers "User/password not valid" instead of issuing a 30-day token for the old password. The 5.4.1 fix covered only logins that also upgraded the hash. Custom flows that call `generateToken` on a stale document now get a Mongoose `VersionError` (or `DocumentNotFoundError` with versioning disabled) instead of a session.
58
+ - **Concurrent logins and logouts no longer overwrite each other.** Issuing a token rewrote the whole session array whenever an expired token was stored, so two simultaneous logins failed one with a 500, and a logout landing during a login came back to life. Tokens are now appended atomically and expired ones removed with a separate update. Pending changes on the document are still saved with the token, as before.
59
+ - **A repeated `lng` query parameter no longer answers 500.** `?lng=a&lng=_` reached i18next as an array and failed every route with an error-level log. Non-string detector values are now ignored.
60
+ - **An unsupported language no longer stops language detection.** `X-Lang: de` with only `en`/`ru` configured ended detection with the fallback language, hiding a supported `?lng=ru`. Detection now continues to the next detector when the value's language is not in `i18n.supportedLngs`.
61
+ - **The HTTP server accepts connections only once the app is ready.** It used to listen from the `HttpServer` constructor, before controllers, `bootHttp`, the 404 page and the error handler were mounted, so early requests got Express's HTML 404. `startServer` now calls the new `httpServer.listen()` last and resolves after the port is bound.
62
+ - **In-memory cache entries with long TTLs no longer vanish.** A TTL above about 24.8 days overflowed Node's timer and the entry expired after 1 ms. Entries now store their expiry time, checked on every read.
63
+ - **An oversized streamed body gets a 413 instead of a connection reset.** The parser now stops reading and answers 413 with `Connection: close`; a body over the declared-length limit also closes the connection rather than being drained.
64
+ - **Pagination rejects pages that overflow.** A `page` of hundreds of digits parsed to `Infinity`; the query schema now reports it as not a number, and the middleware falls back to page 1 whenever `skip` would not be a safe integer.
65
+ - **CORS keeps other `Vary` values and always varies by `Origin`.** The middleware replaced any existing `Vary` header and set it only for allowed origins, so a shared cache could serve a response without the allow-origin header to an allowed origin.
66
+
9
67
  ## [5.4.1] - 2026-09-11
10
68
 
11
69
  ### Fixed
package/README.md CHANGED
@@ -70,6 +70,48 @@ To add the framework to an existing project instead:
70
70
  npm install @adaptivestone/framework
71
71
  ```
72
72
 
73
+ ## Upgrade notes (5.5.0)
74
+
75
+ See the [5.5.0 release notes](CHANGELOG.md) for everything new. Check these when
76
+ you upgrade:
77
+
78
+ - Logs are redacted by default: fields named `authorization`, `cookie`,
79
+ `password`, `secret` or `token` are written as `[REDACTED]`. Your own
80
+ `redact` list in `config/log.ts` replaces the default, so keep these names in
81
+ it; `redact: []` turns redaction off.
82
+ - A few error responses changed. Field-error 400s always carry `message` and
83
+ per-field arrays (safety-net `errors.<field>` used to be a string), every 500
84
+ has one text, the default 404 text is `Not found`, and the `Role` and
85
+ `RateLimiter` responses carry `error` codes. Tests that compare whole bodies
86
+ may need updating.
87
+ - Errors thrown in middleware go through the error-handler registry: an
88
+ `HttpError` from a middleware answers with its own status instead of a 500.
89
+ The built-in `Auth`, `Role` and `RateLimiter` now throw instead of writing
90
+ the response, so tests that call them directly must expect a thrown error.
91
+ - Built-in health endpoints answer at `/health/live` and `/health/ready`. Your
92
+ own `controllers/Health.ts` replaces them; `GET /health` itself stays free.
93
+ - Counters of request-keyed rate limits (`consumeKeyComponents.request`) reset
94
+ on deploy: their keys are now normalized and hashed.
95
+ - New: `npm run cli createEnv` creates `.env` with a fresh `AUTH_SALT` on a
96
+ fresh clone.
97
+ - Deprecated, removed in v6: `usedAuthParameters` (now `authSchemes`), the
98
+ positional `body` argument of `HttpError`, `RateLimiter.gerenateConsumeKey`,
99
+ and `notVerified` in the unverified-login response.
100
+
101
+ ## Upgrade notes (5.4.2)
102
+
103
+ See the [5.4.2 release notes](CHANGELOG.md) for all fixes. Most need no action:
104
+
105
+ - Projects that run `npm run gen` must update the optional peer:
106
+ `npm i -D oxc-parser@^0.152.0`.
107
+ - `user.generateToken()` now rejects with a Mongoose `VersionError` when the
108
+ stored password changed after the document was loaded; the built-in login
109
+ answers this like a wrong password. Custom login flows should do the same.
110
+ - The HTTP server opens its port only after routes, `bootHttp` and error
111
+ handlers are mounted; `startServer()` resolves once it is listening.
112
+ - `createuser --token` prints a usable session token; without the flag the
113
+ command no longer creates a session.
114
+
73
115
  ## Authentication and cache upgrade notes (5.4.1)
74
116
 
75
117
  See the [5.4.1 release notes](CHANGELOG.md) for all fixes, including model/validation
@@ -4,21 +4,20 @@
4
4
  * `getModel('Bar')` are typed against the project's actual config /
5
5
  * model files.
6
6
  */
7
- import type { IApp } from '../server.ts';
8
7
  /** Subset of the framework logger we use here. */
9
8
  export interface CodegenLogger {
10
9
  info?(msg: string): void;
11
10
  warn?(msg: string): void;
12
11
  error?(msg: string): void;
13
12
  }
14
- /** Generate the app-level `genTypes.d.ts` file. */
15
- export declare function generateAppTypes(app: IApp, logger?: CodegenLogger | null): Promise<void>;
16
13
  /** Render the `genTypes.d.ts` template text from config values + model paths.
17
14
  *
18
15
  * `configPaths` (config name → contributing source files) is optional: when
19
16
  * present, env-only keys dropped by the value pass are recovered from source
20
- * (see {@link valueToTypeString}). Omitted by unit tests that pass raw values. */
17
+ * (see {@link valueToTypeString}). Omitted by unit tests that pass raw values.
18
+ * `overriddenConfigPaths` (config name → framework files an app config
19
+ * replaced) supplies the fallback env shape for undefined spread keys. */
21
20
  export declare function getTemplate(configs: Map<string, unknown>, modelPaths: {
22
21
  file: string;
23
22
  path: string;
24
- }[], configPaths?: Map<string, string[]>): Promise<string>;
23
+ }[], configPaths?: Map<string, string[]>, overriddenConfigPaths?: Map<string, string[]>): Promise<string>;
@@ -4,8 +4,8 @@
4
4
  * `getModel('Bar')` are typed against the project's actual config /
5
5
  * model files.
6
6
  */
7
- import fs from 'node:fs/promises';
8
7
  import path from 'node:path';
8
+ import { isPlainObject } from '../helpers/objects.js';
9
9
  import { envShapeToType, extractConfigEnvShape, mergeEnvShapes, } from './astConfig.js';
10
10
  import { isBaseModelSource } from './astModel.js';
11
11
  import { sq } from './emit.js';
@@ -19,12 +19,6 @@ function toRelativeSpecifier(dir, target) {
19
19
  }
20
20
  return `./${rel.split(path.sep).join('/')}`;
21
21
  }
22
- /** Generate the app-level `genTypes.d.ts` file. */
23
- export async function generateAppTypes(app, logger) {
24
- const template = await getTemplate(app.internalFilesCache.configs, app.internalFilesCache.modelPaths, app.internalFilesCache.configPaths);
25
- await fs.writeFile(`${process.cwd()}/genTypes.d.ts`, template);
26
- logger?.info?.('TypeScript types generated successfully at genTypes.d.ts');
27
- }
28
22
  /**
29
23
  * Render a TypeScript type from a runtime config value's **shape** — value
30
24
  * *types* (`string`, `number`), never the literal values. This is emitted
@@ -41,8 +35,13 @@ export async function generateAppTypes(app, logger) {
41
35
  * whether or not the var happened to be set during codegen (deterministic
42
36
  * output, no `as` cast at the read site). Keys with a value at gen time and no
43
37
  * env-shape entry (literals, `process.env.X || default`) are typed from value.
38
+ *
39
+ * `fallback` is the env shape of the framework config an app config
40
+ * overrides. It fills ONLY keys whose value is `undefined` and that the app's
41
+ * own source does not read from env — e.g. `saltSecret` reaching the app
42
+ * through `...frameworkAuth`. A key with a value keeps its value type.
44
43
  */
45
- function valueToTypeString(value, env) {
44
+ function valueToTypeString(value, env, fallback) {
46
45
  if (value === null) {
47
46
  return 'null';
48
47
  }
@@ -71,8 +70,7 @@ function valueToTypeString(value, env) {
71
70
  : `[${itemTypes.join(', ')}]`;
72
71
  }
73
72
  // Only walk plain objects; anything exotic (Date, RegExp, Map, …) is opaque.
74
- const proto = Object.getPrototypeOf(value);
75
- if (proto !== Object.prototype && proto !== null) {
73
+ if (!isPlainObject(value)) {
76
74
  return 'unknown';
77
75
  }
78
76
  const rendered = new Map();
@@ -93,10 +91,14 @@ function valueToTypeString(value, env) {
93
91
  rendered.set(k, e);
94
92
  continue;
95
93
  }
94
+ const f = fallback?.[k];
96
95
  if (v === undefined) {
97
- continue; // recovered from a nested `env` shape below, if any
96
+ if (typeof f === 'string') {
97
+ rendered.set(k, f);
98
+ }
99
+ continue; // else recovered from a nested `env` shape below, if any
98
100
  }
99
- rendered.set(k, valueToTypeString(v, typeof e === 'object' ? e : undefined));
101
+ rendered.set(k, valueToTypeString(v, typeof e === 'object' ? e : undefined, typeof f === 'object' ? f : undefined));
100
102
  }
101
103
  // Recover env-only keys that never appeared in the value (dropped because
102
104
  // `undefined` at gen time, or a wholly env-only sub-object) — typed from
@@ -125,19 +127,26 @@ function valueToTypeString(value, env) {
125
127
  *
126
128
  * `configPaths` (config name → contributing source files) is optional: when
127
129
  * present, env-only keys dropped by the value pass are recovered from source
128
- * (see {@link valueToTypeString}). Omitted by unit tests that pass raw values. */
129
- export async function getTemplate(configs, modelPaths, configPaths) {
130
+ * (see {@link valueToTypeString}). Omitted by unit tests that pass raw values.
131
+ * `overriddenConfigPaths` (config name → framework files an app config
132
+ * replaced) supplies the fallback env shape for undefined spread keys. */
133
+ export async function getTemplate(configs, modelPaths, configPaths, overriddenConfigPaths) {
130
134
  const dir = process.cwd();
131
135
  // Parse each config's source(s) once for env-only keys (no value import).
132
- const envByConfig = new Map();
133
- if (configPaths) {
134
- await Promise.all(Array.from(configPaths, async ([name, paths]) => {
135
- const shapes = await Promise.all(paths.map(extractConfigEnvShape));
136
- envByConfig.set(name, mergeEnvShapes(shapes));
137
- }));
138
- }
136
+ const envShapes = async (pathsByConfig) => {
137
+ const byConfig = new Map();
138
+ if (pathsByConfig) {
139
+ await Promise.all(Array.from(pathsByConfig, async ([name, paths]) => {
140
+ const shapes = await Promise.all(paths.map(extractConfigEnvShape));
141
+ byConfig.set(name, mergeEnvShapes(shapes));
142
+ }));
143
+ }
144
+ return byConfig;
145
+ };
146
+ const envByConfig = await envShapes(configPaths);
147
+ const fallbackByConfig = await envShapes(overriddenConfigPaths);
139
148
  const configTypes = Array.from(configs)
140
- .map(([name, value]) => ` getConfig(configName: ${sq(name)}): ${valueToTypeString(value, envByConfig.get(name))};`)
149
+ .map(([name, value]) => ` getConfig(configName: ${sq(name)}): ${valueToTypeString(value, envByConfig.get(name), fallbackByConfig.get(name))};`)
141
150
  .join('\n');
142
151
  // Detect `BaseModel` subclasses by parsing each model's source (no runtime
143
152
  // import — codegen never loads the model graph / Mongoose). Result drives both
@@ -1 +1 @@
1
- {"version":3,"file":"appTypes.js","sourceRoot":"","sources":["../../src/codegen/appTypes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAEL,cAAc,EACd,qBAAqB,EACrB,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAE/B;;kFAEkF;AAClF,SAAS,mBAAmB,CAAC,GAAW,EAAE,MAAc;IACtD,MAAM,GAAG,GA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I,EAAE,SAAS,CAAC,IAAI;QACpB,OAAO,EAAE,mBAAmB,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,CAAC;QACjD,WAAW,EAAE,MAAM,iBAAiB,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,UAAU,CAAC;KACpE,CAAC,CAAC,CACJ,CAAC;IAEF,MAAM,UAAU,GAAG,MAAM;SACtB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,SAAS,GAAG,CAAC,CAAC,WAAW;YAC7B,CAAC,CAAC,uCAAuC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY;YAClE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,4BAA4B,CAAC;QACxD,OAAO,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,SAAS,GAAG,CAAC;IAC5C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,+EAA+E;IAC/E,2EAA2E;IAC3E,6EAA6E;IAC7E,2EAA2E;IAC3E,mCAAmC;IACnC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC;IACzE,MAAM,WAAW,GAAG,SAAS;QAC3B,CAAC,CAAC;;;6DAGuD,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC;;;CAGjF;QACG,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;;;;;;QAMD,UAAU;;;;QAIV,WAAW;;;EAGjB,WAAW,EAAE,CAAC;AAChB,CAAC"}
@@ -8,10 +8,10 @@
8
8
  * - `<File>.routes.gen.ts` next to each controller (handler request shapes)
9
9
  */
10
10
  import type { IApp } from '../server.ts';
11
- import { type CodegenLogger, generateAppTypes } from './appTypes.ts';
11
+ import { type CodegenLogger } from './appTypes.ts';
12
12
  import { generateRouteTypesViaAst } from './astEmit.ts';
13
13
  export type { CodegenLogger };
14
- export { generateAppTypes, generateRouteTypesViaAst };
14
+ export { generateRouteTypesViaAst };
15
15
  export interface GenerateAllOptions {
16
16
  /** Verify-only (CI drift guard): compare rendered output against disk, write
17
17
  * nothing, throw (non-zero exit) on any missing/stale/orphan file. */
@@ -9,9 +9,9 @@
9
9
  */
10
10
  import fs from 'node:fs/promises';
11
11
  import path from 'node:path';
12
- import { generateAppTypes, getTemplate, } from './appTypes.js';
12
+ import { getTemplate } from './appTypes.js';
13
13
  import { deleteOrphans, generateRouteTypesViaAst, planRouteTypes, writePlanned, } from './astEmit.js';
14
- export { generateAppTypes, generateRouteTypesViaAst };
14
+ export { generateRouteTypesViaAst };
15
15
  /**
16
16
  * Generate both app-level and per-controller route types from the AST front-end
17
17
  * — no app boot, no model imports. A controller whose `routes` / `middleware` /
@@ -27,7 +27,7 @@ export { generateAppTypes, generateRouteTypesViaAst };
27
27
  */
28
28
  export async function generateAll(app, logger, options = {}) {
29
29
  // 1. Analyze everything first (pure text, no writes).
30
- const appTypesText = await getTemplate(app.internalFilesCache.configs, app.internalFilesCache.modelPaths, app.internalFilesCache.configPaths);
30
+ const appTypesText = await getTemplate(app.internalFilesCache.configs, app.internalFilesCache.modelPaths, app.internalFilesCache.configPaths, app.internalFilesCache.overriddenConfigPaths);
31
31
  const plan = await planRouteTypes(app, logger, { skipNonAnalyzable: true });
32
32
  if (plan.needsBoot.length > 0) {
33
33
  const names = plan.needsBoot.map((p) => path.basename(p)).join(', ');
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAEL,gBAAgB,EAChB,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,aAAa,EACb,wBAAwB,EAExB,cAAc,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F;AAClF,KAAK,UAAU,YAAY,CACzB,OAAwB,EACxB,OAAiB;IAEjB,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,OAAO,EAAE,CAAC;QACxC,IAAI,MAAM,GAAkB,IAAI,CAAC;QACjC,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,KAAK,CAAC,IAAI,CAAC,cAAc,OAAO,EAAE,CAAC,CAAC;QACtC,CAAC;aAAM,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YAC3B,KAAK,CAAC,IAAI,CAAC,cAAc,OAAO,EAAE,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,cAAc,MAAM,EAAE,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,7 @@
1
+ import AbstractCommand from '../modules/AbstractCommand.ts';
2
+ declare class CreateEnv extends AbstractCommand {
3
+ static get description(): string;
4
+ static isShouldInitModels: boolean;
5
+ run(): Promise<boolean>;
6
+ }
7
+ export default CreateEnv;
@@ -0,0 +1,36 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { existsSync } from 'node:fs';
3
+ import { readFile, writeFile } from 'node:fs/promises';
4
+ import AbstractCommand from '../modules/AbstractCommand.js';
5
+ const ENV_FILE = '.env';
6
+ const EXAMPLE_FILE = '.env.example';
7
+ const SALT_LINE = /^AUTH_SALT=.*$/m;
8
+ class CreateEnv extends AbstractCommand {
9
+ static get description() {
10
+ return 'Create .env from .env.example with a fresh AUTH_SALT. Does nothing if .env already exists.';
11
+ }
12
+ static isShouldInitModels = false;
13
+ async run() {
14
+ if (existsSync(ENV_FILE)) {
15
+ this.logger?.info(`${ENV_FILE} already exists, nothing changed.`);
16
+ return true;
17
+ }
18
+ const salt = `AUTH_SALT=${randomBytes(32).toString('hex')}`;
19
+ const hasExample = existsSync(EXAMPLE_FILE);
20
+ let contents = hasExample ? await readFile(EXAMPLE_FILE, 'utf8') : '';
21
+ if (SALT_LINE.test(contents)) {
22
+ contents = contents.replace(SALT_LINE, () => salt);
23
+ }
24
+ else {
25
+ const separator = contents === '' || contents.endsWith('\n') ? '' : '\n';
26
+ contents += `${separator}${salt}\n`;
27
+ }
28
+ // `wx`: never overwrite a .env that appeared in the meantime.
29
+ await writeFile(ENV_FILE, contents, { flag: 'wx' });
30
+ // The salt is a secret: report the file, never the value.
31
+ this.logger?.info(`Created ${ENV_FILE}${hasExample ? ` from ${EXAMPLE_FILE}` : ''} with a new AUTH_SALT.`);
32
+ return true;
33
+ }
34
+ }
35
+ export default CreateEnv;
36
+ //# sourceMappingURL=CreateEnv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateEnv.js","sourceRoot":"","sources":["../../src/commands/CreateEnv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,eAAe,MAAM,+BAA+B,CAAC;AAE5D,MAAM,QAAQ,GAAG,MAAM,CAAC;AACxB,MAAM,YAAY,GAAG,cAAc,CAAC;AACpC,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAEpC,MAAM,SAAU,SAAQ,eAAe;IACrC,MAAM,KAAK,WAAW;QACpB,OAAO,4FAA4F,CAAC;IACtG,CAAC;IAED,MAAM,CAAC,kBAAkB,GAAG,KAAK,CAAC;IAElC,KAAK,CA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description: 'Update user if it exists';
28
28
  };
29
+ readonly token: {
30
+ readonly type: 'boolean';
31
+ readonly default: false;
32
+ readonly description: 'Issue a 30-day session and print its token once (to stdout, not the log)';
33
+ };
29
34
  };
30
35
  run(): Promise<boolean>;
31
36
  }
@@ -1,5 +1,5 @@
1
1
  import AbstractCommand, {} from '../modules/AbstractCommand.js';
2
- // Example: node src/cli createuser --email=somemail@gmail.com --password=somePassword --roles=user,admin,someOtherRoles
2
+ // Example: node src/cli createuser --email=somemail@gmail.com --password=somePassword --roles=user,admin,someOtherRoles --token
3
3
  class CreateUser extends AbstractCommand {
4
4
  static get description() {
5
5
  return 'Create user in a database';
@@ -30,11 +30,16 @@ class CreateUser extends AbstractCommand {
30
30
  default: false,
31
31
  description: 'Update user if it exists',
32
32
  },
33
+ token: {
34
+ type: 'boolean',
35
+ default: false,
36
+ description: 'Issue a 30-day session and print its token once (to stdout, not the log)',
37
+ },
33
38
  };
34
39
  }
35
40
  async run() {
36
41
  const User = this.app.getModel('User');
37
- const { id, email, password, roles, update } = this
42
+ const { id, email, password, roles, update, token } = this
38
43
  .args;
39
44
  if (!email && !id) {
40
45
  this.logger?.error('Input validation failded');
@@ -74,10 +79,15 @@ class CreateUser extends AbstractCommand {
74
79
  user.set('roles', roles.split(','));
75
80
  }
76
81
  await user.save();
77
- await user.generateToken();
78
82
  // Log identifiers only — serializing the document leaks the password hash
79
83
  // and all session/recovery/verification tokens.
80
84
  this.logger?.info(`User was created/updated: id=${user.id}, email=${user.email}, nick=${user.name?.nick ?? ''}`);
85
+ if (token) {
86
+ const session = await user.generateToken();
87
+ // The raw token exists only here (the database keeps its hash), so print
88
+ // it once — to stdout, never the logger, whose transports may ship it.
89
+ console.log(`Session token (valid until ${session.valid.toISOString()}): ${session.token}`);
90
+ }
81
91
  return true;
82
92
  }
83
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CreateUser.js","sourceRoot":"","sources":["../../src/commands/CreateUser.ts"],"names":[],"mappings":"AACA,OAAO,e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AAC,MAAM,EAAE,IAAI,CACf,gCAAgC,IAAI,CAAC,EAAE,WAAW,IAAI,CAAC,KAAK,UAC1D,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,EACrB,EAAE,CACH,CAAC;QAEF,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YAC3C,yEAAyE;YACzE,uEAAuE;YACvE,OAAO,CAAC,GAAG,CACT,8BAA8B,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,MAAM,OAAO,CAAC,KAAK,EAAE,CAC/E,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,eAAe,UAAU,CAAC"}
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ token: string | undefined;
3
+ };
4
+ export default _default;
@@ -0,0 +1,8 @@
1
+ export default {
2
+ // Optional shared secret for the health endpoints (`/health/live`,
3
+ // `/health/ready`). Unset (the default) leaves them open. When set, probes
4
+ // send it in the `X-Health-Token` header (preferred) or as `?token=` for load
5
+ // balancers that cannot send headers (e.g. AWS ALB health checks).
6
+ token: process.env.HEALTH_TOKEN,
7
+ };
8
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/config/health.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,mEAAmE;IACnE,2EAA2E;IAC3E,8EAA8E;IAC9E,mEAAmE;IACnE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,YAAkC;CACtD,CAAC"}
@@ -2,6 +2,7 @@ declare const _default: {
2
2
  port: string | number;
3
3
  hostname: string;
4
4
  corsDomains: string[];
5
+ corsExposedHeaders: string[];
5
6
  myDomain: string;
6
7
  siteDomain: string;
7
8
  securityHeaders: {
@@ -7,6 +7,10 @@ export default {
7
7
  // `/example\.com/` also matches evil-example.com and example.com.attacker.io.
8
8
  // `corsDomains: [/./]` reflects EVERY origin — dangerous, dev-only.
9
9
  corsDomains: ['http://localhost:3000'],
10
+ // Response headers that browser code on those origins may read (CORS hides
11
+ // all but a few basic ones). `Retry-After` lets a web app show the rate
12
+ // limiter's wait time. Your own array REPLACES this one — keep 'Retry-After'.
13
+ corsExposedHeaders: ['Retry-After'],
10
14
  myDomain: process.env.HTTP_DOMAIN || 'http://localhost:3300',
11
15
  siteDomain: process.env.FRONT_DOMAIN || 'http://localhost:3000',
12
16
  // Standard security response headers, applied to every response (set a value
@@ -1 +1 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/config/http.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,IAAI;IACnC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,SAAS;IAC5C,sEAAsE;IACtE,0EAA0E;IAC1E,+EAA+E;IAC/E,8EAA8E;IAC9E,oEAAoE;IACpE,WAAW,EAAE,CAAC,uBAAuB,CAAC;IACtC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,uBAAuB;IAC5D,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,uBAAuB;IAC/D,6EAA6E;IAC7E,8EAA8E;IAC9E,eAAe;IACf,eAAe,EAAE;QACf,OAAO,EAAE,IAAI;QACb,wBAAwB,EAAE,SAAS;QACnC,iBAAiB,EAAE,MAAM;QACzB,iBAAiB,EAAE,aAAa;QAChC,0EAA0E;QAC1E,6CAA6C;QAC7C,2EAA2E;QAC3E,2BAA2B,EAAE,IAAqB;KACnD;IACD,uEAAuE;IACvE,8EAA8E;IAC9E,yEAAyE;IACzE,0CAA0C;IAC1C,uEAAuE;IACvE,6EAA6E;IAC7E,yEAAyE;IACzE,aAAa,EAAE;QACb,WAAW,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,iBAAiB;QAChD,gBAAgB,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,E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C,GAAG,IAAI,GAAG,IAAI,EAAE,8CAA8C;KAC/E;CACF,CAAC"}
@@ -6,6 +6,8 @@ export type TLogConfig = {
6
6
  } & Record<string, unknown>;
7
7
  enable: boolean;
8
8
  }[];
9
+ /** Field names whose values are replaced before any transport (any depth, any case). */
10
+ redact?: string[];
9
11
  };
10
12
  declare const _default: TLogConfig;
11
13
  export default _default;
@@ -17,5 +17,10 @@ export default {
17
17
  enable: envBool('LOGGER_CONSOLE_ENABLE', true),
18
18
  },
19
19
  ],
20
+ // Log fields whose values are replaced with [REDACTED] before reaching any
21
+ // transport, at any depth and in any letter case. Message text is never
22
+ // rewritten, so pass sensitive values as fields. Your own array replaces
23
+ // this one; keep these names and add yours. `[]` turns redaction off.
24
+ redact: ['authorization', 'cookie', 'password', 'secret', 'token'],
20
25
  };
21
26
  //# sourceMappingURL=log.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/config/log.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAY5C,eAAe;IACb,UAAU,EAAE;QACV;YACE,SAAS,EAAE,QAAQ;YACnB,gBAAgB,EAAE;gBAChB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,MAAM;aACZ;YACtC,MAAM,EAAE,OAAO,CAAC,sBAAsB,EAAE,KAAK,CAAC;SAC/C;QACD;YACE,SAAS,EAAE,SAAS;YACpB,gBAAgB,EAAE;gBAChB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,OAAO;gBAClD,SAAS,EAAE,IAAI;aACsB;YACvC,MAAM,EAAE,OAAO,CAAC,uBAAuB,EAAE,IAAI,CAAC;SAC/C;KACF;CACY,CAAC"}
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/config/log.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAc5C,eAAe;IACb,UAAU,EAAE;QACV;YACE,SAAS,EAAE,QAAQ;YACnB,gBAAgB,EAAE;gBAChB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,MAAM;aACZ;YACtC,MAAM,EAAE,OAAO,CAAC,sBAAsB,EAAE,KAAK,CAAC;SAC/C;QACD;YACE,SAAS,EAAE,SAAS;YACpB,gBAAgB,EAAE;gBAChB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,OAAO;gBAClD,SAAS,EAAE,IAAI;aACsB;YACvC,MAAM,EAAE,OAAO,CAAC,uBAAuB,EAAE,IAAI,CAAC;SAC/C;KACF;IACD,2EAA2E;IAC3E,wEAAwE;IACxE,yEAAyE;IACzE,sEAAsE;IACtE,MAAM,EAAE,CAAC,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,CAAC;CACrD,CAAC"}
@@ -11,7 +11,7 @@ export default {
11
11
  ip: true, // include ip to key generation
12
12
  route: true, // include route to key generation
13
13
  user: true, // include user id to key generation (if user exits)
14
- request: [], // what should be included from request (req.appInfo.request) if it presented
14
+ request: [], // req.body fields to include (raw, before validation); values are case-folded and hashed
15
15
  },
16
16
  };
17
17
  //# sourceMappingURL=rateLimiter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rateLimiter.js","sourceRoot":"","sources":["../../src/config/rateLimiter.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,cAAc,EAAE;QACd,uDAAuD;QACvD,oEAAoE;QACpE,MAAM,EAAE,EAAE,EAAE,YAAY;QACxB,QAAQ,EAAE,EAAE,EAAE,iBAAiB;KACT;IACxB,MAAM,EAAE,OAAO,EAAE,0BAA0B;IAC3C,aAAa,EAAE,CAAC;IAChB,oBAAoB,EAAE;QACpB,EAAE,EAAE,IAAI,EAAE,+BAA+B;QACzC,KAAK,EAAE,IAAI,EAAE,kCAAkC;QAC/C,IAAI,EAAE,IAAI,EAAE,oDAAoD;QAChE,OAAO,EAAE,EAAE,EAAE,6EAA6E;KAC3F;CACF,CAAC"}
1
+ {"version":3,"file":"rateLimiter.js","sourceRoot":"","sources":["../../src/config/rateLimiter.ts"],"names":[],"mappings":"AAEA,eAAe;IACb,cAAc,EAAE;QACd,uDAAuD;QACvD,oEAAoE;QACpE,MAAM,EAAE,EAAE,EAAE,YAAY;QACxB,QAAQ,EAAE,EAAE,EAAE,iBAAiB;KACT;IACxB,MAAM,EAAE,OAAO,EAAE,0BAA0B;IAC3C,aAAa,EAAE,CAAC;IAChB,oBAAoB,EAAE;QACpB,EAAE,EAAE,IAAI,EAAE,+BAA+B;QACzC,KAAK,EAAE,IAAI,EAAE,kCAAkC;QAC/C,IAAI,EAAE,IAAI,EAAE,oDAAoD;QAChE,OAAO,EAAE,EAAE,EAAE,yFAAyF;KACvG;CACF,CAAC"}