elseware-nodejs 1.7.4 → 1.7.6

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.d.cts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as express from 'express';
2
2
  import { Request, Response, NextFunction } from 'express';
3
3
  import { Model, PopulateOptions, Query } from 'mongoose';
4
- import Joi, { Schema } from 'joi';
4
+ import { ZodSchema } from 'zod';
5
5
  import { CorsOptions } from 'cors';
6
+ import { Schema } from 'joi';
6
7
  import { SignOptions, JwtPayload } from 'jsonwebtoken';
7
8
 
8
9
  /**
@@ -75,11 +76,10 @@ interface DatabaseConfig {
75
76
  }
76
77
  declare function connectMongoDB(config: DatabaseConfig): Promise<void>;
77
78
 
78
- /**
79
- * Generic env loader for Elseware apps
80
- * App provides its own Joi schema
81
- */
82
- declare function loadEnv<T>(schema: Joi.ObjectSchema<T>): T;
79
+ declare function loadEnv(options: {
80
+ schema: ZodSchema;
81
+ transform?: (env: any) => any;
82
+ }): any;
83
83
 
84
84
  interface LoggerOptions {
85
85
  timestamp?: boolean;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as express from 'express';
2
2
  import { Request, Response, NextFunction } from 'express';
3
3
  import { Model, PopulateOptions, Query } from 'mongoose';
4
- import Joi, { Schema } from 'joi';
4
+ import { ZodSchema } from 'zod';
5
5
  import { CorsOptions } from 'cors';
6
+ import { Schema } from 'joi';
6
7
  import { SignOptions, JwtPayload } from 'jsonwebtoken';
7
8
 
8
9
  /**
@@ -75,11 +76,10 @@ interface DatabaseConfig {
75
76
  }
76
77
  declare function connectMongoDB(config: DatabaseConfig): Promise<void>;
77
78
 
78
- /**
79
- * Generic env loader for Elseware apps
80
- * App provides its own Joi schema
81
- */
82
- declare function loadEnv<T>(schema: Joi.ObjectSchema<T>): T;
79
+ declare function loadEnv(options: {
80
+ schema: ZodSchema;
81
+ transform?: (env: any) => any;
82
+ }): any;
83
83
 
84
84
  interface LoggerOptions {
85
85
  timestamp?: boolean;
package/dist/index.js CHANGED
@@ -284,7 +284,7 @@ var Logger = class {
284
284
  this.output(`\u2705 ${msg}`);
285
285
  }
286
286
  info(msg) {
287
- this.output(`\u2139\uFE0F ${msg}`);
287
+ this.output(`\u{1F539} ${msg}`);
288
288
  }
289
289
  warning(msg) {
290
290
  this.output(`\u26A0\uFE0F ${msg}`);
@@ -322,17 +322,31 @@ async function connectMongoDB(config) {
322
322
  process.exit(1);
323
323
  }
324
324
  }
325
- dotenv.config({ quiet: true });
326
- function loadEnv(schema) {
327
- const { value, error } = schema.validate(process.env, {
328
- abortEarly: false,
329
- allowUnknown: true
325
+ dotenv.config();
326
+ function loadEnv(options) {
327
+ const result = options.schema.safeParse(process.env);
328
+ if (!result.success) {
329
+ handleError(result.error);
330
+ }
331
+ logger.success("Env Configurations validated");
332
+ return options.transform ? options.transform(result.data) : result.data;
333
+ }
334
+ function handleError(error) {
335
+ logger.danger("ENV VALIDATION FAILED");
336
+ const grouped = {};
337
+ error.issues.forEach((err) => {
338
+ const key = err.path.join(".") || "unknown";
339
+ if (!grouped[key]) grouped[key] = [];
340
+ grouped[key].push(err.message);
330
341
  });
331
- if (error) {
332
- throw new Error(`\u274C Env validation error: ${error.message}`);
333
- }
334
- logger.success("Configurations passed");
335
- return value;
342
+ Object.entries(grouped).forEach(([key, messages]) => {
343
+ logger.info(`${key}`);
344
+ messages.forEach((msg) => {
345
+ logger.log(`${msg}`);
346
+ });
347
+ });
348
+ logger.danger("Application startup aborted.\n");
349
+ process.exit(1);
336
350
  }
337
351
 
338
352
  // src/configs/cors/allowedOrigins.ts
@@ -5424,7 +5438,7 @@ var JWTService = class {
5424
5438
  try {
5425
5439
  return jwt.verify(token, this.accessSecret);
5426
5440
  } catch (err) {
5427
- console.error("Access token verification failed:", err.message);
5441
+ logger.danger("Access token verification failed:", err.message);
5428
5442
  return null;
5429
5443
  }
5430
5444
  }
@@ -5432,7 +5446,7 @@ var JWTService = class {
5432
5446
  try {
5433
5447
  return jwt.verify(token, this.refreshSecret);
5434
5448
  } catch (err) {
5435
- console.error("Refresh token verification failed:", err.message);
5449
+ logger.danger("Refresh token verification failed:", err.message);
5436
5450
  return null;
5437
5451
  }
5438
5452
  }