@adonisjs/http-server 8.0.0-next.5 → 8.0.0-next.6
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/build/{chunk-BFGF3A5X.js → chunk-7ROFCP6L.js} +1095 -548
- package/build/{chunk-ASX56VAK.js → chunk-NQNHMINZ.js} +59 -0
- package/build/factories/http_context.d.ts +2 -1
- package/build/factories/http_server.d.ts +7 -0
- package/build/factories/main.js +31 -5
- package/build/factories/qs_parser_factory.d.ts +3 -2
- package/build/factories/request.d.ts +1 -0
- package/build/factories/response.d.ts +1 -0
- package/build/factories/router.d.ts +1 -0
- package/build/factories/server_factory.d.ts +1 -0
- package/build/factories/url_builder_factory.d.ts +1 -0
- package/build/index.d.ts +3 -1
- package/build/index.js +87 -37
- package/build/src/cookies/client.d.ts +35 -0
- package/build/src/cookies/drivers/encrypted.d.ts +13 -0
- package/build/src/cookies/drivers/plain.d.ts +9 -0
- package/build/src/cookies/drivers/signed.d.ts +13 -0
- package/build/src/cookies/parser.d.ts +18 -0
- package/build/src/cookies/serializer.d.ts +20 -0
- package/build/src/define_config.d.ts +1 -3
- package/build/src/define_middleware.d.ts +1 -1
- package/build/src/exception_handler.d.ts +72 -31
- package/build/src/helpers.d.ts +50 -0
- package/build/src/helpers.js +5 -1
- package/build/src/http_context/local_storage.d.ts +17 -0
- package/build/src/http_context/main.d.ts +8 -0
- package/build/src/qs.d.ts +14 -0
- package/build/src/redirect.d.ts +25 -9
- package/build/src/request.d.ts +109 -10
- package/build/src/response.d.ts +399 -203
- package/build/src/router/brisk.d.ts +13 -0
- package/build/src/router/executor.d.ts +4 -0
- package/build/src/router/factories/use_return_value.d.ts +5 -0
- package/build/src/router/group.d.ts +17 -0
- package/build/src/router/legacy/url_builder.d.ts +7 -0
- package/build/src/router/main.d.ts +72 -1
- package/build/src/router/matchers.d.ts +3 -0
- package/build/src/router/resource.d.ts +33 -0
- package/build/src/router/route.d.ts +8 -0
- package/build/src/router/signed_url_builder.d.ts +4 -8
- package/build/src/router/store.d.ts +9 -0
- package/build/src/router/url_builder.d.ts +4 -9
- package/build/src/server/factories/middleware_handler.d.ts +10 -1
- package/build/src/server/factories/route_finder.d.ts +13 -3
- package/build/src/server/factories/write_response.d.ts +9 -2
- package/build/src/server/main.d.ts +77 -23
- package/build/src/tracing_channels.d.ts +4 -4
- package/build/src/types/middleware.d.ts +33 -8
- package/build/src/types/qs.d.ts +5 -0
- package/build/src/types/request.d.ts +1 -1
- package/build/src/types/response.d.ts +14 -6
- package/build/src/types/route.d.ts +40 -17
- package/build/src/types/server.d.ts +26 -11
- package/build/src/types/tracing_channels.d.ts +21 -3
- package/build/src/types/url_builder.d.ts +24 -11
- package/package.json +15 -13
|
@@ -15,6 +15,63 @@ function parseRoute(pattern, matchers) {
|
|
|
15
15
|
const tokens = matchit.parse(pattern, matchers);
|
|
16
16
|
return tokens;
|
|
17
17
|
}
|
|
18
|
+
function createURL(pattern, tokens, searchParamsStringifier, params, options) {
|
|
19
|
+
const uriSegments = [];
|
|
20
|
+
const paramsArray = Array.isArray(params) ? params : null;
|
|
21
|
+
const paramsObject = !Array.isArray(params) ? params ?? {} : {};
|
|
22
|
+
let paramsIndex = 0;
|
|
23
|
+
for (const token of tokens) {
|
|
24
|
+
if (token.type === 0) {
|
|
25
|
+
uriSegments.push(token.val === "/" ? "" : `${token.val}${token.end}`);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (token.type === 2) {
|
|
29
|
+
const values = paramsArray ? paramsArray.slice(paramsIndex) : paramsObject["*"];
|
|
30
|
+
if (!Array.isArray(values) || !values.length) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Cannot make URL for "${pattern}". Invalid value provided for the wildcard param`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
uriSegments.push(`${values.join("/")}${token.end}`);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
const paramName = token.val;
|
|
39
|
+
const value = paramsArray ? paramsArray[paramsIndex] : paramsObject[paramName];
|
|
40
|
+
const isDefined = value !== void 0 && value !== null;
|
|
41
|
+
if (token.type === 1 && !isDefined) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Cannot make URL for "${pattern}". Missing value for the "${paramName}" param`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (isDefined) {
|
|
47
|
+
uriSegments.push(`${value}${token.end}`);
|
|
48
|
+
}
|
|
49
|
+
paramsIndex++;
|
|
50
|
+
}
|
|
51
|
+
let URI = `/${uriSegments.join("/")}`;
|
|
52
|
+
if (options?.prefixUrl) {
|
|
53
|
+
URI = `${options?.prefixUrl.replace(/\/$/, "")}${URI}`;
|
|
54
|
+
}
|
|
55
|
+
if (options?.qs) {
|
|
56
|
+
const queryString = searchParamsStringifier(options?.qs);
|
|
57
|
+
URI = queryString ? `${URI}?${queryString}` : URI;
|
|
58
|
+
}
|
|
59
|
+
return URI;
|
|
60
|
+
}
|
|
61
|
+
function createSignedURL(identifier, tokens, searchParamsStringifier, encryption, params, options) {
|
|
62
|
+
const signature = encryption.verifier.sign(
|
|
63
|
+
createURL(identifier, tokens, searchParamsStringifier, params, {
|
|
64
|
+
...options,
|
|
65
|
+
prefixUrl: void 0
|
|
66
|
+
}),
|
|
67
|
+
options?.expiresIn,
|
|
68
|
+
options?.purpose
|
|
69
|
+
);
|
|
70
|
+
return createURL(identifier, tokens, searchParamsStringifier, params, {
|
|
71
|
+
...options,
|
|
72
|
+
qs: { ...options?.qs, signature }
|
|
73
|
+
});
|
|
74
|
+
}
|
|
18
75
|
function matchRoute(url, patterns) {
|
|
19
76
|
const tokensBucket = patterns.map((pattern) => parseRoute(pattern));
|
|
20
77
|
const match = matchit.match(url, tokensBucket);
|
|
@@ -67,6 +124,8 @@ async function routeInfo(route) {
|
|
|
67
124
|
export {
|
|
68
125
|
__export,
|
|
69
126
|
parseRoute,
|
|
127
|
+
createURL,
|
|
128
|
+
createSignedURL,
|
|
70
129
|
matchRoute,
|
|
71
130
|
serializeCookie,
|
|
72
131
|
middlewareInfo,
|
|
@@ -15,10 +15,11 @@ export declare class HttpContextFactory {
|
|
|
15
15
|
#private;
|
|
16
16
|
/**
|
|
17
17
|
* Merge factory params
|
|
18
|
+
* @param params - Partial factory parameters to merge
|
|
18
19
|
*/
|
|
19
20
|
merge(params: Partial<FactoryParameters>): this;
|
|
20
21
|
/**
|
|
21
|
-
* Create
|
|
22
|
+
* Create HTTP context instance
|
|
22
23
|
*/
|
|
23
24
|
create(): HttpContext;
|
|
24
25
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { type IncomingMessage, type Server, type ServerResponse } from 'node:http';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP server factory for testing purposes
|
|
4
|
+
*/
|
|
2
5
|
export declare const httpServer: {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new HTTP server for testing with automatic cleanup
|
|
8
|
+
* @param handler - The request handler function
|
|
9
|
+
*/
|
|
3
10
|
create(handler: (req: IncomingMessage, res: ServerResponse) => any | Promise<any>): Promise<{
|
|
4
11
|
server: Server;
|
|
5
12
|
url: string;
|
package/build/factories/main.js
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
Router,
|
|
7
7
|
Server,
|
|
8
8
|
defineConfig
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-7ROFCP6L.js";
|
|
10
|
+
import "../chunk-NQNHMINZ.js";
|
|
11
11
|
|
|
12
12
|
// factories/router.ts
|
|
13
13
|
import { AppFactory } from "@adonisjs/application/factories";
|
|
@@ -15,6 +15,9 @@ import { EncryptionFactory } from "@adonisjs/encryption/factories";
|
|
|
15
15
|
|
|
16
16
|
// factories/qs_parser_factory.ts
|
|
17
17
|
var QsParserFactory = class {
|
|
18
|
+
/**
|
|
19
|
+
* Default configuration options for the QS parser
|
|
20
|
+
*/
|
|
18
21
|
#options = {
|
|
19
22
|
parse: {
|
|
20
23
|
depth: 5,
|
|
@@ -31,7 +34,8 @@ var QsParserFactory = class {
|
|
|
31
34
|
}
|
|
32
35
|
};
|
|
33
36
|
/**
|
|
34
|
-
* Merge
|
|
37
|
+
* Merge QS parser factory options
|
|
38
|
+
* @param options - Partial options to merge with existing configuration
|
|
35
39
|
*/
|
|
36
40
|
merge(options) {
|
|
37
41
|
Object.assign(this.#options.parse, options.parse);
|
|
@@ -39,7 +43,7 @@ var QsParserFactory = class {
|
|
|
39
43
|
return this;
|
|
40
44
|
}
|
|
41
45
|
/**
|
|
42
|
-
* Create instance of the
|
|
46
|
+
* Create instance of the QS parser class
|
|
43
47
|
*/
|
|
44
48
|
create() {
|
|
45
49
|
return new Qs(this.#options);
|
|
@@ -48,6 +52,9 @@ var QsParserFactory = class {
|
|
|
48
52
|
|
|
49
53
|
// factories/router.ts
|
|
50
54
|
var RouterFactory = class {
|
|
55
|
+
/**
|
|
56
|
+
* Factory parameters for creating router instances
|
|
57
|
+
*/
|
|
51
58
|
#parameters = {};
|
|
52
59
|
/**
|
|
53
60
|
* Returns an instance of the application class
|
|
@@ -64,6 +71,7 @@ var RouterFactory = class {
|
|
|
64
71
|
}
|
|
65
72
|
/**
|
|
66
73
|
* Merge factory params
|
|
74
|
+
* @param params - Partial factory parameters to merge
|
|
67
75
|
*/
|
|
68
76
|
merge(params) {
|
|
69
77
|
Object.assign(this.#parameters, params);
|
|
@@ -84,6 +92,9 @@ import { randomUUID } from "crypto";
|
|
|
84
92
|
import { IncomingMessage, ServerResponse } from "http";
|
|
85
93
|
import { EncryptionFactory as EncryptionFactory2 } from "@adonisjs/encryption/factories";
|
|
86
94
|
var RequestFactory = class {
|
|
95
|
+
/**
|
|
96
|
+
* Factory parameters for creating request instances
|
|
97
|
+
*/
|
|
87
98
|
#parameters = {};
|
|
88
99
|
/**
|
|
89
100
|
* Returns the config for the request class
|
|
@@ -115,6 +126,7 @@ var RequestFactory = class {
|
|
|
115
126
|
}
|
|
116
127
|
/**
|
|
117
128
|
* Returns the HTTP res object
|
|
129
|
+
* @param req - The incoming message request object
|
|
118
130
|
*/
|
|
119
131
|
#createResponse(req) {
|
|
120
132
|
return this.#parameters.res || new ServerResponse(req);
|
|
@@ -128,6 +140,7 @@ var RequestFactory = class {
|
|
|
128
140
|
}
|
|
129
141
|
/**
|
|
130
142
|
* Merge factory params
|
|
143
|
+
* @param params - Partial factory parameters to merge
|
|
131
144
|
*/
|
|
132
145
|
merge(params) {
|
|
133
146
|
Object.assign(this.#parameters, params);
|
|
@@ -153,6 +166,9 @@ import { Socket as Socket2 } from "net";
|
|
|
153
166
|
import { IncomingMessage as IncomingMessage2, ServerResponse as ServerResponse2 } from "http";
|
|
154
167
|
import { EncryptionFactory as EncryptionFactory3 } from "@adonisjs/encryption/factories";
|
|
155
168
|
var ResponseFactory = class {
|
|
169
|
+
/**
|
|
170
|
+
* Factory parameters for creating response instances
|
|
171
|
+
*/
|
|
156
172
|
#parameters = {};
|
|
157
173
|
/**
|
|
158
174
|
* Returns the config for the request class
|
|
@@ -185,6 +201,7 @@ var ResponseFactory = class {
|
|
|
185
201
|
}
|
|
186
202
|
/**
|
|
187
203
|
* Returns the HTTP res object
|
|
204
|
+
* @param req - The incoming message request object
|
|
188
205
|
*/
|
|
189
206
|
#createResponse(req) {
|
|
190
207
|
return this.#parameters.res || new ServerResponse2(req);
|
|
@@ -198,6 +215,7 @@ var ResponseFactory = class {
|
|
|
198
215
|
}
|
|
199
216
|
/**
|
|
200
217
|
* Merge factory params
|
|
218
|
+
* @param params - Partial factory parameters to merge
|
|
201
219
|
*/
|
|
202
220
|
merge(params) {
|
|
203
221
|
Object.assign(this.#parameters, params);
|
|
@@ -225,6 +243,9 @@ import { Emitter } from "@adonisjs/events";
|
|
|
225
243
|
import { AppFactory as AppFactory2 } from "@adonisjs/application/factories";
|
|
226
244
|
import { EncryptionFactory as EncryptionFactory4 } from "@adonisjs/encryption/factories";
|
|
227
245
|
var ServerFactory = class {
|
|
246
|
+
/**
|
|
247
|
+
* Factory parameters for creating server instances
|
|
248
|
+
*/
|
|
228
249
|
#parameters = {};
|
|
229
250
|
/**
|
|
230
251
|
* Returns the emitter instance
|
|
@@ -259,6 +280,7 @@ var ServerFactory = class {
|
|
|
259
280
|
}
|
|
260
281
|
/**
|
|
261
282
|
* Merge factory params
|
|
283
|
+
* @param params - Partial factory parameters to merge
|
|
262
284
|
*/
|
|
263
285
|
merge(params) {
|
|
264
286
|
Object.assign(this.#parameters, params);
|
|
@@ -282,6 +304,9 @@ var ServerFactory = class {
|
|
|
282
304
|
import { Container } from "@adonisjs/fold";
|
|
283
305
|
import { LoggerFactory } from "@adonisjs/logger/factories";
|
|
284
306
|
var HttpContextFactory = class {
|
|
307
|
+
/**
|
|
308
|
+
* Factory parameters for creating HTTP context instances
|
|
309
|
+
*/
|
|
285
310
|
#parameters = {};
|
|
286
311
|
/**
|
|
287
312
|
* Returns the request class instance
|
|
@@ -303,13 +328,14 @@ var HttpContextFactory = class {
|
|
|
303
328
|
}
|
|
304
329
|
/**
|
|
305
330
|
* Merge factory params
|
|
331
|
+
* @param params - Partial factory parameters to merge
|
|
306
332
|
*/
|
|
307
333
|
merge(params) {
|
|
308
334
|
Object.assign(this.#parameters, params);
|
|
309
335
|
return this;
|
|
310
336
|
}
|
|
311
337
|
/**
|
|
312
|
-
* Create
|
|
338
|
+
* Create HTTP context instance
|
|
313
339
|
*/
|
|
314
340
|
create() {
|
|
315
341
|
return new HttpContext(
|
|
@@ -7,14 +7,15 @@ import type { QSParserConfig } from '../src/types/qs.ts';
|
|
|
7
7
|
export declare class QsParserFactory {
|
|
8
8
|
#private;
|
|
9
9
|
/**
|
|
10
|
-
* Merge
|
|
10
|
+
* Merge QS parser factory options
|
|
11
|
+
* @param options - Partial options to merge with existing configuration
|
|
11
12
|
*/
|
|
12
13
|
merge(options: Partial<{
|
|
13
14
|
parse: Partial<QSParserConfig['parse']>;
|
|
14
15
|
stringify: Partial<QSParserConfig['stringify']>;
|
|
15
16
|
}>): this;
|
|
16
17
|
/**
|
|
17
|
-
* Create instance of the
|
|
18
|
+
* Create instance of the QS parser class
|
|
18
19
|
*/
|
|
19
20
|
create(): Qs;
|
|
20
21
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -9,8 +9,10 @@ export { BriskRoute } from './src/router/brisk.ts';
|
|
|
9
9
|
export { RouteGroup } from './src/router/group.ts';
|
|
10
10
|
export { defineConfig } from './src/define_config.ts';
|
|
11
11
|
export { CookieClient } from './src/cookies/client.ts';
|
|
12
|
+
export { CookieParser } from './src/cookies/parser.ts';
|
|
12
13
|
export { HttpContext } from './src/http_context/main.ts';
|
|
13
14
|
export { RouteResource } from './src/router/resource.ts';
|
|
14
15
|
export { ResponseStatus } from './src/response_status.ts';
|
|
15
|
-
export { ExceptionHandler } from './src/exception_handler.ts';
|
|
16
16
|
export * as tracingChannels from './src/tracing_channels.ts';
|
|
17
|
+
export { ExceptionHandler } from './src/exception_handler.ts';
|
|
18
|
+
export { CookieSerializer } from './src/cookies/serializer.ts';
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BriskRoute,
|
|
3
3
|
CookieClient,
|
|
4
|
+
CookieParser,
|
|
5
|
+
CookieSerializer,
|
|
4
6
|
E_CANNOT_LOOKUP_ROUTE,
|
|
5
7
|
E_HTTP_EXCEPTION,
|
|
6
8
|
E_HTTP_REQUEST_ABORTED,
|
|
@@ -20,39 +22,43 @@ import {
|
|
|
20
22
|
errors_exports,
|
|
21
23
|
parseRange,
|
|
22
24
|
tracing_channels_exports
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import "./chunk-
|
|
25
|
+
} from "./chunk-7ROFCP6L.js";
|
|
26
|
+
import "./chunk-NQNHMINZ.js";
|
|
25
27
|
|
|
26
28
|
// src/exception_handler.ts
|
|
27
29
|
import is from "@sindresorhus/is";
|
|
28
30
|
import Macroable from "@poppinss/macroable";
|
|
29
31
|
var ExceptionHandler = class extends Macroable {
|
|
30
32
|
/**
|
|
31
|
-
*
|
|
33
|
+
* Cached expanded status pages mapping individual status codes to their renderers
|
|
34
|
+
* Computed from the statusPages property when first accessed
|
|
32
35
|
*/
|
|
33
36
|
#expandedStatusPages;
|
|
34
37
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
38
|
+
* Controls whether to include debug information in error responses
|
|
39
|
+
* When enabled, errors include complete stack traces and detailed debugging info
|
|
40
|
+
* Defaults to true in non-production environments
|
|
37
41
|
*/
|
|
38
42
|
debug = process.env.NODE_ENV !== "production";
|
|
39
43
|
/**
|
|
40
|
-
*
|
|
41
|
-
* errors with matching status codes
|
|
42
|
-
*
|
|
44
|
+
* Controls whether to render custom status pages for unhandled errors
|
|
45
|
+
* When enabled, errors with matching status codes use configured status page renderers
|
|
46
|
+
* Defaults to true in production environments
|
|
43
47
|
*/
|
|
44
48
|
renderStatusPages = process.env.NODE_ENV === "production";
|
|
45
49
|
/**
|
|
46
|
-
*
|
|
50
|
+
* Mapping of HTTP status code ranges to their corresponding page renderers
|
|
51
|
+
* Supports ranges like '400-499' or individual codes like '404'
|
|
47
52
|
*/
|
|
48
53
|
statusPages = {};
|
|
49
54
|
/**
|
|
50
|
-
*
|
|
55
|
+
* Controls whether errors should be reported to logging systems
|
|
56
|
+
* When disabled, errors are handled but not logged or reported
|
|
51
57
|
*/
|
|
52
58
|
reportErrors = true;
|
|
53
59
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
60
|
+
* Array of exception class constructors to exclude from error reporting
|
|
61
|
+
* These exceptions are handled but not logged or reported to external systems
|
|
56
62
|
*/
|
|
57
63
|
ignoreExceptions = [
|
|
58
64
|
E_HTTP_EXCEPTION,
|
|
@@ -61,17 +67,19 @@ var ExceptionHandler = class extends Macroable {
|
|
|
61
67
|
E_HTTP_REQUEST_ABORTED
|
|
62
68
|
];
|
|
63
69
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
70
|
+
* Array of HTTP status codes to exclude from error reporting
|
|
71
|
+
* Errors with these status codes are handled but not logged
|
|
66
72
|
*/
|
|
67
73
|
ignoreStatuses = [400, 422, 401];
|
|
68
74
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
75
|
+
* Array of custom error codes to exclude from error reporting
|
|
76
|
+
* Errors with these codes are handled but not logged
|
|
71
77
|
*/
|
|
72
78
|
ignoreCodes = [];
|
|
73
79
|
/**
|
|
74
|
-
* Expands status
|
|
80
|
+
* Expands status page ranges into individual status code mappings
|
|
81
|
+
* Creates a cached lookup table for faster status page resolution
|
|
82
|
+
* @returns Mapping of status codes to renderers
|
|
75
83
|
*/
|
|
76
84
|
#expandStatusPages() {
|
|
77
85
|
if (!this.#expandedStatusPages) {
|
|
@@ -87,8 +95,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
87
95
|
return this.#expandedStatusPages;
|
|
88
96
|
}
|
|
89
97
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
98
|
+
* Normalizes any thrown value into a standardized HttpError object
|
|
99
|
+
* Ensures the error has required properties like message and status
|
|
100
|
+
* @param error - Any thrown value (Error, string, object, etc.)
|
|
101
|
+
* @returns {HttpError} Normalized error object with status and message
|
|
92
102
|
*/
|
|
93
103
|
#toHttpError(error) {
|
|
94
104
|
const httpError = is.object(error) ? error : new Error(String(error));
|
|
@@ -101,7 +111,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
101
111
|
return httpError;
|
|
102
112
|
}
|
|
103
113
|
/**
|
|
104
|
-
*
|
|
114
|
+
* Provides additional context information for error reporting
|
|
115
|
+
* Includes request ID when available for correlation across logs
|
|
116
|
+
* @param ctx - HTTP context containing request information
|
|
117
|
+
* @returns Additional context data for error reporting
|
|
105
118
|
*/
|
|
106
119
|
context(ctx) {
|
|
107
120
|
const requestId = ctx.request.id();
|
|
@@ -110,8 +123,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
110
123
|
} : {};
|
|
111
124
|
}
|
|
112
125
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
126
|
+
* Determines the appropriate log level based on HTTP status code
|
|
127
|
+
* 5xx errors are logged as 'error', 4xx as 'warn', others as 'info'
|
|
128
|
+
* @param error - HTTP error object with status code
|
|
129
|
+
* @returns {Level} Appropriate logging level for the error
|
|
115
130
|
*/
|
|
116
131
|
getErrorLogLevel(error) {
|
|
117
132
|
if (error.status >= 500) {
|
|
@@ -123,14 +138,19 @@ var ExceptionHandler = class extends Macroable {
|
|
|
123
138
|
return "info";
|
|
124
139
|
}
|
|
125
140
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
141
|
+
* Determines whether debug information should be included in error responses
|
|
142
|
+
* Override this method to implement context-specific debug control
|
|
143
|
+
* @param _ - HTTP context (unused in base implementation)
|
|
144
|
+
* @returns {boolean} True if debugging should be enabled
|
|
128
145
|
*/
|
|
129
146
|
isDebuggingEnabled(_) {
|
|
130
147
|
return this.debug;
|
|
131
148
|
}
|
|
132
149
|
/**
|
|
133
|
-
*
|
|
150
|
+
* Determines whether an error should be reported to logging systems
|
|
151
|
+
* Checks against ignore lists for exceptions, status codes, and error codes
|
|
152
|
+
* @param error - HTTP error to evaluate for reporting
|
|
153
|
+
* @returns {boolean} True if the error should be reported
|
|
134
154
|
*/
|
|
135
155
|
shouldReport(error) {
|
|
136
156
|
if (this.reportErrors === false) {
|
|
@@ -148,7 +168,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
148
168
|
return true;
|
|
149
169
|
}
|
|
150
170
|
/**
|
|
151
|
-
* Renders an error
|
|
171
|
+
* Renders an error as a JSON response
|
|
172
|
+
* In debug mode, includes full stack trace using Youch
|
|
173
|
+
* @param error - HTTP error to render
|
|
174
|
+
* @param ctx - HTTP context for the request
|
|
152
175
|
*/
|
|
153
176
|
async renderErrorAsJSON(error, ctx) {
|
|
154
177
|
if (this.isDebuggingEnabled(ctx)) {
|
|
@@ -160,7 +183,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
160
183
|
ctx.response.status(error.status).send({ message: error.message });
|
|
161
184
|
}
|
|
162
185
|
/**
|
|
163
|
-
* Renders an error
|
|
186
|
+
* Renders an error as a JSON API compliant response
|
|
187
|
+
* Follows JSON API specification for error objects
|
|
188
|
+
* @param error - HTTP error to render
|
|
189
|
+
* @param ctx - HTTP context for the request
|
|
164
190
|
*/
|
|
165
191
|
async renderErrorAsJSONAPI(error, ctx) {
|
|
166
192
|
if (this.isDebuggingEnabled(ctx)) {
|
|
@@ -180,7 +206,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
180
206
|
});
|
|
181
207
|
}
|
|
182
208
|
/**
|
|
183
|
-
* Renders an error
|
|
209
|
+
* Renders an error as an HTML response
|
|
210
|
+
* Uses status pages if configured, otherwise shows debug info or simple message
|
|
211
|
+
* @param error - HTTP error to render
|
|
212
|
+
* @param ctx - HTTP context for the request
|
|
184
213
|
*/
|
|
185
214
|
async renderErrorAsHTML(error, ctx) {
|
|
186
215
|
const statusPages = this.#expandStatusPages();
|
|
@@ -203,8 +232,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
203
232
|
ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
|
|
204
233
|
}
|
|
205
234
|
/**
|
|
206
|
-
* Renders
|
|
207
|
-
*
|
|
235
|
+
* Renders validation error messages as a JSON response
|
|
236
|
+
* Returns errors in a simple format with field-specific messages
|
|
237
|
+
* @param error - Validation error containing messages array
|
|
238
|
+
* @param ctx - HTTP context for the request
|
|
208
239
|
*/
|
|
209
240
|
async renderValidationErrorAsJSON(error, ctx) {
|
|
210
241
|
ctx.response.status(error.status).send({
|
|
@@ -212,8 +243,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
212
243
|
});
|
|
213
244
|
}
|
|
214
245
|
/**
|
|
215
|
-
* Renders
|
|
216
|
-
*
|
|
246
|
+
* Renders validation error messages as JSON API compliant response
|
|
247
|
+
* Transforms validation messages to JSON API error object format
|
|
248
|
+
* @param error - Validation error containing messages array
|
|
249
|
+
* @param ctx - HTTP context for the request
|
|
217
250
|
*/
|
|
218
251
|
async renderValidationErrorAsJSONAPI(error, ctx) {
|
|
219
252
|
ctx.response.status(error.status).send({
|
|
@@ -230,7 +263,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
230
263
|
});
|
|
231
264
|
}
|
|
232
265
|
/**
|
|
233
|
-
* Renders
|
|
266
|
+
* Renders validation error messages as an HTML response
|
|
267
|
+
* Creates simple HTML list of field errors separated by line breaks
|
|
268
|
+
* @param error - Validation error containing messages array
|
|
269
|
+
* @param ctx - HTTP context for the request
|
|
234
270
|
*/
|
|
235
271
|
async renderValidationErrorAsHTML(error, ctx) {
|
|
236
272
|
ctx.response.status(error.status).type("html").send(
|
|
@@ -240,7 +276,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
240
276
|
);
|
|
241
277
|
}
|
|
242
278
|
/**
|
|
243
|
-
* Renders
|
|
279
|
+
* Renders an error to the appropriate response format based on content negotiation
|
|
280
|
+
* Supports HTML, JSON API, and JSON formats based on Accept headers
|
|
281
|
+
* @param error - HTTP error to render
|
|
282
|
+
* @param ctx - HTTP context for the request
|
|
244
283
|
*/
|
|
245
284
|
renderError(error, ctx) {
|
|
246
285
|
switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
|
|
@@ -254,7 +293,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
254
293
|
}
|
|
255
294
|
}
|
|
256
295
|
/**
|
|
257
|
-
* Renders
|
|
296
|
+
* Renders validation errors to the appropriate response format based on content negotiation
|
|
297
|
+
* Supports HTML, JSON API, and JSON formats for validation error messages
|
|
298
|
+
* @param error - Validation error to render
|
|
299
|
+
* @param ctx - HTTP context for the request
|
|
258
300
|
*/
|
|
259
301
|
renderValidationError(error, ctx) {
|
|
260
302
|
switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
|
|
@@ -268,7 +310,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
268
310
|
}
|
|
269
311
|
}
|
|
270
312
|
/**
|
|
271
|
-
* Reports an error
|
|
313
|
+
* Reports an error to logging systems if reporting is enabled
|
|
314
|
+
* Allows errors to self-report via their own report method if available
|
|
315
|
+
* @param error - Any error object to report
|
|
316
|
+
* @param ctx - HTTP context for additional reporting context
|
|
272
317
|
*/
|
|
273
318
|
async report(error, ctx) {
|
|
274
319
|
const httpError = this.#toHttpError(error);
|
|
@@ -290,7 +335,10 @@ var ExceptionHandler = class extends Macroable {
|
|
|
290
335
|
);
|
|
291
336
|
}
|
|
292
337
|
/**
|
|
293
|
-
* Handles
|
|
338
|
+
* Handles errors during HTTP request processing
|
|
339
|
+
* Delegates to error's own handle method if available, otherwise renders response
|
|
340
|
+
* @param error - Any error object to handle
|
|
341
|
+
* @param ctx - HTTP context for error handling
|
|
294
342
|
*/
|
|
295
343
|
async handle(error, ctx) {
|
|
296
344
|
const httpError = this.#toHttpError(error);
|
|
@@ -306,6 +354,8 @@ var ExceptionHandler = class extends Macroable {
|
|
|
306
354
|
export {
|
|
307
355
|
BriskRoute,
|
|
308
356
|
CookieClient,
|
|
357
|
+
CookieParser,
|
|
358
|
+
CookieSerializer,
|
|
309
359
|
ExceptionHandler,
|
|
310
360
|
HttpContext,
|
|
311
361
|
Redirect,
|
|
@@ -5,33 +5,68 @@ import type { Encryption } from '@adonisjs/encryption';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class CookieClient {
|
|
7
7
|
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Create a new instance of CookieClient
|
|
10
|
+
*
|
|
11
|
+
* @param encryption - The encryption instance for cookie operations
|
|
12
|
+
*/
|
|
8
13
|
constructor(encryption: Encryption);
|
|
9
14
|
/**
|
|
10
15
|
* Encrypt a key value pair to be sent in the cookie header
|
|
16
|
+
*
|
|
17
|
+
* @param key - The cookie key
|
|
18
|
+
* @param value - The value to encrypt
|
|
19
|
+
* @returns The encrypted cookie string or null if encryption fails
|
|
11
20
|
*/
|
|
12
21
|
encrypt(key: string, value: any): string | null;
|
|
13
22
|
/**
|
|
14
23
|
* Sign a key value pair to be sent in the cookie header
|
|
24
|
+
*
|
|
25
|
+
* @param key - The cookie key
|
|
26
|
+
* @param value - The value to sign
|
|
27
|
+
* @returns The signed cookie string or null if signing fails
|
|
15
28
|
*/
|
|
16
29
|
sign(key: string, value: any): string | null;
|
|
17
30
|
/**
|
|
18
31
|
* Encode a key value pair to be sent in the cookie header
|
|
32
|
+
*
|
|
33
|
+
* @param _ - Unused key parameter
|
|
34
|
+
* @param value - The value to encode
|
|
35
|
+
* @param stringify - Whether to stringify the value before encoding
|
|
36
|
+
* @returns The encoded cookie string or null if encoding fails
|
|
19
37
|
*/
|
|
20
38
|
encode(_: string, value: any, stringify?: boolean): string | null;
|
|
21
39
|
/**
|
|
22
40
|
* Unsign a signed cookie value
|
|
41
|
+
*
|
|
42
|
+
* @param key - The cookie key
|
|
43
|
+
* @param value - The signed cookie value to unsign
|
|
44
|
+
* @returns The original value if valid signature, null otherwise
|
|
23
45
|
*/
|
|
24
46
|
unsign(key: string, value: string): any;
|
|
25
47
|
/**
|
|
26
48
|
* Decrypt an encrypted cookie value
|
|
49
|
+
*
|
|
50
|
+
* @param key - The cookie key
|
|
51
|
+
* @param value - The encrypted cookie value to decrypt
|
|
52
|
+
* @returns The decrypted value or null if decryption fails
|
|
27
53
|
*/
|
|
28
54
|
decrypt(key: string, value: string): any;
|
|
29
55
|
/**
|
|
30
56
|
* Decode an encoded cookie value
|
|
57
|
+
*
|
|
58
|
+
* @param _ - Unused key parameter
|
|
59
|
+
* @param value - The encoded cookie value to decode
|
|
60
|
+
* @param stringified - Whether the value was stringified during encoding
|
|
61
|
+
* @returns The decoded value or null if decoding fails
|
|
31
62
|
*/
|
|
32
63
|
decode(_: string, value: string, stringified?: boolean): any;
|
|
33
64
|
/**
|
|
34
65
|
* Parse response cookie
|
|
66
|
+
*
|
|
67
|
+
* @param key - The cookie key
|
|
68
|
+
* @param value - The cookie value to parse
|
|
69
|
+
* @returns The parsed value or undefined if parsing fails
|
|
35
70
|
*/
|
|
36
71
|
parse(key: string, value: any): any;
|
|
37
72
|
}
|