@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.
Files changed (67) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +4 -2
  3. package/docs/README.md +3 -1
  4. package/docs/exceptions.md +37 -1
  5. package/lib/{index-B2ulzZIr.d.cts → index-BJjk2X1S.d.mts} +478 -33
  6. package/lib/index-BJjk2X1S.d.mts.map +1 -0
  7. package/lib/{index-C8lUQePd.d.mts → index-DZ6NU03y.d.cts} +478 -33
  8. package/lib/index-DZ6NU03y.d.cts.map +1 -0
  9. package/lib/index.cjs +37 -2
  10. package/lib/index.d.cts +2 -2
  11. package/lib/index.d.mts +2 -2
  12. package/lib/index.mjs +3 -3
  13. package/lib/legacy-compat/index.cjs +8 -6
  14. package/lib/legacy-compat/index.cjs.map +1 -1
  15. package/lib/legacy-compat/index.d.cts +11 -16
  16. package/lib/legacy-compat/index.d.cts.map +1 -1
  17. package/lib/legacy-compat/index.d.mts +11 -16
  18. package/lib/legacy-compat/index.d.mts.map +1 -1
  19. package/lib/legacy-compat/index.mjs +7 -5
  20. package/lib/legacy-compat/index.mjs.map +1 -1
  21. package/lib/{src-Cu9OAnfp.cjs → src-C46ePe3d.cjs} +1970 -171
  22. package/lib/src-C46ePe3d.cjs.map +1 -0
  23. package/lib/{src-Baabu2R8.mjs → src-K2k0riYJ.mjs} +1941 -202
  24. package/lib/src-K2k0riYJ.mjs.map +1 -0
  25. package/lib/testing/index.cjs +2 -2
  26. package/lib/testing/index.d.cts +1 -1
  27. package/lib/testing/index.d.mts +1 -1
  28. package/lib/testing/index.mjs +2 -2
  29. package/lib/{use-guards.decorator-EvI2m2DK.cjs → use-guards.decorator-B6tghdxM.cjs} +7 -4
  30. package/lib/use-guards.decorator-B6tghdxM.cjs.map +1 -0
  31. package/lib/{use-guards.decorator-ChJVzYLW.mjs → use-guards.decorator-Be_QUx6b.mjs} +6 -3
  32. package/lib/use-guards.decorator-Be_QUx6b.mjs.map +1 -0
  33. package/package.json +3 -3
  34. package/src/__tests__/responders.spec.mts +339 -0
  35. package/src/decorators/endpoint.decorator.mts +49 -97
  36. package/src/decorators/module.decorator.mts +12 -0
  37. package/src/decorators/multipart.decorator.mts +62 -87
  38. package/src/decorators/stream.decorator.mts +66 -76
  39. package/src/index.mts +1 -0
  40. package/src/legacy-compat/__type-tests__/legacy-decorators.spec-d.mts +0 -2
  41. package/src/legacy-compat/decorators/endpoint.decorator.mts +21 -47
  42. package/src/legacy-compat/decorators/multipart.decorator.mts +20 -41
  43. package/src/legacy-compat/decorators/stream.decorator.mts +48 -42
  44. package/src/metadata/module.metadata.mts +2 -0
  45. package/src/responders/enums/framework-error.enum.mts +38 -0
  46. package/src/responders/enums/index.mts +1 -0
  47. package/src/responders/index.mts +4 -0
  48. package/src/responders/interfaces/error-responder.interface.mts +42 -0
  49. package/src/responders/interfaces/error-response.interface.mts +22 -0
  50. package/src/responders/interfaces/index.mts +3 -0
  51. package/src/responders/interfaces/problem-details.interface.mts +34 -0
  52. package/src/responders/services/error-response-producer.service.mts +143 -0
  53. package/src/responders/services/forbidden-responder.service.mts +77 -0
  54. package/src/responders/services/index.mts +5 -0
  55. package/src/responders/services/internal-server-error-responder.service.mts +57 -0
  56. package/src/responders/services/not-found-responder.service.mts +76 -0
  57. package/src/responders/services/validation-error-responder.service.mts +78 -0
  58. package/src/responders/tokens/index.mts +1 -0
  59. package/src/responders/tokens/responder.tokens.mts +84 -0
  60. package/src/services/guard-runner.service.mts +19 -6
  61. package/src/services/module-loader.service.mts +63 -0
  62. package/lib/index-B2ulzZIr.d.cts.map +0 -1
  63. package/lib/index-C8lUQePd.d.mts.map +0 -1
  64. package/lib/src-Baabu2R8.mjs.map +0 -1
  65. package/lib/src-Cu9OAnfp.cjs.map +0 -1
  66. package/lib/use-guards.decorator-ChJVzYLW.mjs.map +0 -1
  67. package/lib/use-guards.decorator-EvI2m2DK.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,64 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.0-alpha.2] - 2026-01-07
