@boo-labs/server 0.0.0-stage → 1.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.
Files changed (114) hide show
  1. package/README.md +229 -2
  2. package/index.mjs +23 -0
  3. package/package.json +71 -4
  4. package/source/application/Kernel/index.mjs +1137 -0
  5. package/source/application/Server/index.mjs +1201 -0
  6. package/source/application/configurations/Http2CleartextServerConfiguration/index.mjs +168 -0
  7. package/source/application/configurations/Http2SecureServerConfiguration/index.mjs +172 -0
  8. package/source/application/configurations/HttpServerConfiguration/index.mjs +169 -0
  9. package/source/application/configurations/HttpsServerConfiguration/index.mjs +172 -0
  10. package/source/application/configurations/ServerConfiguration/Options/CORSOptions/CORSOptionsValue.mjs +158 -0
  11. package/source/application/configurations/ServerConfiguration/Options/CORSOptions/index.mjs +87 -0
  12. package/source/application/configurations/ServerConfiguration/Options/CSRFOptions/CSRFOptionsValue.mjs +178 -0
  13. package/source/application/configurations/ServerConfiguration/Options/CSRFOptions/index.mjs +80 -0
  14. package/source/application/configurations/ServerConfiguration/Options/CompressOptions/CompressOptionsValue.mjs +126 -0
  15. package/source/application/configurations/ServerConfiguration/Options/CompressOptions/index.mjs +81 -0
  16. package/source/application/configurations/ServerConfiguration/Options/CookieParserOptions/CookieParserOptionsValue.mjs +107 -0
  17. package/source/application/configurations/ServerConfiguration/Options/CookieParserOptions/index.mjs +82 -0
  18. package/source/application/configurations/ServerConfiguration/Options/CookieSessionOptions/CookieSessionOptionsValue.mjs +182 -0
  19. package/source/application/configurations/ServerConfiguration/Options/CookieSessionOptions/index.mjs +86 -0
  20. package/source/application/configurations/ServerConfiguration/Options/ListenOptions/ListenOptionsValue.mjs +95 -0
  21. package/source/application/configurations/ServerConfiguration/Options/ListenOptions/index.mjs +47 -0
  22. package/source/application/configurations/ServerConfiguration/Options/MiddlewareOption.mjs +102 -0
  23. package/source/application/configurations/ServerConfiguration/Options/Options.mjs +105 -0
  24. package/source/application/configurations/ServerConfiguration/Options/RateLimitOptions/RateLimitOptionsValue.mjs +164 -0
  25. package/source/application/configurations/ServerConfiguration/Options/RateLimitOptions/index.mjs +84 -0
  26. package/source/application/configurations/ServerConfiguration/Options/RequestOptions/RequestOptionsValue.mjs +108 -0
  27. package/source/application/configurations/ServerConfiguration/Options/RequestOptions/index.mjs +47 -0
  28. package/source/application/configurations/ServerConfiguration/Options/ResponseOptions/ResponseOptionsValue.mjs +101 -0
  29. package/source/application/configurations/ServerConfiguration/Options/ResponseOptions/index.mjs +47 -0
  30. package/source/application/configurations/ServerConfiguration/Options/SecurityHeadersOptions/SecurityHeadersOptionsValue.mjs +272 -0
  31. package/source/application/configurations/ServerConfiguration/Options/SecurityHeadersOptions/index.mjs +85 -0
  32. package/source/application/configurations/ServerConfiguration/Options/ServerOption.mjs +50 -0
  33. package/source/application/configurations/ServerConfiguration/Options/StaticOptions/StaticOptionsValue.mjs +164 -0
  34. package/source/application/configurations/ServerConfiguration/Options/StaticOptions/index.mjs +89 -0
  35. package/source/application/configurations/ServerConfiguration/index.mjs +781 -0
  36. package/source/application/resolvers/TransportResolver/index.mjs +119 -0
  37. package/source/application/use-cases/CloseServer/index.mjs +85 -0
  38. package/source/application/use-cases/ListenServer/index.mjs +98 -0
  39. package/source/core/EventSystem/index.mjs +110 -0
  40. package/source/core/Exchange/ExchangeContext.mjs +291 -0
  41. package/source/core/Exchange/Telemetry.mjs +193 -0
  42. package/source/core/Exchange/index.mjs +604 -0
  43. package/source/core/ExchangeLayerBuilder/index.mjs +133 -0
  44. package/source/core/IPCMain/IPCMain.mjs +507 -0
  45. package/source/core/IPCMain/IPCProtocol.mjs +441 -0
  46. package/source/core/IPCMain/IPCServerChannel.mjs +331 -0
  47. package/source/core/IPCMain/WebSocketAdapter.mjs +189 -0
  48. package/source/core/Request/BodyParser/BodyParser.mjs +197 -0
  49. package/source/core/Request/BodyParser/JSONParser.mjs +70 -0
  50. package/source/core/Request/BodyParser/MultipartParser.mjs +612 -0
  51. package/source/core/Request/BodyParser/URLEncodedParser.mjs +71 -0
  52. package/source/core/Request/RequestHeaders.mjs +177 -0
  53. package/source/core/Request/index.mjs +805 -0
  54. package/source/core/Response/ResponseHeaders.mjs +402 -0
  55. package/source/core/Response/index.mjs +1370 -0
  56. package/source/core/middlewares/CORSMiddleware/index.mjs +289 -0
  57. package/source/core/middlewares/CSRFMiddleware/index.mjs +284 -0
  58. package/source/core/middlewares/CompressMiddleware/index.mjs +460 -0
  59. package/source/core/middlewares/CookieParserMiddleware/index.mjs +194 -0
  60. package/source/core/middlewares/CookieSessionMiddleware/index.mjs +460 -0
  61. package/source/core/middlewares/RateLimitMiddleware/index.mjs +245 -0
  62. package/source/core/middlewares/SecurityHeadersMiddleware/index.mjs +151 -0
  63. package/source/core/middlewares/StaticMiddleware/index.mjs +628 -0
  64. package/source/core/routing/ExchangeLayer/ExchangeMatcher.mjs +127 -0
  65. package/source/core/routing/ExchangeLayer/index.mjs +254 -0
  66. package/source/core/routing/Pipeline/index.mjs +157 -0
  67. package/source/core/routing/Router/Route.mjs +184 -0
  68. package/source/core/routing/Router/index.mjs +523 -0
  69. package/source/core/routing/RouterRegister/OptionsMiddleware.mjs +147 -0
  70. package/source/core/routing/RouterRegister/index.mjs +150 -0
  71. package/source/core/routing/RouterSystem/index.mjs +225 -0
  72. package/source/core/value-objects/Address/index.mjs +281 -0
  73. package/source/core/value-objects/Endpoint/index.mjs +293 -0
  74. package/source/index.mjs +62 -0
  75. package/source/infrastructure/adapters/Http2Adapter/index.mjs +144 -0
  76. package/source/infrastructure/adapters/Http2CleartextAdapter/index.mjs +147 -0
  77. package/source/infrastructure/adapters/HttpAdapter/index.mjs +124 -0
  78. package/source/infrastructure/adapters/HttpsAdapter/index.mjs +124 -0
  79. package/source/infrastructure/adapters/TransportAdapter/createWebSocketOpenRequest.mjs +843 -0
  80. package/source/infrastructure/adapters/TransportAdapter/index.mjs +555 -0
  81. package/source/shared/Identifier/index.mjs +671 -0
  82. package/source/shared/constants/symbols/brands/index.mjs +45 -0
  83. package/source/shared/domain/UUIDV7/index.mjs +346 -0
  84. package/source/shared/errors/BaseError/index.mjs +157 -0
  85. package/source/shared/errors/IPCError/index.mjs +97 -0
  86. package/source/shared/errors/MiddlewareError/index.mjs +106 -0
  87. package/source/shared/errors/PathnamePatternError/index.mjs +103 -0
  88. package/source/shared/errors/RequestError/index.mjs +116 -0
  89. package/source/shared/errors/ResponseError/index.mjs +140 -0
  90. package/source/shared/errors/RouterError/index.mjs +90 -0
  91. package/source/shared/errors/ServerConfigurationError/index.mjs +551 -0
  92. package/source/shared/errors/ServerError/index.mjs +127 -0
  93. package/source/shared/errors/WebSocketError/index.mjs +58 -0
  94. package/source/shared/outcome/ErrorSchema.mjs +361 -0
  95. package/source/shared/outcome/Result/index.mjs +239 -0
  96. package/source/shared/outcome/Validation/index.mjs +208 -0
  97. package/source/shared/validations/Middleware/index.mjs +160 -0
  98. package/source/shared/validations/PathnamePattern/index.mjs +256 -0
  99. package/source/shared/validations/Server/NotFoundHandler/index.mjs +94 -0
  100. package/source/shared/validations/Server/Router/index.mjs +68 -0
  101. package/source/shared/validations/Server/ServerConfiguration/index.mjs +68 -0
  102. package/source/shared/validations/Server/SystemErrorHandler/index.mjs +94 -0
  103. package/source/shared/validations/ServerConfiguration/CORSOptions/index.mjs +310 -0
  104. package/source/shared/validations/ServerConfiguration/CSRFOptions/index.mjs +299 -0
  105. package/source/shared/validations/ServerConfiguration/CompressOptions/index.mjs +204 -0
  106. package/source/shared/validations/ServerConfiguration/CookieParserOptions/index.mjs +102 -0
  107. package/source/shared/validations/ServerConfiguration/CookieSessionOptions/index.mjs +332 -0
  108. package/source/shared/validations/ServerConfiguration/ListenOptions/index.mjs +178 -0
  109. package/source/shared/validations/ServerConfiguration/RateLimitOptions/index.mjs +229 -0
  110. package/source/shared/validations/ServerConfiguration/RequestOptions/index.mjs +132 -0
  111. package/source/shared/validations/ServerConfiguration/ResponseOptions/index.mjs +122 -0
  112. package/source/shared/validations/ServerConfiguration/SecurityHeadersOptions/index.mjs +137 -0
  113. package/source/shared/validations/ServerConfiguration/StaticOptions/index.mjs +248 -0
  114. package/types/index.d.ts +719 -0
