fiberx-backend-toolkit 0.1.7 → 0.1.9

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.
@@ -431,7 +431,7 @@ ${attributes}
431
431
  ${schema_model_name}Schema.columns,
432
432
  {
433
433
  sequelize,
434
- table_name: ${schema_model_name}Schema.table_name,
434
+ tableName: ${schema_model_name}Schema.table_name,
435
435
  modelName: ${schema_model_name}Schema.model_name,
436
436
  timestamps: ${schema_model_name}Schema.timestamps,
437
437
  indexes: ${schema_model_name}Schema.indexes,
@@ -19,5 +19,6 @@ declare class AuthenicationMiddleWare<TRequestInfo extends DefaultRequestInfo =
19
19
  requireNoAuth(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
20
20
  requirePartialAuth(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
21
21
  requireFullAuth(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
22
+ requireAppAuthMiddleWareMethod(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
22
23
  }
23
24
  export default AuthenicationMiddleWare;
@@ -112,6 +112,13 @@ class AuthenicationMiddleWare {
112
112
  return this.options?.requireFullAuthMiddleWareMethod(req, res, next);
113
113
  }
114
114
  ;
115
+ async requireAppAuthMiddleWareMethod(req, res, next) {
116
+ if (!this.options?.requireAppAuthMiddleWareMethod) {
117
+ return next();
118
+ }
119
+ return this.options?.requireAppAuthMiddleWareMethod(req, res, next);
120
+ }
121
+ ;
115
122
  }
116
123
  __decorate([
117
124
  main_1.SafeExecuteUtil.safeExecuteReturn("authentication_middle_ware", null),
@@ -179,4 +186,10 @@ __decorate([
179
186
  __metadata("design:paramtypes", [Object, Object, Function]),
180
187
  __metadata("design:returntype", Promise)
181
188
  ], AuthenicationMiddleWare.prototype, "requireFullAuth", null);
189
+ __decorate([
190
+ main_1.SafeExecuteUtil.safeExecuteThrow("authentication_middle_ware"),
191
+ __metadata("design:type", Function),
192
+ __metadata("design:paramtypes", [Object, Object, Function]),
193
+ __metadata("design:returntype", Promise)
194
+ ], AuthenicationMiddleWare.prototype, "requireAppAuthMiddleWareMethod", null);
182
195
  exports.default = AuthenicationMiddleWare;
@@ -7,3 +7,4 @@ export * from "./module_type";
7
7
  export * from "./express_decelaration";
8
8
  export * from "./rbac_type";
9
9
  export * from "./mailer_type";
10
+ export * from "./validator_type";
@@ -23,3 +23,4 @@ __exportStar(require("./module_type"), exports);
23
23
  __exportStar(require("./express_decelaration"), exports);
24
24
  __exportStar(require("./rbac_type"), exports);
25
25
  __exportStar(require("./mailer_type"), exports);
26
+ __exportStar(require("./validator_type"), exports);
@@ -90,4 +90,5 @@ export interface AuthenticatorOptions<TRequestInfo extends DefaultRequestInfo =
90
90
  requireNoAuthMiddleWareMethod(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
91
91
  requirePartialAuthMiddleWareMethod(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
92
92
  requireFullAuthMiddleWareMethod(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
93
+ requireAppAuthMiddleWareMethod(req: Request, res: Response, next: NextFunction): Promise<void | Response>;
93
94
  }
@@ -0,0 +1,15 @@
1
+ export type QueryValueType = "string" | "number" | "boolean" | "enum" | "date" | "date-range" | "array" | "object";
2
+ export interface QueryFieldSchemaInterface<T = any> {
3
+ key: string;
4
+ type: QueryValueType;
5
+ required?: boolean;
6
+ default?: T;
7
+ enum_values?: readonly any[];
8
+ min?: number;
9
+ max?: number;
10
+ }
11
+ export interface QueryValidationResultInterface<T> {
12
+ v_state: boolean;
13
+ v_msg: string;
14
+ v_data?: T;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import QueryValidatorUtil from "./query_validator_util";
2
+ export { QueryValidatorUtil };
@@ -0,0 +1,8 @@
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
+ exports.QueryValidatorUtil = void 0;
7
+ const query_validator_util_1 = __importDefault(require("./query_validator_util"));
8
+ exports.QueryValidatorUtil = query_validator_util_1.default;
@@ -0,0 +1,6 @@
1
+ import { QueryFieldSchemaInterface, QueryValidationResultInterface } from "../types/validator_type";
2
+ declare class QueryValidatorUtil {
3
+ private constructor();
4
+ static validate<T extends Record<string, any>>(query: Record<string, any>, schema: QueryFieldSchemaInterface[]): QueryValidationResultInterface<T>;
5
+ }
6
+ export default QueryValidatorUtil;
@@ -0,0 +1,110 @@
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 dayjs_1 = __importDefault(require("dayjs"));
7
+ class QueryValidatorUtil {
8
+ constructor() { }
9
+ static validate(query, schema) {
10
+ const result = {};
11
+ for (const field of schema) {
12
+ const raw_value = query[field.key];
13
+ // Handle missing value
14
+ if (raw_value === undefined || raw_value === null || raw_value === "") {
15
+ if (field.required) {
16
+ return {
17
+ v_state: false,
18
+ v_msg: `missing_required_query_${field.key}`
19
+ };
20
+ }
21
+ result[field.key] = field.default ?? null;
22
+ continue;
23
+ }
24
+ switch (field.type) {
25
+ case "string": {
26
+ result[field.key] = String(raw_value);
27
+ break;
28
+ }
29
+ case "number": {
30
+ const num = Number(raw_value);
31
+ if (isNaN(num)) {
32
+ return { v_state: false, v_msg: `invalid_query_${field.key}` };
33
+ }
34
+ if (field.min !== undefined && num < field.min) {
35
+ return { v_state: false, v_msg: `invalid_query_${field.key}` };
36
+ }
37
+ if (field.max !== undefined && num > field.max) {
38
+ return { v_state: false, v_msg: `invalid_query_${field.key}` };
39
+ }
40
+ result[field.key] = num;
41
+ break;
42
+ }
43
+ case "boolean": {
44
+ const val = String(raw_value).toLowerCase();
45
+ if (!["true", "false"].includes(val)) {
46
+ return { v_state: false, v_msg: `invalid_query_${field.key}` };
47
+ }
48
+ result[field.key] = val === "true";
49
+ break;
50
+ }
51
+ case "enum": {
52
+ if (!field.enum_values?.includes(raw_value)) {
53
+ return { v_state: false, v_msg: `invalid_query_${field.key}` };
54
+ }
55
+ result[field.key] = raw_value;
56
+ break;
57
+ }
58
+ case "date": {
59
+ const parsed = (0, dayjs_1.default)(raw_value);
60
+ if (!parsed.isValid()) {
61
+ return { v_state: false, v_msg: `invalid_query_${field.key}` };
62
+ }
63
+ // Return as native Date (recommended for DB usage)
64
+ result[field.key] = parsed.toDate();
65
+ break;
66
+ }
67
+ case "date-range": {
68
+ const parts = String(raw_value).split(",");
69
+ if (parts.length !== 2) {
70
+ return { v_state: false, v_msg: `invalid_query_${field.key}` };
71
+ }
72
+ const start = (0, dayjs_1.default)(parts[0]);
73
+ const end = (0, dayjs_1.default)(parts[1]);
74
+ if (!start.isValid() || !end.isValid()) {
75
+ return { v_state: false, v_msg: `invalid_query_${field.key}` };
76
+ }
77
+ // ✅ Ensure end is after start
78
+ if (!end.isAfter(start)) {
79
+ return { v_state: false, v_msg: `invalid_query_${field.key}_range` };
80
+ }
81
+ result[field.key] = {
82
+ start_date: start.toDate(),
83
+ end_date: end.toDate()
84
+ };
85
+ break;
86
+ }
87
+ case "array": {
88
+ if (!Array.isArray(raw_value)) {
89
+ return { v_state: false, v_msg: `invalid_query_${field.key}` };
90
+ }
91
+ result[field.key] = raw_value;
92
+ break;
93
+ }
94
+ case "object": {
95
+ if (typeof raw_value !== "object") {
96
+ return { v_state: false, v_msg: `invalid_query_${field.key}` };
97
+ }
98
+ result[field.key] = raw_value;
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ return {
104
+ v_state: true,
105
+ v_msg: "valid_query_params",
106
+ v_data: result
107
+ };
108
+ }
109
+ }
110
+ exports.default = QueryValidatorUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiberx-backend-toolkit",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
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",