@tezx/devtools 1.0.13 → 4.0.1

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/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -25,7 +25,6 @@ In your TezX app entry (e.g., `server.ts` or `index.ts`):
25
25
 
26
26
  ```ts
27
27
  import { TezX } from "tezx";
28
- import {nodeAdapter} from "tezx/node";
29
28
  import DevTools from "@tezx/devtools";
30
29
 
31
30
  const app = new TezX();
@@ -39,7 +38,6 @@ app.get(
39
38
  })
40
39
  );
41
40
 
42
- nodeAdapter(app).listen(3000);
43
41
  ```
44
42
 
45
43
  Now visit:
@@ -74,35 +72,6 @@ DevTools(app: TezX<any>, options?: Options): Callback
74
72
 
75
73
  ---
76
74
 
77
- ## 🛠️ Add Custom Tabs
78
-
79
- You can inject your own debug panels using the `extraTabs` option.
80
-
81
- ```ts
82
- import DevTools , { dumpMiddlewares } from "@tezx/devtools";
83
-
84
- app.get(
85
- "/devtools",
86
- DevTools(app, {
87
- extraTabs(ctx) {
88
- const rows = dumpMiddlewares(app)
89
- .map(r => `<tr><td>${r.endpoint}</td><td>${r.pattern}</td><td>${r.appliedMiddlewares}</td></tr>`)
90
- .join("");
91
- return [
92
- {
93
- tab: "middlewares",
94
- label: "Middleware Table",
95
- doc_title: "Middleware Overview",
96
- content: `<table>${rows}</table>`
97
- }
98
- ];
99
- }
100
- })
101
- );
102
- ```
103
-
104
- ---
105
-
106
75
  ## 📚 Types
107
76
 
108
77
  ```ts
package/cjs/html/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.html = html;
4
4
  const cookies_js_1 = require("./cookies.js");
5
- const env_js_1 = require("./env.js");
6
5
  const routes_js_1 = require("./routes.js");
7
6
  const StaticFile_js_1 = require("./StaticFile.js");
8
7
  function html(ctx, app) {
@@ -25,12 +24,6 @@ function html(ctx, app) {
25
24
  doc_title: "DevTools - Cookie Inspector",
26
25
  content: (0, cookies_js_1.CookiesInspector)(ctx),
27
26
  },
28
- {
29
- tab: ".env",
30
- label: "Environment",
31
- doc_title: "DevTools - Environment",
32
- content: (0, env_js_1.EnvInspector)(ctx),
33
- },
34
27
  ];
35
28
  return tabDb;
36
29
  }
package/cjs/index.js CHANGED
@@ -1,11 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DevTools = DevTools;
4
- const helper_1 = require("tezx/helper");
5
4
  const index_js_1 = require("./html/index.js");
6
- function DevTools(app, options = { disableTabs: [] }) {
7
- let { disableTabs, extraTabs } = options;
5
+ function DevTools(app, options = {
6
+ disableTabs: [],
7
+ enable: true,
8
+ }) {
9
+ let { disableTabs } = options;
8
10
  return async (ctx) => {
11
+ if (!options?.enable) {
12
+ return ctx
13
+ .status(404)
14
+ .json({ error: "Devtools not enabled in this environment" });
15
+ }
9
16
  let extraTabs = await (typeof options.extraTabs === "function"
10
17
  ? options.extraTabs(ctx)
11
18
  : []);
@@ -26,14 +33,11 @@ function DevTools(app, options = { disableTabs: [] }) {
26
33
  </div>
27
34
  <div class="tabs">
28
35
  <a class="toggle-dark" onclick="toggleTheme()">🌙 Toggle Dark</a>
29
- <a class="active">
30
- ${helper_1.GlobalConfig.adapter}
31
- </a>
32
36
  </div>
33
37
  </header>
34
38
  `;
35
39
  let find = html.find((r) => r?.tab == tab);
36
- return ctx.html `
40
+ return ctx.html(`
37
41
  <!DOCTYPE html>
38
42
  <html lang="en">
39
43
  <head>
@@ -392,7 +396,7 @@ function DevTools(app, options = { disableTabs: [] }) {
392
396
  </script>
393
397
  </body>
394
398
  </html>
395
- `;
399
+ `);
396
400
  };
397
401
  }
398
402
  exports.default = DevTools;
package/html/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { CookiesInspector } from "./cookies.js";
2
- import { EnvInspector } from "./env.js";
3
2
  import { Routes } from "./routes.js";
4
3
  import { StaticFile } from "./StaticFile.js";
