@macss/modular-api 0.7.0 → 0.7.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/README.md CHANGED
@@ -42,6 +42,25 @@ curl -X POST http://localhost:8080/api/greetings/hello \
42
42
 
43
43
  See `example/example.ts` for the full implementation including Input, Output, UseCase with `validate()`, and the builder.
44
44
 
45
+ ### JSON body limit
46
+
47
+ Set `jsonBodyLimit` in `ModularApiOptions` to configure the JSON parser installed by
48
+ `serve()`. It accepts a size string such as `'1mb'` or a number of bytes:
49
+
50
+ ```ts
51
+ const api = new ModularApi({
52
+ basePath: '/api',
53
+ jsonBodyLimit: '1mb', // Equivalent to 1_048_576 bytes.
54
+ });
55
+ api.module('greetings', buildGreetingsModule);
56
+ await api.serve({ port: 8080 });
57
+ ```
58
+
59
+ Omitting the option or passing `undefined` keeps the default `'100kb'` (102,400
60
+ bytes). The limit measures UTF-8 body bytes, applies only to bodies handled by the
61
+ JSON parser, and is independent for each `ModularApi` instance. Oversized bodies
62
+ keep the existing error response.
63
+
45
64
  ---
46
65
 
47
66
  ## Features
@@ -9,6 +9,11 @@ import type { GraphqlOptions } from '../graphql/runtime/graphql_runtime_options'
9
9
  export interface ModularApiOptions {
10
10
  /** Base path prefix for all module routes. Default: '/api' */
11
11
  basePath?: string;
12
+ /**
13
+ * Maximum JSON request body size. Number in bytes or a size string (e.g. '1mb').
14
+ * Default: '100kb' (102400 bytes), matching Express/body-parser.
15
+ */
16
+ jsonBodyLimit?: string | number;
12
17
  /** API title shown in Swagger UI. Default: 'API' */
13
18
  title?: string;
14
19
  /** API version string (e.g. '1.0.0'). Used in health check response. Default: '0.0.0' */
@@ -71,6 +76,7 @@ export declare class ModularApi {
71
76
  private readonly app;
72
77
  private readonly rootRouter;
73
78
  private readonly basePath;
79
+ private readonly jsonBodyLimit;
74
80
  private readonly title;
75
81
  private readonly version;
76
82
  private readonly middlewares;
@@ -47,6 +47,7 @@ class ModularApi {
47
47
  app;
48
48
  rootRouter;
49
49
  basePath;
50
+ jsonBodyLimit;
50
51
  title;
51
52
  version;
52
53
  middlewares = [];
@@ -74,6 +75,7 @@ class ModularApi {
74
75
  }
75
76
  constructor(options = {}) {
76
77
  this.basePath = options.basePath ?? '/api';
78
+ this.jsonBodyLimit = options.jsonBodyLimit ?? '100kb';
77
79
  this.title = options.title ?? 'Modular API';
78
80
  this.version = options.version ?? 'x.y.z';
79
81
  this.healthService = new health_service_1.HealthService({
@@ -279,7 +281,7 @@ class ModularApi {
279
281
  : { traceFieldFormatter: this.tracing.traceFieldFormatter }),
280
282
  }));
281
283
  // Body parsing AFTER loggingMiddleware — SyntaxErrors now have trace_id.
282
- this.app.use(express_1.default.json());
284
+ this.app.use(express_1.default.json({ limit: this.jsonBodyLimit }));
283
285
  this.app.use(body_parser_error_handler_1.bodyParserErrorHandler);
284
286
  pluginHost.applyMiddlewares('preRouting', this.app);
285
287
  // Register middlewares before routes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@macss/modular-api",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Use-case-centric toolkit for building modular APIs with Express. Define UseCase classes (input \u2192 validate \u2192 execute \u2192 output), connect them to HTTP routes, and expose Swagger/OpenAPI documentation automatically.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",