@weconjs/core 0.2.0 → 1.2.0
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/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +6 -8
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +30 -21
- package/dist/context.js.map +1 -1
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +1 -2
- package/dist/database/index.js.map +1 -1
- package/dist/devtools/client/assets/ModuleDetail-Cv1SUhav.js +1 -0
- package/dist/devtools/client/assets/TranslationEditor-CwBjcmjN.js +6 -0
- package/dist/devtools/client/assets/api-DHFLRYt1.js +11 -0
- package/dist/devtools/client/assets/arrow-left-XXd8AsXj.js +6 -0
- package/dist/devtools/client/assets/chevron-right-DN23SEYa.js +6 -0
- package/dist/devtools/client/assets/index-BFzJyDrn.css +1 -0
- package/dist/devtools/client/assets/index-BbARU3f6.js +1 -0
- package/dist/devtools/client/assets/index-Cwwdi5uz.js +181 -0
- package/dist/devtools/client/assets/index-DH5TZlGZ.js +6 -0
- package/dist/devtools/client/assets/index-DbBxhrHS.js +1 -0
- package/dist/devtools/client/assets/index-LkCf2mcb.js +1 -0
- package/dist/devtools/client/assets/index-jqJ0mfFs.js +6 -0
- package/dist/devtools/client/index.html +15 -0
- package/dist/devtools/controllers/config.controller.d.ts +28 -0
- package/dist/devtools/controllers/config.controller.d.ts.map +1 -0
- package/dist/devtools/controllers/config.controller.js +100 -0
- package/dist/devtools/controllers/config.controller.js.map +1 -0
- package/dist/devtools/controllers/i18n.controller.d.ts +22 -0
- package/dist/devtools/controllers/i18n.controller.d.ts.map +1 -0
- package/dist/devtools/controllers/i18n.controller.js +93 -0
- package/dist/devtools/controllers/i18n.controller.js.map +1 -0
- package/dist/devtools/controllers/modules.controller.d.ts +16 -0
- package/dist/devtools/controllers/modules.controller.d.ts.map +1 -0
- package/dist/devtools/controllers/modules.controller.js +73 -0
- package/dist/devtools/controllers/modules.controller.js.map +1 -0
- package/dist/devtools/controllers/routes.controller.d.ts +13 -0
- package/dist/devtools/controllers/routes.controller.d.ts.map +1 -0
- package/dist/devtools/controllers/routes.controller.js +32 -0
- package/dist/devtools/controllers/routes.controller.js.map +1 -0
- package/dist/devtools/index.d.ts +29 -0
- package/dist/devtools/index.d.ts.map +1 -0
- package/dist/devtools/index.js +94 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/devtools/middleware.d.ts +11 -0
- package/dist/devtools/middleware.d.ts.map +1 -0
- package/dist/devtools/middleware.js +30 -0
- package/dist/devtools/middleware.js.map +1 -0
- package/dist/devtools/types.d.ts +59 -0
- package/dist/devtools/types.d.ts.map +1 -0
- package/dist/devtools/types.js +5 -0
- package/dist/devtools/types.js.map +1 -0
- package/dist/errors/ConfigError.d.ts +6 -0
- package/dist/errors/ConfigError.d.ts.map +1 -0
- package/dist/errors/ConfigError.js +16 -0
- package/dist/errors/ConfigError.js.map +1 -0
- package/dist/errors/RequestError.d.ts +6 -0
- package/dist/errors/RequestError.d.ts.map +1 -0
- package/dist/errors/RequestError.js +16 -0
- package/dist/errors/RequestError.js.map +1 -0
- package/dist/errors/index.d.ts +9 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +5 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/module/index.d.ts +6 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +5 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/module-loader.d.ts +60 -0
- package/dist/module/module-loader.d.ts.map +1 -0
- package/dist/module/module-loader.js +119 -0
- package/dist/module/module-loader.js.map +1 -0
- package/dist/routing/ErrorCatcher.d.ts +18 -0
- package/dist/routing/ErrorCatcher.d.ts.map +1 -0
- package/dist/routing/ErrorCatcher.js +50 -0
- package/dist/routing/ErrorCatcher.js.map +1 -0
- package/dist/routing/RaiMatcher.d.ts +27 -0
- package/dist/routing/RaiMatcher.d.ts.map +1 -0
- package/dist/routing/RaiMatcher.js +127 -0
- package/dist/routing/RaiMatcher.js.map +1 -0
- package/dist/routing/Route.d.ts +28 -0
- package/dist/routing/Route.d.ts.map +1 -0
- package/dist/routing/Route.js +125 -0
- package/dist/routing/Route.js.map +1 -0
- package/dist/routing/Routes.d.ts +31 -0
- package/dist/routing/Routes.d.ts.map +1 -0
- package/dist/routing/Routes.js +151 -0
- package/dist/routing/Routes.js.map +1 -0
- package/dist/routing/RoutesParam.d.ts +29 -0
- package/dist/routing/RoutesParam.d.ts.map +1 -0
- package/dist/routing/RoutesParam.js +113 -0
- package/dist/routing/RoutesParam.js.map +1 -0
- package/dist/routing/Wecon.d.ts +66 -0
- package/dist/routing/Wecon.d.ts.map +1 -0
- package/dist/routing/Wecon.js +248 -0
- package/dist/routing/Wecon.js.map +1 -0
- package/dist/routing/index.d.ts +9 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +7 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/server/banner.d.ts +20 -0
- package/dist/server/banner.d.ts.map +1 -0
- package/dist/server/banner.js +77 -0
- package/dist/server/banner.js.map +1 -0
- package/dist/server/index.d.ts +29 -5
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +76 -12
- package/dist/server/index.js.map +1 -1
- package/dist/types.d.ts +75 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{c as m,r as a,j as e,m as h}from"./index-Cwwdi5uz.js";import{a as y,L as u}from"./api-DHFLRYt1.js";/**
|
|
2
|
+
* @license lucide-react v0.460.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const b=m("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]),f={GET:"bg-green-100 text-green-700",POST:"bg-blue-100 text-blue-700",PUT:"bg-yellow-100 text-yellow-700",PATCH:"bg-orange-100 text-orange-700",DELETE:"bg-red-100 text-red-700"};function N(){const[r,c]=a.useState([]),[n,d]=a.useState(!0),[s,i]=a.useState("");if(a.useEffect(()=>{y.get("/routes").then(t=>c(t.data)).catch(console.error).finally(()=>d(!1))},[]),n)return e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(u,{className:"size-8 animate-spin text-primary"})});const x=r.filter(t=>t.path.toLowerCase().includes(s.toLowerCase())||t.rai.toLowerCase().includes(s.toLowerCase())||t.method.toLowerCase().includes(s.toLowerCase()));return e.jsxs(h.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},transition:{duration:.3},className:"flex size-full flex-col gap-6 overflow-y-auto p-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:"Routes"}),e.jsxs("p",{className:"mt-1 text-sm text-secondary",children:[r.length," endpoint",r.length!==1?"s":""]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(b,{className:"absolute left-3 top-1/2 size-4 -translate-y-1/2 text-secondary"}),e.jsx("input",{type:"text",placeholder:"Search by path, RAI, or method...",value:s,onChange:t=>i(t.target.value),className:"w-full rounded-secondary border border-primary bg-secondary py-2 pl-9 pr-4 text-sm text-primary outline-none focus:border-blue-500"})]}),e.jsx("div",{className:"overflow-auto rounded-primary border border-primary",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-primary bg-primary text-left text-xs text-secondary",children:[e.jsx("th",{className:"px-4 py-3",children:"Method"}),e.jsx("th",{className:"px-4 py-3",children:"Path"}),e.jsx("th",{className:"px-4 py-3",children:"RAI"}),e.jsx("th",{className:"px-4 py-3",children:"Roles"})]})}),e.jsx("tbody",{children:x.map((t,p)=>{var l;return e.jsxs("tr",{className:"border-b border-primary bg-secondary last:border-0",children:[e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("span",{className:`inline-block rounded px-2 py-0.5 text-xs font-semibold ${f[t.method.toUpperCase()]??"bg-gray-100 text-gray-700"}`,children:t.method.toUpperCase()})}),e.jsx("td",{className:"px-4 py-2.5 font-mono text-xs text-primary",children:t.path}),e.jsx("td",{className:"px-4 py-2.5 font-mono text-xs text-secondary",children:t.rai}),e.jsx("td",{className:"px-4 py-2.5",children:e.jsx("div",{className:"flex flex-wrap gap-1",children:(l=t.roles)==null?void 0:l.map(o=>e.jsx("span",{className:"rounded-full bg-primary px-2 py-0.5 text-xs text-secondary",children:o},o))})})]},p)})})]})})]})}export{N as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as i,u as x,j as e,m as r,G as n}from"./index-Cwwdi5uz.js";import{a as d,L as p}from"./api-DHFLRYt1.js";import{C as f}from"./chevron-right-DN23SEYa.js";function j(){const[a,c]=i.useState([]),[l,o]=i.useState(!0),m=x();return i.useEffect(()=>{d.get("/i18n").then(s=>c(s.data)).catch(console.error).finally(()=>o(!1))},[]),l?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(p,{className:"size-8 animate-spin text-primary"})}):a.length===0?e.jsxs(r.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},transition:{duration:.3},className:"flex size-full flex-col items-center justify-center gap-4 p-6",children:[e.jsx(n,{className:"size-12 text-secondary"}),e.jsx("p",{className:"text-secondary",children:"No i18n namespaces found"}),e.jsx("p",{className:"text-xs text-secondary",children:"Enable i18n in your Wecon config to manage translations."})]}):e.jsxs(r.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},transition:{duration:.3},className:"flex size-full flex-col gap-6 overflow-y-auto p-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:"Translations"}),e.jsxs("p",{className:"mt-1 text-sm text-secondary",children:[a.length," namespace",a.length!==1?"s":""]})]}),e.jsx("div",{className:"flex flex-col gap-3",children:a.map(s=>e.jsxs("div",{className:"rounded-primary border border-primary bg-secondary p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-3",children:[e.jsx(n,{className:"size-5 text-secondary"}),e.jsx("span",{className:"font-semibold text-primary",children:s.namespace})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.languages.map(t=>e.jsxs(r.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>m(`/i18n/${s.namespace}/${t}`),className:"flex items-center gap-2 rounded-secondary border border-primary px-3 py-1.5 text-xs transition-colors hover:bg-primary",children:[e.jsx("span",{className:"font-semibold text-primary",children:t.toUpperCase()}),e.jsxs("span",{className:"text-secondary",children:[s.keyCount[t]??0," keys"]}),e.jsx(f,{className:"size-3 text-secondary"})]},t))})]},s.namespace))})]})}export{j as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as t,u as g,j as e,B as y,R as v,S as j,G as N,m as l}from"./index-Cwwdi5uz.js";import{L as b,a as c}from"./api-DHFLRYt1.js";function S(){const[i,d]=t.useState({modules:0,routes:0,config:!1}),[m,u]=t.useState(!0),[o,x]=t.useState(null),p=g();if(t.useEffect(()=>{(async()=>{var r,n;try{const[a,h]=await Promise.all([c.get("/modules"),c.get("/routes")]);d({modules:((r=a.data)==null?void 0:r.length)??0,routes:((n=h.data)==null?void 0:n.length)??0,config:!0})}catch(a){x(a.message||"Failed to connect to DevTools API")}finally{u(!1)}})()},[]),m)return e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(b,{className:"size-8 animate-spin text-primary"})});if(o)return e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"rounded-primary border border-primary bg-secondary p-8 text-center",children:[e.jsx("div",{className:"mb-3 text-lg font-semibold text-primary",children:"Connection Error"}),e.jsx("p",{className:"text-sm text-secondary",children:o}),e.jsx("p",{className:"mt-2 text-xs text-secondary",children:"Make sure your Wecon app is running with devtools enabled."})]})});const f=[{title:"Modules",value:i.modules,icon:y,description:"Registered application modules",path:"/modules"},{title:"Routes",value:i.routes,icon:v,description:"API route endpoints (RAIs)",path:"/routes"},{title:"Config",value:"View",icon:j,description:"Application configuration",path:"/config"},{title:"I18n",value:"Manage",icon:N,description:"Translation namespaces",path:"/i18n"}];return e.jsxs(l.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},transition:{duration:.3},className:"flex size-full flex-col gap-6 overflow-y-auto p-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:"Wecon DevTools"}),e.jsx("p",{className:"mt-1 text-sm text-secondary",children:"Inspect and manage your application modules, routes, config, and translations."})]}),e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",children:f.map(s=>e.jsxs(l.div,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>p(s.path),className:"flex cursor-pointer flex-col gap-3 rounded-primary border border-primary bg-secondary p-5 shadow-small transition-shadow hover:shadow-medium",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.icon,{className:"size-5 text-secondary"}),e.jsx("span",{className:"text-2xl font-bold text-primary",children:s.value})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-primary",children:s.title}),e.jsx("div",{className:"text-xs text-secondary",children:s.description})]})]},s.title))})]})}export{S as default};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{c as o,r as l,j as e,m as x}from"./index-Cwwdi5uz.js";import{a as m,L as f}from"./api-DHFLRYt1.js";import{C as p}from"./chevron-right-DN23SEYa.js";/**
|
|
2
|
+
* @license lucide-react v0.460.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const d=o("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);function u(){const[s,n]=l.useState(null),[r,t]=l.useState(!0);return l.useEffect(()=>{m.get("/config").then(a=>n(a.data)).catch(console.error).finally(()=>t(!1))},[]),r?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(f,{className:"size-8 animate-spin text-primary"})}):e.jsxs(x.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},transition:{duration:.3},className:"flex size-full flex-col gap-6 overflow-y-auto p-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:"Configuration"}),e.jsx("p",{className:"mt-1 text-sm text-secondary",children:"Resolved application configuration"})]}),s&&e.jsx("div",{className:"rounded-primary border border-primary bg-secondary p-4",children:e.jsx(c,{data:s})})]})}function c({data:s,depth:n=0}){if(s==null)return e.jsx("span",{className:"text-gray-400",children:"null"});if(typeof s!="object")return typeof s=="string"?e.jsxs("span",{className:"text-green-600",children:['"',s,'"']}):typeof s=="boolean"?e.jsx("span",{className:"text-blue-600",children:s?"true":"false"}):e.jsx("span",{className:"text-orange-600",children:String(s)});if(Array.isArray(s))return s.length===0?e.jsx("span",{className:"text-gray-400",children:"[]"}):e.jsx("div",{className:"flex flex-col gap-1",style:{marginLeft:n>0?16:0},children:s.map((t,a)=>e.jsxs("div",{className:"flex items-start gap-1",children:[e.jsxs("span",{className:"text-xs text-gray-400",children:["[",a,"]"]}),e.jsx(c,{data:t,depth:n+1})]},a))});const r=Object.entries(s);return r.length===0?e.jsx("span",{className:"text-gray-400",children:"{}"}):e.jsx("div",{className:"flex flex-col gap-1",style:{marginLeft:n>0?16:0},children:r.map(([t,a])=>e.jsx(j,{propKey:t,value:a,depth:n},t))})}function j({propKey:s,value:n,depth:r}){const[t,a]=l.useState(r<2),i=typeof n=="object"&&n!==null;return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:`flex items-center gap-1 font-mono text-xs ${i?"cursor-pointer":""}`,onClick:()=>i&&a(!t),children:[i?t?e.jsx(d,{className:"size-3 text-secondary"}):e.jsx(p,{className:"size-3 text-secondary"}):e.jsx("span",{className:"inline-block w-3"}),e.jsx("span",{className:"font-semibold text-primary",children:s}),e.jsx("span",{className:"text-gray-400",children:":"}),!i&&e.jsx("span",{className:"ml-1",children:e.jsx(c,{data:n,depth:r+1})}),i&&!t&&e.jsx("span",{className:"text-gray-400",children:Array.isArray(n)?`[${n.length}]`:`{${Object.keys(n).length}}`})]}),i&&t&&e.jsx(c,{data:n,depth:r+1})]})}export{u as default};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>Wecon DevTools</title>
|
|
8
|
+
<script type="module" crossorigin src="./assets/index-Cwwdi5uz.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="./assets/index-BFzJyDrn.css">
|
|
10
|
+
</head>
|
|
11
|
+
|
|
12
|
+
<body>
|
|
13
|
+
<div id="root"></div>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools Config Controller
|
|
3
|
+
*
|
|
4
|
+
* Read and update global config and per-module config.
|
|
5
|
+
*/
|
|
6
|
+
import type { Request, Response } from "express";
|
|
7
|
+
import type { DevToolsContext } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* GET /config - Get full resolved config
|
|
10
|
+
*/
|
|
11
|
+
export declare function getConfig(dtCtx: DevToolsContext): (_req: Request, res: Response) => void;
|
|
12
|
+
/**
|
|
13
|
+
* PUT /config - Update global config values (dot-path notation)
|
|
14
|
+
*
|
|
15
|
+
* Body: { "path": "logging.level", "value": "debug" }
|
|
16
|
+
*/
|
|
17
|
+
export declare function updateConfig(dtCtx: DevToolsContext): (req: Request, res: Response) => void;
|
|
18
|
+
/**
|
|
19
|
+
* GET /config/:moduleName - Get module config and schema info
|
|
20
|
+
*/
|
|
21
|
+
export declare function getModuleConfig(dtCtx: DevToolsContext): (req: Request, res: Response) => void;
|
|
22
|
+
/**
|
|
23
|
+
* PUT /config/:moduleName - Update module config (Zod-validated)
|
|
24
|
+
*
|
|
25
|
+
* Body: the full new config object
|
|
26
|
+
*/
|
|
27
|
+
export declare function updateModuleConfig(dtCtx: DevToolsContext): (req: Request, res: Response) => void;
|
|
28
|
+
//# sourceMappingURL=config.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.controller.d.ts","sourceRoot":"","sources":["../../../src/devtools/controllers/config.controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,eAAe,IACtC,MAAM,OAAO,EAAE,KAAK,QAAQ,KAAG,IAAI,CAK5C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,eAAe,IACzC,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAAI,CA4C3C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,eAAe,IAC5C,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAAI,CAa3C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,eAAe,IAC/C,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAAI,CAe3C"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools Config Controller
|
|
3
|
+
*
|
|
4
|
+
* Read and update global config and per-module config.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* GET /config - Get full resolved config
|
|
8
|
+
*/
|
|
9
|
+
export function getConfig(dtCtx) {
|
|
10
|
+
return (_req, res) => {
|
|
11
|
+
// Return a sanitized copy (exclude sensitive fields)
|
|
12
|
+
const config = { ...dtCtx.ctx.config };
|
|
13
|
+
res.json({ success: true, data: config });
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* PUT /config - Update global config values (dot-path notation)
|
|
18
|
+
*
|
|
19
|
+
* Body: { "path": "logging.level", "value": "debug" }
|
|
20
|
+
*/
|
|
21
|
+
export function updateConfig(dtCtx) {
|
|
22
|
+
return (req, res) => {
|
|
23
|
+
const { path, value } = req.body;
|
|
24
|
+
if (!path || typeof path !== "string") {
|
|
25
|
+
res.status(400).json({
|
|
26
|
+
success: false,
|
|
27
|
+
errors: [{ code: "INVALID_INPUT", message: "\"path\" is required (dot notation)" }],
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// Prevent updating immutable fields
|
|
32
|
+
const immutable = ["app.name", "mode"];
|
|
33
|
+
if (immutable.includes(path)) {
|
|
34
|
+
res.status(400).json({
|
|
35
|
+
success: false,
|
|
36
|
+
errors: [{ code: "IMMUTABLE", message: `Cannot update "${path}" at runtime` }],
|
|
37
|
+
});
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Navigate to the target and set value
|
|
41
|
+
const parts = path.split(".");
|
|
42
|
+
let target = dtCtx.ctx.config;
|
|
43
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
44
|
+
const part = parts[i];
|
|
45
|
+
if (target[part] === undefined || typeof target[part] !== "object") {
|
|
46
|
+
res.status(400).json({
|
|
47
|
+
success: false,
|
|
48
|
+
errors: [{ code: "INVALID_PATH", message: `Path "${path}" is invalid at "${part}"` }],
|
|
49
|
+
});
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
target = target[part];
|
|
53
|
+
}
|
|
54
|
+
const lastKey = parts[parts.length - 1];
|
|
55
|
+
target[lastKey] = value;
|
|
56
|
+
dtCtx.ctx.logger.info(`Config updated: ${path}`, { value });
|
|
57
|
+
res.json({ success: true, data: { path, value } });
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* GET /config/:moduleName - Get module config and schema info
|
|
62
|
+
*/
|
|
63
|
+
export function getModuleConfig(dtCtx) {
|
|
64
|
+
return (req, res) => {
|
|
65
|
+
const { moduleName } = req.params;
|
|
66
|
+
try {
|
|
67
|
+
const config = dtCtx.ctx.getModuleConfig(moduleName);
|
|
68
|
+
res.json({ success: true, data: { moduleName, config } });
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
res.status(404).json({
|
|
72
|
+
success: false,
|
|
73
|
+
errors: [{ code: "NOT_FOUND", message: err.message }],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* PUT /config/:moduleName - Update module config (Zod-validated)
|
|
80
|
+
*
|
|
81
|
+
* Body: the full new config object
|
|
82
|
+
*/
|
|
83
|
+
export function updateModuleConfig(dtCtx) {
|
|
84
|
+
return (req, res) => {
|
|
85
|
+
const { moduleName } = req.params;
|
|
86
|
+
try {
|
|
87
|
+
dtCtx.ctx.setModuleConfig(moduleName, req.body);
|
|
88
|
+
const updated = dtCtx.ctx.getModuleConfig(moduleName);
|
|
89
|
+
dtCtx.ctx.logger.info(`Module config updated: ${moduleName}`);
|
|
90
|
+
res.json({ success: true, data: { moduleName, config: updated } });
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
res.status(400).json({
|
|
94
|
+
success: false,
|
|
95
|
+
errors: [{ code: "VALIDATION_ERROR", message: err.message }],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=config.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.controller.js","sourceRoot":"","sources":["../../../src/devtools/controllers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EAAG,GAAa,CAAC,OAAO,EAAE,CAAC;aACxE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools i18n Controller
|
|
3
|
+
*
|
|
4
|
+
* List namespaces, read and update translations.
|
|
5
|
+
*/
|
|
6
|
+
import type { Request, Response } from "express";
|
|
7
|
+
import type { DevToolsContext } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* GET /i18n - List all namespaces with languages and key counts
|
|
10
|
+
*/
|
|
11
|
+
export declare function listNamespaces(dtCtx: DevToolsContext, modulesDir: string): (_req: Request, res: Response) => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* GET /i18n/:namespace/:lang - Get translations for namespace + language
|
|
14
|
+
*/
|
|
15
|
+
export declare function getTranslations(dtCtx: DevToolsContext, modulesDir: string): (req: Request, res: Response) => void;
|
|
16
|
+
/**
|
|
17
|
+
* PUT /i18n/:namespace/:lang - Update translations
|
|
18
|
+
*
|
|
19
|
+
* Body: the full translations object
|
|
20
|
+
*/
|
|
21
|
+
export declare function updateTranslations(dtCtx: DevToolsContext, modulesDir: string): (req: Request, res: Response) => void;
|
|
22
|
+
//# sourceMappingURL=i18n.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.controller.d.ts","sourceRoot":"","sources":["../../../src/devtools/controllers/i18n.controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,IACzD,MAAM,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAAC,CAuB3D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,IAChE,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAAI,CA0B3C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,IACnE,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAAI,CAwB3C"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools i18n Controller
|
|
3
|
+
*
|
|
4
|
+
* List namespaces, read and update translations.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
7
|
+
import { join, dirname } from "path";
|
|
8
|
+
import { loadI18nResources } from "../../i18n/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* GET /i18n - List all namespaces with languages and key counts
|
|
11
|
+
*/
|
|
12
|
+
export function listNamespaces(dtCtx, modulesDir) {
|
|
13
|
+
return async (_req, res) => {
|
|
14
|
+
try {
|
|
15
|
+
const resources = await loadI18nResources(modulesDir);
|
|
16
|
+
const namespaces = Object.entries(resources).map(([namespace, langs]) => ({
|
|
17
|
+
namespace,
|
|
18
|
+
languages: Object.keys(langs),
|
|
19
|
+
keyCounts: Object.fromEntries(Object.entries(langs).map(([lang, translations]) => [
|
|
20
|
+
lang,
|
|
21
|
+
Object.keys(translations).length,
|
|
22
|
+
])),
|
|
23
|
+
}));
|
|
24
|
+
res.json({ success: true, data: namespaces });
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
res.status(500).json({
|
|
28
|
+
success: false,
|
|
29
|
+
errors: [{ code: "I18N_ERROR", message: err.message }],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* GET /i18n/:namespace/:lang - Get translations for namespace + language
|
|
36
|
+
*/
|
|
37
|
+
export function getTranslations(dtCtx, modulesDir) {
|
|
38
|
+
return (req, res) => {
|
|
39
|
+
const { namespace, lang } = req.params;
|
|
40
|
+
const filePath = join(modulesDir, namespace, "i18n", `${lang}.translation.json`);
|
|
41
|
+
if (!existsSync(filePath)) {
|
|
42
|
+
res.status(404).json({
|
|
43
|
+
success: false,
|
|
44
|
+
errors: [{
|
|
45
|
+
code: "NOT_FOUND",
|
|
46
|
+
message: `Translation file not found: ${namespace}/${lang}`,
|
|
47
|
+
}],
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const content = readFileSync(filePath, "utf-8");
|
|
53
|
+
const translations = JSON.parse(content);
|
|
54
|
+
res.json({ success: true, data: { namespace, lang, translations } });
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
res.status(500).json({
|
|
58
|
+
success: false,
|
|
59
|
+
errors: [{ code: "PARSE_ERROR", message: err.message }],
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* PUT /i18n/:namespace/:lang - Update translations
|
|
66
|
+
*
|
|
67
|
+
* Body: the full translations object
|
|
68
|
+
*/
|
|
69
|
+
export function updateTranslations(dtCtx, modulesDir) {
|
|
70
|
+
return (req, res) => {
|
|
71
|
+
const { namespace, lang } = req.params;
|
|
72
|
+
const filePath = join(modulesDir, namespace, "i18n", `${lang}.translation.json`);
|
|
73
|
+
try {
|
|
74
|
+
// Ensure directory exists
|
|
75
|
+
const dir = dirname(filePath);
|
|
76
|
+
if (!existsSync(dir)) {
|
|
77
|
+
mkdirSync(dir, { recursive: true });
|
|
78
|
+
}
|
|
79
|
+
// Write formatted JSON
|
|
80
|
+
const content = JSON.stringify(req.body, null, 2);
|
|
81
|
+
writeFileSync(filePath, content + "\n", "utf-8");
|
|
82
|
+
dtCtx.ctx.logger.info(`Translations updated: ${namespace}/${lang}`);
|
|
83
|
+
res.json({ success: true, data: { namespace, lang, translations: req.body } });
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
res.status(500).json({
|
|
87
|
+
success: false,
|
|
88
|
+
errors: [{ code: "WRITE_ERROR", message: err.message }],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=i18n.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.controller.js","sourceRoot":"","sources":["../../../src/devtools/controllers/i18n.controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAGrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAsB,EAAE,UAAkB;IACvE,OAAO,KAAK,EAAE,IAAa,EAAE,GAAa,EAAiB,EAAE;QAC3D,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,UAAU,CAAC,CAAC;YAEtD,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;gBACxE,SAAS;gBACT,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC7B,SAAS,EAAE,MAAM,CAAC,WAAW,CAC3B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,EAAE,CAAC;oBAClD,IAAI;oBACJ,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM;iBACjC,CAAC,CACH;aACF,CA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EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACjF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBACnB,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAG,GAAa,CAAC,OAAO,EAAE,CAAC;aACnE,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools Modules Controller
|
|
3
|
+
*
|
|
4
|
+
* List and inspect registered modules.
|
|
5
|
+
*/
|
|
6
|
+
import type { Request, Response } from "express";
|
|
7
|
+
import type { DevToolsContext } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* GET /modules - List all modules
|
|
10
|
+
*/
|
|
11
|
+
export declare function listModules(dtCtx: DevToolsContext): (_req: Request, res: Response) => void;
|
|
12
|
+
/**
|
|
13
|
+
* GET /modules/:name - Get module detail
|
|
14
|
+
*/
|
|
15
|
+
export declare function getModule(dtCtx: DevToolsContext): (req: Request, res: Response) => void;
|
|
16
|
+
//# sourceMappingURL=modules.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modules.controller.d.ts","sourceRoot":"","sources":["../../../src/devtools/controllers/modules.controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAA+B,MAAM,aAAa,CAAC;AAEhF;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,eAAe,IACxC,MAAM,OAAO,EAAE,KAAK,QAAQ,KAAG,IAAI,CAa5C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,eAAe,IACtC,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAAI,CAgD3C"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools Modules Controller
|
|
3
|
+
*
|
|
4
|
+
* List and inspect registered modules.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* GET /modules - List all modules
|
|
8
|
+
*/
|
|
9
|
+
export function listModules(dtCtx) {
|
|
10
|
+
return (_req, res) => {
|
|
11
|
+
const summaries = dtCtx.modules.map((mod) => ({
|
|
12
|
+
name: mod.name,
|
|
13
|
+
namespace: mod.namespace,
|
|
14
|
+
description: mod.description,
|
|
15
|
+
hasConfig: !!mod.config?.schema,
|
|
16
|
+
hasRoutes: !!mod.routes,
|
|
17
|
+
imports: mod.imports ?? [],
|
|
18
|
+
exports: mod.exports ?? [],
|
|
19
|
+
}));
|
|
20
|
+
res.json({ success: true, data: summaries });
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* GET /modules/:name - Get module detail
|
|
25
|
+
*/
|
|
26
|
+
export function getModule(dtCtx) {
|
|
27
|
+
return (req, res) => {
|
|
28
|
+
const { name } = req.params;
|
|
29
|
+
const mod = dtCtx.modules.find((m) => m.name === name);
|
|
30
|
+
if (!mod) {
|
|
31
|
+
res.status(404).json({
|
|
32
|
+
success: false,
|
|
33
|
+
errors: [{ code: "NOT_FOUND", message: `Module "${name}" not found` }],
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// Get current config if available
|
|
38
|
+
let currentConfig = null;
|
|
39
|
+
try {
|
|
40
|
+
currentConfig = dtCtx.ctx.getModuleConfig(name);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Module has no config
|
|
44
|
+
}
|
|
45
|
+
// Describe schema if available
|
|
46
|
+
let schemaDescription = null;
|
|
47
|
+
if (mod.config?.schema) {
|
|
48
|
+
try {
|
|
49
|
+
// Zod schemas have a .describe() or ._def we can inspect
|
|
50
|
+
const def = mod.config.schema._def;
|
|
51
|
+
schemaDescription = def ? JSON.stringify(def, null, 2) : null;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
schemaDescription = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const detail = {
|
|
58
|
+
name: mod.name,
|
|
59
|
+
namespace: mod.namespace,
|
|
60
|
+
description: mod.description,
|
|
61
|
+
hasConfig: !!mod.config?.schema,
|
|
62
|
+
hasRoutes: !!mod.routes,
|
|
63
|
+
imports: mod.imports ?? [],
|
|
64
|
+
exports: mod.exports ?? [],
|
|
65
|
+
config: {
|
|
66
|
+
schema: schemaDescription,
|
|
67
|
+
current: currentConfig,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
res.json({ success: true, data: detail });
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=modules.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modules.controller.js","sourceRoot":"","sources":["../../../src/devtools/controllers/modules.controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAsB;IAChD,OAAO,CAAC,IAAa,EAAE,GAAa,EAAQ,EAAE;QAC5C,MAAM,SAAS,GAAoB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC7D,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM;YAC/B,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM;YACvB,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE;YAC1B,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE;SAC3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AC,IAAI,CAAC;YAChE,CAAC;YAAC,MAAM,CAAC;gBACP,iBAAiB,GAAG,IAAI,CAAC;YAC3B,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAiB;YAC3B,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM;YAC/B,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM;YACvB,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE;YAC1B,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE;YAC1B,MAAM,EAAE;gBACN,MAAM,EAAE,iBAAiB;gBACzB,OAAO,EAAE,aAAa;aACvB;SACF,CAAC;QAEF,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5C,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools Routes Controller
|
|
3
|
+
*
|
|
4
|
+
* List all registered RAIs with their methods, paths, and roles.
|
|
5
|
+
*/
|
|
6
|
+
import type { Request, Response } from "express";
|
|
7
|
+
import type { DevToolsContext } from "../types.js";
|
|
8
|
+
import type Wecon from "../../routing/Wecon.js";
|
|
9
|
+
/**
|
|
10
|
+
* GET /routes - List all registered routes
|
|
11
|
+
*/
|
|
12
|
+
export declare function listRoutes(dtCtx: DevToolsContext, wecon?: Wecon): (_req: Request, res: Response) => void;
|
|
13
|
+
//# sourceMappingURL=routes.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.controller.d.ts","sourceRoot":"","sources":["../../../src/devtools/controllers/routes.controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAgB,MAAM,aAAa,CAAC;AACjE,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAEhD;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,EAAE,KAAK,IACtD,MAAM,OAAO,EAAE,KAAK,QAAQ,KAAG,IAAI,CAyB5C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools Routes Controller
|
|
3
|
+
*
|
|
4
|
+
* List all registered RAIs with their methods, paths, and roles.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* GET /routes - List all registered routes
|
|
8
|
+
*/
|
|
9
|
+
export function listRoutes(dtCtx, wecon) {
|
|
10
|
+
return (_req, res) => {
|
|
11
|
+
if (!wecon) {
|
|
12
|
+
res.json({ success: true, data: [] });
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const routes = wecon.getRoutes();
|
|
16
|
+
const summaries = [];
|
|
17
|
+
for (const route of routes) {
|
|
18
|
+
summaries.push({
|
|
19
|
+
rai: route.rai,
|
|
20
|
+
method: route.method,
|
|
21
|
+
path: route.path,
|
|
22
|
+
roles: route.roles,
|
|
23
|
+
module: route.meta?.module,
|
|
24
|
+
name: route.name,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// Sort by path for readability
|
|
28
|
+
summaries.sort((a, b) => a.path.localeCompare(b.path));
|
|
29
|
+
res.json({ success: true, data: summaries });
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=routes.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.controller.js","sourceRoot":"","sources":["../../../src/devtools/controllers/routes.controller.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAsB,EAAE,KAAa;IAC9D,OAAO,CAAC,IAAa,EAAE,GAAa,EAAQ,EAAE;QAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YACtC,OAAO;QACT,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QACjC,MAAM,SAAS,GAAmB,EAAE,CAAC;QAErC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,SAAS,CAAC,IAAI,CAAC;gBACb,GAAG,EAAE,KAAK,CAAC,GAAG;gBACd,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,MAA4B;gBAChD,IAAI,EAAE,KAAK,CAAC,IAAI;aACjB,CAAC,CAAC;QACL,CAAC;QAED,+BAA+B;QAC/B,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QAEvD,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools Module
|
|
3
|
+
*
|
|
4
|
+
* REST API for inspecting and managing modules, config, i18n, and routes.
|
|
5
|
+
* Includes a built-in web UI served at /ui.
|
|
6
|
+
* Disabled in production by default.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const app = await createWecon({
|
|
11
|
+
* config,
|
|
12
|
+
* modules: [authModule],
|
|
13
|
+
* devtools: {
|
|
14
|
+
* enabled: true,
|
|
15
|
+
* auth: { token: process.env.DEVTOOLS_TOKEN },
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { Router } from "express";
|
|
21
|
+
import type { WeconContext, WeconModule } from "../types.js";
|
|
22
|
+
import type Wecon from "../routing/Wecon.js";
|
|
23
|
+
import type { DevToolsOptions } from "./types.js";
|
|
24
|
+
export type { DevToolsOptions } from "./types.js";
|
|
25
|
+
/**
|
|
26
|
+
* Create the devtools Express Router
|
|
27
|
+
*/
|
|
28
|
+
export declare function createDevToolsRouter(ctx: WeconContext, modules: WeconModule[], options?: DevToolsOptions, wecon?: Wecon): Router | null;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAqB,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,KAAK,MAAM,qBAAqB,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,YAAY,CAAC;AAOnE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAoBlD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,YAAY,EACjB,OAAO,EAAE,WAAW,EAAE,EACtB,OAAO,GAAE,eAAoB,EAC7B,KAAK,CAAC,EAAE,KAAK,GACZ,MAAM,GAAG,IAAI,CAoDf"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools Module
|
|
3
|
+
*
|
|
4
|
+
* REST API for inspecting and managing modules, config, i18n, and routes.
|
|
5
|
+
* Includes a built-in web UI served at /ui.
|
|
6
|
+
* Disabled in production by default.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const app = await createWecon({
|
|
11
|
+
* config,
|
|
12
|
+
* modules: [authModule],
|
|
13
|
+
* devtools: {
|
|
14
|
+
* enabled: true,
|
|
15
|
+
* auth: { token: process.env.DEVTOOLS_TOKEN },
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import path from "path";
|
|
21
|
+
import { fileURLToPath } from "url";
|
|
22
|
+
import fs from "fs";
|
|
23
|
+
import { createDevToolsAuth } from "./middleware.js";
|
|
24
|
+
import { listModules, getModule } from "./controllers/modules.controller.js";
|
|
25
|
+
import { getConfig, updateConfig, getModuleConfig, updateModuleConfig } from "./controllers/config.controller.js";
|
|
26
|
+
import { listNamespaces, getTranslations, updateTranslations } from "./controllers/i18n.controller.js";
|
|
27
|
+
import { listRoutes } from "./controllers/routes.controller.js";
|
|
28
|
+
/**
|
|
29
|
+
* Resolve the path to the built-in client UI directory.
|
|
30
|
+
* Falls back gracefully if the client build is not present.
|
|
31
|
+
*/
|
|
32
|
+
function resolveClientDir() {
|
|
33
|
+
try {
|
|
34
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
35
|
+
const __dirname = path.dirname(__filename);
|
|
36
|
+
const clientDir = path.resolve(__dirname, "client");
|
|
37
|
+
if (fs.existsSync(clientDir) && fs.existsSync(path.join(clientDir, "index.html"))) {
|
|
38
|
+
return clientDir;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// fallback for CJS environments
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create the devtools Express Router
|
|
48
|
+
*/
|
|
49
|
+
export function createDevToolsRouter(ctx, modules, options = {}, wecon) {
|
|
50
|
+
// Check if devtools should be enabled
|
|
51
|
+
const isProduction = ctx.config.mode === "production";
|
|
52
|
+
const enabled = options.enabled ?? !isProduction;
|
|
53
|
+
if (!enabled) {
|
|
54
|
+
ctx.logger.debug("DevTools disabled");
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
// Dynamic import express to get Router
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
59
|
+
const express = require("express");
|
|
60
|
+
const router = express.Router();
|
|
61
|
+
const dtCtx = { ctx, modules };
|
|
62
|
+
const modulesDir = options.modulesDir ?? "./src/modules";
|
|
63
|
+
// Optional bearer token auth
|
|
64
|
+
if (options.auth?.token) {
|
|
65
|
+
router.use(createDevToolsAuth(options.auth.token));
|
|
66
|
+
}
|
|
67
|
+
// -- API endpoints --
|
|
68
|
+
router.get("/modules", listModules(dtCtx));
|
|
69
|
+
router.get("/modules/:name", getModule(dtCtx));
|
|
70
|
+
router.get("/config", getConfig(dtCtx));
|
|
71
|
+
router.put("/config", updateConfig(dtCtx));
|
|
72
|
+
router.get("/config/:moduleName", getModuleConfig(dtCtx));
|
|
73
|
+
router.put("/config/:moduleName", updateModuleConfig(dtCtx));
|
|
74
|
+
router.get("/i18n", listNamespaces(dtCtx, modulesDir));
|
|
75
|
+
router.get("/i18n/:namespace/:lang", getTranslations(dtCtx, modulesDir));
|
|
76
|
+
router.put("/i18n/:namespace/:lang", updateTranslations(dtCtx, modulesDir));
|
|
77
|
+
router.get("/routes", listRoutes(dtCtx, wecon));
|
|
78
|
+
// -- Built-in Web UI --
|
|
79
|
+
const clientDir = resolveClientDir();
|
|
80
|
+
if (clientDir) {
|
|
81
|
+
// Serve static assets
|
|
82
|
+
router.use("/ui", express.static(clientDir));
|
|
83
|
+
// SPA fallback: serve index.html for any /ui sub-routes that aren't static files
|
|
84
|
+
router.use("/ui", (_req, res) => {
|
|
85
|
+
res.sendFile(path.join(clientDir, "index.html"));
|
|
86
|
+
});
|
|
87
|
+
// DevTools with UI - shown in startup banner
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// DevTools API only - shown in startup banner
|
|
91
|
+
}
|
|
92
|
+
return router;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,MAAM,IAAI,CAAC;AAKpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAClH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACvG,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAIhE;;;GAGG;AACH,SAAS,gBAAgB;IACvB,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACpD,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,EAAE,CAAC;YAClF,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,g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BAAqB,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1D,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7D,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;IACvD,MAAM,CAAC,GAAG,CAAC,wBAAwB,EAAE,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;IACzE,MAAM,CAAC,GAAG,CAAC,wBAAwB,EAAE,kBAAkB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;IAC5E,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEhD,wBAAwB;IACxB,MAAM,SAAS,GAAG,gBAAgB,EAAE,CAAC;IACrC,IAAI,SAAS,EAAE,CAAC;QACd,sBAAsB;QACtB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAE7C,iFAAiF;QACjF,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,IAAa,EAAE,GAAa,EAAE,EAAE;YACjD,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QAEH,6CAA6C;IAC/C,CAAC;SAAM,CAAC;QACN,8CAA8C;IAChD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wecon/core - DevTools Auth Middleware
|
|
3
|
+
*
|
|
4
|
+
* Optional bearer token authentication for devtools endpoints.
|
|
5
|
+
*/
|
|
6
|
+
import type { Request, Response, NextFunction } from "express";
|
|
7
|
+
/**
|
|
8
|
+
* Create bearer token auth middleware for devtools
|
|
9
|
+
*/
|
|
10
|
+
export declare function createDevToolsAuth(token: string): (req: Request, res: Response, next: NextFunction) => void;
|
|
11
|
+
//# sourceMappingURL=middleware.d.ts.map
|