5
4
  export function html(ctx, app) {
@@ -22,12 +21,6 @@ export function html(ctx, app) {
22
21
  doc_title: "DevTools - Cookie Inspector",
23
22
  content: CookiesInspector(ctx),
24
23
  },
25
- {
26
- tab: ".env",
27
- label: "Environment",
28
- doc_title: "DevTools - Environment",
29
- content: EnvInspector(ctx),
30
- },
31
24
  ];
32
25
  return tabDb;
33
26
  }
package/index.d.ts CHANGED
@@ -1,8 +1,16 @@
1
1
  import { Callback, Context, TezX } from "tezx";
2
2
  import { Tab, TabType } from "./html/index.js";
3
+ /**
4
+ * Configuration options for the devtools.
5
+ *
6
+ * @property extraTabs - A function that receives the current context and returns additional tabs to be displayed. Can return a single tab or a promise resolving to a tab.
7
+ * @property disableTabs - An array of tabs to be disabled in the UI.
8
+ * @property enable - Indicates whether the devtools should be enabled. Set to `true` to activate devtools, or `false` to disable (e.g., in production).
9
+ */
3
10
  export type Options = {
4
11
  extraTabs?: (ctx: Context) => Promise<TabType> | TabType;
5
12
  disableTabs?: Tab[];
13
+ enable?: boolean;
6
14
  };
7
15
  export declare function DevTools(app: TezX<any>, options?: Options): Callback;
8
16
  export default DevTools;
package/index.js CHANGED
@@ -1,8 +1,15 @@
1
- import { GlobalConfig } from "tezx/helper";
2
1
  import { html as htmlTab } from "./html/index.js";
