tezx 3.0.3-beta → 3.0.5-beta

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.
Files changed (111) hide show
  1. package/bun/index.d.ts +1 -1
  2. package/bun/index.js +1 -1
  3. package/bun/ws.js +1 -1
  4. package/cjs/bun/index.js +1 -1
  5. package/cjs/bun/ws.js +1 -1
  6. package/cjs/core/context.js +34 -11
  7. package/cjs/core/request.js +4 -3
  8. package/cjs/core/router.js +12 -9
  9. package/cjs/core/server.js +9 -5
  10. package/cjs/deno/index.js +1 -1
  11. package/cjs/deno/serveStatic.js +3 -3
  12. package/cjs/helper/index.js +16 -5
  13. package/cjs/index.js +1 -1
  14. package/cjs/middleware/{basic-auth/index.js → basic-auth.js} +3 -3
  15. package/cjs/middleware/{cache-control/index.js → cache-control.js} +1 -1
  16. package/cjs/middleware/{detect-bot/index.js → detect-bot.js} +2 -2
  17. package/cjs/middleware/{detect-locale/index.js → detect-locale.js} +2 -2
  18. package/cjs/middleware/{i18n/index.js → i18n.js} +4 -4
  19. package/cjs/middleware/{lazy-loader/index.js → lazy-loader.js} +1 -1
  20. package/cjs/middleware/{logger/index.js → logger.js} +1 -1
  21. package/cjs/middleware/{rate-limiter/index.js → rate-limiter.js} +3 -2
  22. package/cjs/middleware/{request-id/index.js → request-id.js} +1 -1
  23. package/cjs/middleware/{request-timeout/index.js → request-timeout.js} +1 -1
  24. package/cjs/middleware/{sanitize-headers/index.js → sanitize-headers.js} +5 -5
  25. package/cjs/middleware/{xss-protection/index.js → xss-protection.js} +1 -1
  26. package/cjs/node/mount-node.js +10 -7
  27. package/cjs/node/serveStatic.js +2 -2
  28. package/cjs/node/toWebRequest.js +6 -2
  29. package/cjs/registry/RadixRouter.js +19 -18
  30. package/cjs/types/headers.js +2 -0
  31. package/cjs/utils/formData.js +11 -5
  32. package/cjs/utils/generateID.js +2 -1
  33. package/cjs/utils/low-level.js +1 -1
  34. package/cjs/utils/mimeTypes.js +0 -52
  35. package/cjs/utils/regexRouter.js +3 -5
  36. package/cjs/utils/response.js +10 -5
  37. package/cjs/utils/url.js +6 -6
  38. package/core/context.d.ts +54 -54
  39. package/core/context.js +35 -12
  40. package/core/request.d.ts +11 -11
  41. package/core/request.js +4 -3
  42. package/core/router.d.ts +57 -44
  43. package/core/router.js +12 -9
  44. package/core/server.d.ts +90 -90
  45. package/core/server.js +9 -5
  46. package/deno/index.d.ts +1 -1
  47. package/deno/index.js +1 -1
  48. package/deno/serveStatic.js +4 -4
  49. package/deno/ws.d.ts +2 -2
  50. package/helper/index.d.ts +1 -1
  51. package/helper/index.js +20 -9
  52. package/index.d.ts +1 -1
  53. package/index.js +1 -1
  54. package/middleware/{basic-auth/index.d.ts → basic-auth.d.ts} +2 -2
  55. package/middleware/{basic-auth/index.js → basic-auth.js} +3 -3
  56. package/middleware/{cache-control/index.d.ts → cache-control.d.ts} +2 -2
  57. package/middleware/{cache-control/index.js → cache-control.js} +1 -1
  58. package/middleware/{cors/index.d.ts → cors.d.ts} +1 -1
  59. package/middleware/{detect-bot/index.d.ts → detect-bot.d.ts} +2 -2
  60. package/middleware/{detect-bot/index.js → detect-bot.js} +2 -2
  61. package/middleware/{detect-locale/index.d.ts → detect-locale.d.ts} +2 -2
  62. package/middleware/{detect-locale/index.js → detect-locale.js} +3 -3
  63. package/middleware/{i18n/index.d.ts → i18n.d.ts} +1 -1
  64. package/middleware/{i18n/index.js → i18n.js} +4 -4
  65. package/middleware/{lazy-loader/index.d.ts → lazy-loader.d.ts} +2 -2
  66. package/middleware/{lazy-loader/index.js → lazy-loader.js} +2 -2
  67. package/middleware/{logger/index.d.ts → logger.d.ts} +2 -2
  68. package/middleware/{logger/index.js → logger.js} +2 -2
  69. package/middleware/{pagination/index.d.ts → pagination.d.ts} +2 -2
  70. package/middleware/{pagination/index.js → pagination.js} +1 -1
  71. package/middleware/{powered-by/index.d.ts → powered-by.d.ts} +2 -2
  72. package/middleware/{powered-by/index.js → powered-by.js} +1 -1
  73. package/middleware/{rate-limiter/index.d.ts → rate-limiter.d.ts} +7 -6
  74. package/middleware/{rate-limiter/index.js → rate-limiter.js} +3 -2
  75. package/middleware/{request-id/index.d.ts → request-id.d.ts} +2 -2
  76. package/middleware/{request-id/index.js → request-id.js} +2 -2
  77. package/middleware/{request-timeout/index.d.ts → request-timeout.d.ts} +3 -3
  78. package/middleware/{request-timeout/index.js → request-timeout.js} +2 -2
  79. package/middleware/{sanitize-headers/index.d.ts → sanitize-headers.d.ts} +1 -1
  80. package/middleware/{sanitize-headers/index.js → sanitize-headers.js} +5 -5
  81. package/middleware/{secure-headers/index.d.ts → secure-headers.d.ts} +2 -2
  82. package/middleware/{secure-headers/index.js → secure-headers.js} +1 -1
  83. package/middleware/{xss-protection/index.d.ts → xss-protection.d.ts} +3 -3
  84. package/middleware/{xss-protection/index.js → xss-protection.js} +2 -2
  85. package/node/index.d.ts +3 -3
  86. package/node/index.js +1 -1
  87. package/node/mount-node.js +10 -7
  88. package/node/serveStatic.js +3 -3
  89. package/node/toWebRequest.js +6 -2
  90. package/package.json +5 -80
  91. package/registry/RadixRouter.d.ts +5 -5
  92. package/registry/RadixRouter.js +19 -18
  93. package/registry/index.d.ts +1 -1
  94. package/types/headers.d.ts +2 -0
  95. package/types/headers.js +1 -0
  96. package/types/index.d.ts +8 -3
  97. package/utils/formData.js +11 -5
  98. package/utils/generateID.js +2 -1
  99. package/utils/low-level.d.ts +7 -7
  100. package/utils/low-level.js +1 -1
  101. package/utils/mimeTypes.d.ts +0 -6
  102. package/utils/mimeTypes.js +0 -51
  103. package/utils/regexRouter.d.ts +18 -18
  104. package/utils/regexRouter.js +3 -5
  105. package/utils/response.js +10 -5
  106. package/utils/url.js +6 -6
  107. /package/cjs/middleware/{cors/index.js → cors.js} +0 -0
  108. /package/cjs/middleware/{pagination/index.js → pagination.js} +0 -0
  109. /package/cjs/middleware/{powered-by/index.js → powered-by.js} +0 -0
  110. /package/cjs/middleware/{secure-headers/index.js → secure-headers.js} +0 -0
  111. /package/middleware/{cors/index.js → cors.js} +0 -0
