devanvil 0.0.0-stage → 2.1.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 +21 -0
- package/README.ar.md +113 -0
- package/README.md +272 -2
- package/SECURITY.md +49 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +664 -0
- package/dist/core/contract-drift.d.ts +49 -0
- package/dist/core/contract-drift.js +312 -0
- package/dist/core/converters.d.ts +18 -0
- package/dist/core/converters.js +989 -0
- package/dist/core/cron.d.ts +33 -0
- package/dist/core/cron.js +309 -0
- package/dist/core/crypto.d.ts +59 -0
- package/dist/core/crypto.js +260 -0
- package/dist/core/curl.d.ts +17 -0
- package/dist/core/curl.js +174 -0
- package/dist/core/diff.d.ts +36 -0
- package/dist/core/diff.js +148 -0
- package/dist/core/encoding.d.ts +3 -0
- package/dist/core/encoding.js +143 -0
- package/dist/core/importers.d.ts +65 -0
- package/dist/core/importers.js +361 -0
- package/dist/core/jwt.d.ts +39 -0
- package/dist/core/jwt.js +269 -0
- package/dist/core/llm-tokens.d.ts +38 -0
- package/dist/core/llm-tokens.js +125 -0
- package/dist/core/log-analyzer.d.ts +30 -0
- package/dist/core/log-analyzer.js +155 -0
- package/dist/core/network.d.ts +72 -0
- package/dist/core/network.js +185 -0
- package/dist/core/oauth-protobuf.d.ts +74 -0
- package/dist/core/oauth-protobuf.js +396 -0
- package/dist/core/openapi.d.ts +27 -0
- package/dist/core/openapi.js +257 -0
- package/dist/core/pipeline.d.ts +28 -0
- package/dist/core/pipeline.js +154 -0
- package/dist/core/regex.d.ts +50 -0
- package/dist/core/regex.js +360 -0
- package/dist/core/runner.d.ts +53 -0
- package/dist/core/runner.js +250 -0
- package/dist/core/secrets.d.ts +87 -0
- package/dist/core/secrets.js +603 -0
- package/dist/core/security.d.ts +34 -0
- package/dist/core/security.js +301 -0
- package/dist/core/sql-explain.d.ts +50 -0
- package/dist/core/sql-explain.js +259 -0
- package/dist/core/tls.d.ts +44 -0
- package/dist/core/tls.js +169 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +31 -0
- package/dist/server/app.d.ts +31 -0
- package/dist/server/app.js +359 -0
- package/dist/server/http-proxy.d.ts +55 -0
- package/dist/server/http-proxy.js +373 -0
- package/dist/server/http-utils.d.ts +28 -0
- package/dist/server/http-utils.js +118 -0
- package/dist/server/load-tester.d.ts +53 -0
- package/dist/server/load-tester.js +137 -0
- package/dist/server/mcp.d.ts +35 -0
- package/dist/server/mcp.js +470 -0
- package/dist/server/mock-store.d.ts +38 -0
- package/dist/server/mock-store.js +238 -0
- package/dist/server/plugin-loader.d.ts +61 -0
- package/dist/server/plugin-loader.js +305 -0
- package/dist/server/recorder-store.d.ts +35 -0
- package/dist/server/recorder-store.js +147 -0
- package/dist/server/routes/network-routes.d.ts +3 -0
- package/dist/server/routes/network-routes.js +441 -0
- package/dist/server/routes/tools-routes.d.ts +3 -0
- package/dist/server/routes/tools-routes.js +299 -0
- package/dist/server/routes/workspace-routes.d.ts +3 -0
- package/dist/server/routes/workspace-routes.js +262 -0
- package/dist/server/webhook-store.d.ts +29 -0
- package/dist/server/webhook-store.js +100 -0
- package/dist/server/workspace-store.d.ts +91 -0
- package/dist/server/workspace-store.js +448 -0
- package/dist/server/ws-probe.d.ts +34 -0
- package/dist/server/ws-probe.js +291 -0
- package/dist/ui/app.js +290 -0
- package/dist/ui/favicon.svg +14 -0
- package/dist/ui/index.html +83 -0
- package/dist/ui/logo.png +0 -0
- package/dist/ui/styles.css +694 -0
- package/dist/ui/tools-data.js +719 -0
- package/dist/ui/tools-network.js +769 -0
- package/dist/ui/tools-ops.js +299 -0
- package/dist/ui/tools-pro.js +500 -0
- package/dist/ui/tools-security.js +397 -0
- package/dist/ui/tools-v12.js +765 -0
- package/dist/ui/tools-v13.js +321 -0
- package/dist/ui/tools-v20.js +563 -0
- package/dist/ui/tools-v21.js +411 -0
- package/package.json +75 -4
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
const { h, api, toast, copyText, registerTool, openInApiStudio } = window.DevAnvil;
|
|
4
|
+
|
|
5
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
6
|
+
// 14. Workspaces, Importers (Postman/HAR/.http) & AI Agent MCP Config
|
|
7
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
8
|
+
registerTool({
|
|
9
|
+
id: 'workspaces-mcp',
|
|
10
|
+
group: 'Network & API',
|
|
11
|
+
name: 'Workspaces, Import & MCP',
|
|
12
|
+
icon: '📦',
|
|
13
|
+
subtitle: 'Git-native Collections & Environments, Postman/HAR/.http Importer & AI Agent MCP Server',
|
|
14
|
+
keywords: ['workspace', 'collection', 'environment', 'postman', 'har', 'http', 'mcp', 'claude', 'cursor', 'import', 'export'],
|
|
15
|
+
render(root) {
|
|
16
|
+
let activeTab = 'workspace';
|
|
17
|
+
const tabBar = h('div', { class: 'tabs' });
|
|
18
|
+
const paneWorkspace = h('div', { class: 'stack' });
|
|
19
|
+
const paneImport = h('div', { class: 'stack' });
|
|
20
|
+
const paneMcp = h('div', { class: 'stack' });
|
|
21
|
+
|
|
22
|
+
// ─── Tab 1: Git-Native Workspaces, Environments & Collections ─────────
|
|
23
|
+
const persistBadge = h('span', { class: 'badge badge-subtle' }, 'Checking…');
|
|
24
|
+
const secretAuditBox = h('div', { class: 'stack' });
|
|
25
|
+
const runOutputBox = h('pre', { class: 'code-box', style: { display: 'none' } }, '');
|
|
26
|
+
const envListEl = h('div', { class: 'stack' });
|
|
27
|
+
const colListEl = h('div', { class: 'stack' });
|
|
28
|
+
|
|
29
|
+
const envNameIn = h('input', { type: 'text', placeholder: 'Environment name (e.g. Production)' });
|
|
30
|
+
const envVarsIn = h('textarea', {
|
|
31
|
+
rows: 4,
|
|
32
|
+
value: 'BASE_URL=https://api.example.com\nAPI_TOKEN={{env.API_TOKEN}}',
|
|
33
|
+
placeholder: 'KEY=VALUE (tip: use {{env.MY_SECRET}} so secrets stay out of Git!)',
|
|
34
|
+
});
|
|
35
|
+
const importWsArea = h('textarea', {
|
|
36
|
+
rows: 4,
|
|
37
|
+
placeholder: 'Paste exported devanvil.json or encrypted .anvil bundle here…',
|
|
38
|
+
});
|
|
39
|
+
const encPassIn = h('input', { type: 'password', placeholder: 'Passphrase (min 6 chars) for AES-256-GCM .anvil bundle' });
|
|
40
|
+
|
|
41
|
+
function parseKvLines(text) {
|
|
42
|
+
const out = {};
|
|
43
|
+
for (const line of text.split(/\r?\n/)) {
|
|
44
|
+
const idx = line.indexOf('=');
|
|
45
|
+
if (idx > 0) out[line.slice(0, idx).trim()] = line.slice(idx + 1).trim();
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function refreshWorkspace() {
|
|
51
|
+
try {
|
|
52
|
+
const data = await api('/api/workspace');
|
|
53
|
+
const ws = data.workspace;
|
|
54
|
+
persistBadge.textContent = data.persistent
|
|
55
|
+
? `Git-Native Persistence: ${data.filePath}${data.localOverridesPath ? ' (+ .local overrides)' : ''}`
|
|
56
|
+
: 'In-Memory Mode (pass --workspace ./devanvil.json to auto-save)';
|
|
57
|
+
persistBadge.className = `badge ${data.persistent ? 'badge-ok' : 'badge-info'}`;
|
|
58
|
+
|
|
59
|
+
// Surface Workspace Secret Audit warnings (prevent accidental secret commits!)
|
|
60
|
+
secretAuditBox.textContent = '';
|
|
61
|
+
const warns = data.secretWarnings || [];
|
|
62
|
+
if (warns.length > 0) {
|
|
63
|
+
for (const w of warns) {
|
|
64
|
+
secretAuditBox.appendChild(
|
|
65
|
+
h(
|
|
66
|
+
'div',
|
|
67
|
+
{ class: 'finding fail' },
|
|
68
|
+
h('strong', {}, `Secret Warning (${w.location}): `),
|
|
69
|
+
`${w.ruleName} [${w.masked}] — ${w.recommendation}`,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
secretAuditBox.appendChild(
|
|
75
|
+
h('div', { class: 'finding pass' }, 'Workspace Secret Guard: 0 plaintext credentials detected. Tip: reference secrets safely via {{env.VAR_NAME}} or devanvil.local.json.'),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
envListEl.textContent = '';
|
|
80
|
+
for (const env of ws.environments || []) {
|
|
81
|
+
const isActive = env.id === ws.activeEnvironmentId;
|
|
82
|
+
const varsText = Object.entries(env.variables || {})
|
|
83
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
84
|
+
.join(' · ');
|
|
85
|
+
envListEl.appendChild(
|
|
86
|
+
h(
|
|
87
|
+
'div',
|
|
88
|
+
{ class: 'list-item' },
|
|
89
|
+
h(
|
|
90
|
+
'div',
|
|
91
|
+
{ class: 'row-between' },
|
|
92
|
+
h(
|
|
93
|
+
'div',
|
|
94
|
+
{ class: 'row' },
|
|
95
|
+
h('strong', {}, env.name),
|
|
96
|
+
isActive ? h('span', { class: 'badge badge-ok' }, 'ACTIVE') : null,
|
|
97
|
+
),
|
|
98
|
+
h(
|
|
99
|
+
'div',
|
|
100
|
+
{ class: 'row' },
|
|
101
|
+
!isActive
|
|
102
|
+
? h(
|
|
103
|
+
'button',
|
|
104
|
+
{
|
|
105
|
+
type: 'button',
|
|
106
|
+
class: 'btn btn-xs btn-primary',
|
|
107
|
+
onClick: async () => {
|
|
108
|
+
try {
|
|
109
|
+
await api('/api/workspace/environments/active', { body: { id: env.id } });
|
|
110
|
+
toast(`Switched active environment -> ${env.name}`, 'ok');
|
|
111
|
+
await refreshWorkspace();
|
|
112
|
+
} catch (err) {
|
|
113
|
+
toast(err.message, 'err');
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
'Set Active',
|
|
118
|
+
)
|
|
119
|
+
: null,
|
|
120
|
+
h(
|
|
121
|
+
'button',
|
|
122
|
+
{
|
|
123
|
+
type: 'button',
|
|
124
|
+
class: 'btn btn-xs',
|
|
125
|
+
onClick: () => {
|
|
126
|
+
envNameIn.value = env.name;
|
|
127
|
+
envVarsIn.value = Object.entries(env.variables || {})
|
|
128
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
129
|
+
.join('\n');
|
|
130
|
+
envNameIn.dataset.editId = env.id;
|
|
131
|
+
toast(`Loaded "${env.name}" for editing`, 'ok');
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
'Edit',
|
|
135
|
+
),
|
|
136
|
+
ws.environments.length > 1
|
|
137
|
+
? h(
|
|
138
|
+
'button',
|
|
139
|
+
{
|
|
140
|
+
type: 'button',
|
|
141
|
+
class: 'btn btn-xs btn-ghost',
|
|
142
|
+
onClick: async () => {
|
|
143
|
+
try {
|
|
144
|
+
await api(`/api/workspace/environments/${encodeURIComponent(env.id)}`, { method: 'DELETE' });
|
|
145
|
+
toast(`Deleted environment "${env.name}"`, 'ok');
|
|
146
|
+
await refreshWorkspace();
|
|
147
|
+
} catch (err) {
|
|
148
|
+
toast(err.message, 'err');
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
'Delete',
|
|
153
|
+
)
|
|
154
|
+
: null,
|
|
155
|
+
),
|
|
156
|
+
),
|
|
157
|
+
h('div', { class: 'mono', style: { fontSize: '11.5px', color: 'var(--text-muted)' } }, varsText || '(no variables)'),
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
colListEl.textContent = '';
|
|
163
|
+
if (!ws.collections || !ws.collections.length) {
|
|
164
|
+
colListEl.appendChild(h('div', { class: 'finding info' }, 'No collections yet — import Postman/HAR/.http or save requests from API Studio.'));
|
|
165
|
+
} else {
|
|
166
|
+
for (const col of ws.collections) {
|
|
167
|
+
const reqRows = h('div', { class: 'stack' });
|
|
168
|
+
for (const req of col.requests || []) {
|
|
169
|
+
const aCount = (req.assertions || []).length;
|
|
170
|
+
const eCount = (req.extract || []).length;
|
|
171
|
+
const editorPanel = h('div', { class: 'stack', style: { display: 'none', marginTop: '6px', padding: '8px', background: 'var(--bg-input)', borderRadius: '6px', border: '1px solid var(--border)' } });
|
|
172
|
+
|
|
173
|
+
// Visual Assertions & Request Chaining (extract) Builder
|
|
174
|
+
const assertionsState = (req.assertions || []).map((x) => ({ ...x }));
|
|
175
|
+
const extractState = (req.extract || []).map((x) => ({ ...x }));
|
|
176
|
+
const assertionsWrap = h('div', { class: 'stack' });
|
|
177
|
+
const extractWrap = h('div', { class: 'stack' });
|
|
178
|
+
|
|
179
|
+
function renderAssertionsEditor() {
|
|
180
|
+
assertionsWrap.textContent = '';
|
|
181
|
+
if (!assertionsState.length) {
|
|
182
|
+
assertionsWrap.appendChild(h('div', { style: { fontSize: '11.5px', color: 'var(--text-dim)' } }, 'No assertions yet (defaults to HTTP 2xx).'));
|
|
183
|
+
}
|
|
184
|
+
assertionsState.forEach((a, idx) => {
|
|
185
|
+
const typeSel = h(
|
|
186
|
+
'select',
|
|
187
|
+
{ style: { width: '135px' } },
|
|
188
|
+
['status', 'jsonPathEquals', 'bodyContains', 'headerContains', 'maxLatencyMs'].map((t) =>
|
|
189
|
+
h('option', { value: t, selected: a.type === t }, t),
|
|
190
|
+
),
|
|
191
|
+
);
|
|
192
|
+
const targetIn = h('input', { type: 'text', value: a.target || '', placeholder: 'target (e.g. $.user / content-type)', style: { width: '170px' } });
|
|
193
|
+
const expIn = h('input', { type: 'text', value: a.expected !== undefined ? String(a.expected) : '', placeholder: 'expected value (e.g. 200 / true)', style: { flex: '1' } });
|
|
194
|
+
typeSel.addEventListener('change', () => { a.type = typeSel.value; });
|
|
195
|
+
targetIn.addEventListener('input', () => { a.target = targetIn.value || undefined; });
|
|
196
|
+
expIn.addEventListener('input', () => {
|
|
197
|
+
const v = expIn.value.trim();
|
|
198
|
+
if (a.type === 'status' || a.type === 'maxLatencyMs') a.expected = Number(v) || 0;
|
|
199
|
+
else if (v === 'true') a.expected = true;
|
|
200
|
+
else if (v === 'false') a.expected = false;
|
|
201
|
+
else if (v !== '' && !Number.isNaN(Number(v)) && a.type === 'jsonPathEquals') a.expected = Number(v);
|
|
202
|
+
else a.expected = expIn.value;
|
|
203
|
+
});
|
|
204
|
+
assertionsWrap.appendChild(
|
|
205
|
+
h(
|
|
206
|
+
'div',
|
|
207
|
+
{ class: 'row' },
|
|
208
|
+
typeSel,
|
|
209
|
+
targetIn,
|
|
210
|
+
expIn,
|
|
211
|
+
h('button', { type: 'button', class: 'btn btn-xs btn-ghost', onClick: () => { assertionsState.splice(idx, 1); renderAssertionsEditor(); } }, 'x'),
|
|
212
|
+
),
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function renderExtractEditor() {
|
|
218
|
+
extractWrap.textContent = '';
|
|
219
|
+
if (!extractState.length) {
|
|
220
|
+
extractWrap.appendChild(h('div', { style: { fontSize: '11.5px', color: 'var(--text-dim)' } }, 'No chained variables extracted yet (e.g. TOKEN from $.accessToken).'));
|
|
221
|
+
}
|
|
222
|
+
extractState.forEach((ex, idx) => {
|
|
223
|
+
const varIn = h('input', { type: 'text', value: ex.variable || '', placeholder: 'VAR_NAME (e.g. TOKEN)', style: { width: '130px' } });
|
|
224
|
+
const srcSel = h(
|
|
225
|
+
'select',
|
|
226
|
+
{ style: { width: '110px' } },
|
|
227
|
+
['jsonPath', 'header'].map((s) => h('option', { value: s, selected: ex.source === s }, s)),
|
|
228
|
+
);
|
|
229
|
+
const exprIn = h('input', { type: 'text', value: ex.expression || '', placeholder: '$.accessToken or x-session-id', style: { flex: '1' } });
|
|
230
|
+
varIn.addEventListener('input', () => { ex.variable = varIn.value.trim(); });
|
|
231
|
+
srcSel.addEventListener('change', () => { ex.source = srcSel.value; });
|
|
232
|
+
exprIn.addEventListener('input', () => { ex.expression = exprIn.value.trim(); });
|
|
233
|
+
extractWrap.appendChild(
|
|
234
|
+
h(
|
|
235
|
+
'div',
|
|
236
|
+
{ class: 'row' },
|
|
237
|
+
varIn,
|
|
238
|
+
srcSel,
|
|
239
|
+
exprIn,
|
|
240
|
+
h('button', { type: 'button', class: 'btn btn-xs btn-ghost', onClick: () => { extractState.splice(idx, 1); renderExtractEditor(); } }, 'x'),
|
|
241
|
+
),
|
|
242
|
+
);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
renderAssertionsEditor();
|
|
247
|
+
renderExtractEditor();
|
|
248
|
+
|
|
249
|
+
editorPanel.appendChild(
|
|
250
|
+
h(
|
|
251
|
+
'div',
|
|
252
|
+
{ class: 'row-between' },
|
|
253
|
+
h('strong', { style: { fontSize: '12px' } }, 'Assertions (Test Rules)'),
|
|
254
|
+
h('button', { type: 'button', class: 'btn btn-xs', onClick: () => { assertionsState.push({ type: 'status', expected: 200 }); renderAssertionsEditor(); } }, '+ Assertion'),
|
|
255
|
+
),
|
|
256
|
+
);
|
|
257
|
+
editorPanel.appendChild(assertionsWrap);
|
|
258
|
+
editorPanel.appendChild(
|
|
259
|
+
h(
|
|
260
|
+
'div',
|
|
261
|
+
{ class: 'row-between' },
|
|
262
|
+
h('strong', { style: { fontSize: '12px' } }, 'Request Chaining (Extract -> {{VAR}} for next requests)'),
|
|
263
|
+
h('button', { type: 'button', class: 'btn btn-xs', onClick: () => { extractState.push({ variable: 'TOKEN', source: 'jsonPath', expression: '$.token' }); renderExtractEditor(); } }, '+ Extract Var'),
|
|
264
|
+
),
|
|
265
|
+
);
|
|
266
|
+
editorPanel.appendChild(extractWrap);
|
|
267
|
+
editorPanel.appendChild(
|
|
268
|
+
h(
|
|
269
|
+
'div',
|
|
270
|
+
{ class: 'row' },
|
|
271
|
+
h(
|
|
272
|
+
'button',
|
|
273
|
+
{
|
|
274
|
+
type: 'button',
|
|
275
|
+
class: 'btn btn-xs btn-primary',
|
|
276
|
+
onClick: async () => {
|
|
277
|
+
try {
|
|
278
|
+
await api(`/api/workspace/collections/${encodeURIComponent(col.id)}/requests/${encodeURIComponent(req.id)}`, {
|
|
279
|
+
method: 'PUT',
|
|
280
|
+
body: {
|
|
281
|
+
assertions: assertionsState.filter((a) => a.type),
|
|
282
|
+
extract: extractState.filter((e) => e.variable && e.expression),
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
toast(`Saved rules & chaining for "${req.name}"`, 'ok');
|
|
286
|
+
await refreshWorkspace();
|
|
287
|
+
} catch (err) {
|
|
288
|
+
toast(err.message, 'err');
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
'Save Rules & Chaining',
|
|
293
|
+
),
|
|
294
|
+
h(
|
|
295
|
+
'button',
|
|
296
|
+
{
|
|
297
|
+
type: 'button',
|
|
298
|
+
class: 'btn btn-xs btn-ghost',
|
|
299
|
+
onClick: async () => {
|
|
300
|
+
try {
|
|
301
|
+
await api(`/api/workspace/collections/${encodeURIComponent(col.id)}/requests/${encodeURIComponent(req.id)}`, { method: 'DELETE' });
|
|
302
|
+
toast(`Deleted request "${req.name}"`, 'ok');
|
|
303
|
+
await refreshWorkspace();
|
|
304
|
+
} catch (err) {
|
|
305
|
+
toast(err.message, 'err');
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
'Delete Request',
|
|
310
|
+
),
|
|
311
|
+
),
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
reqRows.appendChild(
|
|
315
|
+
h(
|
|
316
|
+
'div',
|
|
317
|
+
{ class: 'stack', style: { padding: '6px 8px', background: 'var(--bg-card)', borderRadius: '6px', border: '1px solid var(--border)' } },
|
|
318
|
+
h(
|
|
319
|
+
'div',
|
|
320
|
+
{ class: 'row-between' },
|
|
321
|
+
h(
|
|
322
|
+
'div',
|
|
323
|
+
{ class: 'row' },
|
|
324
|
+
h('span', { class: 'badge badge-info' }, req.method),
|
|
325
|
+
h('strong', { style: { fontSize: '12.5px' } }, req.name),
|
|
326
|
+
h('span', { class: 'mono', style: { fontSize: '11.5px', color: 'var(--text-dim)' } }, req.url),
|
|
327
|
+
aCount ? h('span', { class: 'badge badge-ok' }, `${aCount} assert`) : null,
|
|
328
|
+
eCount ? h('span', { class: 'badge badge-warn' }, `${eCount} chain`) : null,
|
|
329
|
+
),
|
|
330
|
+
h(
|
|
331
|
+
'div',
|
|
332
|
+
{ class: 'row' },
|
|
333
|
+
h(
|
|
334
|
+
'button',
|
|
335
|
+
{
|
|
336
|
+
type: 'button',
|
|
337
|
+
class: 'btn btn-xs btn-ghost',
|
|
338
|
+
onClick: () => {
|
|
339
|
+
editorPanel.style.display = editorPanel.style.display === 'none' ? '' : 'none';
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
'Rules / Chain',
|
|
343
|
+
),
|
|
344
|
+
h(
|
|
345
|
+
'button',
|
|
346
|
+
{
|
|
347
|
+
type: 'button',
|
|
348
|
+
class: 'btn btn-xs btn-primary',
|
|
349
|
+
onClick: () => openInApiStudio({ method: req.method, url: req.url, headers: req.headers || {}, body: req.body || '' }),
|
|
350
|
+
},
|
|
351
|
+
'Open ->',
|
|
352
|
+
),
|
|
353
|
+
),
|
|
354
|
+
),
|
|
355
|
+
editorPanel,
|
|
356
|
+
),
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
colListEl.appendChild(
|
|
360
|
+
h(
|
|
361
|
+
'div',
|
|
362
|
+
{ class: 'list-item' },
|
|
363
|
+
h(
|
|
364
|
+
'div',
|
|
365
|
+
{ class: 'row-between' },
|
|
366
|
+
h('div', { class: 'row' }, h('strong', {}, col.name), h('span', { class: 'badge badge-subtle' }, `${(col.requests || []).length} request(s)`)),
|
|
367
|
+
h(
|
|
368
|
+
'div',
|
|
369
|
+
{ class: 'row' },
|
|
370
|
+
h(
|
|
371
|
+
'button',
|
|
372
|
+
{
|
|
373
|
+
type: 'button',
|
|
374
|
+
class: 'btn btn-xs btn-primary',
|
|
375
|
+
onClick: async () => {
|
|
376
|
+
try {
|
|
377
|
+
const res = await api('/api/workspace/run', { body: { collectionId: col.id, includeJunit: true } });
|
|
378
|
+
const rep = res.report;
|
|
379
|
+
runOutputBox.style.display = '';
|
|
380
|
+
runOutputBox.textContent = JSON.stringify(rep, null, 2);
|
|
381
|
+
runOutputBox.dataset.junit = res.junitXml || '';
|
|
382
|
+
toast(`Collection "${col.name}": ${rep.passedRequests}/${rep.totalRequests} passed (${rep.totalDurationMs}ms)`, rep.passed ? 'ok' : 'err');
|
|
383
|
+
} catch (err) {
|
|
384
|
+
toast(err.message, 'err');
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
'Run Tests',
|
|
389
|
+
),
|
|
390
|
+
h(
|
|
391
|
+
'button',
|
|
392
|
+
{
|
|
393
|
+
type: 'button',
|
|
394
|
+
class: 'btn btn-xs btn-ghost',
|
|
395
|
+
onClick: () => {
|
|
396
|
+
if (runOutputBox.dataset.junit) copyText(runOutputBox.dataset.junit, 'Copied JUnit XML report!');
|
|
397
|
+
else toast('Run collection tests first to generate JUnit XML', 'err');
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
'Copy JUnit',
|
|
401
|
+
),
|
|
402
|
+
h(
|
|
403
|
+
'button',
|
|
404
|
+
{
|
|
405
|
+
type: 'button',
|
|
406
|
+
class: 'btn btn-xs btn-ghost',
|
|
407
|
+
onClick: async () => {
|
|
408
|
+
try {
|
|
409
|
+
await api(`/api/workspace/collections/${encodeURIComponent(col.id)}`, { method: 'DELETE' });
|
|
410
|
+
toast(`Deleted collection "${col.name}"`, 'ok');
|
|
411
|
+
await refreshWorkspace();
|
|
412
|
+
} catch (err) {
|
|
413
|
+
toast(err.message, 'err');
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
'Delete',
|
|
418
|
+
),
|
|
419
|
+
),
|
|
420
|
+
),
|
|
421
|
+
reqRows,
|
|
422
|
+
),
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
} catch (err) {
|
|
427
|
+
toast(err.message, 'err');
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
paneWorkspace.appendChild(
|
|
432
|
+
h(
|
|
433
|
+
'div',
|
|
434
|
+
{ class: 'card' },
|
|
435
|
+
h(
|
|
436
|
+
'div',
|
|
437
|
+
{ class: 'row-between' },
|
|
438
|
+
h('div', { class: 'row' }, h('h2', { class: 'card-title' }, 'Workspace Status'), persistBadge),
|
|
439
|
+
h(
|
|
440
|
+
'div',
|
|
441
|
+
{ class: 'row' },
|
|
442
|
+
h(
|
|
443
|
+
'button',
|
|
444
|
+
{
|
|
445
|
+
type: 'button',
|
|
446
|
+
class: 'btn btn-sm',
|
|
447
|
+
onClick: async () => {
|
|
448
|
+
try {
|
|
449
|
+
const data = await api('/api/workspace');
|
|
450
|
+
await copyText(JSON.stringify(data.workspace, null, 2), 'Exported devanvil.json to clipboard');
|
|
451
|
+
} catch (err) {
|
|
452
|
+
toast(err.message, 'err');
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
'Export devanvil.json',
|
|
457
|
+
),
|
|
458
|
+
h('button', { type: 'button', class: 'btn btn-ghost btn-sm', onClick: refreshWorkspace }, 'Refresh'),
|
|
459
|
+
),
|
|
460
|
+
),
|
|
461
|
+
secretAuditBox,
|
|
462
|
+
),
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
paneWorkspace.appendChild(
|
|
466
|
+
h(
|
|
467
|
+
'div',
|
|
468
|
+
{ class: 'grid-2' },
|
|
469
|
+
h(
|
|
470
|
+
'div',
|
|
471
|
+
{ class: 'card' },
|
|
472
|
+
h('h2', { class: 'card-title' }, 'Environments ({{VAR}} Interpolation)'),
|
|
473
|
+
envListEl,
|
|
474
|
+
h('label', { class: 'field-label' }, 'Add / Update Environment'),
|
|
475
|
+
envNameIn,
|
|
476
|
+
envVarsIn,
|
|
477
|
+
h(
|
|
478
|
+
'div',
|
|
479
|
+
{ class: 'row' },
|
|
480
|
+
h(
|
|
481
|
+
'button',
|
|
482
|
+
{
|
|
483
|
+
type: 'button',
|
|
484
|
+
class: 'btn btn-primary btn-sm',
|
|
485
|
+
onClick: async () => {
|
|
486
|
+
try {
|
|
487
|
+
await api('/api/workspace/environments', {
|
|
488
|
+
body: {
|
|
489
|
+
id: envNameIn.dataset.editId || undefined,
|
|
490
|
+
name: envNameIn.value,
|
|
491
|
+
variables: parseKvLines(envVarsIn.value),
|
|
492
|
+
},
|
|
493
|
+
});
|
|
494
|
+
delete envNameIn.dataset.editId;
|
|
495
|
+
envNameIn.value = '';
|
|
496
|
+
toast('Saved environment', 'ok');
|
|
497
|
+
await refreshWorkspace();
|
|
498
|
+
} catch (err) {
|
|
499
|
+
toast(err.message, 'err');
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
'Save Environment',
|
|
504
|
+
),
|
|
505
|
+
),
|
|
506
|
+
),
|
|
507
|
+
h(
|
|
508
|
+
'div',
|
|
509
|
+
{ class: 'card' },
|
|
510
|
+
h('h2', { class: 'card-title' }, 'Saved API Collections'),
|
|
511
|
+
colListEl,
|
|
512
|
+
runOutputBox,
|
|
513
|
+
h('label', { class: 'field-label' }, 'Restore devanvil.json or Encrypted .anvil Bundle'),
|
|
514
|
+
importWsArea,
|
|
515
|
+
encPassIn,
|
|
516
|
+
h(
|
|
517
|
+
'div',
|
|
518
|
+
{ class: 'row' },
|
|
519
|
+
h(
|
|
520
|
+
'button',
|
|
521
|
+
{
|
|
522
|
+
type: 'button',
|
|
523
|
+
class: 'btn btn-sm',
|
|
524
|
+
onClick: async () => {
|
|
525
|
+
try {
|
|
526
|
+
await api('/api/workspace/import', { body: { json: importWsArea.value, replaceMocks: false } });
|
|
527
|
+
importWsArea.value = '';
|
|
528
|
+
toast('Workspace restored cleanly!', 'ok');
|
|
529
|
+
await refreshWorkspace();
|
|
530
|
+
} catch (err) {
|
|
531
|
+
toast(err.message, 'err');
|
|
532
|
+
}
|
|
533
|
+
},
|
|
534
|
+
},
|
|
535
|
+
'Import Plain JSON',
|
|
536
|
+
),
|
|
537
|
+
h(
|
|
538
|
+
'button',
|
|
539
|
+
{
|
|
540
|
+
type: 'button',
|
|
541
|
+
class: 'btn btn-sm',
|
|
542
|
+
onClick: async () => {
|
|
543
|
+
try {
|
|
544
|
+
const res = await api('/api/workspace/export-encrypted', { body: { passphrase: encPassIn.value } });
|
|
545
|
+
await copyText(JSON.stringify(res.bundle, null, 2), 'Copied AES-256-GCM encrypted .anvil bundle!');
|
|
546
|
+
} catch (err) {
|
|
547
|
+
toast(err.message, 'err');
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
},
|
|
551
|
+
'Export Encrypted .anvil',
|
|
552
|
+
),
|
|
553
|
+
h(
|
|
554
|
+
'button',
|
|
555
|
+
{
|
|
556
|
+
type: 'button',
|
|
557
|
+
class: 'btn btn-sm btn-primary',
|
|
558
|
+
onClick: async () => {
|
|
559
|
+
try {
|
|
560
|
+
await api('/api/workspace/import-encrypted', { body: { bundle: importWsArea.value, passphrase: encPassIn.value } });
|
|
561
|
+
importWsArea.value = '';
|
|
562
|
+
toast('Decrypted & restored .anvil workspace!', 'ok');
|
|
563
|
+
await refreshWorkspace();
|
|
564
|
+
} catch (err) {
|
|
565
|
+
toast(err.message, 'err');
|
|
566
|
+
}
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
'Decrypt & Import .anvil',
|
|
570
|
+
),
|
|
571
|
+
),
|
|
572
|
+
),
|
|
573
|
+
),
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
// ─── Tab 2: Postman v2.1 / HAR 1.2 / .http Importer ───────────────────
|
|
577
|
+
const samplePostman = JSON.stringify(
|
|
578
|
+
{
|
|
579
|
+
info: { name: 'Sample Acme API (Postman v2.1)', schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json' },
|
|
580
|
+
item: [
|
|
581
|
+
{
|
|
582
|
+
name: 'Get User Profile',
|
|
583
|
+
request: {
|
|
584
|
+
method: 'GET',
|
|
585
|
+
header: [{ key: 'Accept', value: 'application/json' }],
|
|
586
|
+
url: { raw: '{{BASE_URL}}/mock/users/42' },
|
|
587
|
+
},
|
|
588
|
+
response: [{ name: '200 OK', code: 200, body: '{"id":42,"name":"Ada Lovelace","role":"admin"}' }],
|
|
589
|
+
},
|
|
590
|
+
],
|
|
591
|
+
},
|
|
592
|
+
null,
|
|
593
|
+
2,
|
|
594
|
+
);
|
|
595
|
+
|
|
596
|
+
const impFormatSel = h(
|
|
597
|
+
'select',
|
|
598
|
+
{ style: { width: '175px' } },
|
|
599
|
+
[
|
|
600
|
+
['auto', 'Auto-Detect Format'],
|
|
601
|
+
['postman', 'Postman v2.1 JSON'],
|
|
602
|
+
['har', 'Browser HAR 1.2'],
|
|
603
|
+
['http', '.http / .rest File'],
|
|
604
|
+
].map(([v, l]) => h('option', { value: v }, l)),
|
|
605
|
+
);
|
|
606
|
+
const mountMocksChk = h('input', { type: 'checkbox', checked: true });
|
|
607
|
+
const impInput = h('textarea', { rows: 13, value: samplePostman });
|
|
608
|
+
const impResult = h('pre', { class: 'code-box' }, 'Paste Postman v2.1 JSON, browser DevTools HAR export, or VS Code .http file and click Import.');
|
|
609
|
+
|
|
610
|
+
paneImport.appendChild(
|
|
611
|
+
h(
|
|
612
|
+
'div',
|
|
613
|
+
{ class: 'card' },
|
|
614
|
+
h(
|
|
615
|
+
'div',
|
|
616
|
+
{ class: 'row-between' },
|
|
617
|
+
h(
|
|
618
|
+
'div',
|
|
619
|
+
{ class: 'row' },
|
|
620
|
+
impFormatSel,
|
|
621
|
+
h('label', { class: 'row', style: { fontSize: '12px' } }, mountMocksChk, 'Also mount captured HAR/Postman responses -> Live /mock/*'),
|
|
622
|
+
),
|
|
623
|
+
h(
|
|
624
|
+
'button',
|
|
625
|
+
{
|
|
626
|
+
type: 'button',
|
|
627
|
+
class: 'btn btn-primary btn-sm',
|
|
628
|
+
onClick: async () => {
|
|
629
|
+
try {
|
|
630
|
+
const res = await api('/api/import/collection', {
|
|
631
|
+
body: { input: impInput.value, format: impFormatSel.value, mountMocks: mountMocksChk.checked },
|
|
632
|
+
});
|
|
633
|
+
impResult.textContent = JSON.stringify(
|
|
634
|
+
{
|
|
635
|
+
detectedFormat: res.format,
|
|
636
|
+
collectionName: res.collection.name,
|
|
637
|
+
importedRequests: res.importedRequestsCount,
|
|
638
|
+
mountedLiveMocks: res.mountedMocksCount,
|
|
639
|
+
warnings: res.warnings,
|
|
640
|
+
},
|
|
641
|
+
null,
|
|
642
|
+
2,
|
|
643
|
+
);
|
|
644
|
+
toast(`Imported ${res.importedRequestsCount} request(s) & ${res.mountedMocksCount} live mock(s)!`, 'ok');
|
|
645
|
+
await refreshWorkspace();
|
|
646
|
+
} catch (err) {
|
|
647
|
+
toast(err.message, 'err');
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
},
|
|
651
|
+
'Import Collection',
|
|
652
|
+
),
|
|
653
|
+
),
|
|
654
|
+
h('div', { class: 'grid-2' }, impInput, impResult),
|
|
655
|
+
),
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
// ─── Tab 3: AI Agent MCP Server Setup (Claude Code / Cursor / Windsurf) ──
|
|
659
|
+
const mcpJsonConfig = JSON.stringify(
|
|
660
|
+
{
|
|
661
|
+
mcpServers: {
|
|
662
|
+
devanvil: {
|
|
663
|
+
command: 'devanvil',
|
|
664
|
+
args: ['mcp'],
|
|
665
|
+
},
|
|
666
|
+
},
|
|
667
|
+
},
|
|
668
|
+
null,
|
|
669
|
+
2,
|
|
670
|
+
);
|
|
671
|
+
const claudeCliCmd = 'claude mcp add devanvil -- devanvil mcp';
|
|
672
|
+
|
|
673
|
+
const mcpToolsList = [
|
|
674
|
+
['devanvil_scan_secrets', 'Scan code/diffs/logs offline & return redacted text'],
|
|
675
|
+
['devanvil_scan_directory', 'Recursive repo scan (.gitignore-aware) + SARIF 2.1.0'],
|
|
676
|
+
['devanvil_check_env', 'Validate .env syntax & drift vs .env.example'],
|
|
677
|
+
['devanvil_openapi_to_mocks', 'Parse OpenAPI 3.x/Swagger -> realistic mock payloads'],
|
|
678
|
+
['devanvil_jwt_audit', 'Decode, audit & verify HS/RS/ES JWT tokens offline'],
|
|
679
|
+
['devanvil_regex_test', 'Static ReDoS check + isolated 250ms node:vm regex runner'],
|
|
680
|
+
['devanvil_convert_data', 'JSON / YAML / TOML / CSV / TypeScript / JSON Schema'],
|
|
681
|
+
['devanvil_semantic_diff', 'Order-independent Semantic JSON & LCS text diff'],
|
|
682
|
+
['devanvil_llm_tokens', 'Offline BPE token/cost estimator + context compactor'],
|
|
683
|
+
['devanvil_generate_id', 'Batch RFC 9562 UUIDv7, UUIDv4, ULID, NanoID & API keys'],
|
|
684
|
+
['devanvil_cron_explain', 'Explain 5/6-field Cron + upcoming UTC schedules'],
|
|
685
|
+
['devanvil_inspect_cert', 'Inspect PEM X.509 SSL/TLS certificates offline'],
|
|
686
|
+
['devanvil_explain_sql', 'Analyze Postgres/SQLite EXPLAIN plans & detect bottlenecks'],
|
|
687
|
+
['devanvil_analyze_logs', 'NDJSON/log error fingerprinting, P95 latency & secret leak check'],
|
|
688
|
+
['devanvil_check_contract_drift', 'Validate real API responses against OpenAPI contracts for breaking drift'],
|
|
689
|
+
['devanvil_decode_protobuf', 'Decode raw Protobuf binary wire payloads (+ optional .proto mapping)'],
|
|
690
|
+
];
|
|
691
|
+
|
|
692
|
+
paneMcp.appendChild(
|
|
693
|
+
h(
|
|
694
|
+
'div',
|
|
695
|
+
{ class: 'grid-2' },
|
|
696
|
+
h(
|
|
697
|
+
'div',
|
|
698
|
+
{ class: 'card' },
|
|
699
|
+
h(
|
|
700
|
+
'div',
|
|
701
|
+
{ class: 'row-between' },
|
|
702
|
+
h('h2', { class: 'card-title' }, 'Connect Claude Desktop / Cursor / Windsurf'),
|
|
703
|
+
h('button', { type: 'button', class: 'btn btn-primary btn-xs', onClick: () => copyText(mcpJsonConfig, 'Copied MCP JSON config') }, 'Copy JSON'),
|
|
704
|
+
),
|
|
705
|
+
h('p', { style: { fontSize: '12.5px', color: 'var(--text-muted)', margin: '0' } }, 'DevAnvil includes a built-in zero-dependency Model Context Protocol (MCP) server over stdio. Drop this into your MCP config:'),
|
|
706
|
+
h('pre', { class: 'code-box' }, mcpJsonConfig),
|
|
707
|
+
h(
|
|
708
|
+
'div',
|
|
709
|
+
{ class: 'row-between' },
|
|
710
|
+
h('strong', { style: { fontSize: '12.5px' } }, 'Claude Code (1-Line Setup)'),
|
|
711
|
+
h('button', { type: 'button', class: 'btn btn-xs', onClick: () => copyText(claudeCliCmd, 'Copied Claude Code command') }, 'Copy'),
|
|
712
|
+
),
|
|
713
|
+
h('pre', { class: 'code-box' }, claudeCliCmd),
|
|
714
|
+
),
|
|
715
|
+
h(
|
|
716
|
+
'div',
|
|
717
|
+
{ class: 'card' },
|
|
718
|
+
h('h2', { class: 'card-title' }, '16 Offline MCP Tools Exposed to AI Agents'),
|
|
719
|
+
h(
|
|
720
|
+
'div',
|
|
721
|
+
{ class: 'stack' },
|
|
722
|
+
mcpToolsList.map(([name, desc]) =>
|
|
723
|
+
h(
|
|
724
|
+
'div',
|
|
725
|
+
{ class: 'finding pass' },
|
|
726
|
+
h('span', { class: 'mono', style: { fontWeight: '700' } }, name),
|
|
727
|
+
h('span', { style: { color: 'var(--text-muted)' } }, `— ${desc}`),
|
|
728
|
+
),
|
|
729
|
+
),
|
|
730
|
+
),
|
|
731
|
+
),
|
|
732
|
+
),
|
|
733
|
+
);
|
|
734
|
+
|
|
735
|
+
// Tabs switching
|
|
736
|
+
function showTab(id) {
|
|
737
|
+
activeTab = id;
|
|
738
|
+
paneWorkspace.style.display = id === 'workspace' ? '' : 'none';
|
|
739
|
+
paneImport.style.display = id === 'import' ? '' : 'none';
|
|
740
|
+
paneMcp.style.display = id === 'mcp' ? '' : 'none';
|
|
741
|
+
Array.from(tabBar.children).forEach((btn) => {
|
|
742
|
+
btn.classList.toggle('active', btn.dataset.tab === id);
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
[
|
|
747
|
+
['workspace', 'Collections & Environments'],
|
|
748
|
+
['import', 'Import Postman / HAR / .http'],
|
|
749
|
+
['mcp', 'AI Agent MCP Server'],
|
|
750
|
+
].forEach(([id, label]) => {
|
|
751
|
+
tabBar.appendChild(
|
|
752
|
+
h(
|
|
753
|
+
'button',
|
|
754
|
+
{ type: 'button', class: `tab-btn ${activeTab === id ? 'active' : ''}`, 'data-tab': id, onClick: () => showTab(id) },
|
|
755
|
+
label,
|
|
756
|
+
),
|
|
757
|
+
);
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
root.appendChild(h('div', { class: 'stack' }, tabBar, paneWorkspace, paneImport, paneMcp));
|
|
761
|
+
showTab('workspace');
|
|
762
|
+
void refreshWorkspace();
|
|
763
|
+
},
|
|
764
|
+
});
|
|
765
|
+
})();
|