@exyconn/common 2.3.4 → 2.3.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/client/http/index.js +1 -3
- package/dist/client/http/index.js.map +1 -1
- package/dist/client/http/index.mjs +1 -3
- package/dist/client/http/index.mjs.map +1 -1
- package/dist/client/index.js +4 -4
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +4 -4
- package/dist/client/index.mjs.map +1 -1
- package/dist/client/logger/index.js +3 -1
- package/dist/client/logger/index.js.map +1 -1
- package/dist/client/logger/index.mjs +3 -1
- package/dist/client/logger/index.mjs.map +1 -1
- package/dist/client/utils/index.js +3 -3
- package/dist/client/utils/index.js.map +1 -1
- package/dist/client/utils/index.mjs +3 -3
- package/dist/client/utils/index.mjs.map +1 -1
- package/dist/{index-Ckhm_HaX.d.mts → index-B8O4iu6q.d.mts} +7 -2
- package/dist/{index-br6POSyA.d.ts → index-MpV0UNTq.d.ts} +7 -2
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +171 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +168 -17
- package/dist/index.mjs.map +1 -1
- package/dist/server/configs/index.js +3 -0
- package/dist/server/configs/index.js.map +1 -1
- package/dist/server/configs/index.mjs +3 -0
- package/dist/server/configs/index.mjs.map +1 -1
- package/dist/server/index.d.mts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +161 -8
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +156 -8
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/middleware/index.js +3 -3
- package/dist/server/middleware/index.js.map +1 -1
- package/dist/server/middleware/index.mjs +3 -3
- package/dist/server/middleware/index.mjs.map +1 -1
- package/dist/server/utils/index.d.mts +99 -1
- package/dist/server/utils/index.d.ts +99 -1
- package/dist/server/utils/index.js +154 -0
- package/dist/server/utils/index.js.map +1 -1
- package/dist/server/utils/index.mjs +148 -3
- package/dist/server/utils/index.mjs.map +1 -1
- package/package.json +25 -25
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import winston from 'winston';
|
|
2
2
|
import DailyRotateFile from 'winston-daily-rotate-file';
|
|
3
|
-
import
|
|
3
|
+
import path2, { resolve } from 'path';
|
|
4
4
|
import mongoose, { Types } from 'mongoose';
|
|
5
5
|
import jwt from 'jsonwebtoken';
|
|
6
|
-
import { existsSync, readFileSync } from 'fs';
|
|
6
|
+
import fs, { existsSync, readFileSync } from 'fs';
|
|
7
|
+
import os from 'os';
|
|
7
8
|
import rateLimit from 'express-rate-limit';
|
|
8
9
|
import axios from 'axios';
|
|
9
10
|
import { createContext, useState, useCallback, useMemo, useRef, useEffect, useContext } from 'react';
|
|
@@ -58,12 +59,14 @@ __export(server_exports, {
|
|
|
58
59
|
createCorsOptions: () => createCorsOptions,
|
|
59
60
|
createCrudControllers: () => createCrudControllers,
|
|
60
61
|
createDdosRateLimiter: () => createDdosRateLimiter,
|
|
62
|
+
createHealthHandler: () => createHealthHandler,
|
|
61
63
|
createLogger: () => createLogger,
|
|
62
64
|
createMorganStream: () => createMorganStream,
|
|
63
65
|
createMultiBrandCorsOptions: () => createMultiBrandCorsOptions,
|
|
64
66
|
createPaginationMiddleware: () => createPaginationMiddleware,
|
|
65
67
|
createPrefixedKeyGenerator: () => createPrefixedKeyGenerator,
|
|
66
68
|
createRateLimiter: () => createRateLimiter,
|
|
69
|
+
createRootHandler: () => createRootHandler,
|
|
67
70
|
createStandardRateLimiter: () => createStandardRateLimiter,
|
|
68
71
|
createStrictRateLimiter: () => createStrictRateLimiter,
|
|
69
72
|
createUserKeyGenerator: () => createUserKeyGenerator,
|
|
@@ -77,6 +80,7 @@ __export(server_exports, {
|
|
|
77
80
|
extractSchemaMeta: () => extractSchemaMeta,
|
|
78
81
|
forbiddenResponse: () => forbiddenResponse,
|
|
79
82
|
formatPackageCheckResult: () => formatPackageCheckResult,
|
|
83
|
+
generateHealthResponse: () => generateHealthResponse,
|
|
80
84
|
generateNcuCommand: () => generateNcuCommand,
|
|
81
85
|
getConnectionStatus: () => getConnectionStatus,
|
|
82
86
|
getDatabaseOptions: () => getDatabaseOptions,
|
|
@@ -321,7 +325,7 @@ var createLogger = (config = {}) => {
|
|
|
321
325
|
}),
|
|
322
326
|
// Combined logs (all levels)
|
|
323
327
|
new DailyRotateFile({
|
|
324
|
-
filename:
|
|
328
|
+
filename: path2.join(finalConfig.logsDir, "combined-%DATE%.log"),
|
|
325
329
|
datePattern: "YYYY-MM-DD",
|
|
326
330
|
maxSize: finalConfig.maxSize,
|
|
327
331
|
maxFiles: finalConfig.maxFiles,
|
|
@@ -329,7 +333,7 @@ var createLogger = (config = {}) => {
|
|
|
329
333
|
}),
|
|
330
334
|
// Error logs only
|
|
331
335
|
new DailyRotateFile({
|
|
332
|
-
filename:
|
|
336
|
+
filename: path2.join(finalConfig.logsDir, "error-%DATE%.log"),
|
|
333
337
|
datePattern: "YYYY-MM-DD",
|
|
334
338
|
level: "error",
|
|
335
339
|
maxSize: finalConfig.maxSize,
|
|
@@ -790,7 +794,7 @@ function createCrudControllers(config) {
|
|
|
790
794
|
};
|
|
791
795
|
const getById = async (req, res, _next) => {
|
|
792
796
|
try {
|
|
793
|
-
const
|
|
797
|
+
const id = req.params.id;
|
|
794
798
|
if (!id || !Types.ObjectId.isValid(id)) {
|
|
795
799
|
badRequestResponse(res, "Invalid ID format");
|
|
796
800
|
return;
|
|
@@ -865,7 +869,7 @@ function createCrudControllers(config) {
|
|
|
865
869
|
};
|
|
866
870
|
const update = async (req, res, _next) => {
|
|
867
871
|
try {
|
|
868
|
-
const
|
|
872
|
+
const id = req.params.id;
|
|
869
873
|
if (!id || !Types.ObjectId.isValid(id)) {
|
|
870
874
|
badRequestResponse(res, "Invalid ID format");
|
|
871
875
|
return;
|
|
@@ -909,7 +913,7 @@ function createCrudControllers(config) {
|
|
|
909
913
|
};
|
|
910
914
|
const deleteOne = async (req, res, _next) => {
|
|
911
915
|
try {
|
|
912
|
-
const
|
|
916
|
+
const id = req.params.id;
|
|
913
917
|
if (!id || !Types.ObjectId.isValid(id)) {
|
|
914
918
|
badRequestResponse(res, "Invalid ID format");
|
|
915
919
|
return;
|
|
@@ -1438,6 +1442,150 @@ var packageCheckServer = {
|
|
|
1438
1442
|
generateNcuCommand,
|
|
1439
1443
|
print: printPackageCheckSummary
|
|
1440
1444
|
};
|
|
1445
|
+
var serverStartTime = Date.now();
|
|
1446
|
+
function getTimezoneOffset() {
|
|
1447
|
+
const offset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
1448
|
+
const hours = Math.floor(Math.abs(offset) / 60);
|
|
1449
|
+
const minutes = Math.abs(offset) % 60;
|
|
1450
|
+
const sign = offset <= 0 ? "+" : "-";
|
|
1451
|
+
return `${sign}${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}`;
|
|
1452
|
+
}
|
|
1453
|
+
function getTimezoneName() {
|
|
1454
|
+
try {
|
|
1455
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1456
|
+
} catch {
|
|
1457
|
+
return "UTC";
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
function getPackageInfo(criticalPackages = []) {
|
|
1461
|
+
try {
|
|
1462
|
+
const possiblePaths = [
|
|
1463
|
+
path2.join(process.cwd(), "package.json"),
|
|
1464
|
+
path2.join(__dirname, "..", "..", "..", "..", "package.json"),
|
|
1465
|
+
path2.join(__dirname, "..", "..", "package.json")
|
|
1466
|
+
];
|
|
1467
|
+
for (const pkgPath of possiblePaths) {
|
|
1468
|
+
if (fs.existsSync(pkgPath)) {
|
|
1469
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
1470
|
+
const deps = pkg.dependencies || {};
|
|
1471
|
+
const devDeps = pkg.devDependencies || {};
|
|
1472
|
+
const total = Object.keys(deps).length + Object.keys(devDeps).length;
|
|
1473
|
+
const critical = {};
|
|
1474
|
+
for (const pkgName of criticalPackages) {
|
|
1475
|
+
if (deps[pkgName]) {
|
|
1476
|
+
critical[pkgName] = deps[pkgName].replace("^", "").replace("~", "");
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
return { total, critical };
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
} catch {
|
|
1483
|
+
}
|
|
1484
|
+
return { total: 0, critical: {} };
|
|
1485
|
+
}
|
|
1486
|
+
async function generateHealthResponse(config) {
|
|
1487
|
+
const startTime = Date.now();
|
|
1488
|
+
const now = /* @__PURE__ */ new Date();
|
|
1489
|
+
let dependencies = {};
|
|
1490
|
+
if (config.checkDependencies) {
|
|
1491
|
+
try {
|
|
1492
|
+
dependencies = await config.checkDependencies();
|
|
1493
|
+
} catch {
|
|
1494
|
+
dependencies = { error: "DOWN" };
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
const hasDownDep = Object.values(dependencies).includes("DOWN");
|
|
1498
|
+
const status = hasDownDep ? "DEGRADED" : "UP";
|
|
1499
|
+
const defaultCriticalPackages = ["express", "mongoose", "cors", "dotenv"];
|
|
1500
|
+
const packageInfo = getPackageInfo(config.criticalPackages || defaultCriticalPackages);
|
|
1501
|
+
const totalMem = os.totalmem();
|
|
1502
|
+
const freeMem = os.freemem();
|
|
1503
|
+
const usedMem = totalMem - freeMem;
|
|
1504
|
+
const isProduction2 = process.env.NODE_ENV === "production";
|
|
1505
|
+
const serverUrl = isProduction2 ? `https://${config.domain}` : `http://localhost:${config.port}`;
|
|
1506
|
+
const response = {
|
|
1507
|
+
status,
|
|
1508
|
+
app: config.name,
|
|
1509
|
+
env: process.env.NODE_ENV || "development",
|
|
1510
|
+
version: config.version,
|
|
1511
|
+
urls: {
|
|
1512
|
+
...config.uiUrl && { ui: config.uiUrl },
|
|
1513
|
+
server: config.serverUrl || serverUrl,
|
|
1514
|
+
health: `${config.serverUrl || serverUrl}/health`
|
|
1515
|
+
},
|
|
1516
|
+
time: {
|
|
1517
|
+
serverTime: now.toISOString(),
|
|
1518
|
+
timezone: getTimezoneName(),
|
|
1519
|
+
offset: getTimezoneOffset(),
|
|
1520
|
+
epoch: Math.floor(now.getTime() / 1e3)
|
|
1521
|
+
},
|
|
1522
|
+
uptimeSec: Math.floor((Date.now() - serverStartTime) / 1e3),
|
|
1523
|
+
node: {
|
|
1524
|
+
version: process.version,
|
|
1525
|
+
platform: os.platform(),
|
|
1526
|
+
arch: os.arch()
|
|
1527
|
+
},
|
|
1528
|
+
system: {
|
|
1529
|
+
hostname: os.hostname(),
|
|
1530
|
+
memoryUsedMB: Math.round(usedMem / 1024 / 1024),
|
|
1531
|
+
memoryTotalMB: Math.round(totalMem / 1024 / 1024),
|
|
1532
|
+
memoryFreePercent: Math.round(freeMem / totalMem * 100),
|
|
1533
|
+
cpuLoad: os.loadavg().map((l) => Math.round(l * 100) / 100),
|
|
1534
|
+
cpuCount: os.cpus().length
|
|
1535
|
+
},
|
|
1536
|
+
packages: {
|
|
1537
|
+
appVersion: config.version,
|
|
1538
|
+
totalDependencies: packageInfo.total,
|
|
1539
|
+
critical: packageInfo.critical
|
|
1540
|
+
},
|
|
1541
|
+
dependencies,
|
|
1542
|
+
...config.infra && { infra: config.infra },
|
|
1543
|
+
responseTimeMs: Date.now() - startTime
|
|
1544
|
+
};
|
|
1545
|
+
return response;
|
|
1546
|
+
}
|
|
1547
|
+
function createHealthHandler(config) {
|
|
1548
|
+
return async (_req, res) => {
|
|
1549
|
+
try {
|
|
1550
|
+
const health = await generateHealthResponse(config);
|
|
1551
|
+
const statusCode2 = health.status === "UP" ? 200 : health.status === "DEGRADED" ? 200 : 503;
|
|
1552
|
+
res.status(statusCode2).json(health);
|
|
1553
|
+
} catch (error) {
|
|
1554
|
+
res.status(503).json({
|
|
1555
|
+
status: "DOWN",
|
|
1556
|
+
app: config.name,
|
|
1557
|
+
env: process.env.NODE_ENV || "development",
|
|
1558
|
+
version: config.version,
|
|
1559
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
1560
|
+
time: {
|
|
1561
|
+
serverTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1562
|
+
timezone: getTimezoneName(),
|
|
1563
|
+
offset: getTimezoneOffset(),
|
|
1564
|
+
epoch: Math.floor(Date.now() / 1e3)
|
|
1565
|
+
}
|
|
1566
|
+
});
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
function createRootHandler(config) {
|
|
1571
|
+
return async (_req, res) => {
|
|
1572
|
+
try {
|
|
1573
|
+
const health = await generateHealthResponse(config);
|
|
1574
|
+
res.json({
|
|
1575
|
+
message: `Welcome to ${config.name}`,
|
|
1576
|
+
description: config.description || `${config.name} API Server`,
|
|
1577
|
+
...config.endpoints && { endpoints: config.endpoints },
|
|
1578
|
+
...health
|
|
1579
|
+
});
|
|
1580
|
+
} catch (error) {
|
|
1581
|
+
res.status(503).json({
|
|
1582
|
+
status: "DOWN",
|
|
1583
|
+
app: config.name,
|
|
1584
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1441
1589
|
|
|
1442
1590
|
// src/server/configs/cors.config.ts
|
|
1443
1591
|
var DEFAULT_CORS_CONFIG = {
|
|
@@ -1719,6 +1867,8 @@ var createApiRateLimiter = (config = {}, options = {}) => {
|
|
|
1719
1867
|
});
|
|
1720
1868
|
};
|
|
1721
1869
|
var RateLimiterBuilder = class {
|
|
1870
|
+
config;
|
|
1871
|
+
options;
|
|
1722
1872
|
constructor(preset = "STANDARD") {
|
|
1723
1873
|
const presetConfig = DEFAULT_RATE_LIMIT_TIERS[preset];
|
|
1724
1874
|
this.config = {
|
|
@@ -1920,6 +2070,7 @@ function deepMerge(target, source) {
|
|
|
1920
2070
|
return result;
|
|
1921
2071
|
}
|
|
1922
2072
|
var ConfigBuilder = class {
|
|
2073
|
+
config;
|
|
1923
2074
|
constructor() {
|
|
1924
2075
|
this.config = {
|
|
1925
2076
|
server: { ...DEFAULT_SERVER_CONFIG },
|
|
@@ -2281,9 +2432,7 @@ __export(client_exports, {
|
|
|
2281
2432
|
|
|
2282
2433
|
// src/client/http/logger.ts
|
|
2283
2434
|
var Logger = class {
|
|
2284
|
-
|
|
2285
|
-
this.isDevelopment = typeof window !== "undefined" && window.location.hostname === "localhost";
|
|
2286
|
-
}
|
|
2435
|
+
isDevelopment = typeof window !== "undefined" && window.location.hostname === "localhost";
|
|
2287
2436
|
/**
|
|
2288
2437
|
* Log informational messages
|
|
2289
2438
|
*/
|
|
@@ -2496,9 +2645,9 @@ var parsePaginatedResponse = (response) => {
|
|
|
2496
2645
|
return { items: [], total: 0, page: 1, limit: 10 };
|
|
2497
2646
|
}
|
|
2498
2647
|
};
|
|
2499
|
-
var extractNestedData = (response,
|
|
2648
|
+
var extractNestedData = (response, path3, fallback = null) => {
|
|
2500
2649
|
try {
|
|
2501
|
-
const keys =
|
|
2650
|
+
const keys = path3.split(".");
|
|
2502
2651
|
let current = response;
|
|
2503
2652
|
for (const key of keys) {
|
|
2504
2653
|
if (current && typeof current === "object" && key in current) {
|
|
@@ -2829,8 +2978,10 @@ var LOG_LEVELS = {
|
|
|
2829
2978
|
error: 3
|
|
2830
2979
|
};
|
|
2831
2980
|
var ClientLogger = class {
|
|
2981
|
+
config;
|
|
2982
|
+
buffer = [];
|
|
2983
|
+
flushTimer;
|
|
2832
2984
|
constructor(config = {}) {
|
|
2833
|
-
this.buffer = [];
|
|
2834
2985
|
this.config = {
|
|
2835
2986
|
enabled: config.enabled ?? process.env.NODE_ENV !== "production",
|
|
2836
2987
|
minLevel: config.minLevel ?? "debug",
|
|
@@ -6632,11 +6783,11 @@ function getContrastColor(hex) {
|
|
|
6632
6783
|
}
|
|
6633
6784
|
function flattenToCssVars(obj, prefix = "--ec") {
|
|
6634
6785
|
const result = {};
|
|
6635
|
-
function flatten(current,
|
|
6786
|
+
function flatten(current, path3 = []) {
|
|
6636
6787
|
for (const key in current) {
|
|
6637
6788
|
if (Object.prototype.hasOwnProperty.call(current, key)) {
|
|
6638
6789
|
const value = current[key];
|
|
6639
|
-
const newPath = [...
|
|
6790
|
+
const newPath = [...path3, key];
|
|
6640
6791
|
const varName = `${prefix}-${newPath.join("-")}`;
|
|
6641
6792
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
6642
6793
|
flatten(value, newPath);
|
|
@@ -6894,8 +7045,8 @@ function ThemeProvider({
|
|
|
6894
7045
|
);
|
|
6895
7046
|
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: contextValue, children });
|
|
6896
7047
|
}
|
|
6897
|
-
function cssVar(
|
|
6898
|
-
return `var(${prefix}-${
|
|
7048
|
+
function cssVar(path3, prefix = "--ec") {
|
|
7049
|
+
return `var(${prefix}-${path3.replace(/\./g, "-")})`;
|
|
6899
7050
|
}
|
|
6900
7051
|
function useThemeValue(selector) {
|
|
6901
7052
|
const { theme } = useTheme();
|