9
+
10
+ ### Added
11
+
12
+ - **Module Overrides**: New `overrides` option in `@Module()` decorator for service override classes
13
+ - Service override classes are imported for side effects to ensure their `@Injectable` decorators execute
14
+ - Overrides should use the same `InjectionToken` as the original service with a higher priority
15
+ - `ModuleLoaderService` validates overrides and logs warnings if override is not active or not registered
16
+ - Useful for testing and swapping implementations without modifying original modules
17
+
18
+ ### Changed
19
+
20
+ - **Simplified Endpoint Type Utilities**: Refactored `EndpointParams<T>` type to use new `RequestArgs` type from `@navios/builder`
21
+ - Cleaner type inference with support for `urlParamsSchema`
22
+ - Server-side handlers receive `z.output` types (parsed/transformed values)
23
+ - Client-side receives `z.input` types (raw input values)
24
+ - **Updated Builder Types**: All adapters and decorators now use `EndpointOptions` and `BaseEndpointOptions` from `@navios/builder` instead of legacy `BaseEndpointConfig`
25
+ - **Legacy Decorator Improvements**: Simplified type definitions in legacy-compat decorators for better maintainability
26
+
27
+ ### Dependencies
28
+
29
+ - Updated to support `@navios/builder` ^1.0.0-alpha.2 with new `RequestArgs` type system
30
+
31
+ ## [1.0.0-alpha.1] - 2026-01-22
32
+
33
+ ### Added
34
+
35
+ - **RFC 7807 Problem Details Error Responses**: New standardized error response system using RFC 7807 Problem Details format
36
+ - `ErrorResponseProducerService` - Central service for producing standardized error responses
37
+ - `FrameworkError` enum - Explicit error type specification (NotFound, Forbidden, InternalServerError, ValidationError)
38
+ - Customizable error responders with dependency injection support:
39
+ - `NotFoundResponderService` - Handles 404 Not Found errors
40
+ - `ForbiddenResponderService` - Handles 403 Forbidden errors (used by guards)
41
+ - `InternalServerErrorResponderService` - Handles 500 Internal Server errors
42
+ - `ValidationErrorResponderService` - Handles 400 Validation errors with structured Zod error details
43
+ - All responders registered with low priority (-10) for easy override
44
+ - `ErrorResponder` interface for custom responder implementations
45
+ - `ProblemDetails` interface following RFC 7807 specification
46
+ - `ErrorResponse` interface with status code, payload, and headers
47
+ - **Guard Error Handling Enhancement**: `GuardRunnerService` now uses `ErrorResponseProducerService` for standardized error responses
48
+ - Guard rejections now return RFC 7807 compliant responses
49
+ - Guard execution errors produce standardized internal server error responses
50
+
51
+ ### Changed
52
+
53
+ - **Error Response Format**: Error responses now use RFC 7807 Problem Details format instead of simple JSON
54
+ - Content-Type header set to `application/problem+json`
55
+ - Responses include `type`, `title`, `status`, and `detail` fields
56
+ - Validation errors include structured `errors` field with Zod validation details
57
+ - HttpException responses remain backward compatible (preserved original format)
58
+
59
+ ### Breaking Changes
60
+
61
+ - **Error Response Format**: Non-HttpException errors now return RFC 7807 Problem Details format
62
+ - Previous format: `{ message: "..." }`
63
+ - New format: `{ type: "about:blank", title: "...", status: 404, detail: "..." }`
64
+ - HttpException responses are unchanged for backward compatibility
65
+
8
66
  ## [0.9.3] - 2026-01-05
9
67
 
10
68
  ### Fixed
package/README.md CHANGED
@@ -30,7 +30,7 @@ The adapter must be provided when creating your Navios application to define the
30
30
  - **Build with Navios Builder**: Navios Builder is a powerful HTTP client that simplifies API requests. By combining it with Navios, you can use the same API definition for both the client and server, ensuring consistency and reducing duplication.
31
31
  - **Declarative API**: The API is designed to be declarative, allowing you to define your API endpoints and their schemas in a clear and concise manner. This makes it easy to understand and maintain your API client.
32
32
  - **Customizable**: The package allows you to customize the behavior of the API client, such as using a custom client.
