@alepha/devtools 0.16.1 → 0.19.2

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 (238) hide show
  1. package/README.md +1 -5
  2. package/dist/index.browser.js +224 -0
  3. package/dist/index.browser.js.map +1 -0
  4. package/dist/index.d.ts +351 -323
  5. package/dist/index.js +350 -186
  6. package/dist/index.js.map +1 -1
  7. package/package.json +33 -25
  8. package/src/assets.ts +6 -0
  9. package/src/{api/entities → entities}/logs.ts +2 -2
  10. package/src/index.browser.ts +11 -0
  11. package/src/index.shared.ts +15 -0
  12. package/src/index.ts +11 -37
  13. package/src/{api/providers → providers}/DevToolsMetadataProvider.ts +84 -47
  14. package/src/providers/DevToolsProvider.ts +394 -0
  15. package/src/{api/schemas → schemas}/DevActionMetadata.ts +8 -0
  16. package/src/{api/schemas → schemas}/DevEntityMetadata.ts +3 -0
  17. package/src/{api/schemas → schemas}/DevMetadata.ts +13 -2
  18. package/src/{api/schemas → schemas}/DevPageMetadata.ts +3 -0
  19. package/src/{api/schemas → schemas}/DevTopicMetadata.ts +1 -0
  20. package/src/ui/AppRouter.tsx +73 -59
  21. package/src/ui/components/DevLayout.tsx +103 -84
  22. package/src/ui/components/configuration/ConfigAtoms.page.tsx +5 -0
  23. package/src/ui/components/configuration/ConfigAtoms.tsx +511 -0
  24. package/src/ui/components/configuration/ConfigEnv.page.tsx +5 -0
  25. package/src/ui/components/configuration/ConfigEnv.tsx +230 -0
  26. package/src/ui/components/configuration/DevConfiguration.tsx +36 -0
  27. package/src/ui/components/configuration/index.ts +3 -0
  28. package/src/ui/components/dashboard/DevDashboard.tsx +501 -0
  29. package/src/ui/components/database/DatabaseEditor.page.tsx +23 -0
  30. package/src/ui/components/database/DatabaseEditor.tsx +402 -0
  31. package/src/ui/components/database/DatabaseErd.page.tsx +28 -0
  32. package/src/ui/components/database/DatabaseErd.tsx +107 -0
  33. package/src/ui/components/database/DevDatabase.tsx +36 -0
  34. package/src/ui/components/database/EntityNode.tsx +83 -0
  35. package/src/ui/components/emails/DevEmails.tsx +250 -0
  36. package/src/ui/components/explorer/DevExplorer.tsx +351 -0
  37. package/src/ui/components/explorer/ExplorerTree.tsx +178 -0
  38. package/src/ui/components/explorer/panels/DevPanelAction.tsx +499 -0
  39. package/src/ui/components/explorer/panels/DevPanelCache.tsx +73 -0
  40. package/src/ui/components/explorer/panels/DevPanelPage.tsx +96 -0
  41. package/src/ui/components/explorer/panels/DevPanelQueue.tsx +51 -0
  42. package/src/ui/components/explorer/panels/DevPanelTopic.tsx +56 -0
  43. package/src/ui/components/explorer/panels/index.ts +5 -0
  44. package/src/ui/components/graph/DevDependencyGraph.tsx +35 -60
  45. package/src/ui/components/graph/GraphControls.tsx +10 -11
  46. package/src/ui/components/graph/NodeDetails.tsx +22 -29
  47. package/src/ui/components/graph/ProviderNode.tsx +4 -4
  48. package/src/ui/components/graph/helpers.ts +1 -1
  49. package/src/ui/components/logs/DevLogs.tsx +661 -0
  50. package/src/ui/components/logs/index.ts +1 -0
  51. package/src/ui/components/shared/TreeView.tsx +189 -0
  52. package/src/ui/components/sms/DevSms.tsx +225 -0
  53. package/src/ui/main.css +17 -0
  54. package/src/ui/main.ts +2 -6
  55. package/LICENSE +0 -21
  56. package/assets/devtools/actions.html +0 -21
  57. package/assets/devtools/actions.html.br +0 -0
  58. package/assets/devtools/actions.html.gz +0 -0
  59. package/assets/devtools/asset.BZV40eAE.css +0 -1
  60. package/assets/devtools/asset.BZV40eAE.css.br +0 -0
  61. package/assets/devtools/asset.BZV40eAE.css.gz +0 -0
  62. package/assets/devtools/asset.CBnMq2vO.css +0 -1
  63. package/assets/devtools/asset.CBnMq2vO.css.br +0 -0
  64. package/assets/devtools/asset.CBnMq2vO.css.gz +0 -0
  65. package/assets/devtools/atoms.html +0 -21
  66. package/assets/devtools/atoms.html.br +0 -0
  67. package/assets/devtools/atoms.html.gz +0 -0
  68. package/assets/devtools/caches.html +0 -21
  69. package/assets/devtools/caches.html.br +0 -0
  70. package/assets/devtools/caches.html.gz +0 -0
  71. package/assets/devtools/chunk.6INqNjF0.js +0 -1
  72. package/assets/devtools/chunk.6INqNjF0.js.br +0 -0
  73. package/assets/devtools/chunk.6INqNjF0.js.gz +0 -0
  74. package/assets/devtools/chunk.9vpWpXSF.js +0 -1
  75. package/assets/devtools/chunk.9vpWpXSF.js.br +0 -0
  76. package/assets/devtools/chunk.9vpWpXSF.js.gz +0 -0
  77. package/assets/devtools/chunk.B4peH6PS.js +0 -1
  78. package/assets/devtools/chunk.B4peH6PS.js.br +0 -0
  79. package/assets/devtools/chunk.B4peH6PS.js.gz +0 -0
  80. package/assets/devtools/chunk.B8CNjZzU.js +0 -1
  81. package/assets/devtools/chunk.B8CNjZzU.js.br +0 -0
  82. package/assets/devtools/chunk.B8CNjZzU.js.gz +0 -0
  83. package/assets/devtools/chunk.Bgd10SVI.js +0 -1
  84. package/assets/devtools/chunk.Bgd10SVI.js.br +0 -0
  85. package/assets/devtools/chunk.Bgd10SVI.js.gz +0 -0
  86. package/assets/devtools/chunk.BjFrJKj1.js +0 -1
  87. package/assets/devtools/chunk.BjFrJKj1.js.br +0 -2
  88. package/assets/devtools/chunk.BjFrJKj1.js.gz +0 -0
  89. package/assets/devtools/chunk.BlqFPyLh.js +0 -1
  90. package/assets/devtools/chunk.BlqFPyLh.js.br +0 -0
  91. package/assets/devtools/chunk.BlqFPyLh.js.gz +0 -0
  92. package/assets/devtools/chunk.BqBNmfN9.js +0 -1
  93. package/assets/devtools/chunk.BqBNmfN9.js.br +0 -0
  94. package/assets/devtools/chunk.BqBNmfN9.js.gz +0 -0
  95. package/assets/devtools/chunk.Bt0_vkJm.js +0 -2
  96. package/assets/devtools/chunk.Bt0_vkJm.js.br +0 -0
  97. package/assets/devtools/chunk.Bt0_vkJm.js.gz +0 -0
  98. package/assets/devtools/chunk.C3GuU4pz.js +0 -2
  99. package/assets/devtools/chunk.C3GuU4pz.js.br +0 -0
  100. package/assets/devtools/chunk.C3GuU4pz.js.gz +0 -0
  101. package/assets/devtools/chunk.CGwoN_Mo.js +0 -1
  102. package/assets/devtools/chunk.CGwoN_Mo.js.br +0 -0
  103. package/assets/devtools/chunk.CGwoN_Mo.js.gz +0 -0
  104. package/assets/devtools/chunk.CJCvhHA7.js +0 -1
  105. package/assets/devtools/chunk.CJCvhHA7.js.br +0 -2
  106. package/assets/devtools/chunk.CJCvhHA7.js.gz +0 -0
  107. package/assets/devtools/chunk.CKr2VE6v.js +0 -1
  108. package/assets/devtools/chunk.CKr2VE6v.js.br +0 -0
  109. package/assets/devtools/chunk.CKr2VE6v.js.gz +0 -0
  110. package/assets/devtools/chunk.CLvTwbkw.js +0 -1
  111. package/assets/devtools/chunk.CLvTwbkw.js.br +0 -0
  112. package/assets/devtools/chunk.CLvTwbkw.js.gz +0 -0
  113. package/assets/devtools/chunk.CR13dZhE.js +0 -7
  114. package/assets/devtools/chunk.CR13dZhE.js.br +0 -0
  115. package/assets/devtools/chunk.CR13dZhE.js.gz +0 -0
  116. package/assets/devtools/chunk.C_C-cVqs.js +0 -1
  117. package/assets/devtools/chunk.C_C-cVqs.js.br +0 -1
  118. package/assets/devtools/chunk.C_C-cVqs.js.gz +0 -0
  119. package/assets/devtools/chunk.CjevPbPy.js +0 -1
  120. package/assets/devtools/chunk.CjevPbPy.js.br +0 -0
  121. package/assets/devtools/chunk.CjevPbPy.js.gz +0 -0
  122. package/assets/devtools/chunk.CkNMZqAe.js +0 -1
  123. package/assets/devtools/chunk.CkNMZqAe.js.br +0 -0
  124. package/assets/devtools/chunk.CkNMZqAe.js.gz +0 -0
  125. package/assets/devtools/chunk.Cl1Mlnqx.js +0 -1
  126. package/assets/devtools/chunk.Cl1Mlnqx.js.br +0 -0
  127. package/assets/devtools/chunk.Cl1Mlnqx.js.gz +0 -0
  128. package/assets/devtools/chunk.CyY8OGdZ.js +0 -1
  129. package/assets/devtools/chunk.CyY8OGdZ.js.br +0 -0
  130. package/assets/devtools/chunk.CyY8OGdZ.js.gz +0 -0
  131. package/assets/devtools/chunk.Cyx9kLqD.js +0 -1
  132. package/assets/devtools/chunk.Cyx9kLqD.js.br +0 -0
  133. package/assets/devtools/chunk.Cyx9kLqD.js.gz +0 -0
  134. package/assets/devtools/chunk.D1MGgxUI.js +0 -1
  135. package/assets/devtools/chunk.D1MGgxUI.js.br +0 -0
  136. package/assets/devtools/chunk.D1MGgxUI.js.gz +0 -0
  137. package/assets/devtools/chunk.D5Ci-dwk.js +0 -1
  138. package/assets/devtools/chunk.D5Ci-dwk.js.br +0 -0
  139. package/assets/devtools/chunk.D5Ci-dwk.js.gz +0 -0
  140. package/assets/devtools/chunk.DFrWQW5x.js +0 -9
  141. package/assets/devtools/chunk.DFrWQW5x.js.br +0 -0
  142. package/assets/devtools/chunk.DFrWQW5x.js.gz +0 -0
  143. package/assets/devtools/chunk.DaVlli3f.js +0 -1
  144. package/assets/devtools/chunk.DaVlli3f.js.br +0 -0
  145. package/assets/devtools/chunk.DaVlli3f.js.gz +0 -0
  146. package/assets/devtools/chunk.DdyBCs50.js +0 -1
  147. package/assets/devtools/chunk.DdyBCs50.js.br +0 -0
  148. package/assets/devtools/chunk.DdyBCs50.js.gz +0 -0
  149. package/assets/devtools/chunk.Dl0THvrP.js +0 -1
  150. package/assets/devtools/chunk.Dl0THvrP.js.br +0 -0
  151. package/assets/devtools/chunk.Dl0THvrP.js.gz +0 -0
  152. package/assets/devtools/chunk.DwUNDm68.js +0 -1
  153. package/assets/devtools/chunk.DwUNDm68.js.br +0 -0
  154. package/assets/devtools/chunk.DwUNDm68.js.gz +0 -0
  155. package/assets/devtools/chunk.DzDkh4C6.js +0 -1
  156. package/assets/devtools/chunk.DzDkh4C6.js.br +0 -0
  157. package/assets/devtools/chunk.DzDkh4C6.js.gz +0 -0
  158. package/assets/devtools/chunk.QTExp4CY.js +0 -1
  159. package/assets/devtools/chunk.QTExp4CY.js.br +0 -0
  160. package/assets/devtools/chunk.QTExp4CY.js.gz +0 -0
  161. package/assets/devtools/chunk.ReCPcJln.js +0 -1
  162. package/assets/devtools/chunk.ReCPcJln.js.br +0 -0
  163. package/assets/devtools/chunk.ReCPcJln.js.gz +0 -0
  164. package/assets/devtools/chunk.UEhIKOMY.js +0 -1
  165. package/assets/devtools/chunk.UEhIKOMY.js.br +0 -0
  166. package/assets/devtools/chunk.UEhIKOMY.js.gz +0 -0
  167. package/assets/devtools/chunk.mWQqK3dU.js +0 -1
  168. package/assets/devtools/chunk.mWQqK3dU.js.br +0 -0
  169. package/assets/devtools/chunk.mWQqK3dU.js.gz +0 -0
  170. package/assets/devtools/chunk.uyVen0u2.js +0 -1
  171. package/assets/devtools/chunk.uyVen0u2.js.br +0 -0
  172. package/assets/devtools/chunk.uyVen0u2.js.gz +0 -0
  173. package/assets/devtools/chunk.yLRX_cUF.js +0 -1
  174. package/assets/devtools/chunk.yLRX_cUF.js.br +0 -0
  175. package/assets/devtools/chunk.yLRX_cUF.js.gz +0 -0
  176. package/assets/devtools/chunk.zuZxBYZg.js +0 -1
  177. package/assets/devtools/chunk.zuZxBYZg.js.br +0 -0
  178. package/assets/devtools/chunk.zuZxBYZg.js.gz +0 -0
  179. package/assets/devtools/db.html +0 -21
  180. package/assets/devtools/db.html.br +0 -0
  181. package/assets/devtools/db.html.gz +0 -0
  182. package/assets/devtools/entry.Cry3rxEI.js +0 -79
  183. package/assets/devtools/entry.Cry3rxEI.js.br +0 -0
  184. package/assets/devtools/entry.Cry3rxEI.js.gz +0 -0
  185. package/assets/devtools/env.html +0 -21
  186. package/assets/devtools/env.html.br +0 -0
  187. package/assets/devtools/env.html.gz +0 -0
  188. package/assets/devtools/graph.html +0 -22
  189. package/assets/devtools/graph.html.br +0 -0
  190. package/assets/devtools/graph.html.gz +0 -0
  191. package/assets/devtools/index.html +0 -21
  192. package/assets/devtools/index.html.br +0 -0
  193. package/assets/devtools/index.html.gz +0 -0
  194. package/assets/devtools/logs.html +0 -21
  195. package/assets/devtools/logs.html.br +0 -0
  196. package/assets/devtools/logs.html.gz +0 -0
  197. package/assets/devtools/queues.html +0 -21
  198. package/assets/devtools/queues.html.br +0 -0
  199. package/assets/devtools/queues.html.gz +0 -0
  200. package/assets/devtools/topics.html +0 -21
  201. package/assets/devtools/topics.html.br +0 -0
  202. package/assets/devtools/topics.html.gz +0 -0
  203. package/src/api/DevToolsProvider.ts +0 -157
  204. package/src/api/providers/DevToolsDatabaseProvider.ts +0 -27
  205. package/src/api/repositories/LogRepository.ts +0 -8
  206. package/src/api/schemas/DevCommandMetadata.ts +0 -9
  207. package/src/ui/components/DevAtomsViewer.tsx +0 -637
  208. package/src/ui/components/DevCacheInspector.tsx +0 -423
  209. package/src/ui/components/DevDashboard.tsx +0 -38
  210. package/src/ui/components/DevEnvExplorer.tsx +0 -462
  211. package/src/ui/components/DevLogViewer.tsx +0 -252
  212. package/src/ui/components/DevQueueMonitor.tsx +0 -51
  213. package/src/ui/components/DevTopicsViewer.tsx +0 -686
  214. package/src/ui/components/actions/ActionGroup.tsx +0 -37
  215. package/src/ui/components/actions/ActionItem.tsx +0 -138
  216. package/src/ui/components/actions/DevActionsExplorer.tsx +0 -132
  217. package/src/ui/components/actions/MethodBadge.tsx +0 -18
  218. package/src/ui/components/actions/SchemaViewer.tsx +0 -21
  219. package/src/ui/components/actions/TryItPanel.tsx +0 -140
  220. package/src/ui/components/actions/constants.ts +0 -7
  221. package/src/ui/components/actions/helpers.ts +0 -18
  222. package/src/ui/components/actions/index.ts +0 -8
  223. package/src/ui/components/db/ColumnBadge.tsx +0 -55
  224. package/src/ui/components/db/DevDbStudio.tsx +0 -485
  225. package/src/ui/components/db/constants.ts +0 -11
  226. package/src/ui/components/db/index.ts +0 -4
  227. package/src/ui/components/db/types.ts +0 -7
  228. package/src/ui/styles.css +0 -1
  229. /package/src/{api/schemas → schemas}/DevAtomMetadata.ts +0 -0
  230. /package/src/{api/schemas → schemas}/DevBucketMetadata.ts +0 -0
  231. /package/src/{api/schemas → schemas}/DevCacheMetadata.ts +0 -0
  232. /package/src/{api/schemas → schemas}/DevEnvMetadata.ts +0 -0
  233. /package/src/{api/schemas → schemas}/DevModuleMetadata.ts +0 -0
  234. /package/src/{api/schemas → schemas}/DevProviderMetadata.ts +0 -0
  235. /package/src/{api/schemas → schemas}/DevQueueMetadata.ts +0 -0
  236. /package/src/{api/schemas → schemas}/DevRealmMetadata.ts +0 -0
  237. /package/src/{api/schemas → schemas}/DevRouteMetadata.ts +0 -0
  238. /package/src/{api/schemas → schemas}/DevSchedulerMetadata.ts +0 -0
