@navios/core 0.1.1 → 0.1.3

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.js CHANGED
@@ -77,6 +77,11 @@ __export(src_exports, {
77
77
  Application: () => Application,
78
78
  AttributeFactory: () => AttributeFactory,
79
79
  BadRequestException: () => BadRequestException,
80
+ ConfigProvider: () => ConfigProvider,
81
+ ConfigProviderFactory: () => ConfigProviderFactory,
82
+ ConfigProviderInjectionToken: () => ConfigProviderInjectionToken,
83
+ ConfigProviderOptions: () => ConfigProviderOptions,
84
+ ConfigServiceInstance: () => ConfigServiceInstance,
80
85
  ConflictException: () => ConflictException,
81
86
  ConsoleLogger: () => ConsoleLogger,
82
87
  Controller: () => Controller,
@@ -84,6 +89,7 @@ __export(src_exports, {
84
89
  ControllerMetadataKey: () => ControllerMetadataKey,
85
90
  Endpoint: () => Endpoint,
86
91
  EndpointMetadataKey: () => EndpointMetadataKey,
92
+ EndpointType: () => EndpointType,
87
93
  ErrorsEnum: () => ErrorsEnum,
88
94
  EventEmitter: () => EventEmitter,
89
95
  ExecutionContext: () => ExecutionContext2,
@@ -92,6 +98,8 @@ __export(src_exports, {
92
98
  FactoryNotFound: () => FactoryNotFound,
93
99
  ForbiddenException: () => ForbiddenException,
94
100
  GuardRunnerService: () => GuardRunnerService,
101
+ Header: () => Header,
102
+ HttpCode: () => HttpCode,
95
103
  HttpException: () => HttpException,
96
104
  Injectable: () => Injectable,
97
105
  InjectableScope: () => InjectableScope,
@@ -127,6 +135,8 @@ __export(src_exports, {
127
135
  UseGuards: () => UseGuards,
128
136
  addLeadingSlash: () => addLeadingSlash,
129
137
  clc: () => clc,
138
+ envInt: () => envInt,
139
+ envString: () => envString,
130
140
  extractControllerMetadata: () => extractControllerMetadata,
131
141
  extractModuleMetadata: () => extractModuleMetadata,
132
142
  filterLogLevels: () => filterLogLevels,
@@ -151,6 +161,7 @@ __export(src_exports, {
151
161
  isString: () => isString,
152
162
  isSymbol: () => isSymbol,
153
163
  isUndefined: () => isUndefined,
164
+ makeConfigToken: () => makeConfigToken,
154
165
  normalizePath: () => normalizePath,
155
166
  override: () => override,
156
167
  provideServiceLocator: () => provideServiceLocator,
@@ -161,115 +172,117 @@ __export(src_exports, {
161
172
  });
162
173
  module.exports = __toCommonJS(src_exports);
163
174
 
164
- // packages/core/src/metadata/endpoint.metadata.mts
165
- var EndpointMetadataKey = Symbol("EndpointMetadataKey");
166
- function getAllEndpointMetadata(context) {
167
- if (context.metadata) {
168
- const metadata = context.metadata[EndpointMetadataKey];
169
- if (metadata) {
170
- return metadata;
171
- } else {
172
- context.metadata[EndpointMetadataKey] = /* @__PURE__ */ new Set();
173
- return context.metadata[EndpointMetadataKey];
174
- }
175
- }
176
- throw new Error("[Navios] Wrong environment.");
175
+ // packages/core/src/config/utils/helpers.mts
176
+ var import_node_process = require("process");
177
+ function envInt(key, defaultValue) {
178
+ const envKey = import_node_process.env[key] || process.env[key];
179
+ return envKey ? parseInt(envKey, 10) : defaultValue;
177
180
  }
178
- function getEndpointMetadata(target, context) {
179
- if (context.metadata) {
180
- const metadata = getAllEndpointMetadata(context);
181
- if (metadata) {
182
- const endpointMetadata = Array.from(metadata).find(
183
- (item) => item.classMethod === target.name
184
- );
185
- if (endpointMetadata) {
186
- return endpointMetadata;
187
- } else {
188
- const newMetadata = {
189
- classMethod: target.name,
190
- url: "",
191
- httpMethod: "GET",
192
- config: null,
193
- guards: /* @__PURE__ */ new Set(),
194
- customAttributes: /* @__PURE__ */ new Map()
195
- };
196
- metadata.add(newMetadata);
197
- return newMetadata;
198
- }
199
- }
200
- }
201
- throw new Error("[Navios] Wrong environment.");
181
+ function envString(key, defaultValue) {
182
+ return import_node_process.env[key] || process.env[key] || defaultValue || void 0;
202
183
  }
203
184
 
204
- // packages/core/src/metadata/controller.metadata.mts
205
- var ControllerMetadataKey = Symbol("ControllerMetadataKey");
206
- function getControllerMetadata(target, context) {
207
- if (context.metadata) {
208
- const metadata = context.metadata[ControllerMetadataKey];
209
- if (metadata) {
210
- return metadata;
211
- } else {
212
- const endpointsMetadata = getAllEndpointMetadata(context);
213
- const newMetadata = {
214
- endpoints: endpointsMetadata,
215
- guards: /* @__PURE__ */ new Set(),
216
- customAttributes: /* @__PURE__ */ new Map()
217
- };
218
- context.metadata[ControllerMetadataKey] = newMetadata;
219
- target[ControllerMetadataKey] = newMetadata;
220
- return newMetadata;
221
- }
222
- }
223
- throw new Error("[Navios] Wrong environment.");
185
+ // packages/core/src/config/config.provider.mts
186
+ var import_zod3 = require("zod");
187
+
188
+ // packages/core/src/logger/utils/cli-colors.util.mts
189
+ var isColorAllowed = () => !process.env.NO_COLOR;
190
+ var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
191
+ var clc = {
192
+ bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
193
+ green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
194
+ yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
195
+ red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
196
+ magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
197
+ cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
198
+ };
199
+ var yellow = colorIfAllowed(
200
+ (text) => `\x1B[38;5;3m${text}\x1B[39m`
201
+ );
202
+
203
+ // packages/core/src/logger/log-levels.mts
204
+ var LOG_LEVELS = [
205
+ "verbose",
206
+ "debug",
207
+ "log",
208
+ "warn",
209
+ "error",
210
+ "fatal"
211
+ ];
212
+
213
+ // packages/core/src/logger/utils/is-log-level.util.mts
214
+ function isLogLevel(maybeLogLevel) {
215
+ return LOG_LEVELS.includes(maybeLogLevel);
224
216
  }
225
- function extractControllerMetadata(target) {
226
- const metadata = target[ControllerMetadataKey];
227
- if (!metadata) {
228
- throw new Error(
229
- "[Navios] Controller metadata not found. Make sure to use @Controller decorator."
217
+
218
+ // packages/core/src/logger/utils/filter-log-levelts.util.mts
219
+ function filterLogLevels(parseableString = "") {
220
+ const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
221
+ if (sanitizedString[0] === ">") {
222
+ const orEqual = sanitizedString[1] === "=";
223
+ const logLevelIndex = LOG_LEVELS.indexOf(
224
+ sanitizedString.substring(orEqual ? 2 : 1)
230
225
  );
226
+ if (logLevelIndex === -1) {
227
+ throw new Error(`parse error (unknown log level): ${sanitizedString}`);
228
+ }
229
+ return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
230
+ } else if (sanitizedString.includes(",")) {
231
+ return sanitizedString.split(",").filter(isLogLevel);
231
232
  }
232
- return metadata;
233
- }
234
- function hasControllerMetadata(target) {
235
- const metadata = target[ControllerMetadataKey];
236
- return !!metadata;
233
+ return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
237
234
  }
238
235
 
239
- // packages/core/src/metadata/module.metadata.mts
240
- var ModuleMetadataKey = Symbol("ControllerMetadataKey");
241
- function getModuleMetadata(target, context) {
242
- if (context.metadata) {
243
- const metadata = context.metadata[ModuleMetadataKey];
244
- if (metadata) {
245
- return metadata;
246
- } else {
247
- const newMetadata = {
248
- controllers: /* @__PURE__ */ new Set(),
249
- imports: /* @__PURE__ */ new Set(),
250
- guards: /* @__PURE__ */ new Set(),
251
- customAttributes: /* @__PURE__ */ new Map()
252
- };
253
- context.metadata[ModuleMetadataKey] = newMetadata;
254
- target[ModuleMetadataKey] = newMetadata;
255
- return newMetadata;
256
- }
236
+ // packages/core/src/logger/utils/is-log-level-enabled.mts
237
+ var LOG_LEVEL_VALUES = {
238
+ verbose: 0,
239
+ debug: 1,
240
+ log: 2,
241
+ warn: 3,
242
+ error: 4,
243
+ fatal: 5
244
+ };
245
+ function isLogLevelEnabled(targetLevel, logLevels) {
246
+ var _a;
247
+ if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
248
+ return false;
257
249
  }
258
- throw new Error("[Navios] Wrong environment.");
259
- }
260
- function extractModuleMetadata(target) {
261
- const metadata = target[ModuleMetadataKey];
262
- if (!metadata) {
263
- throw new Error(
264
- "[Navios] Module metadata not found. Make sure to use @Module decorator."
265
- );
250
+ if (logLevels.includes(targetLevel)) {
251
+ return true;
266
252
  }
267
- return metadata;
268
- }
269
- function hasModuleMetadata(target) {
270
- return !!target[ModuleMetadataKey];
253
+ const highestLogLevelValue = (_a = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a[0];
254
+ const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
255
+ return targetLevelValue >= highestLogLevelValue;
271
256
  }
272
257
 
258
+ // packages/core/src/logger/utils/shared.utils.mts
259
+ var isUndefined = (obj) => typeof obj === "undefined";
260
+ var isObject = (fn) => !isNil(fn) && typeof fn === "object";
261
+ var isPlainObject = (fn) => {
262
+ if (!isObject(fn)) {
263
+ return false;
264
+ }
265
+ const proto = Object.getPrototypeOf(fn);
266
+ if (proto === null) {
267
+ return true;
268
+ }
269
+ const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
270
+ return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
271
+ };
272
+ var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
273
+ var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
274
+ var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
275
+ var isFunction = (val) => typeof val === "function";
276
+ var isString = (val) => typeof val === "string";
277
+ var isNumber = (val) => typeof val === "number";
278
+ var isConstructor = (val) => val === "constructor";
279
+ var isNil = (val) => isUndefined(val) || val === null;
280
+ var isEmpty = (array) => !(array && array.length > 0);
281
+ var isSymbol = (val) => typeof val === "symbol";
282
+
283
+ // packages/core/src/logger/console-logger.service.mts
284
+ var import_util = require("util");
285
+
273
286
  // packages/core/src/service-locator/enums/injectable-scope.enum.mts
274
287
  var InjectableScope = /* @__PURE__ */ ((InjectableScope2) => {
275
288
  InjectableScope2["Singleton"] = "Singleton";
@@ -828,7 +841,15 @@ var ServiceLocator = class {
828
841
  ).then(() => null);
829
842
  }
830
843
  makeInstanceName(token, args) {
831
- let stringifiedArgs = args ? ":" + JSON.stringify(args).replaceAll(/"/g, "").replaceAll(/:/g, "=").replaceAll(/,/g, "|") : "";
844
+ let stringifiedArgs = args ? ":" + JSON.stringify(args, (_, value) => {
845
+ if (typeof value === "function") {
846
+ return `function:${value.name}(${value.length})`;
847
+ }
848
+ if (typeof value === "symbol") {
849
+ return value.toString();
850
+ }
851
+ return value;
852
+ }).replaceAll(/"/g, "").replaceAll(/:/g, "=").replaceAll(/,/g, "|") : "";
832
853
  const { name: name2 } = token;
833
854
  if (typeof name2 === "function") {
834
855
  const className = name2.name;
@@ -1104,318 +1125,58 @@ function override(token, target) {
1104
1125
  };
1105
1126
  }
1106
1127
 
1107
- // packages/core/src/decorators/controller.decorator.mts
1108
- function Controller({ guards } = {}) {
1109
- return function(target, context) {
1110
- if (context.kind !== "class") {
1111
- throw new Error(
1112
- "[Navios] @Controller decorator can only be used on classes."
1113
- );
1114
- }
1115
- const token = InjectionToken.create(target);
1116
- if (context.metadata) {
1117
- const controllerMetadata = getControllerMetadata(target, context);
1118
- if (guards) {
1119
- for (const guard of Array.from(guards).reverse()) {
1120
- controllerMetadata.guards.add(guard);
1121
- }
1122
- }
1123
- }
1124
- return Injectable({
1125
- token,
1126
- type: "Class" /* Class */,
1127
- scope: "Instance" /* Instance */
1128
- })(target, context);
1129
- };
1130
- }
1131
-
1132
- // packages/core/src/decorators/endpoint.decorator.mts
1133
- function Endpoint(endpoint) {
1134
- return (target, context) => {
1135
- if (typeof target !== "function") {
1136
- throw new Error(
1137
- "[Navios] Endpoint decorator can only be used on functions."
1138
- );
1139
- }
1140
- if (context.kind !== "method") {
1141
- throw new Error(
1142
- "[Navios] Endpoint decorator can only be used on methods."
1143
- );
1144
- }
1145
- const config = endpoint.config;
1146
- if (context.metadata) {
1147
- let endpointMetadata = getEndpointMetadata(target, context);
1148
- if (endpointMetadata.config && endpointMetadata.config.url) {
1149
- throw new Error(
1150
- `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
1151
- );
1152
- }
1153
- endpointMetadata.config = config;
1154
- endpointMetadata.classMethod = target.name;
1155
- endpointMetadata.httpMethod = config.method;
1156
- endpointMetadata.url = config.url;
1157
- }
1158
- return target;
1159
- };
1160
- }
1161
-
1162
- // packages/core/src/decorators/module.decorator.mts
1163
- function Module(metadata) {
1164
- return (target, context) => {
1165
- if (context.kind !== "class") {
1166
- throw new Error("[Navios] @Module decorator can only be used on classes.");
1167
- }
1168
- const token = InjectionToken.create(target);
1169
- const moduleMetadata = getModuleMetadata(target, context);
1170
- if (metadata.controllers) {
1171
- for (const controller of metadata.controllers) {
1172
- moduleMetadata.controllers.add(controller);
1173
- }
1174
- }
1175
- if (metadata.imports) {
1176
- for (const importedModule of metadata.imports) {
1177
- moduleMetadata.imports.add(importedModule);
1178
- }
1179
- }
1180
- if (metadata.guards) {
1181
- for (const guard of Array.from(metadata.guards).reverse()) {
1182
- moduleMetadata.guards.add(guard);
1183
- }
1184
- }
1185
- return Injectable({
1186
- token,
1187
- type: "Class" /* Class */,
1188
- scope: "Singleton" /* Singleton */
1189
- })(target, context);
1190
- };
1191
- }
1192
-
1193
- // packages/core/src/decorators/use-guards.decorator.mts
1194
- function UseGuards(...guards) {
1195
- return function(target, context) {
1196
- if (context.kind === "class") {
1197
- const controllerMetadata = getControllerMetadata(
1198
- target,
1199
- context
1200
- );
1201
- for (const guard of guards.reverse()) {
1202
- controllerMetadata.guards.add(guard);
1203
- }
1204
- } else if (context.kind === "method") {
1205
- const endpointMetadata = getEndpointMetadata(target, context);
1206
- for (const guard of guards.reverse()) {
1207
- endpointMetadata.guards.add(guard);
1208
- }
1209
- } else {
1210
- throw new Error(
1211
- "[Navios] @UseGuards decorator can only be used on classes or methods."
1212
- );
1213
- }
1214
- return target;
1215
- };
1216
- }
1217
-
1218
- // packages/core/src/exceptions/http.exception.mts
1219
- var HttpException = class {
1220
- constructor(statusCode, response, error) {
1221
- this.statusCode = statusCode;
1222
- this.response = response;
1223
- this.error = error;
1224
- }
1225
- };
1226
-
1227
- // packages/core/src/exceptions/bad-request.exception.mts
1228
- var BadRequestException = class extends HttpException {
1229
- constructor(message) {
1230
- super(400, message);
1231
- }
1232
- };
1233
-
1234
- // packages/core/src/exceptions/forbidden.exception.mts
1235
- var ForbiddenException = class extends HttpException {
1236
- constructor(message) {
1237
- super(403, message);
1238
- }
1239
- };
1240
-
1241
- // packages/core/src/exceptions/internal-server-error.exception.mts
1242
- var InternalServerErrorException = class extends HttpException {
1243
- constructor(message, error) {
1244
- super(500, message, error);
1245
- }
1246
- };
1247
-
1248
- // packages/core/src/exceptions/not-found.exception.mts
1249
- var NotFoundException = class extends HttpException {
1250
- constructor(response, error) {
1251
- super(404, response, error);
1252
- this.response = response;
1253
- this.error = error;
1254
- }
1255
- };
1256
-
1257
- // packages/core/src/exceptions/unauthorized.exception.mts
1258
- var UnauthorizedException = class extends HttpException {
1259
- constructor(message, error) {
1260
- super(401, message, error);
1261
- }
1262
- };
1263
-
1264
- // packages/core/src/exceptions/conflict.exception.mts
1265
- var ConflictException = class extends HttpException {
1266
- constructor(message, error) {
1267
- super(409, message, error);
1268
- }
1269
- };
1270
-
1271
- // packages/core/src/logger/utils/cli-colors.util.mts
1272
- var isColorAllowed = () => !process.env.NO_COLOR;
1273
- var colorIfAllowed = (colorFn) => (text) => isColorAllowed() ? colorFn(text) : text;
1274
- var clc = {
1275
- bold: colorIfAllowed((text) => `\x1B[1m${text}\x1B[0m`),
1276
- green: colorIfAllowed((text) => `\x1B[32m${text}\x1B[39m`),
1277
- yellow: colorIfAllowed((text) => `\x1B[33m${text}\x1B[39m`),
1278
- red: colorIfAllowed((text) => `\x1B[31m${text}\x1B[39m`),
1279
- magentaBright: colorIfAllowed((text) => `\x1B[95m${text}\x1B[39m`),
1280
- cyanBright: colorIfAllowed((text) => `\x1B[96m${text}\x1B[39m`)
1281
- };
1282
- var yellow = colorIfAllowed(
1283
- (text) => `\x1B[38;5;3m${text}\x1B[39m`
1284
- );
1285
-
1286
- // packages/core/src/logger/log-levels.mts
1287
- var LOG_LEVELS = [
1288
- "verbose",
1289
- "debug",
1290
- "log",
1291
- "warn",
1292
- "error",
1293
- "fatal"
1294
- ];
1295
-
1296
- // packages/core/src/logger/utils/is-log-level.util.mts
1297
- function isLogLevel(maybeLogLevel) {
1298
- return LOG_LEVELS.includes(maybeLogLevel);
1299
- }
1300
-
1301
- // packages/core/src/logger/utils/filter-log-levelts.util.mts
1302
- function filterLogLevels(parseableString = "") {
1303
- const sanitizedString = parseableString.replaceAll(" ", "").toLowerCase();
1304
- if (sanitizedString[0] === ">") {
1305
- const orEqual = sanitizedString[1] === "=";
1306
- const logLevelIndex = LOG_LEVELS.indexOf(
1307
- sanitizedString.substring(orEqual ? 2 : 1)
1308
- );
1309
- if (logLevelIndex === -1) {
1310
- throw new Error(`parse error (unknown log level): ${sanitizedString}`);
1311
- }
1312
- return LOG_LEVELS.slice(orEqual ? logLevelIndex : logLevelIndex + 1);
1313
- } else if (sanitizedString.includes(",")) {
1314
- return sanitizedString.split(",").filter(isLogLevel);
1315
- }
1316
- return isLogLevel(sanitizedString) ? [sanitizedString] : LOG_LEVELS;
1317
- }
1318
-
1319
- // packages/core/src/logger/utils/is-log-level-enabled.mts
1320
- var LOG_LEVEL_VALUES = {
1321
- verbose: 0,
1322
- debug: 1,
1323
- log: 2,
1324
- warn: 3,
1325
- error: 4,
1326
- fatal: 5
1327
- };
1328
- function isLogLevelEnabled(targetLevel, logLevels) {
1329
- var _a;
1330
- if (!logLevels || Array.isArray(logLevels) && (logLevels == null ? void 0 : logLevels.length) === 0) {
1331
- return false;
1332
- }
1333
- if (logLevels.includes(targetLevel)) {
1334
- return true;
1335
- }
1336
- const highestLogLevelValue = (_a = logLevels.map((level) => LOG_LEVEL_VALUES[level]).sort((a, b) => b - a)) == null ? void 0 : _a[0];
1337
- const targetLevelValue = LOG_LEVEL_VALUES[targetLevel];
1338
- return targetLevelValue >= highestLogLevelValue;
1339
- }
1340
-
1341
- // packages/core/src/logger/utils/shared.utils.mts
1342
- var isUndefined = (obj) => typeof obj === "undefined";
1343
- var isObject = (fn) => !isNil(fn) && typeof fn === "object";
1344
- var isPlainObject = (fn) => {
1345
- if (!isObject(fn)) {
1346
- return false;
1347
- }
1348
- const proto = Object.getPrototypeOf(fn);
1349
- if (proto === null) {
1350
- return true;
1351
- }
1352
- const ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
1353
- return typeof ctor === "function" && ctor instanceof ctor && Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object);
1354
- };
1355
- var addLeadingSlash = (path) => path && typeof path === "string" ? path.charAt(0) !== "/" && path.substring(0, 2) !== "{/" ? "/" + path : path : "";
1356
- var normalizePath = (path) => path ? path.startsWith("/") ? ("/" + path.replace(/\/+$/, "")).replace(/\/+/g, "/") : "/" + path.replace(/\/+$/, "") : "/";
1357
- var stripEndSlash = (path) => path[path.length - 1] === "/" ? path.slice(0, path.length - 1) : path;
1358
- var isFunction = (val) => typeof val === "function";
1359
- var isString = (val) => typeof val === "string";
1360
- var isNumber = (val) => typeof val === "number";
1361
- var isConstructor = (val) => val === "constructor";
1362
- var isNil = (val) => isUndefined(val) || val === null;
1363
- var isEmpty = (array) => !(array && array.length > 0);
1364
- var isSymbol = (val) => typeof val === "symbol";
1365
-
1366
- // packages/core/src/logger/console-logger.service.mts
1367
- var import_util = require("util");
1368
- var DEFAULT_DEPTH = 5;
1369
- var DEFAULT_LOG_LEVELS = [
1370
- "log",
1371
- "error",
1372
- "warn",
1373
- "debug",
1374
- "verbose",
1375
- "fatal"
1376
- ];
1377
- var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
1378
- year: "numeric",
1379
- hour: "numeric",
1380
- minute: "numeric",
1381
- second: "numeric",
1382
- day: "2-digit",
1383
- month: "2-digit"
1384
- });
1385
- var _ConsoleLogger_decorators, _init;
1386
- _ConsoleLogger_decorators = [Injectable()];
1387
- var _ConsoleLogger = class _ConsoleLogger {
1388
- /**
1389
- * The options of the logger.
1390
- */
1391
- options;
1392
- /**
1393
- * The context of the logger (can be set manually or automatically inferred).
1394
- */
1395
- context;
1396
- /**
1397
- * The original context of the logger (set in the constructor).
1398
- */
1399
- originalContext;
1400
- /**
1401
- * The options used for the "inspect" method.
1402
- */
1403
- inspectOptions;
1404
- /**
1405
- * The last timestamp at which the log message was printed.
1406
- */
1407
- static lastTimestampAt;
1408
- constructor(contextOrOptions, options) {
1409
- let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions == null ? void 0 : contextOrOptions.context, contextOrOptions];
1410
- opts = opts ?? {};
1411
- opts.logLevels ??= DEFAULT_LOG_LEVELS;
1412
- opts.colors ??= opts.colors ?? (opts.json ? false : true);
1413
- opts.prefix ??= "Navios";
1414
- this.options = opts;
1415
- this.inspectOptions = this.getInspectOptions();
1416
- if (context) {
1417
- this.context = context;
1418
- this.originalContext = context;
1128
+ // packages/core/src/logger/console-logger.service.mts
1129
+ var DEFAULT_DEPTH = 5;
1130
+ var DEFAULT_LOG_LEVELS = [
1131
+ "log",
1132
+ "error",
1133
+ "warn",
1134
+ "debug",
1135
+ "verbose",
1136
+ "fatal"
1137
+ ];
1138
+ var dateTimeFormatter = new Intl.DateTimeFormat(void 0, {
1139
+ year: "numeric",
1140
+ hour: "numeric",
1141
+ minute: "numeric",
1142
+ second: "numeric",
1143
+ day: "2-digit",
1144
+ month: "2-digit"
1145
+ });
1146
+ var _ConsoleLogger_decorators, _init;
1147
+ _ConsoleLogger_decorators = [Injectable()];
1148
+ var _ConsoleLogger = class _ConsoleLogger {
1149
+ /**
1150
+ * The options of the logger.
1151
+ */
1152
+ options;
1153
+ /**
1154
+ * The context of the logger (can be set manually or automatically inferred).
1155
+ */
1156
+ context;
1157
+ /**
1158
+ * The original context of the logger (set in the constructor).
1159
+ */
1160
+ originalContext;
1161
+ /**
1162
+ * The options used for the "inspect" method.
1163
+ */
1164
+ inspectOptions;
1165
+ /**
1166
+ * The last timestamp at which the log message was printed.
1167
+ */
1168
+ static lastTimestampAt;
1169
+ constructor(contextOrOptions, options) {
1170
+ let [context, opts] = isString(contextOrOptions) ? [contextOrOptions, options] : options ? [void 0, options] : [contextOrOptions == null ? void 0 : contextOrOptions.context, contextOrOptions];
1171
+ opts = opts ?? {};
1172
+ opts.logLevels ??= DEFAULT_LOG_LEVELS;
1173
+ opts.colors ??= opts.colors ?? (opts.json ? false : true);
1174
+ opts.prefix ??= "Navios";
1175
+ this.options = opts;
1176
+ this.inspectOptions = this.getInspectOptions();
1177
+ if (context) {
1178
+ this.context = context;
1179
+ this.originalContext = context;
1419
1180
  }
1420
1181
  }
1421
1182
  log(message, ...optionalParams) {
@@ -1746,177 +1507,580 @@ var _LoggerInstance = class _LoggerInstance {
1746
1507
  return this.registerLocalInstanceRef();
1747
1508
  }
1748
1509
  }
1749
- return _LoggerInstance.staticInstanceRef;
1510
+ return _LoggerInstance.staticInstanceRef;
1511
+ }
1512
+ error(message, ...optionalParams) {
1513
+ var _a;
1514
+ optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(
1515
+ this.context
1516
+ ) : optionalParams;
1517
+ (_a = this.localInstance) == null ? void 0 : _a.error(message, ...optionalParams);
1518
+ }
1519
+ log(message, ...optionalParams) {
1520
+ var _a;
1521
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1522
+ (_a = this.localInstance) == null ? void 0 : _a.log(message, ...optionalParams);
1523
+ }
1524
+ warn(message, ...optionalParams) {
1525
+ var _a;
1526
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1527
+ (_a = this.localInstance) == null ? void 0 : _a.warn(message, ...optionalParams);
1528
+ }
1529
+ debug(message, ...optionalParams) {
1530
+ var _a, _b;
1531
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1532
+ (_b = (_a = this.localInstance) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1533
+ }
1534
+ verbose(message, ...optionalParams) {
1535
+ var _a, _b;
1536
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1537
+ (_b = (_a = this.localInstance) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1538
+ }
1539
+ fatal(message, ...optionalParams) {
1540
+ var _a, _b;
1541
+ optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1542
+ (_b = (_a = this.localInstance) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1543
+ }
1544
+ static error(message, ...optionalParams) {
1545
+ var _a;
1546
+ (_a = this.staticInstanceRef) == null ? void 0 : _a.error(message, ...optionalParams);
1547
+ }
1548
+ static log(message, ...optionalParams) {
1549
+ var _a;
1550
+ (_a = this.staticInstanceRef) == null ? void 0 : _a.log(message, ...optionalParams);
1551
+ }
1552
+ static warn(message, ...optionalParams) {
1553
+ var _a;
1554
+ (_a = this.staticInstanceRef) == null ? void 0 : _a.warn(message, ...optionalParams);
1555
+ }
1556
+ static debug(message, ...optionalParams) {
1557
+ var _a, _b;
1558
+ (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1559
+ }
1560
+ static verbose(message, ...optionalParams) {
1561
+ var _a, _b;
1562
+ (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1563
+ }
1564
+ static fatal(message, ...optionalParams) {
1565
+ var _a, _b;
1566
+ (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1567
+ }
1568
+ static getTimestamp() {
1569
+ return dateTimeFormatter2.format(Date.now());
1570
+ }
1571
+ static overrideLogger(logger) {
1572
+ var _a, _b;
1573
+ if (Array.isArray(logger)) {
1574
+ _LoggerInstance.logLevels = logger;
1575
+ return (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.setLogLevels) == null ? void 0 : _b.call(_a, logger);
1576
+ }
1577
+ if (isObject(logger)) {
1578
+ this.staticInstanceRef = logger;
1579
+ } else {
1580
+ this.staticInstanceRef = void 0;
1581
+ }
1582
+ }
1583
+ static isLevelEnabled(level) {
1584
+ const logLevels = _LoggerInstance.logLevels;
1585
+ return isLogLevelEnabled(level, logLevels);
1586
+ }
1587
+ registerLocalInstanceRef() {
1588
+ var _a;
1589
+ if (this.localInstanceRef) {
1590
+ return this.localInstanceRef;
1591
+ }
1592
+ this.localInstanceRef = new ConsoleLogger(this.context, {
1593
+ timestamp: (_a = this.options) == null ? void 0 : _a.timestamp,
1594
+ logLevels: _LoggerInstance.logLevels
1595
+ });
1596
+ return this.localInstanceRef;
1597
+ }
1598
+ };
1599
+ _init2 = __decoratorStart(null);
1600
+ _LoggerInstance = __decorateElement(_init2, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
1601
+ __runInitializers(_init2, 1, _LoggerInstance);
1602
+ var LoggerInstance = _LoggerInstance;
1603
+
1604
+ // packages/core/src/logger/logger.factory.mts
1605
+ var LoggerInjectionToken = "LoggerInjectionToken";
1606
+ var LoggerOptions = import_zod2.z.object({
1607
+ context: import_zod2.z.string().optional(),
1608
+ options: import_zod2.z.object({
1609
+ timestamp: import_zod2.z.boolean().optional()
1610
+ }).optional()
1611
+ }).optional();
1612
+ var Logger = InjectionToken.create(LoggerInjectionToken, LoggerOptions);
1613
+ var _LoggerFactory_decorators, _init3;
1614
+ _LoggerFactory_decorators = [Injectable({
1615
+ type: "Factory" /* Factory */,
1616
+ token: Logger
1617
+ })];
1618
+ var LoggerFactory = class {
1619
+ create(ctx, args) {
1620
+ return new LoggerInstance(args == null ? void 0 : args.context, args == null ? void 0 : args.options);
1621
+ }
1622
+ };
1623
+ _init3 = __decoratorStart(null);
1624
+ LoggerFactory = __decorateElement(_init3, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
1625
+ __runInitializers(_init3, 1, LoggerFactory);
1626
+
1627
+ // packages/core/src/logger/pino-wrapper.mts
1628
+ var PinoWrapper = class _PinoWrapper {
1629
+ constructor(logger) {
1630
+ this.logger = logger;
1631
+ }
1632
+ fatal(message, ...optionalParams) {
1633
+ if (this.logger.fatal === void 0) {
1634
+ return this.error(message, ...optionalParams);
1635
+ }
1636
+ this.logger.fatal(message, ...optionalParams);
1750
1637
  }
1751
1638
  error(message, ...optionalParams) {
1752
- var _a;
1753
- optionalParams = this.context ? (optionalParams.length ? optionalParams : [void 0]).concat(
1754
- this.context
1755
- ) : optionalParams;
1756
- (_a = this.localInstance) == null ? void 0 : _a.error(message, ...optionalParams);
1757
- }
1758
- log(message, ...optionalParams) {
1759
- var _a;
1760
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1761
- (_a = this.localInstance) == null ? void 0 : _a.log(message, ...optionalParams);
1639
+ this.logger.error(message, ...optionalParams);
1762
1640
  }
1763
1641
  warn(message, ...optionalParams) {
1764
- var _a;
1765
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1766
- (_a = this.localInstance) == null ? void 0 : _a.warn(message, ...optionalParams);
1642
+ this.logger.warn(message, ...optionalParams);
1643
+ }
1644
+ info() {
1767
1645
  }
1768
1646
  debug(message, ...optionalParams) {
1769
1647
  var _a, _b;
1770
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1771
- (_b = (_a = this.localInstance) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1648
+ (_b = (_a = this.logger).debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1772
1649
  }
1773
- verbose(message, ...optionalParams) {
1650
+ trace(message, ...optionalParams) {
1774
1651
  var _a, _b;
1775
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1776
- (_b = (_a = this.localInstance) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1652
+ (_b = (_a = this.logger).verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1777
1653
  }
1778
- fatal(message, ...optionalParams) {
1779
- var _a, _b;
1780
- optionalParams = this.context ? optionalParams.concat(this.context) : optionalParams;
1781
- (_b = (_a = this.localInstance) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1654
+ silent() {
1782
1655
  }
1783
- static error(message, ...optionalParams) {
1784
- var _a;
1785
- (_a = this.staticInstanceRef) == null ? void 0 : _a.error(message, ...optionalParams);
1656
+ child(options) {
1657
+ const keys = Object.keys(options);
1658
+ let newContext = this.logger["context"] ?? "";
1659
+ if (keys.length > 1) {
1660
+ newContext = `${this.logger["context"] ?? ""}:${JSON.stringify(options)}`;
1661
+ }
1662
+ return new _PinoWrapper(
1663
+ // @ts-expect-error We don't need to support this in the current version
1664
+ new LoggerInstance(newContext, this.logger["options"])
1665
+ );
1786
1666
  }
1787
- static log(message, ...optionalParams) {
1788
- var _a;
1789
- (_a = this.staticInstanceRef) == null ? void 0 : _a.log(message, ...optionalParams);
1667
+ get level() {
1668
+ if ("level" in this.logger && this.logger.level) {
1669
+ return this.logger.level;
1670
+ }
1671
+ const levels = LoggerInstance["logLevels"];
1672
+ if (levels) {
1673
+ return levels.find((level) => level !== "verbose");
1674
+ }
1675
+ return "warn";
1790
1676
  }
1791
- static warn(message, ...optionalParams) {
1792
- var _a;
1793
- (_a = this.staticInstanceRef) == null ? void 0 : _a.warn(message, ...optionalParams);
1677
+ };
1678
+
1679
+ // packages/core/src/config/config.service.mts
1680
+ var import_common = require("@navios/common");
1681
+ var ConfigServiceInstance = class {
1682
+ constructor(config = {}, logger) {
1683
+ this.config = config;
1684
+ this.logger = logger;
1794
1685
  }
1795
- static debug(message, ...optionalParams) {
1796
- var _a, _b;
1797
- (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1686
+ getConfig() {
1687
+ return this.config;
1798
1688
  }
1799
- static verbose(message, ...optionalParams) {
1689
+ get(key) {
1800
1690
  var _a, _b;
1801
- (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1691
+ try {
1692
+ const parts = String(key).split(".");
1693
+ let value = this.config;
1694
+ for (const part of parts) {
1695
+ if (value === null || value === void 0 || typeof value !== "object") {
1696
+ return null;
1697
+ }
1698
+ value = value[part];
1699
+ }
1700
+ return value ?? null;
1701
+ } catch (error) {
1702
+ (_b = (_a = this.logger).debug) == null ? void 0 : _b.call(
1703
+ _a,
1704
+ `Failed to get config value for key ${String(key)}`,
1705
+ error
1706
+ );
1707
+ return null;
1708
+ }
1802
1709
  }
1803
- static fatal(message, ...optionalParams) {
1804
- var _a, _b;
1805
- (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.fatal) == null ? void 0 : _b.call(_a, message, ...optionalParams);
1710
+ getOrDefault(key, defaultValue) {
1711
+ const value = this.get(key);
1712
+ return value !== null ? value : defaultValue;
1806
1713
  }
1807
- static getTimestamp() {
1808
- return dateTimeFormatter2.format(Date.now());
1714
+ getOrThrow(key, errorMessage) {
1715
+ const value = this.get(key);
1716
+ if (value === null) {
1717
+ const message = errorMessage || `Configuration value for key "${String(key)}" is not defined`;
1718
+ this.logger.error(message);
1719
+ throw new import_common.NaviosException(message);
1720
+ }
1721
+ return value;
1809
1722
  }
1810
- static overrideLogger(logger) {
1811
- var _a, _b;
1812
- console.log(logger);
1813
- if (Array.isArray(logger)) {
1814
- _LoggerInstance.logLevels = logger;
1815
- return (_b = (_a = this.staticInstanceRef) == null ? void 0 : _a.setLogLevels) == null ? void 0 : _b.call(_a, logger);
1723
+ };
1724
+
1725
+ // packages/core/src/config/config.provider.mts
1726
+ var ConfigProviderInjectionToken = "ConfigProvider";
1727
+ var ConfigProviderOptions = import_zod3.z.object({
1728
+ load: import_zod3.z.function()
1729
+ });
1730
+ var ConfigProvider = InjectionToken.create(ConfigProviderInjectionToken, ConfigProviderOptions);
1731
+ var _ConfigProviderFactory_decorators, _init4;
1732
+ _ConfigProviderFactory_decorators = [Injectable({
1733
+ token: ConfigProvider,
1734
+ type: "Factory" /* Factory */
1735
+ })];
1736
+ var ConfigProviderFactory = class {
1737
+ logger = inject(Logger, {
1738
+ context: "ConfigService"
1739
+ });
1740
+ async create(ctx, args) {
1741
+ const { load } = args;
1742
+ const logger = await this.logger;
1743
+ try {
1744
+ const config = await load();
1745
+ return new ConfigServiceInstance(config, logger);
1746
+ } catch (error) {
1747
+ logger.error("Error loading config", error);
1748
+ throw error;
1749
+ }
1750
+ }
1751
+ };
1752
+ _init4 = __decoratorStart(null);
1753
+ ConfigProviderFactory = __decorateElement(_init4, 0, "ConfigProviderFactory", _ConfigProviderFactory_decorators, ConfigProviderFactory);
1754
+ __runInitializers(_init4, 1, ConfigProviderFactory);
1755
+ function makeConfigToken(options) {
1756
+ var _ConfigServiceImpl_decorators, _init9;
1757
+ _ConfigServiceImpl_decorators = [Injectable({
1758
+ type: "Factory" /* Factory */
1759
+ })];
1760
+ class ConfigServiceImpl {
1761
+ configService = inject(ConfigProvider, options);
1762
+ create() {
1763
+ return this.configService;
1764
+ }
1765
+ }
1766
+ _init9 = __decoratorStart(null);
1767
+ ConfigServiceImpl = __decorateElement(_init9, 0, "ConfigServiceImpl", _ConfigServiceImpl_decorators, ConfigServiceImpl);
1768
+ __runInitializers(_init9, 1, ConfigServiceImpl);
1769
+ return getInjectableToken(ConfigServiceImpl);
1770
+ }
1771
+
1772
+ // packages/core/src/metadata/endpoint.metadata.mts
1773
+ var EndpointMetadataKey = Symbol("EndpointMetadataKey");
1774
+ var EndpointType = /* @__PURE__ */ ((EndpointType2) => {
1775
+ EndpointType2["Unknown"] = "unknown";
1776
+ EndpointType2["Config"] = "config";
1777
+ EndpointType2["Handler"] = "handler";
1778
+ return EndpointType2;
1779
+ })(EndpointType || {});
1780
+ function getAllEndpointMetadata(context) {
1781
+ if (context.metadata) {
1782
+ const metadata = context.metadata[EndpointMetadataKey];
1783
+ if (metadata) {
1784
+ return metadata;
1785
+ } else {
1786
+ context.metadata[EndpointMetadataKey] = /* @__PURE__ */ new Set();
1787
+ return context.metadata[EndpointMetadataKey];
1788
+ }
1789
+ }
1790
+ throw new Error("[Navios] Wrong environment.");
1791
+ }
1792
+ function getEndpointMetadata(target, context) {
1793
+ if (context.metadata) {
1794
+ const metadata = getAllEndpointMetadata(context);
1795
+ if (metadata) {
1796
+ const endpointMetadata = Array.from(metadata).find(
1797
+ (item) => item.classMethod === target.name
1798
+ );
1799
+ if (endpointMetadata) {
1800
+ return endpointMetadata;
1801
+ } else {
1802
+ const newMetadata = {
1803
+ classMethod: target.name,
1804
+ url: "",
1805
+ successStatusCode: 200,
1806
+ headers: {},
1807
+ type: "unknown" /* Unknown */,
1808
+ httpMethod: "GET",
1809
+ config: null,
1810
+ guards: /* @__PURE__ */ new Set(),
1811
+ customAttributes: /* @__PURE__ */ new Map()
1812
+ };
1813
+ metadata.add(newMetadata);
1814
+ return newMetadata;
1815
+ }
1816
+ }
1817
+ }
1818
+ throw new Error("[Navios] Wrong environment.");
1819
+ }
1820
+
1821
+ // packages/core/src/metadata/controller.metadata.mts
1822
+ var ControllerMetadataKey = Symbol("ControllerMetadataKey");
1823
+ function getControllerMetadata(target, context) {
1824
+ if (context.metadata) {
1825
+ const metadata = context.metadata[ControllerMetadataKey];
1826
+ if (metadata) {
1827
+ return metadata;
1828
+ } else {
1829
+ const endpointsMetadata = getAllEndpointMetadata(context);
1830
+ const newMetadata = {
1831
+ endpoints: endpointsMetadata,
1832
+ guards: /* @__PURE__ */ new Set(),
1833
+ customAttributes: /* @__PURE__ */ new Map()
1834
+ };
1835
+ context.metadata[ControllerMetadataKey] = newMetadata;
1836
+ target[ControllerMetadataKey] = newMetadata;
1837
+ return newMetadata;
1838
+ }
1839
+ }
1840
+ throw new Error("[Navios] Wrong environment.");
1841
+ }
1842
+ function extractControllerMetadata(target) {
1843
+ const metadata = target[ControllerMetadataKey];
1844
+ if (!metadata) {
1845
+ throw new Error(
1846
+ "[Navios] Controller metadata not found. Make sure to use @Controller decorator."
1847
+ );
1848
+ }
1849
+ return metadata;
1850
+ }
1851
+ function hasControllerMetadata(target) {
1852
+ const metadata = target[ControllerMetadataKey];
1853
+ return !!metadata;
1854
+ }
1855
+
1856
+ // packages/core/src/metadata/module.metadata.mts
1857
+ var ModuleMetadataKey = Symbol("ControllerMetadataKey");
1858
+ function getModuleMetadata(target, context) {
1859
+ if (context.metadata) {
1860
+ const metadata = context.metadata[ModuleMetadataKey];
1861
+ if (metadata) {
1862
+ return metadata;
1863
+ } else {
1864
+ const newMetadata = {
1865
+ controllers: /* @__PURE__ */ new Set(),
1866
+ imports: /* @__PURE__ */ new Set(),
1867
+ guards: /* @__PURE__ */ new Set(),
1868
+ customAttributes: /* @__PURE__ */ new Map()
1869
+ };
1870
+ context.metadata[ModuleMetadataKey] = newMetadata;
1871
+ target[ModuleMetadataKey] = newMetadata;
1872
+ return newMetadata;
1873
+ }
1874
+ }
1875
+ throw new Error("[Navios] Wrong environment.");
1876
+ }
1877
+ function extractModuleMetadata(target) {
1878
+ const metadata = target[ModuleMetadataKey];
1879
+ if (!metadata) {
1880
+ throw new Error(
1881
+ "[Navios] Module metadata not found. Make sure to use @Module decorator."
1882
+ );
1883
+ }
1884
+ return metadata;
1885
+ }
1886
+ function hasModuleMetadata(target) {
1887
+ return !!target[ModuleMetadataKey];
1888
+ }
1889
+
1890
+ // packages/core/src/decorators/controller.decorator.mts
1891
+ function Controller({ guards } = {}) {
1892
+ return function(target, context) {
1893
+ if (context.kind !== "class") {
1894
+ throw new Error(
1895
+ "[Navios] @Controller decorator can only be used on classes."
1896
+ );
1897
+ }
1898
+ const token = InjectionToken.create(target);
1899
+ if (context.metadata) {
1900
+ const controllerMetadata = getControllerMetadata(target, context);
1901
+ if (guards) {
1902
+ for (const guard of Array.from(guards).reverse()) {
1903
+ controllerMetadata.guards.add(guard);
1904
+ }
1905
+ }
1906
+ }
1907
+ return Injectable({
1908
+ token,
1909
+ type: "Class" /* Class */,
1910
+ scope: "Instance" /* Instance */
1911
+ })(target, context);
1912
+ };
1913
+ }
1914
+
1915
+ // packages/core/src/decorators/endpoint.decorator.mts
1916
+ function Endpoint(endpoint) {
1917
+ return (target, context) => {
1918
+ if (typeof target !== "function") {
1919
+ throw new Error(
1920
+ "[Navios] Endpoint decorator can only be used on functions."
1921
+ );
1922
+ }
1923
+ if (context.kind !== "method") {
1924
+ throw new Error(
1925
+ "[Navios] Endpoint decorator can only be used on methods."
1926
+ );
1927
+ }
1928
+ const config = endpoint.config;
1929
+ if (context.metadata) {
1930
+ let endpointMetadata = getEndpointMetadata(target, context);
1931
+ if (endpointMetadata.config && endpointMetadata.config.url) {
1932
+ throw new Error(
1933
+ `[Navios] Endpoint ${config.method} ${config.url} already exists. Please use a different method or url.`
1934
+ );
1935
+ }
1936
+ endpointMetadata.config = config;
1937
+ endpointMetadata.type = "config" /* Config */;
1938
+ endpointMetadata.classMethod = target.name;
1939
+ endpointMetadata.httpMethod = config.method;
1940
+ endpointMetadata.url = config.url;
1816
1941
  }
1817
- if (isObject(logger)) {
1818
- this.staticInstanceRef = logger;
1819
- } else {
1820
- this.staticInstanceRef = void 0;
1942
+ return target;
1943
+ };
1944
+ }
1945
+
1946
+ // packages/core/src/decorators/header.decorator.mts
1947
+ function Header(name2, value) {
1948
+ return (target, context) => {
1949
+ if (context.kind !== "method") {
1950
+ throw new Error("[Navios] Header decorator can only be used on methods.");
1821
1951
  }
1822
- }
1823
- static isLevelEnabled(level) {
1824
- const logLevels = _LoggerInstance.logLevels;
1825
- return isLogLevelEnabled(level, logLevels);
1826
- }
1827
- registerLocalInstanceRef() {
1828
- var _a;
1829
- if (this.localInstanceRef) {
1830
- return this.localInstanceRef;
1952
+ const metadata = getEndpointMetadata(target, context);
1953
+ metadata.headers[name2] = value;
1954
+ return target;
1955
+ };
1956
+ }
1957
+
1958
+ // packages/core/src/decorators/http-code.decorator.mts
1959
+ function HttpCode(code) {
1960
+ return (target, context) => {
1961
+ if (context.kind !== "method") {
1962
+ throw new Error(
1963
+ "[Navios] HttpCode decorator can only be used on methods."
1964
+ );
1831
1965
  }
1832
- this.localInstanceRef = new ConsoleLogger(this.context, {
1833
- timestamp: (_a = this.options) == null ? void 0 : _a.timestamp,
1834
- logLevels: _LoggerInstance.logLevels
1835
- });
1836
- return this.localInstanceRef;
1966
+ const metadata = getEndpointMetadata(target, context);
1967
+ metadata.successStatusCode = code;
1968
+ return target;
1969
+ };
1970
+ }
1971
+
1972
+ // packages/core/src/decorators/module.decorator.mts
1973
+ function Module(metadata) {
1974
+ return (target, context) => {
1975
+ if (context.kind !== "class") {
1976
+ throw new Error("[Navios] @Module decorator can only be used on classes.");
1977
+ }
1978
+ const token = InjectionToken.create(target);
1979
+ const moduleMetadata = getModuleMetadata(target, context);
1980
+ if (metadata.controllers) {
1981
+ for (const controller of metadata.controllers) {
1982
+ moduleMetadata.controllers.add(controller);
1983
+ }
1984
+ }
1985
+ if (metadata.imports) {
1986
+ for (const importedModule of metadata.imports) {
1987
+ moduleMetadata.imports.add(importedModule);
1988
+ }
1989
+ }
1990
+ if (metadata.guards) {
1991
+ for (const guard of Array.from(metadata.guards).reverse()) {
1992
+ moduleMetadata.guards.add(guard);
1993
+ }
1994
+ }
1995
+ return Injectable({
1996
+ token,
1997
+ type: "Class" /* Class */,
1998
+ scope: "Singleton" /* Singleton */
1999
+ })(target, context);
2000
+ };
2001
+ }
2002
+
2003
+ // packages/core/src/decorators/use-guards.decorator.mts
2004
+ function UseGuards(...guards) {
2005
+ return function(target, context) {
2006
+ if (context.kind === "class") {
2007
+ const controllerMetadata = getControllerMetadata(
2008
+ target,
2009
+ context
2010
+ );
2011
+ for (const guard of guards.reverse()) {
2012
+ controllerMetadata.guards.add(guard);
2013
+ }
2014
+ } else if (context.kind === "method") {
2015
+ const endpointMetadata = getEndpointMetadata(target, context);
2016
+ for (const guard of guards.reverse()) {
2017
+ endpointMetadata.guards.add(guard);
2018
+ }
2019
+ } else {
2020
+ throw new Error(
2021
+ "[Navios] @UseGuards decorator can only be used on classes or methods."
2022
+ );
2023
+ }
2024
+ return target;
2025
+ };
2026
+ }
2027
+
2028
+ // packages/core/src/exceptions/http.exception.mts
2029
+ var HttpException = class {
2030
+ constructor(statusCode, response, error) {
2031
+ this.statusCode = statusCode;
2032
+ this.response = response;
2033
+ this.error = error;
1837
2034
  }
1838
2035
  };
1839
- _init2 = __decoratorStart(null);
1840
- _LoggerInstance = __decorateElement(_init2, 0, "LoggerInstance", _LoggerInstance_decorators, _LoggerInstance);
1841
- __runInitializers(_init2, 1, _LoggerInstance);
1842
- var LoggerInstance = _LoggerInstance;
1843
2036
 
1844
- // packages/core/src/logger/logger.factory.mts
1845
- var LoggerInjectionToken = "LoggerInjectionToken";
1846
- var LoggerOptions = import_zod2.z.object({
1847
- context: import_zod2.z.string().optional(),
1848
- options: import_zod2.z.object({
1849
- timestamp: import_zod2.z.boolean().optional()
1850
- }).optional()
1851
- }).optional();
1852
- var Logger = InjectionToken.create(LoggerInjectionToken, LoggerOptions);
1853
- var _LoggerFactory_decorators, _init3;
1854
- _LoggerFactory_decorators = [Injectable({
1855
- type: "Factory" /* Factory */,
1856
- token: Logger
1857
- })];
1858
- var LoggerFactory = class {
1859
- create(ctx, args) {
1860
- return new LoggerInstance(args == null ? void 0 : args.context, args == null ? void 0 : args.options);
2037
+ // packages/core/src/exceptions/bad-request.exception.mts
2038
+ var BadRequestException = class extends HttpException {
2039
+ constructor(message) {
2040
+ super(400, message);
1861
2041
  }
1862
2042
  };
1863
- _init3 = __decoratorStart(null);
1864
- LoggerFactory = __decorateElement(_init3, 0, "LoggerFactory", _LoggerFactory_decorators, LoggerFactory);
1865
- __runInitializers(_init3, 1, LoggerFactory);
1866
2043
 
1867
- // packages/core/src/logger/pino-wrapper.mts
1868
- var PinoWrapper = class _PinoWrapper {
1869
- constructor(logger) {
1870
- this.logger = logger;
1871
- }
1872
- fatal(message, ...optionalParams) {
1873
- if (this.logger.fatal === void 0) {
1874
- return this.error(message, ...optionalParams);
1875
- }
1876
- this.logger.fatal(message, ...optionalParams);
1877
- }
1878
- error(message, ...optionalParams) {
1879
- this.logger.error(message, ...optionalParams);
1880
- }
1881
- warn(message, ...optionalParams) {
1882
- this.logger.warn(message, ...optionalParams);
1883
- }
1884
- info(message, ...optionalParams) {
1885
- this.logger.log(message, ...optionalParams);
1886
- }
1887
- debug(message, ...optionalParams) {
1888
- var _a, _b;
1889
- (_b = (_a = this.logger).debug) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2044
+ // packages/core/src/exceptions/forbidden.exception.mts
2045
+ var ForbiddenException = class extends HttpException {
2046
+ constructor(message) {
2047
+ super(403, message);
1890
2048
  }
1891
- trace(message, ...optionalParams) {
1892
- var _a, _b;
1893
- (_b = (_a = this.logger).verbose) == null ? void 0 : _b.call(_a, message, ...optionalParams);
2049
+ };
2050
+
2051
+ // packages/core/src/exceptions/internal-server-error.exception.mts
2052
+ var InternalServerErrorException = class extends HttpException {
2053
+ constructor(message, error) {
2054
+ super(500, message, error);
1894
2055
  }
1895
- silent(message, ...optionalParams) {
2056
+ };
2057
+
2058
+ // packages/core/src/exceptions/not-found.exception.mts
2059
+ var NotFoundException = class extends HttpException {
2060
+ constructor(response, error) {
2061
+ super(404, response, error);
2062
+ this.response = response;
2063
+ this.error = error;
1896
2064
  }
1897
- child(options) {
1898
- const keys = Object.keys(options);
1899
- let newContext = this.logger["context"] ?? "";
1900
- if (keys.length > 1) {
1901
- newContext = `${this.logger["context"] ?? ""}:${JSON.stringify(options)}`;
1902
- }
1903
- return new _PinoWrapper(
1904
- // @ts-expect-error We don't need to support this in the current version
1905
- new LoggerInstance(newContext, this.logger["options"])
1906
- );
2065
+ };
2066
+
2067
+ // packages/core/src/exceptions/unauthorized.exception.mts
2068
+ var UnauthorizedException = class extends HttpException {
2069
+ constructor(message, error) {
2070
+ super(401, message, error);
1907
2071
  }
1908
- get level() {
1909
- if ("level" in this.logger && this.logger.level) {
1910
- return this.logger.level;
1911
- }
1912
- const levels = LoggerInstance["logLevels"];
1913
- if (levels) {
1914
- return levels[0];
1915
- }
1916
- return "info";
2072
+ };
2073
+
2074
+ // packages/core/src/exceptions/conflict.exception.mts
2075
+ var ConflictException = class extends HttpException {
2076
+ constructor(message, error) {
2077
+ super(409, message, error);
1917
2078
  }
1918
2079
  };
1919
2080
 
2081
+ // packages/core/src/services/controller-adapter.service.mts
2082
+ var import_common2 = require("@navios/common");
2083
+
1920
2084
  // packages/core/src/tokens/application.token.mts
1921
2085
  var ApplicationInjectionToken = "ApplicationInjectionToken";
1922
2086
  var Application = InjectionToken.create(
@@ -1982,7 +2146,7 @@ var ExecutionContext2 = class {
1982
2146
  };
1983
2147
 
1984
2148
  // packages/core/src/services/guard-runner.service.mts
1985
- var _GuardRunnerService_decorators, _init4;
2149
+ var _GuardRunnerService_decorators, _init5;
1986
2150
  _GuardRunnerService_decorators = [Injectable()];
1987
2151
  var GuardRunnerService = class {
1988
2152
  async runGuards(allGuards, executionContext) {
@@ -2045,12 +2209,12 @@ var GuardRunnerService = class {
2045
2209
  return guards;
2046
2210
  }
2047
2211
  };
2048
- _init4 = __decoratorStart(null);
2049
- GuardRunnerService = __decorateElement(_init4, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
2050
- __runInitializers(_init4, 1, GuardRunnerService);
2212
+ _init5 = __decoratorStart(null);
2213
+ GuardRunnerService = __decorateElement(_init5, 0, "GuardRunnerService", _GuardRunnerService_decorators, GuardRunnerService);
2214
+ __runInitializers(_init5, 1, GuardRunnerService);
2051
2215
 
2052
2216
  // packages/core/src/services/controller-adapter.service.mts
2053
- var _ControllerAdapterService_decorators, _init5;
2217
+ var _ControllerAdapterService_decorators, _init6;
2054
2218
  _ControllerAdapterService_decorators = [Injectable()];
2055
2219
  var _ControllerAdapterService = class _ControllerAdapterService {
2056
2220
  guardRunner = syncInject(GuardRunnerService);
@@ -2060,8 +2224,8 @@ var _ControllerAdapterService = class _ControllerAdapterService {
2060
2224
  setupController(controller, instance, moduleMetadata) {
2061
2225
  const controllerMetadata = extractControllerMetadata(controller);
2062
2226
  for (const endpoint of controllerMetadata.endpoints) {
2063
- const { classMethod, url, httpMethod, config } = endpoint;
2064
- if (!url || !config) {
2227
+ const { classMethod, url, httpMethod } = endpoint;
2228
+ if (!url) {
2065
2229
  throw new Error(
2066
2230
  `[Navios] Malformed Endpoint ${controller.name}:${classMethod}`
2067
2231
  );
@@ -2071,99 +2235,123 @@ var _ControllerAdapterService = class _ControllerAdapterService {
2071
2235
  controllerMetadata,
2072
2236
  endpoint
2073
2237
  );
2074
- const guards = this.guardRunner.makeContext(executionContext);
2075
- const { querySchema, requestSchema, responseSchema } = config;
2076
- const schema = {};
2077
- if (querySchema) {
2078
- schema.querystring = querySchema;
2079
- }
2080
- if (requestSchema) {
2081
- schema.body = requestSchema;
2082
- }
2083
- if (responseSchema) {
2084
- schema.response = {
2085
- 200: responseSchema
2086
- };
2087
- }
2088
2238
  instance.withTypeProvider().route({
2089
2239
  method: httpMethod,
2090
2240
  url: url.replaceAll("$", ":"),
2091
- schema,
2092
- preHandler: async (request, reply) => {
2093
- if (guards.size > 0) {
2094
- getServiceLocator().registerInstance(Request, request);
2095
- getServiceLocator().registerInstance(Reply, reply);
2096
- getServiceLocator().registerInstance(
2097
- ExecutionContextToken,
2098
- executionContext
2099
- );
2100
- executionContext.provideRequest(request);
2101
- executionContext.provideReply(reply);
2102
- const canActivate = await this.guardRunner.runGuards(
2103
- guards,
2104
- executionContext
2105
- );
2106
- getServiceLocator().removeInstance(Request);
2107
- getServiceLocator().removeInstance(Reply);
2108
- getServiceLocator().removeInstance(ExecutionContextToken);
2109
- if (!canActivate) {
2110
- return reply;
2111
- }
2112
- }
2113
- },
2114
- handler: async (request, reply) => {
2115
- getServiceLocator().registerInstance(Request, request);
2116
- getServiceLocator().registerInstance(Reply, reply);
2117
- getServiceLocator().registerInstance(
2118
- ExecutionContextToken,
2119
- executionContext
2120
- );
2121
- executionContext.provideRequest(request);
2122
- executionContext.provideReply(reply);
2123
- const controllerInstance = await inject(controller);
2124
- try {
2125
- const { query, params, body } = request;
2126
- const argument = {};
2127
- if (query && Object.keys(query).length > 0) {
2128
- argument.params = query;
2129
- }
2130
- if (params && Object.keys(params).length > 0) {
2131
- argument.urlParams = params;
2132
- }
2133
- if (body) {
2134
- argument.data = body;
2135
- }
2136
- const result = await controllerInstance[classMethod](argument);
2137
- reply.status(200).send(result);
2138
- } catch (error) {
2139
- if (error instanceof HttpException) {
2140
- reply.status(error.statusCode).send(error.response);
2141
- } else {
2142
- reply.status(500).send({
2143
- message: "Internal server error",
2144
- error: error.message
2145
- });
2146
- }
2147
- } finally {
2148
- getServiceLocator().removeInstance(Request);
2149
- getServiceLocator().removeInstance(Reply);
2150
- getServiceLocator().removeInstance(ExecutionContextToken);
2151
- }
2152
- }
2241
+ schema: this.provideSchemaForConfig(endpoint),
2242
+ preHandler: this.providePreHandler(executionContext),
2243
+ handler: this.provideHandler(controller, executionContext, endpoint)
2153
2244
  });
2154
2245
  this.logger.debug(
2155
2246
  `Registered ${httpMethod} ${url} for ${controller.name}:${classMethod}`
2156
2247
  );
2157
2248
  }
2158
2249
  }
2250
+ providePreHandler(executionContext) {
2251
+ const guards = this.guardRunner.makeContext(executionContext);
2252
+ return guards.size > 0 ? async (request, reply) => {
2253
+ getServiceLocator().registerInstance(Request, request);
2254
+ getServiceLocator().registerInstance(Reply, reply);
2255
+ getServiceLocator().registerInstance(
2256
+ ExecutionContextToken,
2257
+ executionContext
2258
+ );
2259
+ executionContext.provideRequest(request);
2260
+ executionContext.provideReply(reply);
2261
+ let canActivate = true;
2262
+ try {
2263
+ canActivate = await this.guardRunner.runGuards(
2264
+ guards,
2265
+ executionContext
2266
+ );
2267
+ } finally {
2268
+ getServiceLocator().removeInstance(Request);
2269
+ getServiceLocator().removeInstance(Reply);
2270
+ getServiceLocator().removeInstance(ExecutionContextToken);
2271
+ }
2272
+ if (!canActivate) {
2273
+ return reply;
2274
+ }
2275
+ } : void 0;
2276
+ }
2277
+ provideSchemaForConfig(endpointMetadata) {
2278
+ if (!endpointMetadata.config) {
2279
+ this.logger.warn(`No config found for endpoint ${endpointMetadata.url}`);
2280
+ return {};
2281
+ }
2282
+ const { querySchema, requestSchema, responseSchema } = endpointMetadata.config;
2283
+ const schema = {};
2284
+ if (querySchema) {
2285
+ schema.querystring = querySchema;
2286
+ }
2287
+ if (requestSchema) {
2288
+ schema.body = requestSchema;
2289
+ }
2290
+ if (responseSchema) {
2291
+ schema.response = {
2292
+ 200: responseSchema
2293
+ };
2294
+ }
2295
+ return schema;
2296
+ }
2297
+ provideHandler(controller, executionContext, endpointMetadata) {
2298
+ switch (endpointMetadata.type) {
2299
+ case "unknown" /* Unknown */:
2300
+ this.logger.error(
2301
+ `Unknown endpoint type ${endpointMetadata.type} for ${controller.name}:${endpointMetadata.classMethod}`
2302
+ );
2303
+ throw new import_common2.NaviosException("Unknown endpoint type");
2304
+ case "config" /* Config */:
2305
+ return this.provideHandlerForConfig(
2306
+ controller,
2307
+ executionContext,
2308
+ endpointMetadata
2309
+ );
2310
+ case "handler" /* Handler */:
2311
+ this.logger.error("Not implemented yet");
2312
+ throw new import_common2.NaviosException("Not implemented yet");
2313
+ }
2314
+ }
2315
+ provideHandlerForConfig(controller, executionContext, endpointMetadata) {
2316
+ return async (request, reply) => {
2317
+ getServiceLocator().registerInstance(Request, request);
2318
+ getServiceLocator().registerInstance(Reply, reply);
2319
+ getServiceLocator().registerInstance(
2320
+ ExecutionContextToken,
2321
+ executionContext
2322
+ );
2323
+ executionContext.provideRequest(request);
2324
+ executionContext.provideReply(reply);
2325
+ const controllerInstance = await inject(controller);
2326
+ try {
2327
+ const { query, params, body } = request;
2328
+ const argument = {};
2329
+ if (query && Object.keys(query).length > 0) {
2330
+ argument.params = query;
2331
+ }
2332
+ if (params && Object.keys(params).length > 0) {
2333
+ argument.urlParams = params;
2334
+ }
2335
+ if (body) {
2336
+ argument.data = body;
2337
+ }
2338
+ const result = await controllerInstance[endpointMetadata.classMethod](argument);
2339
+ reply.status(endpointMetadata.successStatusCode).headers(endpointMetadata.headers).send(result);
2340
+ } finally {
2341
+ getServiceLocator().removeInstance(Request);
2342
+ getServiceLocator().removeInstance(Reply);
2343
+ getServiceLocator().removeInstance(ExecutionContextToken);
2344
+ }
2345
+ };
2346
+ }
2159
2347
  };
2160
- _init5 = __decoratorStart(null);
2161
- _ControllerAdapterService = __decorateElement(_init5, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
2162
- __runInitializers(_init5, 1, _ControllerAdapterService);
2348
+ _init6 = __decoratorStart(null);
2349
+ _ControllerAdapterService = __decorateElement(_init6, 0, "ControllerAdapterService", _ControllerAdapterService_decorators, _ControllerAdapterService);
2350
+ __runInitializers(_init6, 1, _ControllerAdapterService);
2163
2351
  var ControllerAdapterService = _ControllerAdapterService;
2164
2352
 
2165
2353
  // packages/core/src/services/module-loader.service.mts
2166
- var _ModuleLoaderService_decorators, _init6;
2354
+ var _ModuleLoaderService_decorators, _init7;
2167
2355
  _ModuleLoaderService_decorators = [Injectable()];
2168
2356
  var _ModuleLoaderService = class _ModuleLoaderService {
2169
2357
  logger = syncInject(Logger, {
@@ -2220,9 +2408,9 @@ var _ModuleLoaderService = class _ModuleLoaderService {
2220
2408
  return this.modulesMetadata;
2221
2409
  }
2222
2410
  };
2223
- _init6 = __decoratorStart(null);
2224
- _ModuleLoaderService = __decorateElement(_init6, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
2225
- __runInitializers(_init6, 1, _ModuleLoaderService);
2411
+ _init7 = __decoratorStart(null);
2412
+ _ModuleLoaderService = __decorateElement(_init7, 0, "ModuleLoaderService", _ModuleLoaderService_decorators, _ModuleLoaderService);
2413
+ __runInitializers(_init7, 1, _ModuleLoaderService);
2226
2414
  var ModuleLoaderService = _ModuleLoaderService;
2227
2415
 
2228
2416
  // packages/core/src/attribute.factory.mts
@@ -2286,7 +2474,7 @@ var AttributeFactory = class {
2286
2474
  var import_cors = __toESM(require("@fastify/cors"), 1);
2287
2475
  var import_fastify = require("fastify");
2288
2476
  var import_fastify_type_provider_zod = require("fastify-type-provider-zod");
2289
- var _NaviosApplication_decorators, _init7;
2477
+ var _NaviosApplication_decorators, _init8;
2290
2478
  _NaviosApplication_decorators = [Injectable()];
2291
2479
  var _NaviosApplication = class _NaviosApplication {
2292
2480
  moduleLoader = syncInject(ModuleLoaderService);
@@ -2309,6 +2497,7 @@ var _NaviosApplication = class _NaviosApplication {
2309
2497
  }
2310
2498
  await this.moduleLoader.loadModules(this.appModule);
2311
2499
  this.server = await this.getFastifyInstance(this.options);
2500
+ this.configureFastifyInstance(this.server);
2312
2501
  getServiceLocator().registerInstance(Application, this.server);
2313
2502
  this.server.setValidatorCompiler(import_fastify_type_provider_zod.validatorCompiler);
2314
2503
  this.server.setSerializerCompiler(import_fastify_type_provider_zod.serializerCompiler);
@@ -2316,6 +2505,7 @@ var _NaviosApplication = class _NaviosApplication {
2316
2505
  await this.server.register(import_cors.default, this.corsOptions);
2317
2506
  }
2318
2507
  await this.initModules();
2508
+ await this.server.ready();
2319
2509
  this.logger.debug("Navios application initialized");
2320
2510
  }
2321
2511
  async getFastifyInstance(rawOptions) {
@@ -2345,6 +2535,35 @@ var _NaviosApplication = class _NaviosApplication {
2345
2535
  });
2346
2536
  }
2347
2537
  }
2538
+ configureFastifyInstance(fastifyInstance) {
2539
+ fastifyInstance.setErrorHandler((error, request, reply) => {
2540
+ if (error instanceof HttpException) {
2541
+ return reply.status(error.statusCode).send(error.response);
2542
+ } else {
2543
+ const statusCode = error.statusCode || 500;
2544
+ const message = error.message || "Internal Server Error";
2545
+ const response = {
2546
+ statusCode,
2547
+ message,
2548
+ error: error.name || "InternalServerError"
2549
+ };
2550
+ this.logger.error(
2551
+ `Error occurred: ${error.message} on ${request.url}`,
2552
+ error
2553
+ );
2554
+ return reply.status(statusCode).send(response);
2555
+ }
2556
+ });
2557
+ fastifyInstance.setNotFoundHandler((req, reply) => {
2558
+ const response = {
2559
+ statusCode: 404,
2560
+ message: "Not Found",
2561
+ error: "NotFound"
2562
+ };
2563
+ this.logger.error(`Route not found: ${req.url}`);
2564
+ return reply.status(404).send(response);
2565
+ });
2566
+ }
2348
2567
  async initModules() {
2349
2568
  const modules = this.moduleLoader.getAllModules();
2350
2569
  const promises = [];
@@ -2388,12 +2607,13 @@ var _NaviosApplication = class _NaviosApplication {
2388
2607
  if (!this.server) {
2389
2608
  throw new Error("Server is not initialized. Call init() first.");
2390
2609
  }
2391
- await this.server.listen(options);
2610
+ const res = await this.server.listen(options);
2611
+ this.logger.debug(`Navios is listening on ${res}`);
2392
2612
  }
2393
2613
  };
2394
- _init7 = __decoratorStart(null);
2395
- _NaviosApplication = __decorateElement(_init7, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
2396
- __runInitializers(_init7, 1, _NaviosApplication);
2614
+ _init8 = __decoratorStart(null);
2615
+ _NaviosApplication = __decorateElement(_init8, 0, "NaviosApplication", _NaviosApplication_decorators, _NaviosApplication);
2616
+ __runInitializers(_init8, 1, _NaviosApplication);
2397
2617
  var NaviosApplication = _NaviosApplication;
2398
2618
 
2399
2619
  // packages/core/src/navios.factory.mts
@@ -2419,6 +2639,11 @@ var NaviosFactory = class {
2419
2639
  Application,
2420
2640
  AttributeFactory,
2421
2641
  BadRequestException,
2642
+ ConfigProvider,
2643
+ ConfigProviderFactory,
2644
+ ConfigProviderInjectionToken,
2645
+ ConfigProviderOptions,
2646
+ ConfigServiceInstance,
2422
2647
  ConflictException,
2423
2648
  ConsoleLogger,
2424
2649
  Controller,
@@ -2426,6 +2651,7 @@ var NaviosFactory = class {
2426
2651
  ControllerMetadataKey,
2427
2652
  Endpoint,
2428
2653
  EndpointMetadataKey,
2654
+ EndpointType,
2429
2655
  ErrorsEnum,
2430
2656
  EventEmitter,
2431
2657
  ExecutionContext,
@@ -2434,6 +2660,8 @@ var NaviosFactory = class {
2434
2660
  FactoryNotFound,
2435
2661
  ForbiddenException,
2436
2662
  GuardRunnerService,
2663
+ Header,
2664
+ HttpCode,
2437
2665
  HttpException,
2438
2666
  Injectable,
2439
2667
  InjectableScope,
@@ -2469,6 +2697,8 @@ var NaviosFactory = class {
2469
2697
  UseGuards,
2470
2698
  addLeadingSlash,
2471
2699
  clc,
2700
+ envInt,
2701
+ envString,
2472
2702
  extractControllerMetadata,
2473
2703
  extractModuleMetadata,
2474
2704
  filterLogLevels,
@@ -2493,6 +2723,7 @@ var NaviosFactory = class {
2493
2723
  isString,
2494
2724
  isSymbol,
2495
2725
  isUndefined,
2726
+ makeConfigToken,
2496
2727
  normalizePath,
2497
2728
  override,
2498
2729
  provideServiceLocator,