33
- - **Error Handling**: The package provides built-in error handling capabilities, allowing you to handle API errors gracefully and provide meaningful feedback to users.
33
+ - **Error Handling**: The package provides built-in error handling capabilities with RFC 7807 Problem Details format for standardized error responses. Includes customizable error responders and comprehensive exception handling.
34
34
 
35
35
  ## Adapters
36
36
 
@@ -77,7 +77,7 @@ The choice of adapter depends on your deployment environment and performance req
77
77
 
78
78
  ## Main Concepts
79
79
 
80
- - **Module**: A module is a collection of controllers, and other modules. It is used to group related functionality together and provide a clear structure for your API. It also can define some shared guards and attributes.
80
+ - **Module**: A module is a collection of controllers, and other modules. It is used to group related functionality together and provide a clear structure for your API. It also can define some shared guards, attributes, and service overrides.
81
81
  - **Controller**: A controller is a class that defines a set of endpoints for a specific resource. It is used to handle incoming requests and return responses. Controllers can also define guards and attributes that apply to all endpoints in the controller.
82
82
  - **Endpoint**: An endpoint is a specific route in your API that handles a specific request. It used original endpoint definition from Navios Builder, and a set of request and response schemas. Endpoints can also define guards and attributes that apply to the endpoint.
83
83
  - **Service**: A service is a class that defines the business logic for a specific resource. It is used to separate the business logic from the controller and provide a clear structure for your API.
@@ -204,6 +204,8 @@ import { AuthController } from './auth.controller.mjs'
204
204
 
205
205
  @Module({
206
206
  controllers: [AuthController],
207
+ // Optional: overrides for service implementations with higher priority
208
+ // overrides: [OverrideService],
207
209
  })
208
210
  export class AppModule {}
209
211
  ```
package/docs/README.md CHANGED
@@ -200,7 +200,7 @@ Choose the appropriate adapter based on your deployment environment and requirem
200
200
 
201
201
  ## Error Handling
202
202
 
203
- Both adapters provide consistent error handling through Navios's exception system:
203
+ Both adapters provide consistent error handling through Navios's exception system. Framework-level errors (validation errors, guard rejections, not found routes, unhandled errors) use **RFC 7807 Problem Details** format for standardized, machine-readable error responses. HttpException responses maintain backward compatibility with the original format.
204
204
 
205
205
  ```ts
206
206
  import { BadRequestException, NotFoundException } from '@navios/core'
@@ -225,6 +225,8 @@ export class UserController {
225
225
  }
226
226
  ```
227
227
 
228
+ For more information on error handling, including custom error responders and RFC 7807 Problem Details, see the [Error Handling Guide](../../../apps/docs/docs/server/guides/error-handling.md).
229
+
228
230
  ## Configuration
229
231
 
230
232
  Both adapters support the same Navios configuration options:
@@ -168,7 +168,9 @@ export class UserController {
168
168
 
169
169
  ## Exception Response Format
170
170
 
171
- By default, Navios returns exceptions in this format:
171
+ ### HttpException Response Format
172
+
173
+ `HttpException` and its subclasses (like `NotFoundException`, `BadRequestException`, etc.) maintain backward compatibility and return the original format:
172
174
 
173
175
  ```json
174
176
  {
@@ -197,6 +199,40 @@ For exceptions with additional data:
197
199
  }
198
200
  ```
199
201
 
202
+ ### RFC 7807 Problem Details Format
203
+
204
+ Framework-level errors (validation errors, guard rejections, not found routes, unhandled errors) use **RFC 7807 Problem Details** format for standardized, machine-readable error responses:
205
+
206
+ ```json
207
+ {
208
+ "type": "about:blank",
209
+ "title": "Not Found",
210
+ "status": 404,
211
+ "detail": "Route [GET] /api/users/999 not found"
212
+ }
213
+ ```
214
+
215
+ Validation errors include structured error details:
216
+
217
+ ```json
218
+ {
219
+ "type": "about:blank",
220
+ "title": "Validation Error",
221
+ "status": 400,
222
+ "detail": "Request validation failed",
223
+ "errors": {
224
+ "email": {
225
+ "code": "invalid_string",
226
+ "validation": "email",
227
+ "message": "Invalid email",
228
+ "path": ["email"]
229
+ }
230
+ }
231
+ }
232
+ ```
233
+
234
+ All Problem Details responses include the `Content-Type: application/problem+json` header. For more information on customizing error responders, see the [Error Handling Guide](../../../apps/docs/docs/server/guides/error-handling.md).
235
+
200
236
  ## Best Practices
201
237
 
202
238
  ### 1. Use Specific Exceptions