@adaptivestone/framework 5.4.2 → 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 (94) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +28 -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/config/health.d.ts +4 -0
  13. package/dist/config/health.js +8 -0
  14. package/dist/config/health.js.map +1 -0
  15. package/dist/config/http.d.ts +1 -0
  16. package/dist/config/http.js +4 -0
  17. package/dist/config/http.js.map +1 -1
  18. package/dist/config/log.d.ts +2 -0
  19. package/dist/config/log.js +5 -0
  20. package/dist/config/log.js.map +1 -1
  21. package/dist/config/rateLimiter.js +1 -1
  22. package/dist/config/rateLimiter.js.map +1 -1
  23. package/dist/controllers/Auth.js +15 -36
  24. package/dist/controllers/Auth.js.map +1 -1
  25. package/dist/controllers/Health.d.ts +24 -0
  26. package/dist/controllers/Health.js +83 -0
  27. package/dist/controllers/Health.js.map +1 -0
  28. package/dist/controllers/Health.routes.gen.d.ts +13 -0
  29. package/dist/controllers/Health.routes.gen.js +10 -0
  30. package/dist/controllers/Health.routes.gen.js.map +1 -0
  31. package/dist/controllers/index.js +11 -7
  32. package/dist/controllers/index.js.map +1 -1
  33. package/dist/helpers/crypto.d.ts +19 -0
  34. package/dist/helpers/crypto.js +32 -1
  35. package/dist/helpers/crypto.js.map +1 -1
  36. package/dist/helpers/deprecation.d.ts +4 -3
  37. package/dist/helpers/deprecation.js +5 -4
  38. package/dist/helpers/deprecation.js.map +1 -1
  39. package/dist/helpers/files.d.ts +6 -1
  40. package/dist/helpers/files.js +2 -1
  41. package/dist/helpers/files.js.map +1 -1
  42. package/dist/helpers/objects.d.ts +5 -0
  43. package/dist/helpers/objects.js +12 -0
  44. package/dist/helpers/objects.js.map +1 -0
  45. package/dist/modules/AbstractController.d.ts +3 -3
  46. package/dist/server.d.ts +4 -0
  47. package/dist/server.js +16 -2
  48. package/dist/server.js.map +1 -1
  49. package/dist/services/documentation/OpenApiGenerator.js +21 -3
  50. package/dist/services/documentation/OpenApiGenerator.js.map +1 -1
  51. package/dist/services/http/HttpServer.d.ts +13 -11
  52. package/dist/services/http/HttpServer.js +27 -18
  53. package/dist/services/http/HttpServer.js.map +1 -1
  54. package/dist/services/http/builtinErrorHandlers.d.ts +12 -2
  55. package/dist/services/http/builtinErrorHandlers.js +57 -9
  56. package/dist/services/http/builtinErrorHandlers.js.map +1 -1
  57. package/dist/services/http/httpErrors.d.ts +64 -11
  58. package/dist/services/http/httpErrors.js +42 -6
  59. package/dist/services/http/httpErrors.js.map +1 -1
  60. package/dist/services/http/middleware/AbstractMiddleware.d.ts +14 -6
  61. package/dist/services/http/middleware/AbstractMiddleware.js +20 -7
  62. package/dist/services/http/middleware/AbstractMiddleware.js.map +1 -1
  63. package/dist/services/http/middleware/Auth.d.ts +2 -1
  64. package/dist/services/http/middleware/Auth.js +9 -4
  65. package/dist/services/http/middleware/Auth.js.map +1 -1
  66. package/dist/services/http/middleware/Cors.d.ts +2 -0
  67. package/dist/services/http/middleware/Cors.js +5 -0
  68. package/dist/services/http/middleware/Cors.js.map +1 -1
  69. package/dist/services/http/middleware/GetUserByToken.d.ts +1 -1
  70. package/dist/services/http/middleware/GetUserByToken.js +2 -2
  71. package/dist/services/http/middleware/GetUserByToken.js.map +1 -1
  72. package/dist/services/http/middleware/RateLimiter.d.ts +2 -0
  73. package/dist/services/http/middleware/RateLimiter.js +42 -11
  74. package/dist/services/http/middleware/RateLimiter.js.map +1 -1
  75. package/dist/services/http/middleware/RequestLogger.js +10 -2
  76. package/dist/services/http/middleware/RequestLogger.js.map +1 -1
  77. package/dist/services/http/middleware/Role.d.ts +2 -1
  78. package/dist/services/http/middleware/Role.js +14 -5
  79. package/dist/services/http/middleware/Role.js.map +1 -1
  80. package/dist/services/http/routing/ExpressAdapter.js +7 -2
  81. package/dist/services/http/routing/ExpressAdapter.js.map +1 -1
  82. package/dist/services/http/routing/RouteNode.d.ts +7 -8
  83. package/dist/services/logging/redaction.d.ts +15 -0
  84. package/dist/services/logging/redaction.js +54 -0
  85. package/dist/services/logging/redaction.js.map +1 -0
  86. package/dist/services/validate/ValidateService.js +3 -27
  87. package/dist/services/validate/ValidateService.js.map +1 -1
  88. package/dist/services/validate/ValidationError.d.ts +10 -0
  89. package/dist/services/validate/ValidationError.js +28 -0
  90. package/dist/services/validate/ValidationError.js.map +1 -1
  91. package/dist/services/validate/mergeValidatedOutputs.d.ts +2 -6
  92. package/dist/services/validate/mergeValidatedOutputs.js +5 -12
  93. package/dist/services/validate/mergeValidatedOutputs.js.map +1 -1
  94. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -6,6 +6,41 @@ 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
