fiberx-backend-toolkit 0.0.73 → 0.0.74

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.
@@ -21,7 +21,7 @@ class RequestLoggerMiddleWare {
21
21
  // -------------------------
22
22
  async middleWare(req, res, next) {
23
23
  const origin = req.headers.origin || (req.headers.referer ? new URL(req.headers.referer).origin : "unknown");
24
- const device_id = req.headers["x-device-id"] || "unknown";
24
+ const device_id = req.cookies?.device_id || req.headers["x-device-id"] || "unknown";
25
25
  const device_name = req.headers["x-device-name"] || "unknown";
26
26
  const user_agent = req.headers["user-agent"] || "unknown";
27
27
  const request_id = req.cookies?.request_id ?? null;
@@ -0,0 +1,14 @@
1
+ declare class FSActionUtil {
2
+ private static validateSafePath;
3
+ static exists(target_path: string): Promise<boolean>;
4
+ static createDirectory(dir_path: string, recursive?: boolean): Promise<void>;
5
+ static renameDirectory(old_path: string, new_path: string): Promise<void>;
6
+ static deleteDirectory(dir_path: string): Promise<void>;
7
+ static clearDirectory(dir_path: string): Promise<void>;
8
+ static readDirectory(dir_path: string, withStats?: boolean): Promise<string[] | {
9
+ name: string;
10
+ isFile: boolean;
11
+ isDirectory: boolean;
12
+ }[]>;
13
+ }
14
+ export default FSActionUtil;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = require("fs");
7
+ const path_1 = __importDefault(require("path"));
8
+ class FSActionUtil {
9
+ // ==============================
10
+ // Private Safety Guard
11
+ // ==============================
12
+ static validateSafePath(target_path) {
13
+ if (!target_path || target_path === "/" || target_path.length < 3) {
14
+ throw new Error(`Unsafe path operation attempted: ${target_path}`);
15
+ }
16
+ }
17
+ // ==============================
18
+ // Check if path exists
19
+ // ==============================
20
+ static async exists(target_path) {
21
+ try {
22
+ await fs_1.promises.access(target_path);
23
+ return true;
24
+ }
25
+ catch {
26
+ return false;
27
+ }
28
+ }
29
+ // ==============================
30
+ // Create Directory
31
+ // ==============================
32
+ static async createDirectory(dir_path, recursive = true) {
33
+ this.validateSafePath(dir_path);
34
+ await fs_1.promises.mkdir(dir_path, { recursive });
35
+ }
36
+ // ==============================
37
+ // Rename Directory
38
+ // ==============================
39
+ static async renameDirectory(old_path, new_path) {
40
+ this.validateSafePath(old_path);
41
+ this.validateSafePath(new_path);
42
+ await fs_1.promises.rename(old_path, new_path);
43
+ }
44
+ // ==============================
45
+ // Delete Directory (entire)
46
+ // ==============================
47
+ static async deleteDirectory(dir_path) {
48
+ this.validateSafePath(dir_path);
49
+ await fs_1.promises.rm(dir_path, {
50
+ recursive: true,
51
+ force: true,
52
+ });
53
+ }
54
+ // ==============================
55
+ // Clear Directory (keep folder)
56
+ // ==============================
57
+ static async clearDirectory(dir_path) {
58
+ this.validateSafePath(dir_path);
59
+ const exists = await this.exists(dir_path);
60
+ if (!exists)
61
+ return;
62
+ const entries = await fs_1.promises.readdir(dir_path);
63
+ await Promise.all(entries.map(entry => fs_1.promises.rm(path_1.default.join(dir_path, entry), {
64
+ recursive: true,
65
+ force: true,
66
+ })));
67
+ }
68
+ // ==============================
69
+ // Read Directory Contents
70
+ // ==============================
71
+ static async readDirectory(dir_path, withStats = false) {
72
+ this.validateSafePath(dir_path);
73
+ const entries = await fs_1.promises.readdir(dir_path);
74
+ if (!withStats) {
75
+ return entries;
76
+ }
77
+ const detailed = await Promise.all(entries.map(async (entry) => {
78
+ const fullPath = path_1.default.join(dir_path, entry);
79
+ const stats = await fs_1.promises.stat(fullPath);
80
+ return {
81
+ name: entry,
82
+ isFile: stats.isFile(),
83
+ isDirectory: stats.isDirectory(),
84
+ };
85
+ }));
86
+ return detailed;
87
+ }
88
+ }
89
+ exports.default = FSActionUtil;
@@ -10,4 +10,5 @@ import UUIDGeneratorUtil from "./uuid_gen_util";
10
10
  import EncryptorDecryptorUtil from "./encryptor_decryptor_util";
11
11
  import TOTPServiceUtil from "./totp_service_util";
12
12
  import ContentManagerUtil from "./content_manager_util";
13
- export { LoggerUtil, InputTransformerUtil, InputValidatorUtil, EnvManagerUtil, SqlFormatterUtil, ServerUtil, SafeExecuteUtil, InMemoryCacheUtil, UUIDGeneratorUtil, EncryptorDecryptorUtil, TOTPServiceUtil, ContentManagerUtil };
13
+ import FsActionsUtil from "./fs_actions_util";
14
+ export { LoggerUtil, InputTransformerUtil, InputValidatorUtil, EnvManagerUtil, SqlFormatterUtil, ServerUtil, SafeExecuteUtil, InMemoryCacheUtil, UUIDGeneratorUtil, EncryptorDecryptorUtil, TOTPServiceUtil, ContentManagerUtil, FsActionsUtil };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ContentManagerUtil = exports.TOTPServiceUtil = exports.EncryptorDecryptorUtil = exports.UUIDGeneratorUtil = exports.InMemoryCacheUtil = exports.SafeExecuteUtil = exports.ServerUtil = exports.SqlFormatterUtil = exports.EnvManagerUtil = exports.InputValidatorUtil = exports.InputTransformerUtil = exports.LoggerUtil = void 0;
6
+ exports.FsActionsUtil = exports.ContentManagerUtil = exports.TOTPServiceUtil = exports.EncryptorDecryptorUtil = exports.UUIDGeneratorUtil = exports.InMemoryCacheUtil = exports.SafeExecuteUtil = exports.ServerUtil = exports.SqlFormatterUtil = exports.EnvManagerUtil = exports.InputValidatorUtil = exports.InputTransformerUtil = exports.LoggerUtil = void 0;
7
7
  const logger_util_1 = __importDefault(require("./logger_util"));
8
8
  exports.LoggerUtil = logger_util_1.default;
9
9
  const input_transformer_util_1 = __importDefault(require("./input_transformer_util"));
@@ -28,3 +28,5 @@ const totp_service_util_1 = __importDefault(require("./totp_service_util"));
28
28
  exports.TOTPServiceUtil = totp_service_util_1.default;
29
29
  const content_manager_util_1 = __importDefault(require("./content_manager_util"));
30
30
  exports.ContentManagerUtil = content_manager_util_1.default;
31
+ const fs_actions_util_1 = __importDefault(require("./fs_actions_util"));
32
+ exports.FsActionsUtil = fs_actions_util_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiberx-backend-toolkit",
3
- "version": "0.0.73",
3
+ "version": "0.0.74",
4
4
  "description": "A TypeScript backend toolkit providing shared domain logic, infrastructure helpers, and utilities for FiberX server-side applications and services.",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",