package/bun/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { loadEnv } from "../node/env.js";
2
2
  import { serveStatic } from "../node/serveStatic.js";
3
3
  import { getConnInfo } from "./getConnInfo.js";
4
4
  import upgradeWebSocket from "./ws.js";
5
- export type { ServeStatic, StaticFileArray, StaticServeOption, WebSocketCallback, WebSocketEvent, WebSocketOptions } from "../types/index.js";
5
+ export type { ServeStatic, StaticFileArray, StaticServeOption, WebSocketCallback, WebSocketEvent, WebSocketOptions, } from "../types/index.js";
6
6
  export { getConnInfo, loadEnv, serveStatic, upgradeWebSocket };
7
7
  declare const _default: {
8
8
  getConnInfo: typeof getConnInfo;
package/bun/index.js CHANGED
@@ -7,5 +7,5 @@ export default {
7
7
  getConnInfo,
8
8
  loadEnv,
9
9
  upgradeWebSocket,
10
- serveStatic
10
+ serveStatic,
11
11
  };
package/bun/ws.js CHANGED
@@ -24,7 +24,7 @@ export function upgradeWebSocket(callback, options = {}) {
24
24
  return onUpgradeError(new Error("Bun server instance missing for WebSocket"), ctx);
25
25
  }
26
26
  const success = args.upgrade(ctx.rawRequest, {
27
- data: callback(ctx)
27
+ data: callback(ctx),
28
28
  });
29
29
  if (success)
30
30
  return undefined;
package/cjs/bun/index.js CHANGED
@@ -16,5 +16,5 @@ exports.default = {
16
16
  getConnInfo: getConnInfo_js_1.getConnInfo,
17
17
  loadEnv: env_js_1.loadEnv,
18
18
  upgradeWebSocket: ws_js_1.default,
19
- serveStatic: serveStatic_js_1.serveStatic
19
+ serveStatic: serveStatic_js_1.serveStatic,
20
20
  };
package/cjs/bun/ws.js CHANGED
@@ -27,7 +27,7 @@ function upgradeWebSocket(callback, options = {}) {
27
27
  return onUpgradeError(new Error("Bun server instance missing for WebSocket"), ctx);
28
28
  }
29
29
  const success = args.upgrade(ctx.rawRequest, {
30
- data: callback(ctx)
30
+ data: callback(ctx),
31
31
  });
32
32
  if (success)
33
33
  return undefined;
@@ -75,8 +75,12 @@ class Context {
75
75
  }
76
76
  return this.#req;
77
77
  }