@@ -0,0 +1,178 @@
1
+ import { Text } from "@mantine/core";
2
+ import {
3
+ IconApi,
4
+ IconBroadcast,
5
+ IconDatabase,
6
+ IconFileText,
7
+ IconFolder,
8
+ IconFolderOpen,
9
+ IconRoute,
10
+ IconStack2,
11
+ } from "@tabler/icons-react";
12
+ import { useMemo } from "react";
13
+ import { TreeView, type TreeViewNode } from "../shared/TreeView.tsx";
14
+
15
+ export interface TreeNode {
16
+ id: string;
17
+ label: string;
18
+ type: "folder" | "action" | "page" | "queue" | "topic" | "cache";
19
+ children?: TreeNode[];
20
+ data?: any;
21
+ }
22
+
23
+ // Method badge: use Mantine's light variant colors (scheme-aware)
24
+ const METHOD_COLORS: Record<string, { color: string; bg: string }> = {
25
+ GET: {
26
+ color: "var(--mantine-color-green-text)",
27
+ bg: "var(--mantine-color-green-light)",
28
+ },
29
+ POST: {
30
+ color: "var(--mantine-color-blue-text)",
31
+ bg: "var(--mantine-color-blue-light)",
32
+ },
33
+ PUT: {
34
+ color: "var(--mantine-color-orange-text)",
35
+ bg: "var(--mantine-color-orange-light)",
36
+ },
37
+ PATCH: {
38
+ color: "var(--mantine-color-yellow-text)",
39
+ bg: "var(--mantine-color-yellow-light)",
40
+ },
41
+ DELETE: {
42
+ color: "var(--mantine-color-red-text)",
43
+ bg: "var(--mantine-color-red-light)",
44
+ },
45
+ };
46
+
47
+ const nodeIcons: Record<string, any> = {
48
+ page: IconFileText,
49
+ queue: IconStack2,
50
+ topic: IconBroadcast,
51
+ cache: IconDatabase,
52
+ };
53
+
54
+ // Use Mantine text colors: these adapt to light/dark scheme
55
+ const nodeColors: Record<string, string> = {
56
+ page: "var(--mantine-color-blue-text)",
57
+ queue: "var(--mantine-color-orange-text)",
58
+ topic: "var(--mantine-color-pink-text)",
59
+ cache: "var(--mantine-color-cyan-text)",
60
+ };
61
+
62
+ const folderIcons: Record<string, { icon: any; color: string }> = {
63
+ actions: { icon: IconApi, color: "var(--mantine-color-teal-text)" },
64
+ pages: { icon: IconFileText, color: "var(--mantine-color-blue-text)" },
65
+ queues: { icon: IconStack2, color: "var(--mantine-color-orange-text)" },
66
+ topics: { icon: IconBroadcast, color: "var(--mantine-color-pink-text)" },
67
+ caches: { icon: IconDatabase, color: "var(--mantine-color-cyan-text)" },
68
+ routes: { icon: IconRoute, color: "var(--mantine-color-violet-text)" },
69
+ };
70
+
71
+ const MethodBadge = ({ method }: { method: string }) => {
72
+ const upper = method.toUpperCase();
73
+ const short = upper === "DELETE" ? "DEL" : upper;
74
+ const colors = METHOD_COLORS[upper] ?? {
75
+ color: "var(--mantine-color-dimmed)",
76
+ bg: "var(--mantine-color-default-hover)",
77
+ };
78
+ return (
79
+ <Text
80
+ component="span"
81
+ fz={9}
82
+ fw={700}
83
+ ff="monospace"
84
+ lh={1}
85
+ style={{
86
+ paddingTop: 5,
87
+ color: colors.color,
88
+ background: colors.bg,
89
+ padding: "2px 4px",
90
+ borderRadius: 3,
91
+ flexShrink: 0,
92
+ letterSpacing: 0.3,
93
+ width: 32,
94
+ textAlign: "center",
95
+ display: "inline-block",
96
+ }}
97
+ >
98
+ {short}
99
+ </Text>
100
+ );
101
+ };
102
+
103
+ const toTreeViewNode = (
104
+ node: TreeNode,
105
+ openNodes: Set<string>,
106
+ ): TreeViewNode => {
107
+ const isFolder = node.type === "folder";
108
+ const isAction = node.type === "action";
109
+
110
+ let icon: React.ReactNode;
111
+
112
+ if (isFolder) {
113
+ const knownFolder = folderIcons[node.id];
114
+ if (knownFolder) {
115
+ const Icon = knownFolder.icon;
116
+ icon = (
117
+ <Icon size={15} color={knownFolder.color} style={{ flexShrink: 0 }} />
118
+ );
119
+ } else {
120
+ const isOpen = openNodes.has(node.id);
121
+ const Icon = isOpen ? IconFolderOpen : IconFolder;
122
+ icon = (
123
+ <Icon
124
+ size={15}
125
+ color="var(--mantine-color-dimmed)"
126
+ style={{ flexShrink: 0 }}
127
+ />
128
+ );
129
+ }
130
+ } else if (isAction) {
131
+ icon = <MethodBadge method={node.data?.method ?? "GET"} />;
132
+ } else {
133
+ const Icon = nodeIcons[node.type] ?? IconFileText;
134
+ const color = nodeColors[node.type] ?? "var(--mantine-color-dimmed)";
135
+ icon = <Icon size={15} color={color} style={{ flexShrink: 0 }} />;
136
+ }
137
+
138
+ return {
139
+ id: node.id,
140
+ label: node.label,
141
+ icon,
142
+ children: node.children?.map((child) => toTreeViewNode(child, openNodes)),
143
+ };
144
+ };
145
+
146
+ interface ExplorerTreeProps {
147
+ nodes: TreeNode[];
148
+ selectedId: string;
149
+ openNodes: Set<string>;
150
+ search: string;
151
+ onSelect: (id: string) => void;
152
+ onToggle: (id: string) => void;
153
+ }
154
+
155
+ export const ExplorerTree = ({
156
+ nodes,
157
+ selectedId,
158
+ openNodes,
159
+ search,
160
+ onSelect,
161
+ onToggle,
162
+ }: ExplorerTreeProps) => {
163
+ const treeViewNodes = useMemo(
164
+ () => nodes.map((n) => toTreeViewNode(n, openNodes)),
165
+ [nodes, openNodes],
166
+ );
167
+
168
+ return (
169
+ <TreeView
170
+ nodes={treeViewNodes}
171
+ selectedId={selectedId}
172
+ openNodes={openNodes}
173
+ search={search}
174
+ onSelect={onSelect}
175
+ onToggle={onToggle}
176
+ />
177
+ );
178
+ };
@@ -0,0 +1,499 @@
1
+ import { ActionButton, Flex, JsonViewer, TypeForm, ui } from "@alepha/ui";
2
+ import {
3
+ Badge,
4
+ Card,
5
+ Code,
6
+ JsonInput,
7
+ Tabs,
8
+ Text,
9
+ Tooltip,
10
+ } from "@mantine/core";
11
+ import { IconPlayerPlay, IconSchema } from "@tabler/icons-react";
12
+ import { jsonSchemaToTypeBox, t } from "alepha";
13
+ import { useInject } from "alepha/react";
14
+ import { useForm } from "alepha/react/form";
15
+ import { HttpClient } from "alepha/server";
16
+ import { useCallback, useMemo, useRef, useState } from "react";
17
+
18
+ const methodColors: Record<string, string> = {
19
+ GET: "teal",
20
+ POST: "blue",
21
+ PUT: "orange",
22
+ PATCH: "yellow",
23
+ DELETE: "red",
24
+ };
25
+
26
+ const EMPTY_SCHEMA = t.object({});
27
+
28
+ const toTypeBoxObject = (jsonSchema: any): any => {
29
+ if (!jsonSchema) return null;
30
+ try {
31
+ const converted = jsonSchemaToTypeBox(jsonSchema);
32
+ if (converted?.properties) return converted;
33
+ } catch {
34
+ // Schema conversion failed
35
+ }
36
+ return null;
37
+ };
38
+
39
+ const formatPermission = (perm: any): string =>
40
+ typeof perm === "string" ? perm : (perm?.name ?? String(perm));
41
+
42
+ const getMiddlewareSummary = (
43
+ name: string,
44
+ opts: any,
45
+ ): { label: string; color: string }[] | null => {
46
+ if (!opts) return null;
47
+ switch (name) {
48
+ case "$rateLimit":
49
+ if (opts.max) return [{ label: `max:${opts.max}`, color: "red" }];
50
+ break;
51
+ case "$circuit":
52
+ if (opts.threshold)
53
+ return [{ label: `threshold:${opts.threshold}`, color: "red" }];
54
+ break;
55
+ case "$throttle":
56
+ if (opts.rate) return [{ label: `rate:${opts.rate}`, color: "yellow" }];
57
+ break;
58
+ case "$retry":
59
+ if (opts.max) return [{ label: `max:${opts.max}`, color: "blue" }];
60
+ break;
61
+ case "$cors":
62
+ if (opts.origin) return [{ label: String(opts.origin), color: "blue" }];
63
+ break;
64
+ case "$lock":
65
+ if (opts.key) return [{ label: `key:${opts.key}`, color: "pink" }];
66
+ break;
67
+ }
68
+ return null;
69
+ };
70
+
71
+ const MiddlewareEntry = ({ mw }: { mw: any }) => {
72
+ const opts = mw.options;
73
+ const hasSecureDetails =
74
+ opts?.roles?.length ||
75
+ opts?.permissions?.length ||
76
+ opts?.issuers?.length ||
77
+ opts?.optional;
78
+
79
+ const summary =
80
+ mw.name !== "$secure" ? getMiddlewareSummary(mw.name, opts) : null;
81
+
82
+ const nameBadge = (
83
+ <Badge size="sm" variant="light" color="violet">
84
+ {mw.name}
85
+ </Badge>
86
+ );
87
+
88
+ return (
89
+ <Flex gap="xs" wrap="wrap" align="center">
90
+ {opts && !hasSecureDetails && !summary && mw.name !== "$secure" ? (
91
+ <Tooltip
92
+ label={JSON.stringify(opts, null, 2)}
93
+ multiline
94
+ maw={400}
95
+ styles={{ tooltip: { fontFamily: "monospace", fontSize: 11 } }}
96
+ >
97
+ {nameBadge}
98
+ </Tooltip>
99
+ ) : (
100
+ nameBadge
101
+ )}
102
+ {opts?.roles?.length > 0 &&
103
+ opts.roles.map((role: string) => (
104
+ <Badge key={role} size="xs" variant="dot" color="cyan">
105
+ {role}
106
+ </Badge>
107
+ ))}
108
+ {opts?.permissions?.length > 0 &&
109
+ opts.permissions.map((perm: any) => (
110
+ <Badge
111
+ key={formatPermission(perm)}
112
+ size="xs"
113
+ variant="dot"
114
+ color="orange"
115
+ >
116
+ {formatPermission(perm)}
117
+ </Badge>
118
+ ))}
119
+ {opts?.issuers?.length > 0 &&
120
+ opts.issuers.map((issuer: string) => (
121
+ <Badge key={issuer} size="xs" variant="dot" color="green">
122
+ {issuer}
123
+ </Badge>
124
+ ))}
125
+ {opts?.optional && (
126
+ <Badge size="xs" variant="outline" color="gray">
127
+ optional
128
+ </Badge>
129
+ )}
130
+ {summary?.map((item) => (
131
+ <Badge key={item.label} size="xs" variant="dot" color={item.color}>
132
+ {item.label}
133
+ </Badge>
134
+ ))}
135
+ </Flex>
136
+ );
137
+ };
138
+
139
+ export const DevPanelAction = ({ action }: { action: any }) => {
140
+ const http = useInject(HttpClient);
141
+ const [body, setBody] = useState("{}");
142
+ const [response, setResponse] = useState<any>(null);
143
+ const [loading, setLoading] = useState(false);
144
+ const [timing, setTiming] = useState<number>(0);
145
+
146
+ const actionKey = `${action.method}:${action.fullPath}`;
147
+
148
+ const bodySchema = useMemo(
149
+ () => (action.method !== "GET" ? toTypeBoxObject(action.body) : null),
150
+ [actionKey],
151
+ );
152
+ const querySchema = useMemo(() => toTypeBoxObject(action.query), [actionKey]);
153
+ const paramsSchema = useMemo(
154
+ () => toTypeBoxObject(action.params),
155
+ [actionKey],
156
+ );
157
+
158
+ const bodyForm = useForm(
159
+ { schema: bodySchema ?? EMPTY_SCHEMA, handler: () => {} },
160
+ [bodySchema],
161
+ );
162
+ const queryForm = useForm(
163
+ { schema: querySchema ?? EMPTY_SCHEMA, handler: () => {} },
164
+ [querySchema],
165
+ );
166
+ const paramsForm = useForm(
167
+ { schema: paramsSchema ?? EMPTY_SCHEMA, handler: () => {} },
168
+ [paramsSchema],
169
+ );
170
+
171
+ // Track whether we're using TypeForm or JsonInput for the body
172
+ const useTypeFormBody = !!bodySchema;
173
+ const bodyRef = useRef(body);
174
+ bodyRef.current = body;
175
+
176
+ const execute = useCallback(async () => {
177
+ setLoading(true);
178
+ setResponse(null);
179
+ const start = performance.now();
180
+ try {
181
+ // Build URL with path param substitution
182
+ let url = action.fullPath;
183
+ if (paramsSchema) {
184
+ const params = paramsForm.currentValues;
185
+ for (const [k, v] of Object.entries(params)) {
186
+ if (v !== undefined && v !== null) {
187
+ url = url.replace(`:${k}`, encodeURIComponent(String(v)));
188
+ }
189
+ }
190
+ }
191
+
192
+ // Append query params
193
+ if (querySchema) {
194
+ const qp = queryForm.currentValues;
195
+ const searchParams = new URLSearchParams();
196
+ for (const [k, v] of Object.entries(qp)) {
197
+ if (v !== undefined && v !== null && v !== "") {
198
+ searchParams.set(k, String(v));
199
+ }
200
+ }
201
+ const qs = searchParams.toString();
202
+ if (qs) url += `?${qs}`;
203
+ }
204
+
205
+ // Get body
206
+ let parsedBody: any;
207
+ if (action.method !== "GET") {
208
+ if (useTypeFormBody) {
209
+ parsedBody = bodyForm.currentValues;
210
+ } else {
211
+ try {
212
+ parsedBody = JSON.parse(bodyRef.current);
213
+ } catch {
214
+ parsedBody = undefined;
215
+ }
216
+ }
217
+ }
218
+
219
+ const res = await http.fetch(url, {
220
+ method: action.method,
221
+ body: action.method !== "GET" ? JSON.stringify(parsedBody) : undefined,
222
+ headers:
223
+ action.method !== "GET"
224
+ ? { "Content-Type": "application/json" }
225
+ : undefined,
226
+ });
227
+ setTiming(Math.round(performance.now() - start));
228
+ setResponse({ status: res.status, data: res.data });
229
+ } catch (error: any) {
230
+ setTiming(Math.round(performance.now() - start));
231
+ setResponse({ error: error.message ?? "Request failed" });
232
+ } finally {
233
+ setLoading(false);
234
+ }
235
+ }, [
236
+ http,
237
+ action,
238
+ useTypeFormBody,
239
+ bodyForm,
240
+ queryForm,
241
+ paramsForm,
242
+ bodySchema,
243
+ querySchema,
244
+ paramsSchema,
245
+ ]);
246
+
247
+ return (
248
+ <Flex direction="column" gap="md">
249
+ <div>
250
+ <Flex gap="sm" mb="xs">
251
+ <Badge
252
+ size="lg"
253
+ variant="light"
254
+ color={methodColors[action.method] ?? "gray"}
255
+ >
256
+ {action.method}
257
+ </Badge>
258
+ <Code fz="sm">{action.fullPath}</Code>
259
+ {action.secure && (
260
+ <Badge size="xs" variant="outline" color="yellow">
261
+ Secure
262
+ </Badge>
263
+ )}
264
+ </Flex>
265
+ {action.description && (
266
+ <Text fz="sm" c="dimmed">
267
+ {action.description}
268
+ </Text>
269
+ )}
270
+ </div>
271
+
272
+ {action.middlewares?.length > 0 && (
273
+ <div>
274
+ <Text fz="xs" c="dimmed" mb="xs" tt="uppercase" fw={600}>
275
+ Middleware
276
+ </Text>
277
+ <Flex direction="column" gap="xs">
278
+ {action.middlewares.map((mw: any) => (
279
+ <MiddlewareEntry key={mw.name} mw={mw} />
280
+ ))}
281
+ </Flex>
282
+ </div>
283
+ )}
284
+
285
+ <Tabs defaultValue="schema">
286
+ <Tabs.List>
287
+ <Tabs.Tab value="schema" leftSection={<IconSchema size={14} />}>
288
+ Schema
289
+ </Tabs.Tab>
290
+ <Tabs.Tab value="tryit" leftSection={<IconPlayerPlay size={14} />}>
291
+ Try It
292
+ </Tabs.Tab>
293
+ </Tabs.List>
294
+
295
+ <Tabs.Panel value="schema" pt="md">
296
+ <Flex direction="column" gap="md">
297
+ {action.body && (
298
+ <div>
299
+ <Text fz="xs" c="dimmed" mb="xs" tt="uppercase" fw={600}>
300
+ Request Body
301
+ </Text>
302
+ <Card
303
+ padding="sm"
304
+ style={{
305
+ background: ui.colors.surface,
306
+ border: `1px solid ${ui.colors.border}`,
307
+ }}
308
+ >
309
+ <JsonViewer
310
+ data={action.body}
311
+ defaultExpandedDepth={2}
312
+ size="xs"
313
+ />
314
+ </Card>
315
+ </div>
316
+ )}
317
+ {action.params && (
318
+ <div>
319
+ <Text fz="xs" c="dimmed" mb="xs" tt="uppercase" fw={600}>
320
+ Path Parameters
321
+ </Text>
322
+ <Card
323
+ padding="sm"
324
+ style={{
325
+ background: ui.colors.surface,
326
+ border: `1px solid ${ui.colors.border}`,
327
+ }}
328
+ >
329
+ <JsonViewer
330
+ data={action.params}
331
+ defaultExpandedDepth={2}
332
+ size="xs"
333
+ />
334
+ </Card>
335
+ </div>
336
+ )}
337
+ {action.query && (
338
+ <div>
339
+ <Text fz="xs" c="dimmed" mb="xs" tt="uppercase" fw={600}>
340
+ Query Parameters
341
+ </Text>
342
+ <Card
343
+ padding="sm"
344
+ style={{
345
+ background: ui.colors.surface,
346
+ border: `1px solid ${ui.colors.border}`,
347
+ }}
348
+ >
349
+ <JsonViewer
350
+ data={action.query}
351
+ defaultExpandedDepth={2}
352
+ size="xs"
353
+ />
354
+ </Card>
355
+ </div>
356
+ )}
357
+ {action.response && (
358
+ <div>
359
+ <Text fz="xs" c="dimmed" mb="xs" tt="uppercase" fw={600}>
360
+ Response
361
+ </Text>
362
+ <Card
363
+ padding="sm"
364
+ style={{
365
+ background: ui.colors.surface,
366
+ border: `1px solid ${ui.colors.border}`,
367
+ }}
368
+ >
369
+ <JsonViewer
370
+ data={action.response}
371
+ defaultExpandedDepth={2}
372
+ size="xs"
373
+ />
374
+ </Card>
375
+ </div>
376
+ )}
377
+ {!action.body &&
378
+ !action.params &&
379
+ !action.query &&
380
+ !action.response && (
381
+ <Text c="dimmed" fz="sm">
382
+ No schema defined for this action.
383
+ </Text>
384
+ )}
385
+ </Flex>
386
+ </Tabs.Panel>
387
+
388
+ <Tabs.Panel value="tryit" pt="md">
389
+ <Flex direction="column" gap="md">
390
+ {paramsSchema && (
391
+ <div>
392
+ <Text fz="xs" c="dimmed" mb="xs" tt="uppercase" fw={600}>
393
+ Path Parameters
394
+ </Text>
395
+ <TypeForm
396
+ form={paramsForm}
397
+ skipSubmitButton
398
+ skipFormElement
399
+ columns={1}
400
+ />
401
+ </div>
402
+ )}
403
+ {querySchema && (
404
+ <div>
405
+ <Text fz="xs" c="dimmed" mb="xs" tt="uppercase" fw={600}>
406
+ Query Parameters
407
+ </Text>
408
+ <TypeForm
409
+ form={queryForm}
410
+ skipSubmitButton
411
+ skipFormElement
412
+ columns={1}
413
+ />
414
+ </div>
415
+ )}
416
+ {action.method !== "GET" && (
417
+ <div>
418
+ <Text fz="xs" c="dimmed" mb="xs" tt="uppercase" fw={600}>
419
+ Request Body
420
+ </Text>
421
+ {bodySchema ? (
422
+ <TypeForm
423
+ form={bodyForm}
424
+ skipSubmitButton
425
+ skipFormElement
426
+ columns={1}
427
+ />
428
+ ) : (
429
+ <JsonInput
430
+ value={body}
431
+ onChange={setBody}
432
+ formatOnBlur
433
+ autosize
434
+ minRows={4}
435
+ maxRows={12}
436
+ styles={{
437
+ input: { fontFamily: "monospace", fontSize: 12 },
438
+ }}
439
+ />
440
+ )}
441
+ </div>
442
+ )}
443
+ <Flex>
444
+ <ActionButton
445
+ size="xs"
446
+ loading={loading}
447
+ onClick={execute}
448
+ color={methodColors[action.method] ?? "blue"}
449
+ icon={<IconPlayerPlay size={14} />}
450
+ >
451
+ Send Request
452
+ </ActionButton>
453
+ {timing > 0 && (
454
+ <Text fz="xs" c="dimmed">
455
+ {timing}ms
456
+ </Text>
457
+ )}
458
+ </Flex>
459
+ {response && (
460
+ <div>
461
+ <Text fz="xs" c="dimmed" mb="xs" tt="uppercase" fw={600}>
462
+ Response
463
+ </Text>
464
+ <Card
465
+ padding="sm"
466
+ style={{
467
+ background: ui.colors.surface,
468
+ border: `1px solid ${ui.colors.border}`,
469
+ }}
470
+ >
471
+ {response.error ? (
472
+ <Text c="red" fz="sm">
473
+ {response.error}
474
+ </Text>
475
+ ) : (
476
+ <>
477
+ <Badge
478
+ size="xs"
479
+ mb="xs"
480
+ color={response.status < 400 ? "teal" : "red"}
481
+ >
482
+ {response.status}
483
+ </Badge>
484
+ <JsonViewer
485
+ data={response.data}
486
+ defaultExpandedDepth={3}
487
+ size="xs"
488
+ />
489
+ </>
490
+ )}
491
+ </Card>
492
+ </div>
493
+ )}
494
+ </Flex>
495
+ </Tabs.Panel>
496
+ </Tabs>
497
+ </Flex>
498
+ );
499
+ };