+
9
44
  ## [5.4.2] - 2026-10-01
10
45
 
11
46
  ### Added
package/README.md CHANGED
@@ -70,6 +70,34 @@ 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
+
73
101
  ## Upgrade notes (5.4.2)
74
102
 
75
103
  See the [5.4.2 release notes](CHANGELOG.md) for all fixes. Most need no action:
@@ -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,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,GAA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S,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,EACd,YAAY,GACb,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,gBAAgB,EAAE,wBAAwB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Aa,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,CAAC,GAAG;QACP,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,QAAQ,mCAAmC,CAAC,CAAC;YAClE,OAAO,IAAI,CAAC;QACd,CAAC;QACD,MAAM,IAAI,GAAG,aAAa,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5D,MAAM,UAAU,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtE,IAAI,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,MAAM,SAAS,GAAG,QAAQ,KAAK,EAAE,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YACzE,QAAQ,IAAI,GAAG,SAAS,GAAG,IAAI,IAAI,CAAC;QACtC,CAAC;QACD,8DAA8D;QAC9D,MAAM,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,0DAA0D;QAC1D,IAAI,CAAC,MAAM,EAAE,IAAI,CACf,WAAW,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,wBAAwB,CACxF,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,eAAe,SAAS,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,WAA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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,EAAE,yBAAyB;QAC7D,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,CAAC,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"}
@@ -1,4 +1,5 @@
1
1
  import mongoose from 'mongoose';
2
+ import { translateWithDefault } from '../helpers/translate.js';
2
3
  import { hashToken } from '../models/User.js';
3
4
  import AbstractController from '../modules/AbstractController.js';
4
5
  import GetUserByToken from '../services/http/middleware/GetUserByToken.js';
@@ -270,9 +271,7 @@ class Auth extends AbstractController {
270
271
  req.appInfo.request.password);
271
272
  if (!userResult) {
272
273
  return res.status(400).json({
273
- message: req.appInfo.i18n?.t('auth.errorUPValid', {
274
- defaultValue: EN['auth.errorUPValid'],
275
- }),
274
+ message: translateWithDefault(req, 'auth.errorUPValid', EN['auth.errorUPValid']),
276
275
  });
277
276
  }
278
277
  // TypeScript now knows userResult is not false, so it has the instance methods
