@dokebi/web 0.1.2 → 0.4.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.
- package/AI.md +191 -45
- package/README.md +59 -33
- package/dist/compilers.d.ts +9 -0
- package/dist/compilers.js +58 -0
- package/dist/dependency.d.ts +4 -0
- package/dist/dependency.js +14 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.js +106 -0
- package/dist/extension.d.ts +95 -0
- package/dist/extension.js +52 -0
- package/dist/index.d.ts +50 -8
- package/dist/index.js +766 -285
- package/dist/install.d.ts +25 -0
- package/dist/install.js +23 -0
- package/dist/options.d.ts +19 -0
- package/dist/options.js +92 -0
- package/dist/points.d.ts +53 -0
- package/dist/points.js +5 -0
- package/dist/responses.d.ts +80 -0
- package/dist/responses.js +246 -0
- package/dist/seal.d.ts +83 -0
- package/dist/seal.js +273 -0
- package/options.schema.json +68 -14
- package/package.json +43 -13
- package/templates/extension.ts +14 -0
package/dist/seal.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { diagnostics } from '@dokebi/core/libraries';
|
|
2
|
+
import { WebError } from './errors.js';
|
|
3
|
+
/** Response header naming the path a sealed response was sealed with (after a redirect it is the final one). */
|
|
4
|
+
export const SEALED_PATH_HEADER = 'x-dokebi-sealed-path';
|
|
5
|
+
const JSON_TYPE = /^application\/(?:[a-z0-9.+-]+\+)?json$/;
|
|
6
|
+
/** The media type of a Content-Type value: lower case, without parameters. */
|
|
7
|
+
export function mediaType(value) {
|
|
8
|
+
return (String(Array.isArray(value) ? value[0] : (value ?? ''))
|
|
9
|
+
.split(';', 1)[0]
|
|
10
|
+
?.trim()
|
|
11
|
+
.toLowerCase() ?? '');
|
|
12
|
+
}
|
|
13
|
+
/** A request carries a body when it says so (Content-Length above 0 or Transfer-Encoding). */
|
|
14
|
+
function hasBody(headers) {
|
|
15
|
+
if (headers['transfer-encoding'] !== undefined)
|
|
16
|
+
return true;
|
|
17
|
+
const length = headers['content-length'];
|
|
18
|
+
return length !== undefined && length !== '0';
|
|
19
|
+
}
|
|
20
|
+
/** `/a/b?c` → `/a/b`. */
|
|
21
|
+
export function pathOf(url) {
|
|
22
|
+
const end = url.search(/[?#]/);
|
|
23
|
+
return end === -1 ? url : url.slice(0, end);
|
|
24
|
+
}
|
|
25
|
+
/** A host without its port, lower case; IPv6 literals keep their brackets (as `location.hostname`). */
|
|
26
|
+
function withoutPort(host) {
|
|
27
|
+
const raw = host.toLowerCase();
|
|
28
|
+
if (raw.startsWith('['))
|
|
29
|
+
return raw.slice(0, raw.indexOf(']') + 1);
|
|
30
|
+
const colon = raw.lastIndexOf(':');
|
|
31
|
+
return colon === -1 ? raw : raw.slice(0, colon);
|
|
32
|
+
}
|
|
33
|
+
/** `sealExclude` (validated by the options): prefixes without trailing slashes, unique. */
|
|
34
|
+
export function sealExclude(input) {
|
|
35
|
+
return Object.freeze([...new Set(input.map((item) => item.replace(/(.)\/+$/, '$1')))]);
|
|
36
|
+
}
|
|
37
|
+
export function checkSealSetting(value) {
|
|
38
|
+
if (value === undefined || typeof value === 'boolean' || typeof value === 'function')
|
|
39
|
+
return value;
|
|
40
|
+
throw new WebError('INVALID_ROUTE', 'Route seal must be a boolean or a function of the request');
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The seal slot of one web server. Requests are sealed by their route (`seal`) or by a
|
|
44
|
+
* registered predicate (dokebi-app: hosts with `seal: true`); health routes, `seal: false`
|
|
45
|
+
* routes and `sealExclude` prefixes stay plain. A sealed request's body must be sealed (or
|
|
46
|
+
* multipart), and its JSON responses are sealed on the way out.
|
|
47
|
+
*/
|
|
48
|
+
export class WebSealing {
|
|
49
|
+
logger;
|
|
50
|
+
options;
|
|
51
|
+
requestHost;
|
|
52
|
+
#provider;
|
|
53
|
+
#predicates = [];
|
|
54
|
+
/** Routes that may seal (`seal: true` or a function): they need a provider. */
|
|
55
|
+
#routes = 0;
|
|
56
|
+
/** The sealer of every decided request (null: plain). */
|
|
57
|
+
#decided = new WeakMap();
|
|
58
|
+
/** Replies this layer answered itself (415, refused body): sent plain so any client can read them. */
|
|
59
|
+
#plain = new WeakSet();
|
|
60
|
+
#repeats = new diagnostics.Repeats();
|
|
61
|
+
constructor(logger, options, requestHost) {
|
|
62
|
+
this.logger = logger;
|
|
63
|
+
this.options = options;
|
|
64
|
+
this.requestHost = requestHost;
|
|
65
|
+
}
|
|
66
|
+
get provider() {
|
|
67
|
+
return this.#provider;
|
|
68
|
+
}
|
|
69
|
+
/** True when anything may be sealed: a predicate or a sealing route. */
|
|
70
|
+
get wanted() {
|
|
71
|
+
return this.#predicates.length > 0 || this.#routes > 0;
|
|
72
|
+
}
|
|
73
|
+
setProvider(provider) {
|
|
74
|
+
if (this.#provider)
|
|
75
|
+
throw new WebError('SEAL_PROVIDER_INVALID', 'A seal codec is already registered');
|
|
76
|
+
if (provider === null ||
|
|
77
|
+
typeof provider !== 'object' ||
|
|
78
|
+
typeof provider.forRequest !== 'function' ||
|
|
79
|
+
typeof provider.contentType !== 'string' ||
|
|
80
|
+
!/^[a-z]+\/[a-z0-9.+-]{1,100}$/.test(provider.contentType))
|
|
81
|
+
throw new WebError('SEAL_PROVIDER_INVALID', 'Invalid seal codec provider');
|
|
82
|
+
this.#provider = provider;
|
|
83
|
+
this.logger.log('debug', 'Web seal codec registered', {
|
|
84
|
+
contentType: provider.contentType,
|
|
85
|
+
driftMs: this.options.driftMs,
|
|
86
|
+
exclude: [...this.options.exclude],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
addPredicate(predicate) {
|
|
90
|
+
if (typeof predicate !== 'function')
|
|
91
|
+
throw new WebError('INVALID_ARGUMENT', 'Seal predicate must be a function');
|
|
92
|
+
this.#predicates.push(predicate);
|
|
93
|
+
this.logger.log('debug', 'Web seal predicate registered', {
|
|
94
|
+
predicates: this.#predicates.length,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** Counts a route whose own setting may seal it (for the missing provider check). */
|
|
98
|
+
route(setting) {
|
|
99
|
+
if (setting === true || typeof setting === 'function')
|
|
100
|
+
this.#routes++;
|
|
101
|
+
}
|
|
102
|
+
/** Fail closed at start: something wants sealing but no provider will seal it. */
|
|
103
|
+
check() {
|
|
104
|
+
this.logger.log('debug', 'Web sealing', {
|
|
105
|
+
provider: this.#provider !== undefined,
|
|
106
|
+
predicates: this.#predicates.length,
|
|
107
|
+
routes: this.#routes,
|
|
108
|
+
exclude: this.options.exclude.length,
|
|
109
|
+
});
|
|
110
|
+
if (this.wanted && !this.#provider)
|
|
111
|
+
throw new WebError('SEAL_PROVIDER_MISSING', 'Requests are sealed (a seal host or a route with seal) but no seal codec is registered; register the dokebi-seal plugin');
|
|
112
|
+
}
|
|
113
|
+
#sealedRequest(request) {
|
|
114
|
+
const config = (request.routeOptions?.config ?? {});
|
|
115
|
+
if (config.dokebiHealth === true)
|
|
116
|
+
return false;
|
|
117
|
+
const own = config.dokebiSeal;
|
|
118
|
+
if (own === false)
|
|
119
|
+
return false;
|
|
120
|
+
if (own === true || (typeof own === 'function' && own(request) === true))
|
|
121
|
+
return true;
|
|
122
|
+
if (!this.#predicates.length)
|
|
123
|
+
return false;
|
|
124
|
+
const path = pathOf(request.url);
|
|
125
|
+
for (const prefix of this.options.exclude)
|
|
126
|
+
if (path === prefix || path.startsWith(prefix === '/' ? prefix : `${prefix}/`))
|
|
127
|
+
return false;
|
|
128
|
+
return this.#predicates.some((predicate) => predicate(request) === true);
|
|
129
|
+
}
|
|
130
|
+
#codec(request) {
|
|
131
|
+
const path = pathOf(request.url);
|
|
132
|
+
const agent = request.headers['user-agent'];
|
|
133
|
+
const codec = this.#provider.forRequest({
|
|
134
|
+
host: withoutPort(this.requestHost(request)),
|
|
135
|
+
path,
|
|
136
|
+
userAgent: typeof agent === 'string' ? agent : '',
|
|
137
|
+
driftMs: this.options.driftMs,
|
|
138
|
+
});
|
|
139
|
+
return { codec, path };
|
|
140
|
+
}
|
|
141
|
+
/** The sealer of a request, decided once; undefined for a plain request. */
|
|
142
|
+
sealOf(request) {
|
|
143
|
+
const known = this.#decided.get(request);
|
|
144
|
+
if (known !== undefined)
|
|
145
|
+
return known ?? undefined;
|
|
146
|
+
let sealer = null;
|
|
147
|
+
if (this.#provider && this.#sealedRequest(request)) {
|
|
148
|
+
let codec;
|
|
149
|
+
const path = pathOf(request.url);
|
|
150
|
+
sealer = Object.freeze({
|
|
151
|
+
path,
|
|
152
|
+
encode: (text) => {
|
|
153
|
+
codec ??= this.#codec(request).codec;
|
|
154
|
+
return codec.encode(text);
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
this.#decided.set(request, sealer);
|
|
159
|
+
return sealer ?? undefined;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* onRequest: decides the request and refuses a plain body on a sealed one: the 415 error to
|
|
163
|
+
* answer with (sent plain), or undefined. Synchronous: dokebi-web calls it from its
|
|
164
|
+
* callback-style hook and passes the error to `done`, so the error mapping answers it.
|
|
165
|
+
*/
|
|
166
|
+
refusePlain(request) {
|
|
167
|
+
const sealer = this.sealOf(request);
|
|
168
|
+
const debug = this.logger.isEnabled('debug');
|
|
169
|
+
if (!sealer)
|
|
170
|
+
return undefined;
|
|
171
|
+
if (debug)
|
|
172
|
+
this.logger.log('debug', 'HTTP request sealed', {
|
|
173
|
+
method: request.method,
|
|
174
|
+
path: sealer.path.slice(0, 200),
|
|
175
|
+
});
|
|
176
|
+
if (!hasBody(request.headers))
|
|
177
|
+
return undefined;
|
|
178
|
+
const type = mediaType(request.headers['content-type']);
|
|
179
|
+
const provider = this.#provider;
|
|
180
|
+
// Only a sealed body, or an upload (multipart/form-data: files are not sealed), gets through.
|
|
181
|
+
// Every other type is refused before any parser runs, so no parser can let plain text in.
|
|
182
|
+
if (type === provider.contentType || type === 'multipart/form-data')
|
|
183
|
+
return undefined;
|
|
184
|
+
const route = request.routeOptions.url ?? 'unmatched';
|
|
185
|
+
const repeated = this.#repeats.take(`plain ${request.method} ${route}`);
|
|
186
|
+
if (repeated !== undefined)
|
|
187
|
+
this.logger.log('warn', 'Plain request body refused on a sealed route', {
|
|
188
|
+
code: 'SEAL_REQUIRED',
|
|
189
|
+
reason: 'plain-body',
|
|
190
|
+
method: request.method,
|
|
191
|
+
route,
|
|
192
|
+
contentType: type.slice(0, 100) || null,
|
|
193
|
+
...(repeated ? { repeated } : {}),
|
|
194
|
+
});
|
|
195
|
+
this.#plain.add(request);
|
|
196
|
+
return new WebError('SEAL_REQUIRED', 'A sealed route got a plain request body', {
|
|
197
|
+
fix: `This route is sealed (a seal host): send the body sealed as ${provider.contentType} with @dokebi/seal (sealedFetch, or the Inertia bridge sealInertia). File uploads use multipart/form-data; webhooks and server-to-server routes set seal: false or are listed in dokebi-web sealExclude.`,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/** The body parser of the sealed media type: opens, then parses JSON. Refusals are 400. */
|
|
201
|
+
async parse(request, body) {
|
|
202
|
+
let plain;
|
|
203
|
+
try {
|
|
204
|
+
plain = await this.#codec(request).codec.decode(body);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
const reason = typeof error?.reason === 'string'
|
|
208
|
+
? String(error.reason)
|
|
209
|
+
: 'unknown';
|
|
210
|
+
const route = request.routeOptions.url ?? 'unmatched';
|
|
211
|
+
const repeated = this.#repeats.take(`open ${route} ${reason}`);
|
|
212
|
+
// The reason goes to the log only: telling the client drift from replay is an oracle.
|
|
213
|
+
if (repeated !== undefined)
|
|
214
|
+
this.logger.log('warn', 'Sealed request body refused', {
|
|
215
|
+
code: 'SEAL_BODY_REFUSED',
|
|
216
|
+
reason,
|
|
217
|
+
method: request.method,
|
|
218
|
+
route,
|
|
219
|
+
...(repeated ? { repeated } : {}),
|
|
220
|
+
});
|
|
221
|
+
this.#plain.add(request);
|
|
222
|
+
throw new WebError('SEAL_BODY_REFUSED', 'Sealed request body refused', { cause: error });
|
|
223
|
+
}
|
|
224
|
+
if (plain === '')
|
|
225
|
+
return undefined;
|
|
226
|
+
try {
|
|
227
|
+
return JSON.parse(plain);
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
throw new WebError('SEAL_BODY_NOT_JSON', 'Sealed request body is not JSON', {
|
|
231
|
+
cause: error,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/** onSend: seals the JSON response of a sealed request (other types pass unchanged). */
|
|
236
|
+
onSend(request, reply, payload) {
|
|
237
|
+
const sealer = this.#decided.get(request);
|
|
238
|
+
if (!sealer || this.#plain.has(request) || payload === null || payload === undefined)
|
|
239
|
+
return payload;
|
|
240
|
+
if (!JSON_TYPE.test(mediaType(reply.getHeader('content-type'))))
|
|
241
|
+
return payload;
|
|
242
|
+
const provider = this.#provider;
|
|
243
|
+
try {
|
|
244
|
+
let text;
|
|
245
|
+
if (typeof payload === 'string')
|
|
246
|
+
text = payload;
|
|
247
|
+
else if (Buffer.isBuffer(payload))
|
|
248
|
+
text = payload.toString('utf8');
|
|
249
|
+
else
|
|
250
|
+
throw new WebError('SEAL_STREAM_UNSUPPORTED', 'A streamed JSON response cannot be sealed');
|
|
251
|
+
const sealed = sealer.encode(text);
|
|
252
|
+
reply.header('content-type', provider.contentType);
|
|
253
|
+
reply.header(SEALED_PATH_HEADER, sealer.path);
|
|
254
|
+
return sealed;
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
// Fail closed: no plain JSON leaves a sealed request.
|
|
258
|
+
const route = request.routeOptions.url ?? 'unmatched';
|
|
259
|
+
const repeated = this.#repeats.take(`encode ${route}`);
|
|
260
|
+
if (repeated !== undefined)
|
|
261
|
+
this.logger.log('error', 'Sealing a response failed', {
|
|
262
|
+
code: error.code ?? 'SEAL_ENCODE_FAILED',
|
|
263
|
+
method: request.method,
|
|
264
|
+
route,
|
|
265
|
+
error: diagnostics.describeError(error),
|
|
266
|
+
...(repeated ? { repeated } : {}),
|
|
267
|
+
});
|
|
268
|
+
reply.code(500).header('content-type', 'application/json; charset=utf-8');
|
|
269
|
+
reply.removeHeader(SEALED_PATH_HEADER);
|
|
270
|
+
return '{"error":"INTERNAL_SERVER_ERROR"}';
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
package/options.schema.json
CHANGED
|
@@ -7,32 +7,46 @@
|
|
|
7
7
|
"type": "string",
|
|
8
8
|
"minLength": 1,
|
|
9
9
|
"maxLength": 253,
|
|
10
|
-
"default": "127.0.0.1"
|
|
10
|
+
"default": "127.0.0.1",
|
|
11
|
+
"description": "Address to listen on; 0.0.0.0 accepts other machines (put a proxy in front)."
|
|
11
12
|
},
|
|
12
13
|
"port": {
|
|
13
14
|
"type": "integer",
|
|
14
15
|
"minimum": 0,
|
|
15
16
|
"maximum": 65535,
|
|
16
|
-
"default": 0
|
|
17
|
+
"default": 0,
|
|
18
|
+
"description": "Port to listen on; 0 picks a free one."
|
|
19
|
+
},
|
|
20
|
+
"maxBodyBytes": {
|
|
21
|
+
"type": "integer",
|
|
22
|
+
"minimum": 1,
|
|
23
|
+
"maximum": 67108864,
|
|
24
|
+
"default": 1048576,
|
|
25
|
+
"description": "Largest request body in bytes."
|
|
17
26
|
},
|
|
18
27
|
"bodyLimit": {
|
|
19
28
|
"type": "integer",
|
|
20
29
|
"minimum": 1,
|
|
21
30
|
"maximum": 67108864,
|
|
22
|
-
"
|
|
31
|
+
"deprecated": true,
|
|
32
|
+
"description": "Deprecated name of maxBodyBytes; use that key."
|
|
33
|
+
},
|
|
34
|
+
"requestTimeoutMs": {
|
|
35
|
+
"type": "integer",
|
|
36
|
+
"minimum": 1,
|
|
37
|
+
"maximum": 2147483647,
|
|
38
|
+
"default": 30000,
|
|
39
|
+
"description": "Time to receive a whole request in ms (not a limit on the work it starts)."
|
|
23
40
|
},
|
|
24
41
|
"requestTimeout": {
|
|
25
42
|
"type": "integer",
|
|
26
43
|
"minimum": 1,
|
|
27
44
|
"maximum": 2147483647,
|
|
28
|
-
"
|
|
45
|
+
"deprecated": true,
|
|
46
|
+
"description": "Deprecated name of requestTimeoutMs; use that key."
|
|
29
47
|
},
|
|
30
48
|
"healthRoutes": {
|
|
31
|
-
"
|
|
32
|
-
"live": "/health/live",
|
|
33
|
-
"ready": "/health/ready"
|
|
34
|
-
},
|
|
35
|
-
"oneOf": [
|
|
49
|
+
"anyOf": [
|
|
36
50
|
{
|
|
37
51
|
"const": false
|
|
38
52
|
},
|
|
@@ -42,30 +56,70 @@
|
|
|
42
56
|
"properties": {
|
|
43
57
|
"live": {
|
|
44
58
|
"type": "string",
|
|
45
|
-
"pattern": "
|
|
59
|
+
"pattern": "^\\/[^?#\\s]{0,2047}$",
|
|
46
60
|
"default": "/health/live"
|
|
47
61
|
},
|
|
48
62
|
"ready": {
|
|
49
63
|
"type": "string",
|
|
50
|
-
"pattern": "
|
|
64
|
+
"pattern": "^\\/[^?#\\s]{0,2047}$",
|
|
51
65
|
"default": "/health/ready"
|
|
52
66
|
}
|
|
53
67
|
}
|
|
54
68
|
}
|
|
55
|
-
]
|
|
69
|
+
],
|
|
70
|
+
"default": {
|
|
71
|
+
"live": "/health/live",
|
|
72
|
+
"ready": "/health/ready"
|
|
73
|
+
},
|
|
74
|
+
"description": "Liveness and readiness routes (answered before ready and while draining); false registers none."
|
|
56
75
|
},
|
|
57
76
|
"trustProxy": {
|
|
58
77
|
"type": "array",
|
|
59
|
-
"maxItems": 64,
|
|
60
|
-
"uniqueItems": true,
|
|
61
78
|
"items": {
|
|
62
79
|
"type": "string",
|
|
63
80
|
"minLength": 2,
|
|
64
81
|
"maxLength": 45,
|
|
65
82
|
"description": "IPv4 or IPv6 address"
|
|
66
83
|
},
|
|
84
|
+
"maxItems": 64,
|
|
85
|
+
"uniqueItems": true,
|
|
67
86
|
"default": [],
|
|
68
87
|
"description": "Proxy addresses whose X-Forwarded-Host/For/Proto are trusted, e.g. [127.0.0.1, ::1] for a local tunnel"
|
|
88
|
+
},
|
|
89
|
+
"sealDriftMs": {
|
|
90
|
+
"type": "integer",
|
|
91
|
+
"minimum": 1000,
|
|
92
|
+
"maximum": 600000,
|
|
93
|
+
"default": 60000,
|
|
94
|
+
"description": "Seal hosts (D-0062): accepted clock difference of a sealed request body in ms; replay nonces are kept twice as long"
|
|
95
|
+
},
|
|
96
|
+
"sealExclude": {
|
|
97
|
+
"type": "array",
|
|
98
|
+
"items": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"pattern": "^\\/[^?#\\s]{0,2047}$"
|
|
101
|
+
},
|
|
102
|
+
"maxItems": 64,
|
|
103
|
+
"uniqueItems": true,
|
|
104
|
+
"default": [],
|
|
105
|
+
"description": "Seal hosts (D-0062): path prefixes that stay plain (webhooks, server-to-server), matched at a / boundary"
|
|
106
|
+
},
|
|
107
|
+
"formBody": {
|
|
108
|
+
"type": "boolean",
|
|
109
|
+
"default": false,
|
|
110
|
+
"description": "Parse HTML form bodies (application/x-www-form-urlencoded) into request.body (D-0068). Off: such a request gets 415 FORM_BODY_DISABLED. Seal hosts still refuse them (415 SEAL_REQUIRED)"
|
|
111
|
+
},
|
|
112
|
+
"formMaxFields": {
|
|
113
|
+
"type": "integer",
|
|
114
|
+
"minimum": 1,
|
|
115
|
+
"maximum": 10000,
|
|
116
|
+
"default": 1000,
|
|
117
|
+
"description": "Most fields one form body may carry; more is 413 FORM_BODY_TOO_MANY_FIELDS (maxBodyBytes also applies)"
|
|
118
|
+
},
|
|
119
|
+
"developmentErrors": {
|
|
120
|
+
"type": "boolean",
|
|
121
|
+
"default": true,
|
|
122
|
+
"description": "Outside production (NODE_ENV is not production) error bodies also carry fix and details (D-0063). false: never, as in production. hint and data are always sent."
|
|
69
123
|
}
|
|
70
124
|
}
|
|
71
125
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dokebi/web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Fastify 5 HTTP server owned by a Dokebi app: 503 before ready, health routes, drain and cluster handover.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dokebi",
|
|
7
|
+
"dokebi-plugin",
|
|
8
|
+
"web",
|
|
9
|
+
"http",
|
|
10
|
+
"fastify"
|
|
11
|
+
],
|
|
4
12
|
"private": false,
|
|
5
13
|
"type": "module",
|
|
6
14
|
"license": "MIT",
|
|
@@ -10,6 +18,14 @@
|
|
|
10
18
|
".": {
|
|
11
19
|
"types": "./dist/index.d.ts",
|
|
12
20
|
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./points": {
|
|
23
|
+
"types": "./dist/points.d.ts",
|
|
24
|
+
"import": "./dist/points.js"
|
|
25
|
+
},
|
|
26
|
+
"./dependency": {
|
|
27
|
+
"types": "./dist/dependency.d.ts",
|
|
28
|
+
"import": "./dist/dependency.js"
|
|
13
29
|
}
|
|
14
30
|
},
|
|
15
31
|
"files": [
|
|
@@ -24,36 +40,50 @@
|
|
|
24
40
|
"node": ">=24.0.0"
|
|
25
41
|
},
|
|
26
42
|
"scripts": {
|
|
27
|
-
"build": "tsc -p tsconfig.json",
|
|
43
|
+
"build": "tsc -p tsconfig.json && node -e \"import('./dist/options.js').then(async (m) => { const { renderOptionsSchema } = await import('@dokebi/core'); process.stdout.write(renderOptionsSchema(m.options)); })\" > options.schema.json",
|
|
28
44
|
"typecheck": "tsc -p tsconfig.test.json --noEmit",
|
|
29
|
-
"test": "tsc -p tsconfig.test.json && node --test .tmp/tests/tests/*.test.js"
|
|
45
|
+
"test": "node -e \"require('node:fs').rmSync('.tmp/tests',{recursive:true,force:true})\" && tsc -p tsconfig.test.json && node --test .tmp/tests/tests/*.test.js"
|
|
30
46
|
},
|
|
31
47
|
"peerDependencies": {
|
|
32
|
-
"@dokebi/core": "^0.
|
|
48
|
+
"@dokebi/core": "^0.4.0"
|
|
33
49
|
},
|
|
34
50
|
"devDependencies": {
|
|
35
|
-
"@dokebi/health": "0.
|
|
51
|
+
"@dokebi/health": "0.4.0"
|
|
36
52
|
},
|
|
37
53
|
"dokebi": {
|
|
38
54
|
"schemaVersion": 2,
|
|
39
55
|
"id": "dokebi-web",
|
|
40
|
-
"core": "^0.
|
|
56
|
+
"core": "^0.4.0",
|
|
41
57
|
"dependencies": [
|
|
42
58
|
{
|
|
43
59
|
"name": "dokebi-health",
|
|
44
|
-
"version": "^0.
|
|
60
|
+
"version": "^0.4.0",
|
|
45
61
|
"optional": true
|
|
46
62
|
}
|
|
47
63
|
],
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
},
|
|
64
|
+
"contributes": [
|
|
65
|
+
"dokebi-testing:inject"
|
|
66
|
+
],
|
|
67
|
+
"installModule": "dist/install.js",
|
|
54
68
|
"optionsSchema": "options.schema.json",
|
|
55
69
|
"documentation": "AI.md"
|
|
56
70
|
},
|
|
71
|
+
"dokebiCatalog": {
|
|
72
|
+
"kind": "plugin",
|
|
73
|
+
"summary": "Fastify 5 HTTP server (503 before ready, health paths, drain, zero-downtime cluster replacement)",
|
|
74
|
+
"maturity": "preview",
|
|
75
|
+
"provides": [
|
|
76
|
+
"web.http"
|
|
77
|
+
],
|
|
78
|
+
"doesNot": [
|
|
79
|
+
"No built-in authentication, rate limit, CORS or security headers",
|
|
80
|
+
"No file upload (multipart)"
|
|
81
|
+
],
|
|
82
|
+
"recipes": [
|
|
83
|
+
"api",
|
|
84
|
+
"blog"
|
|
85
|
+
]
|
|
86
|
+
},
|
|
57
87
|
"dependencies": {
|
|
58
88
|
"fastify": "5.12.7"
|
|
59
89
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// dokebi-web entry file (src/infra/web/extension.ts): user code. Left as it is, it keeps the
|
|
2
|
+
// default behavior (D-0064).
|
|
3
|
+
//
|
|
4
|
+
// requires: Dokebi plugins (instances or dependency descriptors) that a Fastify onClose hook
|
|
5
|
+
// still uses, so they are cleaned up after the web server has closed. Most projects leave it empty.
|
|
6
|
+
//
|
|
7
|
+
// AppWeb: the only hooks you can change are fastifyOptions(defaults), errorBody(error, context)
|
|
8
|
+
// and unavailable(context). Override only what you need with `protected override`. Do not add
|
|
9
|
+
// constructor arguments. Left empty, it adds no cost per request.
|
|
10
|
+
import { WebExtension } from '@dokebi/web';
|
|
11
|
+
|
|
12
|
+
export const requires = [] as const;
|
|
13
|
+
|
|
14
|
+
export default class AppWeb extends WebExtension {}
|