@appweaver/skill 0.0.0-stage → 3.0.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.
@@ -0,0 +1,1159 @@
1
+ # Configuration
2
+
3
+ Appweaver uses a centralized configuration system based on TypeBox schema validation. Configuration values are loaded
4
+ from multiple sources and merged in priority order.
5
+
6
+ ## Configuration loading order
7
+
8
+ Configuration is loaded and merged in the following order (later sources override earlier ones):
9
+
10
+ 1. **Default values** defined in the TypeBox schema
11
+ 2. **Global JSON config** `appweaver.json` (properties under the `config` key)
12
+ 3. **Inline environment config** `appweaver.json` (properties under the `environments.{NODE_ENV}` key)
13
+ 4. **Environment-specific JSON config** `appweaver.{NODE_ENV}.json` (properties under the `config` key)
14
+ 5. **Default .env file** `.env`, which never replaces a variable the process environment already has
15
+ 6. **Process environment** variables
16
+ 7. **Environment-specific .env file** `.env.{NODE_ENV}` (overrides all above, the process environment included)
17
+
18
+ The environment names are `test`, `local`, `dev`, `staging`, `qa`, and `prod`. `NODE_ENV=development` resolves to `dev`
19
+ and `NODE_ENV=production` to `prod`, for `APP_ENV`, the names of the `environments` sections, and the
20
+ environment-specific file names, and an unset `NODE_ENV` resolves to `prod`.
21
+
22
+ The loaded files are logged at the `debug` level on startup, an inline section as `./appweaver.json#environments.test`.
23
+
24
+ `.env` values support `${VAR_NAME}` expansion referencing any other environment variable; escape as `\${VAR_NAME}` to
25
+ keep it literal.
26
+
27
+ ## JSON configuration format
28
+
29
+ Configuration in JSON files is nested under the `config` key using camelCase property names. This is the preferred way
30
+ for application configuration, committed with the project. These are automatically mapped to their
31
+ `SCREAMING_SNAKE_CASE` equivalents:
32
+
33
+ ```json
34
+ {
35
+ "config": {
36
+ "app": {
37
+ "name": "MyApp",
38
+ "env": "prod"
39
+ },
40
+ "server": {
41
+ "port": 3000,
42
+ "apiPrefix": "/api"
43
+ },
44
+ "database": {
45
+ "url": "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST:-localhost}:5432/${DB_NAME}"
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ Write a key by its camelCase name in the object of its section, as the JSON Schema of `appweaver.json` describes it,
52
+ so the editor completes and checks it: `SECURITY_ACCOUNT_VERIFY_EMAIL_ENABLED` is `security.account.verifyEmailEnabled`.
53
+ Another nesting of the same name (`"verifyEmail": { "enabled": true }`) loads too, unchecked by the schema.
54
+
55
+ ### Environment configuration
56
+
57
+ The overrides of each environment go to the `environments` key of `appweaver.json`, keyed by the environment name. The
58
+ section matching `NODE_ENV` is merged over `config` property by property (an array value replaces the whole array),
59
+ the other ones are ignored. This keeps the whole configuration in a single file, which is what `@appweaver/create`
60
+ scaffolds:
61
+
62
+ ```json
63
+ {
64
+ "config": {
65
+ "database": {
66
+ "url": "file:./data/app.db"
67
+ }
68
+ },
69
+ "environments": {
70
+ "dev": {
71
+ "log": {
72
+ "level": "debug",
73
+ "pretty": true
74
+ }
75
+ },
76
+ "test": {
77
+ "log": {
78
+ "level": "silent",
79
+ "sync": true
80
+ },
81
+ "database": {
82
+ "url": "file:./temp/test.db"
83
+ }
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ An `appweaver.{env}.json` file, holding its overrides under the `config` key, is still loaded over the matching
90
+ section. Use it when an environment's config is supplied separately from the project, i.e. mounted into a production
91
+ container, or kept out of git. Only `appweaver.json` may declare `environments`; an `appweaver.{env}.json` declaring
92
+ them fails the startup with a `CONFIGURATION_INVALID` error.
93
+
94
+ ### Environment variable references
95
+
96
+ String values (and the strings of array values) of the JSON files expand references to the environment variables,
97
+ which include the variables of the `.env` files. Keep passwords and other secrets in the gitignored `.env`, and
98
+ reference them from the committed JSON files instead of writing them there:
99
+
100
+ | Syntax | Expands to |
101
+ |---------------------------|----------------------------------------------------------------|
102
+ | `${VAR_NAME}` | The variable's value, or an empty string when it is not set |
103
+ | `${VAR_NAME:-default}` | The variable's value, or `default` when it is not set or empty |
104
+ | `\\${VAR_NAME}` (in JSON) | The literal `${VAR_NAME}` |
105
+
106
+ Only the braced form is expanded, so a `$` elsewhere in a value stays as it is. A value expanding to an empty string is
107
+ skipped like an empty value, so the schema default applies. Use a `:-default` for the values a deployment overrides,
108
+ like the `DB_HOST` a docker-compose container sets to the database service name.
109
+
110
+ ## Environment variable parsing
111
+
112
+ - **Boolean**: `'true'`, `'on'`, `'yes'`, `'1'` (case-insensitive) are parsed as `true`; all others as `false`
113
+ - **Array**: a JSON array (`["a,b", "c"]`, for items holding a comma), or a comma-separated list whose items are
114
+ trimmed (`a, b`). An ambiguous value fails the startup with `CONFIGURATION_INVALID` instead of becoming one item: a
115
+ JSON array that does not parse, an empty item (`a,,b`, a trailing comma) or a quoted item (`"a","b"`)
116
+ - **Numbers**: Parsed as integers or floats based on schema type
117
+ - **Durations** (the `duration` keys): an integer of milliseconds (`5000`), or a number with a unit, `ms`, `s`, `m`,
118
+ `h`, `d` or `w` (`'200ms'`, `'30s'`, `'15m'`, `'7d'`), read as milliseconds in the code (`jwtConfig.EXPIRES_IN` is
119
+ `604800000` for `'7d'`). The TOTP `period` is the only key in seconds, as RFC 6238 defines it
120
+ - **Sizes** (the `size` keys): an integer of bytes (`1048576`), or a number with a unit in powers of 1024, `B`, `K`,
121
+ `M`, `G` or `T`, with an optional `B` or `iB` (`'64KB'`, `'5MB'`, `'1G'`), read as bytes in the code
122
+ - **Strings**: Used as-is
123
+
124
+ A value of a duration or a size key that is neither fails the startup with `CONFIGURATION_INVALID` naming the key.
125
+ Define such a key of your own with `Duration` and `Size` of `@appweaver/common`:
126
+
127
+ ```ts
128
+ export const reportsConfig = defineConfig('reports', {
129
+ TIMEOUT: Duration({ default: '30s', minimum: 1000 }), // number of milliseconds
130
+ MAX_UPLOAD: Size({ default: '5MB' }) // number of bytes
131
+ });
132
+ ```
133
+
134
+ Unknown environment variables are preserved with an `_appweaver_` prefix.
135
+
136
+ ## Reading the config in code
137
+
138
+ The config is split into **sections**, each declared with `defineConfig` by the module it belongs to. A section reads
139
+ its keys by their short names: the section `server` reads `SERVER_PORT` as `serverConfig.PORT`, and the JSON value
140
+ `config.server.port`. The environment variable names and the JSON paths of every key are the same as before, only the
141
+ code reads them through their section:
142
+
143
+ ```ts
144
+ import { appConfig, logConfig } from '@appweaver/common';
145
+ import { databaseConfig } from '@appweaver/data';
146
+ import { serverConfig } from '@appweaver/web';
147
+
148
+ serverConfig.PORT; // number
149
+ appConfig.HOSTNAME; // string
150
+ databaseConfig.URL; // string
151
+ ```
152
+
153
+ | Section variable | Keys | Imported from |
154
+ |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|-------------------------|
155
+ | `appConfig`, `logConfig` | `APP_*`, `LOG_*` | `@appweaver/common` |
156
+ | `cacheConfig`, `eventsConfig`, `healthConfig` (`HEALTH_CHECK_*`: `PORT`, `HOST`, `PICK_INSTANCES`, `OMIT_INSTANCES`), `localeConfig`, `mailerConfig`, `memoryConfig`, `queueConfig`, `schedulerConfig`, `securityStoreConfig` (`SECURITY_STORE_*`), `smsConfig`, `storageConfig`, `templateConfig` | `CACHE_*`, `HEALTH_CHECK_*`, ... | `@appweaver/core` |
157
+ | `databaseConfig`, `resourceConfig`, `exportConfig`, `imageConfig`, `passwordConfig`, `apiKeyConfig`, `systemConfig`, `auditConfig`, `audit<Category>Config` (`AUDIT_CHANGES_*`, `AUDIT_AUTH_*`, `AUDIT_READ_*`, `AUDIT_WRITE_*`, `AUDIT_CUSTOM_*`, `AUDIT_ROUTES_*`) | `DATABASE_*`, `RESOURCE_*`, ... | `@appweaver/data` |
158
+ | `serverConfig`, `rateLimitConfig`, `swaggerConfig`, `corsConfig`, `healthCheckConfig`, `templatePreviewConfig`, `securityConfig` (`SECURITY_*` not elsewhere), `accountConfig`, `twoFactorConfig` (`SECURITY_ACCOUNT_TWO_FACTOR_*`), `totpConfig` (`SECURITY_ACCOUNT_TWO_FACTOR_TOTP_*`), `recoveryCodesConfig` (`SECURITY_ACCOUNT_TWO_FACTOR_RECOVERY_CODES_*`), `recaptchaConfig`, `turnstileConfig`, `basicAuthConfig`, `jwtConfig`, `oauth2Config`, `oauth2<Provider>Config` (`SECURITY_OAUTH2_<PROVIDER>_*`, i.e. `oauth2GoogleConfig`), `auditRequestConfig` (`AUDIT_EXCLUDE_PATHS`, `AUDIT_REQUEST_BODY`) | `SERVER_*`, `SECURITY_*`, ... | `@appweaver/web` |
159
+ | `redisConfig` | `MEMORY_REDIS_*` | `@appweaver/redis` |
160
+ | `smtpConfig` | `MAILER_SMTP_*` | `@appweaver/nodemailer` |
161
+ | `twilioConfig` | `SMS_TWILIO_*` | `@appweaver/twilio` |
162
+
163
+ A section is parsed on the first access of one of its values, with the defaults of its schema, then kept frozen. A
164
+ missing or invalid value throws a `ConfigurationError` (`CONFIGURATION_INVALID`) naming only the invalid keys of the
165
+ section, each with its environment variable and JSON path. A key no section declares is ignored. `weaver config check`
166
+ finds the invalid values before the startup (see [Inspecting the config](#inspecting-the-config)).
167
+
168
+ ### Application config
169
+
170
+ An application declares its own settings the same way, typed and validated, instead of reading untyped keys:
171
+
172
+ ```ts
173
+ import { Type } from 'typebox';
174
+ import { defineConfig } from '@appweaver/common';
175
+
176
+ export const paymentConfig = defineConfig('payment', {
177
+ API_KEY: Type.String(), // PAYMENT_API_KEY, or config.payment.apiKey of appweaver.json
178
+ TIMEOUT: Type.Integer({ default: 10_000 })
179
+ });
180
+
181
+ paymentConfig.TIMEOUT; // number
182
+ ```
183
+
184
+ A section path can be nested (`defineConfig('storage.gcs', ...)` reads `STORAGE_GCS_*` and `config.storage.gcs.*`).
185
+ Two sections, even of two packages, can share a path with their own keys (`healthCheck` of `@appweaver/core` and
186
+ `@appweaver/web`, `security.oauth2` of `@appweaver/data` and `@appweaver/web`), but a flattened key belongs to one
187
+ section only, otherwise the second definition throws a `ConfigurationError`.
188
+
189
+ ### Config helper methods
190
+
191
+ The `config` object of `@appweaver/common` reads any key by its flattened name, including the keys no section declares,
192
+ with typed accessor methods:
193
+
194
+ ```ts
195
+ import { config } from '@appweaver/common';
196
+
197
+ config.env('APP_ENV', 'prod'); // string
198
+ config.str('APP_NAME', 'MyApp'); // string
199
+ config.int('SERVER_PORT', 5000); // number (integer)
200
+ config.float('SOME_RATIO', 0.5); // number (float)
201
+ config.bool('CACHE_ENABLED', true); // boolean
202
+ config.arr('CORS_METHODS', ['*']); // string[]
203
+ ```
204
+
205
+ A key of a section returns its parsed value, any other key its raw value from the environment or the JSON files.
206
+
207
+ ### Overriding the config in tests
208
+
209
+ `configOverrides` of `@appweaver/common` replaces the value of any key, by its flattened name, in every section:
210
+
211
+ ```ts
212
+ import { configOverrides } from '@appweaver/common';
213
+
214
+ beforeEach(() => {
215
+ configOverrides.SECURITY_API_KEY_ENABLED = true;
216
+ });
217
+
218
+ afterEach(() => {
219
+ delete configOverrides.SECURITY_API_KEY_ENABLED;
220
+ });
221
+ ```
222
+
223
+ A module reading the config when it is imported needs the override before its import, set in a `jest.mock` factory of
224
+ `@appweaver/common` (`Object.assign(jest.requireActual('@appweaver/common').configOverrides, { ... })`).
225
+
226
+ ## Inspecting the config
227
+
228
+ `weaver config` (alias `cfg`) creates the application without starting it, so every enabled module and the application
229
+ files have defined their sections, then:
230
+
231
+ ```sh
232
+ weaver config schema # write ./appweaver.schema.json
233
+ weaver config schema -o ./schemas/config.json # another output path
234
+ weaver config print # every key with its source and value, the secrets hidden
235
+ NODE_ENV=prod weaver config check # validate every section, exit 1 listing the errors
236
+ ```
237
+
238
+ - **`schema`** writes the JSON Schema of `appweaver.json` from the sections of the enabled modules: every key under its
239
+ camelCase name in its section, with its type and default, for `config` and each `environments.<env>`.
240
+ The `$schema` of `appweaver.json` points to it, for the completion and validation of the sections of the module
241
+ packages and of the application. `weaver generate` writes the same file from the sections the enabled modules list
242
+ in their `config` (on every run, so after adding a module too), and this command is only needed for a section
243
+ defined in an application file outside a module:
244
+
245
+ ```json
246
+ {
247
+ "$schema": "./appweaver.schema.json",
248
+ "config": {}
249
+ }
250
+ ```
251
+
252
+ - **`print`** lists every flattened key with its source: `override` (`configOverrides`), `env` (the environment and
253
+ the `.env` files), `json` (the `appweaver*.json` files) or `default`. `configSource(key)` of `@appweaver/common`
254
+ returns the same in code. A value is shown as `********` when its key ends with `PASSWORD`, `SECRET`, `TOKEN`,
255
+ `PRIVATE_KEY`, `CREDENTIALS` or `API_KEY`, or its schema has the `secret: true` option:
256
+
257
+ ```ts
258
+ export const paymentConfig = defineConfig('payment', {
259
+ /** The signing key of the webhooks. */
260
+ WEBHOOK_KEY: Type.String({ secret: true })
261
+ });
262
+ ```
263
+
264
+ - **`check`** parses every section and exits with 1, listing each invalid key with its environment variable and JSON
265
+ path. Run it in CI with the environment of the deployment, so a missing secret fails the pipeline, not the startup.
266
+
267
+ ## Providers
268
+
269
+ Every `*_PROVIDER` key (`config.<section>.provider`) selects the implementation of a contract, and takes:
270
+
271
+ | Value | Selects |
272
+ |------------------|---------------------------------------------------------------------------------------------------------------------------------|
273
+ | `auto` (default) | The driver of an enabled module, otherwise the fallback of core, otherwise none. |
274
+ | `none` | Nothing: the contract is not defined, and neither are the services requiring it (`EmailService` without a `Mailer`). |
275
+ | A provider name | The provider of that name of any enabled module, i.e. `memory` or `json`. A name no enabled module provides fails the startup. |
276
+ | A module path | A value with a `.`, `/` or `@` loads the class the file exports, i.e. `@/infra/my-storage` for a driver inside the application. |
277
+
278
+ | Contract | Key | Providers | `auto` selects |
279
+ |------------------|---------------------------|-----------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
280
+ | `Memory` | `MEMORY_PROVIDER` | `memory`, `redis` | `redis` with `@appweaver/redis`, otherwise `memory` |
281
+ | `Cache` | `CACHE_PROVIDER` | `memory` | `memory`, stored in the selected `Memory` (so in Redis with `redis`) |
282
+ | `Events` | `EVENTS_PROVIDER` | `node` | `node` |
283
+ | `PubSub` | `PUBSUB_PROVIDER` | `memory`, `redis` | `redis` with `@appweaver/redis`, otherwise `memory` |
284
+ | `Storage` | `STORAGE_PROVIDER` | `local` | `local`, unless a module of another driver is enabled |
285
+ | `SecurityStore` | `SECURITY_STORE_PROVIDER` | `database`, `memory` | `database` with the `@appweaver/data` module, otherwise none; `memory` only by its name |
286
+ | `Queue` | `QUEUE_PROVIDER` | `memory`, `bullmq` | `bullmq` with `@appweaver/bullmq` (it requires `@appweaver/redis`), otherwise `memory` |
287
+ | `Mailer` | `MAILER_PROVIDER` | `smtp`, `json` | `smtp` with `@appweaver/nodemailer`, otherwise none; `json` only by its name |
288
+ | `SmsSender` | `SMS_PROVIDER` | `twilio`, `json` | `twilio` with `@appweaver/twilio`, otherwise none; `json` only by its name |
289
+ | `TemplateEngine` | `TEMPLATE_PROVIDER` | `handlebars` | `handlebars` with `@appweaver/handlebars`, otherwise none |
290
+ | `Scheduler` | `SCHEDULER_PROVIDER` | `cron` | `cron` with `@appweaver/cron`, otherwise none |
291
+ | `Database` | `DATABASE_PROVIDER` | `prisma` | `prisma` with `@appweaver/data` |
292
+ | `ImageProcessor` | `IMAGE_PROVIDER` | `sharp` | `sharp` with `@appweaver/sharp`, otherwise none (images stored as uploaded) |
293
+ | `TimeSeries` | `TIMESERIES_PROVIDER` | `database`, `timescale`, `memory` | `database` with `@appweaver/data`, unless a module of another driver is enabled; `timescale` and `memory` only by their names |
294
+
295
+ - Each driver is the module of its package (see [modules](./modules.md)), enabled by installing the package, so
296
+ `npm install @appweaver/redis` moves the memory, the cache and the rate limit to Redis without any config.
297
+ - Two enabled drivers of one contract fail an `auto` key with `MODULE_PROVIDER_AMBIGUOUS` until one is selected by
298
+ name. An unknown name fails with `MODULE_PROVIDER_MISSING`.
299
+ - `selectedProvider(Contract)` of `@appweaver/core` returns the name of the selected provider (or the module path),
300
+ `undefined` when none is. The selection is logged at the `debug` level on startup.
301
+ - A production application falling back to the `memory` queue logs a warning, since its jobs (and the queued emails)
302
+ are lost on a restart.
303
+ - A test environment selects the in-process drivers by name while the driver packages stay installed:
304
+
305
+ ```json
306
+ {
307
+ "environments": {
308
+ "test": {
309
+ "memory": {
310
+ "provider": "memory"
311
+ },
312
+ "queue": {
313
+ "provider": "memory"
314
+ },
315
+ "mailer": {
316
+ "provider": "json"
317
+ },
318
+ "scheduler": {
319
+ "autoStartJob": false
320
+ }
321
+ }
322
+ }
323
+ }
324
+ ```
325
+
326
+ ---
327
+
328
+ ## Configuration properties
329
+
330
+ ### Application (APP\_\*)
331
+
332
+ | Property | Type | Default | Description |
333
+ |--------------------------|----------|------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
334
+ | `APP_ENV` | enum | `'prod'` | Application environment. Values: `test`, `local`, `dev`, `staging`, `qa`, `prod`. Mapped from `NODE_ENV`. |
335
+ | `APP_NAME` | string | `'Appweaver'` | Application name. |
336
+ | `APP_DESCRIPTION` | string? | - | Application description. |
337
+ | `APP_HOSTNAME` | string | `'http://localhost:{SERVER_PORT}'` | Application hostname URL. |
338
+ | `APP_TYPE_BASE` | string | `'urn:appweaver'` | Base of the type URIs of the application, i.e. `urn:appweaver:error:resource-not-found`. A URL base is joined with slashes. |
339
+ | `APP_RUNTIME` | enum | `'node'` | Application runtime. Autodetects Bun global module. Values: `node`, `bun` |
340
+ | `APP_VERSION` | string | `'unknown'` | Application version. Mapped from `npm_package_version`. |
341
+ | `APP_BUILD_PATH` | string | `'./dist'` | Path to compiled build artifacts. |
342
+ | `APP_SOURCE_PATH` | string | `'./src'` | Path to the application source code. Used in other path variables with <srcPath> placeholder. |
343
+ | `APP_SCAN_FILES_PATTERN` | string | `'<srcPath>/*/index.ts'` | Glob pattern for scanning application files. |
344
+ | `APP_MAIN_FILE_PATH` | string | `'<srcPath>/main.ts'` | Path to main application entrypoint file. |
345
+ | `APP_TASKS_DIR_PATH` | string | `'<srcPath>/tasks'` | Directory of the tasks `weaver run` lists and runs by name. See [cli](./cli.md#weaver-run). |
346
+ | `APP_MODULES_PATTERN` | string | `'<srcPath>/modules/*/module.ts'` | Glob of the manifests of the local modules, empty to find none. See [modules](./modules.md). |
347
+ | `APP_MODULES` | string[] | `[]` | Paths of the module manifests to enable besides the package and local ones, relative to the project root. |
348
+ | `APP_MODULES_DISABLED` | string[] | `[]` | Names of the modules to leave disabled, i.e. `@appweaver/web` for an application without a server. |
349
+
350
+ ### Logging (LOG\_\*)
351
+
352
+ | Property | Type | Default | Description |
353
+ |------------------------|----------|------------|-------------------------------------------------------------------------------------------------|
354
+ | `LOG_LEVEL` | enum | `'info'` | Minimum log level. Values: `silent`, `trace`, `debug`, `info`, `warn`, `error`, `fatal`. |
355
+ | `LOG_LEVELS` | record | `{}` | Level of each named logger, overriding `LOG_LEVEL`, i.e. `LOG_LEVELS=database:debug`. |
356
+ | `LOG_PATH` | string? | - | Path to log file. If unset, logs to console only. |
357
+ | `LOG_STREAM` | enum | `'stdout'` | Stream of the console logs, `stdout` or `stderr` (`weaver run` writes a task's logs to stderr). |
358
+ | `LOG_ROTATE` | boolean | `true` | Enable log file rotation. |
359
+ | `LOG_ROTATE_SIZE` | size | `'100MB'` | Maximum size per log file before rotation, bytes or a size string. |
360
+ | `LOG_ROTATE_MAX_SIZE` | size | `'5GB'` | Maximum total size of all log files, bytes or a size string. |
361
+ | `LOG_ROTATE_MAX_FILES` | integer | `1000` | Maximum number of rotated log files to keep. |
362
+ | `LOG_ROTATE_INTERVAL` | duration | `'1d'` | Rotation interval, milliseconds or a duration string of whole seconds (`'1d'` for daily). |
363
+ | `LOG_ROTATE_COMPRESS` | boolean | `true` | Compress rotated log files with gzip. |
364
+ | `LOG_PRETTY` | boolean | `false` | Enable pretty-printed JSON logs. |
365
+ | `LOG_SYNC` | boolean | `false` | Write each record before the next statement runs, instead of buffering it. |
366
+
367
+ See [logging](./logging.md) for the loggers and the levels per module.
368
+
369
+ ### Server (SERVER\_\*)
370
+
371
+ | Property | Type | Default | Description |
372
+ |-----------------------------------------|----------|--------------|------------------------------------------------------------------------------------------------------------------------|
373
+ | `SERVER_PORT` | integer | `5000` | HTTP server listening port. |
374
+ | `SERVER_HOST` | string | `'0.0.0.0'` | HTTP server listening host/IP. |
375
+ | `SERVER_LISTEN` | boolean | `true` | Listen when the app starts, `false` serves only `app.server.inject()` (e2e tests). |
376
+ | `SERVER_API_PREFIX` | string | `'/api'` | Base path prefix for all API routes. |
377
+ | `SERVER_BODY_MAX_SIZE` | size | `'100MB'` | Maximum request body size, i.e. of a multipart file upload, bytes or a size string. |
378
+ | `SERVER_JSON_BODY_MAX_SIZE` | size | `'1MB'` | Maximum size of a JSON request body, parsed at once on the event loop, bytes or a size string. |
379
+ | `SERVER_STATIC_ENABLED` | boolean | `true` | Enable serving static files from disk. |
380
+ | `SERVER_STATIC_DIR_PATH` | string | `'./public'` | Directory containing static files. |
381
+ | `SERVER_STATIC_ROUTE_PREFIX` | string | `'/public'` | URL prefix for static file routes. |
382
+ | `SERVER_STATIC_RESPONSE_HEADERS` | string[] | `[]` | HTTP headers for static files. Format: "{header}: {value}" |
383
+ | `SERVER_STATIC_MAX_AGE` | duration | `'30d'` | Cache-Control max-age for static files, milliseconds or a duration string. |
384
+ | `SERVER_STATIC_ALLOWED_HOST` | string? | - | Host allowed to access static files (CORS). |
385
+ | `SERVER_REQUEST_TIMEOUT` | duration | `60000` | Time a request may take to respond before `503 REQUEST_TIMEOUT`, milliseconds or a duration string, `0` for none. |
386
+ | `SERVER_TRANSFER_TIMEOUT` | duration | `3600000` | The timeout of the file downloads, uploads, exports and static files, milliseconds or a duration string, `0` for none. |
387
+ | `SERVER_TRUST_PROXY` | boolean | `true` | Trust `X-Forwarded-*` headers from reverse proxies. |
388
+ | `SERVER_REQUEST_LOGGING_ENABLED` | boolean | `false` | Enable HTTP request/response logging. |
389
+ | `SERVER_ERROR_DATABASE_MESSAGE_ENABLED` | boolean | `false` | Append the message of the database to the detail of a database error response, in every environment. |
390
+ | `SERVER_ERROR_RESPONSE_MAX_COUNT` | integer | `20` | Maximum validation errors per response. Above `1` every failure is reported, else only the first. |
391
+
392
+ A route sets its own timeout with its `timeout` option (`createRoutes({ query: { timeout: 5000 } })`,
393
+ `registerRoute(handler, { timeout: 0 })`). The timeout answers the client and aborts `request.signal`, but the work of
394
+ the request runs on: Prisma takes no signal, and a SQLite query blocks the event loop until it ends (see
395
+ [database.md](database.md#sqlite-in-production)).
396
+
397
+ ### Response compression (SERVER_COMPRESSION\_\*)
398
+
399
+ | Property | Type | Default | Description |
400
+ |-------------------------------------------|---------|--------------------|--------------------------------------------------------------------------------------------------------------------------|
401
+ | `SERVER_COMPRESSION_ENABLED` | boolean | `true` | Compress the responses, `false` when a reverse proxy or a CDN compresses them already. |
402
+ | `SERVER_COMPRESSION_THRESHOLD` | size | `'1KB'` | The size from which a response is compressed, bytes or a size string. |
403
+ | `SERVER_COMPRESSION_ENCODINGS` | enum[] | `['zstd', 'gzip']` | The encodings in the server's order of preference (`zstd`, `br`, `gzip`, `deflate`). |
404
+ | `SERVER_COMPRESSION_LEVELS` | record | `{}` | The level of each encoding over `{ zstd: 3, br: 4, gzip: 6 }` (`gzip` also for `deflate`). |
405
+ | `SERVER_COMPRESSION_SYNC_THRESHOLD` | size? | by the CPUs | The size up to which a response is compressed on the event loop, larger ones in the thread pool, bytes or a size string. |
406
+ | `SERVER_COMPRESSION_RESPECT_NO_TRANSFORM` | boolean | `true` | Send a response with `Cache-Control: no-transform` as it is. |
407
+
408
+ A route overrides it with its `compress` option: `false`, or `{ threshold, encodings, levels }` over the config
409
+ (`createRoutes({ defaults: { compress: { threshold: '4KB' } }, find: { compress: false } })`,
410
+ `registerRoute(handler, { compress: false })`). The authentication routes (`security.routePrefix`,
411
+ `security.account.routePrefix`), the API key routes (`/api-keys`, the creation answering the plain key), the MCP OAuth
412
+ routes and the realtime routes are never compressed unless they set it: a token compressed beside reflected input is
413
+ exposed to the BREACH attack, and a stream is written as it goes. A route of the application answering a secret sets
414
+ `compress: false`. The
415
+ request bodies are never decompressed. A cached response (the `cache` route option) is stored compressed in the
416
+ encoding of the request caching it, beside the uncompressed payload, so a hit in that encoding is not compressed again.
417
+
418
+ ### Rate limiting (RATE*LIMIT*\*)
419
+
420
+ | Property | Type | Default | Description |
421
+ |-----------------------------------|-----------|----------|-----------------------------------------------------------------------------------------------------------------------------------------|
422
+ | `RATE_LIMIT_ENABLED` | boolean | `true` | Enable global rate limiting middleware. |
423
+ | `RATE_LIMIT_MAX` | integer | `1000` | Maximum requests allowed per time window. |
424
+ | `RATE_LIMIT_WINDOW` | duration | `60000` | Rate limit window, milliseconds or a duration string. |
425
+ | `RATE_LIMIT_ALLOW_LIST` | string[]? | - | IP addresses/patterns exempt from rate limiting. |
426
+ | `RATE_LIMIT_STORE` | enum | `'auto'` | Store of the counters. `auto`: the Redis connection of the `Memory` provider with `redis`, otherwise the process. `local`: the process. |
427
+ | `RATE_LIMIT_SKIP_ON_ERROR` | boolean | `true` | Skip rate limiting instead of failing requests with `503 MEMORY_UNAVAILABLE` when the store errors, e.g. while Redis is down. |
428
+ | `RATE_LIMIT_SECURE_SKIP_ON_ERROR` | boolean | `false` | The same for the secure routes (`rateLimit.secure`). |
429
+
430
+ A route marked `rateLimit: { secure: true }` fails closed while the store is unavailable, the others skip the limit.
431
+ The login, password change, email verification and reset emails, and 2FA code routes are secure; mark the routes
432
+ calling an expensive service (SMS, LLM, payments) the same way. A route's `rateLimit.skipOnError` overrides both keys.
433
+
434
+ ### Swagger / OpenAPI (SWAGGER\_\*)
435
+
436
+ | Property | Type | Default | Description |
437
+ |-------------------------|---------|--------------|---------------------------------------------|
438
+ | `SWAGGER_ENABLED` | boolean | `true` | Enable Swagger/OpenAPI documentation UI. |
439
+ | `SWAGGER_PATH` | string | `'/swagger'` | URL path for the Swagger UI. |
440
+ | `SWAGGER_HIDE_UNTAGGED` | boolean | `false` | Hide untagged endpoints from documentation. |
441
+
442
+ ### Health check (HEALTH*CHECK*\*)
443
+
444
+ The route keys are the `healthCheck` section of `@appweaver/web` (`healthCheckConfig`), the instance filters and the
445
+ health listener the `healthCheck` section of `@appweaver/core` (`healthConfig`). The filters are read by
446
+ `HealthService` for the route and the health listener alike.
447
+
448
+ `GET <prefix>/ready` needs no authentication and answers `{ "ready": true }` only once the `onReady` hook of every
449
+ service completed (the server listens while the queue workers and the scheduled jobs still start), and from the start
450
+ of the shutdown on `{ "ready": false }` with 503 again, while the requests in flight complete. The application sets it
451
+ with `HealthService.setReady`, so `checkReadiness()` reports the same state in code.
452
+
453
+ | Property | Type | Default | Description |
454
+ |-------------------------------|-----------|-------------|-----------------------------------------------------------------------------|
455
+ | `HEALTH_CHECK_ENABLED` | boolean | `true` | Enable the health check endpoint. |
456
+ | `HEALTH_CHECK_AUTH` | boolean | `true` | Require authentication for health check. |
457
+ | `HEALTH_CHECK_ROUTE_PREFIX` | string | `'/health'` | URL prefix for health check routes. |
458
+ | `HEALTH_CHECK_CACHE_TTL` | duration | `3000` | Cache TTL for the health check response, milliseconds or a duration string. |
459
+ | `HEALTH_CHECK_PICK_INSTANCES` | string[]? | - | List of health check instance names to include in response. |
460
+ | `HEALTH_CHECK_OMIT_INSTANCES` | string[]? | - | List of health check instance names to exclude from response. |
461
+
462
+ ### Health listener (HEALTH_CHECK_PORT, HEALTH_CHECK_HOST)
463
+
464
+ An application without the `@appweaver/web` server (a worker, a scheduled job runner) answers `GET /health/check` and
465
+ `GET /health/ready` on its own `node:http` listener, without authentication, running the same checks as the health
466
+ route: `/health/check` responds with 503 when a check is down, `/health/ready` with 503 while the application is not
467
+ ready. The listener stays off beside the server of `@appweaver/web`, which answers the health routes itself, and in
468
+ `weaver run`, whose task may run beside an application listening on the port.
469
+
470
+ | Property | Type | Default | Description |
471
+ |---------------------|---------|-------------|--------------------------------------------|
472
+ | `HEALTH_CHECK_PORT` | integer | `0` | Port of the health listener, `0` for none. |
473
+ | `HEALTH_CHECK_HOST` | string | `'0.0.0.0'` | Host of the health listener. |
474
+
475
+ ### CORS (CORS\_\*)
476
+
477
+ | Property | Type | Default | Description |
478
+ |------------------------|----------|---------|----------------------------------------------------------------------------------------|
479
+ | `CORS_ORIGIN` | string[] | `['*']` | Allowed origins for CORS requests. |
480
+ | `CORS_METHODS` | string[] | `['*']` | Allowed HTTP methods. |
481
+ | `CORS_ALLOWED_HEADERS` | string[] | `['*']` | Allowed request headers. |
482
+ | `CORS_EXPOSED_HEADERS` | string[] | `['*']` | Headers exposed to the browser. |
483
+ | `CORS_MAX_AGE` | duration | `'1d'` | Preflight response cache duration, milliseconds or a duration string of whole seconds. |
484
+ | `CORS_CREDENTIALS` | boolean | `true` | Allow credentials (cookies, auth headers). |
485
+
486
+ ### Resources (RESOURCE\_\*)
487
+
488
+ | Property | Type | Default | Description |
489
+ |-------------------------------------|----------|---------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
490
+ | `RESOURCE_MODEL_PATTERN` | string | `'<srcPath>/resources/*/*model.ts'` | Glob pattern for resource model files. |
491
+ | `RESOURCE_SERVICE_PATTERN` | string | `'<srcPath>/resources/*/*service.ts'` | Glob pattern for resource service files. |
492
+ | `RESOURCE_POLICY_PATTERN` | string | `'<srcPath>/resources/*/*policy.ts'` | Glob pattern for resource policy files. |
493
+ | `RESOURCE_ROUTES_PATTERN` | string | `'<srcPath>/resources/*/*routes.ts'` | Glob pattern for resource routes files. |
494
+ | `RESOURCE_GENERATED_TYPES_PATH` | string | `'<srcPath>/types/generated.ts'` | Output path for generated TypeScript types. |
495
+ | `RESOURCE_QUERY_METHOD` | enum | `'post'` | Methods of the `query` routes: `post`, `get`, or `get-post`. Overridable per route. |
496
+ | `RESOURCE_AGGREGATE_METHOD` | enum | `'post'` | Methods of the `aggregate` routes: `post`, `get`, or `get-post`. Overridable per route. |
497
+ | `RESOURCE_BULK_MAX_ITEMS` | integer | `2000` | Maximum items of a bulk request. Overridable per route (`maxItems`). |
498
+ | `RESOURCE_BULK_TRANSACTION_TIMEOUT` | duration | `5000` | Timeout of the transaction a bulk request runs in, milliseconds or a duration string. |
499
+ | `RESOURCE_BULK_RETURN_RECORDS` | boolean | `true` | Respond with the records, or only `{ success, count }`. Overridable per route. |
500
+ | `RESOURCE_FILTER_MAX_CONDITIONS` | integer | `100` | Maximum conditions (field and operator keys) of a filter, nested filters included. |
501
+ | `RESOURCE_FILTER_MAX_DEPTH` | integer | `5` | Maximum nesting depth of a filter, every nested object or list counting as a level. |
502
+ | `RESOURCE_FILTER_MAX_LIST_VALUES` | integer | `1000` | Maximum number of values of a list in a filter, i.e. of an `_in` list. |
503
+ | `RESOURCE_COUNT_LIMIT` | integer | `10000` | Records the `totalCount` of a query counts, `totalCountExact: false` beyond them. |
504
+ | `RESOURCE_MAX_OFFSET` | integer | `10000` | Records an offset page skips, `400 RESOURCE_OFFSET_TOO_LARGE` beyond (use the cursors). |
505
+ | `RESOURCE_TEXT_SEARCH_MAX_MATCHES` | integer | `1000` | Records the full-text search of a query matches (`textSearch: { mode: 'fts' }`), the most relevant. |
506
+ | `RESOURCE_AGGREGATE_MAX_PERIODS` | integer | `1000` | Periods an aggregate splits its range into by its `interval` (10,000 at most), `400 RESOURCE_INVALID_AGGREGATE` beyond. |
507
+
508
+ ### Data export (EXPORT\_\*)
509
+
510
+ | Property | Type | Default | Description |
511
+ |--------------------------------|---------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------|
512
+ | `EXPORT_BATCH_SIZE` | integer | `1000` | Number of records per batch during export. |
513
+ | `EXPORT_CSV_DELIMITER` | string | `';'` | CSV field delimiter character. |
514
+ | `EXPORT_CSV_JOIN_DELIMITER` | string | `','` | Delimiter for joining array values in CSV cells. |
515
+ | `EXPORT_CSV_ADD_HEADERS` | boolean | `true` | Include a header row in CSV exports. |
516
+ | `EXPORT_CSV_ADD_SEPARATOR_ROW` | boolean | `false` | Add separator row (BOM) for Excel compatibility. |
517
+ | `EXPORT_CSV_ESCAPE_FORMULAS` | boolean | `true` | Prefix with `'` the text cells a spreadsheet would run as a formula (`=`, `+`, `-`, `@`, tab, carriage return), signed numeric text excepted. |
518
+
519
+ ### Security (SECURITY\_\*)
520
+
521
+ #### General
522
+
523
+ | Property | Type | Default | Description |
524
+ |-----------------------------------|-----------|------------------------|--------------------------------------------------------------------------------------------|
525
+ | `SECURITY_ROUTE_PREFIX` | string | `'/auth'` | Base path for authentication routes. |
526
+ | `SECURITY_CACHE_TTL` | duration | `300000` | Security cache TTL, milliseconds or a duration string. |
527
+ | `SECURITY_EXCHANGE_TOKEN_TTL` | duration | `120000` | One-time token TTL for authentication, milliseconds or a duration string. |
528
+ | `SECURITY_ALLOWED_REDIRECT_HOSTS` | string[]? | host of `APP_HOSTNAME` | The hosts the redirects of the authentication and account routes may lead to, `*` for any. |
529
+ | `SECURITY_STORE_PROVIDER` | string | `'auto'` | `auto` (`database` with a database), `database`, `memory`, `none`, or a module path. |
530
+
531
+ #### Password policy
532
+
533
+ | Property | Type | Default | Description |
534
+ |--------------------------------|---------|---------|---------------------------------------------------------------------------------------------------|
535
+ | `SECURITY_PASSWORD_ENABLED` | boolean | `true` | Enable password-based authentication. |
536
+ | `SECURITY_PASSWORD_MIN_LENGTH` | integer | `8` | Minimum password length, 15 recommended when the password is the only factor (NIST SP 800-63B-4). |
537
+ | `SECURITY_PASSWORD_MAX_LENGTH` | integer | `100` | Maximum password length. |
538
+ | `SECURITY_PASSWORD_UPPERCASE` | boolean | `true` | Require at least one uppercase letter. |
539
+ | `SECURITY_PASSWORD_LOWERCASE` | boolean | `true` | Require at least one lowercase letter. |
540
+ | `SECURITY_PASSWORD_NUMERIC` | boolean | `true` | Require at least one digit. |
541
+ | `SECURITY_PASSWORD_SPECIAL` | boolean | `true` | Require at least one special character. |
542
+
543
+ #### Account management
544
+
545
+ | Property | Type | Default | Description |
546
+ |------------------------------------------------------------|-----------|----------------------------|---------------------------------------------------------------------------------------------------------------|
547
+ | `SECURITY_ACCOUNT_ROUTE_PREFIX` | string | `'/auth/account'` | Base path for account management routes. |
548
+ | `SECURITY_ACCOUNT_VERIFY_EMAIL_ENABLED` | boolean | `true` | Enable email verification flow, its routes registered only with a mailer. |
549
+ | `SECURITY_ACCOUNT_VERIFY_EMAIL_TOKEN_TTL` | duration | `7200000` | Email verification token TTL, milliseconds or a duration string. |
550
+ | `SECURITY_ACCOUNT_RESET_PASSWORD_ENABLED` | boolean | `true` | Enable password reset flow, its routes registered only with a mailer. |
551
+ | `SECURITY_ACCOUNT_RESET_PASSWORD_TOKEN_TTL` | duration | `1800000` | Password reset token TTL, milliseconds or a duration string. |
552
+ | `SECURITY_ACCOUNT_VERIFY_PHONE_ENABLED` | boolean | `true` | Enable phone verification by an SMS code, its routes registered only with an SMS sender. |
553
+ | `SECURITY_ACCOUNT_VERIFY_PHONE_CODE_TTL` | duration | `600000` | Phone verification code TTL, milliseconds or a duration string. |
554
+ | `SECURITY_ACCOUNT_TWO_FACTOR_ENABLED` | boolean | `false` | Enable two-factor authentication, its routes and its models. |
555
+ | `SECURITY_ACCOUNT_TWO_FACTOR_FORCED` | boolean | `false` | Force 2FA for every user (or the forced roles), enrolling the ones without a method. |
556
+ | `SECURITY_ACCOUNT_TWO_FACTOR_FORCED_ROLES` | string[] | `[]` | The roles 2FA is forced for, empty for every user. |
557
+ | `SECURITY_ACCOUNT_TWO_FACTOR_GRACE_PERIOD` | duration? | - | How long a forced user without a method still signs in fully (`enrollBy`), milliseconds or a duration string. |
558
+ | `SECURITY_ACCOUNT_TWO_FACTOR_FORCED_SINCE` | string? | - | When 2FA was forced (ISO date), the start of the grace period of the existing users. |
559
+ | `SECURITY_ACCOUNT_TWO_FACTOR_RESET_ROLES` | string[] | `['Admin']` | The roles allowed to reset the 2FA of a user (`DELETE /two-factor/users/:id`). |
560
+ | `SECURITY_ACCOUNT_TWO_FACTOR_CHALLENGE_TTL` | duration | `300000` | 2FA challenge TTL, milliseconds or a duration string. |
561
+ | `SECURITY_ACCOUNT_TWO_FACTOR_METHODS` | enum[] | `['Email', 'Sms', 'Totp']` | The methods users may enable, each available only with its service (see below). |
562
+ | `SECURITY_ACCOUNT_TWO_FACTOR_DEFAULT_METHOD` | enum | `'Email'` | The method of a forced user without one, used only with its verified channel. |
563
+ | `SECURITY_ACCOUNT_TWO_FACTOR_CODE_LENGTH` | integer | `6` | Digits of the codes sent by email and SMS (4-10). |
564
+ | `SECURITY_ACCOUNT_TWO_FACTOR_MAX_ATTEMPTS` | integer | `5` | Wrong codes of a challenge, revoked on the last one. |
565
+ | `SECURITY_ACCOUNT_TWO_FACTOR_REMEMBER_DEVICE_ENABLED` | boolean | `false` | Let a user who passed 2FA on a device skip it there on the next sign-ins, with a device token. |
566
+ | `SECURITY_ACCOUNT_TWO_FACTOR_REMEMBER_DEVICE_TTL` | duration | `'30d'` | How long a device stays trusted, milliseconds or a duration string. |
567
+ | `SECURITY_ACCOUNT_TWO_FACTOR_REMEMBER_DEVICE_MAX_DEVICES` | integer | `10` | The most trusted devices of a user, the oldest forgotten beyond it. |
568
+ | `SECURITY_ACCOUNT_TWO_FACTOR_REMEMBER_DEVICE_ROTATE` | boolean | `true` | Replace the device token on every sign-in it skips 2FA for. |
569
+ | `SECURITY_ACCOUNT_TWO_FACTOR_TOTP_ISSUER` | string? | `app.name` | Issuer the authenticator apps show the account under. |
570
+ | `SECURITY_ACCOUNT_TWO_FACTOR_TOTP_ENCRYPTION_KEY` | string? | - | Secret encrypting the TOTP secrets in the database, required by the `Totp` method. |
571
+ | `SECURITY_ACCOUNT_TWO_FACTOR_TOTP_DIGITS` | integer | `6` | Digits of a TOTP code (6-8), `6` for every authenticator app. |
572
+ | `SECURITY_ACCOUNT_TWO_FACTOR_TOTP_PERIOD` | integer | `30` | Seconds of a TOTP time step, `30` for every authenticator app. |
573
+ | `SECURITY_ACCOUNT_TWO_FACTOR_TOTP_WINDOW` | integer | `1` | Time steps around the current one whose codes are accepted. |
574
+ | `SECURITY_ACCOUNT_TWO_FACTOR_TOTP_SETUP_TTL` | duration | `600000` | Time to confirm a TOTP setup with its first code, milliseconds or a duration string. |
575
+ | `SECURITY_ACCOUNT_TWO_FACTOR_RECOVERY_CODES_ENABLED` | boolean | `true` | Enable the recovery codes, used once each instead of a 2FA code. |
576
+ | `SECURITY_ACCOUNT_TWO_FACTOR_RECOVERY_CODES_COUNT` | integer | `10` | Number of recovery codes generated at once (1-100). |
577
+ | `SECURITY_ACCOUNT_TWO_FACTOR_RECOVERY_CODES_LENGTH` | integer | `16` | Characters of a recovery code (8-128), shown in groups of four. |
578
+ | `SECURITY_ACCOUNT_TWO_FACTOR_RECOVERY_CODES_NOTIFY_ON_USE` | boolean | `true` | Email the user when one of their recovery codes is used. |
579
+
580
+ A method is available only with its service: `Email` with a mailer, `Sms` with an SMS sender (`@appweaver/twilio`, or
581
+ `json`), and `Totp` with `SECURITY_ACCOUNT_TWO_FACTOR_TOTP_ENCRYPTION_KEY`. Changing the encryption key makes the enabled TOTP
582
+ methods unusable, so keep it with the other secrets of the deployment.
583
+ See [security](./security.md#two-factor-authentication-2fa).
584
+
585
+ #### reCAPTCHA
586
+
587
+ | Property | Type | Default | Description |
588
+ |----------------------------------|---------|-----------------------------------------------------|--------------------------------------------------------------------------|
589
+ | `SECURITY_RECAPTCHA_ENABLED` | boolean | `false` | Enable Google reCAPTCHA verification. |
590
+ | `SECURITY_RECAPTCHA_SECRET` | string? | - | Google reCAPTCHA secret key. |
591
+ | `SECURITY_RECAPTCHA_HEADER_NAME` | string | `'x-recaptcha-token'` | Request header name for the reCAPTCHA token. |
592
+ | `SECURITY_RECAPTCHA_MIN_SCORE` | number | `0.4` | Minimum reCAPTCHA v3 score threshold (0-1). |
593
+ | `SECURITY_RECAPTCHA_AUTH_ROUTES` | enum[] | `[]` | The auth routes requiring a token: `login`, `refresh`, `changePassword`. |
594
+ | `SECURITY_RECAPTCHA_VERIFY_URL` | string | `'https://www.google.com/recaptcha/api/siteverify'` | Google reCAPTCHA verification endpoint URL. |
595
+
596
+ #### Cloudflare Turnstile
597
+
598
+ | Property | Type | Default | Description |
599
+ |----------------------------------|---------|---------------------------------------------------------------|--------------------------------------------------------------------------|
600
+ | `SECURITY_TURNSTILE_ENABLED` | boolean | `false` | Enable Cloudflare Turnstile verification. |
601
+ | `SECURITY_TURNSTILE_SECRET` | string? | - | Cloudflare Turnstile secret key. |
602
+ | `SECURITY_TURNSTILE_HEADER_NAME` | string | `'x-turnstile-token'` | Request header name for the Turnstile token. |
603
+ | `SECURITY_TURNSTILE_AUTH_ROUTES` | enum[] | `[]` | The auth routes requiring a token: `login`, `refresh`, `changePassword`. |
604
+ | `SECURITY_TURNSTILE_VERIFY_URL` | string | `'https://challenges.cloudflare.com/turnstile/v0/siteverify'` | Turnstile verification endpoint URL. |
605
+
606
+ #### HTTP Basic authentication
607
+
608
+ | Property | Type | Default | Description |
609
+ |-----------------------------|---------|---------|-----------------------------------|
610
+ | `SECURITY_BASIC_ENABLED` | boolean | `false` | Enable HTTP Basic authentication. |
611
+ | `SECURITY_BASIC_REALM` | string? | - | HTTP Basic auth realm name. |
612
+ | `SECURITY_BASIC_PROXY_MODE` | boolean | `false` | Enable proxy mode for Basic auth. |
613
+
614
+ #### API key authentication
615
+
616
+ | Property | Type | Default | Description |
617
+ |-----------------------------------|-----------|---------------|------------------------------------------------------------------------------|
618
+ | `SECURITY_API_KEY_ENABLED` | boolean | `false` | Enable API key authentication. |
619
+ | `SECURITY_API_KEY_HEADER_NAME` | string | `'x-api-key'` | Request header name for the API key. |
620
+ | `SECURITY_API_KEY_MAX_DURATION` | duration? | - | Maximum API key validity duration, milliseconds or a duration string. |
621
+ | `SECURITY_API_KEY_DELIMITER` | string | `'AK'` | Prefix delimiter between key ID and secret value. |
622
+ | `SECURITY_API_KEY_ROUTES_ENABLED` | boolean | `true` | Register the built-in `/api-keys` routes (JWT only), off to expose your own. |
623
+
624
+ #### JWT (JSON Web Tokens)
625
+
626
+ | Property | Type | Default | Description |
627
+ |-----------------------------------|----------|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
628
+ | `SECURITY_JWT_SECRET` | string? | - | HMAC secret for symmetric JWT signing (HS256), 32 characters or more. If set, RSA keys are not used. |
629
+ | `SECURITY_JWT_PUBLIC_KEY_PATH` | string | `'./storage/__keys__/public.key'` | Path to RSA public key for JWT verification (RS256). |
630
+ | `SECURITY_JWT_PRIVATE_KEY_PATH` | string | `'./storage/__keys__/private.key'` | Path to RSA private key for JWT signing (RS256). |
631
+ | `SECURITY_JWT_AUTO_GENERATE_KEYS` | boolean? | `true` in `dev`, `local`, `test` | Generate an RSA key pair when the key files are missing; without it and without a secret the application fails to start. |
632
+ | `SECURITY_JWT_EXPIRES_IN` | duration | `'15m'` | Access token lifetime, milliseconds or a duration string of whole seconds. |
633
+ | `SECURITY_JWT_REFRESH_EXPIRES_IN` | duration | `'30d'` | Refresh token lifetime, milliseconds or a duration string of whole seconds. A refresh token is used once: the refresh answers a new one, and a refresh token used again (beyond a concurrent refresh within 15 seconds) signs the user out of every session. |
634
+
635
+ #### OAuth2 general
636
+
637
+ | Property | Type | Default | Description |
638
+ |----------------------------------------|----------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
639
+ | `SECURITY_OAUTH2_STATE_TTL` | duration | `600000` | OAuth2 state parameter TTL, milliseconds or a duration string. |
640
+ | `SECURITY_OAUTH2_REGISTRATION_ENABLED` | boolean | `true` | Allow registering new users via OAuth2 login. When `false`, only already existing users (matched by email) can log in via OAuth2. |
641
+ | `SECURITY_OAUTH2_FETCH_AVATAR_ENABLED` | boolean | `true` | Download the user's avatar from the OAuth2 provider during registration and pass it as `avatarFile` to `registrationData` and `registrationFiles`. Set to `false` to pass only `avatarUrl` and skip the download. |
642
+
643
+ #### OAuth2 Google
644
+
645
+ | Property | Type | Default | Description |
646
+ |-----------------------------------------------|---------|---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
647
+ | `SECURITY_OAUTH2_GOOGLE_ENABLED` | boolean | `false` | Enable Google OAuth2 provider. |
648
+ | `SECURITY_OAUTH2_GOOGLE_CLIENT_ID` | string? | - | Google OAuth2 client ID. |
649
+ | `SECURITY_OAUTH2_GOOGLE_CLIENT_SECRET` | string? | - | Google OAuth2 client secret. |
650
+ | `SECURITY_OAUTH2_GOOGLE_USER_INFO_URL` | string | `'https://www.googleapis.com/oauth2/v2/userinfo'` | Google user info endpoint. |
651
+ | `SECURITY_OAUTH2_GOOGLE_AUTHORIZATION_PARAMS` | record | `{}` | Extra query parameters of the authorization request, i.e. `prompt:select_account`. See [security](./security.md#authorization-parameters). |
652
+
653
+ #### OAuth2 Facebook
654
+
655
+ | Property | Type | Default | Description |
656
+ |-------------------------------------------------|---------|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
657
+ | `SECURITY_OAUTH2_FACEBOOK_ENABLED` | boolean | `false` | Enable Facebook OAuth2 provider. |
658
+ | `SECURITY_OAUTH2_FACEBOOK_CLIENT_ID` | string? | - | Facebook OAuth2 client ID. |
659
+ | `SECURITY_OAUTH2_FACEBOOK_CLIENT_SECRET` | string? | - | Facebook OAuth2 client secret. |
660
+ | `SECURITY_OAUTH2_FACEBOOK_USER_INFO_URL` | string | `'https://graph.facebook.com/me'` | Facebook user info endpoint. |
661
+ | `SECURITY_OAUTH2_FACEBOOK_AUTHORIZATION_PARAMS` | record | `{}` | Extra query parameters of the authorization request, i.e. `auth_type:reauthenticate`. See [security](./security.md#authorization-parameters). |
662
+
663
+ #### OAuth2 X (Twitter)
664
+
665
+ The app must be granted the email permission in the X developer portal, otherwise X refuses to return the
666
+ `confirmed_email` field and every login is rejected.
667
+
668
+ | Property | Type | Default | Description |
669
+ |------------------------------------------|---------|----------------------------------|--------------------------------------------------------------------------------------------------------------|
670
+ | `SECURITY_OAUTH2_X_ENABLED` | boolean | `false` | Enable X OAuth2 provider. The flow always uses PKCE, which X requires. |
671
+ | `SECURITY_OAUTH2_X_CLIENT_ID` | string? | - | X OAuth2 client ID. |
672
+ | `SECURITY_OAUTH2_X_CLIENT_SECRET` | string? | - | X OAuth2 client secret. |
673
+ | `SECURITY_OAUTH2_X_USER_INFO_URL` | string | `'https://api.x.com/2/users/me'` | X user info endpoint. |
674
+ | `SECURITY_OAUTH2_X_AUTHORIZATION_PARAMS` | record | `{}` | Extra query parameters of the authorization request. See [security](./security.md#authorization-parameters). |
675
+
676
+ #### OAuth2 GitHub
677
+
678
+ | Property | Type | Default | Description |
679
+ |-----------------------------------------------|---------|---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
680
+ | `SECURITY_OAUTH2_GITHUB_ENABLED` | boolean | `false` | Enable GitHub OAuth2 provider. |
681
+ | `SECURITY_OAUTH2_GITHUB_CLIENT_ID` | string? | - | GitHub OAuth2 client ID. |
682
+ | `SECURITY_OAUTH2_GITHUB_CLIENT_SECRET` | string? | - | GitHub OAuth2 client secret. |
683
+ | `SECURITY_OAUTH2_GITHUB_USER_INFO_URL` | string | `'https://api.github.com/user'` | GitHub user info endpoint. |
684
+ | `SECURITY_OAUTH2_GITHUB_AUTHORIZATION_PARAMS` | record | `{}` | Extra query parameters of the authorization request, i.e. `prompt:select_account`. See [security](./security.md#authorization-parameters). |
685
+
686
+ #### OAuth2 GitLab
687
+
688
+ | Property | Type | Default | Description |
689
+ |-----------------------------------------------|---------|------------------------------------|--------------------------------------------------------------------------------------------------------------|
690
+ | `SECURITY_OAUTH2_GITLAB_ENABLED` | boolean | `false` | Enable GitLab OAuth2 provider. |
691
+ | `SECURITY_OAUTH2_GITLAB_CLIENT_ID` | string? | - | GitLab OAuth2 client ID. |
692
+ | `SECURITY_OAUTH2_GITLAB_CLIENT_SECRET` | string? | - | GitLab OAuth2 client secret. |
693
+ | `SECURITY_OAUTH2_GITLAB_BASE_URL` | string | `'https://gitlab.com'` | Instance base URL for the authorize and token endpoints. Change it for self-managed GitLab. |
694
+ | `SECURITY_OAUTH2_GITLAB_USER_INFO_URL` | string | `'https://gitlab.com/api/v4/user'` | GitLab user info endpoint. |
695
+ | `SECURITY_OAUTH2_GITLAB_AUTHORIZATION_PARAMS` | record | `{}` | Extra query parameters of the authorization request. See [security](./security.md#authorization-parameters). |
696
+
697
+ #### OAuth2 LinkedIn
698
+
699
+ | Property | Type | Default | Description |
700
+ |-------------------------------------------------|---------|------------------------------------------|--------------------------------------------------------------------------------------------------------------|
701
+ | `SECURITY_OAUTH2_LINKEDIN_ENABLED` | boolean | `false` | Enable LinkedIn OAuth2 provider. |
702
+ | `SECURITY_OAUTH2_LINKEDIN_CLIENT_ID` | string? | - | LinkedIn OAuth2 client ID. |
703
+ | `SECURITY_OAUTH2_LINKEDIN_CLIENT_SECRET` | string? | - | LinkedIn OAuth2 client secret. |
704
+ | `SECURITY_OAUTH2_LINKEDIN_USER_INFO_URL` | string | `'https://api.linkedin.com/v2/userinfo'` | LinkedIn user info endpoint. |
705
+ | `SECURITY_OAUTH2_LINKEDIN_AUTHORIZATION_PARAMS` | record | `{}` | Extra query parameters of the authorization request. See [security](./security.md#authorization-parameters). |
706
+
707
+ #### OAuth2 Apple
708
+
709
+ Apple expects the client secret to be a short-lived ES256 JWT: either set `SECURITY_OAUTH2_APPLE_CLIENT_SECRET` to one
710
+ you generated yourself, or provide the team ID, key ID and `.p8` private key and let the framework sign one at startup.
711
+
712
+ | Property | Type | Default | Description |
713
+ |--------------------------------------------------|----------|----------|--------------------------------------------------------------------------------------------------------------------------------------------|
714
+ | `SECURITY_OAUTH2_APPLE_ENABLED` | boolean | `false` | Enable Apple OAuth2 provider. |
715
+ | `SECURITY_OAUTH2_APPLE_CLIENT_ID` | string? | - | Apple OAuth2 client ID (the Services ID identifier, e.g. `com.example.service`). |
716
+ | `SECURITY_OAUTH2_APPLE_CLIENT_SECRET` | string? | - | Pre-generated client secret JWT. Takes precedence over the signing key settings below. |
717
+ | `SECURITY_OAUTH2_APPLE_TEAM_ID` | string? | - | Apple developer team ID. |
718
+ | `SECURITY_OAUTH2_APPLE_KEY_ID` | string? | - | Identifier of the `.p8` signing key. |
719
+ | `SECURITY_OAUTH2_APPLE_PRIVATE_KEY` | string? | - | Contents of the `.p8` private key (PEM). Escaped `\n` sequences are restored. |
720
+ | `SECURITY_OAUTH2_APPLE_PRIVATE_KEY_PATH` | string? | - | Path to the `.p8` private key file. Used when the inline key is not set. |
721
+ | `SECURITY_OAUTH2_APPLE_CLIENT_SECRET_EXPIRES_IN` | duration | `'180d'` | Lifetime of the generated Apple client secret, milliseconds or a duration string. Apple rejects anything above six months (`15777000000`). |
722
+ | `SECURITY_OAUTH2_APPLE_AUTHORIZATION_PARAMS` | record | `{}` | Extra query parameters of the authorization request. See [security](./security.md#authorization-parameters). |
723
+
724
+ #### OAuth2 Microsoft
725
+
726
+ | Property | Type | Default | Description |
727
+ |--------------------------------------------------|---------|-----------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
728
+ | `SECURITY_OAUTH2_MICROSOFT_ENABLED` | boolean | `false` | Enable Microsoft OAuth2 provider. |
729
+ | `SECURITY_OAUTH2_MICROSOFT_CLIENT_ID` | string? | - | Microsoft OAuth2 client ID (the Entra ID application ID). |
730
+ | `SECURITY_OAUTH2_MICROSOFT_CLIENT_SECRET` | string? | - | Microsoft OAuth2 client secret. |
731
+ | `SECURITY_OAUTH2_MICROSOFT_TENANT` | string | `'common'` | Tenant used in the authorize and token endpoints: a tenant ID, `common`, `organizations` or `consumers`. |
732
+ | `SECURITY_OAUTH2_MICROSOFT_USER_INFO_URL` | string | `'https://graph.microsoft.com/v1.0/me'` | Microsoft Graph user info endpoint. |
733
+ | `SECURITY_OAUTH2_MICROSOFT_AUTHORIZATION_PARAMS` | record | `{}` | Extra query parameters of the authorization request, i.e. `prompt:select_account`. See [security](./security.md#authorization-parameters). |
734
+
735
+ #### OAuth2 Custom (OpenID Connect)
736
+
737
+ | Property | Type | Default | Description |
738
+ |-----------------------------------------------|---------|---------|-----------------------------------------------------------------------------------------------------------------------------------|
739
+ | `SECURITY_OAUTH2_CUSTOM_ENABLED` | boolean | `false` | Enable custom OpenID Connect provider. |
740
+ | `SECURITY_OAUTH2_CUSTOM_CLIENT_ID` | string? | - | Custom OAuth2 client ID. |
741
+ | `SECURITY_OAUTH2_CUSTOM_CLIENT_SECRET` | string? | - | Custom OAuth2 client secret. |
742
+ | `SECURITY_OAUTH2_CUSTOM_ISSUER` | string? | - | OpenID Connect issuer URL (used for discovery). |
743
+ | `SECURITY_OAUTH2_CUSTOM_AUTHORIZATION_PARAMS` | record | `{}` | Extra query parameters of the authorization request, i.e. `prompt:login`. See [security](./security.md#authorization-parameters). |
744
+
745
+ ### Database (DATABASE\_\*)
746
+
747
+ | Property | Type | Default | Description |
748
+ |-----------------------------------------|----------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
749
+ | `DATABASE_TYPE` | enum? | - | Database type. Values: `sqlite`, `postgresql`, `mysql`, `sqlserver`. |
750
+ | `DATABASE_URL` | string | `''` | Database connection URL/DSN the application queries the data with. |
751
+ | `DATABASE_MIGRATION_URL` | string | `''` | Connection URL/DSN of the migrations and the `weaver migrate` setup, `''` for the URL. |
752
+ | `DATABASE_KEEP_TABLES` | enum[] | `[]` | Framework tables kept while their feature is off: `ApiKey`, `OneTimeToken`, `ConnectedAccount`, `TwoFactorMethod`, `AuditLog`. |
753
+ | `DATABASE_SCHEMA_PATH` | string | `'./database/schema.prisma'` | Path to Prisma schema file. |
754
+ | `DATABASE_MIGRATIONS_DIR_PATH` | string | `'./database/migrations'` | Path to database migrations directory. |
755
+ | `DATABASE_SEEDERS_DIR_PATH` | string | `'./database/seeders'` | Path to database seeders directory. |
756
+ | `DATABASE_SQL_DIR_PATH` | string | `'./database/sql'` | Path to the SQL migrations directory, applied by `weaver migrate` after the Prisma migrations. |
757
+ | `DATABASE_CLIENT_OUTPUT_DIR_PATH` | string | `'./database/client'` | Path for generated Prisma client output. |
758
+ | `DATABASE_TRANSACTION_MAX_WAIT` | duration | `2000` | Max wait time for acquiring a transaction lock, milliseconds or a duration string. |
759
+ | `DATABASE_TRANSACTION_TIMEOUT` | duration | `5000` | Transaction timeout, milliseconds or a duration string. |
760
+ | `DATABASE_AI_DANGEROUS_ACTIONS_ENABLED` | boolean | `true` | Allow an AI agent to run dangerous Prisma actions, i.e. reset (disable for production). |
761
+ | `DATABASE_LOG_EVENTS` | enum[] | `[]` | List of database events to log. Values: `query`, `info`, `warn`, `error` |
762
+ | `DATABASE_SLOW_QUERY_THRESHOLD` | duration | `0` | Duration from which a query is logged as a warning by the `database` logger, milliseconds or a duration string, `0` to disable it. |
763
+ | `DATABASE_PROVIDER` | string | `'auto'` | `auto` or `prisma`, or `none` for an application without a database. |
764
+
765
+ The application starts and keeps running while the database is unreachable, whatever its type. The connection is
766
+ checked on startup, an unreachable database is logged as an error naming its URL without the password, and its queries
767
+ fail until it is reachable again.
768
+
769
+ ### File storage (STORAGE\_\*)
770
+
771
+ | Property | Type | Default | Description |
772
+ |------------------------------|----------|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
773
+ | `STORAGE_PATH` | string | `'./storage'` | Base directory for file storage. |
774
+ | `STORAGE_RESERVED_PATHS` | string[] | `['__keys__']` | Paths inside the storage directory that files can never be stored under. Each entry is a directory or a full file name relative to `STORAGE_PATH`, matched case-insensitively (no wildcards). Violations fail on startup for configured name patterns, and with a `400` error at runtime. |
775
+ | `STORAGE_NAME_PATTERN` | string | `'{name}-{hash}.{extension}'` | File naming pattern for stored files. |
776
+ | `STORAGE_CACHE_TTL` | duration | `86400000` | File storage cache TTL, milliseconds or a duration string. |
777
+ | `STORAGE_URL_TTL` | duration | `900000` | How long the URL of a storage serving its files directly (i.e. a signed URL) is valid, milliseconds or a duration string. |
778
+ | `STORAGE_FILES_ROUTE_PREFIX` | string | `'/files'` | URL prefix for file access routes. |
779
+ | `STORAGE_PROVIDER` | string | `'auto'` | `auto` (`local` unless another storage driver is enabled), `local`, `none`, or a module path. |
780
+
781
+ ### File versions (STORAGE_VERSIONS\_\*)
782
+
783
+ | Property | Type | Default | Description |
784
+ |------------------------------|-----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
785
+ | `STORAGE_VERSIONS_ENABLED` | boolean | `false` | Keep the previous versions of the files when a file is uploaded again, and register the routes listing and deleting them. The `versions` of a file field overrides the limits, `false` turns it off for the field. |
786
+ | `STORAGE_VERSIONS_MAX_COUNT` | integer | `10` | The most versions of a file kept, the current one included, `0` for no limit. |
787
+ | `STORAGE_VERSIONS_MAX_AGE` | duration? | - | How long a version is kept once replaced, milliseconds or a duration string (`'30d'`), kept until `MAX_COUNT` drops it when unset. |
788
+
789
+ ### Image processing (IMAGE\_\*)
790
+
791
+ | Property | Type | Default | Description |
792
+ |------------------|--------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
793
+ | `IMAGE_PROVIDER` | string | `'auto'` | Image processor of the uploads: `auto` (`sharp` with `@appweaver/sharp`, otherwise none, keeping the images as uploaded), `sharp`, `none`, or a module path. |
794
+
795
+ ### Memory (MEMORY\_\*)
796
+
797
+ The key-value store with locks behind the cache, the rate limit, the memory security store and the BullMQ queue: kept
798
+ in the process (`memory`) or in Redis (`redis`).
799
+
800
+ | Property | Type | Default | Description |
801
+ |------------------------------------------|----------|------------------------------|--------------------------------------------------------------------------------------------------------------------|
802
+ | `MEMORY_PROVIDER` | string | `'auto'` | `auto` (`redis` with `@appweaver/redis`, otherwise `memory`), `memory`, `redis`, or a module path. |
803
+ | `MEMORY_MAX_SIZE` | size? | - | Maximum size of the in-memory store, bytes or a size string (`'64MB'`). Unlimited when unset. |
804
+ | `MEMORY_REDIS_URL` | string | `'redis://localhost:6379/0'` | Redis connection URL of the `redis` provider (`config.memory.redis.url`). |
805
+ | `MEMORY_REDIS_COMMAND_TIMEOUT` | duration | `200` | How long a command waits for its reply before it fails, milliseconds or a duration string, `0` waits indefinitely. |
806
+ | `MEMORY_REDIS_CIRCUIT_BREAKER_THRESHOLD` | integer | `5` | Consecutive failed commands opening the circuit breaker, `0` disables it. |
807
+ | `MEMORY_REDIS_CIRCUIT_BREAKER_COOLDOWN` | duration | `10000` | How long the open circuit breaker skips Redis before probing it, milliseconds or a duration string. |
808
+
809
+ The application starts and keeps running while Redis is unreachable. Connections reconnect in the background, each
810
+ outage and recovery is logged once, and commands fail right away instead of waiting for the reconnection, or after
811
+ `MEMORY_REDIS_COMMAND_TIMEOUT` when Redis stops answering. After `MEMORY_REDIS_CIRCUIT_BREAKER_THRESHOLD` such failures
812
+ in a row the circuit breaker skips Redis (`isAvailable()` is `false`) until a probe after the cooldown, or a
813
+ reconnection, succeeds. The failures are `MEMORY_UNAVAILABLE` errors (`503`). By default the cache falls back to the
814
+ database (see `CACHE_SKIP_ON_ERROR`), rate limiting is skipped except on the secure routes (see
815
+ `RATE_LIMIT_SECURE_SKIP_ON_ERROR`), and queues throw (see [queue.md](./queue.md#unavailable-backend)). The BullMQ
816
+ connections have neither the timeout nor the breaker, which would fail their blocking commands.
817
+
818
+ ### Cache (CACHE\_\*)
819
+
820
+ | Property | Type | Default | Description |
821
+ |-------------------------------|----------|--------------------|------------------------------------------------------------------------------------------|
822
+ | `CACHE_ENABLED` | boolean | `true` | Enable the caching system. |
823
+ | `CACHE_CLEAN_START` | boolean | `false` | Clear all cache entries on application startup. |
824
+ | `CACHE_KEY_PREFIX` | string | `'cache:'` | Prefix prepended to all cache keys. |
825
+ | `CACHE_MAX_ITEMS` | integer | `1000` | Maximum number of items in the cache. |
826
+ | `CACHE_MAX_SIZE` | size? | - | Maximum size used by the cache, bytes or a size string (`'64MB'`). Unlimited when unset. |
827
+ | `CACHE_DEFAULT_TTL` | duration | `5000` | Default time-to-live of the cache entries, milliseconds or a duration string. |
828
+ | `CACHE_EVICTION_GRACE_PERIOD` | duration | `1000` | Grace period before evicting the expired items, milliseconds or a duration string. |
829
+ | `CACHE_EVICTION_STRATEGY` | enum | `'LRU'` | Eviction strategy. Values: `LRU`, `LFU`, `FIFO`. |
830
+ | `CACHE_EVICTION_DEFERRED` | boolean | `false` | Defer eviction to a background process. |
831
+ | `CACHE_INVALIDATION_STRATEGY` | enum | `'expire-related'` | Invalidation strategy. Values: `expire-related`, `expire-all`, `none`. |
832
+ | `CACHE_INVALIDATION_DEFERRED` | boolean | `false` | Defer invalidation to a background process. |
833
+ | `CACHE_SKIP_ON_ERROR` | boolean | `true` | Return empty results instead of failing when the cache backend errors. |
834
+ | `CACHE_PROVIDER` | string | `'auto'` | `auto` or `memory` (stored in the `Memory` provider), `none`, or a module path. |
835
+
836
+ ### Time series (TIMESERIES\_\*)
837
+
838
+ The store of the `series` fields of the models, see [timeseries.md](./timeseries.md).
839
+
840
+ | Property | Type | Default | Description |
841
+ |--------------------------------------|----------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
842
+ | `TIMESERIES_INGEST` | enum | `'direct'` | How the points are written: `direct`, `queue` (by a queue worker), or `auto` (queued on a durable queue only). A model overrides it with `seriesOptions.ingest`. |
843
+ | `TIMESERIES_MAX_POINTS_PER_WRITE` | integer | `5000` | Maximum number of points a write accepts. |
844
+ | `TIMESERIES_MAX_POINTS_PER_QUERY` | integer | `10000` | Maximum number of points a query returns, and its default limit. |
845
+ | `TIMESERIES_MAX_RESOURCES_PER_QUERY` | integer | `100` | Maximum number of resources a query or a write of many resources covers. |
846
+ | `TIMESERIES_QUEUE_NAME` | string | `'timeseries'` | Name of the queue the queued points are sent to. |
847
+ | `TIMESERIES_QUEUE_BATCH_SIZE` | integer | `1000` | Maximum number of points of a queue job, a larger write is split into several jobs. |
848
+ | `TIMESERIES_QUEUE_CONCURRENCY` | integer | `1` | Number of jobs the worker writes at once. |
849
+ | `TIMESERIES_QUEUE_WORKER` | boolean | `true` | Run the worker writing the queued points in this instance, `false` for an instance only queueing them. |
850
+ | `TIMESERIES_ACCESS_CACHE_TTL` | duration | `0` | How long the routes keep the result of the access check of a resource, milliseconds or a duration string, so a frequent writer is not checked on every request, `0` to check every request. |
851
+ | `TIMESERIES_PROVIDER` | string | `'auto'` | `auto` (the driver of an enabled module, otherwise `database` with `@appweaver/data`), `database`, `timescale`, `memory`, `none`, or a module path. |
852
+
853
+ #### Database (TIMESERIES_DATABASE\_\*)
854
+
855
+ The `database` provider (`config.timeseries.database`), of `@appweaver/data`. The retention is overridden by the
856
+ `seriesOptions.retention` of a model.
857
+
858
+ | Property | Type | Default | Description |
859
+ |---------------------------------|-----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
860
+ | `TIMESERIES_DATABASE_RETENTION` | duration? | - | How long the `database` provider keeps the points, milliseconds or a duration string of whole seconds (`'365d'`), overridden by the `seriesOptions.retention` of a model, every point kept when unset. |
861
+
862
+ #### TimescaleDB (TIMESERIES_TIMESCALE\_\*)
863
+
864
+ The `timescale` provider (`config.timeseries.timescale`), of `@appweaver/data`. The durations are overridden by the
865
+ `seriesOptions` of a model.
866
+
867
+ | Property | Type | Default | Description |
868
+ |---------------------------------------|-----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
869
+ | `TIMESERIES_TIMESCALE_CHUNK_INTERVAL` | duration | `'7d'` | Time range of a chunk of the hypertables, milliseconds or a duration string of whole seconds (`'7d'`), overridden by the `seriesOptions.chunkInterval` of a model. |
870
+ | `TIMESERIES_TIMESCALE_COMPRESS_AFTER` | duration? | - | Age from which the chunks are compressed, milliseconds or a duration string of whole seconds (`'30d'`), overridden by the `seriesOptions.compressAfter` of a model, none compressed when unset. |
871
+ | `TIMESERIES_TIMESCALE_RETENTION` | duration? | - | Age from which the chunks are dropped, milliseconds or a duration string of whole seconds (`'365d'`), overridden by the `seriesOptions.retention` of a model, every point kept when unset. |
872
+ | `TIMESERIES_TIMESCALE_SETUP_TIMEOUT` | duration | `60000` | Maximum time the hypertables and their policies take to set up at startup, milliseconds or a duration string. |
873
+
874
+ ### Spatial (SPATIAL\_\*)
875
+
876
+ How the spatial fields of the models are queried, of `@appweaver/data`, see [spatial.md](./spatial.md). Changing the
877
+ provider changes the generated schema.
878
+
879
+ | Property | Type | Default | Description |
880
+ |--------------------------|----------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
881
+ | `SPATIAL_PROVIDER` | enum | `'auto'` | How `_near`, `_within` and `_intersects` are matched: `auto` (`postgis` on PostgreSQL, `database` otherwise), `postgis` (PostgreSQL with PostGIS) or `database` (every database). |
882
+ | `SPATIAL_MAX_CANDIDATES` | integer | `10000` | Maximum number of records a `_near`, `_within` or `_intersects` filter matches, at most `2000` on SQL Server. |
883
+ | `SPATIAL_MAX_VERTICES` | integer | `10000` | Maximum number of positions of a geometry, written or given to a spatial filter. |
884
+ | `SPATIAL_SETUP_TIMEOUT` | duration | `60000` | Maximum time, milliseconds or a duration string the `postgis` provider takes to create its triggers and write the geometries missing at startup, raised for the first start on a large table. |
885
+
886
+ ### Audit log (AUDIT\_\*)
887
+
888
+ The requests and the changes of the records, in the `AuditLog` and `AuditChange` tables (see
889
+ [audit.md](audit.md)). Every category has its own `ENABLED` and `RETENTION`, an empty retention falling back to
890
+ `AUDIT_RETENTION`.
891
+
892
+ | Property | Type | Default | Description |
893
+ |---------------------------|-----------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
894
+ | `AUDIT_ENABLED` | boolean | `false` | Record the requests and the changes of the records. |
895
+ | `AUDIT_RETENTION` | duration | `'90d'` | How long the entries are kept, milliseconds or a duration string (`'90d'`), overridden by the `retention` of a category, `0` to keep them all. |
896
+ | `AUDIT_FLUSH_INTERVAL` | duration | `'1s'` | How often the buffered entries are written to the database, milliseconds or a duration string. |
897
+ | `AUDIT_BATCH_SIZE` | integer | `100` | The buffered entries written at once without waiting for the flush interval. |
898
+ | `AUDIT_MAX_BUFFER` | integer | `10000` | The most rows buffered, an entry and each of its changes, the oldest entries dropped beyond it (`appweaver.audit.dropped`). |
899
+ | `AUDIT_WRITE_VIA` | enum | `'direct'` | How the batches are written: `direct` to the database, or `queue` as jobs of the `audit` queue. |
900
+ | `AUDIT_WRITE_WORKER` | boolean | `true` | Write the batches of the `audit` queue in this instance (`audit.writeVia: 'queue'`). |
901
+ | `AUDIT_EXCLUDE_MODELS` | string[] | `[]` | Models whose requests and changes are left out. |
902
+ | `AUDIT_EXCLUDE_ACTIONS` | string[] | `[]` | Actions left out, of every model (`find`, `export`, `auth.refresh`) or of one (`Post.update`). |
903
+ | `AUDIT_EXCLUDE_PATHS` | string[] | `[]` | URL paths left out, exact or a prefix ending with `*`. The health check, Swagger, static file and template preview routes always are. |
904
+ | `AUDIT_REDACT_KEYS` | string[] | `['code']` | Key and field names redacted besides the hidden and `redact` fields and the names of secrets (`password`, `token`, `apiKey`, ...), compared case-insensitively. |
905
+ | `AUDIT_ANONYMIZE_IP` | boolean | `false` | Record the client addresses without their last octet (IPv4) or last 80 bits (IPv6). |
906
+ | `AUDIT_MAX_VALUE_SIZE` | integer | `2048` | The longest value of a field in a diff or a body, in characters of its JSON, a longer one truncated. |
907
+ | `AUDIT_REQUEST_BODY` | boolean | `false` | Record the JSON bodies of the requests other than the reading ones, their secrets redacted. |
908
+ | `AUDIT_CHANGES_ENABLED` | boolean | `true` | Record the changed fields of the records the resource services create, update and delete (`AuditChange`). |
909
+ | `AUDIT_CHANGES_RETENTION` | duration? | - | How long the entries of the changes made outside of a request (jobs, tasks) are kept, milliseconds or a duration string, `audit.retention` when unset. |
910
+ | `AUDIT_AUTH_ENABLED` | boolean | `true` | Record the requests of the authentication and account routes, failed ones included. |
911
+ | `AUDIT_AUTH_RETENTION` | duration? | - | How long the entries are kept, milliseconds or a duration string, `audit.retention` when unset. |
912
+ | `AUDIT_READ_ENABLED` | boolean | `false` | Record the reading requests: `find`, `query`, `aggregate`, `export` and the `GET` routes. |
913
+ | `AUDIT_READ_RETENTION` | duration? | - | How long the entries are kept, milliseconds or a duration string, `audit.retention` when unset. |
914
+ | `AUDIT_WRITE_ENABLED` | boolean | `true` | Record the writing requests: create, update, delete, bulk, file and the routes of the other methods. |
915
+ | `AUDIT_WRITE_RETENTION` | duration? | - | How long the entries are kept, milliseconds or a duration string, `audit.retention` when unset. |
916
+ | `AUDIT_CUSTOM_ENABLED` | boolean | `true` | Record the entries the application adds with `AuditService.record`. |
917
+ | `AUDIT_CUSTOM_RETENTION` | duration? | - | How long the entries are kept, milliseconds or a duration string, `audit.retention` when unset. |
918
+ | `AUDIT_ROUTES_ENABLED` | boolean | `false` | Serve the read-only routes of the audit log (`/audit-logs`, `/audit-changes`: `find`, `query`), with the service and the policy of the models. |
919
+ | `AUDIT_ROUTES_ROLES` | string[] | `['Admin']` | The roles allowed to read them. |
920
+
921
+ ### Job queue (QUEUE\_\*)
922
+
923
+ | Property | Type | Default | Description |
924
+ |------------------------------|-----------|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
925
+ | `QUEUE_KEEP_COMPLETED_COUNT` | integer | `0` | Number of completed jobs to retain in the queue. |
926
+ | `QUEUE_KEEP_COMPLETED` | duration? | - | How long the completed jobs are kept, milliseconds or a duration string (`'1h'`). Unlimited when unset. |
927
+ | `QUEUE_KEEP_FAILED_COUNT` | integer | `50` | Number of failed jobs to retain in the queue. |
928
+ | `QUEUE_KEEP_FAILED` | duration? | - | How long the failed jobs are kept, milliseconds or a duration string (`'7d'`). Unlimited when unset. |
929
+ | `QUEUE_RETRY_ATTEMPTS` | integer | `3` | Number of retry attempts for failed jobs. |
930
+ | `QUEUE_RETRY_BACKOFF` | duration | `3000` | Initial backoff delay between retries, milliseconds or a duration string. |
931
+ | `QUEUE_RETRY_BACKOFF_TYPE` | enum | `'fixed'` | Retry backoff type. Values: `fixed`, `exponential`. |
932
+ | `QUEUE_WAIT_TIMEOUT` | duration | `30000` | How long a caller waits for the result of a job it sent, i.e. a text message sent with `sendAndWait`, before it fails with `QUEUE_JOB_TIMEOUT`, milliseconds or a duration string. |
933
+ | `QUEUE_PROVIDER` | string | `'auto'` | `auto` (`bullmq` with `@appweaver/bullmq`, otherwise `memory`), `memory`, `bullmq`, `none`, or a module path. |
934
+ | Property | Type | Default | Description |
935
+ | `MAINTENANCE_ENABLED` | boolean | `true` | Run the maintenance jobs on their schedule in this instance, `false` for the instances leaving them to another one or to `weaver run maintenance`. |
936
+ | `MAINTENANCE_BATCH_SIZE` | integer | `1000` | The most records a delete of a job removes at once, so a purge never holds a long lock. |
937
+ | `MAINTENANCE_LOCK_TTL` | duration | `'1h'` | How long a run holds the lock keeping the other instances from running the job, released when it ends. |
938
+ | `MAINTENANCE_JOBS` | record | `{}` | The `schedule` (an interval, or a cron expression needing the `Scheduler`) and the `enabled` switch of each job by its name, i.e. `MAINTENANCE_JOBS_AUDIT_RETENTION_SCHEDULE=0 3 * * *`. |
939
+
940
+ ### Scheduler (SCHEDULER\_\*)
941
+
942
+ | Property | Type | Default | Description |
943
+ |----------------------------|---------|----------|-------------------------------------------------------------------------------------------|
944
+ | `SCHEDULER_AUTO_START_JOB` | boolean | `true` | Auto-start scheduled jobs on application startup. |
945
+ | `SCHEDULER_PROVIDER` | string | `'auto'` | `auto` (`cron` with `@appweaver/cron`, otherwise none), `cron`, `none`, or a module path. |
946
+
947
+ ### Events (EVENTS\_\*)
948
+
949
+ | Property | Type | Default | Description |
950
+ |------------------------|---------|----------|-----------------------------------------|
951
+ | `EVENTS_MAX_LISTENERS` | integer | `20` | Maximum event listeners per event type. |
952
+ | `EVENTS_PROVIDER` | string | `'auto'` | `auto` or `node`, or a module path. |
953
+
954
+ ### Pub/sub (PUBSUB\_\*)
955
+
956
+ The publish/subscribe of the messages every instance receives, i.e. the events of the realtime connections.
957
+
958
+ | Property | Type | Default | Description |
959
+ |-------------------------------|--------|----------------|------------------------------------------------------------------------------------------------------------|
960
+ | `PUBSUB_PROVIDER` | string | `'auto'` | `auto` (`redis` with `@appweaver/redis`, otherwise `memory`), `memory`, `redis`, `none`, or a module path. |
961
+ | `PUBSUB_REDIS_CHANNEL_PREFIX` | string | `'appweaver:'` | Prefix of the Redis channels the messages are published to, on the server of `MEMORY_REDIS_URL`. (redis) |
962
+
963
+ ### Realtime (REALTIME\_\*)
964
+
965
+ The realtime connections of `@appweaver/realtime` ([realtime.md](./realtime.md)).
966
+
967
+ | Property | Type | Default | Description |
968
+ |---------------------------------------------|----------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
969
+ | `REALTIME_ENABLED` | boolean | `true` | Enable the realtime routes: the tickets, the event streams, the WebSocket and the actions. |
970
+ | `REALTIME_ROUTE_PREFIX` | string | `'/realtime'` | Prefix of the realtime routes, under the API prefix. |
971
+ | `REALTIME_SSE_ENABLED` | boolean | `true` | Enable the Server-Sent Events transport (`GET <prefix>/events`). |
972
+ | `REALTIME_WEBSOCKET_ENABLED` | boolean | `true` | Enable the WebSocket transport (`GET <prefix>/ws`). |
973
+ | `REALTIME_ANONYMOUS_ENABLED` | boolean | `false` | Allow the anonymous clients: connections without a ticket and HTTP action calls without credentials, limited to the `public` channels and actions. |
974
+ | `REALTIME_TICKET_TTL` | duration | `30000` | How long a connection ticket is valid for, used once, milliseconds or a duration string. |
975
+ | `REALTIME_HEARTBEAT_INTERVAL` | duration | `25000` | Time between the heartbeats of a connection, a WebSocket ping or an SSE comment, milliseconds or a duration string. |
976
+ | `REALTIME_CONNECTION_MAX_AGE` | duration | `3600000` | How long a connection stays open before the client has to reconnect with a new ticket, closed earlier when the token it was opened with expires, milliseconds or a duration string, `0` for no limit. |
977
+ | `REALTIME_MAX_CONNECTIONS` | integer | `10000` | Maximum number of open connections of the instance, `0` for no limit. |
978
+ | `REALTIME_MAX_CONNECTIONS_PER_USER` | integer | `10` | Maximum number of open connections of a user on the instance, `0` for no limit. |
979
+ | `REALTIME_MAX_ANONYMOUS_CONNECTIONS_PER_IP` | integer | `10` | Maximum number of open anonymous connections of an IP address on the instance, `0` for no limit (the IP of `SERVER_TRUST_PROXY`). |
980
+ | `REALTIME_MAX_SUBSCRIPTIONS` | integer | `50` | Maximum number of subscriptions of a connection. |
981
+ | `REALTIME_MAX_MESSAGE_SIZE` | size | `'64KB'` | Maximum size of a WebSocket message of a client, bytes or a size string. |
982
+ | `REALTIME_SEND_BUFFER_LIMIT` | size | `'1MB'` | Size a connection may have waiting to be sent before it is closed as too slow, bytes or a size string. |
983
+ | `REALTIME_MESSAGE_RATE_LIMIT` | integer | `20` | Maximum number of WebSocket messages a client sends per second, `0` for no limit. |
984
+ | `REALTIME_STREAM_REPLAY_LIMIT` | size | `'256KB'` | Size of the last chunks a stream keeps for the subscribers joining late or resuming, unless the stream sets its own `replay.maxSize`, bytes or a size string. |
985
+ | `REALTIME_STREAM_HIGH_WATER_MARK` | size | `'64KB'` | Size a subscriber of a stream may have waiting to be sent before `ready` of the writer waits, pausing the producer, i.e. the generator of a streaming action, bytes or a size string. |
986
+ | `REALTIME_STREAM_LINGER` | duration | `10000` | How long an ended stream, or a streaming action whose client disconnected, stays resumable, milliseconds or a duration string. |
987
+ | `REALTIME_STREAM_RELAY_FLUSH_INTERVAL` | duration | `20` | How long the chunks of a stream are batched for before they are relayed to the other instances, milliseconds or a duration string. |
988
+ | `REALTIME_STREAM_RELAY_MAX_BATCH` | size | `'64KB'` | Size of the chunks relayed to the other instances in one message at most, sent before the flush interval once reached, bytes or a size string. |
989
+ | `REALTIME_STREAM_RELAY_HEARTBEAT` | duration | `5000` | Time between the messages keeping the relay of the streams between the instances alive, a relayed stream silent for three of them being lost, milliseconds or a duration string. |
990
+ | `REALTIME_STREAM_INPUT_WINDOW` | size | `'256KB'` | Size a client may stream to an action ahead of its handler reading them, given back as the handler reads, bytes or a size string. |
991
+ | `REALTIME_STREAM_INPUT_MAX_SIZE` | size | `'10MB'` | Size a client may stream to an action in all, unless the action sets its own `input.maxSize`, bytes or a size string. |
992
+ | `REALTIME_SHUTDOWN_GRACE_PERIOD` | duration | `30000` | How long a shutting down instance waits for its calls to end, i.e. the answers of an LLM, after moving its clients to the other instances (close code `1012`), milliseconds or a duration string, `0` to end them at once. |
993
+
994
+ ### MCP (MCP\_\*)
995
+
996
+ The MCP server of `@appweaver/mcp` ([mcp.md](./mcp.md)).
997
+
998
+ | Property | Type | Default | Description |
999
+ |-------------------------------|----------|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
1000
+ | `MCP_ENABLED` | boolean | `true` | Enable the MCP endpoint. |
1001
+ | `MCP_ROUTE_PREFIX` | string | `'/mcp'` | Path of the MCP endpoint, at the root (`'/api/mcp'` under the API). |
1002
+ | `MCP_AUTH` | string[] | `['jwt', 'apiKey']` | The authentication strategies of the endpoint. |
1003
+ | `MCP_ANONYMOUS_ENABLED` | boolean | `false` | Allow the anonymous clients, which see only the `public` tools. |
1004
+ | `MCP_DESTRUCTIVE_ENABLED` | boolean | `false` | Expose the destructive tools: the `update` and `delete` resource actions and the `destructive` tools. |
1005
+ | `MCP_SERVER_NAME` | string? | `app.name` | The name of the server shown to the agents. |
1006
+ | `MCP_INSTRUCTIONS` | string? | - | Instructions for the agents, i.e. what the application is for. |
1007
+ | `MCP_MAX_LIMIT` | integer | `50` | The maximum records a query tool returns, unless its resource sets `maxLimit`. |
1008
+ | `MCP_MAX_RESULT_SIZE` | size | `'256KB'` | The maximum size of the result of a tool, bytes or a size string. |
1009
+ | `MCP_ALLOWED_ORIGINS` | string[] | `[]` | Browser origins allowed to call the endpoint (`*` for any); requests without `Origin` always pass. |
1010
+ | `MCP_LOG_CALLS` | boolean | `true` | Log every tool call at the info level. |
1011
+ | `MCP_CACHE_ENABLED` | boolean | `false` | Cache the results of the read-only tools (the read resource actions, the tools setting `cache`). |
1012
+ | `MCP_CACHE_TTL` | duration | `5000` | Time-to-live of a cached result, milliseconds or a duration string, unless the tool sets its own. |
1013
+ | `MCP_RATE_LIMIT_ENABLED` | boolean | `false` | Limit the tool calls of each authenticated user, counted in the `Memory` provider. |
1014
+ | `MCP_RATE_LIMIT_MAX` | integer | `60` | Maximum tool calls of a user per window. |
1015
+ | `MCP_RATE_LIMIT_WINDOW` | duration | `60000` | The window, milliseconds or a duration string. |
1016
+ | `MCP_OAUTH2_ENABLED` | boolean | `false` | Make the application the OAuth 2.1 authorization server of the MCP clients (discovery, DCR, PKCE). |
1017
+ | `MCP_OAUTH2_ROUTE_PREFIX` | string | `'/oauth'` | Path of the authorization, token and registration endpoints. |
1018
+ | `MCP_OAUTH2_PROVIDERS` | string[] | `[]` | The `security.oauth2` providers offered to sign in (`google`, `github`, ...), every enabled one by default. |
1019
+ | `MCP_OAUTH2_FORMS_ENABLED` | boolean | `true` | Ask for the password of an account to link and the 2FA code, otherwise refuse these users. |
1020
+ | `MCP_OAUTH2_PASSWORD_ENABLED` | boolean | `false` | Offer the email and password form on the sign-in page, counted with the API logins; needs the forms, left out while the login requires a bot check. |
1021
+
1022
+ ### AI (AI\_\*)
1023
+
1024
+ The AI models of `@appweaver/ai` ([ai.md](./ai.md)): the endpoints by their names, the default models and the aliases
1025
+ the code calls the models by. A model reference is `<endpoint>:<model>` (`local:qwen3:8b`), the built-in `mock`
1026
+ endpoint answering without a server.
1027
+
1028
+ | Property | Type | Default | Description |
1029
+ |------------------------------|----------|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1030
+ | `AI_ENDPOINTS` | record | `{}` | The endpoints by name, each with `preset` (`openai`, `openrouter`, `ollama`, `lmstudio`, `vllm`, `llamacpp`, `litellm`, `groq`, `together`, `fireworks`, `deepseek`, `mistral`, `xai`, `gemini`, `huggingface`, `mock`), `driver`, `baseUrl`, `apiKey`, `headers` (`Name: value`), `capabilities`, `timeout` and `maxRetries`. Each property is also its own variable, `AI_ENDPOINTS_<NAME>_<PROPERTY>` (`AI_ENDPOINTS_OPENROUTER_API_KEY`). |
1031
+ | `AI_DEFAULT_MODEL` | string? | - | The model of a call naming none, a model reference or an alias. |
1032
+ | `AI_DEFAULT_EMBEDDING_MODEL` | string? | - | The embedding model of a call naming none, a model reference or an alias. |
1033
+ | `AI_ALIASES` | record | `{}` | The names the code calls the models by (`fast`, `smart`, any name without `:`), each a model reference or a list of them tried in turn on a rate limit, a timeout or an unavailable provider (comma-separated in a variable). |
1034
+ | `AI_MAX_TOKENS` | integer? | - | The maximum output tokens of a call setting none. |
1035
+ | `AI_TEMPERATURE` | number? | - | The temperature of a call setting none. |
1036
+ | `AI_TIMEOUT` | duration | `120000` | The timeout of a request to a model, milliseconds or a duration string. |
1037
+ | `AI_MAX_RETRIES` | integer | `2` | Retries of a request failing with a rate limit, a timeout or a server error, unless the endpoint sets its own. |
1038
+ | `AI_MAX_STEPS` | integer | `5` | Maximum model calls of a call with tools, the model being called again with the results of the tools it called. |
1039
+ | `AI_REPAIR_ATTEMPTS` | integer | `1` | Calls repairing an object not matching its schema (`generateObject`), sent the validation errors. |
1040
+ | `AI_LOG_PROMPTS` | boolean | `false` | Log the prompts and the responses at the `debug` level. |
1041
+ | `AI_HEALTH_CHECK_ENDPOINTS` | string[] | `[]` | The endpoints the `ai` health check checks, by listing their models. |
1042
+ | `AI_QUEUE_CONCURRENCY` | integer | `4` | Jobs of the `ai` queue a worker runs at once. |
1043
+ | `AI_STREAM_FLUSH_INTERVAL` | duration | `50` | How long the parts of a queued stream are batched for before they are published, milliseconds or a duration string. |
1044
+
1045
+ ### Mailer (MAILER\_\*)
1046
+
1047
+ | Property | Type | Default | Description |
1048
+ |-------------------------|---------|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1049
+ | `MAILER_SENDER_NAME` | string? | - | Display name of the default sender of the emails, which send from the bare address without one. |
1050
+ | `MAILER_SENDER_ADDRESS` | string? | - | Address of the default sender of the emails, required by an enabled mailer, which fails to start without it. |
1051
+ | `MAILER_PROVIDER` | string | `'auto'` | `auto` (`smtp` with `@appweaver/nodemailer`, otherwise none), `smtp`, `json` (logs the emails, for development and tests), `none`, or a module path. Without a mailer the email features (email verification, password reset, the `email` 2FA method) respond with `501`. |
1052
+ | `MAILER_SMTP_HOST` | string | `'127.0.0.1'` | SMTP server hostname. |
1053
+ | `MAILER_SMTP_PORT` | integer | `587` | SMTP server port. |
1054
+ | `MAILER_SMTP_SECURE` | boolean | `false` | Use TLS/SSL for SMTP connections. |
1055
+ | `MAILER_SMTP_USER` | string? | - | SMTP authentication username. |
1056
+ | `MAILER_SMTP_PASSWORD` | string? | - | SMTP authentication password. |
1057
+
1058
+ ### SMS (SMS\_\*)
1059
+
1060
+ The messages are sent through the `sms` queue, see [sms](./sms.md).
1061
+
1062
+ | Property | Type | Default | Description |
1063
+ |------------------------------------|----------|--------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1064
+ | `SMS_SENDER` | string? | - | Default sender of the text messages, a phone number in the E.164 format or an alphanumeric sender ID. |
1065
+ | `SMS_PROVIDER` | string | `'auto'` | `auto` (`twilio` with `@appweaver/twilio`, otherwise none), `twilio`, `json` (logs the messages, for development and tests), `none`, or a module path. Without one the SMS 2FA method and the phone verification are unavailable. |
1066
+ | `SMS_TWILIO_ACCOUNT_SID` | string? | - | Twilio account SID, required by the `twilio` provider. |
1067
+ | `SMS_TWILIO_AUTH_TOKEN` | string? | - | Twilio auth token of the account, required by the `twilio` provider. |
1068
+ | `SMS_TWILIO_MESSAGING_SERVICE_SID` | string? | - | SID of the Twilio messaging service sending the messages, needed without an `SMS_SENDER` number. |
1069
+ | `SMS_TWILIO_API_URL` | string | `'https://api.twilio.com'` | Base URL of the Twilio REST API. |
1070
+ | `SMS_TWILIO_STATUS_URL` | string | `'https://status.twilio.com/api/v2/status.json'` | Status page of the Twilio platform read by the health check, down during a major or critical outage. |
1071
+ | `SMS_TWILIO_TIMEOUT` | duration | `10000` | Timeout of a request to the Twilio API, milliseconds or a duration string. |
1072
+
1073
+ ### Telemetry (TELEMETRY\_\*)
1074
+
1075
+ The OpenTelemetry instrumentation of the framework, and the SDK of `@appweaver/opentelemetry` exporting it, see
1076
+ [telemetry](./telemetry.md). The keys of the first table belong to the framework, the others to the module.
1077
+
1078
+ | Property | Type | Default | Description |
1079
+ |----------------------------------------|----------|---------|-------------------------------------------------------------------------------------------------------------------|
1080
+ | `TELEMETRY_ENABLED` | boolean | `true` | Enable the instrumentation, the log correlation and the SDK. Nothing is recorded until an SDK is registered. |
1081
+ | `TELEMETRY_LOG_CORRELATION` | boolean | `true` | Add the `trace_id`, `span_id` and `trace_flags` of the active span to every log record. |
1082
+ | `TELEMETRY_INSTRUMENTATIONS_HTTP` | boolean | `true` | Trace and measure the requests of the HTTP server. |
1083
+ | `TELEMETRY_INSTRUMENTATIONS_DATABASE` | boolean | `true` | Trace and measure the database operations. |
1084
+ | `TELEMETRY_INSTRUMENTATIONS_QUEUE` | boolean | `true` | Trace and measure the queue jobs, carrying the trace from the sender to the worker. |
1085
+ | `TELEMETRY_INSTRUMENTATIONS_SCHEDULER` | boolean | `true` | Trace and measure the runs of the scheduled jobs. |
1086
+ | `TELEMETRY_INSTRUMENTATIONS_MAILER` | boolean | `true` | Trace the emails the mailer sends. |
1087
+ | `TELEMETRY_INSTRUMENTATIONS_SMS` | boolean | `true` | Trace the text messages the SMS sender sends. |
1088
+ | `TELEMETRY_INSTRUMENTATIONS_CACHE` | boolean | `true` | Count the cache hits and misses. |
1089
+ | `TELEMETRY_INSTRUMENTATIONS_TASK` | boolean | `true` | Trace the tasks of `weaver run`. |
1090
+ | `TELEMETRY_INSTRUMENTATIONS_REALTIME` | boolean | `true` | Trace the realtime actions and streams, and measure the realtime connections, events and streams. (realtime) |
1091
+ | `TELEMETRY_INSTRUMENTATIONS_AI` | boolean | `true` | Trace and measure the calls of the AI models, their tokens and the tool calls. (ai) |
1092
+ | `TELEMETRY_INSTRUMENTATIONS_MCP` | boolean | `true` | Trace and measure the calls of the MCP server. (mcp) |
1093
+ | `TELEMETRY_INSTRUMENTATIONS_AUDIT` | boolean | `true` | Count the audit log entries written and dropped. (audit) |
1094
+ | `TELEMETRY_HTTP_IGNORE_PATHS` | string[] | `[]` | URL paths left out of the traces and the metrics: an exact path, or a prefix ending with `*` (`/public/*`). (web) |
1095
+ | `TELEMETRY_HTTP_HEALTH_CHECK` | boolean | `false` | Trace and measure the requests of the health check routes. (web) |
1096
+
1097
+ With `@appweaver/opentelemetry`:
1098
+
1099
+ | Property | Type | Default | Description |
1100
+ |------------------------------------|----------|-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
1101
+ | `TELEMETRY_SERVICE_NAME` | string? | `APP_NAME` | Name of the service in the telemetry. The `OTEL_SERVICE_NAME` environment variable is used before `APP_NAME`. |
1102
+ | `TELEMETRY_SERVICE_VERSION` | string? | `APP_VERSION` | Version of the service in the telemetry. |
1103
+ | `TELEMETRY_RESOURCE_ATTRIBUTES` | string[] | `[]` | Resource attributes as `name=value` entries, added to the ones of `OTEL_RESOURCE_ATTRIBUTES`. |
1104
+ | `TELEMETRY_EXPORTER` | enum? | `'otlp'` | `otlp`, `console` (prints the telemetry) or `none`. `'none'` in the `test` environment. |
1105
+ | `TELEMETRY_ENDPOINT` | string? | - | Base URL of the OTLP endpoint, the signal paths (`/v1/traces`, ...) are appended. Else `OTEL_EXPORTER_OTLP_ENDPOINT`, else `http://localhost:4318`. |
1106
+ | `TELEMETRY_HEADERS` | string[] | `[]` | Headers of the OTLP requests as `name=value` entries, i.e. the API key of the backend. Hidden by `weaver config print`. |
1107
+ | `TELEMETRY_PROTOCOL` | enum | `'http/protobuf'` | Encoding of the OTLP requests: `http/protobuf` or `http/json`. |
1108
+ | `TELEMETRY_TIMEOUT` | duration | `10000` | Timeout of an export request, milliseconds or a duration string. |
1109
+ | `TELEMETRY_TRACES_ENABLED` | boolean | `true` | Record and export the traces. |
1110
+ | `TELEMETRY_TRACES_SAMPLE_RATIO` | number | `1` | Ratio of the traces recorded, `0` to `1`. A trace continued from another service follows the decision of that service. |
1111
+ | `TELEMETRY_TRACES_ENDPOINT` | string? | - | Full URL of the OTLP traces endpoint, overriding `TELEMETRY_ENDPOINT`. |
1112
+ | `TELEMETRY_METRICS_ENABLED` | boolean | `true` | Record and export the metrics. |
1113
+ | `TELEMETRY_METRICS_INTERVAL` | duration | `60000` | Interval between two exports of the metrics, milliseconds or a duration string. |
1114
+ | `TELEMETRY_METRICS_ENDPOINT` | string? | - | Full URL of the OTLP metrics endpoint, overriding `TELEMETRY_ENDPOINT`. |
1115
+ | `TELEMETRY_LOGS_ENABLED` | boolean | `false` | Export the log records of the application loggers over OTLP, besides the console and the log file. |
1116
+ | `TELEMETRY_LOGS_LEVEL` | enum | `'info'` | Lowest level of the exported log records, which never lowers `LOG_LEVEL`. |
1117
+ | `TELEMETRY_LOGS_ENDPOINT` | string? | - | Full URL of the OTLP logs endpoint, overriding `TELEMETRY_ENDPOINT`. |
1118
+ | `TELEMETRY_INSTRUMENTATIONS_FETCH` | boolean | `true` | Trace the outbound `fetch` requests, sending the trace context to the services they call. Node.js only. |
1119
+
1120
+ ### Template (TEMPLATE\_\*)
1121
+
1122
+ | Property | Type | Default | Description |
1123
+ |---------------------------------|---------|-----------------|-------------------------------------------------------------------------------------------------------------|
1124
+ | `TEMPLATE_PATH` | string | `'./templates'` | Directory of the template files (emails, pages, exports), see [templates](./templates.md). |
1125
+ | `TEMPLATE_CACHE` | boolean | `true` | Keep the loaded templates in memory. Disable it to reload the changed files on every render. |
1126
+ | `TEMPLATE_PREVIEW_ENABLED` | boolean | `false` | Enable the route previewing a template rendered with the data of its query parameters. |
1127
+ | `TEMPLATE_PREVIEW_AUTH` | boolean | `false` | Require authentication for the template preview route. |
1128
+ | `TEMPLATE_PREVIEW_ROUTE_PREFIX` | string | `'/templates'` | URL prefix for the template preview route. |
1129
+ | `TEMPLATE_PROVIDER` | string | `'auto'` | `auto` (`handlebars` with `@appweaver/handlebars`, otherwise none), `handlebars`, `none`, or a module path. |
1130
+
1131
+ ### Locale (LOCALE\_\*)
1132
+
1133
+ | Property | Type | Default | Description |
1134
+ |------------------|--------|---------------|------------------------------------------------------------------------------------|
1135
+ | `LOCALE_DEFAULT` | string | `'en'` | The locale used when none is given to a translation or a template render. |
1136
+ | `LOCALE_PATH` | string | `'./locales'` | Directory of the translation files, a nested JSON file per locale, i.e. `de.json`. |
1137
+
1138
+ ### System (SYSTEM\_\*)
1139
+
1140
+ | Property | Type | Default | Description |
1141
+ |---------------------------------|---------|------------------------|---------------------------------------------------|
1142
+ | `SYSTEM_ADMIN_INITIAL_EMAIL` | string | `'admin@appweaver.co'` | Initial admin account email created on first run. |
1143
+ | `SYSTEM_ADMIN_INITIAL_PASSWORD` | string? | - | Initial admin account password. |
1144
+
1145
+ ---
1146
+
1147
+ ## Configuration files summary
1148
+
1149
+ | File | Purpose |
1150
+ |-------------------------|---------------------------------------------------------------------------------|
1151
+ | `appweaver.json` | Global configuration (`config`) and the overrides of each env (`environments`) |
1152
+ | `appweaver.{env}.json` | Optional environment-specific overrides, loaded over the `environments` section |
1153
+ | `appweaver.schema.json` | The JSON Schema of the enabled modules' sections, from `weaver generate` |
1154
+ | `.env` | Environment variables (all environments) |
1155
+ | `.env.{env}` | Environment-specific env variable overrides |
1156
+
1157
+ ## Environment values
1158
+
1159
+ `test`, `local`, `dev`, `staging`, `qa`, `prod` or any custom value like `preStaging` or `prod-us-east`