@webjsdev/core 0.7.7 → 0.7.9

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,179 @@
1
+ /**
2
+ * TypeScript overlay for the `webjs` config block in a webjs app's
3
+ * package.json.
4
+ *
5
+ * // package.json is JSON, so author it there, but a typed reference
6
+ * // helps an agent or a human author the block correctly:
7
+ * import type { WebjsConfig } from '@webjsdev/core';
8
+ * const config: WebjsConfig = { trailingSlash: 'never', csp: true };
9
+ *
10
+ * The server reads this object key by key. Without a type or schema a
11
+ * typo'd key (e.g. `redirect` for `redirects`) was silently dropped and
12
+ * the feature stayed at its default with no diagnostic. This type plus
13
+ * the published JSON Schema close that gap.
14
+ *
15
+ * LOCKSTEP: this file, the JSON Schema at
16
+ * packages/server/webjs-config.schema.json, and the server reader
17
+ * functions MUST stay in sync. The readers are: readElideEnabled
18
+ * (dev.js, elide), compileHeaderRules (headers.js, headers),
19
+ * compileRedirectRules / readTrailingSlashPolicy (redirects.js,
20
+ * redirects / trailingSlash), readBasePath (base-path.js, basePath),
21
+ * readCspConfig (csp.js, csp), and
22
+ * readBodyLimits / computeServerTimeouts (body-limit.js, the byte caps
23
+ * and timeouts). Adding a `webjs.*` key means updating all three places.
24
+ * See packages/server/AGENTS.md for the one documented procedure.
25
+ *
26
+ * Every key is optional (the whole block is optional and every key has a
27
+ * default). Zero runtime cost: nothing in this file ships to the browser.
28
+ */
29
+
30
+ /** One header directive in a `webjs.headers` rule. */
31
+ export interface WebjsHeaderDirective {
32
+ /** Header name, e.g. `X-Frame-Options`. */
33
+ key: string;
34
+ /**
35
+ * Header value. A `null` or `false` value REMOVES the header on a
36
+ * match, the escape hatch that drops a secure default on a path.
37
+ * `true` is intentionally not allowed (the runtime would stringify it
38
+ * to the literal `"true"`, which is never a useful header value).
39
+ */
40
+ value?: string | null | false;
41
+ }
42
+
43
+ /** One per-path response-header rule in `webjs.headers`. */
44
+ export interface WebjsHeaderRule {
45
+ /**
46
+ * Path pattern matched with the native URLPattern API, so `:param` and
47
+ * `:rest*` syntax works.
48
+ */
49
+ source: string;
50
+ /** Header directives applied on a match. */
51
+ headers: WebjsHeaderDirective[];
52
+ }
53
+
54
+ /** One declarative redirect rule in `webjs.redirects`. */
55
+ export interface WebjsRedirectRule {
56
+ /**
57
+ * Path pattern matched with the native URLPattern API, so `:param` and
58
+ * `:rest*` syntax works.
59
+ */
60
+ source: string;
61
+ /**
62
+ * Target path, a path referencing named groups captured by `source`,
63
+ * or an absolute URL. The incoming query string is preserved and
64
+ * merged onto the destination.
65
+ */
66
+ destination: string;
67
+ /**
68
+ * `true` (the default) is a 308 Permanent Redirect, `false` is a 307
69
+ * Temporary Redirect. Both preserve the request method and body.
70
+ * `statusCode` wins over this when set.
71
+ */
72
+ permanent?: boolean;
73
+ /**
74
+ * Explicit redirect status, for a tool needing a legacy code. Wins
75
+ * over `permanent`. One of 301, 302, 303, 307, 308.
76
+ */
77
+ statusCode?: 301 | 302 | 303 | 307 | 308;
78
+ }
79
+
80
+ /** The trailing-slash canonicalization policy in `webjs.trailingSlash`. */
81
+ export type WebjsTrailingSlash = 'never' | 'always' | 'ignore';
82
+
83
+ /** The object form of `webjs.csp` (the non-boolean shape). */
84
+ export interface WebjsCspConfig {
85
+ /**
86
+ * Directive map merged over the strict defaults, e.g.
87
+ * `{ 'connect-src': "'self' https://api.example.com" }`. A `null` /
88
+ * `false` / `''` value drops a default directive. A `__NONCE__` token
89
+ * in a value is replaced with the per-request nonce.
90
+ */
91
+ directives?: Record<string, string | null | boolean>;
92
+ /**
93
+ * `true` emits `Content-Security-Policy-Report-Only` instead of the
94
+ * enforcing header (the staged-rollout path).
95
+ */
96
+ reportOnly?: boolean;
97
+ }
98
+
99
+ /**
100
+ * The `webjs` object in a webjs app's package.json. Every key is
101
+ * optional. Mirrors what the server readers actually consume, NOT a
102
+ * Next.js superset.
103
+ */
104
+ export interface WebjsConfig {
105
+ /**
106
+ * Display-only and inert-route dead-JS elision switch. Default `true`.
107
+ * Set to `false` to ship every module's JS app-wide. The `WEBJS_ELIDE`
108
+ * env override wins over this.
109
+ */
110
+ elide?: boolean;
111
+
112
+ /** Per-path response-header rules, shaped like Next's. */
113
+ headers?: WebjsHeaderRule[];
114
+
115
+ /** Declarative permanent / temporary redirects for moved URLs. */
116
+ redirects?: WebjsRedirectRule[];
117
+
118
+ /**
119
+ * Trailing-slash canonicalization policy. Default `'ignore'` (no-op).
120
+ * `'never'` strips a trailing slash, `'always'` adds one (both via a
121
+ * 308 redirect).
122
+ */
123
+ trailingSlash?: WebjsTrailingSlash;
124
+
125
+ /**
126
+ * Sub-path deployment prefix for an app mounted under
127
+ * `example.com/app/` behind a proxy that does NOT strip the prefix.
128
+ * `'app'`, `'/app'`, and `'/app/'` all normalize to `'/app'`; an empty
129
+ * value (the default) is a root mount and a pure no-op. The prefix is
130
+ * stripped from the incoming path at ingress and prepended to every
131
+ * framework-emitted URL (importmap targets, modulepreload hints, boot
132
+ * module specifiers, the dev reload src). Author-written `<a href>`
133
+ * links and client-router navigation are NOT auto-prefixed (a
134
+ * documented follow-up).
135
+ */
136
+ basePath?: string;
137
+
138
+ /**
139
+ * Content-Security-Policy config. Off by default. `true` enables a
140
+ * strict nonce-based default policy. An object customizes directives
141
+ * and report-only mode.
142
+ */
143
+ csp?: boolean | WebjsCspConfig;
144
+
145
+ /**
146
+ * JSON / RPC request body cap in bytes. Default 1048576 (1 MiB). `0`
147
+ * disables the cap. The `WEBJS_MAX_BODY_BYTES` env override wins.
148
+ */
149
+ maxBodyBytes?: number;
150
+
151
+ /**
152
+ * Form / multipart request body cap in bytes. Default 10485760 (10
153
+ * MiB). `0` disables the cap. The `WEBJS_MAX_MULTIPART_BYTES` env
154
+ * override wins.
155
+ */
156
+ maxMultipartBytes?: number;
157
+
158
+ /**
159
+ * Max time in ms to receive the ENTIRE request (headers plus body).
160
+ * Default 30000. `0` disables the timeout. The
161
+ * `WEBJS_REQUEST_TIMEOUT_MS` env override wins.
162
+ */
163
+ requestTimeoutMs?: number;
164
+
165
+ /**
166
+ * Max time in ms to receive just the request headers. Default 20000.
167
+ * Clamped strictly under `requestTimeoutMs` per node semantics. `0`
168
+ * disables the timeout. The `WEBJS_HEADERS_TIMEOUT_MS` env override
169
+ * wins.
170
+ */
171
+ headersTimeoutMs?: number;
172
+
173
+ /**
174
+ * Idle time in ms before a kept-alive socket is closed. Default 5000.
175
+ * `0` disables the timeout. The `WEBJS_KEEP_ALIVE_TIMEOUT_MS` env
176
+ * override wins.
177
+ */
178
+ keepAliveTimeoutMs?: number;
179
+ }