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,170 @@
1
+ function tokenizeShellArgs(command) {
2
+ const tokens = [];
3
+ let current = '';
4
+ let inSingle = false;
5
+ let inDouble = false;
6
+ const normalized = command.replace(/\\\r?\n/g, ' ').trim();
7
+ for (let i = 0; i < normalized.length; i++) {
8
+ const ch = normalized[i];
9
+ if (inSingle) {
10
+ if (ch === "'")
11
+ inSingle = false;
12
+ else
13
+ current += ch;
14
+ }
15
+ else if (inDouble) {
16
+ if (ch === '"')
17
+ inDouble = false;
18
+ else if (ch === '\\' && i + 1 < normalized.length) {
19
+ current += normalized[i + 1];
20
+ i++;
21
+ }
22
+ else {
23
+ current += ch;
24
+ }
25
+ }
26
+ else {
27
+ if (ch === "'")
28
+ inSingle = true;
29
+ else if (ch === '"')
30
+ inDouble = true;
31
+ else if (ch === '\\' && i + 1 < normalized.length) {
32
+ current += normalized[i + 1];
33
+ i++;
34
+ }
35
+ else if (/\s/.test(ch)) {
36
+ if (current) {
37
+ tokens.push(current);
38
+ current = '';
39
+ }
40
+ }
41
+ else {
42
+ current += ch;
43
+ }
44
+ }
45
+ }
46
+ if (current)
47
+ tokens.push(current);
48
+ return tokens;
49
+ }
50
+ /**
51
+ * Parses a pasted cURL command into structured HTTP request parameters.
52
+ */
53
+ export function parseCurlCommand(curlCmd) {
54
+ const args = tokenizeShellArgs(curlCmd);
55
+ if (args.length === 0)
56
+ throw new Error('Empty cURL command');
57
+ let i = args[0] === 'curl' ? 1 : 0;
58
+ let method = '';
59
+ let url = '';
60
+ const headers = {};
61
+ const bodyParts = [];
62
+ while (i < args.length) {
63
+ const arg = args[i];
64
+ if (arg === '-X' || arg === '--request') {
65
+ method = (args[++i] ?? 'GET').toUpperCase();
66
+ }
67
+ else if (arg === '-H' || arg === '--header') {
68
+ const hdr = args[++i] ?? '';
69
+ const idx = hdr.indexOf(':');
70
+ if (idx > 0) {
71
+ headers[hdr.slice(0, idx).trim()] = hdr.slice(idx + 1).trim();
72
+ }
73
+ }
74
+ else if (arg === '-d' || arg === '--data' || arg === '--data-raw' || arg === '--data-binary') {
75
+ bodyParts.push(args[++i] ?? '');
76
+ }
77
+ else if (arg === '-u' || arg === '--user') {
78
+ const creds = args[++i] ?? '';
79
+ headers['Authorization'] = `Basic ${Buffer.from(creds, 'utf8').toString('base64')}`;
80
+ }
81
+ else if (arg === '-A' || arg === '--user-agent') {
82
+ headers['User-Agent'] = args[++i] ?? '';
83
+ }
84
+ else if (arg === '--url') {
85
+ url = args[++i] ?? '';
86
+ }
87
+ else if (!arg.startsWith('-') && !url && /^https?:\/\//i.test(arg)) {
88
+ url = arg;
89
+ }
90
+ else if (!arg.startsWith('-') && !url) {
91
+ url = arg;
92
+ }
93
+ i++;
94
+ }
95
+ if (!url)
96
+ throw new Error('Could not find URL in cURL command');
97
+ const body = bodyParts.join('&');
98
+ if (!method)
99
+ method = body ? 'POST' : 'GET';
100
+ return { method, url, headers, body };
101
+ }
102
+ function escapeSingleQuote(s) {
103
+ return s.replace(/'/g, `'\\''`);
104
+ }
105
+ export function generateCodeSnippets(req) {
106
+ const method = (req.method || 'GET').toUpperCase();
107
+ const url = req.url.trim();
108
+ const headers = req.headers ?? {};
109
+ const body = req.body ?? '';
110
+ const headerEntries = Object.entries(headers).filter(([k]) => k.trim().length > 0);
111
+ // cURL
112
+ const curlLines = [`curl -X ${method} '${escapeSingleQuote(url)}'`];
113
+ for (const [k, v] of headerEntries) {
114
+ curlLines.push(` -H '${escapeSingleQuote(`${k}: ${v}`)}'`);
115
+ }
116
+ if (body && method !== 'GET' && method !== 'HEAD') {
117
+ curlLines.push(` --data-raw '${escapeSingleQuote(body)}'`);
118
+ }
119
+ const curl = curlLines.join(' \\\n');
120
+ // JavaScript fetch
121
+ const fetchOpts = { method };
122
+ if (headerEntries.length > 0)
123
+ fetchOpts.headers = Object.fromEntries(headerEntries);
124
+ if (body && method !== 'GET' && method !== 'HEAD')
125
+ fetchOpts.body = body;
126
+ const fetchSnippet = `const response = await fetch(${JSON.stringify(url)}, ${JSON.stringify(fetchOpts, null, 2)});\nconst data = await response.text();\nconsole.log(response.status, data);`;
127
+ // Python requests
128
+ const pyLines = ['import requests', ''];
129
+ pyLines.push(`url = ${JSON.stringify(url)}`);
130
+ if (headerEntries.length > 0) {
131
+ pyLines.push(`headers = ${JSON.stringify(Object.fromEntries(headerEntries), null, 2)}`);
132
+ }
133
+ if (body && method !== 'GET' && method !== 'HEAD') {
134
+ pyLines.push(`payload = ${JSON.stringify(body)}`);
135
+ }
136
+ const pyArgs = ['url'];
137
+ if (headerEntries.length > 0)
138
+ pyArgs.push('headers=headers');
139
+ if (body && method !== 'GET' && method !== 'HEAD')
140
+ pyArgs.push('data=payload');
141
+ pyArgs.push('timeout=15');
142
+ pyLines.push(`resp = requests.request(${JSON.stringify(method)}, ${pyArgs.join(', ')})`);
143
+ pyLines.push('print(resp.status_code, resp.text)');
144
+ const python = pyLines.join('\n');
145
+ // Go net/http
146
+ const goHasBody = Boolean(body && method !== 'GET' && method !== 'HEAD');
147
+ const goLines = [
148
+ 'package main',
149
+ '',
150
+ 'import (',
151
+ '\t"fmt"',
152
+ '\t"io"',
153
+ '\t"net/http"',
154
+ ...(goHasBody ? ['\t"strings"'] : []),
155
+ ')',
156
+ '',
157
+ 'func main() {',
158
+ goHasBody
159
+ ? `\treq, _ := http.NewRequest(${JSON.stringify(method)}, ${JSON.stringify(url)}, strings.NewReader(${JSON.stringify(body)}))`
160
+ : `\treq, _ := http.NewRequest(${JSON.stringify(method)}, ${JSON.stringify(url)}, nil)`,
161
+ ...headerEntries.map(([k, v]) => `\treq.Header.Set(${JSON.stringify(k)}, ${JSON.stringify(v)})`),
162
+ '\tresp, err := http.DefaultClient.Do(req)',
163
+ '\tif err != nil { panic(err) }',
164
+ '\tdefer resp.Body.Close()',
165
+ '\tdata, _ := io.ReadAll(resp.Body)',
166
+ '\tfmt.Println(resp.StatusCode, string(data))',
167
+ '}',
168
+ ];
169
+ return { curl, fetch: fetchSnippet, python, go: goLines.join('\n') };
170
+ }
@@ -0,0 +1,36 @@
1
+ export interface DiffLine {
2
+ type: 'equal' | 'add' | 'remove';
3
+ leftLine?: number;
4
+ rightLine?: number;
5
+ text: string;
6
+ }
7
+ export interface TextDiffResult {
8
+ lines: DiffLine[];
9
+ stats: {
10
+ added: number;
11
+ removed: number;
12
+ unchanged: number;
13
+ };
14
+ unified: string;
15
+ }
16
+ /**
17
+ * Computes an exact line-by-line LCS diff with common prefix/suffix trimming
18
+ * for sub-millisecond performance on large files with localized edits.
19
+ */
20
+ export declare function diffText(left: string, right: string): TextDiffResult;
21
+ export interface SemanticChange {
22
+ path: string;
23
+ kind: 'added' | 'removed' | 'changed' | 'type_changed';
24
+ before?: unknown;
25
+ after?: unknown;
26
+ }
27
+ export interface SemanticJsonDiffResult {
28
+ equal: boolean;
29
+ changes: SemanticChange[];
30
+ summary: {
31
+ added: number;
32
+ removed: number;
33
+ changed: number;
34
+ };
35
+ }
36
+ export declare function diffJsonSemantic(leftJson: string, rightJson: string): SemanticJsonDiffResult;
@@ -0,0 +1,148 @@
1
+ import { safeJsonParse } from './security.js';
2
+ /**
3
+ * Computes an exact line-by-line LCS diff with common prefix/suffix trimming
4
+ * for sub-millisecond performance on large files with localized edits.
5
+ */
6
+ export function diffText(left, right) {
7
+ const aAll = left.replace(/\r\n/g, '\n').split('\n');
8
+ const bAll = right.replace(/\r\n/g, '\n').split('\n');
9
+ // Trim identical prefix and suffix lines before running O(m*n) LCS DP
10
+ let prefixLen = 0;
11
+ const minLen = Math.min(aAll.length, bAll.length);
12
+ while (prefixLen < minLen && aAll[prefixLen] === bAll[prefixLen]) {
13
+ prefixLen++;
14
+ }
15
+ let suffixLen = 0;
16
+ while (suffixLen < minLen - prefixLen &&
17
+ aAll[aAll.length - 1 - suffixLen] === bAll[bAll.length - 1 - suffixLen]) {
18
+ suffixLen++;
19
+ }
20
+ const a = aAll.slice(prefixLen, aAll.length - suffixLen);
21
+ const b = bAll.slice(prefixLen, bAll.length - suffixLen);
22
+ const m = a.length;
23
+ const n = b.length;
24
+ // Guard DP matrix memory for extreme divergent diffs
25
+ if (m * n > 6_250_000) {
26
+ throw new Error('Diff changed-window too large for exact LCS (exceeds 2,500 x 2,500 changed lines)');
27
+ }
28
+ const lines = [];
29
+ let added = 0;
30
+ let removed = 0;
31
+ let unchanged = 0;
32
+ for (let p = 0; p < prefixLen; p++) {
33
+ lines.push({ type: 'equal', leftLine: p + 1, rightLine: p + 1, text: aAll[p] });
34
+ unchanged++;
35
+ }
36
+ if (m > 0 || n > 0) {
37
+ const dp = Array.from({ length: m + 1 }, () => new Int32Array(n + 1));
38
+ for (let i = m - 1; i >= 0; i--) {
39
+ for (let j = n - 1; j >= 0; j--) {
40
+ if (a[i] === b[j]) {
41
+ dp[i][j] = dp[i + 1][j + 1] + 1;
42
+ }
43
+ else {
44
+ dp[i][j] = Math.max(dp[i + 1][j], dp[i][j + 1]);
45
+ }
46
+ }
47
+ }
48
+ let i = 0;
49
+ let j = 0;
50
+ while (i < m && j < n) {
51
+ if (a[i] === b[j]) {
52
+ lines.push({ type: 'equal', leftLine: prefixLen + i + 1, rightLine: prefixLen + j + 1, text: a[i] });
53
+ unchanged++;
54
+ i++;
55
+ j++;
56
+ }
57
+ else if (dp[i + 1][j] >= dp[i][j + 1]) {
58
+ lines.push({ type: 'remove', leftLine: prefixLen + i + 1, text: a[i] });
59
+ removed++;
60
+ i++;
61
+ }
62
+ else {
63
+ lines.push({ type: 'add', rightLine: prefixLen + j + 1, text: b[j] });
64
+ added++;
65
+ j++;
66
+ }
67
+ }
68
+ while (i < m) {
69
+ lines.push({ type: 'remove', leftLine: prefixLen + i + 1, text: a[i] });
70
+ removed++;
71
+ i++;
72
+ }
73
+ while (j < n) {
74
+ lines.push({ type: 'add', rightLine: prefixLen + j + 1, text: b[j] });
75
+ added++;
76
+ j++;
77
+ }
78
+ }
79
+ for (let s = 0; s < suffixLen; s++) {
80
+ const li = aAll.length - suffixLen + s;
81
+ const ri = bAll.length - suffixLen + s;
82
+ lines.push({ type: 'equal', leftLine: li + 1, rightLine: ri + 1, text: aAll[li] });
83
+ unchanged++;
84
+ }
85
+ const unified = lines
86
+ .map((l) => (l.type === 'add' ? `+ ${l.text}` : l.type === 'remove' ? `- ${l.text}` : ` ${l.text}`))
87
+ .join('\n');
88
+ return { lines, stats: { added, removed, unchanged }, unified };
89
+ }
90
+ function compareJsonValues(a, b, path, changes) {
91
+ if (Object.is(a, b))
92
+ return;
93
+ const typeA = a === null ? 'null' : Array.isArray(a) ? 'array' : typeof a;
94
+ const typeB = b === null ? 'null' : Array.isArray(b) ? 'array' : typeof b;
95
+ if (typeA !== typeB) {
96
+ changes.push({ path, kind: 'type_changed', before: a, after: b });
97
+ return;
98
+ }
99
+ if (typeA === 'array') {
100
+ const arrA = a;
101
+ const arrB = b;
102
+ const maxLen = Math.max(arrA.length, arrB.length);
103
+ for (let i = 0; i < maxLen; i++) {
104
+ const elemPath = `${path}[${i}]`;
105
+ if (i >= arrA.length) {
106
+ changes.push({ path: elemPath, kind: 'added', after: arrB[i] });
107
+ }
108
+ else if (i >= arrB.length) {
109
+ changes.push({ path: elemPath, kind: 'removed', before: arrA[i] });
110
+ }
111
+ else {
112
+ compareJsonValues(arrA[i], arrB[i], elemPath, changes);
113
+ }
114
+ }
115
+ return;
116
+ }
117
+ if (typeA === 'object') {
118
+ const objA = a;
119
+ const objB = b;
120
+ const allKeys = Array.from(new Set([...Object.keys(objA), ...Object.keys(objB)])).sort();
121
+ for (const key of allKeys) {
122
+ const propPath = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`;
123
+ if (!(key in objA)) {
124
+ changes.push({ path: propPath, kind: 'added', after: objB[key] });
125
+ }
126
+ else if (!(key in objB)) {
127
+ changes.push({ path: propPath, kind: 'removed', before: objA[key] });
128
+ }
129
+ else {
130
+ compareJsonValues(objA[key], objB[key], propPath, changes);
131
+ }
132
+ }
133
+ return;
134
+ }
135
+ changes.push({ path, kind: 'changed', before: a, after: b });
136
+ }
137
+ export function diffJsonSemantic(leftJson, rightJson) {
138
+ const left = safeJsonParse(leftJson);
139
+ const right = safeJsonParse(rightJson);
140
+ const changes = [];
141
+ compareJsonValues(left, right, '$', changes);
142
+ const summary = {
143
+ added: changes.filter((c) => c.kind === 'added').length,
144
+ removed: changes.filter((c) => c.kind === 'removed').length,
145
+ changed: changes.filter((c) => c.kind === 'changed' || c.kind === 'type_changed').length,
146
+ };
147
+ return { equal: changes.length === 0, changes, summary };
148
+ }
@@ -0,0 +1,3 @@
1
+ export type EncodingCodec = 'base64' | 'base64url' | 'hex' | 'url' | 'html' | 'unicode' | 'gzip-base64' | 'deflate-base64' | 'binary' | 'rot13';
2
+ export declare function encodeText(input: string, codec: EncodingCodec): string;
3
+ export declare function decodeText(input: string, codec: EncodingCodec, maxOutputBytes?: number): string;
@@ -0,0 +1,143 @@
1
+ import { deflateSync, gunzipSync, gzipSync, inflateSync } from 'node:zlib';
2
+ import { DEFAULT_MAX_DECOMPRESS_BYTES } from './security.js';
3
+ const HTML_ENCODE_MAP = {
4
+ '&': '&amp;',
5
+ '<': '&lt;',
6
+ '>': '&gt;',
7
+ '"': '&quot;',
8
+ "'": '&#39;',
9
+ };
10
+ const HTML_NAMED_DECODE = {
11
+ amp: '&',
12
+ lt: '<',
13
+ gt: '>',
14
+ quot: '"',
15
+ apos: "'",
16
+ nbsp: '\u00a0',
17
+ copy: '\u00a9',
18
+ reg: '\u00ae',
19
+ mdash: '\u2014',
20
+ ndash: '\u2013',
21
+ hellip: '\u2026',
22
+ };
23
+ function rot13(input) {
24
+ return input.replace(/[a-zA-Z]/g, (ch) => {
25
+ const base = ch <= 'Z' ? 65 : 97;
26
+ return String.fromCharCode(((ch.charCodeAt(0) - base + 13) % 26) + base);
27
+ });
28
+ }
29
+ export function encodeText(input, codec) {
30
+ switch (codec) {
31
+ case 'base64':
32
+ return Buffer.from(input, 'utf8').toString('base64');
33
+ case 'base64url':
34
+ return Buffer.from(input, 'utf8').toString('base64url');
35
+ case 'hex':
36
+ return Buffer.from(input, 'utf8').toString('hex');
37
+ case 'url':
38
+ return encodeURIComponent(input);
39
+ case 'html':
40
+ return input.replace(/[&<>"']/g, (ch) => HTML_ENCODE_MAP[ch] ?? ch);
41
+ case 'unicode': {
42
+ let out = '';
43
+ for (const ch of input) {
44
+ const cp = ch.codePointAt(0);
45
+ if (cp <= 0xffff) {
46
+ out += `\\u${cp.toString(16).padStart(4, '0')}`;
47
+ }
48
+ else {
49
+ out += `\\u{${cp.toString(16)}}`;
50
+ }
51
+ }
52
+ return out;
53
+ }
54
+ case 'gzip-base64':
55
+ return gzipSync(Buffer.from(input, 'utf8')).toString('base64');
56
+ case 'deflate-base64':
57
+ return deflateSync(Buffer.from(input, 'utf8')).toString('base64');
58
+ case 'binary':
59
+ return Array.from(Buffer.from(input, 'utf8'))
60
+ .map((b) => b.toString(2).padStart(8, '0'))
61
+ .join(' ');
62
+ case 'rot13':
63
+ return rot13(input);
64
+ default:
65
+ throw new Error(`Unsupported encoding codec: ${String(codec)}`);
66
+ }
67
+ }
68
+ export function decodeText(input, codec, maxOutputBytes = DEFAULT_MAX_DECOMPRESS_BYTES) {
69
+ switch (codec) {
70
+ case 'base64': {
71
+ const cleaned = input.replace(/\s+/g, '');
72
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(cleaned) || cleaned.length % 4 === 1) {
73
+ throw new Error('Invalid Base64 input');
74
+ }
75
+ return Buffer.from(cleaned, 'base64').toString('utf8');
76
+ }
77
+ case 'base64url': {
78
+ const cleaned = input.replace(/\s+/g, '');
79
+ if (!/^[A-Za-z0-9_-]*={0,2}$/.test(cleaned)) {
80
+ throw new Error('Invalid Base64URL input');
81
+ }
82
+ return Buffer.from(cleaned, 'base64url').toString('utf8');
83
+ }
84
+ case 'hex': {
85
+ const cleaned = input.replace(/[\s:,-]+/g, '').replace(/^0x/i, '');
86
+ if (cleaned.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(cleaned)) {
87
+ throw new Error('Invalid hexadecimal string');
88
+ }
89
+ return Buffer.from(cleaned, 'hex').toString('utf8');
90
+ }
91
+ case 'url':
92
+ try {
93
+ return decodeURIComponent(input.replace(/\+/g, '%20'));
94
+ }
95
+ catch {
96
+ throw new Error('Malformed percent-encoded URL string');
97
+ }
98
+ case 'html':
99
+ return input.replace(/&(#x[0-9a-fA-F]+|#\d+|[a-zA-Z]+);/g, (match, entity) => {
100
+ if (entity.startsWith('#x') || entity.startsWith('#X')) {
101
+ const code = parseInt(entity.slice(2), 16);
102
+ return Number.isFinite(code) && code <= 0x10ffff ? String.fromCodePoint(code) : match;
103
+ }
104
+ if (entity.startsWith('#')) {
105
+ const code = parseInt(entity.slice(1), 10);
106
+ return Number.isFinite(code) && code <= 0x10ffff ? String.fromCodePoint(code) : match;
107
+ }
108
+ return HTML_NAMED_DECODE[entity] ?? match;
109
+ });
110
+ case 'unicode':
111
+ return input.replace(/\\u\{([0-9a-fA-F]+)\}|\\u([0-9a-fA-F]{4})/g, (match, braced, fixed) => {
112
+ const hex = braced || fixed;
113
+ const cp = parseInt(hex, 16);
114
+ return Number.isFinite(cp) && cp <= 0x10ffff ? String.fromCodePoint(cp) : match;
115
+ });
116
+ case 'gzip-base64': {
117
+ const buf = Buffer.from(input.replace(/\s+/g, ''), 'base64');
118
+ // Guard against zip-bomb payloads using maxOutputLength
119
+ const out = gunzipSync(buf, { maxOutputLength: maxOutputBytes });
120
+ return out.toString('utf8');
121
+ }
122
+ case 'deflate-base64': {
123
+ const buf = Buffer.from(input.replace(/\s+/g, ''), 'base64');
124
+ const out = inflateSync(buf, { maxOutputLength: maxOutputBytes });
125
+ return out.toString('utf8');
126
+ }
127
+ case 'binary': {
128
+ const tokens = input.trim().split(/\s+/).filter(Boolean);
129
+ const bytes = [];
130
+ for (const tok of tokens) {
131
+ if (!/^[01]{1,8}$/.test(tok)) {
132
+ throw new Error(`Invalid binary byte token: "${tok}"`);
133
+ }
134
+ bytes.push(parseInt(tok, 2));
135
+ }
136
+ return Buffer.from(bytes).toString('utf8');
137
+ }
138
+ case 'rot13':
139
+ return rot13(input);
140
+ default:
141
+ throw new Error(`Unsupported decoding codec: ${String(codec)}`);
142
+ }
143
+ }
@@ -0,0 +1,65 @@
1
+ import type { MockRouteInput } from '../server/mock-store.js';
2
+ export interface RequestAssertion {
3
+ type: 'status' | 'maxLatencyMs' | 'headerContains' | 'bodyContains' | 'jsonPathEquals';
4
+ expected?: string | number | boolean;
5
+ target?: string;
6
+ }
7
+ export interface RequestExtraction {
8
+ variable: string;
9
+ source: 'jsonPath' | 'header';
10
+ expression: string;
11
+ }
12
+ export interface SavedApiRequest {
13
+ id: string;
14
+ name: string;
15
+ folder?: string;
16
+ method: string;
17
+ url: string;
18
+ headers: Record<string, string>;
19
+ body?: string;
20
+ notes?: string;
21
+ assertions?: RequestAssertion[];
22
+ extract?: RequestExtraction[];
23
+ }
24
+ export interface ImportCollectionResult {
25
+ format: 'postman-v2.1' | 'har-1.2' | 'http-file';
26
+ collectionName: string;
27
+ requests: SavedApiRequest[];
28
+ mockRoutes: MockRouteInput[];
29
+ warnings: string[];
30
+ }
31
+ /**
32
+ * Resolves `{{VAR_NAME}}` and `{{env.SYSTEM_VAR}}` placeholders across request URL, headers,
33
+ * and body. System `{{env.*}}` variables are only resolved when `options.processEnv` is provided
34
+ * so secrets never need to be stored in plaintext inside `devanvil.json`.
35
+ */
36
+ export declare function interpolateEnvString(input: string, variables: Record<string, string>, options?: {
37
+ processEnv?: Record<string, string | undefined>;
38
+ }): string;
39
+ export declare function interpolateRequestWithEnv(req: {
40
+ method: string;
41
+ url: string;
42
+ headers?: Record<string, string>;
43
+ body?: string;
44
+ }, variables: Record<string, string>, options?: {
45
+ processEnv?: Record<string, string | undefined>;
46
+ }): {
47
+ method: string;
48
+ url: string;
49
+ headers: Record<string, string>;
50
+ body: string;
51
+ };
52
+ /**
53
+ * Parses a Postman v2.0 / v2.1 Collection JSON into DevAnvil requests and optional Mock routes
54
+ * (from saved Postman example responses).
55
+ */
56
+ export declare function importPostmanCollection(rawJson: string): ImportCollectionResult;
57
+ /**
58
+ * Parses a browser DevTools HAR 1.2 archive into replayable DevAnvil API requests
59
+ * AND instant offline Mock routes capturing real status codes and JSON/text responses!
60
+ */
61
+ export declare function importHarArchive(rawJson: string): ImportCollectionResult;
62
+ /**
63
+ * Parses standard `.http` / `.rest` files (VS Code REST Client / JetBrains HTTP Client).
64
+ */
65
+ export declare function importHttpFile(rawText: string): ImportCollectionResult;