tezx 2.0.3 → 2.0.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/bun/index.d.ts CHANGED
@@ -1,2 +1,9 @@
1
- export * from "./adapter.js";
1
+ import { loadEnv } from "../node/env.js";
2
+ import { bunAdapter } from "./adapter.js";
2
3
  export * from "../node/env.js";
4
+ export * from "./adapter.js";
5
+ declare const _default: {
6
+ bunAdapter: typeof bunAdapter;
7
+ loadEnv: typeof loadEnv;
8
+ };
9
+ export default _default;
package/bun/index.js CHANGED
@@ -1,2 +1,8 @@
1
- export * from "./adapter.js";
1
+ import { loadEnv } from "../node/env.js";
2
+ import { bunAdapter } from "./adapter.js";
2
3
  export * from "../node/env.js";
4
+ export * from "./adapter.js";
5
+ export default {
6
+ bunAdapter,
7
+ loadEnv,
8
+ };
package/cjs/bun/index.js CHANGED
@@ -14,5 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./adapter.js"), exports);
17
+ const env_js_1 = require("../node/env.js");
18
+ const adapter_js_1 = require("./adapter.js");
18
19
  __exportStar(require("../node/env.js"), exports);
20
+ __exportStar(require("./adapter.js"), exports);
21
+ exports.default = {
22
+ bunAdapter: adapter_js_1.bunAdapter,
23
+ loadEnv: env_js_1.loadEnv,
24
+ };
@@ -128,7 +128,7 @@ class TezX extends router_js_1.Router {
128
128
  return res;
129
129
  }
130
130
  if (!res && !ctx.body) {
131
- throw new Error(`Handler failed: Middleware chain incomplete or response missing. Did you forget ${colors_js_1.COLORS.bgRed} 'await next()' ${colors_js_1.COLORS.reset} or to return a response? ${colors_js_1.COLORS.bgCyan} Path: ${ctx.pathname}, Method: ${ctx.method} ${colors_js_1.COLORS.reset}`);
131
+ throw new Error(`Handler failed: Middleware chain incomplete or response missing. Did you forget ${(0, colors_js_1.colorText)(" await next() ", "bgRed")} or to return a response? ${(0, colors_js_1.colorText)(` Path: ${ctx.pathname}, Method: ${ctx.method} `, "bgCyan")}`);
132
132
  }
133
133
  const resBody = res || ctx.body;
134
134
  const toJson = {};
@@ -163,7 +163,7 @@ class TezX extends router_js_1.Router {
163
163
  let resolvePath = pathname;
164
164
  if (this.#onPathResolve) {
165
165
  resolvePath = await this.#onPathResolve(pathname);
166
- config_js_1.GlobalConfig.debugging.warn(`${colors_js_1.COLORS.white} PATH RESOLVE ${colors_js_1.COLORS.reset} ${colors_js_1.COLORS.red}${pathname}${colors_js_1.COLORS.reset} ➞ ${colors_js_1.COLORS.cyan}${resolvePath}${colors_js_1.COLORS.reset}`);
166
+ config_js_1.GlobalConfig.debugging.warn(`${(0, colors_js_1.colorText)(" PATH RESOLVE ", "white")} ${(0, colors_js_1.colorText)(pathname, "red")} ➞ ${(0, colors_js_1.colorText)(resolvePath, "cyan")}`);
167
167
  }
168
168
  if (typeof resolvePath !== "string") {
169
169
  throw new Error(`Path resolution failed: expected a string, got ${typeof resolvePath}`);
@@ -226,7 +226,7 @@ class TezX extends router_js_1.Router {
226
226
  if (err instanceof Error) {
227
227
  error = err.stack;
228
228
  }
229
- config_js_1.GlobalConfig.debugging.error(`${colors_js_1.COLORS.bgRed} ${ctx.pathname}, Method: ${ctx.method} ${colors_js_1.COLORS.reset}`, `${httpStatusMap_js_1.httpStatusMap[500]}: ${error} `);
229
+ config_js_1.GlobalConfig.debugging.error(`${(0, colors_js_1.colorText)(` ${ctx.pathname}, Method: ${ctx.method} `, "bgRed")}`, `${httpStatusMap_js_1.httpStatusMap[500]}: ${error} `);
230
230
  let res = await config_js_1.GlobalConfig.onError(error, ctx);
231
231
  ctx.setStatus = res.status;
232
232
  return res;
package/cjs/deno/env.js CHANGED
@@ -7,7 +7,7 @@ function parseEnvFile(filePath, result) {
7
7
  try {
8
8
  let runtime = environment_js_1.Environment.getEnvironment;
9
9
  if (runtime !== "deno") {
10
- throw new Error(`Please use ${colors_js_1.COLORS.bgRed}import {loadEnv} from "tezx/${runtime}"${colors_js_1.COLORS.reset} environment`);
10
+ throw new Error(`Please use ${(0, colors_js_1.colorText)(`import {loadEnv} from "tezx/${runtime}"`, "bgRed")} environment`);
11
11
  }
12
12
  let fileExists = false;
13
13
  try {
package/cjs/deno/index.js CHANGED
@@ -14,5 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ const adpater_js_1 = require("./adpater.js");
18
+ const env_js_1 = require("./env.js");
17
19
  __exportStar(require("./adpater.js"), exports);
18
20
  __exportStar(require("./env.js"), exports);
21
+ exports.default = {
22
+ denoAdapter: adpater_js_1.denoAdapter,
23
+ loadEnv: env_js_1.loadEnv,
24
+ };
@@ -1,11 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateID = exports.sanitizePathSplit = exports.GlobalConfig = exports.Environment = void 0;
4
- var environment_js_1 = require("../core/environment.js");
5
- Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return environment_js_1.Environment; } });
6
- var config_js_1 = require("../core/config.js");
7
- Object.defineProperty(exports, "GlobalConfig", { enumerable: true, get: function () { return config_js_1.GlobalConfig; } });
8
- var url_js_1 = require("../utils/url.js");
9
- Object.defineProperty(exports, "sanitizePathSplit", { enumerable: true, get: function () { return url_js_1.sanitizePathSplit; } });
10
- var common_js_1 = require("./common.js");
11
- Object.defineProperty(exports, "generateID", { enumerable: true, get: function () { return common_js_1.generateID; } });
3
+ exports.generateID = exports.sanitizePathSplit = exports.Environment = exports.GlobalConfig = void 0;
4
+ const config_js_1 = require("../core/config.js");
5
+ const environment_js_1 = require("../core/environment.js");
6
+ const url_js_1 = require("../utils/url.js");
7
+ const common_js_1 = require("./common.js");
8
+ var config_js_2 = require("../core/config.js");
9
+ Object.defineProperty(exports, "GlobalConfig", { enumerable: true, get: function () { return config_js_2.GlobalConfig; } });
10
+ var environment_js_2 = require("../core/environment.js");
11
+ Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return environment_js_2.Environment; } });
12
+ var url_js_2 = require("../utils/url.js");
13
+ Object.defineProperty(exports, "sanitizePathSplit", { enumerable: true, get: function () { return url_js_2.sanitizePathSplit; } });
14
+ var common_js_2 = require("./common.js");
15
+ Object.defineProperty(exports, "generateID", { enumerable: true, get: function () { return common_js_2.generateID; } });
16
+ exports.default = {
17
+ Environment: environment_js_1.Environment,
18
+ GlobalConfig: config_js_1.GlobalConfig,
19
+ sanitizePathSplit: url_js_1.sanitizePathSplit,
20
+ generateID: common_js_1.generateID,
21
+ };
package/cjs/index.js CHANGED
@@ -1,10 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = exports.useParams = exports.TezX = exports.Router = void 0;
4
+ const express_1 = require("express");
5
+ const server_js_1 = require("./core/server.js");
6
+ const params_js_1 = require("./utils/params.js");
7
+ Object.defineProperty(exports, "useParams", { enumerable: true, get: function () { return params_js_1.useParams; } });
4
8
  var router_js_1 = require("./core/router.js");
