@knitli/openapi-mcp 0.0.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/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +362 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +249 -0
- package/dist/compile.d.ts +14 -0
- package/dist/compile.js +132 -0
- package/dist/compiler.d.ts +13 -0
- package/dist/compiler.js +7 -0
- package/dist/conformance/fixtures.d.ts +24 -0
- package/dist/conformance/fixtures.js +119 -0
- package/dist/conformance/index.d.ts +2 -0
- package/dist/conformance/index.js +2 -0
- package/dist/conformance/runtime-suite.d.ts +31 -0
- package/dist/conformance/runtime-suite.js +343 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/load.d.ts +31 -0
- package/dist/load.js +20 -0
- package/dist/operations.d.ts +27 -0
- package/dist/operations.js +231 -0
- package/dist/permissions.d.ts +31 -0
- package/dist/permissions.js +89 -0
- package/dist/release/compile-release.d.ts +33 -0
- package/dist/release/compile-release.js +1620 -0
- package/dist/release/load-v4.d.ts +29 -0
- package/dist/release/load-v4.js +297 -0
- package/dist/release/manifest-builder.d.ts +19 -0
- package/dist/release/manifest-builder.js +28 -0
- package/dist/release/publish.d.ts +45 -0
- package/dist/release/publish.js +346 -0
- package/dist/release/reference-map.d.ts +53 -0
- package/dist/release/reference-map.js +347 -0
- package/dist/release/schema-v4.d.ts +5 -0
- package/dist/release/schema-v4.js +91 -0
- package/dist/runtime/action-permit.d.ts +11 -0
- package/dist/runtime/action-permit.js +1 -0
- package/dist/runtime/classify.d.ts +16 -0
- package/dist/runtime/classify.js +279 -0
- package/dist/runtime/credential-binding.d.ts +3 -0
- package/dist/runtime/credential-binding.js +101 -0
- package/dist/runtime/digest.d.ts +8 -0
- package/dist/runtime/digest.js +80 -0
- package/dist/runtime/errors.d.ts +14 -0
- package/dist/runtime/errors.js +15 -0
- package/dist/runtime/index.d.ts +20 -0
- package/dist/runtime/index.js +14 -0
- package/dist/runtime/manifest.d.ts +33 -0
- package/dist/runtime/manifest.js +489 -0
- package/dist/runtime/prepared-call.d.ts +39 -0
- package/dist/runtime/prepared-call.js +566 -0
- package/dist/runtime/references.d.ts +7 -0
- package/dist/runtime/references.js +197 -0
- package/dist/runtime/runtime.d.ts +25 -0
- package/dist/runtime/runtime.js +1272 -0
- package/dist/runtime/schema-keywords.d.ts +2 -0
- package/dist/runtime/schema-keywords.js +30 -0
- package/dist/runtime/schema-resolver.d.ts +10 -0
- package/dist/runtime/schema-resolver.js +237 -0
- package/dist/runtime/serialize.d.ts +12 -0
- package/dist/runtime/serialize.js +877 -0
- package/dist/runtime/store.d.ts +52 -0
- package/dist/runtime/store.js +582 -0
- package/dist/runtime/strict-json.d.ts +19 -0
- package/dist/runtime/strict-json.js +539 -0
- package/dist/runtime/types.d.ts +457 -0
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/verify-record.d.ts +6 -0
- package/dist/runtime/verify-record.js +492 -0
- package/dist/runtime/versions.d.ts +63 -0
- package/dist/runtime/versions.js +86 -0
- package/dist/safety.d.ts +28 -0
- package/dist/safety.js +60 -0
- package/dist/schema.d.ts +5 -0
- package/dist/schema.js +52 -0
- package/dist/schemas.d.ts +9 -0
- package/dist/schemas.js +16 -0
- package/dist/sign.d.ts +20 -0
- package/dist/sign.js +55 -0
- package/dist/sqlite/auth.d.ts +33 -0
- package/dist/sqlite/auth.js +973 -0
- package/dist/sqlite/catalog-store.d.ts +20 -0
- package/dist/sqlite/catalog-store.js +370 -0
- package/dist/sqlite/destination-guard.d.ts +24 -0
- package/dist/sqlite/destination-guard.js +140 -0
- package/dist/sqlite/generation-store.d.ts +12 -0
- package/dist/sqlite/generation-store.js +721 -0
- package/dist/sqlite/guarded-fetch.d.ts +24 -0
- package/dist/sqlite/guarded-fetch.js +626 -0
- package/dist/sqlite/index.d.ts +5 -0
- package/dist/sqlite/index.js +5 -0
- package/dist/sqlite/oauth-resource.d.ts +2 -0
- package/dist/sqlite/oauth-resource.js +15 -0
- package/dist/sqlite/release-completion.d.ts +5 -0
- package/dist/sqlite/release-completion.js +80 -0
- package/dist/stdio/action-broker.d.ts +15 -0
- package/dist/stdio/action-broker.js +136 -0
- package/dist/stdio/authorizer.d.ts +30 -0
- package/dist/stdio/authorizer.js +484 -0
- package/dist/stdio/config.d.ts +77 -0
- package/dist/stdio/config.js +144 -0
- package/dist/stdio/exact-policy.d.ts +41 -0
- package/dist/stdio/exact-policy.js +361 -0
- package/dist/stdio/index.d.ts +6 -0
- package/dist/stdio/index.js +148 -0
- package/dist/stdio/render.d.ts +8 -0
- package/dist/stdio/render.js +253 -0
- package/dist/stdio/request-state.d.ts +18 -0
- package/dist/stdio/request-state.js +79 -0
- package/dist/stdio/search.d.ts +10 -0
- package/dist/stdio/search.js +76 -0
- package/dist/stdio/server.d.ts +29 -0
- package/dist/stdio/server.js +309 -0
- package/dist/types.d.ts +32 -0
- package/dist/types.js +1 -0
- package/package.json +131 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { OperationRecord, PermConfidence } from "./types.ts";
|
|
2
|
+
export interface PermissionsDataset {
|
|
3
|
+
permissions: Record<string, {
|
|
4
|
+
schemes?: Record<string, {
|
|
5
|
+
privilegeLevel?: number;
|
|
6
|
+
}>;
|
|
7
|
+
pathSets?: Array<{
|
|
8
|
+
methods?: string[];
|
|
9
|
+
paths?: Record<string, unknown>;
|
|
10
|
+
}>;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export interface PermissionMatch {
|
|
14
|
+
permissions: string[];
|
|
15
|
+
privilegeLevel: number | null;
|
|
16
|
+
confidence: PermConfidence;
|
|
17
|
+
}
|
|
18
|
+
export interface PermissionIndex {
|
|
19
|
+
/** method -> normalised path -> permission names */
|
|
20
|
+
byMethod: Map<string, Map<string, Set<string>>>;
|
|
21
|
+
privilege: Map<string, number>;
|
|
22
|
+
}
|
|
23
|
+
export declare function buildPermissionIndex(dataset: PermissionsDataset): PermissionIndex;
|
|
24
|
+
/**
|
|
25
|
+
* Three strategies in order: exact, OData-suffix-stripped, then longest
|
|
26
|
+
* prefix. Prefix matches are a heuristic and are marked as such — a child
|
|
27
|
+
* path can require a broader permission than its parent.
|
|
28
|
+
*/
|
|
29
|
+
export declare function lookupPermissions(index: PermissionIndex, path: string, method: string): PermissionMatch | null;
|
|
30
|
+
/** Annotates records in place and recomputes risk now that privilege is known. */
|
|
31
|
+
export declare function applyPermissions(ops: OperationRecord[], index: PermissionIndex): void;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { riskFor } from "./safety.js";
|
|
2
|
+
/** Parameter names differ between the two Microsoft datasets; erase them. */
|
|
3
|
+
function normalise(path) {
|
|
4
|
+
return path
|
|
5
|
+
.replace(/\{[^}]*\}/g, "{}")
|
|
6
|
+
.replace(/\/+$/, "")
|
|
7
|
+
.toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
const ODATA_SUFFIX = /\/(\$count|\$ref|\$value|microsoft\.graph\.[a-z0-9.]+)$/;
|
|
10
|
+
export function buildPermissionIndex(dataset) {
|
|
11
|
+
const byMethod = new Map();
|
|
12
|
+
const privilege = new Map();
|
|
13
|
+
for (const [name, body] of Object.entries(dataset.permissions ?? {})) {
|
|
14
|
+
const level = body.schemes?.DelegatedWork?.privilegeLevel;
|
|
15
|
+
if (typeof level === "number")
|
|
16
|
+
privilege.set(name, level);
|
|
17
|
+
for (const set of body.pathSets ?? []) {
|
|
18
|
+
for (const method of set.methods ?? []) {
|
|
19
|
+
const key = method.toUpperCase();
|
|
20
|
+
let table = byMethod.get(key);
|
|
21
|
+
if (!table) {
|
|
22
|
+
table = new Map();
|
|
23
|
+
byMethod.set(key, table);
|
|
24
|
+
}
|
|
25
|
+
for (const path of Object.keys(set.paths ?? {})) {
|
|
26
|
+
const n = normalise(path);
|
|
27
|
+
let names = table.get(n);
|
|
28
|
+
if (!names) {
|
|
29
|
+
names = new Set();
|
|
30
|
+
table.set(n, names);
|
|
31
|
+
}
|
|
32
|
+
names.add(name);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return { byMethod, privilege };
|
|
38
|
+
}
|
|
39
|
+
function finish(index, names, confidence) {
|
|
40
|
+
const permissions = [...names].sort();
|
|
41
|
+
// Several permissions can authorise one operation; the strictest bounds risk.
|
|
42
|
+
const levels = permissions
|
|
43
|
+
.map((p) => index.privilege.get(p))
|
|
44
|
+
.filter((l) => typeof l === "number");
|
|
45
|
+
return {
|
|
46
|
+
permissions,
|
|
47
|
+
privilegeLevel: levels.length ? Math.max(...levels) : null,
|
|
48
|
+
confidence,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Three strategies in order: exact, OData-suffix-stripped, then longest
|
|
53
|
+
* prefix. Prefix matches are a heuristic and are marked as such — a child
|
|
54
|
+
* path can require a broader permission than its parent.
|
|
55
|
+
*/
|
|
56
|
+
export function lookupPermissions(index, path, method) {
|
|
57
|
+
const table = index.byMethod.get(method.toUpperCase());
|
|
58
|
+
if (!table)
|
|
59
|
+
return null;
|
|
60
|
+
const exact = normalise(path);
|
|
61
|
+
const hitExact = table.get(exact);
|
|
62
|
+
if (hitExact)
|
|
63
|
+
return finish(index, hitExact, "exact");
|
|
64
|
+
const stripped = exact.replace(ODATA_SUFFIX, "");
|
|
65
|
+
if (stripped !== exact) {
|
|
66
|
+
const hitSuffix = table.get(stripped);
|
|
67
|
+
if (hitSuffix)
|
|
68
|
+
return finish(index, hitSuffix, "suffix");
|
|
69
|
+
}
|
|
70
|
+
const parts = stripped.split("/");
|
|
71
|
+
for (let i = parts.length - 1; i > 1; i--) {
|
|
72
|
+
const hitPrefix = table.get(parts.slice(0, i).join("/"));
|
|
73
|
+
if (hitPrefix)
|
|
74
|
+
return finish(index, hitPrefix, "prefix");
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
/** Annotates records in place and recomputes risk now that privilege is known. */
|
|
79
|
+
export function applyPermissions(ops, index) {
|
|
80
|
+
for (const op of ops) {
|
|
81
|
+
const match = lookupPermissions(index, op.path, op.method);
|
|
82
|
+
if (match) {
|
|
83
|
+
op.permissions = match.permissions;
|
|
84
|
+
op.permConfidence = match.confidence;
|
|
85
|
+
op.privilegeLevel = match.privilegeLevel;
|
|
86
|
+
}
|
|
87
|
+
op.risk = riskFor(op.safety, op.privilegeLevel, op.path);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type CompilerLimits } from "./load-v4.ts";
|
|
2
|
+
import { type CompiledRelease, type CompiledReleasePaths } from "./publish.ts";
|
|
3
|
+
import { type ReferenceResolver } from "./reference-map.ts";
|
|
4
|
+
type Provenance = {
|
|
5
|
+
readonly sourceUri: string;
|
|
6
|
+
readonly sourceLabel?: never;
|
|
7
|
+
} | {
|
|
8
|
+
readonly sourceLabel: string;
|
|
9
|
+
readonly sourceUri?: never;
|
|
10
|
+
};
|
|
11
|
+
export type CompileReleaseOptions = Provenance & {
|
|
12
|
+
readonly specPath: string;
|
|
13
|
+
readonly sourceRevision: string;
|
|
14
|
+
readonly catalogId: string;
|
|
15
|
+
readonly releaseId: string;
|
|
16
|
+
readonly generation: number;
|
|
17
|
+
readonly issuer: string;
|
|
18
|
+
readonly keyId: string;
|
|
19
|
+
readonly policyId: string;
|
|
20
|
+
readonly allowedOrigins: readonly string[];
|
|
21
|
+
readonly outDir: string;
|
|
22
|
+
readonly privateKeyPem: string;
|
|
23
|
+
readonly permissionsPath?: string;
|
|
24
|
+
readonly referenceRoot?: string;
|
|
25
|
+
readonly referenceMapPath?: string;
|
|
26
|
+
readonly referenceResolver?: ReferenceResolver;
|
|
27
|
+
readonly limits?: CompilerLimits;
|
|
28
|
+
};
|
|
29
|
+
export type ConstructionCheckpoint = "before-sqlite-created" | "before-signature-created" | "before-manifest-created" | "after-sqlite-opened" | "after-sqlite-emitted" | "before-sqlite-snapshot-read" | "after-signature-opened" | "after-manifest-opened";
|
|
30
|
+
type ConstructionHook = (checkpoint: ConstructionCheckpoint, paths: CompiledReleasePaths) => void | Promise<void>;
|
|
31
|
+
export declare function compileReleaseWithCheckpoint(options: CompileReleaseOptions, checkpoint?: ConstructionHook): Promise<CompiledRelease>;
|
|
32
|
+
export declare function compileRelease(options: CompileReleaseOptions): Promise<CompiledRelease>;
|
|
33
|
+
export {};
|