package/README.md CHANGED
@@ -1,3 +1,230 @@
1
- # Temporary Holding Version
1
+ # @boo-labs/server
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A lightweight, zero-dependency HTTP server for Node.js, designed around
4
+ modular architecture, explicit configuration, and a predictable request
5
+ lifecycle.
6
+
7
+ `@boo-labs/server` provides a small public API for building HTTP applications
8
+ with support for HTTP/1.1, HTTPS, and HTTP/2, along with routing,
9
+ middleware composition, lifecycle events, and graceful resource management.
10
+
11
+ ## Features
12
+
13
+ - **Zero runtime dependencies** — built on Node.js native APIs.
14
+ - **Multiple transports** — HTTP, HTTPS, HTTP/2 cleartext, and secure HTTP/2.
15
+ - **Composable routing** — organize endpoints with reusable routers.
16
+ - **Middleware pipeline** — process requests through ordered middleware.
17
+ - **Lifecycle events** — observe server and request-exchange activity.
18
+ - **Explicit resource management** — supports asynchronous disposal.
19
+ - **JavaScript-first implementation** — includes TypeScript declarations for consumers.
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install @boo-labs/server
25
+ ```
26
+
27
+ ## Imports
28
+
29
+ `@boo-labs/server` is an ECMAScript module (ESM).
30
+
31
+ ```js
32
+ import Server, {
33
+ Router,
34
+ HttpServerConfiguration,
35
+ HttpsServerConfiguration,
36
+ Http2CleartextServerConfiguration,
37
+ Http2SecureServerConfiguration,
38
+ } from '@boo-labs/server';
39
+ ```
40
+
41
+ TypeScript declarations for the public API are included in the package.
42
+
43
+ ## Getting Started
44
+
45
+ ```js
46
+ import Server, { HttpServerConfiguration } from '@boo-labs/server';
47
+
48
+ const server = new Server(
49
+ new HttpServerConfiguration({
50
+ listen: {
51
+ host: '127.0.0.1',
52
+ port: 3000,
53
+ },
54
+ }),
55
+ );
56
+
57
+ server.get('/hello', (exchange) => {
58
+ exchange.response.json({ message: 'Hello, World!' });
59
+ });
60
+
61
+ server.onListen(({ endpoint }) => {
62
+ console.log(`Server listening on ${endpoint.displayUrl}`);
63
+ });
64
+
65
+ server.onError((error) => {
66
+ console.error('Server error:', error);
67
+ });
68
+
69
+ await server.listen();
70
+ ```
71
+
72
+ ## Concepts
73
+
74
+ ### Exchange
75
+
76
+ An `Exchange` represents a single HTTP transaction. It couples the incoming
77
+ request with its outgoing response and exposes shared per-request state,
78
+ correlation identifiers, and a cancellation signal.
79
+
80
+ Exchanges are created by the runtime and passed to middleware and handlers.
81
+ Consumers do not construct exchanges.
82
+
83
+ ```js
84
+ server.get('/hello', async (exchange) => {
85
+ exchange.response.json({ message: 'Hello, World!' });
86
+ });
87
+ ```
88
+
89
+ Key properties: `id`, `traceId`, `spanId`, `signal`, `request`, `response`,
90
+ and `state` (a mutable plain object for request-scoped data).
91
+
92
+ ### Request
93
+
94
+ A transport-independent view of the incoming message. Exposes normalized
95
+ metadata and lazy body access via `request.body()`.
96
+
97
+ Supported media types for `body()`:
98
+
99
+ | Media type | Result |
100
+ |-------------------------------------|---------------------------------|
101
+ | `application/json` | Parsed JSON value |
102
+ | `application/*+json` | Parsed JSON value |
103
+ | `application/x-www-form-urlencoded` | Parsed key/value object |
104
+ | `multipart/form-data` | Parsed multipart representation |
105
+
106
+ Unsupported media types raise `RequestError`. When the body exceeds the
107
+ configured limit, reading fails with `RequestError` and the connection may
108
+ be closed without a normal error response.
109
+
110
+ The `CONNECT` method is not supported.
111
+
112
+ ### Response
113
+
114
+ Built progressively by configuring status, headers, and body. Body methods
115
+ do not send anything; only `end()` materializes and sends the response.
116
+ A response can describe at most one body.
117
+
118
+ Convenience methods: `json()`, `html()`, `text()`, `send()`, `stream()`,
119
+ `redirect()`, `cache()`, `noCache()`, `vary()`.
120
+
121
+ ### Middleware
122
+
123
+ Middleware functions receive `(exchange, next)` and run in registration
124
+ order. They may be registered globally, by pathname, on a route, or on a
125
+ router.
126
+
127
+ ```js
128
+ server.use(async (exchange, next) => {
129
+ // before
130
+ await next();
131
+ // after
132
+ });
133
+ ```
134
+
135
+ ### Not Found and System Error Handling
136
+
137
+ - `server.notFound(handler)` — when no route matches (default: `404` JSON).
138
+ - `server.systemError(handler)` — when an error propagates (default: `500` JSON).
139
+
140
+ ## Routing
141
+
142
+ Routes associate an HTTP method and a pathname pattern with middleware.
143
+
144
+ Supported methods: `get`, `post`, `put`, `patch`, `delete`, `head`,
145
+ `trace`, `query`. Routers also support `all()`. `OPTIONS` is handled
146
+ automatically.
147
+
148
+ Pathname patterns support literals, named parameters (`:id` or `{id}`),
149
+ and wildcards (`*` / trailing `/*`). Named parameters and wildcards are
150
+ used only for matching; captured values are not exposed on the exchange.
151
+ To read a path segment, parse `exchange.request.pathname` directly.
152
+
153
+ ```js
154
+ const api = new Router();
155
+ api.get('/users', listUsers);
156
+ server.mount('/api', api);
157
+ // Available at /api/users
158
+ ```
159
+
160
+ ## Server Configuration
161
+
162
+ Four configuration classes fix the transport:
163
+
164
+ | Class | Protocol | Transport |
165
+ |-------------------------------------|----------|-----------|
166
+ | `HttpServerConfiguration` | `http` | `h1` |
167
+ | `HttpsServerConfiguration` | `https` | `h1s` |
168
+ | `Http2CleartextServerConfiguration` | `http` | `h2c` |
169
+ | `Http2SecureServerConfiguration` | `https` | `h2` |
170
+
171
+ Common top-level options: `connection`, `listen`, `request`, `response`,
172
+ `static`, `cors`, `securityHeaders`, `rateLimit`, `cookie`, `csrf`,
173
+ `compress`.
174
+
175
+ These options enable server features. When enabled, the corresponding
176
+ behavior is applied before user-registered middleware.
177
+
178
+ See the [full API reference](./Docs/BOO_SERVER_API.md) for the complete
179
+ option shapes and defaults.
180
+
181
+ ## Lifecycle and Events
182
+
183
+ ```js
184
+ await server.listen();
185
+ // ...
186
+ await server.close();
187
+ ```
188
+
189
+ States: `idle` → `starting` → `listening` → `stopping` → `closed` (or `error`).
190
+
191
+ Events: `listen`, `close`, `error`, `exchange:start`, `exchange:end`,
192
+ `exchange:error`. Convenience methods: `onListen()`, `onClose()`,
193
+ `onError()`, `onExchangeStart()`, `onExchangeEnd()`, `onExchangeError()`.
194
+
195
+ `Server` implements `Symbol.asyncDispose` for `await using` when the
196
+ runtime supports it.
197
+
198
+ ## IPC
199
+
200
+ An IPC API over WebSocket at `/ipc`. Supports request-response channels
201
+ (`handle` / invoke) and one-way events (`on` / event). Available while the
202
+ server is listening via `server.ipc`.
203
+
204
+ See the [full API reference](./Docs/BOO_SERVER_API.md) for the wire protocol
205
+ and handler details.
206
+
207
+ ## Errors
208
+
209
+ Public APIs throw errors that extend `Error` and expose a stable `code`
210
+ property. Error types include `ServerConfigurationError`, `RequestError`,
211
+ `ResponseError`, `RouterError`, `PathnamePatternError`, `MiddlewareError`,
212
+ `ServerError`, and `IPCError`.
213
+
214
+ Error codes are documented in the
215
+ [project wiki](https://github.com/vgbr-dev/boo-labs/wiki/Errors).
216
+
217
+ ## Documentation
218
+
219
+ - [Full API reference](./Docs/SERVER_API.md) — complete public API,
220
+ configuration options, response methods, IPC protocol, and more.
221
+
222
+ ## License
223
+
224
+ Distributed under the MIT License. See the [LICENSE](./LICENSE) file for
225
+ details.
226
+
227
+ ## Dedication
228
+
229
+ This project is named after my sister — "Boo". Her nickname gave this
230
+ project its name.
package/index.mjs ADDED
@@ -0,0 +1,23 @@
1
+ // @ts-check
2
+ /**
3
+ * @file Entry point for `ES Module` consumers.
4
+ *
5
+ * @description Provides the default export and named exports of the
6
+ * `@boo/server` public API for modern JavaScript environments using ES Modules.
7
+ *
8
+ * This file acts as a facade, re-exporting the main functionality from the
9
+ * internal source module while maintaining a clean public boundary.
10
+ *
11
+ * @module @boo/server/esm
12
+ * @since 1.0.0
13
+ */
14
+
15
+ // ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
16
+ export {
17
+ default,
18
+ Router,
19
+ HttpServerConfiguration,
20
+ HttpsServerConfiguration,
21
+ Http2CleartextServerConfiguration,
22
+ Http2SecureServerConfiguration,
23
+ } from './source/index.mjs';
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@boo-labs/server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "A zero-dependency, frameworkless HTTP server for Node.js, built around Clean Architecture principles.",
5
+ "keywords": [
6
+ "http-server",
7
+ "nodejs",
8
+ "zero-dependency",
9
+ "frameworkless",
10
+ "esm",
11
+ "router",
12
+ "middleware",
13
+ "clean-architecture"
14
+ ],
15
+ "homepage": "https://github.com/vgbr-dev/boo-labs#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/vgbr-dev/boo-labs/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/vgbr-dev/boo-labs.git",
22
+ "directory": "packages/server"
23
+ },
24
+ "files": [
25
+ "source",
26
+ "types",
27
+ "index.mjs",
28
+ "README.md",
29
+ "LICENSE"
30
+ ],
31
+ "author": {
32
+ "name": "Victor Giovanni Beltrán Rodríguez",
33
+ "email": "vgbr.dev@gmail.com",
34
+ "url": "https://vgbr-dev.blogspot.com"
35
+ },
36
+ "type": "module",
37
+ "license": "MIT",
38
+ "types": "./types/index.d.ts",
39
+ "exports": {
40
+ ".": {
41
+ "types": "./types/index.d.ts",
42
+ "import": "./index.mjs",
43
+ "default": "./index.mjs"
44
+ }
45
+ },
46
+ "imports": {
47
+ "#Server": "./source/application/Server/index.mjs",
48
+ "#Kernel": "./source/application/Kernel/index.mjs",
49
+ "#Exchange": "./source/core/Exchange/index.mjs",
50
+ "#IPCMain": "./source/core/IPCMain/IPCMain.mjs",
51
+ "#ServerOptions/*": "./source/application/configurations/ServerConfiguration/Options/*/index.mjs",
52
+ "#configurations/*": "./source/application/configurations/*/index.mjs",
53
+ "#Request": "./source/core/Request/index.mjs",
54
+ "#Response": "./source/core/Response/index.mjs",
55
+ "#use-cases/*": "./source/application/use-cases/*/index.mjs",
56
+ "#value-objects/*": "./source/core/value-objects/*/index.mjs",
57
+ "#adapters/*": "./source/infrastructure/adapters/*/index.mjs",
58
+ "#resolvers/*": "./source/application/resolvers/*/index.mjs",
59
+ "#routing/*": "./source/core/routing/*/index.mjs",
60
+ "#ExchangeLayerBuilder": "./source/core/ExchangeLayerBuilder/index.mjs",
61
+ "#middlewares/*": "./source/core/middlewares/*/index.mjs",
62
+ "#EventSystem": "./source/core/EventSystem/index.mjs",
63
+ "#shared/*": "./source/shared/*/index.mjs"
64
+ },
65
+ "scripts": {
66
+ "test": "node --env-file=.env.test --test test/**/*.test.mjs",
67
+ "lint": "eslint .",
68
+ "prepublishOnly": "npm test"
69
+ },
70
+ "engines": {
71
+ "node": ">=22"
72
+ }
73
+ }