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 +24 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +24 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
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
|
|
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
|
-
|
|
80
|
-
|
|
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
|
|
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
|
-
|
|
80
|
-
|
|
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
|
@@ -322,17 +322,31 @@ async function connectMongoDB(config) {
|
|
|
322
322
|
process.exit(1);
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
|
-
dotenv.config(
|
|
326
|
-
function loadEnv(
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
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("\u2705 Env Configurations validated");
|
|
332
|
+
return options.transform ? options.transform(result.data) : result.data;
|
|
333
|
+
}
|
|
334
|
+
function handleError(error) {
|
|
335
|
+
console.error("\u274C 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
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
342
|
+
Object.entries(grouped).forEach(([key, messages]) => {
|
|
343
|
+
console.error(`\u{1F539} ${key}`);
|
|
344
|
+
messages.forEach((msg) => {
|
|
345
|
+
console.error(` - ${msg}`);
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
console.error("\u{1F6AB} Application startup aborted.\n");
|
|
349
|
+
process.exit(1);
|
|
336
350
|
}
|
|
337
351
|
|
|
338
352
|
// src/configs/cors/allowedOrigins.ts
|