tezx 2.0.2 → 2.0.4
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 +8 -1
- package/bun/index.js +7 -1
- package/cjs/bun/index.js +7 -1
- package/cjs/core/server.js +3 -3
- package/cjs/deno/env.js +1 -1
- package/cjs/deno/index.js +6 -0
- package/cjs/helper/index.js +19 -9
- package/cjs/index.js +1 -1
- package/cjs/middleware/basicAuth.js +2 -2
- package/cjs/middleware/index.js +39 -6
- package/cjs/middleware/logger.js +4 -4
- package/cjs/node/env.js +1 -1
- package/cjs/node/index.js +6 -0
- package/cjs/utils/colors.js +4 -0
- package/cjs/ws/index.js +1 -0
- package/core/server.js +4 -4
- package/deno/env.js +2 -2
- package/deno/index.d.ts +7 -0
- package/deno/index.js +6 -0
- package/helper/index.d.ts +28 -2
- package/helper/index.js +11 -1
- package/index.d.ts +4 -4
- package/index.js +1 -1
- package/middleware/basicAuth.d.ts +2 -4
- package/middleware/basicAuth.js +3 -3
- package/middleware/detectBot.d.ts +2 -3
- package/middleware/index.d.ts +23 -3
- package/middleware/index.js +36 -2
- package/middleware/lazyLoadModules.d.ts +1 -2
- package/middleware/logger.js +5 -5
- package/middleware/requestTimeout.d.ts +1 -2
- package/middleware/sanitizeHeader.d.ts +1 -2
- package/node/adapter.d.ts +3 -4
- package/node/env.js +2 -2
- package/node/index.d.ts +7 -0
- package/node/index.js +6 -0
- package/package.json +1 -1
- package/utils/colors.d.ts +1 -0
- package/utils/colors.js +3 -0
- package/ws/index.d.ts +1 -1
- package/ws/index.js +1 -0
package/bun/index.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
import { loadEnv } from "../node/env.js";
|
|
2
|
+
import { bunAdapter } from "./adapter.js";
|
|
3
|
+
export * from "../node/env.js";
|
|
1
4
|
export * from "./adapter.js";
|
|
2
|
-
|
|
5
|
+
declare const _default: {
|
|
6
|
+
bunAdapter: typeof bunAdapter;
|
|
7
|
+
loadEnv: typeof loadEnv;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
package/bun/index.js
CHANGED
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
|
+
const env_js_1 = require("../node/env.js");
|
|
18
|
+
const adapter_js_1 = require("./adapter.js");
|
|
19
|
+
__exportStar(require("../node/env.js"), exports);
|
|
17
20
|
__exportStar(require("./adapter.js"), exports);
|
|
18
|
-
|
|
21
|
+
exports.default = {
|
|
22
|
+
bunAdapter: adapter_js_1.bunAdapter,
|
|
23
|
+
loadEnv: env_js_1.loadEnv,
|
|
24
|
+
};
|
package/cjs/core/server.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
+
};
|
package/cjs/helper/index.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateID = exports.sanitizePathSplit = exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "
|
|
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
|
@@ -7,4 +7,4 @@ var server_js_1 = require("./core/server.js");
|
|
|
7
7
|
Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_1.TezX; } });
|
|
8
8
|
var params_js_1 = require("./utils/params.js");
|
|
9
9
|
Object.defineProperty(exports, "useParams", { enumerable: true, get: function () { return params_js_1.useParams; } });
|
|
10
|
-
exports.version = "2.0.
|
|
10
|
+
exports.version = "2.0.4";
|
|
@@ -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.
|
|
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.
|
|
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
|
};
|
package/cjs/middleware/index.js
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
Object.defineProperty(exports, "detectBot", { enumerable: true, get: function () { return
|
|
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
|
-
|
|
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
|
+
};
|
package/cjs/middleware/logger.js
CHANGED
|
@@ -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.
|
|
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.
|
|
13
|
-
`${colors_js_1.
|
|
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.
|
|
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.
|
|
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
|
+
};
|
package/cjs/utils/colors.js
CHANGED
|
@@ -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
package/core/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 ${
|
|
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(`${
|
|
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(`${
|
|
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 {
|
|
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 ${
|
|
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
package/deno/index.js
CHANGED
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 {
|
|
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
|
-
|
|
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,10 @@
|
|
|
1
1
|
export { Router } from "./core/router.js";
|
|
2
|
-
export type { Callback, ctx as Context, Middleware, NextCallback, RouterConfig, StaticServeOption
|
|
2
|
+
export type { Callback, ctx as Context, Middleware, NextCallback, RouterConfig, StaticServeOption } from "./core/router.js";
|
|
3
|
+
export type { AdapterType } from "./core/config.js";
|
|
3
4
|
export type { CookieOptions, ResponseHeaders } from "./core/context.js";
|
|
4
|
-
export type { NetAddr as AddressType, ConnAddress, FormDataOptions, HTTPMethod
|
|
5
|
+
export type { NetAddr as AddressType, ConnAddress, FormDataOptions, HTTPMethod } from "./core/request.js";
|
|
5
6
|
export { TezX } from "./core/server.js";
|
|
6
|
-
export type {
|
|
7
|
-
export type { TezXConfig } from "./core/server.js";
|
|
7
|
+
export type { TezXConfig, TezXServeOptions } from "./core/server.js";
|
|
8
8
|
export { useParams } from "./utils/params.js";
|
|
9
9
|
export type { UrlRef } from "./utils/url.js";
|
|
10
10
|
export declare let version: string;
|
package/index.js
CHANGED
|
@@ -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 {};
|
package/middleware/basicAuth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GlobalConfig } from "../core/config.js";
|
|
2
|
-
import {
|
|
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(`${
|
|
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(`${
|
|
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 {};
|
package/middleware/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { cors } from "./cors.js";
|
|
2
|
+
import { logger } from "./logger.js";
|
|
1
3
|
export * from "./basicAuth.js";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
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
|
-
|
|
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;
|
package/middleware/index.js
CHANGED
|
@@ -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
|
|
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
|
|
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 {};
|
package/middleware/logger.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
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(`${
|
|
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(`${
|
|
10
|
-
`${
|
|
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(`${
|
|
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 {
|
|
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 ${
|
|
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
package/node/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tezx",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
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
package/utils/colors.js
CHANGED
package/ws/index.d.ts
CHANGED
package/ws/index.js
CHANGED