5
9
  Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_js_1.Router; } });
6
- var server_js_1 = require("./core/server.js");
7
- Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_1.TezX; } });
8
- var params_js_1 = require("./utils/params.js");
9
- Object.defineProperty(exports, "useParams", { enumerable: true, get: function () { return params_js_1.useParams; } });
10
- exports.version = "2.0.3";
10
+ var server_js_2 = require("./core/server.js");
11
+ Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_2.TezX; } });
12
+ exports.version = "2.0.5";
13
+ exports.default = {
14
+ Router: express_1.Router,
15
+ TezX: server_js_1.TezX,
16
+ useParams: params_js_1.useParams,
17
+ version: exports.version,
18
+ };
@@ -37,7 +37,7 @@ const basicAuth = (options) => {
37
37
  credentials = { apiKey: ctx.headers.get("x-api-key") };
38
38
  }
39
39
  if (!authMethod || !supportedMethods.includes(authMethod)) {
40
- config_js_1.GlobalConfig.debugging.error(`${colors_js_1.COLORS.bgRed}[AUTH]${colors_js_1.COLORS.reset} Unsupported or missing authentication method.`);
40
+ config_js_1.GlobalConfig.debugging.error(`${(0, colors_js_1.colorText)("[AUTH]", "bgRed")} Unsupported or missing authentication method.`);
41
41
  return onUnauthorized(ctx, new Error("Unsupported authentication method"));
42
42
  }
43
43
  if (rateLimit) {
@@ -63,7 +63,7 @@ const basicAuth = (options) => {
63
63
  return await next();
64
64
  }
65
65
  catch (error) {
66
- config_js_1.GlobalConfig.debugging.error(`${colors_js_1.COLORS.bgRed}[AUTH]${colors_js_1.COLORS.reset} Failure for method: ${ctx.method}`);
66
+ config_js_1.GlobalConfig.debugging.error(`${(0, colors_js_1.colorText)("[AUTH]", "bgRed")} Failure for method: ${ctx.method}`);
67
67
  return onUnauthorized(ctx, error);
68
68
  }
69
69
  };