3
- export function DevTools(app, options = { disableTabs: [] }) {
4
- let { disableTabs, extraTabs } = options;
2
+ export function DevTools(app, options = {
3
+ disableTabs: [],
4
+ enable: true,
5
+ }) {
6
+ let { disableTabs } = options;
5
7
  return async (ctx) => {
8
+ if (!options?.enable) {
9
+ return ctx
10
+ .status(404)
11
+ .json({ error: "Devtools not enabled in this environment" });
12
+ }
6
13
  let extraTabs = await (typeof options.extraTabs === "function"
7
14
  ? options.extraTabs(ctx)
8
15
  : []);
@@ -23,14 +30,11 @@ export function DevTools(app, options = { disableTabs: [] }) {
23
30
  </div>
24
31
  <div class="tabs">
25
32
  <a class="toggle-dark" onclick="toggleTheme()">🌙 Toggle Dark</a>
26
- <a class="active">
27
- ${GlobalConfig.adapter}
28
- </a>
29
33
  </div>
30
34
  </header>
31
35
  `;
32
36
  let find = html.find((r) => r?.tab == tab);
33
- return ctx.html `
37
+ return ctx.html(`
34
38
  <!DOCTYPE html>
35
39
  <html lang="en">
36
40
  <head>
@@ -389,7 +393,7 @@ export function DevTools(app, options = { disableTabs: [] }) {
389
393
  </script>
390
394
  </body>
391
395
  </html>
392
- `;
396
+ `);
393
397
  };
394
398
  }
395
399
  export default DevTools;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tezx/devtools",
3
- "version": "1.0.13",
3
+ "version": "4.0.1",
4
4
  "description": "Developer tools for the TezX framework, including route inspector, cookie manager, and real-time diagnostics. Lightweight and plug-and-play compatible with Node.js, Bun, and Deno.",
5
5
  "type": "module",
6
6
  "main": "cjs/index.cjs",
package/cjs/html/env.js DELETED
@@ -1,135 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EnvInspector = EnvInspector;
4
- function EnvInspector(ctx) {
5
- const env = ctx.env;
6
- const entries = Object.entries(env);
7
- const tableRows = entries.length
8
- ? entries
9
- .map(([key, value], i) => {
10
- const safeKey = key.replace(/"/g, "&quot;");
11
- const safeValue = value.replace(/`/g, "\\`").replace(/"/g, "&quot;");
12
- return `
13
- <tr data-key="${safeKey.toLowerCase()}" data-value="${value.toLowerCase()}">
14
- <td>${i + 1}</td>
15
- <td><code>${safeKey}</code></td>
16
- <td><code>${value}</code></td>
17
- <td>
18
- <button class="copy-btn" onclick="copyRowEnv('${safeKey}', \`${safeValue}\`)" title="Copy">
19
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
20
- <path d="M10 1.5A1.5 1.5 0 0 1 11.5 3v1h-1V3a.5.5 0 0 0-.5-.5H4A1.5 1.5 0 0 0 2.5 4v8A1.5 1.5 0 0 0 4 13.5H5v1H4A2.5 2.5 0 0 1 1.5 12V4A2.5 2.5 0 0 1 4 1.5h6z"/>
21
- <path d="M5.5 5A1.5 1.5 0 0 0 4 6.5v7A1.5 1.5 0 0 0 5.5 15h6A1.5 1.5 0 0 0 13 13.5v-7A1.5 1.5 0 0 0 11.5 5h-6zM5 6.5A.5.5 0 0 1 5.5 6h6a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-7z"/>
22
- </svg>
23
- </button>
24
- </td>
25
- </tr>`;
26
- })
27
- .join("")
28
- : `
29
- <tr>
30
- <td colspan="4">
31
- <p>⚠️ <strong>No environment variables found.</strong></p>
32
- <pre class="code-block">
33
- const env = loadEnv();
34
-
35
- export const app = new TezX({
36
- env: env,
37
- debugMode: true,
38
- allowDuplicateMw: true,
39
- });
40
- </pre>
41
- </td>
42
- </tr>`;
43
- return `
44
- <style>
45
- .search-container {
46
- margin-bottom: 1rem;
47
- }
48
-
49
- .search-container input {
50
- padding: 0.5rem;
51
- width: 100%;
52
- max-width: 400px;
53
- border: 1px solid #cbd5e1;
54
- border-radius: 0.375rem;
55
- }
56
-
57
- .code-block {
58
- background: #f1f5f9;
59
- padding: 1rem;
60
- border-radius: 0.5rem;
61
- font-size: 0.875rem;
62
- }
63
-
64
- </style>
65
-
66
- <div class="tabs">
67
- <a onclick="exportEnv()">📤 Export JSON</a>
68
- <a onclick="copyAllEnv()">📋 Copy All</a>
69
- </div>
70
-
71
- <div class="search-container">
72
- <input type="text" id="env-search" placeholder="🔍 Search environment variables..." oninput="filterEnvTable()" />
73
- </div>
74
-
75
- <div class="table-container">
76
- <table>
77
- <thead>
78
- <tr>
79
- <th>#</th>
80
- <th>Key</th>
81
- <th>Value</th>
82
- <th>Copy</th>
83
- </tr>
84
- </thead>
85
- <tbody id="env-body">
86
- ${tableRows}
87
- </tbody>
88
- </table>
89
- </div>
90
-
91
- <pre id="json-output">${JSON.stringify(env, null, 2)}</pre>
92
-
93
- <script>
94
- function exportEnv() {
95
- const output = document.getElementById('json-output');
96
- const blob = new Blob([output.textContent], { type: 'application/json' });
97
- const url = URL.createObjectURL(blob);
98
- const a = document.createElement('a');
99
- a.href = url;
100
- a.download = 'env.json';
101
- a.click();
102
- URL.revokeObjectURL(url);
103
- }
104
-
105
- function copyAllEnv() {
106
- const output = document.getElementById('json-output');
107
- navigator.clipboard.writeText(output.textContent).then(() => {
108
- showToast('✅ All environment variables copied!');
109
- }).catch(err => {
110
- alert('❌ Failed to copy: ' + err);
111
- });
112
- }
113
-
114
- function copyRowEnv(key, value) {
115
- const text = \`\${key}=\${value}\`;
116
- navigator.clipboard.writeText(text).then(() => {
117
- showToast(\`✅ Copied: \${key}\`);
118
- }).catch(err => {
119
- alert('❌ Failed to copy: ' + err);
120
- });
121
- }
122
-
123
- function filterEnvTable() {
124
- const input = document.getElementById('env-search').value.toLowerCase();
125
- const rows = document.querySelectorAll('#env-body tr');
126
-
127
- rows.forEach(row => {
128
- const key = row.getAttribute('data-key') || '';
129
- const value = row.getAttribute('data-value') || '';
130
- row.style.display = (key.includes(input) || value.includes(input)) ? '' : 'none';
131
- });
132
- }
133
- </script>
134
- `;
135
- }
package/html/env.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { Context } from "tezx";
2
- export declare function EnvInspector(ctx: Context): string;
package/html/env.js DELETED
@@ -1,132 +0,0 @@
1
- export function EnvInspector(ctx) {
2
- const env = ctx.env;
3
- const entries = Object.entries(env);
4
- const tableRows = entries.length
5
- ? entries
6
- .map(([key, value], i) => {
7
- const safeKey = key.replace(/"/g, "&quot;");
8
- const safeValue = value.replace(/`/g, "\\`").replace(/"/g, "&quot;");
9
- return `
10
- <tr data-key="${safeKey.toLowerCase()}" data-value="${value.toLowerCase()}">
11
- <td>${i + 1}</td>
12
- <td><code>${safeKey}</code></td>
13
- <td><code>${value}</code></td>
14
- <td>
15
- <button class="copy-btn" onclick="copyRowEnv('${safeKey}', \`${safeValue}\`)" title="Copy">
16
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
17
- <path d="M10 1.5A1.5 1.5 0 0 1 11.5 3v1h-1V3a.5.5 0 0 0-.5-.5H4A1.5 1.5 0 0 0 2.5 4v8A1.5 1.5 0 0 0 4 13.5H5v1H4A2.5 2.5 0 0 1 1.5 12V4A2.5 2.5 0 0 1 4 1.5h6z"/>
18
- <path d="M5.5 5A1.5 1.5 0 0 0 4 6.5v7A1.5 1.5 0 0 0 5.5 15h6A1.5 1.5 0 0 0 13 13.5v-7A1.5 1.5 0 0 0 11.5 5h-6zM5 6.5A.5.5 0 0 1 5.5 6h6a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-.5.5h-6a.5.5 0 0 1-.5-.5v-7z"/>
19
- </svg>
20
- </button>
21
- </td>
22
- </tr>`;
23
- })
24
- .join("")
25
- : `
26
- <tr>
27
- <td colspan="4">
28
- <p>⚠️ <strong>No environment variables found.</strong></p>
29
- <pre class="code-block">
30
- const env = loadEnv();
31
-
32
- export const app = new TezX({
33
- env: env,
34
- debugMode: true,
35
- allowDuplicateMw: true,
36
- });
37
- </pre>
38
- </td>
39
- </tr>`;
40
- return `
41
- <style>
42
- .search-container {
43
- margin-bottom: 1rem;
44
- }
45
-
46
- .search-container input {
47
- padding: 0.5rem;
48
- width: 100%;
49
- max-width: 400px;
50
- border: 1px solid #cbd5e1;
51
- border-radius: 0.375rem;
52
- }
53
-
54
- .code-block {
55
- background: #f1f5f9;
56
- padding: 1rem;
57
- border-radius: 0.5rem;
58
- font-size: 0.875rem;
59
- }
60
-
61
- </style>
62
-
63
- <div class="tabs">
64
- <a onclick="exportEnv()">📤 Export JSON</a>
65
- <a onclick="copyAllEnv()">📋 Copy All</a>
66
- </div>
67
-
68
- <div class="search-container">
69
- <input type="text" id="env-search" placeholder="🔍 Search environment variables..." oninput="filterEnvTable()" />
70
- </div>
71
-
72
- <div class="table-container">
73
- <table>
74
- <thead>
75
- <tr>
76
- <th>#</th>
77
- <th>Key</th>
78
- <th>Value</th>
79
- <th>Copy</th>
80
- </tr>
81
- </thead>
82
- <tbody id="env-body">
83
- ${tableRows}
84
- </tbody>
85
- </table>
86
- </div>
87
-
88
- <pre id="json-output">${JSON.stringify(env, null, 2)}</pre>
89
-
90
- <script>
91
- function exportEnv() {
92
- const output = document.getElementById('json-output');
93
- const blob = new Blob([output.textContent], { type: 'application/json' });
94
- const url = URL.createObjectURL(blob);
95
- const a = document.createElement('a');
96
- a.href = url;
97
- a.download = 'env.json';
98
- a.click();
99
- URL.revokeObjectURL(url);
100
- }
101
-
102
- function copyAllEnv() {
103
- const output = document.getElementById('json-output');
104
- navigator.clipboard.writeText(output.textContent).then(() => {
105
- showToast('✅ All environment variables copied!');
106
- }).catch(err => {
107
- alert('❌ Failed to copy: ' + err);
108
- });
109
- }
110
-
111
- function copyRowEnv(key, value) {
112
- const text = \`\${key}=\${value}\`;
113
- navigator.clipboard.writeText(text).then(() => {
114
- showToast(\`✅ Copied: \${key}\`);
115
- }).catch(err => {
116
- alert('❌ Failed to copy: ' + err);
117
- });
118
- }
119
-
120
- function filterEnvTable() {
121
- const input = document.getElementById('env-search').value.toLowerCase();
122
- const rows = document.querySelectorAll('#env-body tr');
123
-
124
- rows.forEach(row => {
125
- const key = row.getAttribute('data-key') || '';
126
- const value = row.getAttribute('data-value') || '';
127
- row.style.display = (key.includes(input) || value.includes(input)) ? '' : 'none';
128
- });
129
- }
130
- </script>
131
- `;
132
- }