78
- get body() { return this.#body; }
79
- set body(value) { this.#body = value; }
78
+ get body() {
79
+ return this.#body;
80
+ }
81
+ set body(value) {
82
+ this.#body = value;
83
+ }
80
84
  status = (status) => {
81
85
  this.#status = status;
82
86
  return this;
@@ -90,7 +94,10 @@ class Context {
90
94
  text(content, init) {
91
95
  return this.createResponse(content, {
92
96
  ...init,
93
- headers: { "Content-Type": "text/plain; charset=utf-8", ...init?.headers }
97
+ headers: {
98
+ "Content-Type": "text/plain; charset=utf-8",
99
+ ...init?.headers,
100
+ },
94
101
  });
95
102
  }
96
103
  html(strings, ...args) {
@@ -101,35 +108,51 @@ class Context {
101
108
  return result + str + value;
102
109
  }, "");
103
110
  return this.createResponse(html, {
104
- headers: { "Content-Type": "text/html; charset=utf-8" }
111
+ headers: {
112
+ "Content-Type": "text/html; charset=utf-8",
113
+ },
105
114
  });
106
115
  }
107
116
  else {
108
117
  let init = args?.[0];
109
118
  return this.createResponse(html, {
110
119
  ...init,
111
- headers: { "Content-Type": "text/html; charset=utf-8", ...init?.headers }
120
+ headers: {
121
+ "Content-Type": "text/html; charset=utf-8",
122
+ ...init?.headers,
123
+ },
112
124
  });
113
125
  }
114
126
  }
115
127
  xml(xml, init) {
116
128
  return this.createResponse(xml, {
117
129
  ...init,
118
- headers: { "Content-Type": "application/xml; charset=utf-8", ...init?.headers }
130
+ headers: {
131
+ "Content-Type": "application/xml; charset=utf-8",
132
+ ...init?.headers,
133
+ },
119
134
  });
120
135
  }
121
136
  json(json, init) {
122
137
  return this.createResponse(JSON.stringify(json), {
123
138
  ...init,
124
- headers: { "Content-Type": "application/json; charset=utf-8", ...init?.headers }
139
+ headers: {
140
+ "Content-Type": "application/json; charset=utf-8",
141
+ ...init?.headers,
142
+ },
125
143
  });
126
144
  }
127
145
  send(body, init) {
128
146
  let { body: _body, type } = (0, response_js_1.determineContentTypeBody)(body);
129
- const contentType = init?.headers?.["Content-Type"] || init?.headers?.["content-type"] || type;
147
+ const contentType = init?.headers?.["Content-Type"] ||
148
+ init?.headers?.["content-type"] ||
149
+ type;
130
150
  return this.createResponse(_body, {
131
151
  ...init,
132
- headers: { "Content-Type": contentType, ...init?.headers }
152
+ headers: {
153
+ "Content-Type": contentType,
154
+ ...init?.headers,
155
+ },
133
156
  });
134
157
  }
135
158
  redirect(url, status = 302) {
@@ -139,7 +162,7 @@ class Context {
139
162
  });
140
163
  }
141
164
  async download(filePath, filename) {
142
- if (!await (0, file_js_1.fileExists)(filePath))
165
+ if (!(await (0, file_js_1.fileExists)(filePath)))
143
166
  throw Error("File not found");
144
167
  let buf = await (0, file_js_1.getFileBuffer)(filePath);
145
168
  return this.createResponse(buf, {
@@ -152,7 +175,7 @@ class Context {
152
175
  });
153
176
  }
154
177
  async sendFile(filePath, init) {
155
- if (!await (0, file_js_1.fileExists)(filePath))
178
+ if (!(await (0, file_js_1.fileExists)(filePath)))
156
179
  throw Error("File not found");
157
180
  let size = await (0, file_js_1.fileSize)(filePath);
158
181
  const ext = (0, low_level_js_1.extensionExtract)(filePath) || "";
@@ -37,7 +37,7 @@ class TezXRequest {
37
37
  return this.#headersCache;
38
38
  }
39
39
  get query() {
40
- return this.#queryCache ??= (0, url_js_1.url2query)(this.url);
40
+ return (this.#queryCache ??= (0, url_js_1.url2query)(this.url));
41
41
  }
42
42
  async #ensureRawBuffer() {
43
43
  if (this.#bodyConsumed)
@@ -84,11 +84,12 @@ class TezXRequest {
84
84
  const ct = this.#contentType;
85
85
  if (!ct)
86
86
  throw new Error("Missing Content-Type");
87
- if (ct === "application/x-www-form-urlencoded" || ct === "multipart/form-data") {
87
+ if (ct === "application/x-www-form-urlencoded" ||
88
+ ct === "multipart/form-data") {
88
89
  if (this.#bodyConsumed) {
89
90
  throw new Error("Multipart body already consumed elsewhere");
90
91
  }
91
- this.#cachedFormObject = await this.#rawRequest.formData();
92
+ this.#cachedFormObject = (await this.#rawRequest.formData());
92
93
  this.#bodyConsumed = true;
93
94
  return this.#cachedFormObject;
94
95
  }
@@ -7,9 +7,9 @@ class Router {
7
7
  env = {};
8
8
  router;
9
9
  route = [];
10
- staticFileRouter = Object.create(null);
10
+ staticFile = Object.create(null);
11
11
  basePath;
12
- constructor({ basePath = "/", env = {}, routeRegistry = new RadixRouter_js_1.RadixRouter() } = {}) {
12
+ constructor({ basePath = "/", env = {}, routeRegistry = new RadixRouter_js_1.RadixRouter(), } = {}) {
13
13
  this.router = routeRegistry;
14
14
  this.basePath = basePath;
15
15
  this.env = { ...env };
@@ -24,7 +24,7 @@ class Router {
24
24
  static(serveStatic) {
25
25
  if (Array.isArray(serveStatic?.files)) {
26
26
  serveStatic?.files.forEach((r) => {
27
- this.staticFileRouter[`GET ${r?.route}`] = (ctx) => {
27
+ this.staticFile[`GET ${r?.route}`] = (ctx) => {
28
28
  if (serveStatic?.options?.cacheControl) {
29
29
  ctx.setHeader("Cache-Control", serveStatic?.options.cacheControl);
30
30
  }
@@ -69,8 +69,11 @@ class Router {
69
69
  this.#registerRoute("ALL", path, ...args);
70
70
  return this;
71
71
  }
72
- addRoute(method, path, ...args) {
73
- this.#registerRoute(method, path, ...args);
72
+ when(methods, path, ...args) {
73
+ const methodList = Array.isArray(methods) ? methods : [methods];
74
+ for (const method of methodList) {
75
+ this.#registerRoute(method.toUpperCase(), path, ...args);
76
+ }
74
77
  return this;
75
78
  }
76
79
  addRouter(path, router) {
@@ -134,7 +137,7 @@ class Router {
134
137
  this.route.push({
135
138
  method: method,
136
139
  pattern: pattern,
137
- handlers: handlers
140
+ handlers: handlers,
138
141
  });
139
142
  }
140
143
  #registerRoute(method, path, ...args) {
@@ -175,17 +178,17 @@ class Router {
175
178
  }
176
179
  if (this.router?.mergeRouter) {
177
180
  const parts = (0, low_level_js_1.sanitizePathSplitBasePath)(this.basePath, path);
178
- router.route.forEach(r => {
181
+ router.route.forEach((r) => {
179
182
  this.#addRoute(r?.method, `/${(0, low_level_js_1.sanitizePathSplitBasePath)(path, r?.pattern).join("/")}`, r?.handlers, true);
180
183
  });
181
184
  this.router.mergeRouter(`/${parts.join("/")}`, router.router);
182
185
  }
183
186
  else {
184
- router.route.forEach(r => {
187
+ router.route.forEach((r) => {
185
188
  this.#addRoute(r?.method, `/${(0, low_level_js_1.sanitizePathSplitBasePath)(path, r?.pattern).join("/")}`, r?.handlers);
186
189
  });
187
190
  }
188
- Object.assign(this.staticFileRouter, router.staticFileRouter);
191
+ Object.assign(this.staticFile, router.staticFile);
189
192
  }
190
193
  }
191
194
  exports.Router = Router;
@@ -40,7 +40,7 @@ class TezX extends router_js_1.Router {
40
40
  }
41
41
  #chain(middlewares) {
42
42
  if (!Array.isArray(middlewares)) {
43
- throw new TypeError('Middleware stack must be an array!');
43
+ throw new TypeError("Middleware stack must be an array!");
44
44
  }
45
45
  const len = middlewares.length;
46
46
  return async function (ctx) {
@@ -76,7 +76,7 @@ class TezX extends router_js_1.Router {
76
76
  pathname,
77
77
  method,
78
78
  env: this.env,
79
- args
79
+ args,
80
80
  });
81
81
  try {
82
82
  if (method === "HEAD") {
@@ -89,12 +89,13 @@ class TezX extends router_js_1.Router {
89
89
  });
90
90
  }
91
91
  const staticKey = `${method} ${pathname}`;
92
- const staticHandler = this.staticFileRouter?.[staticKey];
92
+ const staticHandler = this.staticFile?.[staticKey];
93
93
  if (staticHandler) {
94
94
  return staticHandler(ctx);
95
95
  }
96
96
  const route = this.router.search(method, pathname);
97
- if (!route || (route.handlers.length === 0 && route.middlewares.length === 0)) {
97
+ if (!route ||
98
+ (route.handlers.length === 0 && route.middlewares.length === 0)) {
98
99
  return this.#notFound(ctx);
99
100
  }
100
101
  ctx.params = route.params;
@@ -106,7 +107,10 @@ class TezX extends router_js_1.Router {
106
107
  return ctx.send(ctx.body);
107
108
  return this.#notFound(ctx);
108
109
  }
109
- let res = await this.#chain([...route.middlewares, ...route.handlers])(ctx);
110
+ let res = await this.#chain([
111
+ ...route.middlewares,
112
+ ...route.handlers,
113
+ ])(ctx);
110
114
  if (!res && ctx.body !== undefined) {
111
115
  res = ctx.send(ctx.body);
112
116
  }
package/cjs/deno/index.js CHANGED
@@ -13,5 +13,5 @@ exports.default = {
13
13
  serveStatic: serveStatic_js_1.serveStatic,
14
14
  getConnInfo: getConnInfo_js_1.getConnInfo,
15
15
  loadEnv: env_js_1.loadEnv,
16
- upgradeWebSocket: ws_js_1.upgradeWebSocket
16
+ upgradeWebSocket: ws_js_1.upgradeWebSocket,
17
17
  };
@@ -27,7 +27,7 @@ function serveStatic(...args) {
27
27
  }
28
28
  return {
29
29
  files: getFiles(dir, route, options),
30
- options
30
+ options,
31
31
  };
32
32
  }
33
33
  function getFiles(dir, basePath = "/", option = {}) {
@@ -35,7 +35,7 @@ function getFiles(dir, basePath = "/", option = {}) {
35
35
  for (const entry of Deno.readDirSync(dir)) {
36
36
  const path = `${dir}/${entry.name}`;
37
37
  if (entry.isDirectory) {
38
- files.push(...(getFiles(path, `${basePath}/${entry.name}`, option)));
38
+ files.push(...getFiles(path, `${basePath}/${entry.name}`, option));
39
39
  }
40
40
  else {
41
41
  const ext = (0, low_level_js_1.extensionExtract)(entry.name);
@@ -44,7 +44,7 @@ function getFiles(dir, basePath = "/", option = {}) {
44
44
  }
45
45
  files.push({
46
46
  fileSource: path,
47
- route: `/${(0, low_level_js_1.sanitizePathSplitBasePath)(basePath, entry.name).join("/")}`
47
+ route: `/${(0, low_level_js_1.sanitizePathSplitBasePath)(basePath, entry.name).join("/")}`,
48
48
  });
49
49
  }
50
50
  }
@@ -33,11 +33,22 @@ Object.defineProperty(exports, "useFormData", { enumerable: true, get: function
33
33
  exports.default = {
34
34
  useFormData: formData_js_1.useFormData,
35
35
  Environment: runtime_js_1.Environment,
36
- extensionExtract: low_level_js_1.extensionExtract, normalizeHeaderKey: low_level_js_1.normalizeHeaderKey, sanitizePathSplit: low_level_js_1.sanitizePathSplit, sanitizePathSplitBasePath: low_level_js_1.sanitizePathSplitBasePath, sanitized: low_level_js_1.sanitized,
37
- allCookies: cookie_js_1.allCookies, deleteCookie: cookie_js_1.deleteCookie, getCookie: cookie_js_1.getCookie, setCookie: cookie_js_1.setCookie,
38
- fileExists: file_js_1.fileExists, fileSize: file_js_1.fileSize, getFileBuffer: file_js_1.getFileBuffer, readStream: file_js_1.readStream,
39
- generateID: generateID_js_1.generateID, generateUUID: generateID_js_1.generateUUID,
36
+ extensionExtract: low_level_js_1.extensionExtract,
37
+ normalizeHeaderKey: low_level_js_1.normalizeHeaderKey,
38
+ sanitizePathSplit: low_level_js_1.sanitizePathSplit,
39
+ sanitizePathSplitBasePath: low_level_js_1.sanitizePathSplitBasePath,
40
+ sanitized: low_level_js_1.sanitized,
41
+ allCookies: cookie_js_1.allCookies,
42
+ deleteCookie: cookie_js_1.deleteCookie,
43
+ getCookie: cookie_js_1.getCookie,
44
+ setCookie: cookie_js_1.setCookie,
45
+ fileExists: file_js_1.fileExists,
46
+ fileSize: file_js_1.fileSize,
47
+ getFileBuffer: file_js_1.getFileBuffer,
48
+ readStream: file_js_1.readStream,
49
+ generateID: generateID_js_1.generateID,
50
+ generateUUID: generateID_js_1.generateUUID,
40
51
  httpStatusMap: httpStatusMap_js_1.httpStatusMap,
41
52
  colorText: colors_js_1.colorText,
42
- GlobalConfig: config_js_1.GlobalConfig
53
+ GlobalConfig: config_js_1.GlobalConfig,
43
54
  };
package/cjs/index.js CHANGED
@@ -5,7 +5,7 @@ const router_js_1 = require("./core/router.js");
5
5
  Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_js_1.Router; } });
6
6
  const server_js_1 = require("./core/server.js");
7
7
  Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_1.TezX; } });
8
- exports.version = "3.0.3-beta";
8
+ exports.version = "3.0.5-beta";
9
9
  exports.default = {
10
10
  Router: router_js_1.Router,
11
11
  TezX: server_js_1.TezX,
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.basicAuth = void 0;
4
4
  const node_buffer_1 = require("node:buffer");
5
- const config_js_1 = require("../../core/config.js");
6
- const colors_js_1 = require("../../utils/colors.js");
7
- const rateLimit_js_1 = require("../../utils/rateLimit.js");
5
+ const config_js_1 = require("../core/config.js");
6
+ const colors_js_1 = require("../utils/colors.js");
7
+ const rateLimit_js_1 = require("../utils/rateLimit.js");
8
8
  const basicAuth = (options) => {
9
9
  const { validateCredentials, getRealm = () => "Restricted Area", onUnauthorized = (ctx, error) => {
10
10
  const realm = getRealm(ctx);
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.default = exports.cacheControl = void 0;
37
- const config_js_1 = require("../../core/config.js");
37
+ const config_js_1 = require("../core/config.js");
38
38
  const cacheControl = (options) => {
39
39
  const { defaultSettings, useWeakETag = false, rules = [], logEvent = (event, ctx, error) => {
40
40
  if (event === "error") {
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.detectBot = void 0;
4
- const config_js_1 = require("../../core/config.js");
5
- const rateLimit_js_1 = require("../../utils/rateLimit.js");
4
+ const config_js_1 = require("../core/config.js");
5
+ const rateLimit_js_1 = require("../utils/rateLimit.js");
6
6
  const detectBot = (options = {}) => {
7
7
  const { botUserAgents = ["bot", "spider", "crawl", "slurp"], maxRequests = 30, windowMs = 60000, isBlacklisted = async () => false, queryKeyBot = "bot", onBotDetected = "block", enableRateLimiting = false, customBotDetector = async () => false, customBlockedResponse = (ctx, { reason }) => {
8
8
  ctx.setStatus = 403;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.detectLocale = void 0;
4
- const config_js_1 = require("../../core/config.js");
5
- const cookie_js_1 = require("../../utils/cookie.js");
4
+ const config_js_1 = require("../core/config.js");
5
+ const cookie_js_1 = require("../utils/cookie.js");
6
6
  const detectLocale = (options) => {
7
7
  const { supportedLocales, defaultLocale = "en", queryKeyLocale = "lang", cookieKeyLocale = "locale", localeContextKey = "locale", customLocaleDetector, } = options;
8
8
  return async function detectLocale(ctx, next) {
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.i18n = void 0;
4
- const config_js_1 = require("../../core/config.js");
5
- const cookie_js_1 = require("../../utils/cookie.js");
4
+ const config_js_1 = require("../core/config.js");
5
+ const cookie_js_1 = require("../utils/cookie.js");
6
6
  const i18n = (options) => {
7
7
  const { loadTranslations, defaultCacheDuration = 3600000, isCacheValid = (cached) => cached.expiresAt > Date.now(), detectLanguage = (ctx) => {
8
8
  if (ctx.req.query.lang) {
9
9
  return ctx.req.query.lang;
10
10
  }
11
- else if ((0, cookie_js_1.getCookie)(ctx, 'lang')) {
12
- return ctx.cookies?.['lang'];
11
+ else if ((0, cookie_js_1.getCookie)(ctx, "lang")) {
12
+ return ctx.cookies?.["lang"];
13
13
  }
14
14
  else if (ctx.req.header("accept-language")) {
15
15
  const lang = ctx.req.header("accept-language")?.split(",")[0];
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.lazyLoader = void 0;
4
- const config_js_1 = require("../../core/config.js");
4
+ const config_js_1 = require("../core/config.js");
5
5
  const lazyLoader = (options) => {
6
6
  const { moduleKey = (ctx) => ctx.req.params[queryKeyModule] || ctx.req.query[queryKeyModule], getModuleLoader, queryKeyModule = "module", moduleContextKey = "module", cacheTTL = 3600000, enableCache = true, cacheStorage, lifecycleHooks = {}, validateModule, } = options;
7
7
  let storage = cacheStorage;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logger = logger;
4
4
  exports.default = logger;
5
- const colors_js_1 = require("../../utils/colors.js");
5
+ const colors_js_1 = require("../utils/colors.js");
6
6
  function logger() {
7
7
  return async function logger(ctx, next) {
8
8
  try {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rateLimiter = void 0;
4
- const rateLimit_js_1 = require("../../utils/rateLimit.js");
3
+ exports.default = exports.rateLimiter = void 0;
4
+ const rateLimit_js_1 = require("../utils/rateLimit.js");
5
5
  const rateLimiter = (options) => {
6
6
  const { maxRequests, windowMs, keyGenerator = (ctx) => `${ctx.req.remoteAddress.address}:${ctx.req.remoteAddress.port}`, storage = (0, rateLimit_js_1.createRateLimitDefaultStorage)(), onError = (ctx, retryAfter, error) => {
7
7
  ctx.setStatus = 429;
@@ -22,3 +22,4 @@ const rateLimiter = (options) => {
22
22
  };
23
23
  };
24
24
  exports.rateLimiter = rateLimiter;
25
+ exports.default = rateLimiter;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.requestID = void 0;
4
- const index_js_1 = require("../../helper/index.js");
4
+ const index_js_1 = require("../helper/index.js");
5
5
  const requestID = (headerName = "X-Request-ID", contextKey = "requestID") => {
6
6
  return function requestID(ctx, next) {
7
7
  let requestId = ctx.header(headerName);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.requestTimeout = void 0;
4
- const config_js_1 = require("../../core/config.js");
4
+ const config_js_1 = require("../core/config.js");
5
5
  const requestTimeout = (options) => {
6
6
  const { getTimeout, onTimeout = (ctx) => {
7
7
  ctx.setStatus = 504;
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sanitizeHeaders = exports.default = void 0;
4
- const config_js_1 = require("../../core/config.js");
4
+ const config_js_1 = require("../core/config.js");
5
5
  const sanitizeHeaders = (options = {}) => {
6
6
  const { whitelist = [], blacklist = [], allowUnsafeCharacters = false, } = options;
7
- const normalizedWhitelist = whitelist.map(h => h.toLowerCase());
8
- const normalizedBlacklist = blacklist.map(h => h.toLowerCase());
7
+ const normalizedWhitelist = whitelist.map((h) => h.toLowerCase());
8
+ const normalizedBlacklist = blacklist.map((h) => h.toLowerCase());
9
9
  return async function sanitizeHeaders(ctx, next) {
10
10
  const sanitizedHeaders = {};
11
11
  for (const key in ctx.header()) {
12
12
  let value = ctx.header(key);
13
13
  const normalizedKey = key.toLowerCase();
14
- if (normalizedWhitelist.length > 0 && !normalizedWhitelist.includes(normalizedKey)) {
14
+ if (normalizedWhitelist.length > 0 &&
15
+ !normalizedWhitelist.includes(normalizedKey)) {
15
16
  config_js_1.GlobalConfig.debugging.warn(`🚫 Header "${key}" not in whitelist - removed`);
16
17
  continue;
17
18
  }
@@ -34,7 +35,6 @@ const sanitizeHeaders = (options = {}) => {
34
35
  let v = sanitizedHeaders[k];
35
36
  ctx.setHeader(k, v);
36
37
  }
37
- ;
38
38
  ctx.clearHeader = sanitizedHeaders;
39
39
  return await next();
40
40
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.xssProtection = void 0;
4
- const config_js_1 = require("../../core/config.js");
4
+ const config_js_1 = require("../core/config.js");
5
5
  const xssProtection = (options = {}) => {
6
6
  const { enabled = true, mode = "block", fallbackCSP = "default-src 'self'; script-src 'self';", } = options;
7
7
  return async function xssProtection(ctx, next) {
@@ -27,14 +27,16 @@ function readableStreamToNodeStream(stream) {
27
27
  });
28
28
  }
29
29
  function mountTezXOnNode(app, server) {
30
- server.on('request', async (req, res) => {
30
+ server.on("request", async (req, res) => {
31
31
  try {
32
32
  const request = (0, toWebRequest_js_1.toWebRequest)(req, req.method);
33
33
  const response = await app.serve(request, req, res, server);
34
34
  if (res.writableEnded || res.headersSent)
35
35
  return;
36
- const { status = 200, statusText = '', headers = {}, body } = response;
37
- const nodeHeaders = Object.fromEntries(headers instanceof Headers ? headers.entries() : Object.entries(headers));
36
+ const { status = 200, statusText = "", headers = {}, body } = response;
37
+ const nodeHeaders = Object.fromEntries(headers instanceof Headers
38
+ ? headers.entries()
39
+ : Object.entries(headers));
38
40
  res.writeHead(status, statusText, nodeHeaders);
39
41
  if (!body) {
40
42
  return res.end();
@@ -42,15 +44,16 @@ function mountTezXOnNode(app, server) {
42
44
  if (body instanceof node_stream_1.Readable) {
43
45
  return body.pipe(res);
44
46
  }
45
- if (typeof body.getReader === 'function') {
46
- return node_stream_1.Readable.fromWeb?.(body)?.pipe?.(res) ?? readableStreamToNodeStream(body).pipe(res);
47
+ if (typeof body.getReader === "function") {
48
+ return (node_stream_1.Readable.fromWeb?.(body)?.pipe?.(res) ??
49
+ readableStreamToNodeStream(body).pipe(res));
47
50
  }
48
51
  res.end(body);
49
52
  }
50
53
  catch (err) {
51
54
  res.statusCode = 500;
52
- config_js_1.GlobalConfig.debugging?.error?.(err?.message || 'Unknown error');
53
- res.end(err?.message || 'Internal Server Error');
55
+ config_js_1.GlobalConfig.debugging?.error?.(err?.message || "Unknown error");
56
+ res.end(err?.message || "Internal Server Error");
54
57
  }
55
58
  });
56
59
  }
@@ -29,7 +29,7 @@ function serveStatic(...args) {
29
29
  }
30
30
  return {
31
31
  files: getFiles(dir, route, options),
32
- options
32
+ options,
33
33
  };
34
34
  }
35
35
  function getFiles(dir, basePath = "/", option = {}) {
@@ -47,7 +47,7 @@ function getFiles(dir, basePath = "/", option = {}) {
47
47
  }
48
48
  files.push({
49
49
  fileSource: fullPath,
50
- route: `/${(0, low_level_js_1.sanitizePathSplitBasePath)(basePath, entry.name).join("/")}`
50
+ route: `/${(0, low_level_js_1.sanitizePathSplitBasePath)(basePath, entry.name).join("/")}`,
51
51
  });
52
52
  }
53
53
  }
@@ -3,9 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toWebRequest = toWebRequest;
4
4
  const node_stream_1 = require("node:stream");
5
5
  function toWebRequest(req, method = "GET") {
6
- const protocol = (req.socket && req.socket.encrypted) ? "https:" : "http:";
6
+ const protocol = req.socket && req.socket.encrypted ? "https:" : "http:";
7
7
  const upperMethod = method.length === 3
8
- ? (method === "get" ? "GET" : (method === "put" ? "PUT" : method.toUpperCase()))
8
+ ? method === "get"
9
+ ? "GET"
10
+ : method === "put"
11
+ ? "PUT"
12
+ : method.toUpperCase()
9
13
  : method.toUpperCase();
10
14
  let host = req.headers.host || "localhost";
11
15
  const hasBody = upperMethod !== "GET" && upperMethod !== "HEAD";