@@ -14,12 +14,28 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.detectBot = exports.cors = void 0;
17
+ exports.detectBot = void 0;
18
+ const basicAuth_js_1 = require("./basicAuth.js");
19
+ const cacheControl_js_1 = require("./cacheControl.js");
20
+ const cors_js_1 = require("./cors.js");
21
+ const detectBot_js_1 = require("./detectBot.js");
22
+ const detectLocale_js_1 = require("./detectLocale.js");
23
+ const i18n_js_1 = require("./i18n.js");
24
+ const lazyLoadModules_js_1 = require("./lazyLoadModules.js");
25
+ const logger_js_1 = require("./logger.js");
26
+ const pagination_js_1 = require("./pagination.js");
27
+ const powered_by_js_1 = require("./powered-by.js");
28
+ const rateLimiter_js_1 = require("./rateLimiter.js");
29
+ const request_id_js_1 = require("./request-id.js");
30
+ const requestTimeout_js_1 = require("./requestTimeout.js");
31
+ const sanitizeHeader_js_1 = require("./sanitizeHeader.js");
32
+ const secureHeaders_js_1 = require("./secureHeaders.js");
33
+ const xssProtection_js_1 = require("./xssProtection.js");
18
34
  __exportStar(require("./basicAuth.js"), exports);
19
- var cors_js_1 = require("./cors.js");
20
- Object.defineProperty(exports, "cors", { enumerable: true, get: function () { return cors_js_1.cors; } });
21
- var detectBot_js_1 = require("./detectBot.js");
22
- Object.defineProperty(exports, "detectBot", { enumerable: true, get: function () { return detectBot_js_1.detectBot; } });
35
+ __exportStar(require("./cacheControl.js"), exports);
36
+ __exportStar(require("./cors.js"), exports);
37
+ var detectBot_js_2 = require("./detectBot.js");
38
+ Object.defineProperty(exports, "detectBot", { enumerable: true, get: function () { return detectBot_js_2.detectBot; } });
23
39
  __exportStar(require("./detectLocale.js"), exports);
24
40
  __exportStar(require("./i18n.js"), exports);
25
41
  __exportStar(require("./lazyLoadModules.js"), exports);
@@ -32,4 +48,21 @@ __exportStar(require("./requestTimeout.js"), exports);
32
48
  __exportStar(require("./sanitizeHeader.js"), exports);
33
49
  __exportStar(require("./secureHeaders.js"), exports);
34
50
  __exportStar(require("./xssProtection.js"), exports);
