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,49 @@
1
+ export interface OpenApiSchema {
2
+ type?: string;
3
+ format?: string;
4
+ enum?: unknown[];
5
+ required?: string[];
6
+ properties?: Record<string, OpenApiSchema>;
7
+ items?: OpenApiSchema;
8
+ $ref?: string;
9
+ allOf?: OpenApiSchema[];
10
+ nullable?: boolean;
11
+ }
12
+ export type DriftSeverity = 'breaking' | 'warning' | 'info';
13
+ export interface ContractDriftIssue {
14
+ severity: DriftSeverity;
15
+ code: 'ENDPOINT_NOT_FOUND' | 'UNDOCUMENTED_STATUS' | 'MISSING_REQUIRED_FIELD' | 'TYPE_MISMATCH' | 'ENUM_VIOLATION' | 'FORMAT_MISMATCH' | 'UNDOCUMENTED_FIELD' | 'NULLABLE_VIOLATION' | 'INVALID_JSON_BODY';
16
+ path: string;
17
+ expected?: string;
18
+ actual?: string;
19
+ message: string;
20
+ }
21
+ export interface ContractDriftReport {
22
+ matched: boolean;
23
+ compatible: boolean;
24
+ score: number;
25
+ specTitle: string;
26
+ specVersion: string;
27
+ method: string;
28
+ requestPath: string;
29
+ matchedTemplate?: string;
30
+ statusCode: number;
31
+ summary: {
32
+ breaking: number;
33
+ warning: number;
34
+ info: number;
35
+ };
36
+ issues: ContractDriftIssue[];
37
+ }
38
+ export interface ContractCheckInput {
39
+ spec: string;
40
+ method: string;
41
+ path: string;
42
+ status: number;
43
+ body: string;
44
+ }
45
+ /**
46
+ * Compares a live/captured API response against an OpenAPI 3.x / Swagger 2.0 contract
47
+ * and reports breaking changes, undocumented fields, enum/format violations, and a compatibility score.
48
+ */
49
+ export declare function checkOpenApiContractDrift(input: ContractCheckInput): ContractDriftReport;
@@ -0,0 +1,302 @@
1
+ import { parseYaml } from './converters.js';
2
+ import { parseOpenApiSpec } from './openapi.js';
3
+ import { safeJsonParse } from './security.js';
4
+ function normalizePath(p) {
5
+ const clean = p.split('?')[0] ?? '/';
6
+ if (!clean.startsWith('/'))
7
+ return `/${clean}`;
8
+ return clean.length > 1 && clean.endsWith('/') ? clean.slice(0, -1) : clean;
9
+ }
10
+ function matchPathTemplate(template, actualPath) {
11
+ const tSegs = normalizePath(template).split('/').filter(Boolean);
12
+ const aSegs = normalizePath(actualPath).split('/').filter(Boolean);
13
+ if (tSegs.length !== aSegs.length)
14
+ return false;
15
+ for (let i = 0; i < tSegs.length; i++) {
16
+ const t = tSegs[i];
17
+ const a = aSegs[i];
18
+ if ((t.startsWith('{') && t.endsWith('}')) || t.startsWith(':'))
19
+ continue;
20
+ if (t !== a)
21
+ return false;
22
+ }
23
+ return true;
24
+ }
25
+ function findMatchingEndpoint(endpoints, method, reqPath) {
26
+ const upperMethod = method.toUpperCase();
27
+ const norm = normalizePath(reqPath);
28
+ const exact = endpoints.find((e) => e.method === upperMethod && normalizePath(e.openApiPath) === norm);
29
+ if (exact)
30
+ return exact;
31
+ return endpoints.find((e) => e.method === upperMethod && matchPathTemplate(e.openApiPath, norm));
32
+ }
33
+ function getValueType(val) {
34
+ if (val === null)
35
+ return 'null';
36
+ if (Array.isArray(val))
37
+ return 'array';
38
+ if (typeof val === 'number')
39
+ return Number.isInteger(val) ? 'integer' : 'number';
40
+ return typeof val;
41
+ }
42
+ function isValidFormat(format, value) {
43
+ switch (format.toLowerCase()) {
44
+ case 'email':
45
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
46
+ case 'uuid':
47
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
48
+ case 'date-time':
49
+ return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(value) && !Number.isNaN(Date.parse(value));
50
+ case 'date':
51
+ return /^\d{4}-\d{2}-\d{2}$/.test(value);
52
+ case 'uri':
53
+ case 'url':
54
+ return /^https?:\/\/\S+$/i.test(value);
55
+ case 'ipv4':
56
+ return /^(?:\d{1,3}\.){3}\d{1,3}$/.test(value);
57
+ default:
58
+ return true;
59
+ }
60
+ }
61
+ function resolveRefSchema(schema, components, depth = 0) {
62
+ if (!schema || depth > 10)
63
+ return schema;
64
+ if (typeof schema.$ref === 'string') {
65
+ const refName = schema.$ref.split('/').pop() ?? '';
66
+ const target = components[refName];
67
+ if (target)
68
+ return resolveRefSchema(target, components, depth + 1);
69
+ }
70
+ if (Array.isArray(schema.allOf) && schema.allOf.length > 0) {
71
+ const merged = { type: 'object', properties: {}, required: [] };
72
+ for (const part of schema.allOf) {
73
+ const resolved = resolveRefSchema(part, components, depth + 1);
74
+ if (!resolved)
75
+ continue;
76
+ if (resolved.properties) {
77
+ merged.properties = { ...merged.properties, ...resolved.properties };
78
+ }
79
+ if (Array.isArray(resolved.required)) {
80
+ merged.required = [...new Set([...(merged.required ?? []), ...resolved.required])];
81
+ }
82
+ }
83
+ return merged;
84
+ }
85
+ return schema;
86
+ }
87
+ function extractRawResponseSchema(rawSpec, endpoint, status) {
88
+ const componentsObj = rawSpec.components ?? {};
89
+ const schemasMap = componentsObj.schemas ??
90
+ rawSpec.definitions ??
91
+ {};
92
+ const paths = rawSpec.paths ?? {};
93
+ const pathItem = paths[endpoint.openApiPath] ?? {};
94
+ const op = pathItem[endpoint.method.toLowerCase()] ?? {};
95
+ const responses = op.responses ?? {};
96
+ const statusKey = String(status);
97
+ const statusObj = responses[statusKey] ?? responses[`${Math.floor(status / 100)}XX`] ?? responses.default;
98
+ if (!statusObj) {
99
+ return { hasStatusDoc: false, components: schemasMap };
100
+ }
101
+ const content = statusObj.content;
102
+ const jsonContent = content?.['application/json'] ?? (content ? Object.values(content)[0] : undefined);
103
+ const schema = (jsonContent?.schema ?? statusObj.schema);
104
+ return { hasStatusDoc: true, schema, components: schemasMap };
105
+ }
106
+ function validateValueAgainstSchema(value, rawSchema, components, jsonPath, issues, depth = 0) {
107
+ if (!rawSchema || depth > 12)
108
+ return;
109
+ const schema = resolveRefSchema(rawSchema, components, depth);
110
+ if (!schema)
111
+ return;
112
+ const actualType = getValueType(value);
113
+ const nullable = Boolean(schema.nullable);
114
+ if (value === null) {
115
+ if (!nullable && schema.type && schema.type !== 'null') {
116
+ issues.push({
117
+ severity: 'breaking',
118
+ code: 'NULLABLE_VIOLATION',
119
+ path: jsonPath,
120
+ expected: schema.type,
121
+ actual: 'null',
122
+ message: `Field "${jsonPath}" returned null, but OpenAPI schema declares non-nullable "${schema.type}".`,
123
+ });
124
+ }
125
+ return;
126
+ }
127
+ // Type check (integer is compatible with number)
128
+ if (schema.type) {
129
+ const typeMatches = schema.type === actualType ||
130
+ (schema.type === 'number' && actualType === 'integer');
131
+ if (!typeMatches) {
132
+ issues.push({
133
+ severity: 'breaking',
134
+ code: 'TYPE_MISMATCH',
135
+ path: jsonPath,
136
+ expected: schema.type,
137
+ actual: actualType,
138
+ message: `Type mismatch at "${jsonPath}": expected "${schema.type}", got "${actualType}".`,
139
+ });
140
+ return;
141
+ }
142
+ }
143
+ // Enum check
144
+ if (Array.isArray(schema.enum) && schema.enum.length > 0) {
145
+ if (!schema.enum.includes(value)) {
146
+ issues.push({
147
+ severity: 'breaking',
148
+ code: 'ENUM_VIOLATION',
149
+ path: jsonPath,
150
+ expected: schema.enum.map((v) => String(v)).join(' | '),
151
+ actual: String(value),
152
+ message: `Value "${String(value)}" at "${jsonPath}" is not in allowed enum [${schema.enum.join(', ')}].`,
153
+ });
154
+ }
155
+ }
156
+ // Format check for strings
157
+ if (typeof value === 'string' && typeof schema.format === 'string') {
158
+ if (!isValidFormat(schema.format, value)) {
159
+ issues.push({
160
+ severity: 'warning',
161
+ code: 'FORMAT_MISMATCH',
162
+ path: jsonPath,
163
+ expected: `format:${schema.format}`,
164
+ actual: value.slice(0, 60),
165
+ message: `String at "${jsonPath}" does not match declared OpenAPI format "${schema.format}".`,
166
+ });
167
+ }
168
+ }
169
+ // Object properties & required fields
170
+ if (actualType === 'object' && value && typeof value === 'object' && !Array.isArray(value)) {
171
+ const obj = value;
172
+ const requiredFields = Array.isArray(schema.required) ? schema.required : [];
173
+ for (const reqKey of requiredFields) {
174
+ if (!(reqKey in obj)) {
175
+ issues.push({
176
+ severity: 'breaking',
177
+ code: 'MISSING_REQUIRED_FIELD',
178
+ path: `${jsonPath}.${reqKey}`,
179
+ expected: 'required property',
180
+ actual: 'undefined',
181
+ message: `Breaking drift: required field "${jsonPath}.${reqKey}" is missing from response.`,
182
+ });
183
+ }
184
+ }
185
+ const props = schema.properties ?? {};
186
+ for (const [k, v] of Object.entries(obj)) {
187
+ const propSchema = props[k];
188
+ if (!propSchema) {
189
+ if (Object.keys(props).length > 0) {
190
+ issues.push({
191
+ severity: 'warning',
192
+ code: 'UNDOCUMENTED_FIELD',
193
+ path: `${jsonPath}.${k}`,
194
+ expected: 'documented property',
195
+ actual: getValueType(v),
196
+ message: `Undocumented field "${jsonPath}.${k}" returned in response (schema drift).`,
197
+ });
198
+ }
199
+ continue;
200
+ }
201
+ validateValueAgainstSchema(v, propSchema, components, `${jsonPath}.${k}`, issues, depth + 1);
202
+ }
203
+ }
204
+ // Array items (sample up to first 25 items)
205
+ if (Array.isArray(value) && schema.items) {
206
+ const limit = Math.min(value.length, 25);
207
+ for (let i = 0; i < limit; i++) {
208
+ validateValueAgainstSchema(value[i], schema.items, components, `${jsonPath}[${i}]`, issues, depth + 1);
209
+ }
210
+ }
211
+ }
212
+ /**
213
+ * Compares a live/captured API response against an OpenAPI 3.x / Swagger 2.0 contract
214
+ * and reports breaking changes, undocumented fields, enum/format violations, and a compatibility score.
215
+ */
216
+ export function checkOpenApiContractDrift(input) {
217
+ const parsed = parseOpenApiSpec(input.spec);
218
+ const method = input.method.trim().toUpperCase();
219
+ const reqPath = normalizePath(input.path);
220
+ const statusCode = Math.trunc(input.status || 200);
221
+ const issues = [];
222
+ const endpoint = findMatchingEndpoint(parsed.endpoints, method, reqPath);
223
+ if (!endpoint) {
224
+ issues.push({
225
+ severity: 'breaking',
226
+ code: 'ENDPOINT_NOT_FOUND',
227
+ path: `${method} ${reqPath}`,
228
+ message: `Endpoint "${method} ${reqPath}" is not documented in OpenAPI spec "${parsed.title}".`,
229
+ });
230
+ return {
231
+ matched: false,
232
+ compatible: false,
233
+ score: 0,
234
+ specTitle: parsed.title,
235
+ specVersion: parsed.version,
236
+ method,
237
+ requestPath: reqPath,
238
+ statusCode,
239
+ summary: { breaking: 1, warning: 0, info: 0 },
240
+ issues,
241
+ };
242
+ }
243
+ const trimmedSpec = input.spec.trim();
244
+ const rawSpec = (trimmedSpec.startsWith('{') ? safeJsonParse(trimmedSpec) : parseYaml(trimmedSpec));
245
+ const { hasStatusDoc, schema, components } = extractRawResponseSchema(rawSpec, endpoint, statusCode);
246
+ if (!hasStatusDoc) {
247
+ issues.push({
248
+ severity: 'breaking',
249
+ code: 'UNDOCUMENTED_STATUS',
250
+ path: `${method} ${endpoint.openApiPath}`,
251
+ expected: 'documented HTTP status',
252
+ actual: String(statusCode),
253
+ message: `HTTP status ${statusCode} is not documented for "${method} ${endpoint.openApiPath}".`,
254
+ });
255
+ }
256
+ else if (schema) {
257
+ const trimmed = input.body.trim();
258
+ if (!trimmed) {
259
+ issues.push({
260
+ severity: 'breaking',
261
+ code: 'INVALID_JSON_BODY',
262
+ path: '$',
263
+ expected: schema.type ?? 'json',
264
+ actual: 'empty body',
265
+ message: 'Response body is empty, but OpenAPI contract expects a structured payload.',
266
+ });
267
+ }
268
+ else {
269
+ try {
270
+ const jsonBody = safeJsonParse(trimmed);
271
+ validateValueAgainstSchema(jsonBody, schema, components, '$', issues);
272
+ }
273
+ catch (err) {
274
+ issues.push({
275
+ severity: 'breaking',
276
+ code: 'INVALID_JSON_BODY',
277
+ path: '$',
278
+ expected: 'valid JSON',
279
+ actual: err.message,
280
+ message: `Response body is not valid JSON: ${err.message}`,
281
+ });
282
+ }
283
+ }
284
+ }
285
+ const breaking = issues.filter((i) => i.severity === 'breaking').length;
286
+ const warning = issues.filter((i) => i.severity === 'warning').length;
287
+ const info = issues.filter((i) => i.severity === 'info').length;
288
+ const score = Math.max(0, 100 - breaking * 25 - warning * 8);
289
+ return {
290
+ matched: true,
291
+ compatible: breaking === 0,
292
+ score,
293
+ specTitle: parsed.title,
294
+ specVersion: parsed.version,
295
+ method,
296
+ requestPath: reqPath,
297
+ matchedTemplate: endpoint.openApiPath,
298
+ statusCode,
299
+ summary: { breaking, warning, info },
300
+ issues,
301
+ };
302
+ }
@@ -0,0 +1,18 @@
1
+ export type DataFormat = 'json' | 'yaml' | 'toml' | 'csv' | 'query' | 'typescript' | 'jsonschema';
2
+ export declare function parseYaml(input: string): unknown;
3
+ export declare function stringifyYaml(value: unknown, indent?: number): string;
4
+ export declare function parseToml(input: string): Record<string, unknown>;
5
+ export declare function stringifyToml(value: unknown, prefix?: string): string;
6
+ export declare function parseCsv(input: string, delimiter?: string): Record<string, unknown>[];
7
+ export declare function stringifyCsv(value: unknown, delimiter?: string): string;
8
+ export declare function parseQueryString(input: string): Record<string, unknown>;
9
+ export declare function stringifyQueryString(value: unknown): string;
10
+ export declare function generateTypeScriptInterfaces(value: unknown, rootName?: string): string;
11
+ export declare function generateJsonSchema(value: unknown, title?: string): Record<string, unknown>;
12
+ export declare function convertData(input: string, from: Exclude<DataFormat, 'typescript' | 'jsonschema'>, to: DataFormat, options?: {
13
+ indent?: number;
14
+ sortKeys?: boolean;
15
+ minify?: boolean;
16
+ }): string;
17
+ export declare function queryJsonPath(data: unknown, expression: string): unknown[];
18
+ export declare function formatSql(sql: string): string;