devanvil 0.0.0-stage → 2.1.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.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.ar.md +113 -0
  3. package/README.md +272 -2
  4. package/SECURITY.md +49 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +659 -0
  7. package/dist/core/contract-drift.d.ts +49 -0
  8. package/dist/core/contract-drift.js +302 -0
  9. package/dist/core/converters.d.ts +18 -0
  10. package/dist/core/converters.js +981 -0
  11. package/dist/core/cron.d.ts +33 -0
  12. package/dist/core/cron.js +306 -0
  13. package/dist/core/crypto.d.ts +59 -0
  14. package/dist/core/crypto.js +250 -0
  15. package/dist/core/curl.d.ts +17 -0
  16. package/dist/core/curl.js +170 -0
  17. package/dist/core/diff.d.ts +36 -0
  18. package/dist/core/diff.js +148 -0
  19. package/dist/core/encoding.d.ts +3 -0
  20. package/dist/core/encoding.js +143 -0
  21. package/dist/core/importers.d.ts +65 -0
  22. package/dist/core/importers.js +361 -0
  23. package/dist/core/jwt.d.ts +39 -0
  24. package/dist/core/jwt.js +256 -0
  25. package/dist/core/llm-tokens.d.ts +38 -0
  26. package/dist/core/llm-tokens.js +125 -0
  27. package/dist/core/log-analyzer.d.ts +30 -0
  28. package/dist/core/log-analyzer.js +155 -0
  29. package/dist/core/network.d.ts +72 -0
  30. package/dist/core/network.js +185 -0
  31. package/dist/core/oauth-protobuf.d.ts +74 -0
  32. package/dist/core/oauth-protobuf.js +390 -0
  33. package/dist/core/openapi.d.ts +27 -0
  34. package/dist/core/openapi.js +257 -0
  35. package/dist/core/pipeline.d.ts +28 -0
  36. package/dist/core/pipeline.js +154 -0
  37. package/dist/core/regex.d.ts +50 -0
  38. package/dist/core/regex.js +351 -0
  39. package/dist/core/runner.d.ts +53 -0
  40. package/dist/core/runner.js +250 -0
  41. package/dist/core/secrets.d.ts +87 -0
  42. package/dist/core/secrets.js +599 -0
  43. package/dist/core/security.d.ts +34 -0
  44. package/dist/core/security.js +284 -0
  45. package/dist/core/sql-explain.d.ts +50 -0
  46. package/dist/core/sql-explain.js +259 -0
  47. package/dist/core/tls.d.ts +44 -0
  48. package/dist/core/tls.js +166 -0
  49. package/dist/index.d.ts +31 -0
  50. package/dist/index.js +31 -0
  51. package/dist/server/app.d.ts +31 -0
  52. package/dist/server/app.js +348 -0
  53. package/dist/server/http-proxy.d.ts +55 -0
  54. package/dist/server/http-proxy.js +364 -0
  55. package/dist/server/http-utils.d.ts +28 -0
  56. package/dist/server/http-utils.js +106 -0
  57. package/dist/server/load-tester.d.ts +53 -0
  58. package/dist/server/load-tester.js +134 -0
  59. package/dist/server/mcp.d.ts +35 -0
  60. package/dist/server/mcp.js +466 -0
  61. package/dist/server/mock-store.d.ts +38 -0
  62. package/dist/server/mock-store.js +197 -0
  63. package/dist/server/plugin-loader.d.ts +60 -0
  64. package/dist/server/plugin-loader.js +285 -0
  65. package/dist/server/recorder-store.d.ts +35 -0
  66. package/dist/server/recorder-store.js +146 -0
  67. package/dist/server/routes/network-routes.d.ts +3 -0
  68. package/dist/server/routes/network-routes.js +391 -0
  69. package/dist/server/routes/tools-routes.d.ts +3 -0
  70. package/dist/server/routes/tools-routes.js +292 -0
  71. package/dist/server/routes/workspace-routes.d.ts +3 -0
  72. package/dist/server/routes/workspace-routes.js +240 -0
  73. package/dist/server/webhook-store.d.ts +29 -0
  74. package/dist/server/webhook-store.js +90 -0
  75. package/dist/server/workspace-store.d.ts +91 -0
  76. package/dist/server/workspace-store.js +447 -0
  77. package/dist/server/ws-probe.d.ts +34 -0
  78. package/dist/server/ws-probe.js +283 -0
  79. package/dist/ui/app.js +274 -0
  80. package/dist/ui/favicon.svg +14 -0
  81. package/dist/ui/index.html +83 -0
  82. package/dist/ui/logo.png +0 -0
  83. package/dist/ui/styles.css +694 -0
  84. package/dist/ui/tools-data.js +704 -0
  85. package/dist/ui/tools-network.js +727 -0
  86. package/dist/ui/tools-ops.js +295 -0
  87. package/dist/ui/tools-pro.js +500 -0
  88. package/dist/ui/tools-security.js +389 -0
  89. package/dist/ui/tools-v12.js +745 -0
  90. package/dist/ui/tools-v13.js +321 -0
  91. package/dist/ui/tools-v20.js +563 -0
  92. package/dist/ui/tools-v21.js +395 -0
  93. package/package.json +75 -4