@@ -280,9 +279,9 @@ class Auth extends AbstractController {
280
279
  const isAuthWithVerificationFlow = isVerificationFlowEnabled(this.app.getConfig('auth'));
281
280
  if (isAuthWithVerificationFlow && !user.isVerified) {
282
281
  return res.status(400).json({
283
- message: req.appInfo.i18n?.t('email.notVerified', {
284
- defaultValue: EN['email.notVerified'],
285
- }),
282
+ error: 'EMAIL_NOT_VERIFIED',
283
+ message: translateWithDefault(req, 'email.notVerified', EN['email.notVerified']),
284
+ // @deprecated in favor of `error`; removed in v6.
286
285
  notVerified: true,
287
286
  });
288
287
  }
@@ -297,9 +296,7 @@ class Auth extends AbstractController {
297
296
  if (err instanceof mongoose.Error.VersionError ||
298
297
  err instanceof mongoose.Error.DocumentNotFoundError) {
299
298
  return res.status(400).json({
300
- message: req.appInfo.i18n?.t('auth.errorUPValid', {
301
- defaultValue: EN['auth.errorUPValid'],
302
- }),
299
+ message: translateWithDefault(req, 'auth.errorUPValid', EN['auth.errorUPValid']),
303
300
  });
304
301
  }
305
302
  throw err;
@@ -316,9 +313,7 @@ class Auth extends AbstractController {
316
313
  let user = (await User.getUserByEmail(req.appInfo.request.email));
317
314
  if (user) {
318
315
  return res.status(400).json({
319
- message: req.appInfo.i18n?.t('email.registered', {
320
- defaultValue: EN['email.registered'],
321
- }),
316
+ message: translateWithDefault(req, 'email.registered', EN['email.registered']),
322
317
  });
323
318
  }
324
319
  if (req.appInfo.request.nickName) {
@@ -327,9 +322,7 @@ class Auth extends AbstractController {
327
322
  }));
328
323
  if (user) {
329
324
  return res.status(400).json({
330
- message: req.appInfo.i18n?.t('auth.nicknameExists', {
331
- defaultValue: EN['auth.nicknameExists'],
332
- }),
325
+ message: translateWithDefault(req, 'auth.nicknameExists', EN['auth.nicknameExists']),
333
326
  });
334
327
  }
335
328
  }
@@ -353,16 +346,12 @@ class Auth extends AbstractController {
353
346
  const dupFields = duplicateKeyFields(err);
354
347
  if (dupFields?.includes('email')) {
355
348
  return res.status(400).json({
356
- message: req.appInfo.i18n?.t('email.registered', {
357
- defaultValue: EN['email.registered'],
358
- }),
349
+ message: translateWithDefault(req, 'email.registered', EN['email.registered']),
359
350
  });
360
351
  }
361
352
  if (dupFields?.includes('name.nick')) {
362
353
  return res.status(400).json({
363
- message: req.appInfo.i18n?.t('auth.nicknameExists', {
364
- defaultValue: EN['auth.nicknameExists'],
365
- }),
354
+ message: translateWithDefault(req, 'auth.nicknameExists', EN['auth.nicknameExists']),
366
355
  });
367
356
  }
368
357
  throw err;
@@ -400,17 +389,13 @@ class Auth extends AbstractController {
400
389
  }
401
390
  catch {
402
391
  return res.status(400).json({
403
- message: req.appInfo.i18n?.t('email.alreadyVerifiedOrWrongToken', {
404
- defaultValue: EN['email.alreadyVerifiedOrWrongToken'],
405
- }),
392
+ message: translateWithDefault(req, 'email.alreadyVerifiedOrWrongToken', EN['email.alreadyVerifiedOrWrongToken']),
406
393
  });
407
394
  }
408
395
  this.logger?.debug(`Verify user ${user?.id}`);
409
396
  if (!user) {
410
397
  return res.status(400).json({
411
- message: req.appInfo.i18n?.t('email.alreadyVerifiedOrWrongToken', {
412
- defaultValue: EN['email.alreadyVerifiedOrWrongToken'],
413
- }),
398
+ message: translateWithDefault(req, 'email.alreadyVerifiedOrWrongToken', EN['email.alreadyVerifiedOrWrongToken']),
414
399
  });
415
400
  }
416
401
  user.isVerified = true;
@@ -435,9 +420,7 @@ class Auth extends AbstractController {
435
420
  this.logger?.error(e);
436
421
  }
437
422
  return res.status(200).json({
438
- message: req.appInfo.i18n?.t('auth.recoveryEmailSent', {
439
- defaultValue: EN['auth.recoveryEmailSent'],
440
- }),
423
+ message: translateWithDefault(req, 'auth.recoveryEmailSent', EN['auth.recoveryEmailSent']),
441
424
  });
442
425
  }
443
426
  async recoverPassword(req, res) {
@@ -447,9 +430,7 @@ class Auth extends AbstractController {
447
430
  });
448
431
  if (!user) {
449
432
  return res.status(400).json({
450
- message: req.appInfo.i18n?.t('password.wrongToken', {
451
- defaultValue: EN['password.wrongToken'],
452
- }),
433
+ message: translateWithDefault(req, 'password.wrongToken', EN['password.wrongToken']),
453
434
  });
454
435
  }
455
436
  this.logger?.debug(`Password recovery user ${user.id}`);
@@ -478,9 +459,7 @@ class Auth extends AbstractController {
478
459
  this.logger?.error(e);
479
460
  }
480
461
  return res.status(200).json({
481
- message: req.appInfo.i18n?.t('auth.verificationEmailSent', {
482
- defaultValue: EN['auth.verificationEmailSent'],
483
- }),
462
+ message: translateWithDefault(req, 'auth.verificationEmailSent', EN['auth.verificationEmailSent']),
484
463
  });
485
464
  }
486
465
  static get middleware() {