@boo-labs/server 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +287 -2
- package/index.mjs +23 -0
- package/package.json +71 -4
- package/source/application/Kernel/index.mjs +1137 -0
- package/source/application/Server/index.mjs +1201 -0
- package/source/application/configurations/Http2CleartextServerConfiguration/index.mjs +168 -0
- package/source/application/configurations/Http2SecureServerConfiguration/index.mjs +172 -0
- package/source/application/configurations/HttpServerConfiguration/index.mjs +169 -0
- package/source/application/configurations/HttpsServerConfiguration/index.mjs +172 -0
- package/source/application/configurations/ServerConfiguration/Options/CORSOptions/CORSOptionsValue.mjs +158 -0
- package/source/application/configurations/ServerConfiguration/Options/CORSOptions/index.mjs +87 -0
- package/source/application/configurations/ServerConfiguration/Options/CSRFOptions/CSRFOptionsValue.mjs +178 -0
- package/source/application/configurations/ServerConfiguration/Options/CSRFOptions/index.mjs +80 -0
- package/source/application/configurations/ServerConfiguration/Options/CompressOptions/CompressOptionsValue.mjs +126 -0
- package/source/application/configurations/ServerConfiguration/Options/CompressOptions/index.mjs +81 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieParserOptions/CookieParserOptionsValue.mjs +107 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieParserOptions/index.mjs +82 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieSessionOptions/CookieSessionOptionsValue.mjs +182 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieSessionOptions/index.mjs +86 -0
- package/source/application/configurations/ServerConfiguration/Options/ListenOptions/ListenOptionsValue.mjs +95 -0
- package/source/application/configurations/ServerConfiguration/Options/ListenOptions/index.mjs +47 -0
- package/source/application/configurations/ServerConfiguration/Options/MiddlewareOption.mjs +102 -0
- package/source/application/configurations/ServerConfiguration/Options/Options.mjs +105 -0
- package/source/application/configurations/ServerConfiguration/Options/RateLimitOptions/RateLimitOptionsValue.mjs +164 -0
- package/source/application/configurations/ServerConfiguration/Options/RateLimitOptions/index.mjs +84 -0
- package/source/application/configurations/ServerConfiguration/Options/RequestOptions/RequestOptionsValue.mjs +108 -0
- package/source/application/configurations/ServerConfiguration/Options/RequestOptions/index.mjs +47 -0
- package/source/application/configurations/ServerConfiguration/Options/ResponseOptions/ResponseOptionsValue.mjs +101 -0
- package/source/application/configurations/ServerConfiguration/Options/ResponseOptions/index.mjs +47 -0
- package/source/application/configurations/ServerConfiguration/Options/SecurityHeadersOptions/SecurityHeadersOptionsValue.mjs +272 -0
- package/source/application/configurations/ServerConfiguration/Options/SecurityHeadersOptions/index.mjs +85 -0
- package/source/application/configurations/ServerConfiguration/Options/ServerOption.mjs +50 -0
- package/source/application/configurations/ServerConfiguration/Options/StaticOptions/StaticOptionsValue.mjs +164 -0
- package/source/application/configurations/ServerConfiguration/Options/StaticOptions/index.mjs +89 -0
- package/source/application/configurations/ServerConfiguration/index.mjs +781 -0
- package/source/application/resolvers/TransportResolver/index.mjs +119 -0
- package/source/application/use-cases/CloseServer/index.mjs +85 -0
- package/source/application/use-cases/ListenServer/index.mjs +98 -0
- package/source/core/EventSystem/index.mjs +110 -0
- package/source/core/Exchange/ExchangeContext.mjs +291 -0
- package/source/core/Exchange/Telemetry.mjs +193 -0
- package/source/core/Exchange/index.mjs +604 -0
- package/source/core/ExchangeLayerBuilder/index.mjs +133 -0
- package/source/core/IPCMain/IPCMain.mjs +507 -0
- package/source/core/IPCMain/IPCProtocol.mjs +441 -0
- package/source/core/IPCMain/IPCServerChannel.mjs +331 -0
- package/source/core/IPCMain/WebSocketAdapter.mjs +189 -0
- package/source/core/Request/BodyParser/BodyParser.mjs +197 -0
- package/source/core/Request/BodyParser/JSONParser.mjs +70 -0
- package/source/core/Request/BodyParser/MultipartParser.mjs +612 -0
- package/source/core/Request/BodyParser/URLEncodedParser.mjs +71 -0
- package/source/core/Request/RequestHeaders.mjs +177 -0
- package/source/core/Request/index.mjs +805 -0
- package/source/core/Response/ResponseHeaders.mjs +402 -0
- package/source/core/Response/index.mjs +1370 -0
- package/source/core/middlewares/CORSMiddleware/index.mjs +289 -0
- package/source/core/middlewares/CSRFMiddleware/index.mjs +284 -0
- package/source/core/middlewares/CompressMiddleware/index.mjs +460 -0
- package/source/core/middlewares/CookieParserMiddleware/index.mjs +194 -0
- package/source/core/middlewares/CookieSessionMiddleware/index.mjs +460 -0
- package/source/core/middlewares/RateLimitMiddleware/index.mjs +245 -0
- package/source/core/middlewares/SecurityHeadersMiddleware/index.mjs +151 -0
- package/source/core/middlewares/StaticMiddleware/index.mjs +628 -0
- package/source/core/routing/ExchangeLayer/ExchangeMatcher.mjs +127 -0
- package/source/core/routing/ExchangeLayer/index.mjs +254 -0
- package/source/core/routing/Pipeline/index.mjs +157 -0
- package/source/core/routing/Router/Route.mjs +184 -0
- package/source/core/routing/Router/index.mjs +523 -0
- package/source/core/routing/RouterRegister/OptionsMiddleware.mjs +147 -0
- package/source/core/routing/RouterRegister/index.mjs +150 -0
- package/source/core/routing/RouterSystem/index.mjs +225 -0
- package/source/core/value-objects/Address/index.mjs +281 -0
- package/source/core/value-objects/Endpoint/index.mjs +293 -0
- package/source/index.mjs +62 -0
- package/source/infrastructure/adapters/Http2Adapter/index.mjs +144 -0
- package/source/infrastructure/adapters/Http2CleartextAdapter/index.mjs +147 -0
- package/source/infrastructure/adapters/HttpAdapter/index.mjs +124 -0
- package/source/infrastructure/adapters/HttpsAdapter/index.mjs +124 -0
- package/source/infrastructure/adapters/TransportAdapter/createWebSocketOpenRequest.mjs +843 -0
- package/source/infrastructure/adapters/TransportAdapter/index.mjs +555 -0
- package/source/shared/Identifier/index.mjs +671 -0
- package/source/shared/constants/symbols/brands/index.mjs +45 -0
- package/source/shared/domain/UUIDV7/index.mjs +346 -0
- package/source/shared/errors/BaseError/index.mjs +157 -0
- package/source/shared/errors/IPCError/index.mjs +97 -0
- package/source/shared/errors/MiddlewareError/index.mjs +106 -0
- package/source/shared/errors/PathnamePatternError/index.mjs +103 -0
- package/source/shared/errors/RequestError/index.mjs +116 -0
- package/source/shared/errors/ResponseError/index.mjs +140 -0
- package/source/shared/errors/RouterError/index.mjs +90 -0
- package/source/shared/errors/ServerConfigurationError/index.mjs +551 -0
- package/source/shared/errors/ServerError/index.mjs +127 -0
- package/source/shared/errors/WebSocketError/index.mjs +58 -0
- package/source/shared/outcome/ErrorSchema.mjs +361 -0
- package/source/shared/outcome/Result/index.mjs +239 -0
- package/source/shared/outcome/Validation/index.mjs +208 -0
- package/source/shared/validations/Middleware/index.mjs +160 -0
- package/source/shared/validations/PathnamePattern/index.mjs +256 -0
- package/source/shared/validations/Server/NotFoundHandler/index.mjs +94 -0
- package/source/shared/validations/Server/Router/index.mjs +68 -0
- package/source/shared/validations/Server/ServerConfiguration/index.mjs +68 -0
- package/source/shared/validations/Server/SystemErrorHandler/index.mjs +94 -0
- package/source/shared/validations/ServerConfiguration/CORSOptions/index.mjs +310 -0
- package/source/shared/validations/ServerConfiguration/CSRFOptions/index.mjs +299 -0
- package/source/shared/validations/ServerConfiguration/CompressOptions/index.mjs +204 -0
- package/source/shared/validations/ServerConfiguration/CookieParserOptions/index.mjs +102 -0
- package/source/shared/validations/ServerConfiguration/CookieSessionOptions/index.mjs +332 -0
- package/source/shared/validations/ServerConfiguration/ListenOptions/index.mjs +178 -0
- package/source/shared/validations/ServerConfiguration/RateLimitOptions/index.mjs +229 -0
- package/source/shared/validations/ServerConfiguration/RequestOptions/index.mjs +132 -0
- package/source/shared/validations/ServerConfiguration/ResponseOptions/index.mjs +122 -0
- package/source/shared/validations/ServerConfiguration/SecurityHeadersOptions/index.mjs +137 -0
- package/source/shared/validations/ServerConfiguration/StaticOptions/index.mjs +248 -0
- package/types/index.d.ts +719 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Defines domain-specific errors for server configuration.
|
|
3
|
+
*
|
|
4
|
+
* @description ServerConfigurationError extends BaseError to provide
|
|
5
|
+
* structured, identifiable errors specific to server configuration
|
|
6
|
+
* validation, including request options, response options, listen
|
|
7
|
+
* options, static options, and adapter initialization failures.
|
|
8
|
+
*
|
|
9
|
+
* @module ServerConfigurationError
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// ━━ IMPORT MODULES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
13
|
+
// » IMPORT LOCAL MODULES
|
|
14
|
+
import BaseError from '../BaseError/index.mjs';
|
|
15
|
+
|
|
16
|
+
// ━━ TYPE DEFINITIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
17
|
+
/**
|
|
18
|
+
* @template {string} T
|
|
19
|
+
* @typedef {T | (string & {})} LiteralUnion
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Identifies a predefined server configuration error or allows a custom
|
|
24
|
+
* error message.
|
|
25
|
+
*
|
|
26
|
+
* @typedef {LiteralUnion<
|
|
27
|
+
* 'INVALID_REQUEST_OPTIONS' |
|
|
28
|
+
* 'INVALID_BODY_LIMIT' |
|
|
29
|
+
* 'INVALID_BODY_LIMIT_TYPE' |
|
|
30
|
+
* 'INVALID_BODY_LIMIT_RANGE' |
|
|
31
|
+
* 'INVALID_TRUST_PROXY' |
|
|
32
|
+
* 'INVALID_TRUST_PROXY_TYPE' |
|
|
33
|
+
* 'INVALID_TRUST_PROXY_RANGE' |
|
|
34
|
+
* 'INVALID_RESPONSE_OPTIONS' |
|
|
35
|
+
* 'INVALID_ETAG_TYPE' |
|
|
36
|
+
* 'INVALID_ETAG' |
|
|
37
|
+
* 'INVALID_DEFAULT_CHARSET_TYPE' |
|
|
38
|
+
* 'INVALID_DEFAULT_CHARSET_VALUE' |
|
|
39
|
+
* 'INVALID_DEFAULT_CHARSET' |
|
|
40
|
+
* 'INVALID_LISTEN_OPTIONS' |
|
|
41
|
+
* 'MISSING_PORT' |
|
|
42
|
+
* 'INVALID_PORT' |
|
|
43
|
+
* 'INVALID_PORT_TYPE' |
|
|
44
|
+
* 'INVALID_PORT_RANGE' |
|
|
45
|
+
* 'INVALID_HOST' |
|
|
46
|
+
* 'INVALID_HOST_TYPE' |
|
|
47
|
+
* 'INVALID_HOST_VALUE' |
|
|
48
|
+
* 'INVALID_HOST_RANGE' |
|
|
49
|
+
* 'INVALID_BACKLOG' |
|
|
50
|
+
* 'INVALID_BACKLOG_TYPE' |
|
|
51
|
+
* 'INVALID_BACKLOG_RANGE' |
|
|
52
|
+
* 'INVALID_STATIC_OPTIONS' |
|
|
53
|
+
* 'MISSING_STATIC_ROOT' |
|
|
54
|
+
* 'INVALID_STATIC_ROOT_TYPE' |
|
|
55
|
+
* 'INVALID_STATIC_ROOT_VALUE' |
|
|
56
|
+
* 'INVALID_STATIC_INDEX_TYPE' |
|
|
57
|
+
* 'INVALID_STATIC_INDEX_ITEM' |
|
|
58
|
+
* 'INVALID_STATIC_MAX_AGE_TYPE' |
|
|
59
|
+
* 'INVALID_STATIC_MAX_AGE_VALUE' |
|
|
60
|
+
* 'INVALID_STATIC_ETAG_TYPE' |
|
|
61
|
+
* 'INVALID_STATIC_LAST_MODIFIED_TYPE' |
|
|
62
|
+
* 'INVALID_STATIC_FALLTHROUGH_TYPE' |
|
|
63
|
+
* 'INVALID_STATIC_EXTENSIONS_TYPE' |
|
|
64
|
+
* 'INVALID_STATIC_EXTENSIONS_ITEM' |
|
|
65
|
+
* 'INVALID_STATIC_DOTFILES_TYPE' |
|
|
66
|
+
* 'SERVER_CONFIGURATION_INVALID' |
|
|
67
|
+
* 'SERVER_ADAPTER_INIT_FAILED' |
|
|
68
|
+
* 'INVALID_CORS_OPTIONS' |
|
|
69
|
+
* 'INVALID_CORS_ORIGIN_TYPE' |
|
|
70
|
+
* 'INVALID_CORS_ORIGIN_ITEM' |
|
|
71
|
+
* 'INVALID_CORS_METHODS_TYPE' |
|
|
72
|
+
* 'INVALID_CORS_METHODS_ITEM' |
|
|
73
|
+
* 'INVALID_CORS_ALLOWED_HEADERS_TYPE' |
|
|
74
|
+
* 'INVALID_CORS_ALLOWED_HEADERS_ITEM' |
|
|
75
|
+
* 'INVALID_CORS_EXPOSED_HEADERS_TYPE' |
|
|
76
|
+
* 'INVALID_CORS_EXPOSED_HEADERS_ITEM' |
|
|
77
|
+
* 'INVALID_CORS_CREDENTIALS_TYPE' |
|
|
78
|
+
* 'INVALID_CORS_MAX_AGE_TYPE' |
|
|
79
|
+
* 'INVALID_CORS_MAX_AGE_RANGE' |
|
|
80
|
+
* 'INVALID_CORS_PREFLIGHT_CONTINUE_TYPE' |
|
|
81
|
+
* 'INVALID_CORS_OPTIONS_SUCCESS_STATUS_TYPE' |
|
|
82
|
+
* 'INVALID_CORS_OPTIONS_SUCCESS_STATUS_RANGE' |
|
|
83
|
+
* 'INVALID_SECURITY_HEADERS_OPTIONS' |
|
|
84
|
+
* 'INVALID_SECURITY_HEADERS_OPTION_TYPE' |
|
|
85
|
+
* 'INVALID_RATE_LIMIT_OPTIONS' |
|
|
86
|
+
* 'INVALID_RATE_LIMIT_WINDOW_MS_TYPE' |
|
|
87
|
+
* 'INVALID_RATE_LIMIT_WINDOW_MS_RANGE' |
|
|
88
|
+
* 'INVALID_RATE_LIMIT_MAX_TYPE' |
|
|
89
|
+
* 'INVALID_RATE_LIMIT_MAX_RANGE' |
|
|
90
|
+
* 'INVALID_RATE_LIMIT_STATUS_CODE_TYPE' |
|
|
91
|
+
* 'INVALID_RATE_LIMIT_STATUS_CODE_RANGE' |
|
|
92
|
+
* 'INVALID_RATE_LIMIT_MESSAGE_TYPE' |
|
|
93
|
+
* 'INVALID_RATE_LIMIT_STANDARD_HEADERS_TYPE' |
|
|
94
|
+
* 'INVALID_RATE_LIMIT_LEGACY_HEADERS_TYPE' |
|
|
95
|
+
* 'INVALID_COOKIE_PARSER_OPTIONS' |
|
|
96
|
+
* 'INVALID_COOKIE_PARSER_DECODE_TYPE' |
|
|
97
|
+
* 'INVALID_COOKIE_SESSION_OPTIONS' |
|
|
98
|
+
* 'COOKIE_SESSION_REQUIRES_COOKIE_PARSER' |
|
|
99
|
+
* 'MISSING_COOKIE_SESSION_KEYS' |
|
|
100
|
+
* 'INVALID_COOKIE_SESSION_NAME_TYPE' |
|
|
101
|
+
* 'INVALID_COOKIE_SESSION_NAME_VALUE' |
|
|
102
|
+
* 'INVALID_COOKIE_SESSION_KEYS_TYPE' |
|
|
103
|
+
* 'INVALID_COOKIE_SESSION_KEYS_ITEM' |
|
|
104
|
+
* 'INVALID_COOKIE_SESSION_MAX_AGE_TYPE' |
|
|
105
|
+
* 'INVALID_COOKIE_SESSION_MAX_AGE_RANGE' |
|
|
106
|
+
* 'INVALID_COOKIE_SESSION_PATH_TYPE' |
|
|
107
|
+
* 'INVALID_COOKIE_SESSION_PATH_VALUE' |
|
|
108
|
+
* 'INVALID_COOKIE_SESSION_DOMAIN_TYPE' |
|
|
109
|
+
* 'INVALID_COOKIE_SESSION_DOMAIN_VALUE' |
|
|
110
|
+
* 'INVALID_COOKIE_SESSION_SECURE_TYPE' |
|
|
111
|
+
* 'INVALID_COOKIE_SESSION_HTTP_ONLY_TYPE' |
|
|
112
|
+
* 'INVALID_COOKIE_SESSION_SAME_SITE_VALUE' |
|
|
113
|
+
* 'INVALID_COOKIE_SESSION_OVERWRITE_TYPE' |
|
|
114
|
+
* 'COOKIE_SESSION_NONE_REQUIRES_SECURE' |
|
|
115
|
+
* 'INVALID_CSRF_OPTIONS' |
|
|
116
|
+
* 'INVALID_CSRF_COOKIE_NAME_TYPE' |
|
|
117
|
+
* 'INVALID_CSRF_COOKIE_NAME_VALUE' |
|
|
118
|
+
* 'INVALID_CSRF_HEADER_NAME_TYPE' |
|
|
119
|
+
* 'INVALID_CSRF_HEADER_NAME_VALUE' |
|
|
120
|
+
* 'INVALID_CSRF_SAFE_METHODS_TYPE' |
|
|
121
|
+
* 'INVALID_CSRF_SAFE_METHODS_ITEM' |
|
|
122
|
+
* 'INVALID_CSRF_TOKEN_BYTES_TYPE' |
|
|
123
|
+
* 'INVALID_CSRF_TOKEN_BYTES_RANGE' |
|
|
124
|
+
* 'INVALID_CSRF_PATH_TYPE' |
|
|
125
|
+
* 'INVALID_CSRF_PATH_VALUE' |
|
|
126
|
+
* 'INVALID_CSRF_DOMAIN_TYPE' |
|
|
127
|
+
* 'INVALID_CSRF_DOMAIN_VALUE' |
|
|
128
|
+
* 'INVALID_CSRF_SECURE_TYPE' |
|
|
129
|
+
* 'INVALID_CSRF_SAME_SITE_VALUE' |
|
|
130
|
+
* 'CSRF_NONE_REQUIRES_SECURE' |
|
|
131
|
+
* 'INVALID_COMPRESS_OPTIONS' |
|
|
132
|
+
* 'INVALID_COMPRESS_THRESHOLD_TYPE' |
|
|
133
|
+
* 'INVALID_COMPRESS_THRESHOLD_RANGE' |
|
|
134
|
+
* 'INVALID_COMPRESS_LEVEL_TYPE' |
|
|
135
|
+
* 'INVALID_COMPRESS_LEVEL_RANGE' |
|
|
136
|
+
* 'INVALID_COMPRESS_TYPES_TYPE' |
|
|
137
|
+
* 'INVALID_COMPRESS_TYPES_ITEM'
|
|
138
|
+
* >} ServerConfigurationErrorIdentifier
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Options for creating an error instance.
|
|
143
|
+
*
|
|
144
|
+
* @typedef {object} ServerConfigurationErrorOptions
|
|
145
|
+
* @property {Record<string, unknown>} [values] - Values for template placeholders in the error message.
|
|
146
|
+
* @property {unknown} [details] - Additional contextual information about the error.
|
|
147
|
+
* @property {Error} [cause] - The original error that caused this error.
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
// ━━ MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
151
|
+
/**
|
|
152
|
+
* Error thrown when server configuration is invalid or an adapter cannot
|
|
153
|
+
* be initialized.
|
|
154
|
+
*
|
|
155
|
+
* @classdesc This error type provides identifiable failures related to
|
|
156
|
+
* server configuration validation and adapter lifecycle.
|
|
157
|
+
*
|
|
158
|
+
* @augments BaseError
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
class ServerConfigurationError extends BaseError {
|
|
162
|
+
/**
|
|
163
|
+
* Creates a new {@link ServerConfigurationError}.
|
|
164
|
+
*
|
|
165
|
+
* @param {ServerConfigurationErrorIdentifier} identifier - A predefined error identifier or a custom error message.
|
|
166
|
+
* @param {ServerConfigurationErrorOptions} [options] - Additional information used to format the message, attach domain details, or preserve the original cause.
|
|
167
|
+
* @example
|
|
168
|
+
* ```js
|
|
169
|
+
* throw new ServerConfigurationError('INVALID_BODY_LIMIT', {
|
|
170
|
+
* values: { received: typeof bodyLimit },
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
* @example
|
|
174
|
+
* ```js
|
|
175
|
+
* throw new ServerConfigurationError('MISSING_PORT', {
|
|
176
|
+
* values: {},
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
constructor(identifier, options = {}) {
|
|
181
|
+
super(identifier, options);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Collection of predefined server configuration error messages.
|
|
186
|
+
*
|
|
187
|
+
* Available error identifiers:
|
|
188
|
+
*
|
|
189
|
+
* Request options:
|
|
190
|
+
*
|
|
191
|
+
* - `'INVALID_REQUEST_OPTIONS'`.
|
|
192
|
+
* - `'INVALID_BODY_LIMIT'`.
|
|
193
|
+
* - `'INVALID_BODY_LIMIT_TYPE'`.
|
|
194
|
+
* - `'INVALID_BODY_LIMIT_RANGE'`.
|
|
195
|
+
* - `'INVALID_TRUST_PROXY'`.
|
|
196
|
+
* - `'INVALID_TRUST_PROXY_TYPE'`.
|
|
197
|
+
* - `'INVALID_TRUST_PROXY_RANGE'`.
|
|
198
|
+
*
|
|
199
|
+
* Response options:
|
|
200
|
+
*
|
|
201
|
+
* - `'INVALID_RESPONSE_OPTIONS'`.
|
|
202
|
+
* - `'INVALID_ETAG_TYPE'`.
|
|
203
|
+
* - `'INVALID_ETAG'`.
|
|
204
|
+
* - `'INVALID_DEFAULT_CHARSET_TYPE'`.
|
|
205
|
+
* - `'INVALID_DEFAULT_CHARSET_VALUE'`.
|
|
206
|
+
* - `'INVALID_DEFAULT_CHARSET'`.
|
|
207
|
+
*
|
|
208
|
+
* Listen options:
|
|
209
|
+
*
|
|
210
|
+
* - `'INVALID_LISTEN_OPTIONS'`.
|
|
211
|
+
* - `'MISSING_PORT'`.
|
|
212
|
+
* - `'INVALID_PORT'`.
|
|
213
|
+
* - `'INVALID_PORT_TYPE'`.
|
|
214
|
+
* - `'INVALID_PORT_RANGE'`.
|
|
215
|
+
* - `'INVALID_HOST'`.
|
|
216
|
+
* - `'INVALID_HOST_TYPE'`.
|
|
217
|
+
* - `'INVALID_HOST_VALUE'`.
|
|
218
|
+
* - `'INVALID_HOST_RANGE'`.
|
|
219
|
+
* - `'INVALID_BACKLOG'`.
|
|
220
|
+
* - `'INVALID_BACKLOG_TYPE'`.
|
|
221
|
+
* - `'INVALID_BACKLOG_RANGE'`.
|
|
222
|
+
*
|
|
223
|
+
* Static options:
|
|
224
|
+
*
|
|
225
|
+
* - `'INVALID_STATIC_OPTIONS'`.
|
|
226
|
+
* - `'MISSING_STATIC_ROOT'`.
|
|
227
|
+
* - `'INVALID_STATIC_ROOT_TYPE'`.
|
|
228
|
+
* - `'INVALID_STATIC_ROOT_VALUE'`.
|
|
229
|
+
* - `'INVALID_STATIC_INDEX_TYPE'`.
|
|
230
|
+
* - `'INVALID_STATIC_INDEX_ITEM'`.
|
|
231
|
+
* - `'INVALID_STATIC_MAX_AGE_TYPE'`.
|
|
232
|
+
* - `'INVALID_STATIC_MAX_AGE_VALUE'`.
|
|
233
|
+
* - `'INVALID_STATIC_ETAG_TYPE'`.
|
|
234
|
+
* - `'INVALID_STATIC_LAST_MODIFIED_TYPE'`.
|
|
235
|
+
* - `'INVALID_STATIC_FALLTHROUGH_TYPE'`.
|
|
236
|
+
* - `'INVALID_STATIC_EXTENSIONS_TYPE'`.
|
|
237
|
+
* - `'INVALID_STATIC_EXTENSIONS_ITEM'`.
|
|
238
|
+
* - `'INVALID_STATIC_DOTFILES_TYPE'`.
|
|
239
|
+
*
|
|
240
|
+
* Configuration:
|
|
241
|
+
*
|
|
242
|
+
* - `'SERVER_CONFIGURATION_INVALID'`.
|
|
243
|
+
* - `'SERVER_ADAPTER_INIT_FAILED'`.
|
|
244
|
+
*
|
|
245
|
+
* CORS options:
|
|
246
|
+
*
|
|
247
|
+
* - `'INVALID_CORS_OPTIONS'`.
|
|
248
|
+
* - `'INVALID_CORS_ORIGIN_TYPE'`.
|
|
249
|
+
* - `'INVALID_CORS_ORIGIN_ITEM'`.
|
|
250
|
+
* - `'INVALID_CORS_METHODS_TYPE'`.
|
|
251
|
+
* - `'INVALID_CORS_METHODS_ITEM'`.
|
|
252
|
+
* - `'INVALID_CORS_ALLOWED_HEADERS_TYPE'`.
|
|
253
|
+
* - `'INVALID_CORS_ALLOWED_HEADERS_ITEM'`.
|
|
254
|
+
* - `'INVALID_CORS_EXPOSED_HEADERS_TYPE'`.
|
|
255
|
+
* - `'INVALID_CORS_EXPOSED_HEADERS_ITEM'`.
|
|
256
|
+
* - `'INVALID_CORS_CREDENTIALS_TYPE'`.
|
|
257
|
+
* - `'INVALID_CORS_MAX_AGE_TYPE'`.
|
|
258
|
+
* - `'INVALID_CORS_MAX_AGE_RANGE'`.
|
|
259
|
+
* - `'INVALID_CORS_PREFLIGHT_CONTINUE_TYPE'`.
|
|
260
|
+
* - `'INVALID_CORS_OPTIONS_SUCCESS_STATUS_TYPE'`.
|
|
261
|
+
* - `'INVALID_CORS_OPTIONS_SUCCESS_STATUS_RANGE'`.
|
|
262
|
+
*
|
|
263
|
+
* Security headers options:
|
|
264
|
+
*
|
|
265
|
+
* - `'INVALID_SECURITY_HEADERS_OPTIONS'`.
|
|
266
|
+
* - `'INVALID_SECURITY_HEADERS_OPTION_TYPE'`.
|
|
267
|
+
*
|
|
268
|
+
* Rate limit options:
|
|
269
|
+
*
|
|
270
|
+
* - `'INVALID_RATE_LIMIT_OPTIONS'`.
|
|
271
|
+
* - `'INVALID_RATE_LIMIT_WINDOW_MS_TYPE'`.
|
|
272
|
+
* - `'INVALID_RATE_LIMIT_WINDOW_MS_RANGE'`.
|
|
273
|
+
* - `'INVALID_RATE_LIMIT_MAX_TYPE'`.
|
|
274
|
+
* - `'INVALID_RATE_LIMIT_MAX_RANGE'`.
|
|
275
|
+
* - `'INVALID_RATE_LIMIT_STATUS_CODE_TYPE'`.
|
|
276
|
+
* - `'INVALID_RATE_LIMIT_STATUS_CODE_RANGE'`.
|
|
277
|
+
* - `'INVALID_RATE_LIMIT_MESSAGE_TYPE'`.
|
|
278
|
+
* - `'INVALID_RATE_LIMIT_STANDARD_HEADERS_TYPE'`.
|
|
279
|
+
* - `'INVALID_RATE_LIMIT_LEGACY_HEADERS_TYPE'`.
|
|
280
|
+
*
|
|
281
|
+
* Cookie parser options:
|
|
282
|
+
*
|
|
283
|
+
* - `'INVALID_COOKIE_PARSER_OPTIONS'`.
|
|
284
|
+
* - `'INVALID_COOKIE_PARSER_DECODE_TYPE'`.
|
|
285
|
+
*
|
|
286
|
+
* Cookie session options:
|
|
287
|
+
*
|
|
288
|
+
* - `'INVALID_COOKIE_SESSION_OPTIONS'`.
|
|
289
|
+
* - `'COOKIE_SESSION_REQUIRES_COOKIE_PARSER'`.
|
|
290
|
+
* - `'MISSING_COOKIE_SESSION_KEYS'`.
|
|
291
|
+
* - `'INVALID_COOKIE_SESSION_NAME_TYPE'`.
|
|
292
|
+
* - `'INVALID_COOKIE_SESSION_NAME_VALUE'`.
|
|
293
|
+
* - `'INVALID_COOKIE_SESSION_KEYS_TYPE'`.
|
|
294
|
+
* - `'INVALID_COOKIE_SESSION_KEYS_ITEM'`.
|
|
295
|
+
* - `'INVALID_COOKIE_SESSION_MAX_AGE_TYPE'`.
|
|
296
|
+
* - `'INVALID_COOKIE_SESSION_MAX_AGE_RANGE'`.
|
|
297
|
+
* - `'INVALID_COOKIE_SESSION_PATH_TYPE'`.
|
|
298
|
+
* - `'INVALID_COOKIE_SESSION_PATH_VALUE'`.
|
|
299
|
+
* - `'INVALID_COOKIE_SESSION_DOMAIN_TYPE'`.
|
|
300
|
+
* - `'INVALID_COOKIE_SESSION_DOMAIN_VALUE'`.
|
|
301
|
+
* - `'INVALID_COOKIE_SESSION_SECURE_TYPE'`.
|
|
302
|
+
* - `'INVALID_COOKIE_SESSION_HTTP_ONLY_TYPE'`.
|
|
303
|
+
* - `'INVALID_COOKIE_SESSION_SAME_SITE_VALUE'`.
|
|
304
|
+
* - `'INVALID_COOKIE_SESSION_OVERWRITE_TYPE'`.
|
|
305
|
+
* - `'COOKIE_SESSION_NONE_REQUIRES_SECURE'`.
|
|
306
|
+
*
|
|
307
|
+
* CSRF options:
|
|
308
|
+
*
|
|
309
|
+
* - `'INVALID_CSRF_OPTIONS'`.
|
|
310
|
+
* - `'INVALID_CSRF_COOKIE_NAME_TYPE'`.
|
|
311
|
+
* - `'INVALID_CSRF_COOKIE_NAME_VALUE'`.
|
|
312
|
+
* - `'INVALID_CSRF_HEADER_NAME_TYPE'`.
|
|
313
|
+
* - `'INVALID_CSRF_HEADER_NAME_VALUE'`.
|
|
314
|
+
* - `'INVALID_CSRF_SAFE_METHODS_TYPE'`.
|
|
315
|
+
* - `'INVALID_CSRF_SAFE_METHODS_ITEM'`.
|
|
316
|
+
* - `'INVALID_CSRF_TOKEN_BYTES_TYPE'`.
|
|
317
|
+
* - `'INVALID_CSRF_TOKEN_BYTES_RANGE'`.
|
|
318
|
+
* - `'INVALID_CSRF_PATH_TYPE'`.
|
|
319
|
+
* - `'INVALID_CSRF_PATH_VALUE'`.
|
|
320
|
+
* - `'INVALID_CSRF_DOMAIN_TYPE'`.
|
|
321
|
+
* - `'INVALID_CSRF_DOMAIN_VALUE'`.
|
|
322
|
+
* - `'INVALID_CSRF_SECURE_TYPE'`.
|
|
323
|
+
* - `'INVALID_CSRF_SAME_SITE_VALUE'`.
|
|
324
|
+
* - `'CSRF_NONE_REQUIRES_SECURE'`.
|
|
325
|
+
*
|
|
326
|
+
* Compress options:
|
|
327
|
+
*
|
|
328
|
+
* - `'INVALID_COMPRESS_OPTIONS'`.
|
|
329
|
+
* - `'INVALID_COMPRESS_THRESHOLD_TYPE'`.
|
|
330
|
+
* - `'INVALID_COMPRESS_THRESHOLD_RANGE'`.
|
|
331
|
+
* - `'INVALID_COMPRESS_LEVEL_TYPE'`.
|
|
332
|
+
* - `'INVALID_COMPRESS_LEVEL_RANGE'`.
|
|
333
|
+
* - `'INVALID_COMPRESS_TYPES_TYPE'`.
|
|
334
|
+
* - `'INVALID_COMPRESS_TYPES_ITEM'`.
|
|
335
|
+
*
|
|
336
|
+
* @private
|
|
337
|
+
* @static
|
|
338
|
+
* @type {Map<ServerConfigurationErrorIdentifier, string>}
|
|
339
|
+
*/
|
|
340
|
+
static MESSAGES = new Map([
|
|
341
|
+
// ── Request options ────────────────────────────────────────────────────
|
|
342
|
+
['INVALID_REQUEST_OPTIONS', 'Request options must be a plain object, received: {received}.'],
|
|
343
|
+
['INVALID_BODY_LIMIT', 'bodyLimit must be a positive safe integer, received: {received}.'],
|
|
344
|
+
['INVALID_BODY_LIMIT_TYPE', 'bodyLimit must be a number, received: {received}.'],
|
|
345
|
+
[
|
|
346
|
+
'INVALID_BODY_LIMIT_RANGE',
|
|
347
|
+
'bodyLimit must be a positive safe integer, received: {bodyLimit}.',
|
|
348
|
+
],
|
|
349
|
+
[
|
|
350
|
+
'INVALID_TRUST_PROXY',
|
|
351
|
+
'trustProxy must be a boolean or a non-negative integer, received: {received}.',
|
|
352
|
+
],
|
|
353
|
+
[
|
|
354
|
+
'INVALID_TRUST_PROXY_TYPE',
|
|
355
|
+
'trustProxy must be a boolean or a non-negative integer, received: {received}.',
|
|
356
|
+
],
|
|
357
|
+
[
|
|
358
|
+
'INVALID_TRUST_PROXY_RANGE',
|
|
359
|
+
'trustProxy must be a non-negative integer, received: {trustProxy}.',
|
|
360
|
+
],
|
|
361
|
+
|
|
362
|
+
// ── Response options ───────────────────────────────────────────────────
|
|
363
|
+
['INVALID_RESPONSE_OPTIONS', 'Response options must be a plain object, received: {received}.'],
|
|
364
|
+
['INVALID_ETAG_TYPE', 'etag must be a boolean, received: {received}.'],
|
|
365
|
+
['INVALID_ETAG', 'etag must be a boolean, received: {received}.'],
|
|
366
|
+
['INVALID_DEFAULT_CHARSET_TYPE', 'defaultCharset must be a string, received: {received}.'],
|
|
367
|
+
['INVALID_DEFAULT_CHARSET_VALUE', 'defaultCharset must be a non-empty string.'],
|
|
368
|
+
['INVALID_DEFAULT_CHARSET', 'defaultCharset must be a non-empty string, received: {received}.'],
|
|
369
|
+
|
|
370
|
+
// ── Listen options ─────────────────────────────────────────────────────
|
|
371
|
+
['INVALID_LISTEN_OPTIONS', 'Listen options must be a plain object, received: {received}.'],
|
|
372
|
+
['MISSING_PORT', 'Listen options must declare a port.'],
|
|
373
|
+
['INVALID_PORT', 'port must be a valid integer between 0 and 65535.'],
|
|
374
|
+
['INVALID_PORT_TYPE', 'port must be a number, received: {received}.'],
|
|
375
|
+
['INVALID_PORT_RANGE', 'port must be an integer between 0 and 65535, received: {port}.'],
|
|
376
|
+
['INVALID_HOST', 'host must be a non-empty string, received: {received}.'],
|
|
377
|
+
['INVALID_HOST_TYPE', 'host must be a string, received: {received}.'],
|
|
378
|
+
['INVALID_HOST_VALUE', 'host must be a non-empty string.'],
|
|
379
|
+
['INVALID_HOST_RANGE', 'host must be a non-empty string.'],
|
|
380
|
+
['INVALID_BACKLOG', 'backlog must be a positive integer, received: {received}.'],
|
|
381
|
+
['INVALID_BACKLOG_TYPE', 'backlog must be a number, received: {received}.'],
|
|
382
|
+
['INVALID_BACKLOG_RANGE', 'backlog must be a positive integer, received: {backlog}.'],
|
|
383
|
+
|
|
384
|
+
// ── Static options ─────────────────────────────────────────────────────
|
|
385
|
+
['INVALID_STATIC_OPTIONS', 'Static options must be a plain object, received: {received}.'],
|
|
386
|
+
['MISSING_STATIC_ROOT', 'Static options must declare a root.'],
|
|
387
|
+
['INVALID_STATIC_ROOT_TYPE', 'root must be a string, received: {received}.'],
|
|
388
|
+
['INVALID_STATIC_ROOT_VALUE', 'root must be a non-empty string.'],
|
|
389
|
+
['INVALID_STATIC_INDEX_TYPE', 'index must be an array, received: {received}.'],
|
|
390
|
+
['INVALID_STATIC_INDEX_ITEM', 'index items must be non-empty strings.'],
|
|
391
|
+
['INVALID_STATIC_MAX_AGE_TYPE', 'maxAge must be a number, received: {received}.'],
|
|
392
|
+
['INVALID_STATIC_MAX_AGE_VALUE', 'maxAge must be a non-negative integer, received: {maxAge}.'],
|
|
393
|
+
['INVALID_STATIC_ETAG_TYPE', 'etag must be a boolean, received: {received}.'],
|
|
394
|
+
['INVALID_STATIC_LAST_MODIFIED_TYPE', 'lastModified must be a boolean, received: {received}.'],
|
|
395
|
+
['INVALID_STATIC_FALLTHROUGH_TYPE', 'fallthrough must be a boolean, received: {received}.'],
|
|
396
|
+
['INVALID_STATIC_EXTENSIONS_TYPE', 'extensions must be an array, received: {received}.'],
|
|
397
|
+
['INVALID_STATIC_EXTENSIONS_ITEM', 'extensions items must be non-empty strings.'],
|
|
398
|
+
['INVALID_STATIC_DOTFILES_TYPE', 'dotfiles must be a boolean, received: {received}.'],
|
|
399
|
+
|
|
400
|
+
// ── Configuration ──────────────────────────────────────────────────────
|
|
401
|
+
['SERVER_CONFIGURATION_INVALID', 'Server configuration is invalid: {reason}.'],
|
|
402
|
+
['SERVER_ADAPTER_INIT_FAILED', 'Server adapter failed to initialize: {reason}.'],
|
|
403
|
+
|
|
404
|
+
// ── CORS options ───────────────────────────────────────────────────────
|
|
405
|
+
['INVALID_CORS_OPTIONS', 'CORS options must be a plain object, received: {received}.'],
|
|
406
|
+
[
|
|
407
|
+
'INVALID_CORS_ORIGIN_TYPE',
|
|
408
|
+
'origin must be `true`, a string, or an array of strings, received: {received}.',
|
|
409
|
+
],
|
|
410
|
+
['INVALID_CORS_ORIGIN_ITEM', 'origin array items must be non-empty strings.'],
|
|
411
|
+
['INVALID_CORS_METHODS_TYPE', 'methods must be an array, received: {received}.'],
|
|
412
|
+
['INVALID_CORS_METHODS_ITEM', 'methods items must be non-empty strings.'],
|
|
413
|
+
['INVALID_CORS_ALLOWED_HEADERS_TYPE', 'allowedHeaders must be an array, received: {received}.'],
|
|
414
|
+
['INVALID_CORS_ALLOWED_HEADERS_ITEM', 'allowedHeaders items must be non-empty strings.'],
|
|
415
|
+
['INVALID_CORS_EXPOSED_HEADERS_TYPE', 'exposedHeaders must be an array, received: {received}.'],
|
|
416
|
+
['INVALID_CORS_EXPOSED_HEADERS_ITEM', 'exposedHeaders items must be non-empty strings.'],
|
|
417
|
+
['INVALID_CORS_CREDENTIALS_TYPE', 'credentials must be a boolean, received: {received}.'],
|
|
418
|
+
['INVALID_CORS_MAX_AGE_TYPE', 'maxAge must be a number, received: {received}.'],
|
|
419
|
+
['INVALID_CORS_MAX_AGE_RANGE', 'maxAge must be a non-negative integer, received: {maxAge}.'],
|
|
420
|
+
[
|
|
421
|
+
'INVALID_CORS_PREFLIGHT_CONTINUE_TYPE',
|
|
422
|
+
'preflightContinue must be a boolean, received: {received}.',
|
|
423
|
+
],
|
|
424
|
+
[
|
|
425
|
+
'INVALID_CORS_OPTIONS_SUCCESS_STATUS_TYPE',
|
|
426
|
+
'optionsSuccessStatus must be a number, received: {received}.',
|
|
427
|
+
],
|
|
428
|
+
[
|
|
429
|
+
'INVALID_CORS_OPTIONS_SUCCESS_STATUS_RANGE',
|
|
430
|
+
'optionsSuccessStatus must be an integer between 100 and 599, received: {optionsSuccessStatus}.',
|
|
431
|
+
],
|
|
432
|
+
|
|
433
|
+
// ── Security headers options ───────────────────────────────────────────
|
|
434
|
+
[
|
|
435
|
+
'INVALID_SECURITY_HEADERS_OPTIONS',
|
|
436
|
+
'Security headers options must be a plain object, received: {received}.',
|
|
437
|
+
],
|
|
438
|
+
[
|
|
439
|
+
'INVALID_SECURITY_HEADERS_OPTION_TYPE',
|
|
440
|
+
'Security header option `{key}` must be a string or `false`, received: {received}.',
|
|
441
|
+
],
|
|
442
|
+
|
|
443
|
+
// ── Rate limit options ─────────────────────────────────────────────────
|
|
444
|
+
[
|
|
445
|
+
'INVALID_RATE_LIMIT_OPTIONS',
|
|
446
|
+
'Rate limit options must be a plain object, received: {received}.',
|
|
447
|
+
],
|
|
448
|
+
['INVALID_RATE_LIMIT_WINDOW_MS_TYPE', 'windowMs must be a number, received: {received}.'],
|
|
449
|
+
[
|
|
450
|
+
'INVALID_RATE_LIMIT_WINDOW_MS_RANGE',
|
|
451
|
+
'windowMs must be a positive integer, received: {windowMs}.',
|
|
452
|
+
],
|
|
453
|
+
['INVALID_RATE_LIMIT_MAX_TYPE', 'max must be a number, received: {received}.'],
|
|
454
|
+
['INVALID_RATE_LIMIT_MAX_RANGE', 'max must be a positive integer, received: {max}.'],
|
|
455
|
+
['INVALID_RATE_LIMIT_STATUS_CODE_TYPE', 'statusCode must be a number, received: {received}.'],
|
|
456
|
+
[
|
|
457
|
+
'INVALID_RATE_LIMIT_STATUS_CODE_RANGE',
|
|
458
|
+
'statusCode must be an integer between 400 and 599, received: {statusCode}.',
|
|
459
|
+
],
|
|
460
|
+
['INVALID_RATE_LIMIT_MESSAGE_TYPE', 'message must be a plain object, received: {received}.'],
|
|
461
|
+
[
|
|
462
|
+
'INVALID_RATE_LIMIT_STANDARD_HEADERS_TYPE',
|
|
463
|
+
'standardHeaders must be a boolean, received: {received}.',
|
|
464
|
+
],
|
|
465
|
+
[
|
|
466
|
+
'INVALID_RATE_LIMIT_LEGACY_HEADERS_TYPE',
|
|
467
|
+
'legacyHeaders must be a boolean, received: {received}.',
|
|
468
|
+
],
|
|
469
|
+
|
|
470
|
+
// ── Cookie parser options ──────────────────────────────────────────────
|
|
471
|
+
[
|
|
472
|
+
'INVALID_COOKIE_PARSER_OPTIONS',
|
|
473
|
+
'Cookie parser options must be a plain object, received: {received}.',
|
|
474
|
+
],
|
|
475
|
+
['INVALID_COOKIE_PARSER_DECODE_TYPE', 'decode must be a boolean, received: {received}.'],
|
|
476
|
+
|
|
477
|
+
// ── Cookie session options ─────────────────────────────────────────────
|
|
478
|
+
[
|
|
479
|
+
'INVALID_COOKIE_SESSION_OPTIONS',
|
|
480
|
+
'Cookie session options must be a plain object, received: {received}.',
|
|
481
|
+
],
|
|
482
|
+
[
|
|
483
|
+
'COOKIE_SESSION_REQUIRES_COOKIE_PARSER',
|
|
484
|
+
'Cookie session requires a cookie parser to be configured.',
|
|
485
|
+
],
|
|
486
|
+
['MISSING_COOKIE_SESSION_KEYS', 'Cookie session keys must be a non-empty array of strings.'],
|
|
487
|
+
['INVALID_COOKIE_SESSION_NAME_TYPE', 'name must be a string, received: {received}.'],
|
|
488
|
+
['INVALID_COOKIE_SESSION_NAME_VALUE', 'name must be a non-empty string.'],
|
|
489
|
+
['INVALID_COOKIE_SESSION_KEYS_TYPE', 'keys must be an array, received: {received}.'],
|
|
490
|
+
['INVALID_COOKIE_SESSION_KEYS_ITEM', 'keys items must be non-empty strings.'],
|
|
491
|
+
['INVALID_COOKIE_SESSION_MAX_AGE_TYPE', 'maxAge must be a number, received: {received}.'],
|
|
492
|
+
[
|
|
493
|
+
'INVALID_COOKIE_SESSION_MAX_AGE_RANGE',
|
|
494
|
+
'maxAge must be a positive integer, received: {maxAge}.',
|
|
495
|
+
],
|
|
496
|
+
['INVALID_COOKIE_SESSION_PATH_TYPE', 'path must be a string, received: {received}.'],
|
|
497
|
+
['INVALID_COOKIE_SESSION_PATH_VALUE', 'path must be a non-empty string.'],
|
|
498
|
+
['INVALID_COOKIE_SESSION_DOMAIN_TYPE', 'domain must be a string, received: {received}.'],
|
|
499
|
+
['INVALID_COOKIE_SESSION_DOMAIN_VALUE', 'domain must be a non-empty string.'],
|
|
500
|
+
['INVALID_COOKIE_SESSION_SECURE_TYPE', 'secure must be a boolean, received: {received}.'],
|
|
501
|
+
['INVALID_COOKIE_SESSION_HTTP_ONLY_TYPE', 'httpOnly must be a boolean, received: {received}.'],
|
|
502
|
+
[
|
|
503
|
+
'INVALID_COOKIE_SESSION_SAME_SITE_VALUE',
|
|
504
|
+
"sameSite must be 'Strict', 'Lax', or 'None', received: {received}.",
|
|
505
|
+
],
|
|
506
|
+
['INVALID_COOKIE_SESSION_OVERWRITE_TYPE', 'overwrite must be a boolean, received: {received}.'],
|
|
507
|
+
['COOKIE_SESSION_NONE_REQUIRES_SECURE', "sameSite 'None' requires secure to be true."],
|
|
508
|
+
|
|
509
|
+
// ── CSRF options ───────────────────────────────────────────────────────
|
|
510
|
+
['INVALID_CSRF_OPTIONS', 'CSRF options must be a plain object, received: {received}.'],
|
|
511
|
+
['INVALID_CSRF_COOKIE_NAME_TYPE', 'cookieName must be a string, received: {received}.'],
|
|
512
|
+
['INVALID_CSRF_COOKIE_NAME_VALUE', 'cookieName must be a non-empty string.'],
|
|
513
|
+
['INVALID_CSRF_HEADER_NAME_TYPE', 'headerName must be a string, received: {received}.'],
|
|
514
|
+
['INVALID_CSRF_HEADER_NAME_VALUE', 'headerName must be a non-empty string.'],
|
|
515
|
+
['INVALID_CSRF_SAFE_METHODS_TYPE', 'safeMethods must be an array, received: {received}.'],
|
|
516
|
+
['INVALID_CSRF_SAFE_METHODS_ITEM', 'safeMethods items must be non-empty strings.'],
|
|
517
|
+
['INVALID_CSRF_TOKEN_BYTES_TYPE', 'tokenBytes must be a number, received: {received}.'],
|
|
518
|
+
[
|
|
519
|
+
'INVALID_CSRF_TOKEN_BYTES_RANGE',
|
|
520
|
+
'tokenBytes must be a positive integer, received: {tokenBytes}.',
|
|
521
|
+
],
|
|
522
|
+
['INVALID_CSRF_PATH_TYPE', 'path must be a string, received: {received}.'],
|
|
523
|
+
['INVALID_CSRF_PATH_VALUE', 'path must be a non-empty string.'],
|
|
524
|
+
['INVALID_CSRF_DOMAIN_TYPE', 'domain must be a string, received: {received}.'],
|
|
525
|
+
['INVALID_CSRF_DOMAIN_VALUE', 'domain must be a non-empty string.'],
|
|
526
|
+
['INVALID_CSRF_SECURE_TYPE', 'secure must be a boolean, received: {received}.'],
|
|
527
|
+
[
|
|
528
|
+
'INVALID_CSRF_SAME_SITE_VALUE',
|
|
529
|
+
"sameSite must be 'Strict', 'Lax', or 'None', received: {received}.",
|
|
530
|
+
],
|
|
531
|
+
['CSRF_NONE_REQUIRES_SECURE', "sameSite 'None' requires secure to be true."],
|
|
532
|
+
|
|
533
|
+
// ── Compress options ───────────────────────────────────────────────────
|
|
534
|
+
['INVALID_COMPRESS_OPTIONS', 'Compress options must be a plain object, received: {received}.'],
|
|
535
|
+
['INVALID_COMPRESS_THRESHOLD_TYPE', 'threshold must be a number, received: {received}.'],
|
|
536
|
+
[
|
|
537
|
+
'INVALID_COMPRESS_THRESHOLD_RANGE',
|
|
538
|
+
'threshold must be a non-negative integer, received: {threshold}.',
|
|
539
|
+
],
|
|
540
|
+
['INVALID_COMPRESS_LEVEL_TYPE', 'level must be a number, received: {received}.'],
|
|
541
|
+
[
|
|
542
|
+
'INVALID_COMPRESS_LEVEL_RANGE',
|
|
543
|
+
'level must be an integer between -1 and 11, received: {level}.',
|
|
544
|
+
],
|
|
545
|
+
['INVALID_COMPRESS_TYPES_TYPE', 'types must be an array, received: {received}.'],
|
|
546
|
+
['INVALID_COMPRESS_TYPES_ITEM', 'types items must be non-empty strings.'],
|
|
547
|
+
]);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
551
|
+
export default ServerConfigurationError;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Defines the internal error type used for `Server`
|
|
3
|
+
* lifecycle failures.
|
|
4
|
+
*
|
|
5
|
+
* @description This class supports predefined error identifiers as well
|
|
6
|
+
* as custom error messages. When a known error identifier is provided,
|
|
7
|
+
* it is automatically resolved to its corresponding message.
|
|
8
|
+
*
|
|
9
|
+
* @private
|
|
10
|
+
* @module ServerError
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// ━━ IMPORT MODULES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
14
|
+
// » IMPORT LOCAL MODULES
|
|
15
|
+
import BaseError from '../BaseError/index.mjs';
|
|
16
|
+
|
|
17
|
+
// ━━ TYPE DEFINITIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
18
|
+
/**
|
|
19
|
+
* @template {string} T
|
|
20
|
+
* @typedef {T | (string & {})} LiteralUnion
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {LiteralUnion<
|
|
25
|
+
* 'SERVER_LISTEN_FAILED' |
|
|
26
|
+
* 'SERVER_CLOSE_FAILED' |
|
|
27
|
+
* 'SERVER_ADAPTER_INIT_FAILED' |
|
|
28
|
+
* 'SERVER_ALREADY_STARTING' |
|
|
29
|
+
* 'SERVER_ALREADY_LISTENING' |
|
|
30
|
+
* 'SERVER_ALREADY_STOPPING' |
|
|
31
|
+
* 'SERVER_ALREADY_CLOSED' |
|
|
32
|
+
* 'SERVER_NOT_LISTENING' |
|
|
33
|
+
* 'SERVER_STOPPING' |
|
|
34
|
+
* 'SERVER_CLOSED' |
|
|
35
|
+
* 'SERVER_ERROR' |
|
|
36
|
+
* 'SERVER_INVALID_STATE_TRANSITION' |
|
|
37
|
+
* 'SERVER_EXCHANGE_INIT_FAILED'
|
|
38
|
+
* >} ServerErrorIdentifier
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Options for creating an error instance.
|
|
43
|
+
*
|
|
44
|
+
* @typedef {object} ServerErrorOptions
|
|
45
|
+
* @property {Record<string, unknown>} [values] - Values for template placeholders in the error message.
|
|
46
|
+
* @property {unknown} [details] - Additional contextual information about the error.
|
|
47
|
+
* @property {Error} [cause] - The original error that caused this error (for error chaining).
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
// ━━ MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
51
|
+
/**
|
|
52
|
+
* Error thrown when a `HttpServer` operation cannot be completed.
|
|
53
|
+
*
|
|
54
|
+
* This error type covers failures related to `HttpServer` lifecycle
|
|
55
|
+
* and `HttpServer` state transitions.
|
|
56
|
+
*
|
|
57
|
+
* @augments BaseError
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
class ServerError extends BaseError {
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new {@link ServerError}.
|
|
63
|
+
* @param {ServerErrorIdentifier} identifier - A predefined error identifier or a custom error message.
|
|
64
|
+
* @param {ServerErrorOptions} [options] - Additional information used to format the message, attach domain details, or preserve the original cause.
|
|
65
|
+
* @example
|
|
66
|
+
* ```js
|
|
67
|
+
* if (server.listening) {
|
|
68
|
+
* throw new ServerError('SERVER_ALREADY_LISTENING');
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* await server.listen();
|
|
72
|
+
* ```
|
|
73
|
+
* @example
|
|
74
|
+
* ```js
|
|
75
|
+
* throw new ServerError('SERVER_INVALID_STATE_TRANSITION', {
|
|
76
|
+
* values: {
|
|
77
|
+
* from: 'closed',
|
|
78
|
+
* to: 'listening',
|
|
79
|
+
* },
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
constructor(identifier, options = {}) {
|
|
85
|
+
super(identifier, options);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Collection of predefined server error messages.
|
|
90
|
+
*
|
|
91
|
+
* Available error identifiers.
|
|
92
|
+
*
|
|
93
|
+
* - `SERVER_LISTEN_FAILED`.
|
|
94
|
+
* - `SERVER_CLOSE_FAILED`.
|
|
95
|
+
* - `SERVER_ALREADY_LISTENING`.
|
|
96
|
+
* - `SERVER_ALREADY_CLOSED`.
|
|
97
|
+
* - `SERVER_INVALID_STATE_TRANSITION`.
|
|
98
|
+
*
|
|
99
|
+
* @private
|
|
100
|
+
* @static
|
|
101
|
+
* @type {Map<ServerErrorIdentifier, string>}
|
|
102
|
+
*/
|
|
103
|
+
static MESSAGES = new Map([
|
|
104
|
+
// Lifecycle
|
|
105
|
+
['SERVER_LISTEN_FAILED', 'Failed to start the server.'],
|
|
106
|
+
['SERVER_CLOSE_FAILED', 'Failed to close the server.'],
|
|
107
|
+
['SERVER_ADAPTER_INIT_FAILED', 'Failed to initialize the transport adapter.'],
|
|
108
|
+
|
|
109
|
+
// State guards
|
|
110
|
+
['SERVER_ALREADY_STARTING', 'The server is already starting.'],
|
|
111
|
+
['SERVER_ALREADY_LISTENING', 'The server is already listening.'],
|
|
112
|
+
['SERVER_ALREADY_STOPPING', 'The server is already stopping.'],
|
|
113
|
+
['SERVER_ALREADY_CLOSED', 'The server is already closed.'],
|
|
114
|
+
['SERVER_NOT_LISTENING', 'The server is not listening.'],
|
|
115
|
+
['SERVER_STOPPING', 'The server is stopping.'],
|
|
116
|
+
['SERVER_CLOSED', 'The server is closed.'],
|
|
117
|
+
['SERVER_ERROR', 'The server is in an error state.'],
|
|
118
|
+
|
|
119
|
+
// Transitions
|
|
120
|
+
['SERVER_INVALID_STATE_TRANSITION', 'Cannot transition from "{from}" to "{to}".'],
|
|
121
|
+
|
|
122
|
+
// Exchange
|
|
123
|
+
['SERVER_EXCHANGE_INIT_FAILED', 'Failed to create the exchange for the incoming request.'],
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
// ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
127
|
+
export default ServerError;
|