@navios/core 0.9.3 → 1.0.0-alpha.2
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/CHANGELOG.md +58 -0
- package/README.md +4 -2
- package/docs/README.md +3 -1
- package/docs/exceptions.md +37 -1
- package/lib/{index-B2ulzZIr.d.cts → index-BJjk2X1S.d.mts} +478 -33
- package/lib/index-BJjk2X1S.d.mts.map +1 -0
- package/lib/{index-C8lUQePd.d.mts → index-DZ6NU03y.d.cts} +478 -33
- package/lib/index-DZ6NU03y.d.cts.map +1 -0
- package/lib/index.cjs +37 -2
- package/lib/index.d.cts +2 -2
- package/lib/index.d.mts +2 -2
- package/lib/index.mjs +3 -3
- package/lib/legacy-compat/index.cjs +8 -6
- package/lib/legacy-compat/index.cjs.map +1 -1
- package/lib/legacy-compat/index.d.cts +11 -16
- package/lib/legacy-compat/index.d.cts.map +1 -1
- package/lib/legacy-compat/index.d.mts +11 -16
- package/lib/legacy-compat/index.d.mts.map +1 -1
- package/lib/legacy-compat/index.mjs +7 -5
- package/lib/legacy-compat/index.mjs.map +1 -1
- package/lib/{src-Cu9OAnfp.cjs → src-C46ePe3d.cjs} +1970 -171
- package/lib/src-C46ePe3d.cjs.map +1 -0
- package/lib/{src-Baabu2R8.mjs → src-K2k0riYJ.mjs} +1941 -202
- package/lib/src-K2k0riYJ.mjs.map +1 -0
- package/lib/testing/index.cjs +2 -2
- package/lib/testing/index.d.cts +1 -1
- package/lib/testing/index.d.mts +1 -1
- package/lib/testing/index.mjs +2 -2
- package/lib/{use-guards.decorator-EvI2m2DK.cjs → use-guards.decorator-B6tghdxM.cjs} +7 -4
- package/lib/use-guards.decorator-B6tghdxM.cjs.map +1 -0
- package/lib/{use-guards.decorator-ChJVzYLW.mjs → use-guards.decorator-Be_QUx6b.mjs} +6 -3
- package/lib/use-guards.decorator-Be_QUx6b.mjs.map +1 -0
- package/package.json +3 -3
- package/src/__tests__/responders.spec.mts +339 -0
- package/src/decorators/endpoint.decorator.mts +49 -97
- package/src/decorators/module.decorator.mts +12 -0
- package/src/decorators/multipart.decorator.mts +62 -87
- package/src/decorators/stream.decorator.mts +66 -76
- package/src/index.mts +1 -0
- package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -2
- package/src/legacy-compat/decorators/endpoint.decorator.mts +21 -47
- package/src/legacy-compat/decorators/multipart.decorator.mts +20 -41
- package/src/legacy-compat/decorators/stream.decorator.mts +48 -42
- package/src/metadata/module.metadata.mts +2 -0
- package/src/responders/enums/framework-error.enum.mts +38 -0
- package/src/responders/enums/index.mts +1 -0
- package/src/responders/index.mts +4 -0
- package/src/responders/interfaces/error-responder.interface.mts +42 -0
- package/src/responders/interfaces/error-response.interface.mts +22 -0
- package/src/responders/interfaces/index.mts +3 -0
- package/src/responders/interfaces/problem-details.interface.mts +34 -0
- package/src/responders/services/error-response-producer.service.mts +143 -0
- package/src/responders/services/forbidden-responder.service.mts +77 -0
- package/src/responders/services/index.mts +5 -0
- package/src/responders/services/internal-server-error-responder.service.mts +57 -0
- package/src/responders/services/not-found-responder.service.mts +76 -0
- package/src/responders/services/validation-error-responder.service.mts +78 -0
- package/src/responders/tokens/index.mts +1 -0
- package/src/responders/tokens/responder.tokens.mts +84 -0
- package/src/services/guard-runner.service.mts +19 -6
- package/src/services/module-loader.service.mts +63 -0
- package/lib/index-B2ulzZIr.d.cts.map +0 -1
- package/lib/index-C8lUQePd.d.mts.map +0 -1
- package/lib/src-Baabu2R8.mjs.map +0 -1
- package/lib/src-Cu9OAnfp.cjs.map +0 -1
- package/lib/use-guards.decorator-ChJVzYLW.mjs.map +0 -1
- package/lib/use-guards.decorator-EvI2m2DK.cjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _navios_di0 from "@navios/di";
|
|
2
2
|
import { AnyInjectableType, ClassType, ClassTypeWithInstance, Container, FactoryContext, FactoryInjectionToken, InjectableScope, InjectionToken, Registry, ScopedContainer } from "@navios/di";
|
|
3
3
|
import z, { ZodDiscriminatedUnion, ZodObject, ZodType, z as z$1 } from "zod/v4";
|
|
4
|
-
import {
|
|
4
|
+
import { BaseEndpointOptions, EndpointHandler, EndpointOptions, HttpMethod, RequestArgs, StreamHandler } from "@navios/builder";
|
|
5
5
|
import { InspectOptions } from "util";
|
|
6
6
|
import { OutgoingHttpHeaders } from "http";
|
|
7
7
|
|
|
@@ -287,9 +287,7 @@ declare function Controller({
|
|
|
287
287
|
* }
|
|
288
288
|
* ```
|
|
289
289
|
*/
|
|
290
|
-
type EndpointParams<EndpointDeclaration extends
|
|
291
|
-
config: BaseEndpointConfig<any, any, any, any, any>;
|
|
292
|
-
}, Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodType ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>;
|
|
290
|
+
type EndpointParams<EndpointDeclaration extends EndpointHandler<Config, false>, Config extends EndpointOptions = EndpointDeclaration['config']> = RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>;
|
|
293
291
|
/**
|
|
294
292
|
* Extracts the typed return value for an endpoint handler function.
|
|
295
293
|
*
|
|
@@ -313,7 +311,7 @@ type EndpointParams<EndpointDeclaration extends {
|
|
|
313
311
|
* ```
|
|
314
312
|
*/
|
|
315
313
|
type EndpointResult<EndpointDeclaration extends {
|
|
316
|
-
config:
|
|
314
|
+
config: EndpointOptions;
|
|
317
315
|
}> = EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<infer Options> ? Promise<z$1.input<Options[number]>> : Promise<z$1.input<EndpointDeclaration['config']['responseSchema']>>;
|
|
318
316
|
/**
|
|
319
317
|
* Decorator that marks a method as an HTTP endpoint.
|
|
@@ -345,12 +343,8 @@ type EndpointResult<EndpointDeclaration extends {
|
|
|
345
343
|
* }
|
|
346
344
|
* ```
|
|
347
345
|
*/
|
|
348
|
-
declare function Endpoint<
|
|
349
|
-
|
|
350
|
-
}): (target: (params: Params) => Promise<z$1.input<ResponseSchema>> | z$1.input<ResponseSchema>, context: ClassMethodDecoratorContext) => void;
|
|
351
|
-
declare function Endpoint<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema = undefined, ResponseSchema extends ZodType = ZodType, RequestSchema = ZodType>(endpoint: {
|
|
352
|
-
config: BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema>;
|
|
353
|
-
}): (target: () => Promise<z$1.input<ResponseSchema>> | z$1.input<ResponseSchema>, context: ClassMethodDecoratorContext) => void;
|
|
346
|
+
declare function Endpoint<const Config extends EndpointOptions>(endpoint: EndpointHandler<Config, false>): (target: (params: RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>) => Promise<z$1.input<Config['responseSchema']>> | z$1.input<Config['responseSchema']>, context: ClassMethodDecoratorContext) => void;
|
|
347
|
+
declare function Endpoint<const Config extends EndpointOptions>(endpoint: EndpointHandler<Config, false>): (target: () => Promise<z$1.input<Config['responseSchema']>> | z$1.input<Config['responseSchema']>, context: ClassMethodDecoratorContext) => void;
|
|
354
348
|
//#endregion
|
|
355
349
|
//#region src/metadata/handler.metadata.d.mts
|
|
356
350
|
declare const EndpointMetadataKey: unique symbol;
|
|
@@ -385,6 +379,7 @@ interface ModuleMetadata {
|
|
|
385
379
|
controllers: Set<ClassType>;
|
|
386
380
|
imports: Set<ClassType>;
|
|
387
381
|
guards: Set<ClassTypeWithInstance<CanActivate> | InjectionToken<CanActivate, undefined>>;
|
|
382
|
+
overrides: Set<ClassType>;
|
|
388
383
|
customAttributes: Map<string | symbol, any>;
|
|
389
384
|
}
|
|
390
385
|
declare function getModuleMetadata(target: ClassType, context: ClassDecoratorContext): ModuleMetadata;
|
|
@@ -1118,6 +1113,7 @@ declare class ModuleLoaderService {
|
|
|
1118
1113
|
*/
|
|
1119
1114
|
private registerControllers;
|
|
1120
1115
|
private traverseModules;
|
|
1116
|
+
private validateOverrides;
|
|
1121
1117
|
private mergeMetadata;
|
|
1122
1118
|
getAllModules(): Map<string, ModuleMetadata>;
|
|
1123
1119
|
dispose(): void;
|
|
@@ -1282,6 +1278,13 @@ interface ModuleOptions {
|
|
|
1282
1278
|
* Guards are executed in reverse order (last guard first).
|
|
1283
1279
|
*/
|
|
1284
1280
|
guards?: ClassType[] | Set<ClassType>;
|
|
1281
|
+
/**
|
|
1282
|
+
* Service override classes to import for side effects.
|
|
1283
|
+
* These classes are imported to ensure their @Injectable decorators execute,
|
|
1284
|
+
* allowing them to register with the DI system. Overrides should use the same
|
|
1285
|
+
* InjectionToken as the original service with a higher priority.
|
|
1286
|
+
*/
|
|
1287
|
+
overrides?: ClassType[] | Set<ClassType>;
|
|
1285
1288
|
/**
|
|
1286
1289
|
* Priority to use for the module.
|
|
1287
1290
|
* Priority is used to sort the module in the registry.
|
|
@@ -1316,6 +1319,7 @@ declare function Module({
|
|
|
1316
1319
|
controllers,
|
|
1317
1320
|
imports,
|
|
1318
1321
|
guards,
|
|
1322
|
+
overrides,
|
|
1319
1323
|
priority,
|
|
1320
1324
|
registry
|
|
1321
1325
|
}?: ModuleOptions): (target: ClassType, context: ClassDecoratorContext) => ClassType;
|
|
@@ -1329,15 +1333,15 @@ declare function Module({
|
|
|
1329
1333
|
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
1330
1334
|
*/
|
|
1331
1335
|
type MultipartParams<EndpointDeclaration extends {
|
|
1332
|
-
config:
|
|
1333
|
-
}, Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodObject ? EndpointDeclaration['config']['requestSchema'] extends ZodType ?
|
|
1336
|
+
config: EndpointOptions;
|
|
1337
|
+
}, Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodObject ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? RequestArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], EndpointDeclaration['config']['urlParamsSchema'], true> : RequestArgs<Url, QuerySchema, undefined, EndpointDeclaration['config']['urlParamsSchema'], true> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? RequestArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], EndpointDeclaration['config']['urlParamsSchema'], true> : RequestArgs<Url, undefined, undefined, EndpointDeclaration['config']['urlParamsSchema'], true>;
|
|
1334
1338
|
/**
|
|
1335
1339
|
* Extracts the typed return value for a multipart endpoint handler function.
|
|
1336
1340
|
*
|
|
1337
1341
|
* @typeParam EndpointDeclaration - The endpoint declaration from @navios/builder
|
|
1338
1342
|
*/
|
|
1339
1343
|
type MultipartResult<EndpointDeclaration extends {
|
|
1340
|
-
config:
|
|
1344
|
+
config: EndpointOptions;
|
|
1341
1345
|
}> = EndpointDeclaration['config']['responseSchema'] extends ZodDiscriminatedUnion<infer Options> ? Promise<z$1.input<Options[number]>> : Promise<z$1.input<EndpointDeclaration['config']['responseSchema']>>;
|
|
1342
1346
|
/**
|
|
1343
1347
|
* Decorator that marks a method as a multipart/form-data endpoint.
|
|
@@ -1368,12 +1372,12 @@ type MultipartResult<EndpointDeclaration extends {
|
|
|
1368
1372
|
* }
|
|
1369
1373
|
* ```
|
|
1370
1374
|
*/
|
|
1371
|
-
declare function Multipart<
|
|
1372
|
-
config:
|
|
1373
|
-
}): (target: (params:
|
|
1374
|
-
declare function Multipart<
|
|
1375
|
-
config:
|
|
1376
|
-
}): (target: () => Promise<z$1.input<
|
|
1375
|
+
declare function Multipart<Config extends EndpointOptions>(endpoint: {
|
|
1376
|
+
config: Config;
|
|
1377
|
+
}): (target: (params: RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>) => Promise<z$1.input<Config['responseSchema']>> | z$1.input<Config['responseSchema']>, context: ClassMethodDecoratorContext) => void;
|
|
1378
|
+
declare function Multipart<Config extends EndpointOptions>(endpoint: {
|
|
1379
|
+
config: Config;
|
|
1380
|
+
}): (target: () => Promise<z$1.input<Config['responseSchema']>> | z$1.input<Config['responseSchema']>, context: ClassMethodDecoratorContext) => void;
|
|
1377
1381
|
//#endregion
|
|
1378
1382
|
//#region src/decorators/stream.decorator.d.mts
|
|
1379
1383
|
/**
|
|
@@ -1383,9 +1387,7 @@ declare function Multipart<Method extends HttpMethod = HttpMethod, Url extends s
|
|
|
1383
1387
|
*
|
|
1384
1388
|
* @typeParam EndpointDeclaration - The stream endpoint declaration from @navios/builder
|
|
1385
1389
|
*/
|
|
1386
|
-
type StreamParams<EndpointDeclaration extends
|
|
1387
|
-
config: BaseStreamConfig<any, any, any, any>;
|
|
1388
|
-
}, Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodObject ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, QuerySchema, undefined, true>> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? Util_FlatObject<EndpointFunctionArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], true>> : Util_FlatObject<EndpointFunctionArgs<Url, undefined, undefined, true>>;
|
|
1390
|
+
type StreamParams<EndpointDeclaration extends StreamHandler<Config, false>, Config extends BaseEndpointOptions = EndpointDeclaration['config'], Url extends string = EndpointDeclaration['config']['url'], QuerySchema = EndpointDeclaration['config']['querySchema']> = QuerySchema extends ZodObject ? EndpointDeclaration['config']['requestSchema'] extends ZodType ? RequestArgs<Url, QuerySchema, EndpointDeclaration['config']['requestSchema'], EndpointDeclaration['config']['urlParamsSchema'], true> : RequestArgs<Url, QuerySchema, undefined, EndpointDeclaration['config']['urlParamsSchema'], true> : EndpointDeclaration['config']['requestSchema'] extends ZodType ? RequestArgs<Url, undefined, EndpointDeclaration['config']['requestSchema'], EndpointDeclaration['config']['urlParamsSchema'], true> : RequestArgs<Url, undefined, undefined, EndpointDeclaration['config']['urlParamsSchema'], true>;
|
|
1389
1391
|
/**
|
|
1390
1392
|
* Decorator that marks a method as a streaming endpoint.
|
|
1391
1393
|
*
|
|
@@ -1412,14 +1414,14 @@ type StreamParams<EndpointDeclaration extends {
|
|
|
1412
1414
|
* }
|
|
1413
1415
|
* ```
|
|
1414
1416
|
*/
|
|
1415
|
-
declare function Stream<
|
|
1416
|
-
config:
|
|
1417
|
-
}): (target: (params:
|
|
1418
|
-
declare function Stream<
|
|
1419
|
-
config:
|
|
1420
|
-
}): (target: (params:
|
|
1421
|
-
declare function Stream<
|
|
1422
|
-
config:
|
|
1417
|
+
declare function Stream<Config extends BaseEndpointOptions>(endpoint: {
|
|
1418
|
+
config: Config;
|
|
1419
|
+
}): (target: (params: RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>, reply: any) => any, context: ClassMethodDecoratorContext) => void;
|
|
1420
|
+
declare function Stream<Config extends BaseEndpointOptions>(endpoint: {
|
|
1421
|
+
config: Config;
|
|
1422
|
+
}): (target: (params: RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema'], true>) => any, context: ClassMethodDecoratorContext) => void;
|
|
1423
|
+
declare function Stream<Config extends BaseEndpointOptions>(endpoint: {
|
|
1424
|
+
config: Config;
|
|
1423
1425
|
}): (target: () => any, context: ClassMethodDecoratorContext) => void;
|
|
1424
1426
|
//#endregion
|
|
1425
1427
|
//#region src/decorators/use-guards.decorator.d.mts
|
|
@@ -1660,6 +1662,448 @@ declare class ConflictException extends HttpException {
|
|
|
1660
1662
|
constructor(message: string | object, error?: Error);
|
|
1661
1663
|
}
|
|
1662
1664
|
//#endregion
|
|
1665
|
+
//#region src/responders/enums/framework-error.enum.d.mts
|
|
1666
|
+
/**
|
|
1667
|
+
* Enumeration of framework-level error types.
|
|
1668
|
+
* Used to explicitly specify which error responder should handle an error.
|
|
1669
|
+
*
|
|
1670
|
+
* @example
|
|
1671
|
+
* ```typescript
|
|
1672
|
+
* // In adapter error handling
|
|
1673
|
+
* if (error instanceof ZodError) {
|
|
1674
|
+
* return errorProducer.respond(FrameworkError.ValidationError, error)
|
|
1675
|
+
* }
|
|
1676
|
+
* return errorProducer.handleUnknown(error)
|
|
1677
|
+
* ```
|
|
1678
|
+
*/
|
|
1679
|
+
declare enum FrameworkError {
|
|
1680
|
+
/**
|
|
1681
|
+
* Resource not found (HTTP 404).
|
|
1682
|
+
* Use when a requested resource does not exist.
|
|
1683
|
+
*/
|
|
1684
|
+
NotFound = "NotFound",
|
|
1685
|
+
/**
|
|
1686
|
+
* Forbidden (HTTP 403).
|
|
1687
|
+
* Use when access to a resource is denied (e.g., guard rejection).
|
|
1688
|
+
*/
|
|
1689
|
+
Forbidden = "Forbidden",
|
|
1690
|
+
/**
|
|
1691
|
+
* Internal server error (HTTP 500).
|
|
1692
|
+
* Use for unexpected errors that don't fit other categories.
|
|
1693
|
+
*/
|
|
1694
|
+
InternalServerError = "InternalServerError",
|
|
1695
|
+
/**
|
|
1696
|
+
* Validation error (HTTP 400).
|
|
1697
|
+
* Use when request data fails validation (e.g., Zod errors).
|
|
1698
|
+
*/
|
|
1699
|
+
ValidationError = "ValidationError",
|
|
1700
|
+
}
|
|
1701
|
+
//#endregion
|
|
1702
|
+
//#region src/responders/interfaces/problem-details.interface.d.mts
|
|
1703
|
+
/**
|
|
1704
|
+
* RFC 7807 Problem Details for HTTP APIs
|
|
1705
|
+
* @see https://tools.ietf.org/html/rfc7807
|
|
1706
|
+
*/
|
|
1707
|
+
interface ProblemDetails {
|
|
1708
|
+
/**
|
|
1709
|
+
* A URI reference that identifies the problem type.
|
|
1710
|
+
* When dereferenced, it should provide human-readable documentation.
|
|
1711
|
+
* @default 'about:blank'
|
|
1712
|
+
*/
|
|
1713
|
+
type?: string;
|
|
1714
|
+
/**
|
|
1715
|
+
* A short, human-readable summary of the problem type.
|
|
1716
|
+
* It should not change from occurrence to occurrence.
|
|
1717
|
+
*/
|
|
1718
|
+
title: string;
|
|
1719
|
+
/**
|
|
1720
|
+
* The HTTP status code for this occurrence of the problem.
|
|
1721
|
+
*/
|
|
1722
|
+
status: number;
|
|
1723
|
+
/**
|
|
1724
|
+
* A human-readable explanation specific to this occurrence of the problem.
|
|
1725
|
+
*/
|
|
1726
|
+
detail?: string;
|
|
1727
|
+
/**
|
|
1728
|
+
* Additional extension members.
|
|
1729
|
+
* Custom properties can be added to provide more context.
|
|
1730
|
+
*/
|
|
1731
|
+
[key: string]: unknown;
|
|
1732
|
+
}
|
|
1733
|
+
//#endregion
|
|
1734
|
+
//#region src/responders/interfaces/error-response.interface.d.mts
|
|
1735
|
+
/**
|
|
1736
|
+
* Represents a complete error response that can be sent to the client.
|
|
1737
|
+
* Includes the status code, payload (RFC 7807 Problem Details), and headers.
|
|
1738
|
+
*/
|
|
1739
|
+
interface ErrorResponse {
|
|
1740
|
+
/**
|
|
1741
|
+
* HTTP status code for the response.
|
|
1742
|
+
*/
|
|
1743
|
+
statusCode: number;
|
|
1744
|
+
/**
|
|
1745
|
+
* RFC 7807 Problem Details payload.
|
|
1746
|
+
*/
|
|
1747
|
+
payload: ProblemDetails;
|
|
1748
|
+
/**
|
|
1749
|
+
* HTTP headers to include in the response.
|
|
1750
|
+
*/
|
|
1751
|
+
headers: Record<string, string>;
|
|
1752
|
+
}
|
|
1753
|
+
//#endregion
|
|
1754
|
+
//#region src/responders/interfaces/error-responder.interface.d.mts
|
|
1755
|
+
/**
|
|
1756
|
+
* Interface for error responders that convert errors to HTTP responses.
|
|
1757
|
+
* Each responder handles a specific type of framework error and produces
|
|
1758
|
+
* an RFC 7807 compliant response.
|
|
1759
|
+
*
|
|
1760
|
+
* Implementations are registered with low priority (-10) so they can be
|
|
1761
|
+
* easily overridden by consumers.
|
|
1762
|
+
*
|
|
1763
|
+
* @example
|
|
1764
|
+
* ```typescript
|
|
1765
|
+
* @Injectable({
|
|
1766
|
+
* token: InternalServerErrorResponderToken,
|
|
1767
|
+
* priority: 0, // Override default implementation
|
|
1768
|
+
* })
|
|
1769
|
+
* export class CustomInternalErrorResponder implements ErrorResponder {
|
|
1770
|
+
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
1771
|
+
* return {
|
|
1772
|
+
* statusCode: 500,
|
|
1773
|
+
* payload: {
|
|
1774
|
+
* type: 'https://api.myapp.com/errors/server-error',
|
|
1775
|
+
* title: 'Server Error',
|
|
1776
|
+
* status: 500,
|
|
1777
|
+
* detail: description ?? 'An unexpected error occurred',
|
|
1778
|
+
* },
|
|
1779
|
+
* headers: { 'Content-Type': 'application/problem+json' },
|
|
1780
|
+
* }
|
|
1781
|
+
* }
|
|
1782
|
+
* }
|
|
1783
|
+
* ```
|
|
1784
|
+
*/
|
|
1785
|
+
interface ErrorResponder {
|
|
1786
|
+
/**
|
|
1787
|
+
* Converts an error to an ErrorResponse with RFC 7807 Problem Details.
|
|
1788
|
+
*
|
|
1789
|
+
* @param error - The original error that was thrown
|
|
1790
|
+
* @param description - Optional custom description to include in the response
|
|
1791
|
+
* @returns ErrorResponse with status code, payload, and headers
|
|
1792
|
+
*/
|
|
1793
|
+
getResponse(error: unknown, description?: string): ErrorResponse;
|
|
1794
|
+
}
|
|
1795
|
+
//#endregion
|
|
1796
|
+
//#region src/responders/services/error-response-producer.service.d.mts
|
|
1797
|
+
/**
|
|
1798
|
+
* Service for producing standardized error responses.
|
|
1799
|
+
*
|
|
1800
|
+
* This service coordinates error responders to produce RFC 7807 compliant
|
|
1801
|
+
* Problem Details responses. Adapters use this service to convert errors
|
|
1802
|
+
* into standardized HTTP responses.
|
|
1803
|
+
*
|
|
1804
|
+
* The caller explicitly specifies which type of error response to produce
|
|
1805
|
+
* via the FrameworkError enum, giving full control to the adapter.
|
|
1806
|
+
*
|
|
1807
|
+
* @example Usage in an adapter:
|
|
1808
|
+
* ```typescript
|
|
1809
|
+
* @Injectable()
|
|
1810
|
+
* class MyAdapter {
|
|
1811
|
+
* private errorProducer = inject(ErrorResponseProducerService)
|
|
1812
|
+
*
|
|
1813
|
+
* handleError(error: unknown): Response {
|
|
1814
|
+
* if (error instanceof ZodError) {
|
|
1815
|
+
* const response = this.errorProducer.respond(
|
|
1816
|
+
* FrameworkError.ValidationError,
|
|
1817
|
+
* error,
|
|
1818
|
+
* )
|
|
1819
|
+
* return new Response(JSON.stringify(response.payload), {
|
|
1820
|
+
* status: response.statusCode,
|
|
1821
|
+
* headers: response.headers,
|
|
1822
|
+
* })
|
|
1823
|
+
* }
|
|
1824
|
+
*
|
|
1825
|
+
* // Fallback for unknown errors
|
|
1826
|
+
* const response = this.errorProducer.handleUnknown(error)
|
|
1827
|
+
* return new Response(JSON.stringify(response.payload), {
|
|
1828
|
+
* status: response.statusCode,
|
|
1829
|
+
* headers: response.headers,
|
|
1830
|
+
* })
|
|
1831
|
+
* }
|
|
1832
|
+
* }
|
|
1833
|
+
* ```
|
|
1834
|
+
*/
|
|
1835
|
+
declare class ErrorResponseProducerService {
|
|
1836
|
+
private readonly forbiddenResponder;
|
|
1837
|
+
private readonly internalServerErrorResponder;
|
|
1838
|
+
private readonly notFoundResponder;
|
|
1839
|
+
private readonly validationErrorResponder;
|
|
1840
|
+
/**
|
|
1841
|
+
* Produces an error response for a specific framework error type.
|
|
1842
|
+
*
|
|
1843
|
+
* @param type - The type of framework error (from FrameworkError enum)
|
|
1844
|
+
* @param error - The original error that was thrown
|
|
1845
|
+
* @param description - Optional custom description to include in the response
|
|
1846
|
+
* @returns ErrorResponse with status code, RFC 7807 payload, and headers
|
|
1847
|
+
*/
|
|
1848
|
+
respond(type: FrameworkError, error: unknown, description?: string): ErrorResponse;
|
|
1849
|
+
/**
|
|
1850
|
+
* Handles unknown errors by producing an Internal Server Error response.
|
|
1851
|
+
*
|
|
1852
|
+
* Use this as a fallback when the error type is not known or doesn't
|
|
1853
|
+
* match any specific framework error type.
|
|
1854
|
+
*
|
|
1855
|
+
* @param error - The original error that was thrown
|
|
1856
|
+
* @param description - Optional custom description to include in the response
|
|
1857
|
+
* @returns ErrorResponse with 500 status code
|
|
1858
|
+
*/
|
|
1859
|
+
handleUnknown(error: unknown, description?: string): ErrorResponse;
|
|
1860
|
+
/**
|
|
1861
|
+
* Convenience method to produce a Not Found error response.
|
|
1862
|
+
*
|
|
1863
|
+
* @param error - The original error that was thrown
|
|
1864
|
+
* @param description - Optional custom description
|
|
1865
|
+
* @returns ErrorResponse with 404 status code
|
|
1866
|
+
*/
|
|
1867
|
+
notFound(error: unknown, description?: string): ErrorResponse;
|
|
1868
|
+
/**
|
|
1869
|
+
* Convenience method to produce a Validation Error response.
|
|
1870
|
+
*
|
|
1871
|
+
* @param error - The original error (typically a ZodError)
|
|
1872
|
+
* @param description - Optional custom description
|
|
1873
|
+
* @returns ErrorResponse with 400 status code
|
|
1874
|
+
*/
|
|
1875
|
+
validationError(error: unknown, description?: string): ErrorResponse;
|
|
1876
|
+
/**
|
|
1877
|
+
* Convenience method to produce an Internal Server Error response.
|
|
1878
|
+
*
|
|
1879
|
+
* @param error - The original error
|
|
1880
|
+
* @param description - Optional custom description
|
|
1881
|
+
* @returns ErrorResponse with 500 status code
|
|
1882
|
+
*/
|
|
1883
|
+
internalServerError(error: unknown, description?: string): ErrorResponse;
|
|
1884
|
+
/**
|
|
1885
|
+
* Convenience method to produce a Forbidden error response.
|
|
1886
|
+
*
|
|
1887
|
+
* @param error - The original error
|
|
1888
|
+
* @param description - Optional custom description
|
|
1889
|
+
* @returns ErrorResponse with 403 status code
|
|
1890
|
+
*/
|
|
1891
|
+
forbidden(error: unknown, description?: string): ErrorResponse;
|
|
1892
|
+
}
|
|
1893
|
+
//#endregion
|
|
1894
|
+
//#region src/responders/services/forbidden-responder.service.d.mts
|
|
1895
|
+
/**
|
|
1896
|
+
* Default responder for forbidden errors (HTTP 403).
|
|
1897
|
+
*
|
|
1898
|
+
* Converts errors to RFC 7807 Problem Details format.
|
|
1899
|
+
* Used when access to a resource is denied (e.g., guard rejection).
|
|
1900
|
+
* Registered with low priority (-10) so it can be easily overridden.
|
|
1901
|
+
*
|
|
1902
|
+
* @example Override with custom implementation:
|
|
1903
|
+
* ```typescript
|
|
1904
|
+
* @Injectable({
|
|
1905
|
+
* token: ForbiddenResponderToken,
|
|
1906
|
+
* priority: 0,
|
|
1907
|
+
* })
|
|
1908
|
+
* export class CustomForbiddenResponder implements ErrorResponder {
|
|
1909
|
+
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
1910
|
+
* return {
|
|
1911
|
+
* statusCode: 403,
|
|
1912
|
+
* payload: {
|
|
1913
|
+
* type: 'https://api.myapp.com/errors/forbidden',
|
|
1914
|
+
* title: 'Access Denied',
|
|
1915
|
+
* status: 403,
|
|
1916
|
+
* detail: description ?? 'You do not have permission to access this resource',
|
|
1917
|
+
* },
|
|
1918
|
+
* headers: { 'Content-Type': 'application/problem+json' },
|
|
1919
|
+
* }
|
|
1920
|
+
* }
|
|
1921
|
+
* }
|
|
1922
|
+
* ```
|
|
1923
|
+
*/
|
|
1924
|
+
declare class ForbiddenResponderService implements ErrorResponder {
|
|
1925
|
+
getResponse(error: unknown, description?: string): ErrorResponse;
|
|
1926
|
+
private createResponse;
|
|
1927
|
+
}
|
|
1928
|
+
//#endregion
|
|
1929
|
+
//#region src/responders/services/internal-server-error-responder.service.d.mts
|
|
1930
|
+
/**
|
|
1931
|
+
* Default responder for internal server errors (HTTP 500).
|
|
1932
|
+
*
|
|
1933
|
+
* Converts generic errors to RFC 7807 Problem Details format.
|
|
1934
|
+
* Registered with low priority (-10) so it can be easily overridden.
|
|
1935
|
+
*
|
|
1936
|
+
* @example Override with custom implementation:
|
|
1937
|
+
* ```typescript
|
|
1938
|
+
* @Injectable({
|
|
1939
|
+
* token: InternalServerErrorResponderToken,
|
|
1940
|
+
* priority: 0,
|
|
1941
|
+
* })
|
|
1942
|
+
* export class CustomInternalErrorResponder implements ErrorResponder {
|
|
1943
|
+
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
1944
|
+
* return {
|
|
1945
|
+
* statusCode: 500,
|
|
1946
|
+
* payload: {
|
|
1947
|
+
* type: 'https://api.myapp.com/errors/server-error',
|
|
1948
|
+
* title: 'Server Error',
|
|
1949
|
+
* status: 500,
|
|
1950
|
+
* detail: description ?? 'An unexpected error occurred',
|
|
1951
|
+
* },
|
|
1952
|
+
* headers: { 'Content-Type': 'application/problem+json' },
|
|
1953
|
+
* }
|
|
1954
|
+
* }
|
|
1955
|
+
* }
|
|
1956
|
+
* ```
|
|
1957
|
+
*/
|
|
1958
|
+
declare class InternalServerErrorResponderService implements ErrorResponder {
|
|
1959
|
+
getResponse(error: unknown, description?: string): ErrorResponse;
|
|
1960
|
+
}
|
|
1961
|
+
//#endregion
|
|
1962
|
+
//#region src/responders/services/not-found-responder.service.d.mts
|
|
1963
|
+
/**
|
|
1964
|
+
* Default responder for not found errors (HTTP 404).
|
|
1965
|
+
*
|
|
1966
|
+
* Converts errors to RFC 7807 Problem Details format.
|
|
1967
|
+
* Registered with low priority (-10) so it can be easily overridden.
|
|
1968
|
+
*
|
|
1969
|
+
* @example Override with custom implementation:
|
|
1970
|
+
* ```typescript
|
|
1971
|
+
* @Injectable({
|
|
1972
|
+
* token: NotFoundResponderToken,
|
|
1973
|
+
* priority: 0,
|
|
1974
|
+
* })
|
|
1975
|
+
* export class CustomNotFoundResponder implements ErrorResponder {
|
|
1976
|
+
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
1977
|
+
* return {
|
|
1978
|
+
* statusCode: 404,
|
|
1979
|
+
* payload: {
|
|
1980
|
+
* type: 'https://api.myapp.com/errors/not-found',
|
|
1981
|
+
* title: 'Resource Not Found',
|
|
1982
|
+
* status: 404,
|
|
1983
|
+
* detail: description ?? 'The requested resource was not found',
|
|
1984
|
+
* },
|
|
1985
|
+
* headers: { 'Content-Type': 'application/problem+json' },
|
|
1986
|
+
* }
|
|
1987
|
+
* }
|
|
1988
|
+
* }
|
|
1989
|
+
* ```
|
|
1990
|
+
*/
|
|
1991
|
+
declare class NotFoundResponderService implements ErrorResponder {
|
|
1992
|
+
getResponse(error: unknown, description?: string): ErrorResponse;
|
|
1993
|
+
private createResponse;
|
|
1994
|
+
}
|
|
1995
|
+
//#endregion
|
|
1996
|
+
//#region src/responders/services/validation-error-responder.service.d.mts
|
|
1997
|
+
/**
|
|
1998
|
+
* Default responder for validation errors (HTTP 400).
|
|
1999
|
+
*
|
|
2000
|
+
* Converts Zod validation errors to RFC 7807 Problem Details format.
|
|
2001
|
+
* Includes the structured validation errors from treeifyError.
|
|
2002
|
+
* Registered with low priority (-10) so it can be easily overridden.
|
|
2003
|
+
*
|
|
2004
|
+
* @example Override with custom implementation:
|
|
2005
|
+
* ```typescript
|
|
2006
|
+
* @Injectable({
|
|
2007
|
+
* token: ValidationErrorResponderToken,
|
|
2008
|
+
* priority: 0,
|
|
2009
|
+
* })
|
|
2010
|
+
* export class CustomValidationResponder implements ErrorResponder {
|
|
2011
|
+
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2012
|
+
* const zodError = error as ZodError
|
|
2013
|
+
* return {
|
|
2014
|
+
* statusCode: 422, // Use 422 instead of 400
|
|
2015
|
+
* payload: {
|
|
2016
|
+
* type: 'https://api.myapp.com/errors/validation',
|
|
2017
|
+
* title: 'Unprocessable Entity',
|
|
2018
|
+
* status: 422,
|
|
2019
|
+
* detail: description ?? 'Validation failed',
|
|
2020
|
+
* issues: zodError.issues,
|
|
2021
|
+
* },
|
|
2022
|
+
* headers: { 'Content-Type': 'application/problem+json' },
|
|
2023
|
+
* }
|
|
2024
|
+
* }
|
|
2025
|
+
* }
|
|
2026
|
+
* ```
|
|
2027
|
+
*/
|
|
2028
|
+
declare class ValidationErrorResponderService implements ErrorResponder {
|
|
2029
|
+
getResponse(error: unknown, description?: string): ErrorResponse;
|
|
2030
|
+
}
|
|
2031
|
+
//#endregion
|
|
2032
|
+
//#region src/responders/tokens/responder.tokens.d.mts
|
|
2033
|
+
/**
|
|
2034
|
+
* Injection token for the Internal Server Error responder.
|
|
2035
|
+
* Default implementation returns HTTP 500 with RFC 7807 Problem Details.
|
|
2036
|
+
*
|
|
2037
|
+
* @example Override with custom implementation:
|
|
2038
|
+
* ```typescript
|
|
2039
|
+
* @Injectable({
|
|
2040
|
+
* token: InternalServerErrorResponderToken,
|
|
2041
|
+
* priority: 0, // Higher than default -10
|
|
2042
|
+
* })
|
|
2043
|
+
* export class CustomInternalErrorResponder implements ErrorResponder {
|
|
2044
|
+
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2045
|
+
* // Custom implementation
|
|
2046
|
+
* }
|
|
2047
|
+
* }
|
|
2048
|
+
* ```
|
|
2049
|
+
*/
|
|
2050
|
+
declare const InternalServerErrorResponderToken: InjectionToken<ErrorResponder, undefined, false>;
|
|
2051
|
+
/**
|
|
2052
|
+
* Injection token for the Not Found responder.
|
|
2053
|
+
* Default implementation returns HTTP 404 with RFC 7807 Problem Details.
|
|
2054
|
+
*
|
|
2055
|
+
* @example Override with custom implementation:
|
|
2056
|
+
* ```typescript
|
|
2057
|
+
* @Injectable({
|
|
2058
|
+
* token: NotFoundResponderToken,
|
|
2059
|
+
* priority: 0, // Higher than default -10
|
|
2060
|
+
* })
|
|
2061
|
+
* export class CustomNotFoundResponder implements ErrorResponder {
|
|
2062
|
+
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2063
|
+
* // Custom implementation
|
|
2064
|
+
* }
|
|
2065
|
+
* }
|
|
2066
|
+
* ```
|
|
2067
|
+
*/
|
|
2068
|
+
declare const NotFoundResponderToken: InjectionToken<ErrorResponder, undefined, false>;
|
|
2069
|
+
/**
|
|
2070
|
+
* Injection token for the Validation Error responder.
|
|
2071
|
+
* Default implementation returns HTTP 400 with RFC 7807 Problem Details
|
|
2072
|
+
* and includes validation errors from ZodError.
|
|
2073
|
+
*
|
|
2074
|
+
* @example Override with custom implementation:
|
|
2075
|
+
* ```typescript
|
|
2076
|
+
* @Injectable({
|
|
2077
|
+
* token: ValidationErrorResponderToken,
|
|
2078
|
+
* priority: 0, // Higher than default -10
|
|
2079
|
+
* })
|
|
2080
|
+
* export class CustomValidationResponder implements ErrorResponder {
|
|
2081
|
+
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2082
|
+
* // Custom implementation
|
|
2083
|
+
* }
|
|
2084
|
+
* }
|
|
2085
|
+
* ```
|
|
2086
|
+
*/
|
|
2087
|
+
declare const ValidationErrorResponderToken: InjectionToken<ErrorResponder, undefined, false>;
|
|
2088
|
+
/**
|
|
2089
|
+
* Injection token for the Forbidden responder.
|
|
2090
|
+
* Default implementation returns HTTP 403 with RFC 7807 Problem Details.
|
|
2091
|
+
*
|
|
2092
|
+
* @example Override with custom implementation:
|
|
2093
|
+
* ```typescript
|
|
2094
|
+
* @Injectable({
|
|
2095
|
+
* token: ForbiddenResponderToken,
|
|
2096
|
+
* priority: 0, // Higher than default -10
|
|
2097
|
+
* })
|
|
2098
|
+
* export class CustomForbiddenResponder implements ErrorResponder {
|
|
2099
|
+
* getResponse(error: unknown, description?: string): ErrorResponse {
|
|
2100
|
+
* // Custom implementation
|
|
2101
|
+
* }
|
|
2102
|
+
* }
|
|
2103
|
+
* ```
|
|
2104
|
+
*/
|
|
2105
|
+
declare const ForbiddenResponderToken: InjectionToken<ErrorResponder, undefined, false>;
|
|
2106
|
+
//#endregion
|
|
1663
2107
|
//#region src/services/instance-resolver.service.d.mts
|
|
1664
2108
|
/**
|
|
1665
2109
|
* Result of instance resolution attempt.
|
|
@@ -1769,6 +2213,7 @@ type ControllerResolution<T = any> = InstanceResolution<T>;
|
|
|
1769
2213
|
//#endregion
|
|
1770
2214
|
//#region src/services/guard-runner.service.d.mts
|
|
1771
2215
|
declare class GuardRunnerService {
|
|
2216
|
+
private readonly errorProducer;
|
|
1772
2217
|
private readonly logger;
|
|
1773
2218
|
/**
|
|
1774
2219
|
* Runs guards that need to be resolved from a scoped container.
|
|
@@ -2373,5 +2818,5 @@ declare class NaviosFactory {
|
|
|
2373
2818
|
private static registerLoggerConfiguration;
|
|
2374
2819
|
}
|
|
2375
2820
|
//#endregion
|
|
2376
|
-
export {
|
|
2377
|
-
//# sourceMappingURL=index-
|
|
2821
|
+
export { HttpException as $, yellow as $t, ControllerResolverService as A, ConfigServiceToken as An, LoggerInstance as At, InternalServerErrorResponderService as B, isObject as Bt, EndpointAdapterToken as C, ControllerOptions as Cn, AbstractHttpAdapterInterface as Ct, setRequestIdEnabled as D, ConfigService as Dn, LoggerOptions as Dt, runWithRequestId as E, provideConfig as En, Logger as Et, InternalServerErrorResponderToken as F, PathValue as Fn, isConstructor as Ft, ProblemDetails as G, normalizePath as Gt, ErrorResponseProducerService as H, isString as Ht, NotFoundResponderToken as I, envInt as In, isEmpty as It, UnauthorizedException as J, isLogLevel as Jt, FrameworkError as K, stripEndSlash as Kt, ValidationErrorResponderToken as L, envString as Ln, isFunction as Lt, InstanceResolverService as M, Path as Mn, ConsoleLoggerOptions as Mt, MultiInstanceResolution as N, PathImpl as Nn, LoggerService as Nt, GuardRunnerService as O, ConfigServiceOptions as On, LoggerOutput as Ot, ForbiddenResponderToken as P, PathImpl2 as Pn, addLeadingSlash as Pt, BadRequestException as Q, clc as Qt, ValidationErrorResponderService as R, isNil as Rt, ExecutionContextInjectionToken as S, Controller as Sn, StaticHandler as St, getRequestId as T, EnvConfigProvider as Tn, AbstractHttpCorsOptions as Tt, ErrorResponder as U, isSymbol as Ut, ForbiddenResponderService as V, isPlainObject as Vt, ErrorResponse as W, isUndefined as Wt, InternalServerErrorException as X, LOG_LEVELS as Xt, NotFoundException as Y, filterLogLevels as Yt, ForbiddenException as Z, LogLevel as Zt, NaviosApplication as _, getAllEndpointMetadata as _n, OmitIndexSignature as _t, RequestFactory as a, ModuleMetadata as an, MultipartResult as at, HttpAdapterToken as b, EndpointParams as bn, DynamicHandler as bt, EndpointAdapterFactory as c, getModuleMetadata as cn, HttpCode as ct, ClassSchemaAttribute as d, ControllerMetadataKey as dn, PluginContext as dt, AbstractExecutionContext as en, UseGuards as et, XmlStreamAdapterToken as f, extractControllerMetadata as fn, PluginDefinition as ft, NaviosOptionsToken as g, HandlerMetadata as gn, HttpHeader as gt, Reply as h, EndpointMetadataKey as hn, NaviosModule as ht, ReplyFactory as i, hasManagedMetadata as in, MultipartParams as it, InstanceResolution as j, ConfigServiceInterface as jn, ConsoleLogger as jt, ControllerResolution as k, ConfigServiceOptionsSchema as kn, loggerOptionsSchema as kt, AttributeFactory as l, hasModuleMetadata as ln, Header as lt, Request as m, hasControllerMetadata as mn, ModuleLoaderService as mt, XmlStreamAdapterFactory as n, NaviosManagedMetadataKey as nn, StreamParams as nt, MultipartAdapterFactory as o, ModuleMetadataKey as on, Module as ot, StreamAdapterToken as p, getControllerMetadata as pn, ModuleExtension as pt, ConflictException as q, isLogLevelEnabled as qt, StreamAdapterFactory as r, getManagedMetadata as rn, Multipart as rt, HttpAdapterFactory as s, extractModuleMetadata as sn, ModuleOptions as st, NaviosFactory as t, ManagedMetadata as tn, Stream as tt, ClassAttribute as u, ControllerMetadata as un, NaviosPlugin as ut, NaviosApplicationOptions as v, getEndpointMetadata as vn, CanActivate as vt, generateRequestId as w, ConfigProviderOptions as wn, AbstractHttpListenOptions as wt, ExecutionContext as x, EndpointResult as xn, HandlerResult as xt, MultipartAdapterToken as y, Endpoint as yn, AbstractHttpHandlerAdapterInterface as yt, NotFoundResponderService as z, isNumber as zt };
|
|
2822
|
+
//# sourceMappingURL=index-BJjk2X1S.d.mts.map
|