35
- __exportStar(require("./cacheControl.js"), exports);
51
+ exports.default = {
52
+ basicAuth: basicAuth_js_1.basicAuth,
53
+ cacheControl: cacheControl_js_1.cacheControl,
54
+ cors: cors_js_1.cors,
55
+ detectBot: detectBot_js_1.detectBot,
56
+ detectLocale: detectLocale_js_1.detectLocale,
57
+ i18n: i18n_js_1.i18n,
58
+ lazyLoadModules: lazyLoadModules_js_1.lazyLoadModules,
59
+ logger: logger_js_1.logger,
60
+ paginationHandler: pagination_js_1.paginationHandler,
61
+ poweredBy: powered_by_js_1.poweredBy,
62
+ rateLimiter: rateLimiter_js_1.rateLimiter,
63
+ requestID: request_id_js_1.requestID,
64
+ requestTimeout: requestTimeout_js_1.requestTimeout,
65
+ sanitizeHeaders: sanitizeHeader_js_1.sanitizeHeaders,
66
+ secureHeaders: secureHeaders_js_1.secureHeaders,
67
+ xssProtection: xssProtection_js_1.xssProtection,
68
+ };
@@ -5,16 +5,16 @@ const colors_js_1 = require("../utils/colors.js");
5
5
  function logger() {
6
6
  return async function logger(ctx, next) {
7
7
  try {
8
- console.log(`${colors_js_1.COLORS.bold}<-- ${colors_js_1.COLORS.reset}${colors_js_1.COLORS.bgMagenta} ${ctx.method} ${colors_js_1.COLORS.reset} ${ctx.pathname}`);
8
+ console.log(`${(0, colors_js_1.colorText)("<--", "bold")} ${(0, colors_js_1.colorText)(ctx.method, "bgMagenta")} ${ctx.pathname}`);
9
9
  const startTime = performance.now();
10
10
  let n = await next();
11
11
  const elapsed = performance.now() - startTime;
12
- console.log(`${colors_js_1.COLORS.bold}--> ${colors_js_1.COLORS.reset}${colors_js_1.COLORS.bgBlue} ${ctx.method} ${colors_js_1.COLORS.reset} ${ctx.pathname} ` +
13
- `${colors_js_1.COLORS.yellow}${ctx.getStatus}${colors_js_1.COLORS.reset} ${colors_js_1.COLORS.magenta}${elapsed.toFixed(2)}ms${colors_js_1.COLORS.reset}`);
12
+ console.log(`${(0, colors_js_1.colorText)("-->", "bold")} ${(0, colors_js_1.colorText)(ctx.method, "bgBlue")} ${ctx.pathname} ` +
13
+ `${(0, colors_js_1.colorText)(ctx.getStatus, "yellow")} ${(0, colors_js_1.colorText)(`${elapsed.toFixed(2)}ms`, "magenta")}`);
14
14
  return n;
15
15
  }
16
16
  catch (err) {
17
- console.error(`${colors_js_1.COLORS.red}Error:${colors_js_1.COLORS.reset}`, err.stack);
17
+ console.error(`${(0, colors_js_1.colorText)("Error:", "red")}`, err.stack);
18
18
  throw new Error(err.stack);
19
19
  }
20
20
  };
package/cjs/node/env.js CHANGED
@@ -8,7 +8,7 @@ function parseEnvFile(filePath, result) {
8
8
  try {
9
9
  let runtime = environment_js_1.Environment.getEnvironment;
10
10
  if (runtime !== "bun" && runtime !== "node") {
11
- throw new Error(`Please use ${colors_js_1.COLORS.bgRed}import {loadEnv} from "tezx/${runtime}"${colors_js_1.COLORS.reset} environment`);
11
+ throw new Error(`Please use ${(0, colors_js_1.colorText)(`import {loadEnv} from "tezx/${runtime}"`, "bgRed")} environment`);
12
12
  }
13
13
  let fileExists = (0, node_fs_1.existsSync)(filePath);
14
14
  if (!fileExists) {
package/cjs/node/index.js CHANGED
@@ -14,5 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ const adapter_js_1 = require("./adapter.js");
18
+ const env_js_1 = require("./env.js");
17
19
  __exportStar(require("./adapter.js"), exports);
18
20
  __exportStar(require("./env.js"), exports);
21
+ exports.default = {
22
+ nodeAdapter: adapter_js_1.nodeAdapter,
23
+ loadEnv: env_js_1.loadEnv,
24
+ };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.COLORS = void 0;
4
+ exports.colorText = colorText;
4
5
  exports.COLORS = {
5
6
  reset: "\x1b[0m",
6
7
  bold: "\x1b[1m",
@@ -22,3 +23,6 @@ exports.COLORS = {
22
23
  bgCyan: "\x1b[46m",
23
24
  bgWhite: "\x1b[47m",
24
25
  };
26
+ function colorText(text, color) {
27
+ return `${exports.COLORS[color]}${text}${exports.COLORS.reset}`;
28
+ }
package/cjs/ws/index.js CHANGED
@@ -50,3 +50,4 @@ function upgradeWebSocket(callback, options = {}) {
50
50
  }
51
51
  };
52
52
  }
53
+ exports.default = upgradeWebSocket;
package/core/server.js CHANGED
@@ -1,4 +1,4 @@
1
- import { COLORS } from "../utils/colors.js";
1
+ import { colorText } from "../utils/colors.js";
2
2
  import { httpStatusMap } from "../utils/httpStatusMap.js";
3
3
  import { useParams } from "../utils/params.js";
4
4
  import { GlobalConfig } from "./config.js";
@@ -125,7 +125,7 @@ export class TezX extends Router {
125
125
  return res;
126
126
  }
127
127
  if (!res && !ctx.body) {
128
- throw new Error(`Handler failed: Middleware chain incomplete or response missing. Did you forget ${COLORS.bgRed} 'await next()' ${COLORS.reset} or to return a response? ${COLORS.bgCyan} Path: ${ctx.pathname}, Method: ${ctx.method} ${COLORS.reset}`);
128
+ throw new Error(`Handler failed: Middleware chain incomplete or response missing. Did you forget ${colorText(" await next() ", "bgRed")} or to return a response? ${colorText(` Path: ${ctx.pathname}, Method: ${ctx.method} `, "bgCyan")}`);
129
129
  }
130
130
  const resBody = res || ctx.body;
131
131
  const toJson = {};
@@ -160,7 +160,7 @@ export class TezX extends Router {
160
160
  let resolvePath = pathname;
161
161
  if (this.#onPathResolve) {
162
162
  resolvePath = await this.#onPathResolve(pathname);
163
- GlobalConfig.debugging.warn(`${COLORS.white} PATH RESOLVE ${COLORS.reset} ${COLORS.red}${pathname}${COLORS.reset} ➞ ${COLORS.cyan}${resolvePath}${COLORS.reset}`);
163
+ GlobalConfig.debugging.warn(`${colorText(" PATH RESOLVE ", "white")} ${colorText(pathname, "red")} ➞ ${colorText(resolvePath, "cyan")}`);
164
164
  }
165
165
  if (typeof resolvePath !== "string") {
166
166
  throw new Error(`Path resolution failed: expected a string, got ${typeof resolvePath}`);
@@ -223,7 +223,7 @@ export class TezX extends Router {
223
223
  if (err instanceof Error) {
224
224
  error = err.stack;
225
225
  }
226
- GlobalConfig.debugging.error(`${COLORS.bgRed} ${ctx.pathname}, Method: ${ctx.method} ${COLORS.reset}`, `${httpStatusMap[500]}: ${error} `);
226
+ GlobalConfig.debugging.error(`${colorText(` ${ctx.pathname}, Method: ${ctx.method} `, "bgRed")}`, `${httpStatusMap[500]}: ${error} `);
227
227
  let res = await GlobalConfig.onError(error, ctx);
228
228
  ctx.setStatus = res.status;
229
229
  return res;
package/deno/env.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { Environment } from "../core/environment.js";
2
- import { COLORS } from "../utils/colors.js";
2
+ import { colorText } from "../utils/colors.js";
3
3
  function parseEnvFile(filePath, result) {
4
4
  try {
5
5
  let runtime = Environment.getEnvironment;
6
6
  if (runtime !== "deno") {
7
- throw new Error(`Please use ${COLORS.bgRed}import {loadEnv} from "tezx/${runtime}"${COLORS.reset} environment`);
7
+ throw new Error(`Please use ${colorText(`import {loadEnv} from "tezx/${runtime}"`, "bgRed")} environment`);
8
8
  }
9
9
  let fileExists = false;
10
10
  try {
package/deno/index.d.ts CHANGED
@@ -1,2 +1,9 @@
1
+ import { denoAdapter } from "./adpater.js";
2
+ import { loadEnv } from "./env.js";
1
3
  export * from "./adpater.js";
2
4
  export * from "./env.js";
5
+ declare const _default: {
6
+ denoAdapter: typeof denoAdapter;
7
+ loadEnv: typeof loadEnv;
8
+ };
9
+ export default _default;
package/deno/index.js CHANGED
@@ -1,2 +1,8 @@
1
+ import { denoAdapter } from "./adpater.js";
2
+ import { loadEnv } from "./env.js";
1
3
  export * from "./adpater.js";
2
4
  export * from "./env.js";
5
+ export default {
6
+ denoAdapter,
7
+ loadEnv,
8
+ };
package/helper/index.d.ts CHANGED
@@ -1,4 +1,30 @@
1
+ import { Environment } from "../core/environment.js";
2
+ import { sanitizePathSplit } from "../utils/url.js";
3
+ import { generateID } from "./common.js";
4
+ export { AdapterType, GlobalConfig } from "../core/config.js";
1
5
  export { Environment } from "../core/environment.js";
2
- export { GlobalConfig } from "../core/config.js";
3
- export { sanitizePathSplit } from "../utils/url.js";
6
+ export { sanitizePathSplit, UrlRef } from "../utils/url.js";
4
7
  export { generateID } from "./common.js";
8
+ declare const _default: {
9
+ Environment: typeof Environment;
10
+ GlobalConfig: {
11
+ new (): {};
12
+ notFound: import("../index.js").Callback;
13
+ onError: <T extends Record<string, any> = {}>(err: string, ctx: import("../index.js").Context<T>) => Response;
14
+ allowDuplicateMw?: boolean;
15
+ overwriteMethod?: boolean;
16
+ debugMode?: boolean;
17
+ server: any;
18
+ adapter: import("../core/config.js").AdapterType;
19
+ readonly debugging: {
20
+ info: (msg: string, ...args: unknown[]) => void;
21
+ warn: (msg: string, ...args: unknown[]) => void;
22
+ error: (msg: string, ...args: unknown[]) => void;
23
+ debug: (msg: string, ...args: unknown[]) => void;
24
+ success: (msg: string, ...args: unknown[]) => void;
25
+ };
26
+ };
27
+ sanitizePathSplit: typeof sanitizePathSplit;
28
+ generateID: typeof generateID;
29
+ };
30
+ export default _default;
package/helper/index.js CHANGED
@@ -1,4 +1,14 @@
1
- export { Environment } from "../core/environment.js";
1
+ import { GlobalConfig } from "../core/config.js";
2
+ import { Environment } from "../core/environment.js";
3
+ import { sanitizePathSplit } from "../utils/url.js";
4
+ import { generateID } from "./common.js";
2
5
  export { GlobalConfig } from "../core/config.js";
6
+ export { Environment } from "../core/environment.js";
3
7
  export { sanitizePathSplit } from "../utils/url.js";
4
8
  export { generateID } from "./common.js";
9
+ export default {
10
+ Environment,
11
+ GlobalConfig,
12
+ sanitizePathSplit,
13
+ generateID,
14
+ };
package/index.d.ts CHANGED
@@ -1,10 +1,20 @@
1
+ import { Router } from "express";
2
+ import { TezX } from "./core/server.js";
3
+ import { useParams } from "./utils/params.js";
1
4
  export { Router } from "./core/router.js";
2
- export type { Callback, ctx as Context, Middleware, NextCallback, RouterConfig, StaticServeOption, } from "./core/router.js";
5
+ export type { Callback, ctx as Context, Middleware, NextCallback, RouterConfig, StaticServeOption } from "./core/router.js";
6
+ export type { AdapterType } from "./core/config.js";
3
7
  export type { CookieOptions, ResponseHeaders } from "./core/context.js";
4
- export type { NetAddr as AddressType, ConnAddress, FormDataOptions, HTTPMethod, } from "./core/request.js";
8
+ export type { NetAddr as AddressType, ConnAddress, FormDataOptions, HTTPMethod } from "./core/request.js";
5
9
  export { TezX } from "./core/server.js";
6
- export type { AdapterType } from "./core/config.js";
7
- export type { TezXConfig } from "./core/server.js";
8
- export { useParams } from "./utils/params.js";
10
+ export type { TezXConfig, TezXServeOptions } from "./core/server.js";
9
11
  export type { UrlRef } from "./utils/url.js";
12
+ export { useParams };
10
13
  export declare let version: string;
14
+ declare const _default: {
15
+ Router: typeof Router;
16
+ TezX: typeof TezX;
17
+ useParams: typeof useParams;
18
+ version: string;
19
+ };
20
+ export default _default;
package/index.js CHANGED
@@ -1,4 +1,13 @@
1
+ import { Router } from "express";
2
+ import { TezX } from "./core/server.js";
3
+ import { useParams } from "./utils/params.js";
1
4
  export { Router } from "./core/router.js";
2
5
  export { TezX } from "./core/server.js";
3
- export { useParams } from "./utils/params.js";
4
- export let version = "2.0.3";
6
+ export { useParams };
7
+ export let version = "2.0.5";
8
+ export default {
9
+ Router,
10
+ TezX,
11
+ useParams,
12
+ version,
13
+ };
@@ -1,6 +1,5 @@
1
- import { Middleware } from "../core/router.js";
2
1
  import { Context } from "../core/context.js";
3
- import { CallbackReturn } from "../core/router.js";
2
+ import { CallbackReturn, Middleware } from "../core/router.js";
4
3
  /**
5
4
  * Supported authentication method types.
6
5
  */
@@ -14,7 +13,7 @@ export type AuthCredential = {
14
13
  /**
15
14
  * Configuration options for dynamic basic authentication.
16
15
  */
17
- type DynamicBasicAuthOptions = {
16
+ export type DynamicBasicAuthOptions = {
18
17
  /**
19
18
  * 🔐 Function to validate the provided credentials.
20
19
  * @param method - The method of authentication.
@@ -80,4 +79,3 @@ type DynamicBasicAuthOptions = {
80
79
  * @returns A middleware function.
81
80
  */
82
81
  export declare const basicAuth: (options: DynamicBasicAuthOptions) => Middleware;
83
- export {};
@@ -1,5 +1,5 @@
1
1
  import { GlobalConfig } from "../core/config.js";
2
- import { COLORS } from "../utils/colors.js";
2
+ import { colorText } from "../utils/colors.js";
3
3
  import { createRateLimitDefaultStorage, isRateLimit } from "./detectBot.js";
4
4
  export const basicAuth = (options) => {
5
5
  const { validateCredentials, getRealm = () => "Restricted Area", onUnauthorized = (ctx, error) => {
@@ -34,7 +34,7 @@ export const basicAuth = (options) => {
34
34
  credentials = { apiKey: ctx.headers.get("x-api-key") };
35
35
  }
36
36
  if (!authMethod || !supportedMethods.includes(authMethod)) {
37
- GlobalConfig.debugging.error(`${COLORS.bgRed}[AUTH]${COLORS.reset} Unsupported or missing authentication method.`);
37
+ GlobalConfig.debugging.error(`${colorText("[AUTH]", "bgRed")} Unsupported or missing authentication method.`);
38
38
  return onUnauthorized(ctx, new Error("Unsupported authentication method"));
39
39
  }
40
40
  if (rateLimit) {
@@ -60,7 +60,7 @@ export const basicAuth = (options) => {
60
60
  return await next();
61
61
  }
62
62
  catch (error) {
63
- GlobalConfig.debugging.error(`${COLORS.bgRed}[AUTH]${COLORS.reset} Failure for method: ${ctx.method}`);
63
+ GlobalConfig.debugging.error(`${colorText("[AUTH]", "bgRed")} Failure for method: ${ctx.method}`);
64
64
  return onUnauthorized(ctx, error);
65
65
  }
66
66
  };
@@ -1,12 +1,12 @@
1
1
  import { CallbackReturn } from "../core/router.js";
2
2
  import { Context, Middleware } from "../index.js";
3
3
  export type DetectBotReason = "User-Agent" | "Blacklisted IP" | "Query Parameter" | "Rate Limiting" | "Custom Detector" | "Multiple Indicators";
4
- type BotDetectionResult = {
4
+ export type BotDetectionResult = {
5
5
  isBot: boolean;
6
6
  reason?: DetectBotReason;
7
7
  indicators: string[];
8
8
  };
9
- type DetectBotOptions = {
9
+ export type DetectBotOptions = {
10
10
  /**
11
11
  * 🤖 List of bot-like user-agent substrings to detect
12
12
  * @default ["bot", "spider", "crawl", "slurp"]
@@ -119,4 +119,3 @@ export declare function isRateLimit(ctx: Context, key: string, store: any, maxRe
119
119
  check: boolean;
120
120
  entry: any;
121
121
  };
122
- export {};
@@ -1,6 +1,8 @@
1
+ import { cors } from "./cors.js";
2
+ import { logger } from "./logger.js";
1
3
  export * from "./basicAuth.js";
2
- export { cors } from "./cors.js";
3
- export type { CorsOptions } from "./cors.js";
4
+ export * from "./cacheControl.js";
5
+ export * from "./cors.js";
4
6
  export { detectBot } from "./detectBot.js";
5
7
  export type { DetectBotReason } from "./detectBot.js";
6
8
  export * from "./detectLocale.js";
@@ -15,4 +17,22 @@ export * from "./requestTimeout.js";
15
17
  export * from "./sanitizeHeader.js";
16
18
  export * from "./secureHeaders.js";
17
19
  export * from "./xssProtection.js";
18
- export * from "./cacheControl.js";
20
+ declare const _default: {
21
+ basicAuth: (options: import("./basicAuth.js").DynamicBasicAuthOptions) => import("../index.js").Middleware;
22
+ cacheControl: (options: import("./cacheControl.js").CacheOptions) => import("../index.js").Middleware;
23
+ cors: typeof cors;
24
+ detectBot: (options?: import("./detectBot.js").DetectBotOptions) => import("../index.js").Middleware;
25
+ detectLocale: (options: import("./detectLocale.js").DetectLocaleOptions) => import("../index.js").Middleware;
26
+ i18n: (options: import("./i18n.js").I18nOptions) => import("../index.js").Middleware;
27
+ lazyLoadModules: <T = any>(options: import("./lazyLoadModules.js").LazyLoadOptions<T>) => import("../index.js").Middleware;
28
+ logger: typeof logger;
29
+ paginationHandler: (options?: import("./pagination.js").PaginationOptions) => import("../index.js").Middleware;
30
+ poweredBy: (serverName?: string) => import("../index.js").Middleware;
31
+ rateLimiter: (options: import("./rateLimiter.js").RateLimiterOptions) => import("../index.js").Middleware;
32
+ requestID: (headerName?: string, contextKey?: string) => import("../index.js").Middleware;
33
+ requestTimeout: (options: import("./requestTimeout.js").TimeoutOptions) => import("../index.js").Middleware;
34
+ sanitizeHeaders: (options?: import("./sanitizeHeader.js").SanitizeHeadersOptions) => import("../index.js").Middleware;
35
+ secureHeaders: (options?: import("./secureHeaders.js").SecurityHeaderOptions) => import("../index.js").Middleware;
36
+ xssProtection: (options?: import("./xssProtection.js").XSSProtectionOptions) => (ctx: import("../core/context.js").Context, next: import("../index.js").NextCallback) => Promise<any>;
37
+ };
38
+ export default _default;
@@ -1,5 +1,22 @@
1
+ import { basicAuth } from "./basicAuth.js";
2
+ import { cacheControl } from "./cacheControl.js";
3
+ import { cors } from "./cors.js";
4
+ import { detectBot } from "./detectBot.js";
5
+ import { detectLocale } from "./detectLocale.js";
6
+ import { i18n } from "./i18n.js";
7
+ import { lazyLoadModules } from "./lazyLoadModules.js";
8
+ import { logger } from "./logger.js";
9
+ import { paginationHandler } from "./pagination.js";
10
+ import { poweredBy } from "./powered-by.js";
11
+ import { rateLimiter } from "./rateLimiter.js";
12
+ import { requestID } from "./request-id.js";
13
+ import { requestTimeout } from "./requestTimeout.js";
14
+ import { sanitizeHeaders } from "./sanitizeHeader.js";
15
+ import { secureHeaders } from "./secureHeaders.js";
16
+ import { xssProtection } from "./xssProtection.js";
1
17
  export * from "./basicAuth.js";
2
- export { cors } from "./cors.js";
18
+ export * from "./cacheControl.js";
19
+ export * from "./cors.js";
3
20
  export { detectBot } from "./detectBot.js";
4
21
  export * from "./detectLocale.js";
5
22
  export * from "./i18n.js";
@@ -13,4 +30,21 @@ export * from "./requestTimeout.js";
13
30
  export * from "./sanitizeHeader.js";
14
31
  export * from "./secureHeaders.js";
15
32
  export * from "./xssProtection.js";
16
- export * from "./cacheControl.js";
33
+ export default {
34
+ basicAuth,
35
+ cacheControl,
36
+ cors,
37
+ detectBot,
38
+ detectLocale,
39
+ i18n,
40
+ lazyLoadModules,
41
+ logger,
42
+ paginationHandler,
43
+ poweredBy,
44
+ rateLimiter,
45
+ requestID,
46
+ requestTimeout,
47
+ sanitizeHeaders,
48
+ secureHeaders,
49
+ xssProtection,
50
+ };
@@ -4,7 +4,7 @@ export interface CacheItem<T = any> {
4
4
  module: T;
5
5
  expiresAt: number;
6
6
  }
7
- interface LazyLoadOptions<T> {
7
+ export interface LazyLoadOptions<T> {
8
8
  /**
9
9
  * 🗺️ Key to identify the module to load. This can be a function that extracts the module name from the request context.
10
10
  * @default (ctx) => ctx.req.params[queryKeyModule] || ctx.req.query[queryKeyModule]
@@ -70,4 +70,3 @@ interface LazyLoadOptions<T> {
70
70
  * @returns A middleware function to use in your application.
71
71
  */
72
72
  export declare const lazyLoadModules: <T = any>(options: LazyLoadOptions<T>) => Middleware;
73
- export {};
@@ -1,17 +1,17 @@
1
- import { COLORS } from "../utils/colors.js";
1
+ import { colorText } from "../utils/colors.js";
2
2
  export function logger() {
3
3
  return async function logger(ctx, next) {
4
4
  try {
5
- console.log(`${COLORS.bold}<-- ${COLORS.reset}${COLORS.bgMagenta} ${ctx.method} ${COLORS.reset} ${ctx.pathname}`);
5
+ console.log(`${colorText("<--", "bold")} ${colorText(ctx.method, "bgMagenta")} ${ctx.pathname}`);
6
6
  const startTime = performance.now();
7
7
  let n = await next();
8
8
  const elapsed = performance.now() - startTime;
9
- console.log(`${COLORS.bold}--> ${COLORS.reset}${COLORS.bgBlue} ${ctx.method} ${COLORS.reset} ${ctx.pathname} ` +
10
- `${COLORS.yellow}${ctx.getStatus}${COLORS.reset} ${COLORS.magenta}${elapsed.toFixed(2)}ms${COLORS.reset}`);
9
+ console.log(`${colorText("-->", "bold")} ${colorText(ctx.method, "bgBlue")} ${ctx.pathname} ` +
10
+ `${colorText(ctx.getStatus, "yellow")} ${colorText(`${elapsed.toFixed(2)}ms`, "magenta")}`);
11
11
  return n;
12
12
  }
13
13
  catch (err) {
14
- console.error(`${COLORS.red}Error:${COLORS.reset}`, err.stack);
14
+ console.error(`${colorText("Error:", "red")}`, err.stack);
15
15
  throw new Error(err.stack);
16
16
  }
17
17
  };
@@ -1,6 +1,6 @@
1
1
  import { Context } from "../core/context.js";
2
2
  import { CallbackReturn, Middleware } from "../core/router.js";
3
- type TimeoutOptions = {
3
+ export type TimeoutOptions = {
4
4
  /**
5
5
  * ⏳ Function to dynamically determine the timeout duration (in milliseconds).
6
6
  */
@@ -23,4 +23,3 @@ type TimeoutOptions = {
23
23
  * @param options - Custom options for dynamic timeout handling.
24
24
  */
25
25
  export declare const requestTimeout: (options: TimeoutOptions) => Middleware;
26
- export {};
@@ -1,5 +1,5 @@
1
1
  import { Middleware } from "../core/router.js";
2
- type SanitizeHeadersOptions = {
2
+ export type SanitizeHeadersOptions = {
3
3
  /**
4
4
  * 🟢 Whitelist of allowed headers (case-insensitive)
5
5
  * @default [] (allow all if empty)
@@ -50,4 +50,3 @@ type SanitizeHeadersOptions = {
50
50
  * }));
51
51
  */
52
52
  export declare const sanitizeHeaders: (options?: SanitizeHeadersOptions) => Middleware;
53
- export {};
package/node/adapter.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import type { ServerOptions } from "node:http";
2
2
  import type { TlsOptions } from "node:tls";
3
3
  import { TezX } from "../core/server.js";
4
- type UnixSocketOptions = ServerOptions & {
4
+ export type UnixSocketOptions = ServerOptions & {
5
5
  unix?: string;
6
6
  enableSSL?: false;
7
7
  };
8
- type SSLOptions = ServerOptions & TlsOptions & {
8
+ export type SSLOptions = ServerOptions & TlsOptions & {
9
9
  enableSSL: true;
10
10
  };
11
- type TezXServerOptions = UnixSocketOptions | SSLOptions;
11
+ export type TezXServerOptions = UnixSocketOptions | SSLOptions;
12
12
  /**
13
13
  * Starts the TezX server using Node.js native `http` or `https` module based on the `enableSSL` flag.
14
14
  * - If `enableSSL` is true and valid TLS options are provided, it uses `https.createServer`.
@@ -44,4 +44,3 @@ export declare function nodeAdapter<T extends Record<string, any> = {}>(TezX: Te
44
44
  (port?: number, callback?: () => void): any;
45
45
  };
46
46
  };
47
- export {};
package/node/env.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { Environment } from "../core/environment.js";
3
- import { COLORS } from "../utils/colors.js";
3
+ import { colorText } from "../utils/colors.js";
4
4
  function parseEnvFile(filePath, result) {
5
5
  try {
6
6
  let runtime = Environment.getEnvironment;
7
7
  if (runtime !== "bun" && runtime !== "node") {
8
- throw new Error(`Please use ${COLORS.bgRed}import {loadEnv} from "tezx/${runtime}"${COLORS.reset} environment`);
8
+ throw new Error(`Please use ${colorText(`import {loadEnv} from "tezx/${runtime}"`, "bgRed")} environment`);
9
9
  }
10
10
  let fileExists = existsSync(filePath);
11
11
  if (!fileExists) {
package/node/index.d.ts CHANGED
@@ -1,2 +1,9 @@
1
+ import { nodeAdapter } from "./adapter.js";
2
+ import { loadEnv } from "./env.js";
1
3
  export * from "./adapter.js";
2
4
  export * from "./env.js";
5
+ declare const _default: {
6
+ nodeAdapter: typeof nodeAdapter;
7
+ loadEnv: typeof loadEnv;
8
+ };
9
+ export default _default;
package/node/index.js CHANGED
@@ -1,2 +1,8 @@
1
+ import { nodeAdapter } from "./adapter.js";
2
+ import { loadEnv } from "./env.js";
1
3
  export * from "./adapter.js";
2
4
  export * from "./env.js";
5
+ export default {
6
+ nodeAdapter,
7
+ loadEnv,
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tezx",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "TezX is a high-performance, lightweight JavaScript framework designed for speed, scalability, and flexibility. It enables efficient routing, middleware management, and static file serving with minimal configuration. Fully compatible with Node.js, Deno, and Bun.",
5
5
  "main": "cjs/index.js",
6
6
  "module": "index.js",
package/utils/colors.d.ts CHANGED
@@ -19,3 +19,4 @@ export declare const COLORS: {
19
19
  bgCyan: string;
20
20
  bgWhite: string;
21
21
  };
22
+ export declare function colorText(text: string | number, color: keyof typeof COLORS): string;
package/utils/colors.js CHANGED
@@ -19,3 +19,6 @@ export const COLORS = {
19
19
  bgCyan: "\x1b[46m",
20
20
  bgWhite: "\x1b[47m",
21
21
  };
22
+ export function colorText(text, color) {
23
+ return `${COLORS[color]}${text}${COLORS.reset}`;
24
+ }
package/ws/index.d.ts CHANGED
@@ -177,4 +177,4 @@ export type WebSocketOptions = {
177
177
  maxPayload?: number;
178
178
  };
179
179
  export declare function upgradeWebSocket(callback: WebSocketCallback, options?: WebSocketOptions): Middleware;
180
- export {};
180
+ export default upgradeWebSocket;
package/ws/index.js CHANGED
@@ -47,3 +47,4 @@ export function upgradeWebSocket(callback, options = {}) {
47
47
  }
48
48
  };
49
49
  }
50
+ export default upgradeWebSocket;