elseware-nodejs 1.7.4 → 1.7.5

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
@@ -337,17 +337,31 @@ async function connectMongoDB(config) {
337
337
  process.exit(1);
338
338
  }
339
339
  }
340
- dotenv__default.default.config({ quiet: true });
341
- function loadEnv(schema) {
342
- const { value, error } = schema.validate(process.env, {
343
- abortEarly: false,
344
- allowUnknown: true
340
+ dotenv__default.default.config();
341
+ function loadEnv(options) {
342
+ const result = options.schema.safeParse(process.env);
343
+ if (!result.success) {
344
+ handleError(result.error);
345
+ }
346
+ logger.success("\u2705 Env Configurations validated");
347
+ return options.transform ? options.transform(result.data) : result.data;
348
+ }
349
+ function handleError(error) {
350
+ console.error("\u274C ENV VALIDATION FAILED");
351
+ const grouped = {};
352
+ error.issues.forEach((err) => {
353
+ const key = err.path.join(".") || "unknown";
354
+ if (!grouped[key]) grouped[key] = [];
355
+ grouped[key].push(err.message);
345
356
  });
346
- if (error) {
347
- throw new Error(`\u274C Env validation error: ${error.message}`);
348
- }
349
- logger.success("Configurations passed");
350
- return value;
357
+ Object.entries(grouped).forEach(([key, messages]) => {
358
+ console.error(`\u{1F539} ${key}`);
359
+ messages.forEach((msg) => {
360
+ console.error(` - ${msg}`);
361
+ });
362
+ });
363
+ console.error("\u{1F6AB} Application startup aborted.\n");
364
+ process.exit(1);
351
365
  }
352
366
 
353
367
  // src/configs/cors/allowedOrigins.ts