nural 0.3.8 → 0.3.10

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/dist/index.cjs CHANGED
@@ -4,11 +4,13 @@
4
4
  var zodToOpenapi = require('@asteasolutions/zod-to-openapi');
5
5
  var zod = require('zod');
6
6
  var express = require('express');
7
+ var http = require('http');
7
8
  var Fastify = require('fastify');
8
9
 
9
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
11
 
11
12
  var express__default = /*#__PURE__*/_interopDefault(express);
13
+ var http__default = /*#__PURE__*/_interopDefault(http);
12
14
  var Fastify__default = /*#__PURE__*/_interopDefault(Fastify);
13
15
 
14
16
  // src/core/exceptions.ts
@@ -238,10 +240,11 @@ var ExpressAdapter = class {
238
240
  constructor(errorConfig) {
239
241
  this.app = express__default.default();
240
242
  this.app.use(express__default.default.json());
243
+ this.server = http__default.default.createServer(this.app);
241
244
  this.errorConfig = errorConfig ?? DEFAULT_ERROR_HANDLER_CONFIG;
242
245
  }
243
246
  listen(port, cb) {
244
- this.app.listen(port, cb);
247
+ return this.server.listen(port, cb);
245
248
  }
246
249
  use(middleware) {
247
250
  this.app.use(middleware);
@@ -360,6 +363,9 @@ var ExpressAdapter = class {
360
363
  }
361
364
  };
362
365
  var FastifyAdapter = class {
366
+ get server() {
367
+ return this.app.server;
368
+ }
363
369
  constructor(errorConfig) {
364
370
  this.app = Fastify__default.default();
365
371
  this.errorConfig = errorConfig ?? DEFAULT_ERROR_HANDLER_CONFIG;
@@ -372,6 +378,7 @@ var FastifyAdapter = class {
372
378
  }
373
379
  if (cb) cb();
374
380
  });
381
+ return this.app.server;
375
382
  }
376
383
  use(middleware) {
377
384
  if (typeof middleware === "function") {
@@ -485,118 +492,6 @@ var FastifyAdapter = class {
485
492
  });
486
493
  }
487
494
  };