@@ -0,0 +1,250 @@
1
+ import { queryJsonPath } from './converters.js';
2
+ import { interpolateRequestWithEnv, } from './importers.js';
3
+ import { safeJsonParse } from './security.js';
4
+ import { executeProxyRequest } from '../server/http-proxy.js';
5
+ function evaluateAssertion(assertion, response) {
6
+ switch (assertion.type) {
7
+ case 'status': {
8
+ const expected = Number(assertion.expected ?? 200);
9
+ const passed = response.status === expected;
10
+ return {
11
+ type: 'status',
12
+ expected,
13
+ actual: response.status,
14
+ passed,
15
+ message: passed
16
+ ? `HTTP status == ${expected}`
17
+ : `Expected HTTP ${expected}, got ${response.status}`,
18
+ };
19
+ }
20
+ case 'maxLatencyMs': {
21
+ const limit = Number(assertion.expected ?? 1000);
22
+ const passed = response.latencyMs <= limit;
23
+ return {
24
+ type: 'maxLatencyMs',
25
+ expected: limit,
26
+ actual: response.latencyMs,
27
+ passed,
28
+ message: passed
29
+ ? `Latency ${response.latencyMs}ms <= ${limit}ms`
30
+ : `Latency ${response.latencyMs}ms exceeded max ${limit}ms`,
31
+ };
32
+ }
33
+ case 'headerContains': {
34
+ const hdrName = (assertion.target ?? '').toLowerCase();
35
+ const needle = String(assertion.expected ?? '');
36
+ const entry = Object.entries(response.headers).find(([k]) => k.toLowerCase() === hdrName);
37
+ const actual = entry?.[1] ?? '';
38
+ const passed = Boolean(hdrName) && actual.toLowerCase().includes(needle.toLowerCase());
39
+ return {
40
+ type: 'headerContains',
41
+ target: assertion.target,
42
+ expected: needle,
43
+ actual,
44
+ passed,
45
+ message: passed
46
+ ? `Header "${assertion.target}" contains "${needle}"`
47
+ : `Header "${assertion.target}" ("${actual}") does not contain "${needle}"`,
48
+ };
49
+ }
50
+ case 'bodyContains': {
51
+ const needle = String(assertion.expected ?? '');
52
+ const passed = response.body.includes(needle);
53
+ return {
54
+ type: 'bodyContains',
55
+ expected: needle,
56
+ passed,
57
+ message: passed
58
+ ? `Response body contains "${needle}"`
59
+ : `Response body missing expected substring "${needle}"`,
60
+ };
61
+ }
62
+ case 'jsonPathEquals': {
63
+ const expr = assertion.target ?? '$';
64
+ try {
65
+ const parsed = safeJsonParse(response.body);
66
+ const matches = queryJsonPath(parsed, expr);
67
+ const actual = matches.length === 1 ? matches[0] : matches;
68
+ const passed = actual === assertion.expected ||
69
+ String(actual) === String(assertion.expected);
70
+ return {
71
+ type: 'jsonPathEquals',
72
+ target: expr,
73
+ expected: assertion.expected,
74
+ actual,
75
+ passed,
76
+ message: passed
77
+ ? `JSONPath ${expr} == ${JSON.stringify(assertion.expected)}`
78
+ : `JSONPath ${expr} expected ${JSON.stringify(assertion.expected)}, got ${JSON.stringify(actual)}`,
79
+ };
80
+ }
81
+ catch (err) {
82
+ return {
83
+ type: 'jsonPathEquals',
84
+ target: expr,
85
+ expected: assertion.expected,
86
+ passed: false,
87
+ message: `JSONPath ${expr} failed: ${err instanceof Error ? err.message : String(err)}`,
88
+ };
89
+ }
90
+ }
91
+ default:
92
+ return {
93
+ type: assertion.type,
94
+ passed: false,
95
+ message: `Unsupported assertion type "${String(assertion.type)}"`,
96
+ };
97
+ }
98
+ }
99
+ /**
100
+ * Executes all requests in a DevAnvil Collection sequentially with active environment &
101
+ * optional `{{env.*}}` interpolation, SSRF protection, and declarative assertions.
102
+ * Zero-dependency alternative to Newman for local & CI API testing.
103
+ */
104
+ export async function runCollection(collection, options = {}) {
105
+ const startedAt = new Date().toISOString();
106
+ const suiteStart = performance.now();
107
+ // Clone variable map so request chaining (`extract`) mutates only this run
108
+ const vars = { ...(options.variables ?? {}) };
109
+ const results = [];
110
+ for (const req of collection.requests) {
111
+ const resolved = interpolateRequestWithEnv({ method: req.method, url: req.url, headers: req.headers, body: req.body }, vars, { processEnv: options.processEnv });
112
+ const reqStart = performance.now();
113
+ try {
114
+ const resp = await executeProxyRequest({
115
+ method: resolved.method,
116
+ url: resolved.url,
117
+ headers: resolved.headers,
118
+ body: resolved.body,
119
+ timeoutMs: options.timeoutMs ?? 10_000,
120
+ }, { allowPrivate: options.allowPrivate });
121
+ const latencyMs = Math.round((performance.now() - reqStart) * 10) / 10;
122
+ // Request Chaining: extract variables from JSONPath or response headers for subsequent requests
123
+ const extracted = {};
124
+ if (Array.isArray(req.extract) && req.extract.length > 0) {
125
+ let parsedBody;
126
+ let bodyParsed = false;
127
+ for (const ext of req.extract) {
128
+ const varName = ext.variable?.trim();
129
+ if (!varName || /^(?:__proto__|constructor|prototype)$/.test(varName))
130
+ continue;
131
+ if (ext.source === 'header') {
132
+ const targetHdr = ext.expression.toLowerCase();
133
+ const hit = Object.entries(resp.headers).find(([k]) => k.toLowerCase() === targetHdr);
134
+ if (hit) {
135
+ vars[varName] = hit[1];
136
+ extracted[varName] = hit[1];
137
+ }
138
+ }
139
+ else if (ext.source === 'jsonPath') {
140
+ try {
141
+ if (!bodyParsed) {
142
+ parsedBody = safeJsonParse(resp.body);
143
+ bodyParsed = true;
144
+ }
145
+ const matches = queryJsonPath(parsedBody, ext.expression);
146
+ if (matches.length > 0 && matches[0] !== undefined && matches[0] !== null) {
147
+ const val = typeof matches[0] === 'string' ? matches[0] : JSON.stringify(matches[0]);
148
+ vars[varName] = val;
149
+ extracted[varName] = val;
150
+ }
151
+ }
152
+ catch {
153
+ // Ignore non-JSON body on extraction
154
+ }
155
+ }
156
+ }
157
+ }
158
+ const assertionsToRun = req.assertions && req.assertions.length > 0
159
+ ? req.assertions
160
+ : [{ type: 'status', expected: resp.status < 400 ? resp.status : 200 }];
161
+ const assertionResults = assertionsToRun.map((a) => evaluateAssertion(a, {
162
+ status: resp.status,
163
+ headers: resp.headers,
164
+ body: resp.body,
165
+ latencyMs,
166
+ }));
167
+ const passed = assertionResults.every((r) => r.passed);
168
+ results.push({
169
+ requestId: req.id,
170
+ name: req.name,
171
+ method: resolved.method,
172
+ resolvedUrl: resolved.url,
173
+ status: resp.status,
174
+ latencyMs,
175
+ passed,
176
+ assertions: assertionResults,
177
+ ...(Object.keys(extracted).length > 0 ? { extracted } : {}),
178
+ });
179
+ if (!passed && options.stopOnFailure)
180
+ break;
181
+ }
182
+ catch (err) {
183
+ const latencyMs = Math.round((performance.now() - reqStart) * 10) / 10;
184
+ results.push({
185
+ requestId: req.id,
186
+ name: req.name,
187
+ method: resolved.method,
188
+ resolvedUrl: resolved.url,
189
+ latencyMs,
190
+ passed: false,
191
+ error: err instanceof Error ? err.message : String(err),
192
+ assertions: [],
193
+ });
194
+ if (options.stopOnFailure)
195
+ break;
196
+ }
197
+ }
198
+ const totalDurationMs = Math.round((performance.now() - suiteStart) * 10) / 10;
199
+ const passedRequests = results.filter((r) => r.passed).length;
200
+ const failedRequests = results.length - passedRequests;
201
+ return {
202
+ collectionName: collection.name,
203
+ environmentName: options.environmentName,
204
+ startedAt,
205
+ totalDurationMs,
206
+ totalRequests: results.length,
207
+ passedRequests,
208
+ failedRequests,
209
+ passed: failedRequests === 0,
210
+ results,
211
+ };
212
+ }
213
+ function xmlEsc(input) {
214
+ return input
215
+ .replace(/&/g, '&amp;')
216
+ .replace(/</g, '&lt;')
217
+ .replace(/>/g, '&gt;')
218
+ .replace(/"/g, '&quot;')
219
+ .replace(/'/g, '&apos;');
220
+ }
221
+ /**
222
+ * Formats a DevAnvil CollectionRunReport into standard JUnit XML for GitHub Actions,
223
+ * GitLab CI, Azure DevOps, and Jenkins test result panels.
224
+ */
225
+ export function formatRunReportAsJunitXml(report) {
226
+ const cases = report.results
227
+ .map((r) => {
228
+ const secs = (r.latencyMs / 1000).toFixed(3);
229
+ const nameAttr = xmlEsc(`${r.method} ${r.name}`);
230
+ const classAttr = xmlEsc(report.collectionName);
231
+ if (r.passed) {
232
+ return ` <testcase classname="${classAttr}" name="${nameAttr}" time="${secs}" />`;
233
+ }
234
+ const failureMsg = r.error ??
235
+ r.assertions
236
+ .filter((a) => !a.passed)
237
+ .map((a) => a.message)
238
+ .join('; ');
239
+ return ` <testcase classname="${classAttr}" name="${nameAttr}" time="${secs}">\n <failure message="${xmlEsc(failureMsg)}" />\n </testcase>`;
240
+ })
241
+ .join('\n');
242
+ return [
243
+ '<?xml version="1.0" encoding="UTF-8"?>',
244
+ `<testsuites tests="${report.totalRequests}" failures="${report.failedRequests}" time="${(report.totalDurationMs / 1000).toFixed(3)}">`,
245
+ ` <testsuite name="${xmlEsc(report.collectionName)}" tests="${report.totalRequests}" failures="${report.failedRequests}" timestamp="${xmlEsc(report.startedAt)}">`,
246
+ cases,
247
+ ' </testsuite>',
248
+ '</testsuites>',
249
+ ].join('\n');
250
+ }
@@ -0,0 +1,87 @@
1
+ export interface SecretRule {
2
+ id: string;
3
+ name: string;
4
+ severity: 'critical' | 'high' | 'medium';
5
+ pattern: string;
6
+ flags?: string;
7
+ }
8
+ export interface SecretFinding {
9
+ ruleId: string;
10
+ name: string;
11
+ severity: 'critical' | 'high' | 'medium';
12
+ line: number;
13
+ column: number;
14
+ start: number;
15
+ end: number;
16
+ masked: string;
17
+ entropy: number;
18
+ }
19
+ export interface SecretScanResult {
20
+ clean: boolean;
21
+ totalFindings: number;
22
+ summary: {
23
+ critical: number;
24
+ high: number;
25
+ medium: number;
26
+ };
27
+ findings: SecretFinding[];
28
+ redactedText: string;
29
+ }
30
+ export declare const SECRET_RULES: SecretRule[];
31
+ export declare function calculateShannonEntropy(value: string): number;
32
+ export declare function scanSecrets(input: string, options?: {
33
+ checkHighEntropy?: boolean;
34
+ entropyThreshold?: number;
35
+ }): SecretScanResult;
36
+ export interface EnvValidationIssue {
37
+ line: number;
38
+ key?: string;
39
+ severity: 'error' | 'warning' | 'info';
40
+ message: string;
41
+ }
42
+ export interface EnvAnalysisResult {
43
+ keys: string[];
44
+ valuesCount: number;
45
+ issues: EnvValidationIssue[];
46
+ missingFromTarget: string[];
47
+ extraInTarget: string[];
48
+ secretFindingsCount: number;
49
+ }
50
+ export declare function analyzeEnvFile(envContent: string, exampleContent?: string): EnvAnalysisResult;
51
+ export interface DirectorySecretFinding extends SecretFinding {
52
+ file: string;
53
+ }
54
+ export interface DirectoryScanResult {
55
+ rootDir: string;
56
+ scannedFiles: number;
57
+ skippedFiles: number;
58
+ clean: boolean;
59
+ totalFindings: number;
60
+ summary: {
61
+ critical: number;
62
+ high: number;
63
+ medium: number;
64
+ };
65
+ findings: DirectorySecretFinding[];
66
+ }
67
+ export declare function scanDirectory(targetDir: string, options?: {
68
+ maxFiles?: number;
69
+ maxFileBytes?: number;
70
+ checkHighEntropy?: boolean;
71
+ respectGitignore?: boolean;
72
+ }): DirectoryScanResult;
73
+ /**
74
+ * Scans ONLY files currently staged in the Git index (`git diff --cached`),
75
+ * reading each staged blob directly via `git show :<file>` so unstaged working-tree edits
76
+ * never cause false alarms in pre-commit hooks. Honors `.devanvilignore` and inline `devanvil-ignore`.
77
+ */
78
+ export declare function scanGitStaged(targetDir?: string, options?: {
79
+ maxFileBytes?: number;
80
+ checkHighEntropy?: boolean;
81
+ }): DirectoryScanResult;
82
+ /**
83
+ * Formats directory or single-file secret scan findings into valid SARIF 2.1.0 JSON
84
+ * for direct upload to GitHub Code Scanning (`github/codeql-action/upload-sarif`).
85
+ * Raw secrets are NEVER written into SARIF — only masked fingerprints.
86
+ */
87
+ export declare function formatSecretsAsSarif(findings: DirectorySecretFinding[], toolVersion?: string): Record<string, unknown>;