milieu-cli 0.3.2 → 0.4.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.
- package/README.md +177 -76
- package/dist/bridges/context/agents-json.d.ts +0 -1
- package/dist/bridges/context/agents-json.js +21 -12
- package/dist/bridges/context/auth-clarity.d.ts +0 -1
- package/dist/bridges/context/auth-clarity.js +11 -9
- package/dist/bridges/context/auth-legibility.d.ts +2 -2
- package/dist/bridges/context/auth-legibility.js +67 -60
- package/dist/bridges/context/index.d.ts +1 -2
- package/dist/bridges/context/index.js +19 -40
- package/dist/bridges/context/oauth-metadata.d.ts +14 -0
- package/dist/bridges/context/oauth-metadata.js +127 -0
- package/dist/bridges/context/probe.d.ts +33 -0
- package/dist/bridges/context/probe.js +157 -0
- package/dist/bridges/context/rate-limits.d.ts +5 -2
- package/dist/bridges/context/rate-limits.js +27 -51
- package/dist/bridges/context/tos-contact.d.ts +13 -4
- package/dist/bridges/context/tos-contact.js +108 -46
- package/dist/bridges/context/versioning.d.ts +1 -2
- package/dist/bridges/context/versioning.js +42 -7
- package/dist/bridges/index.d.ts +0 -1
- package/dist/bridges/index.js +0 -1
- package/dist/bridges/reachability/crawler-policy.d.ts +30 -10
- package/dist/bridges/reachability/crawler-policy.js +41 -56
- package/dist/bridges/reachability/http-status.d.ts +3 -2
- package/dist/bridges/reachability/http-status.js +18 -3
- package/dist/bridges/reachability/https-check.d.ts +2 -2
- package/dist/bridges/reachability/https-check.js +6 -3
- package/dist/bridges/reachability/index.d.ts +1 -2
- package/dist/bridges/reachability/index.js +34 -43
- package/dist/bridges/reachability/meta-robots.d.ts +0 -13
- package/dist/bridges/reachability/meta-robots.js +89 -101
- package/dist/bridges/reachability/robots-parser.d.ts +7 -7
- package/dist/bridges/reachability/robots-parser.js +65 -15
- package/dist/bridges/reachability/robots-txt.d.ts +4 -2
- package/dist/bridges/reachability/robots-txt.js +33 -60
- package/dist/bridges/schema/descriptions.d.ts +2 -2
- package/dist/bridges/schema/descriptions.js +79 -44
- package/dist/bridges/schema/error-schemas.d.ts +2 -2
- package/dist/bridges/schema/error-schemas.js +31 -18
- package/dist/bridges/schema/index.d.ts +2 -2
- package/dist/bridges/schema/index.js +48 -30
- package/dist/bridges/schema/oas-types.d.ts +65 -26
- package/dist/bridges/schema/oas-types.js +37 -7
- package/dist/bridges/schema/operation-ids.d.ts +2 -2
- package/dist/bridges/schema/operation-ids.js +2 -3
- package/dist/bridges/schema/required-fields.d.ts +2 -2
- package/dist/bridges/schema/required-fields.js +12 -10
- package/dist/bridges/schema/schema-sources.d.ts +19 -0
- package/dist/bridges/schema/schema-sources.js +182 -0
- package/dist/bridges/schema/schema-types.d.ts +2 -2
- package/dist/bridges/schema/schema-types.js +20 -21
- package/dist/bridges/separation/api-presence.d.ts +3 -15
- package/dist/bridges/separation/api-presence.js +34 -85
- package/dist/bridges/separation/developer-docs.d.ts +6 -18
- package/dist/bridges/separation/developer-docs.js +100 -99
- package/dist/bridges/separation/docs-discovery.d.ts +28 -0
- package/dist/bridges/separation/docs-discovery.js +95 -0
- package/dist/bridges/separation/evidence-summary.d.ts +2 -0
- package/dist/bridges/separation/evidence-summary.js +67 -0
- package/dist/bridges/separation/index.d.ts +2 -19
- package/dist/bridges/separation/index.js +35 -39
- package/dist/bridges/separation/published-routes.d.ts +69 -0
- package/dist/bridges/separation/published-routes.js +271 -0
- package/dist/bridges/separation/sdk-references.d.ts +8 -3
- package/dist/bridges/separation/sdk-references.js +86 -61
- package/dist/bridges/separation/webhook-support.d.ts +3 -23
- package/dist/bridges/separation/webhook-support.js +61 -162
- package/dist/bridges/standards/a2a-agent-card.d.ts +0 -1
- package/dist/bridges/standards/a2a-agent-card.js +24 -9
- package/dist/bridges/standards/graphql.d.ts +3 -4
- package/dist/bridges/standards/graphql.js +70 -66
- package/dist/bridges/standards/index.d.ts +1 -2
- package/dist/bridges/standards/index.js +57 -47
- package/dist/bridges/standards/json-ld.d.ts +25 -11
- package/dist/bridges/standards/json-ld.js +114 -56
- package/dist/bridges/standards/llms-txt.d.ts +4 -2
- package/dist/bridges/standards/llms-txt.js +46 -32
- package/dist/bridges/standards/markdown-negotiation.d.ts +4 -1
- package/dist/bridges/standards/markdown-negotiation.js +16 -11
- package/dist/bridges/standards/mcp.d.ts +3 -12
- package/dist/bridges/standards/mcp.js +89 -132
- package/dist/bridges/standards/openapi.d.ts +7 -15
- package/dist/bridges/standards/openapi.js +657 -207
- package/dist/bridges/standards/probe-evidence.d.ts +30 -0
- package/dist/bridges/standards/probe-evidence.js +90 -0
- package/dist/bridges/standards/schema-org.d.ts +15 -9
- package/dist/bridges/standards/schema-org.js +38 -64
- package/dist/bridges/standards/sitemap.d.ts +2 -3
- package/dist/bridges/standards/sitemap.js +161 -169
- package/dist/bridges/standards/well-known.d.ts +3 -7
- package/dist/bridges/standards/well-known.js +28 -12
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +107 -22
- package/dist/cli/journey-commands.d.ts +3 -0
- package/dist/cli/journey-commands.js +35 -0
- package/dist/cli/read-report.d.ts +2 -0
- package/dist/cli/read-report.js +11 -0
- package/dist/core/bridge-output.d.ts +11 -0
- package/dist/core/bridge-output.js +86 -0
- package/dist/core/bridge-session.d.ts +28 -0
- package/dist/core/bridge-session.js +58 -0
- package/dist/core/bridge-worker.d.ts +1 -0
- package/dist/core/bridge-worker.js +66 -0
- package/dist/core/diff.d.ts +79 -0
- package/dist/core/diff.js +499 -0
- package/dist/core/explanations.d.ts +1 -3
- package/dist/core/explanations.js +36 -59
- package/dist/core/index.d.ts +4 -2
- package/dist/core/index.js +2 -3
- package/dist/core/scan-options.d.ts +0 -1
- package/dist/core/scan-options.js +14 -6
- package/dist/core/scan.d.ts +0 -1
- package/dist/core/scan.js +91 -41
- package/dist/core/scoring.d.ts +6 -0
- package/dist/core/scoring.js +27 -0
- package/dist/core/types.d.ts +97 -61
- package/dist/core/types.js +9 -3
- package/dist/core/validate-report.d.ts +5 -0
- package/dist/core/validate-report.js +95 -0
- package/dist/core/version.d.ts +0 -1
- package/dist/core/version.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/journey/body-worker.d.ts +27 -0
- package/dist/journey/body-worker.js +140 -0
- package/dist/journey/case.d.ts +74 -0
- package/dist/journey/case.js +187 -0
- package/dist/journey/cli.d.ts +14 -0
- package/dist/journey/cli.js +226 -0
- package/dist/journey/compare.d.ts +43 -0
- package/dist/journey/compare.js +83 -0
- package/dist/journey/contracts.d.ts +143 -0
- package/dist/journey/contracts.js +37 -0
- package/dist/journey/decision.d.ts +72 -0
- package/dist/journey/decision.js +121 -0
- package/dist/journey/demo.d.ts +36 -0
- package/dist/journey/demo.js +137 -0
- package/dist/journey/document.d.ts +8 -0
- package/dist/journey/document.js +113 -0
- package/dist/journey/excerpt.d.ts +6 -0
- package/dist/journey/excerpt.js +54 -0
- package/dist/journey/name-guidance.d.ts +2 -0
- package/dist/journey/name-guidance.js +41 -0
- package/dist/journey/providers.d.ts +34 -0
- package/dist/journey/providers.js +197 -0
- package/dist/journey/report-validation.d.ts +3 -0
- package/dist/journey/report-validation.js +457 -0
- package/dist/journey/runner.d.ts +12 -0
- package/dist/journey/runner.js +321 -0
- package/dist/journey/scope.d.ts +8 -0
- package/dist/journey/scope.js +50 -0
- package/dist/journey/transport.d.ts +3 -0
- package/dist/journey/transport.js +45 -0
- package/dist/journey/verify.d.ts +21 -0
- package/dist/journey/verify.js +213 -0
- package/dist/render/colors.d.ts +6 -7
- package/dist/render/colors.js +16 -25
- package/dist/render/discovery-guidance.d.ts +3 -0
- package/dist/render/discovery-guidance.js +66 -0
- package/dist/render/format-bridge.d.ts +1 -2
- package/dist/render/format-bridge.js +22 -17
- package/dist/render/format-diff.d.ts +2 -0
- package/dist/render/format-diff.js +169 -0
- package/dist/render/format-scan.d.ts +0 -1
- package/dist/render/format-scan.js +6 -4
- package/dist/render/format-verbose.d.ts +0 -1
- package/dist/render/format-verbose.js +7 -4
- package/dist/render/index.d.ts +0 -1
- package/dist/render/index.js +1 -2
- package/dist/render/oauth-observations.d.ts +4 -0
- package/dist/render/oauth-observations.js +27 -0
- package/dist/render/progress-bar.d.ts +1 -2
- package/dist/render/progress-bar.js +8 -6
- package/dist/render/robots-inventory.d.ts +3 -0
- package/dist/render/robots-inventory.js +38 -0
- package/dist/render/symbols.d.ts +4 -10
- package/dist/render/symbols.js +15 -17
- package/dist/render/terminal-text.d.ts +1 -3
- package/dist/render/terminal-text.js +1 -5
- package/dist/utils/analysis-worker-entry.d.ts +3 -0
- package/dist/utils/analysis-worker-entry.js +12 -0
- package/dist/utils/analysis-worker.d.ts +12 -0
- package/dist/utils/analysis-worker.js +54 -0
- package/dist/utils/html.d.ts +39 -0
- package/dist/utils/html.js +261 -0
- package/dist/utils/http-client.d.ts +24 -17
- package/dist/utils/http-client.js +166 -200
- package/dist/utils/http-types.d.ts +43 -0
- package/dist/utils/http-types.js +11 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/package-registry.d.ts +11 -0
- package/dist/utils/package-registry.js +69 -0
- package/dist/utils/read-json-file.d.ts +3 -0
- package/dist/utils/read-json-file.js +41 -0
- package/dist/utils/record.d.ts +1 -0
- package/dist/utils/record.js +3 -0
- package/dist/utils/response-body.d.ts +7 -0
- package/dist/utils/response-body.js +71 -0
- package/dist/utils/ssrf.d.ts +11 -15
- package/dist/utils/ssrf.js +80 -44
- package/dist/utils/terminal-text.d.ts +2 -0
- package/dist/utils/terminal-text.js +4 -0
- package/dist/utils/url.d.ts +29 -1
- package/dist/utils/url.js +147 -17
- package/docs/examples/onboarding/account-claim.json +25 -0
- package/docs/examples/onboarding/pages/account-claim.html +3 -0
- package/docs/examples/onboarding/pages/production-activation.html +3 -0
- package/docs/examples/onboarding/pages/test-credential.html +3 -0
- package/docs/examples/onboarding/production-activation.json +25 -0
- package/docs/examples/onboarding/test-credential.json +25 -0
- package/docs/journey-qualification.md +46 -0
- package/docs/journeys.md +83 -0
- package/package.json +28 -8
- package/dist/bridges/context/agents-json.d.ts.map +0 -1
- package/dist/bridges/context/agents-json.js.map +0 -1
- package/dist/bridges/context/auth-clarity.d.ts.map +0 -1
- package/dist/bridges/context/auth-clarity.js.map +0 -1
- package/dist/bridges/context/auth-legibility.d.ts.map +0 -1
- package/dist/bridges/context/auth-legibility.js.map +0 -1
- package/dist/bridges/context/index.d.ts.map +0 -1
- package/dist/bridges/context/index.js.map +0 -1
- package/dist/bridges/context/rate-limits.d.ts.map +0 -1
- package/dist/bridges/context/rate-limits.js.map +0 -1
- package/dist/bridges/context/tos-contact.d.ts.map +0 -1
- package/dist/bridges/context/tos-contact.js.map +0 -1
- package/dist/bridges/context/versioning.d.ts.map +0 -1
- package/dist/bridges/context/versioning.js.map +0 -1
- package/dist/bridges/index.d.ts.map +0 -1
- package/dist/bridges/index.js.map +0 -1
- package/dist/bridges/reachability/crawler-policy.d.ts.map +0 -1
- package/dist/bridges/reachability/crawler-policy.js.map +0 -1
- package/dist/bridges/reachability/http-status.d.ts.map +0 -1
- package/dist/bridges/reachability/http-status.js.map +0 -1
- package/dist/bridges/reachability/https-check.d.ts.map +0 -1
- package/dist/bridges/reachability/https-check.js.map +0 -1
- package/dist/bridges/reachability/index.d.ts.map +0 -1
- package/dist/bridges/reachability/index.js.map +0 -1
- package/dist/bridges/reachability/meta-robots.d.ts.map +0 -1
- package/dist/bridges/reachability/meta-robots.js.map +0 -1
- package/dist/bridges/reachability/robots-parser.d.ts.map +0 -1
- package/dist/bridges/reachability/robots-parser.js.map +0 -1
- package/dist/bridges/reachability/robots-txt.d.ts.map +0 -1
- package/dist/bridges/reachability/robots-txt.js.map +0 -1
- package/dist/bridges/schema/descriptions.d.ts.map +0 -1
- package/dist/bridges/schema/descriptions.js.map +0 -1
- package/dist/bridges/schema/error-schemas.d.ts.map +0 -1
- package/dist/bridges/schema/error-schemas.js.map +0 -1
- package/dist/bridges/schema/index.d.ts.map +0 -1
- package/dist/bridges/schema/index.js.map +0 -1
- package/dist/bridges/schema/oas-types.d.ts.map +0 -1
- package/dist/bridges/schema/oas-types.js.map +0 -1
- package/dist/bridges/schema/operation-ids.d.ts.map +0 -1
- package/dist/bridges/schema/operation-ids.js.map +0 -1
- package/dist/bridges/schema/required-fields.d.ts.map +0 -1
- package/dist/bridges/schema/required-fields.js.map +0 -1
- package/dist/bridges/schema/schema-types.d.ts.map +0 -1
- package/dist/bridges/schema/schema-types.js.map +0 -1
- package/dist/bridges/separation/api-presence.d.ts.map +0 -1
- package/dist/bridges/separation/api-presence.js.map +0 -1
- package/dist/bridges/separation/developer-docs.d.ts.map +0 -1
- package/dist/bridges/separation/developer-docs.js.map +0 -1
- package/dist/bridges/separation/index.d.ts.map +0 -1
- package/dist/bridges/separation/index.js.map +0 -1
- package/dist/bridges/separation/sdk-references.d.ts.map +0 -1
- package/dist/bridges/separation/sdk-references.js.map +0 -1
- package/dist/bridges/separation/webhook-support.d.ts.map +0 -1
- package/dist/bridges/separation/webhook-support.js.map +0 -1
- package/dist/bridges/standards/a2a-agent-card.d.ts.map +0 -1
- package/dist/bridges/standards/a2a-agent-card.js.map +0 -1
- package/dist/bridges/standards/graphql.d.ts.map +0 -1
- package/dist/bridges/standards/graphql.js.map +0 -1
- package/dist/bridges/standards/index.d.ts.map +0 -1
- package/dist/bridges/standards/index.js.map +0 -1
- package/dist/bridges/standards/json-ld.d.ts.map +0 -1
- package/dist/bridges/standards/json-ld.js.map +0 -1
- package/dist/bridges/standards/llms-txt.d.ts.map +0 -1
- package/dist/bridges/standards/llms-txt.js.map +0 -1
- package/dist/bridges/standards/markdown-negotiation.d.ts.map +0 -1
- package/dist/bridges/standards/markdown-negotiation.js.map +0 -1
- package/dist/bridges/standards/mcp.d.ts.map +0 -1
- package/dist/bridges/standards/mcp.js.map +0 -1
- package/dist/bridges/standards/openapi.d.ts.map +0 -1
- package/dist/bridges/standards/openapi.js.map +0 -1
- package/dist/bridges/standards/schema-org.d.ts.map +0 -1
- package/dist/bridges/standards/schema-org.js.map +0 -1
- package/dist/bridges/standards/sitemap.d.ts.map +0 -1
- package/dist/bridges/standards/sitemap.js.map +0 -1
- package/dist/bridges/standards/well-known.d.ts.map +0 -1
- package/dist/bridges/standards/well-known.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/core/explanations.d.ts.map +0 -1
- package/dist/core/explanations.js.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/scan-options.d.ts.map +0 -1
- package/dist/core/scan-options.js.map +0 -1
- package/dist/core/scan.d.ts.map +0 -1
- package/dist/core/scan.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/core/version.d.ts.map +0 -1
- package/dist/core/version.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/render/colors.d.ts.map +0 -1
- package/dist/render/colors.js.map +0 -1
- package/dist/render/format-bridge.d.ts.map +0 -1
- package/dist/render/format-bridge.js.map +0 -1
- package/dist/render/format-scan.d.ts.map +0 -1
- package/dist/render/format-scan.js.map +0 -1
- package/dist/render/format-verbose.d.ts.map +0 -1
- package/dist/render/format-verbose.js.map +0 -1
- package/dist/render/index.d.ts.map +0 -1
- package/dist/render/index.js.map +0 -1
- package/dist/render/progress-bar.d.ts.map +0 -1
- package/dist/render/progress-bar.js.map +0 -1
- package/dist/render/symbols.d.ts.map +0 -1
- package/dist/render/symbols.js.map +0 -1
- package/dist/render/terminal-text.d.ts.map +0 -1
- package/dist/render/terminal-text.js.map +0 -1
- package/dist/utils/http-client.d.ts.map +0 -1
- package/dist/utils/http-client.js.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/ssrf.d.ts.map +0 -1
- package/dist/utils/ssrf.js.map +0 -1
- package/dist/utils/url.d.ts.map +0 -1
- package/dist/utils/url.js.map +0 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { mediaType } from "../../utils/http-types.js";
|
|
1
2
|
import { httpGet } from "../../utils/http-client.js";
|
|
3
|
+
import { transportFailureAt } from "./http-status.js";
|
|
4
|
+
import { directiveInventory } from "./crawler-policy.js";
|
|
2
5
|
import { parseRobotsTxt } from "./robots-parser.js";
|
|
3
|
-
const DIRECTIVE_PATTERN =
|
|
6
|
+
const DIRECTIVE_PATTERN = /^[ \t]*(?:user-agent|disallow|allow|sitemap)[ \t]*:/im;
|
|
4
7
|
/**
|
|
5
8
|
* Fetch and parse robots.txt for the given domain.
|
|
6
9
|
*
|
|
@@ -11,77 +14,47 @@ export async function checkRobotsTxt(origin, timeout) {
|
|
|
11
14
|
const id = "robots_txt";
|
|
12
15
|
const label = "robots.txt";
|
|
13
16
|
const domain = new URL(origin).host;
|
|
14
|
-
const
|
|
15
|
-
|
|
17
|
+
const url = origin + "/robots.txt";
|
|
18
|
+
const result = await httpGet(url, {
|
|
19
|
+
timeout, maxBodyBytes: 500 * 1024,
|
|
16
20
|
});
|
|
21
|
+
function observation(check, inventory, parsed = null) {
|
|
22
|
+
return { parsed, coverage: inventory.coverage, check: { ...check, data: { ...check.data, directiveInventory: inventory } } };
|
|
23
|
+
}
|
|
17
24
|
if (!result.ok) {
|
|
18
25
|
if (result.error.kind === "request_budget_exhausted") {
|
|
19
|
-
return {
|
|
20
|
-
check: { id, label, status: "error", detail: "robots.txt probe skipped: scan request budget exhausted" },
|
|
21
|
-
parsed: null,
|
|
22
|
-
};
|
|
26
|
+
return observation({ id, label, status: "error", detail: "robots.txt probe skipped: scan request budget exhausted" }, { coverage: "unavailable" });
|
|
23
27
|
}
|
|
24
|
-
|
|
28
|
+
const status = result.error.statusCode;
|
|
29
|
+
// RFC 9309 permits crawling when robots.txt returns 4xx.
|
|
25
30
|
if (result.error.kind === "http_error" &&
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
check: {
|
|
29
|
-
id,
|
|
30
|
-
label,
|
|
31
|
-
status: "partial",
|
|
32
|
-
detail: `No robots.txt found at ${domain}`,
|
|
33
|
-
},
|
|
34
|
-
parsed: null,
|
|
35
|
-
};
|
|
31
|
+
status !== undefined && status >= 400 && status < 500) {
|
|
32
|
+
return observation({ id, label, status: "partial", detail: `No robots.txt found at ${domain} (HTTP ${status})`, data: { statusCode: status } }, { coverage: "absent" });
|
|
36
33
|
}
|
|
37
34
|
// Other errors
|
|
38
|
-
return {
|
|
39
|
-
|
|
40
|
-
id,
|
|
41
|
-
label,
|
|
42
|
-
status: "fail",
|
|
43
|
-
detail: result.error.message,
|
|
44
|
-
},
|
|
45
|
-
parsed: null,
|
|
46
|
-
};
|
|
35
|
+
return { ...observation({ id, label, status: "error", detail: result.error.message }, { coverage: "unavailable" }),
|
|
36
|
+
transportFailure: transportFailureAt(result, url) };
|
|
47
37
|
}
|
|
48
38
|
// Success -- validate content type
|
|
49
|
-
const
|
|
50
|
-
const
|
|
39
|
+
const isTextPlain = mediaType(result.headers) === "text/plain";
|
|
40
|
+
const onlyComments = result.body.split(/[\r\n]/).every(line => !line.trim() || line.trimStart().startsWith("#"));
|
|
51
41
|
const hasDirectives = DIRECTIVE_PATTERN.test(result.body);
|
|
52
|
-
if (!isTextPlain &&
|
|
53
|
-
return {
|
|
54
|
-
check: {
|
|
55
|
-
id,
|
|
56
|
-
label,
|
|
57
|
-
status: "fail",
|
|
58
|
-
detail: `robots.txt at ${domain} is not a text file (robots.txt is per-origin)`,
|
|
59
|
-
},
|
|
60
|
-
parsed: null,
|
|
61
|
-
};
|
|
42
|
+
if (result.body.trimStart().startsWith("<") || !(hasDirectives || (isTextPlain && onlyComments))) {
|
|
43
|
+
return observation({ id, label, status: "fail", detail: `robots.txt at ${domain} is not a text file (robots.txt is per-origin)` }, { coverage: "unavailable" });
|
|
62
44
|
}
|
|
63
45
|
// Parse
|
|
64
|
-
const parsed = parseRobotsTxt(result.body);
|
|
46
|
+
const parsed = parseRobotsTxt(result.body, result.url);
|
|
47
|
+
const inventory = result.bodyIncomplete || result.status === 206 || result.headers["content-range"] !== undefined
|
|
48
|
+
? { coverage: "incomplete" } : directiveInventory(parsed);
|
|
49
|
+
if (inventory.coverage === "incomplete") {
|
|
50
|
+
return observation({ id, label, status: "error", detail: `Only part of robots.txt at ${domain} was available` }, inventory);
|
|
51
|
+
}
|
|
65
52
|
if (parsed.ruleCount === 0 && parsed.groups.length === 0) {
|
|
66
|
-
return {
|
|
67
|
-
check: {
|
|
68
|
-
id,
|
|
69
|
-
label,
|
|
70
|
-
status: "partial",
|
|
71
|
-
detail: `robots.txt at ${domain} exists but has no rules`,
|
|
72
|
-
},
|
|
73
|
-
parsed,
|
|
74
|
-
};
|
|
53
|
+
return observation({ id, label, status: "partial", detail: `robots.txt at ${domain} exists but has no rules` }, inventory, parsed);
|
|
75
54
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
detail: `robots.txt at ${domain} found with ${parsed.ruleCount} rules`,
|
|
82
|
-
data: { ruleCount: parsed.ruleCount, sitemaps: parsed.sitemaps },
|
|
83
|
-
},
|
|
84
|
-
parsed,
|
|
85
|
-
};
|
|
55
|
+
// A clipped URL names a different sitemap, so an over-long one is counted but not stored.
|
|
56
|
+
const sitemaps = parsed.sitemaps.filter(href => href.length <= 2048).slice(0, 32);
|
|
57
|
+
return observation({ id, label, status: "pass", detail: `robots.txt at ${domain} found with ${parsed.ruleCount} rules`,
|
|
58
|
+
data: { ruleCount: parsed.ruleCount, sitemaps, sitemapsTotal: parsed.sitemapsTotal,
|
|
59
|
+
...(sitemaps.length < parsed.sitemapsTotal && { sitemapsTruncated: true }) } }, inventory, parsed);
|
|
86
60
|
}
|
|
87
|
-
//# sourceMappingURL=robots-txt.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Check } from "../../core/types.js";
|
|
2
2
|
import type { ParsedOpenApiSpec } from "./oas-types.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { type SchemaWorkBudget } from "./schema-sources.js";
|
|
4
|
+
export declare function checkDescriptions(spec: ParsedOpenApiSpec | undefined, ops?: [string, string, import("./oas-types.js").OasOperation][], budget?: SchemaWorkBudget): Check;
|
|
@@ -1,56 +1,91 @@
|
|
|
1
1
|
import { collectOperations } from "./oas-types.js";
|
|
2
|
-
|
|
2
|
+
import { operationParameters, requestSchemas, schemaForFields } from "./schema-sources.js";
|
|
3
|
+
/**
|
|
4
|
+
* Keys a parameter's name or description for counting it once. A string is its
|
|
5
|
+
* own key. Only strings are graded, so other values need not be told apart
|
|
6
|
+
* exactly: a primitive is keyed as JSON prints it, and every object or array
|
|
7
|
+
* shares one key, because printing one can expand shared YAML aliases far past
|
|
8
|
+
* the size of the document.
|
|
9
|
+
*/
|
|
10
|
+
function valueTokens() {
|
|
11
|
+
const printed = new Map();
|
|
12
|
+
return value => {
|
|
13
|
+
if (typeof value === "string")
|
|
14
|
+
return value;
|
|
15
|
+
const text = typeof value === "object" && value !== null ? "object" : JSON.stringify(value) ?? "null";
|
|
16
|
+
let token = printed.get(text);
|
|
17
|
+
if (token === undefined)
|
|
18
|
+
printed.set(text, token = printed.size);
|
|
19
|
+
return token;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function checkDescriptions(spec, ops = collectOperations(spec), budget) {
|
|
23
|
+
budget?.charge(ops.length);
|
|
3
24
|
const id = "schema_descriptions";
|
|
4
25
|
const label = "Field Descriptions";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
let sampled = 0;
|
|
27
|
+
let withDescription = 0;
|
|
28
|
+
// A parameter counts once per path, location, name and description, however
|
|
29
|
+
// many operations inherit it. Only operations of one path can repeat it, so
|
|
30
|
+
// what a path has counted is dropped after the last of them.
|
|
31
|
+
const counted = new Map();
|
|
32
|
+
const lastOperation = new Map(ops.map(([path], index) => [path, index]));
|
|
33
|
+
const nameToken = valueTokens();
|
|
34
|
+
const descriptionToken = valueTokens();
|
|
35
|
+
// Looking for text reads a blank description to its end, so one shared by
|
|
36
|
+
// many operations is read once.
|
|
37
|
+
const hasText = new Map();
|
|
38
|
+
function count(description) {
|
|
39
|
+
sampled++;
|
|
40
|
+
if (typeof description !== "string")
|
|
41
|
+
return;
|
|
42
|
+
let text = hasText.get(description);
|
|
43
|
+
if (text === undefined)
|
|
44
|
+
hasText.set(description, text = description.trim() !== "");
|
|
45
|
+
if (text)
|
|
46
|
+
withDescription++;
|
|
47
|
+
}
|
|
48
|
+
for (const [index, [path, , op]] of ops.entries()) {
|
|
49
|
+
let names = counted.get(path);
|
|
50
|
+
for (const param of operationParameters(spec, path, op, budget)) {
|
|
51
|
+
if (param.$ref !== undefined)
|
|
52
|
+
return { id, label, status: "error", detail: "A referenced parameter could not be inspected" };
|
|
53
|
+
if (param.in !== "path" && param.in !== "query")
|
|
54
|
+
continue;
|
|
55
|
+
if (!names)
|
|
56
|
+
counted.set(path, names = { path: new Map(), query: new Map() });
|
|
57
|
+
const name = nameToken(param.name);
|
|
58
|
+
let descriptions = names[param.in].get(name);
|
|
59
|
+
if (!descriptions)
|
|
60
|
+
names[param.in].set(name, descriptions = new Set());
|
|
61
|
+
const description = descriptionToken(param.description);
|
|
62
|
+
if (descriptions.has(description))
|
|
63
|
+
continue;
|
|
64
|
+
descriptions.add(description);
|
|
65
|
+
count(param.description);
|
|
22
66
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
items.push({ hasDescription: typeof prop?.description === "string" && prop.description.trim() !== "" });
|
|
35
|
-
if (items.length >= 30)
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
if (items.length >= 30)
|
|
39
|
-
break;
|
|
67
|
+
for (const raw of requestSchemas(spec, path, op, budget)) {
|
|
68
|
+
const schema = schemaForFields(spec, raw, budget);
|
|
69
|
+
if (!schema)
|
|
70
|
+
return { id, label, status: "error", detail: "Could not inspect all request fields due to a reference or schema composition" };
|
|
71
|
+
const properties = Object.values(schema.properties ?? {});
|
|
72
|
+
budget?.charge(properties.length);
|
|
73
|
+
for (const field of properties) {
|
|
74
|
+
const prop = schemaForFields(spec, field, budget);
|
|
75
|
+
if (!prop && field && typeof field === "object")
|
|
76
|
+
return { id, label, status: "error", detail: "Could not inspect a referenced or composed request property" };
|
|
77
|
+
count(prop?.description);
|
|
40
78
|
}
|
|
41
79
|
}
|
|
42
|
-
if (
|
|
43
|
-
|
|
80
|
+
if (lastOperation.get(path) === index)
|
|
81
|
+
counted.delete(path);
|
|
44
82
|
}
|
|
45
|
-
const sampled = items.length;
|
|
46
83
|
if (sampled === 0)
|
|
47
|
-
return { id, label, status: "
|
|
48
|
-
const withDescription = items.filter((i) => i.hasDescription).length;
|
|
84
|
+
return { id, label, status: "error", detail: "No parameters or properties to evaluate", data: { sampled, withDescription } };
|
|
49
85
|
const ratio = withDescription / sampled;
|
|
50
86
|
if (ratio >= 0.8)
|
|
51
|
-
return { id, label, status: "pass", detail: `${withDescription} of ${sampled}
|
|
87
|
+
return { id, label, status: "pass", detail: `${withDescription} of ${sampled} fields have descriptions`, data: { sampled, withDescription } };
|
|
52
88
|
if (ratio >= 0.4)
|
|
53
|
-
return { id, label, status: "partial", detail: `${withDescription} of ${sampled}
|
|
54
|
-
return { id, label, status: "fail", detail: `Only ${withDescription} of ${sampled}
|
|
89
|
+
return { id, label, status: "partial", detail: `${withDescription} of ${sampled} fields have descriptions`, data: { sampled, withDescription } };
|
|
90
|
+
return { id, label, status: "fail", detail: `Only ${withDescription} of ${sampled} fields have descriptions`, data: { sampled, withDescription } };
|
|
55
91
|
}
|
|
56
|
-
//# sourceMappingURL=descriptions.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Check } from "../../core/types.js";
|
|
2
2
|
import type { ParsedOpenApiSpec } from "./oas-types.js";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { type SchemaWorkBudget } from "./schema-sources.js";
|
|
4
|
+
export declare function checkErrorSchemas(spec: ParsedOpenApiSpec | undefined, ops?: [string, string, import("./oas-types.js").OasOperation][], budget?: SchemaWorkBudget): Check;
|
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
import { collectOperations } from "./oas-types.js";
|
|
2
|
-
|
|
2
|
+
import { responseSchemas } from "./schema-sources.js";
|
|
3
|
+
export function checkErrorSchemas(spec, ops = collectOperations(spec), budget) {
|
|
4
|
+
budget?.charge(ops.length);
|
|
3
5
|
const id = "schema_error_responses";
|
|
4
6
|
const label = "Error Response Schemas";
|
|
5
|
-
const ops = collectOperations(spec);
|
|
6
7
|
let total4xx = 0;
|
|
8
|
+
let totalDefault = 0;
|
|
7
9
|
let withSchema = 0;
|
|
10
|
+
let defaultWithSchema = 0;
|
|
8
11
|
for (const [, , op] of ops) {
|
|
9
12
|
if (!op.responses)
|
|
10
13
|
continue;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const responseCodes = Object.keys(op.responses);
|
|
15
|
+
budget?.charge(responseCodes.length);
|
|
16
|
+
const explicit = responseCodes.filter(code => /^4(?:\d{2}|XX)$/i.test(code));
|
|
17
|
+
const codes = explicit.length ? explicit : Object.hasOwn(op.responses, "default") ? ["default"] : [];
|
|
18
|
+
for (const code of codes) {
|
|
19
|
+
if (code === "default")
|
|
20
|
+
totalDefault++;
|
|
21
|
+
else
|
|
22
|
+
total4xx++;
|
|
23
|
+
const schemas = responseSchemas(spec, op.responses[code], budget);
|
|
24
|
+
if (schemas.some(schema => schema !== undefined)) {
|
|
25
|
+
withSchema++;
|
|
26
|
+
if (code === "default")
|
|
27
|
+
defaultWithSchema++;
|
|
28
|
+
}
|
|
29
|
+
else if (schemas.includes(undefined)) {
|
|
30
|
+
return { id, label, status: "error", detail: "A referenced error response or body schema could not be inspected" };
|
|
19
31
|
}
|
|
20
32
|
}
|
|
21
33
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (
|
|
25
|
-
return { id, label, status: "
|
|
26
|
-
if (withSchema
|
|
27
|
-
return { id, label, status: "
|
|
28
|
-
|
|
34
|
+
const total = total4xx + totalDefault;
|
|
35
|
+
const data = { total4xx, withSchema, ...(totalDefault > 0 && { totalDefault, defaultWithSchema }) };
|
|
36
|
+
if (!total)
|
|
37
|
+
return { id, label, status: "fail", detail: "No 4xx or default error responses defined in spec", data };
|
|
38
|
+
if (withSchema === total)
|
|
39
|
+
return { id, label, status: "pass", detail: `All ${total} error responses have body schemas`, data };
|
|
40
|
+
if (withSchema)
|
|
41
|
+
return { id, label, status: "partial", detail: `${withSchema} of ${total} error responses have body schemas`, data };
|
|
42
|
+
return { id, label, status: "fail", detail: `None of ${total} error responses have body schemas`, data };
|
|
29
43
|
}
|
|
30
|
-
//# sourceMappingURL=error-schemas.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { BridgeResult, ScanContext } from "../../core/types.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { SchemaWorkBudget } from "./schema-sources.js";
|
|
3
|
+
export declare function runSchemaBridge(ctx: ScanContext, budget?: SchemaWorkBudget): Promise<BridgeResult<4>>;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { scoreChecks } from "../../core/scoring.js";
|
|
2
|
+
import { collectOperations, unreadPathItemCount } from "./oas-types.js";
|
|
3
|
+
import { SchemaWorkBudget, SchemaWorkLimit } from "./schema-sources.js";
|
|
1
4
|
import { checkOperationIds } from "./operation-ids.js";
|
|
2
5
|
import { checkSchemaTypes } from "./schema-types.js";
|
|
3
6
|
import { checkErrorSchemas } from "./error-schemas.js";
|
|
@@ -17,24 +20,19 @@ const NO_SPEC_CHECKS = [
|
|
|
17
20
|
{ id: "schema_required_fields", label: "Required Fields" },
|
|
18
21
|
{ id: "schema_descriptions", label: "Field Descriptions" },
|
|
19
22
|
];
|
|
20
|
-
function
|
|
21
|
-
let points = 0;
|
|
22
|
-
let maxPoints = 0;
|
|
23
|
-
for (const check of checks) {
|
|
24
|
-
maxPoints += 1;
|
|
25
|
-
if (check.status === "pass")
|
|
26
|
-
points += 1;
|
|
27
|
-
else if (check.status === "partial")
|
|
28
|
-
points += 0.5;
|
|
29
|
-
}
|
|
30
|
-
const score = maxPoints === 0 ? 0 : Math.round((points / maxPoints) * 100);
|
|
31
|
-
const scoreLabel = score >= 80 ? "pass" : score >= 40 ? "partial" : "fail";
|
|
32
|
-
return { score, scoreLabel };
|
|
33
|
-
}
|
|
34
|
-
export async function runSchemaBridge(ctx) {
|
|
23
|
+
export async function runSchemaBridge(ctx, budget = new SchemaWorkBudget()) {
|
|
35
24
|
const start = performance.now();
|
|
36
25
|
const hasSpec = ctx.shared.openApiDetected === true && ctx.shared.openApiSpec != null;
|
|
37
|
-
const spec = hasSpec ? ctx.shared.openApiSpec : undefined;
|
|
26
|
+
const spec = hasSpec ? ctx.shared.openApiSpec ?? undefined : undefined;
|
|
27
|
+
if (!hasSpec && (ctx.shared.openApiDiscoveryIncomplete || ctx.shared.openApiDetected)) {
|
|
28
|
+
const message = ctx.shared.openApiDiscoveryIncomplete
|
|
29
|
+
? "OpenAPI discovery was incomplete, so schema quality could not be measured."
|
|
30
|
+
: "An OpenAPI document was indicated, but its contents were unavailable for schema evaluation.";
|
|
31
|
+
return {
|
|
32
|
+
id: 4, name: "Schema", status: "not_evaluated", score: null, scoreLabel: null,
|
|
33
|
+
checks: [], durationMs: Math.round(performance.now() - start), message,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
38
36
|
// No spec → all five checks fail over a FIXED denominator (score 0), not
|
|
39
37
|
// null. Excluding Bridge 4 from the average when there's no spec made the
|
|
40
38
|
// overall score non-monotone: publishing a mediocre spec could lower it.
|
|
@@ -44,23 +42,43 @@ export async function runSchemaBridge(ctx) {
|
|
|
44
42
|
const checks = NO_SPEC_CHECKS.map(({ id, label }) => ({
|
|
45
43
|
id, label, status: "fail", detail: NO_SPEC_MESSAGES[id],
|
|
46
44
|
}));
|
|
47
|
-
const { score, scoreLabel } =
|
|
45
|
+
const { score, scoreLabel } = scoreChecks(checks);
|
|
48
46
|
return {
|
|
49
47
|
id: 4, name: "Schema", status: "evaluated", score, scoreLabel, checks,
|
|
50
48
|
durationMs: Math.round(performance.now() - start),
|
|
51
49
|
};
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
try {
|
|
52
|
+
// Every Schema check grades the operation collection. Even one unread
|
|
53
|
+
// path can hide operations, request fields and error responses.
|
|
54
|
+
const unread = unreadPathItemCount(spec, budget);
|
|
55
|
+
if (unread) {
|
|
56
|
+
return {
|
|
57
|
+
id: 4, name: "Schema", status: "not_evaluated", score: null, scoreLabel: null, checks: [],
|
|
58
|
+
durationMs: Math.round(performance.now() - start),
|
|
59
|
+
message: `${unread} referenced OpenAPI path item(s) could not be inspected, so the full set of operations is unknown.`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const ops = collectOperations(spec, budget);
|
|
63
|
+
const checks = [
|
|
64
|
+
checkOperationIds(spec, ops, budget),
|
|
65
|
+
checkSchemaTypes(spec, ops, budget),
|
|
66
|
+
checkErrorSchemas(spec, ops, budget),
|
|
67
|
+
checkRequiredFields(spec, ops, budget),
|
|
68
|
+
checkDescriptions(spec, ops, budget),
|
|
69
|
+
];
|
|
70
|
+
const { score, scoreLabel } = scoreChecks(checks);
|
|
71
|
+
return {
|
|
72
|
+
id: 4, name: "Schema", status: "evaluated", score, scoreLabel, checks,
|
|
73
|
+
durationMs: Math.round(performance.now() - start),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (!(error instanceof SchemaWorkLimit))
|
|
78
|
+
throw error;
|
|
79
|
+
return {
|
|
80
|
+
id: 4, name: "Schema", status: "not_evaluated", score: null, scoreLabel: null, checks: [],
|
|
81
|
+
durationMs: Math.round(performance.now() - start), message: error.message,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
65
84
|
}
|
|
66
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,39 +1,68 @@
|
|
|
1
|
+
import { type SchemaWorkBudget } from "./schema-sources.js";
|
|
2
|
+
export interface OasParameter {
|
|
3
|
+
$ref?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
in?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
schema?: OasSchema;
|
|
10
|
+
}
|
|
11
|
+
export interface OasResponse {
|
|
12
|
+
$ref?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
schema?: OasSchema;
|
|
15
|
+
content?: Record<string, {
|
|
16
|
+
schema?: OasSchema;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
export interface OasRequestBody {
|
|
20
|
+
$ref?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
content?: Record<string, {
|
|
24
|
+
schema?: OasSchema;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
1
27
|
export interface OasOperation {
|
|
2
28
|
operationId?: string;
|
|
3
29
|
description?: string;
|
|
4
30
|
summary?: string;
|
|
5
|
-
parameters?:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
required?: boolean;
|
|
9
|
-
in?: string;
|
|
10
|
-
schema?: {
|
|
11
|
-
type?: string;
|
|
12
|
-
};
|
|
13
|
-
}>;
|
|
14
|
-
requestBody?: {
|
|
15
|
-
required?: boolean;
|
|
16
|
-
content?: Record<string, {
|
|
17
|
-
schema?: OasSchema;
|
|
18
|
-
}>;
|
|
19
|
-
};
|
|
20
|
-
responses?: Record<string, {
|
|
21
|
-
description?: string;
|
|
22
|
-
content?: Record<string, {
|
|
23
|
-
schema?: OasSchema;
|
|
24
|
-
}>;
|
|
25
|
-
}>;
|
|
31
|
+
parameters?: OasParameter[];
|
|
32
|
+
requestBody?: OasRequestBody;
|
|
33
|
+
responses?: Record<string, OasResponse>;
|
|
26
34
|
security?: Array<Record<string, string[]>>;
|
|
35
|
+
servers?: unknown;
|
|
27
36
|
}
|
|
28
|
-
export
|
|
29
|
-
|
|
37
|
+
export type OasPathItem = Partial<Record<typeof HTTP_METHODS[number], OasOperation>> & {
|
|
38
|
+
$ref?: string;
|
|
39
|
+
summary?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
parameters?: OasParameter[];
|
|
42
|
+
servers?: unknown;
|
|
43
|
+
};
|
|
44
|
+
export type OasSchema = boolean | OasSchemaObject;
|
|
45
|
+
export interface OasSchemaObject {
|
|
46
|
+
type?: string | string[];
|
|
30
47
|
$ref?: string;
|
|
31
48
|
properties?: Record<string, OasSchema>;
|
|
32
49
|
required?: string[];
|
|
33
50
|
description?: string;
|
|
34
51
|
items?: OasSchema;
|
|
52
|
+
allOf?: OasSchema[];
|
|
53
|
+
oneOf?: OasSchema[];
|
|
54
|
+
anyOf?: OasSchema[];
|
|
35
55
|
}
|
|
36
56
|
export interface ParsedOpenApiSpec {
|
|
57
|
+
servers?: unknown;
|
|
58
|
+
swagger?: string;
|
|
59
|
+
openapi?: string;
|
|
60
|
+
basePath?: string;
|
|
61
|
+
host?: string;
|
|
62
|
+
schemes?: string[];
|
|
63
|
+
parameters?: Record<string, OasParameter>;
|
|
64
|
+
responses?: Record<string, OasResponse>;
|
|
65
|
+
definitions?: Record<string, OasSchema>;
|
|
37
66
|
info?: {
|
|
38
67
|
title?: string;
|
|
39
68
|
version?: string;
|
|
@@ -49,7 +78,7 @@ export interface ParsedOpenApiSpec {
|
|
|
49
78
|
url?: string;
|
|
50
79
|
};
|
|
51
80
|
};
|
|
52
|
-
paths?: Record<string,
|
|
81
|
+
paths?: Record<string, OasPathItem>;
|
|
53
82
|
components?: {
|
|
54
83
|
securitySchemes?: Record<string, {
|
|
55
84
|
type?: string;
|
|
@@ -60,6 +89,10 @@ export interface ParsedOpenApiSpec {
|
|
|
60
89
|
flows?: unknown;
|
|
61
90
|
}>;
|
|
62
91
|
schemas?: Record<string, OasSchema>;
|
|
92
|
+
requestBodies?: Record<string, OasRequestBody>;
|
|
93
|
+
responses?: Record<string, OasResponse>;
|
|
94
|
+
parameters?: Record<string, OasParameter>;
|
|
95
|
+
pathItems?: Record<string, OasPathItem>;
|
|
63
96
|
};
|
|
64
97
|
security?: Array<Record<string, string[]>>;
|
|
65
98
|
securityDefinitions?: Record<string, {
|
|
@@ -69,9 +102,15 @@ export interface ParsedOpenApiSpec {
|
|
|
69
102
|
in?: string;
|
|
70
103
|
}>;
|
|
71
104
|
}
|
|
105
|
+
declare const HTTP_METHODS: readonly ["get", "post", "put", "patch", "delete", "options", "head", "trace"];
|
|
106
|
+
export declare function unreadPathItemCount(spec: ParsedOpenApiSpec | undefined, budget?: SchemaWorkBudget): number;
|
|
72
107
|
/**
|
|
73
108
|
* Collect all operations from a parsed spec.
|
|
74
109
|
* Returns [path, method, operation] tuples.
|
|
75
110
|
*/
|
|
76
|
-
export declare function collectOperations(spec: ParsedOpenApiSpec | undefined): Array<[string, string, OasOperation]>;
|
|
77
|
-
|
|
111
|
+
export declare function collectOperations(spec: ParsedOpenApiSpec | undefined, budget?: SchemaWorkBudget): Array<[string, string, OasOperation]>;
|
|
112
|
+
/** Expand an OpenAPI server template using its published variable defaults. */
|
|
113
|
+
export declare function openApiServerUrl(server: unknown): string | null;
|
|
114
|
+
/** The base path of a Swagger server when it can be sampled on the scan origin. */
|
|
115
|
+
export declare function swaggerBasePath(spec: ParsedOpenApiSpec, origin: string): string | null;
|
|
116
|
+
export {};
|
|
@@ -1,20 +1,30 @@
|
|
|
1
|
+
import { isRecord } from "../../utils/record.js";
|
|
2
|
+
import { resolvePathItem } from "./schema-sources.js";
|
|
1
3
|
const HTTP_METHODS = [
|
|
2
4
|
"get", "post", "put", "patch", "delete", "options", "head", "trace",
|
|
3
5
|
];
|
|
6
|
+
// Context probes append only root-relative paths on the scanned origin.
|
|
7
|
+
function apiPath(path) {
|
|
8
|
+
return path.startsWith("/") && !path.startsWith("//") && !path.includes("\\");
|
|
9
|
+
}
|
|
10
|
+
export function unreadPathItemCount(spec, budget) {
|
|
11
|
+
const paths = Object.entries(spec?.paths ?? {});
|
|
12
|
+
budget?.charge(paths.length);
|
|
13
|
+
return paths.filter(([path, item]) => apiPath(path) && item?.$ref !== undefined && !resolvePathItem(spec, path, budget)).length;
|
|
14
|
+
}
|
|
4
15
|
/**
|
|
5
16
|
* Collect all operations from a parsed spec.
|
|
6
17
|
* Returns [path, method, operation] tuples.
|
|
7
18
|
*/
|
|
8
|
-
export function collectOperations(spec) {
|
|
19
|
+
export function collectOperations(spec, budget) {
|
|
9
20
|
if (!spec?.paths)
|
|
10
21
|
return [];
|
|
11
22
|
const ops = [];
|
|
12
|
-
for (const
|
|
13
|
-
|
|
14
|
-
// these keys to the scanned origin, so never accept authority fragments.
|
|
15
|
-
if (!path.startsWith("/") || path.startsWith("//") || path.includes("\\"))
|
|
23
|
+
for (const path of Object.keys(spec.paths)) {
|
|
24
|
+
if (!apiPath(path))
|
|
16
25
|
continue;
|
|
17
|
-
|
|
26
|
+
const pathItem = resolvePathItem(spec, path, budget);
|
|
27
|
+
if (!pathItem)
|
|
18
28
|
continue;
|
|
19
29
|
for (const method of HTTP_METHODS) {
|
|
20
30
|
const op = pathItem[method];
|
|
@@ -25,4 +35,24 @@ export function collectOperations(spec) {
|
|
|
25
35
|
}
|
|
26
36
|
return ops;
|
|
27
37
|
}
|
|
28
|
-
|
|
38
|
+
/** Expand an OpenAPI server template using its published variable defaults. */
|
|
39
|
+
export function openApiServerUrl(server) {
|
|
40
|
+
if (!isRecord(server) || typeof server.url !== "string" || server.url.length > 8192)
|
|
41
|
+
return null;
|
|
42
|
+
const variables = isRecord(server.variables) ? server.variables : {};
|
|
43
|
+
const raw = server.url.replace(/\{([^{}]+)\}/g, (token, name) => {
|
|
44
|
+
const variable = Object.hasOwn(variables, name) ? variables[name] : undefined;
|
|
45
|
+
return isRecord(variable) && typeof variable.default === "string" && variable.default.length <= 255 ? variable.default : token;
|
|
46
|
+
});
|
|
47
|
+
return raw && raw.length <= 8192 && !/[{}]/.test(raw) ? raw : null;
|
|
48
|
+
}
|
|
49
|
+
/** The base path of a Swagger server when it can be sampled on the scan origin. */
|
|
50
|
+
export function swaggerBasePath(spec, origin) {
|
|
51
|
+
const url = new URL(origin);
|
|
52
|
+
if (spec.host !== undefined && spec.host !== url.host)
|
|
53
|
+
return null;
|
|
54
|
+
if (spec.schemes !== undefined && (!Array.isArray(spec.schemes) || !spec.schemes.includes(url.protocol.slice(0, -1))))
|
|
55
|
+
return null;
|
|
56
|
+
const base = spec.basePath ?? "/";
|
|
57
|
+
return typeof base === "string" && /^\/(?!\/)/.test(base) && !/[{}?#\\]/.test(base) ? base.replace(/\/$/, "") : null;
|
|
58
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import type { SchemaWorkBudget } from "./schema-sources.js";
|
|
1
2
|
import type { Check } from "../../core/types.js";
|
|
2
3
|
import type { ParsedOpenApiSpec } from "./oas-types.js";
|
|
3
|
-
export declare function checkOperationIds(spec: ParsedOpenApiSpec | undefined): Check;
|
|
4
|
-
//# sourceMappingURL=operation-ids.d.ts.map
|
|
4
|
+
export declare function checkOperationIds(spec: ParsedOpenApiSpec | undefined, ops?: [string, string, import("./oas-types.js").OasOperation][], budget?: SchemaWorkBudget): Check;
|