488
-
489
- // src/types/config.ts
490
- var DEFAULT_DOCS_CONFIG = {
491
- enabled: true,
492
- path: "/docs",
493
- ui: "scalar",
494
- openApi: {
495
- info: {
496
- title: "Nural API",
497
- version: "1.0.0",
498
- description: "Powered by Nural Framework"
499
- },
500
- servers: [{ url: "/" }]
501
- },
502
- scalar: {},
503
- swagger: {}
504
- };
505
- function resolveDocsConfig(docs) {
506
- if (docs === false) {
507
- return { ...DEFAULT_DOCS_CONFIG, enabled: false };
508
- }
509
- if (docs === true || docs === void 0) {
510
- return DEFAULT_DOCS_CONFIG;
511
- }
512
- return {
513
- enabled: docs.enabled ?? true,
514
- path: docs.path ?? DEFAULT_DOCS_CONFIG.path,
515
- ui: docs.ui ?? DEFAULT_DOCS_CONFIG.ui,
516
- openApi: {
517
- ...DEFAULT_DOCS_CONFIG.openApi,
518
- ...docs.openApi,
519
- info: {
520
- ...DEFAULT_DOCS_CONFIG.openApi.info,
521
- ...docs.openApi?.info,
522
- // Backward compatibility: use top-level fields if provided
523
- title: docs.title ?? docs.openApi?.info?.title ?? DEFAULT_DOCS_CONFIG.openApi.info?.title,
524
- version: docs.version ?? docs.openApi?.info?.version ?? DEFAULT_DOCS_CONFIG.openApi.info?.version,
525
- description: docs.description ?? docs.openApi?.info?.description ?? DEFAULT_DOCS_CONFIG.openApi.info?.description
526
- }
527
- },
528
- scalar: docs.scalar ?? {},
529
- swagger: docs.swagger ?? {}
530
- };
531
- }
532
-
533
- // src/types/middleware.ts
534
- var DEFAULT_CORS_CONFIG = {
535
- origin: "*",
536
- methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
537
- allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
538
- exposedHeaders: [],
539
- credentials: false,
540
- maxAge: 86400,
541
- // 24 hours
542
- preflightContinue: false,
543
- optionsSuccessStatus: 204
544
- };
545
- var DEFAULT_HELMET_CONFIG = {
546
- contentSecurityPolicy: false,
547
- // Disabled by default (can break apps)
548
- crossOriginEmbedderPolicy: false,
549
- crossOriginOpenerPolicy: { policy: "same-origin" },
550
- crossOriginResourcePolicy: { policy: "same-origin" },
551
- dnsPrefetchControl: { allow: false },
552
- frameguard: { action: "sameorigin" },
553
- hsts: { maxAge: 15552e3, includeSubDomains: true, preload: false },
554
- // 180 days
555
- noSniff: true,
556
- permittedCrossDomainPolicies: { policy: "none" },
557
- referrerPolicy: { policy: "no-referrer" },
558
- xssFilter: false
559
- // Deprecated, browsers ignore it
560
- };
561
- function resolveCorsConfig(cors) {
562
- if (cors === false || cors === void 0) {
563
- return null;
564
- }
565
- if (cors === true) {
566
- return DEFAULT_CORS_CONFIG;
567
- }
568
- return {
569
- origin: cors.origin ?? DEFAULT_CORS_CONFIG.origin,
570
- methods: cors.methods ?? DEFAULT_CORS_CONFIG.methods,
571
- allowedHeaders: cors.allowedHeaders ?? DEFAULT_CORS_CONFIG.allowedHeaders,
572
- exposedHeaders: cors.exposedHeaders ?? DEFAULT_CORS_CONFIG.exposedHeaders,
573
- credentials: cors.credentials ?? DEFAULT_CORS_CONFIG.credentials,
574
- maxAge: cors.maxAge ?? DEFAULT_CORS_CONFIG.maxAge,
575
- preflightContinue: cors.preflightContinue ?? DEFAULT_CORS_CONFIG.preflightContinue,
576
- optionsSuccessStatus: cors.optionsSuccessStatus ?? DEFAULT_CORS_CONFIG.optionsSuccessStatus
577
- };
578
- }
579
- function resolveHelmetConfig(helmet) {
580
- if (helmet === false || helmet === void 0) {
581
- return null;
582
- }
583
- if (helmet === true) {
584
- return DEFAULT_HELMET_CONFIG;
585
- }
586
- return {
587
- contentSecurityPolicy: typeof helmet.contentSecurityPolicy === "object" ? { directives: helmet.contentSecurityPolicy.directives ?? {} } : helmet.contentSecurityPolicy ?? DEFAULT_HELMET_CONFIG.contentSecurityPolicy,
588
- crossOriginEmbedderPolicy: helmet.crossOriginEmbedderPolicy ?? DEFAULT_HELMET_CONFIG.crossOriginEmbedderPolicy,
589
- crossOriginOpenerPolicy: typeof helmet.crossOriginOpenerPolicy === "object" ? helmet.crossOriginOpenerPolicy : DEFAULT_HELMET_CONFIG.crossOriginOpenerPolicy,
590
- crossOriginResourcePolicy: typeof helmet.crossOriginResourcePolicy === "object" ? helmet.crossOriginResourcePolicy : DEFAULT_HELMET_CONFIG.crossOriginResourcePolicy,
591
- dnsPrefetchControl: typeof helmet.dnsPrefetchControl === "object" ? helmet.dnsPrefetchControl : DEFAULT_HELMET_CONFIG.dnsPrefetchControl,
592
- frameguard: typeof helmet.frameguard === "object" ? helmet.frameguard : DEFAULT_HELMET_CONFIG.frameguard,
593
- hsts: typeof helmet.hsts === "object" ? { ...DEFAULT_HELMET_CONFIG.hsts, ...helmet.hsts } : DEFAULT_HELMET_CONFIG.hsts,
594
- noSniff: helmet.noSniff ?? DEFAULT_HELMET_CONFIG.noSniff,
595
- permittedCrossDomainPolicies: typeof helmet.permittedCrossDomainPolicies === "object" ? helmet.permittedCrossDomainPolicies : DEFAULT_HELMET_CONFIG.permittedCrossDomainPolicies,
596
- referrerPolicy: typeof helmet.referrerPolicy === "object" ? helmet.referrerPolicy : DEFAULT_HELMET_CONFIG.referrerPolicy,
597
- xssFilter: helmet.xssFilter ?? DEFAULT_HELMET_CONFIG.xssFilter
598
- };
599
- }
600
495
  var DocumentationGenerator = class {
601
496
  constructor(config) {
602
497
  this.registry = new zodToOpenapi.OpenAPIRegistry();
@@ -987,6 +882,118 @@ var httpLogger = (options = {}) => {
987
882
  };
988
883
  };
989
884
 
885
+ // src/types/config.ts
886
+ var DEFAULT_DOCS_CONFIG = {
887
+ enabled: true,
888
+ path: "/docs",
889
+ ui: "scalar",
890
+ openApi: {
891
+ info: {
892
+ title: "Nural API",
893
+ version: "1.0.0",
894
+ description: "Powered by Nural Framework"
895
+ },
896
+ servers: [{ url: "/" }]
897
+ },
898
+ scalar: {},
899
+ swagger: {}
900
+ };
901
+ function resolveDocsConfig(docs) {
902
+ if (docs === false) {
903
+ return { ...DEFAULT_DOCS_CONFIG, enabled: false };
904
+ }
905
+ if (docs === true || docs === void 0) {
906
+ return DEFAULT_DOCS_CONFIG;
907
+ }
908
+ return {
909
+ enabled: docs.enabled ?? true,
910
+ path: docs.path ?? DEFAULT_DOCS_CONFIG.path,
911
+ ui: docs.ui ?? DEFAULT_DOCS_CONFIG.ui,
912
+ openApi: {
913
+ ...DEFAULT_DOCS_CONFIG.openApi,
914
+ ...docs.openApi,
915
+ info: {
916
+ ...DEFAULT_DOCS_CONFIG.openApi.info,
917
+ ...docs.openApi?.info,
918
+ // Backward compatibility: use top-level fields if provided
919
+ title: docs.title ?? docs.openApi?.info?.title ?? DEFAULT_DOCS_CONFIG.openApi.info?.title,
920
+ version: docs.version ?? docs.openApi?.info?.version ?? DEFAULT_DOCS_CONFIG.openApi.info?.version,
921
+ description: docs.description ?? docs.openApi?.info?.description ?? DEFAULT_DOCS_CONFIG.openApi.info?.description
922
+ }
923
+ },
924
+ scalar: docs.scalar ?? {},
925
+ swagger: docs.swagger ?? {}
926
+ };
927
+ }
928
+
929
+ // src/types/middleware.ts
930
+ var DEFAULT_CORS_CONFIG = {
931
+ origin: "*",
932
+ methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
933
+ allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"],
934
+ exposedHeaders: [],
935
+ credentials: false,
936
+ maxAge: 86400,
937
+ // 24 hours
938
+ preflightContinue: false,
939
+ optionsSuccessStatus: 204
940
+ };
941
+ var DEFAULT_HELMET_CONFIG = {
942
+ contentSecurityPolicy: false,
943
+ // Disabled by default (can break apps)
944
+ crossOriginEmbedderPolicy: false,
945
+ crossOriginOpenerPolicy: { policy: "same-origin" },
946
+ crossOriginResourcePolicy: { policy: "same-origin" },
947
+ dnsPrefetchControl: { allow: false },
948
+ frameguard: { action: "sameorigin" },
949
+ hsts: { maxAge: 15552e3, includeSubDomains: true, preload: false },
950
+ // 180 days
951
+ noSniff: true,
952
+ permittedCrossDomainPolicies: { policy: "none" },
953
+ referrerPolicy: { policy: "no-referrer" },
954
+ xssFilter: false
955
+ // Deprecated, browsers ignore it
956
+ };
957
+ function resolveCorsConfig(cors) {
958
+ if (cors === false || cors === void 0) {
959
+ return null;
960
+ }
961
+ if (cors === true) {
962
+ return DEFAULT_CORS_CONFIG;
963
+ }
964
+ return {
965
+ origin: cors.origin ?? DEFAULT_CORS_CONFIG.origin,
966
+ methods: cors.methods ?? DEFAULT_CORS_CONFIG.methods,
967
+ allowedHeaders: cors.allowedHeaders ?? DEFAULT_CORS_CONFIG.allowedHeaders,
968
+ exposedHeaders: cors.exposedHeaders ?? DEFAULT_CORS_CONFIG.exposedHeaders,
969
+ credentials: cors.credentials ?? DEFAULT_CORS_CONFIG.credentials,
970
+ maxAge: cors.maxAge ?? DEFAULT_CORS_CONFIG.maxAge,
971
+ preflightContinue: cors.preflightContinue ?? DEFAULT_CORS_CONFIG.preflightContinue,
972
+ optionsSuccessStatus: cors.optionsSuccessStatus ?? DEFAULT_CORS_CONFIG.optionsSuccessStatus
973
+ };
974
+ }
975
+ function resolveHelmetConfig(helmet) {
976
+ if (helmet === false || helmet === void 0) {
977
+ return null;
978
+ }
979
+ if (helmet === true) {
980
+ return DEFAULT_HELMET_CONFIG;
981
+ }
982
+ return {
983
+ contentSecurityPolicy: typeof helmet.contentSecurityPolicy === "object" ? { directives: helmet.contentSecurityPolicy.directives ?? {} } : helmet.contentSecurityPolicy ?? DEFAULT_HELMET_CONFIG.contentSecurityPolicy,
984
+ crossOriginEmbedderPolicy: helmet.crossOriginEmbedderPolicy ?? DEFAULT_HELMET_CONFIG.crossOriginEmbedderPolicy,
985
+ crossOriginOpenerPolicy: typeof helmet.crossOriginOpenerPolicy === "object" ? helmet.crossOriginOpenerPolicy : DEFAULT_HELMET_CONFIG.crossOriginOpenerPolicy,
986
+ crossOriginResourcePolicy: typeof helmet.crossOriginResourcePolicy === "object" ? helmet.crossOriginResourcePolicy : DEFAULT_HELMET_CONFIG.crossOriginResourcePolicy,
987
+ dnsPrefetchControl: typeof helmet.dnsPrefetchControl === "object" ? helmet.dnsPrefetchControl : DEFAULT_HELMET_CONFIG.dnsPrefetchControl,
988
+ frameguard: typeof helmet.frameguard === "object" ? helmet.frameguard : DEFAULT_HELMET_CONFIG.frameguard,
989
+ hsts: typeof helmet.hsts === "object" ? { ...DEFAULT_HELMET_CONFIG.hsts, ...helmet.hsts } : DEFAULT_HELMET_CONFIG.hsts,
990
+ noSniff: helmet.noSniff ?? DEFAULT_HELMET_CONFIG.noSniff,
991
+ permittedCrossDomainPolicies: typeof helmet.permittedCrossDomainPolicies === "object" ? helmet.permittedCrossDomainPolicies : DEFAULT_HELMET_CONFIG.permittedCrossDomainPolicies,
992
+ referrerPolicy: typeof helmet.referrerPolicy === "object" ? helmet.referrerPolicy : DEFAULT_HELMET_CONFIG.referrerPolicy,
993
+ xssFilter: helmet.xssFilter ?? DEFAULT_HELMET_CONFIG.xssFilter
994
+ };
995
+ }
996
+
990
997
  // src/core/nural.ts
991
998
  var Nural = class {
992
999
  constructor(config = {}) {
@@ -1012,6 +1019,9 @@ var Nural = class {
1012
1019
  }
1013
1020
  this.applyBuiltInMiddleware();
1014
1021
  }
1022
+ get server() {
1023
+ return this.adapter.server;
1024
+ }
1015
1025
  /**
1016
1026
  * Apply CORS and Helmet middleware based on config
1017
1027
  */
@@ -1051,7 +1061,7 @@ var Nural = class {
1051
1061
  if (this.docsConfig.enabled) {
1052
1062
  this.setupDocs();
1053
1063
  }
1054
- this.adapter.listen(port, () => {
1064
+ return this.adapter.listen(port, () => {
1055
1065
  console.log(`\u{1F680} Nural Server running on port ${port}`);
1056
1066
  if (this.docsConfig.enabled) {
1057
1067
  console.log(