@kya-os/mcp-i 0.1.0-alpha.3.9 → 1.2.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 +350 -213
- package/dist/149.js +1 -0
- package/dist/189.js +1 -0
- package/dist/261.js +1 -0
- package/dist/28.js +1 -0
- package/dist/295.js +1 -0
- package/dist/460.js +1 -0
- package/dist/570.js +1 -0
- package/dist/634.js +1 -0
- package/dist/647.js +1 -0
- package/dist/67.js +1 -0
- package/dist/739.js +1 -0
- package/dist/742.js +1 -0
- package/dist/904.js +1 -0
- package/dist/938.js +1 -0
- package/dist/auth/api-key.d.ts +16 -0
- package/dist/auth/api-key.js +82 -0
- package/dist/auth/jwt.d.ts +43 -0
- package/dist/auth/jwt.js +51 -0
- package/dist/auth/oauth/factory.d.ts +12 -0
- package/dist/auth/oauth/factory.js +36 -0
- package/dist/auth/oauth/index.d.ts +5 -0
- package/dist/auth/oauth/index.js +27 -0
- package/dist/auth/oauth/providers/proxy-provider.d.ts +13 -0
- package/dist/auth/oauth/providers/proxy-provider.js +159 -0
- package/dist/auth/oauth/router.d.ts +4 -0
- package/dist/auth/oauth/router.js +294 -0
- package/dist/auth/oauth/storage/memory-storage.d.ts +12 -0
- package/dist/auth/oauth/storage/memory-storage.js +40 -0
- package/dist/auth/oauth/types.d.ts +112 -0
- package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.js +176 -0
- package/dist/cache/__tests__/concurrency.test.d.ts +5 -0
- package/dist/cache/__tests__/concurrency.test.js +300 -0
- package/dist/cache/__tests__/dynamodb-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/dynamodb-nonce-cache.test.js +176 -0
- package/dist/cache/__tests__/memory-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/memory-nonce-cache.test.js +132 -0
- package/dist/cache/__tests__/nonce-cache-factory-simple.test.d.ts +4 -0
- package/dist/cache/__tests__/nonce-cache-factory-simple.test.js +133 -0
- package/dist/cache/__tests__/nonce-cache-factory.test.d.ts +4 -0
- package/dist/cache/__tests__/nonce-cache-factory.test.js +252 -0
- package/dist/cache/__tests__/redis-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/redis-nonce-cache.test.js +95 -0
- package/dist/cache/cloudflare-kv-nonce-cache.d.ts +14 -0
- package/dist/cache/cloudflare-kv-nonce-cache.js +93 -0
- package/dist/cache/dynamodb-nonce-cache.d.ts +15 -0
- package/dist/cache/dynamodb-nonce-cache.js +92 -0
- package/dist/cache/index.d.ts +16 -0
- package/dist/cache/index.js +32 -0
- package/dist/cache/memory-nonce-cache.d.ts +44 -0
- package/dist/cache/memory-nonce-cache.js +105 -0
- package/dist/cache/nonce-cache-factory.d.ts +20 -0
- package/dist/cache/nonce-cache-factory.js +208 -0
- package/dist/cache/redis-nonce-cache.d.ts +14 -0
- package/dist/cache/redis-nonce-cache.js +53 -0
- package/dist/compiler/compiler-context.d.ts +23 -0
- package/dist/compiler/compiler-context.js +24 -0
- package/dist/compiler/config/constants.d.ts +41 -0
- package/dist/compiler/config/constants.js +45 -0
- package/dist/compiler/config/index.d.ts +252 -0
- package/dist/compiler/config/index.js +15 -0
- package/dist/compiler/config/injection.d.ts +26 -0
- package/dist/compiler/config/injection.js +58 -0
- package/dist/compiler/config/schemas/experimental/index.d.ts +91 -0
- package/dist/compiler/config/schemas/experimental/index.js +16 -0
- package/dist/compiler/config/schemas/experimental/oauth.d.ts +74 -0
- package/dist/compiler/config/schemas/experimental/oauth.js +25 -0
- package/dist/compiler/config/schemas/index.d.ts +6 -0
- package/dist/compiler/config/schemas/index.js +17 -0
- package/dist/compiler/config/schemas/paths.d.ts +9 -0
- package/dist/compiler/config/schemas/paths.js +12 -0
- package/dist/compiler/config/schemas/transport/http.d.ts +82 -0
- package/dist/compiler/config/schemas/transport/http.js +33 -0
- package/dist/compiler/config/schemas/transport/stdio.d.ts +9 -0
- package/dist/compiler/config/schemas/transport/stdio.js +15 -0
- package/dist/compiler/config/schemas/webpack.d.ts +3 -0
- package/dist/compiler/config/schemas/webpack.js +15 -0
- package/dist/compiler/config/types.d.ts +1 -0
- package/dist/compiler/config/types.js +2 -0
- package/dist/compiler/config/utils.d.ts +20 -0
- package/dist/compiler/config/utils.js +36 -0
- package/dist/compiler/generate-env-code.d.ts +1 -0
- package/dist/compiler/generate-env-code.js +8 -0
- package/dist/compiler/generate-import-code.d.ts +1 -0
- package/dist/compiler/generate-import-code.js +24 -0
- package/dist/compiler/get-webpack-config/get-entries.d.ts +3 -0
- package/dist/compiler/get-webpack-config/get-entries.js +29 -0
- package/dist/compiler/get-webpack-config/get-externals.d.ts +7 -0
- package/dist/compiler/get-webpack-config/get-externals.js +88 -0
- package/dist/compiler/get-webpack-config/get-injected-variables.d.ts +8 -0
- package/dist/compiler/get-webpack-config/get-injected-variables.js +25 -0
- package/dist/compiler/get-webpack-config/index.d.ts +4 -0
- package/dist/compiler/get-webpack-config/index.js +101 -0
- package/dist/compiler/get-webpack-config/plugins.d.ts +8 -0
- package/dist/compiler/get-webpack-config/plugins.js +132 -0
- package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.d.ts +9 -0
- package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.js +40 -0
- package/dist/compiler/index.d.ts +6 -0
- package/dist/compiler/index.js +194 -0
- package/dist/compiler/on-first-build.d.ts +3 -0
- package/dist/compiler/on-first-build.js +58 -0
- package/dist/compiler/parse-xmcp-config.d.ts +9 -0
- package/dist/compiler/parse-xmcp-config.js +155 -0
- package/dist/compiler/start-http-server.d.ts +1 -0
- package/dist/compiler/start-http-server.js +34 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +38 -0
- package/dist/index.js.LICENSE.txt +49 -0
- package/dist/runtime/__tests__/audit.test.d.ts +4 -0
- package/dist/runtime/__tests__/audit.test.js +328 -0
- package/dist/runtime/__tests__/identity.test.d.ts +4 -0
- package/dist/runtime/__tests__/identity.test.js +164 -0
- package/dist/runtime/__tests__/mcpi-runtime.test.d.ts +4 -0
- package/dist/runtime/__tests__/mcpi-runtime.test.js +372 -0
- package/dist/runtime/__tests__/proof.test.d.ts +4 -0
- package/dist/runtime/__tests__/proof.test.js +302 -0
- package/dist/runtime/__tests__/session.test.d.ts +4 -0
- package/dist/runtime/__tests__/session.test.js +254 -0
- package/dist/runtime/__tests__/well-known.test.d.ts +4 -0
- package/dist/runtime/__tests__/well-known.test.js +312 -0
- package/dist/runtime/adapter-express.js +2 -0
- package/dist/runtime/adapter-express.js.LICENSE.txt +252 -0
- package/dist/runtime/adapter-nextjs.js +2 -0
- package/dist/runtime/adapter-nextjs.js.LICENSE.txt +53 -0
- package/dist/runtime/adapters/express/index.d.ts +2 -0
- package/dist/runtime/adapters/express/index.js +48 -0
- package/dist/runtime/adapters/nextjs/index.d.ts +8 -0
- package/dist/runtime/adapters/nextjs/index.js +18 -0
- package/dist/runtime/audit.d.ts +93 -0
- package/dist/runtime/audit.js +212 -0
- package/dist/runtime/debug.d.ts +118 -0
- package/dist/runtime/debug.js +612 -0
- package/dist/runtime/delegation-hooks.d.ts +85 -0
- package/dist/runtime/delegation-hooks.js +116 -0
- package/dist/runtime/demo.d.ts +71 -0
- package/dist/runtime/demo.js +135 -0
- package/dist/runtime/headers.d.ts +1 -0
- package/dist/runtime/headers.js +9 -0
- package/dist/runtime/http.js +2 -0
- package/dist/runtime/http.js.LICENSE.txt +252 -0
- package/dist/runtime/identity.d.ts +105 -0
- package/dist/runtime/identity.js +232 -0
- package/dist/runtime/index.d.ts +16 -0
- package/dist/runtime/index.js +56 -0
- package/dist/runtime/mcpi-runtime.d.ts +164 -0
- package/dist/runtime/mcpi-runtime.js +352 -0
- package/dist/runtime/proof.d.ts +87 -0
- package/dist/runtime/proof.js +223 -0
- package/dist/runtime/session.d.ts +88 -0
- package/dist/runtime/session.js +216 -0
- package/dist/runtime/stdio.js +2 -0
- package/dist/runtime/stdio.js.LICENSE.txt +1 -0
- package/dist/runtime/templates/home.d.ts +2 -0
- package/dist/runtime/templates/home.js +50 -0
- package/dist/runtime/transports/http/base-streamable-http.d.ts +25 -0
- package/dist/runtime/transports/http/base-streamable-http.js +16 -0
- package/dist/runtime/transports/http/http-context.d.ts +9 -0
- package/dist/runtime/transports/http/http-context.js +8 -0
- package/dist/runtime/transports/http/index.js +55 -0
- package/dist/runtime/transports/http/setup-cors.d.ts +4 -0
- package/dist/runtime/transports/http/setup-cors.js +24 -0
- package/dist/runtime/transports/http/stateless-streamable-http.d.ts +39 -0
- package/dist/runtime/transports/http/stateless-streamable-http.js +331 -0
- package/dist/runtime/transports/stdio/index.d.ts +1 -0
- package/dist/runtime/transports/stdio/index.js +51 -0
- package/dist/runtime/utils/server.d.ts +42 -0
- package/dist/runtime/utils/server.js +39 -0
- package/dist/runtime/utils/tools.d.ts +8 -0
- package/dist/runtime/utils/tools.js +115 -0
- package/dist/runtime/verifier-middleware.d.ts +76 -0
- package/dist/runtime/verifier-middleware.js +322 -0
- package/dist/runtime/well-known.d.ts +151 -0
- package/dist/runtime/well-known.js +258 -0
- package/dist/storage/config.d.ts +28 -0
- package/dist/storage/config.js +79 -0
- package/dist/storage/delegation.d.ts +59 -0
- package/dist/storage/delegation.js +130 -0
- package/dist/storage/merkle-verifier.d.ts +84 -0
- package/dist/storage/merkle-verifier.js +261 -0
- package/dist/test/__tests__/nonce-cache-integration.test.d.ts +1 -0
- package/dist/test/__tests__/nonce-cache-integration.test.js +116 -0
- package/dist/test/__tests__/nonce-cache.test.d.ts +1 -0
- package/dist/test/__tests__/nonce-cache.test.js +122 -0
- package/dist/test/__tests__/runtime-integration.test.d.ts +4 -0
- package/dist/test/__tests__/runtime-integration.test.js +192 -0
- package/dist/test/__tests__/test-infrastructure.test.d.ts +4 -0
- package/dist/test/__tests__/test-infrastructure.test.js +178 -0
- package/dist/test/deterministic-keys.d.ts +31 -0
- package/dist/test/deterministic-keys.js +108 -0
- package/dist/test/examples/test-usage-example.d.ts +140 -0
- package/dist/test/examples/test-usage-example.js +175 -0
- package/dist/test/index.d.ts +11 -0
- package/dist/test/index.js +27 -0
- package/dist/test/local-verification.d.ts +28 -0
- package/dist/test/local-verification.js +342 -0
- package/dist/test/mock-identity-provider.d.ts +96 -0
- package/dist/test/mock-identity-provider.js +243 -0
- package/dist/test/runtime-integration.d.ts +63 -0
- package/dist/test/runtime-integration.js +140 -0
- package/dist/test/test-environment.d.ts +26 -0
- package/dist/test/test-environment.js +50 -0
- package/dist/types/declarations.d.ts +1 -0
- package/dist/types/declarations.js +6 -0
- package/dist/types/middleware.d.ts +2 -0
- package/dist/types/middleware.js +2 -0
- package/dist/types/tool.d.ts +80 -0
- package/dist/types/tool.js +2 -0
- package/dist/utils/cli-icons.d.ts +3 -0
- package/dist/utils/cli-icons.js +7 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.js +13 -0
- package/dist/utils/context.d.ts +33 -0
- package/dist/utils/context.js +58 -0
- package/dist/utils/file-watcher.d.ts +19 -0
- package/dist/utils/file-watcher.js +49 -0
- package/dist/utils/fs-utils.d.ts +2 -0
- package/dist/utils/fs-utils.js +22 -0
- package/dist/utils/path-validation.d.ts +3 -0
- package/dist/utils/path-validation.js +56 -0
- package/dist/utils/spawn-process.d.ts +9 -0
- package/dist/utils/spawn-process.js +50 -0
- package/dist/utils/subscribable.d.ts +12 -0
- package/dist/utils/subscribable.js +44 -0
- package/package.json +91 -77
- package/dist/cjs/auto.js +0 -16
- package/dist/cjs/cli-mode.d.ts +0 -16
- package/dist/cjs/cli-mode.js +0 -32
- package/dist/cjs/crypto.d.ts +0 -16
- package/dist/cjs/crypto.js +0 -212
- package/dist/cjs/dev-helper.d.ts +0 -3
- package/dist/cjs/dev-helper.js +0 -46
- package/dist/cjs/encrypted-storage.d.ts +0 -11
- package/dist/cjs/encrypted-storage.js +0 -73
- package/dist/cjs/index.d.ts +0 -56
- package/dist/cjs/index.js +0 -727
- package/dist/cjs/logger.d.ts +0 -32
- package/dist/cjs/logger.js +0 -85
- package/dist/cjs/nextjs.d.ts +0 -10
- package/dist/cjs/nextjs.js +0 -83
- package/dist/cjs/platform-info.d.ts +0 -36
- package/dist/cjs/platform-info.js +0 -274
- package/dist/cjs/polling.d.ts +0 -13
- package/dist/cjs/polling.js +0 -52
- package/dist/cjs/registry/index.d.ts +0 -12
- package/dist/cjs/registry/index.js +0 -56
- package/dist/cjs/registry/knowthat.d.ts +0 -17
- package/dist/cjs/registry/knowthat.js +0 -173
- package/dist/cjs/rotation.d.ts +0 -35
- package/dist/cjs/rotation.js +0 -102
- package/dist/cjs/storage.d.ts +0 -41
- package/dist/cjs/storage.js +0 -163
- package/dist/cjs/transport.d.ts +0 -35
- package/dist/cjs/transport.js +0 -300
- package/dist/cjs/types.d.ts +0 -206
- package/dist/cjs/vercel-adapter.d.ts +0 -8
- package/dist/cjs/vercel-adapter.js +0 -67
- package/dist/esm/auto.d.ts +0 -13
- package/dist/esm/auto.d.ts.map +0 -1
- package/dist/esm/auto.js +0 -30
- package/dist/esm/auto.js.map +0 -1
- package/dist/esm/cli-mode.d.ts +0 -52
- package/dist/esm/cli-mode.d.ts.map +0 -1
- package/dist/esm/cli-mode.js +0 -59
- package/dist/esm/cli-mode.js.map +0 -1
- package/dist/esm/crypto.d.ts +0 -51
- package/dist/esm/crypto.d.ts.map +0 -1
- package/dist/esm/crypto.js +0 -230
- package/dist/esm/crypto.js.map +0 -1
- package/dist/esm/dev-helper.d.ts +0 -15
- package/dist/esm/dev-helper.d.ts.map +0 -1
- package/dist/esm/dev-helper.js +0 -63
- package/dist/esm/dev-helper.js.map +0 -1
- package/dist/esm/encrypted-storage.d.ts +0 -19
- package/dist/esm/encrypted-storage.d.ts.map +0 -1
- package/dist/esm/encrypted-storage.js +0 -48
- package/dist/esm/encrypted-storage.js.map +0 -1
- package/dist/esm/index.d.ts +0 -129
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -853
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/logger.d.ts +0 -46
- package/dist/esm/logger.d.ts.map +0 -1
- package/dist/esm/logger.js +0 -100
- package/dist/esm/logger.js.map +0 -1
- package/dist/esm/nextjs.d.ts +0 -22
- package/dist/esm/nextjs.d.ts.map +0 -1
- package/dist/esm/nextjs.js +0 -83
- package/dist/esm/nextjs.js.map +0 -1
- package/dist/esm/package.json +0 -1
- package/dist/esm/platform-info.d.ts +0 -74
- package/dist/esm/platform-info.d.ts.map +0 -1
- package/dist/esm/platform-info.js +0 -293
- package/dist/esm/platform-info.js.map +0 -1
- package/dist/esm/polling.d.ts +0 -29
- package/dist/esm/polling.d.ts.map +0 -1
- package/dist/esm/polling.js +0 -76
- package/dist/esm/polling.js.map +0 -1
- package/dist/esm/registry/index.d.ts +0 -43
- package/dist/esm/registry/index.d.ts.map +0 -1
- package/dist/esm/registry/index.js +0 -89
- package/dist/esm/registry/index.js.map +0 -1
- package/dist/esm/registry/knowthat.d.ts +0 -44
- package/dist/esm/registry/knowthat.d.ts.map +0 -1
- package/dist/esm/registry/knowthat.js +0 -220
- package/dist/esm/registry/knowthat.js.map +0 -1
- package/dist/esm/rotation.d.ts +0 -57
- package/dist/esm/rotation.d.ts.map +0 -1
- package/dist/esm/rotation.js +0 -133
- package/dist/esm/rotation.js.map +0 -1
- package/dist/esm/storage.d.ts +0 -65
- package/dist/esm/storage.d.ts.map +0 -1
- package/dist/esm/storage.js +0 -160
- package/dist/esm/storage.js.map +0 -1
- package/dist/esm/transport.d.ts +0 -52
- package/dist/esm/transport.d.ts.map +0 -1
- package/dist/esm/transport.js +0 -340
- package/dist/esm/transport.js.map +0 -1
- package/dist/esm/types.d.ts +0 -293
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -5
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/vercel-adapter.d.ts +0 -26
- package/dist/esm/vercel-adapter.d.ts.map +0 -1
- package/dist/esm/vercel-adapter.js +0 -80
- package/dist/esm/vercel-adapter.js.map +0 -1
- /package/dist/{cjs → auth/oauth}/types.js +0 -0
- /package/dist/{cjs/auto.d.ts → runtime/transports/http/index.d.ts} +0 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getConfig = getConfig;
|
|
7
|
+
exports.readConfig = readConfig;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const webpack_1 = require("webpack");
|
|
11
|
+
const memfs_1 = require("memfs");
|
|
12
|
+
const compiler_context_1 = require("./compiler-context");
|
|
13
|
+
const config_1 = require("./config");
|
|
14
|
+
const constants_1 = require("./config/constants");
|
|
15
|
+
function validateConfig(config) {
|
|
16
|
+
return config_1.configSchema.parse(config);
|
|
17
|
+
}
|
|
18
|
+
// read if exists
|
|
19
|
+
function readConfigFile(pathToConfig) {
|
|
20
|
+
const configPath = path_1.default.resolve(process.cwd(), pathToConfig);
|
|
21
|
+
if (!fs_1.default.existsSync(configPath)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return fs_1.default.readFileSync(configPath, "utf8");
|
|
25
|
+
}
|
|
26
|
+
const configPaths = {
|
|
27
|
+
ts: "xmcp.config.ts",
|
|
28
|
+
json: "xmcp.config.json",
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Parse and validate xmcp config file
|
|
32
|
+
*/
|
|
33
|
+
async function getConfig() {
|
|
34
|
+
const config = await readConfig();
|
|
35
|
+
const { platforms } = compiler_context_1.compilerContext.getContext();
|
|
36
|
+
if (platforms.vercel) {
|
|
37
|
+
// Remove stdio to deploy on vercel
|
|
38
|
+
delete config.stdio;
|
|
39
|
+
}
|
|
40
|
+
return config;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Read config from file or return default
|
|
44
|
+
*/
|
|
45
|
+
async function readConfig() {
|
|
46
|
+
// Simple json config
|
|
47
|
+
const jsonFile = readConfigFile(configPaths.json);
|
|
48
|
+
if (jsonFile) {
|
|
49
|
+
return validateConfig(JSON.parse(jsonFile));
|
|
50
|
+
}
|
|
51
|
+
// TypeScript config, compile it
|
|
52
|
+
const tsFile = readConfigFile(configPaths.ts);
|
|
53
|
+
if (tsFile) {
|
|
54
|
+
try {
|
|
55
|
+
return await compileConfig();
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw new Error(`Failed to compile xmcp.config.ts:\n${error}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Default config
|
|
62
|
+
return {
|
|
63
|
+
stdio: true,
|
|
64
|
+
http: true,
|
|
65
|
+
paths: constants_1.DEFAULT_PATHS_CONFIG,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* If the user is using a typescript config file,
|
|
70
|
+
* we need to bundle it, run it and return its copiled code
|
|
71
|
+
* */
|
|
72
|
+
async function compileConfig() {
|
|
73
|
+
const configPath = path_1.default.resolve(process.cwd(), configPaths.ts);
|
|
74
|
+
// Create memory filesystem
|
|
75
|
+
const memoryFs = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
|
|
76
|
+
// Webpack configuration
|
|
77
|
+
const webpackConfig = {
|
|
78
|
+
mode: "production",
|
|
79
|
+
entry: configPath,
|
|
80
|
+
target: "node",
|
|
81
|
+
output: {
|
|
82
|
+
path: "/",
|
|
83
|
+
filename: "config.js",
|
|
84
|
+
library: {
|
|
85
|
+
type: "commonjs2",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
resolve: {
|
|
89
|
+
extensions: [".ts", ".js"],
|
|
90
|
+
},
|
|
91
|
+
module: {
|
|
92
|
+
rules: [
|
|
93
|
+
{
|
|
94
|
+
test: /\.ts$/,
|
|
95
|
+
use: {
|
|
96
|
+
loader: "swc-loader",
|
|
97
|
+
options: {
|
|
98
|
+
jsc: {
|
|
99
|
+
parser: {
|
|
100
|
+
syntax: "typescript",
|
|
101
|
+
},
|
|
102
|
+
target: "es2020",
|
|
103
|
+
},
|
|
104
|
+
module: {
|
|
105
|
+
type: "commonjs",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
exclude: /node_modules/,
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
externals: {
|
|
114
|
+
webpack: "commonjs2 webpack",
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
const compiler = (0, webpack_1.webpack)(webpackConfig);
|
|
119
|
+
// Use memory filesystem for output
|
|
120
|
+
compiler.outputFileSystem = memoryFs;
|
|
121
|
+
compiler.run((err, stats) => {
|
|
122
|
+
if (err) {
|
|
123
|
+
reject(err);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (stats?.hasErrors()) {
|
|
127
|
+
reject(new Error(stats.toString({ colors: false, errors: true })));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
// Read the bundled code from memory
|
|
132
|
+
const bundledCode = memoryFs.readFileSync("/config.js", "utf8");
|
|
133
|
+
// Create a temporary module to evaluate the bundled code
|
|
134
|
+
const module = { exports: {} };
|
|
135
|
+
const require = (id) => {
|
|
136
|
+
// Handle webpack require
|
|
137
|
+
if (id === "webpack") {
|
|
138
|
+
return webpack_1.webpack;
|
|
139
|
+
}
|
|
140
|
+
throw new Error(`Cannot resolve module: ${id}`);
|
|
141
|
+
};
|
|
142
|
+
// Evaluate the bundled code
|
|
143
|
+
const func = new Function("module", "exports", "require", "__filename", "__dirname", bundledCode);
|
|
144
|
+
func(module, module.exports, require, configPath, path_1.default.dirname(configPath));
|
|
145
|
+
// Extract the config - it could be default export or direct export
|
|
146
|
+
const configExport = module.exports.default || module.exports;
|
|
147
|
+
const config = typeof configExport === "function" ? configExport() : configExport;
|
|
148
|
+
resolve(validateConfig(config));
|
|
149
|
+
}
|
|
150
|
+
catch (evalError) {
|
|
151
|
+
reject(evalError);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function startHttpServer(): Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startHttpServer = startHttpServer;
|
|
4
|
+
const cli_icons_1 = require("../utils/cli-icons");
|
|
5
|
+
const spawn_process_1 = require("../utils/spawn-process");
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
let httpServerProcess = null;
|
|
8
|
+
function spawnHttpServer() {
|
|
9
|
+
const process = (0, child_process_1.spawn)("node", ["dist/http.js"], {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
shell: true,
|
|
12
|
+
});
|
|
13
|
+
(0, spawn_process_1.watchdog)(process);
|
|
14
|
+
return process;
|
|
15
|
+
}
|
|
16
|
+
async function killProcess(process) {
|
|
17
|
+
process.kill("SIGKILL");
|
|
18
|
+
await new Promise((resolve) => {
|
|
19
|
+
process.on("exit", resolve);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async function startHttpServer() {
|
|
23
|
+
if (!httpServerProcess) {
|
|
24
|
+
console.log(`${cli_icons_1.yellowArrow} Starting http server`);
|
|
25
|
+
// first time starting the server
|
|
26
|
+
httpServerProcess = spawnHttpServer();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.log(`${cli_icons_1.yellowArrow} Restarting http server`);
|
|
30
|
+
// restart the server
|
|
31
|
+
await killProcess(httpServerProcess);
|
|
32
|
+
httpServerProcess = spawnHttpServer();
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { type Middleware } from "./types/middleware";
|
|
2
|
+
export type { ToolMetadata, ToolSchema, ToolExtraArguments, InferSchema, } from "./types/tool";
|
|
3
|
+
export type { XmcpConfigOuputSchema as XmcpConfig } from "./compiler/config";
|
|
4
|
+
export { apiKeyAuthMiddleware } from "./auth/api-key";
|
|
5
|
+
export { jwtAuthMiddleware } from "./auth/jwt";
|
|
6
|
+
export type { OAuthConfigOptions } from "./auth/oauth";
|
|
7
|
+
import "./types/declarations";
|
|
8
|
+
export * from "./test/index";
|
|
9
|
+
export * from "./cache/index";
|
|
10
|
+
export * from "./runtime/identity";
|
|
11
|
+
export * from "./runtime/index";
|
|
12
|
+
export { compile } from "./compiler/index";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.compile = exports.jwtAuthMiddleware = exports.apiKeyAuthMiddleware = void 0;
|
|
21
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
22
|
+
dotenv_1.default.config();
|
|
23
|
+
var api_key_1 = require("./auth/api-key");
|
|
24
|
+
Object.defineProperty(exports, "apiKeyAuthMiddleware", { enumerable: true, get: function () { return api_key_1.apiKeyAuthMiddleware; } });
|
|
25
|
+
var jwt_1 = require("./auth/jwt");
|
|
26
|
+
Object.defineProperty(exports, "jwtAuthMiddleware", { enumerable: true, get: function () { return jwt_1.jwtAuthMiddleware; } });
|
|
27
|
+
require("./types/declarations");
|
|
28
|
+
// Test infrastructure (only available when XMCP_ENV=test)
|
|
29
|
+
__exportStar(require("./test/index"), exports);
|
|
30
|
+
// Nonce cache for replay prevention
|
|
31
|
+
__exportStar(require("./cache/index"), exports);
|
|
32
|
+
// Identity management for CLI and runtime
|
|
33
|
+
__exportStar(require("./runtime/identity"), exports);
|
|
34
|
+
// Runtime creation and management
|
|
35
|
+
__exportStar(require("./runtime/index"), exports);
|
|
36
|
+
// Compiler for CLI usage
|
|
37
|
+
var index_1 = require("./compiler/index");
|
|
38
|
+
Object.defineProperty(exports, "compile", { enumerable: true, get: function () { return index_1.compile; } });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
object-assign
|
|
3
|
+
(c) Sindre Sorhus
|
|
4
|
+
@license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/*!
|
|
8
|
+
* fill-range <https://github.com/jonschlinkert/fill-range>
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
11
|
+
* Licensed under the MIT License.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/*!
|
|
15
|
+
* is-extglob <https://github.com/jonschlinkert/is-extglob>
|
|
16
|
+
*
|
|
17
|
+
* Copyright (c) 2014-2016, Jon Schlinkert.
|
|
18
|
+
* Licensed under the MIT License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/*!
|
|
22
|
+
* is-glob <https://github.com/jonschlinkert/is-glob>
|
|
23
|
+
*
|
|
24
|
+
* Copyright (c) 2014-2017, Jon Schlinkert.
|
|
25
|
+
* Released under the MIT License.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/*!
|
|
29
|
+
* is-number <https://github.com/jonschlinkert/is-number>
|
|
30
|
+
*
|
|
31
|
+
* Copyright (c) 2014-present, Jon Schlinkert.
|
|
32
|
+
* Released under the MIT License.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/*!
|
|
36
|
+
* normalize-path <https://github.com/jonschlinkert/normalize-path>
|
|
37
|
+
*
|
|
38
|
+
* Copyright (c) 2014-2018, Jon Schlinkert.
|
|
39
|
+
* Released under the MIT License.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/*!
|
|
43
|
+
* to-regex-range <https://github.com/micromatch/to-regex-range>
|
|
44
|
+
*
|
|
45
|
+
* Copyright (c) 2015-present, Jon Schlinkert.
|
|
46
|
+
* Released under the MIT License.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tests for Audit Logging System
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const audit_js_1 = require("../audit.js");
|
|
8
|
+
(0, vitest_1.describe)("AuditLogger", () => {
|
|
9
|
+
let auditLogger;
|
|
10
|
+
let mockLogFunction;
|
|
11
|
+
let mockIdentity;
|
|
12
|
+
let mockSession;
|
|
13
|
+
(0, vitest_1.beforeEach)(() => {
|
|
14
|
+
mockLogFunction = vitest_1.vi.fn();
|
|
15
|
+
auditLogger = new audit_js_1.AuditLogger({
|
|
16
|
+
logFunction: mockLogFunction,
|
|
17
|
+
});
|
|
18
|
+
mockIdentity = {
|
|
19
|
+
did: "did:web:example.com:agents:test-agent",
|
|
20
|
+
keyId: "key-test-123",
|
|
21
|
+
privateKey: "test-private-key",
|
|
22
|
+
publicKey: "test-public-key",
|
|
23
|
+
createdAt: new Date().toISOString(),
|
|
24
|
+
};
|
|
25
|
+
mockSession = {
|
|
26
|
+
sessionId: "sess_test_123",
|
|
27
|
+
audience: "example.com",
|
|
28
|
+
nonce: "test-nonce-456",
|
|
29
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
30
|
+
createdAt: Math.floor(Date.now() / 1000),
|
|
31
|
+
lastActivity: Math.floor(Date.now() / 1000),
|
|
32
|
+
ttlMinutes: 30,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.describe)("Audit Record Generation", () => {
|
|
36
|
+
(0, vitest_1.it)("should emit audit record on first call per session", async () => {
|
|
37
|
+
const context = {
|
|
38
|
+
identity: mockIdentity,
|
|
39
|
+
session: mockSession,
|
|
40
|
+
requestHash: "sha256:abc123",
|
|
41
|
+
responseHash: "sha256:def456",
|
|
42
|
+
verified: "yes",
|
|
43
|
+
scopeId: "orders.create",
|
|
44
|
+
};
|
|
45
|
+
await auditLogger.logAuditRecord(context);
|
|
46
|
+
(0, vitest_1.expect)(mockLogFunction).toHaveBeenCalledOnce();
|
|
47
|
+
const auditLine = mockLogFunction.mock.calls[0][0];
|
|
48
|
+
(0, vitest_1.expect)(auditLine).toContain("audit.v1");
|
|
49
|
+
(0, vitest_1.expect)(auditLine).toContain("session=sess_test_123");
|
|
50
|
+
(0, vitest_1.expect)(auditLine).toContain("audience=example.com");
|
|
51
|
+
(0, vitest_1.expect)(auditLine).toContain("did=did:web:example.com:agents:test-agent");
|
|
52
|
+
(0, vitest_1.expect)(auditLine).toContain("kid=key-test-123");
|
|
53
|
+
(0, vitest_1.expect)(auditLine).toContain("reqHash=sha256:abc123");
|
|
54
|
+
(0, vitest_1.expect)(auditLine).toContain("resHash=sha256:def456");
|
|
55
|
+
(0, vitest_1.expect)(auditLine).toContain("verified=yes");
|
|
56
|
+
(0, vitest_1.expect)(auditLine).toContain("scope=orders.create");
|
|
57
|
+
});
|
|
58
|
+
(0, vitest_1.it)("should not emit duplicate audit records for same session", async () => {
|
|
59
|
+
const context = {
|
|
60
|
+
identity: mockIdentity,
|
|
61
|
+
session: mockSession,
|
|
62
|
+
requestHash: "sha256:abc123",
|
|
63
|
+
responseHash: "sha256:def456",
|
|
64
|
+
verified: "yes",
|
|
65
|
+
};
|
|
66
|
+
// First call should emit audit record
|
|
67
|
+
await auditLogger.logAuditRecord(context);
|
|
68
|
+
(0, vitest_1.expect)(mockLogFunction).toHaveBeenCalledOnce();
|
|
69
|
+
// Second call for same session should not emit
|
|
70
|
+
await auditLogger.logAuditRecord(context);
|
|
71
|
+
(0, vitest_1.expect)(mockLogFunction).toHaveBeenCalledOnce(); // Still only once
|
|
72
|
+
});
|
|
73
|
+
(0, vitest_1.it)("should emit separate audit records for different sessions", async () => {
|
|
74
|
+
const context1 = {
|
|
75
|
+
identity: mockIdentity,
|
|
76
|
+
session: mockSession,
|
|
77
|
+
requestHash: "sha256:abc123",
|
|
78
|
+
responseHash: "sha256:def456",
|
|
79
|
+
verified: "yes",
|
|
80
|
+
};
|
|
81
|
+
const context2 = {
|
|
82
|
+
identity: mockIdentity,
|
|
83
|
+
session: { ...mockSession, sessionId: "sess_test_456" },
|
|
84
|
+
requestHash: "sha256:ghi789",
|
|
85
|
+
responseHash: "sha256:jkl012",
|
|
86
|
+
verified: "no",
|
|
87
|
+
};
|
|
88
|
+
await auditLogger.logAuditRecord(context1);
|
|
89
|
+
await auditLogger.logAuditRecord(context2);
|
|
90
|
+
(0, vitest_1.expect)(mockLogFunction).toHaveBeenCalledTimes(2);
|
|
91
|
+
});
|
|
92
|
+
(0, vitest_1.it)('should use "-" for missing scope', async () => {
|
|
93
|
+
const context = {
|
|
94
|
+
identity: mockIdentity,
|
|
95
|
+
session: mockSession,
|
|
96
|
+
requestHash: "sha256:abc123",
|
|
97
|
+
responseHash: "sha256:def456",
|
|
98
|
+
verified: "yes",
|
|
99
|
+
// No scopeId provided
|
|
100
|
+
};
|
|
101
|
+
await auditLogger.logAuditRecord(context);
|
|
102
|
+
const auditLine = mockLogFunction.mock.calls[0][0];
|
|
103
|
+
(0, vitest_1.expect)(auditLine).toContain("scope=-");
|
|
104
|
+
});
|
|
105
|
+
(0, vitest_1.it)("should not log when disabled", async () => {
|
|
106
|
+
const disabledLogger = new audit_js_1.AuditLogger({
|
|
107
|
+
enabled: false,
|
|
108
|
+
logFunction: mockLogFunction,
|
|
109
|
+
});
|
|
110
|
+
const context = {
|
|
111
|
+
identity: mockIdentity,
|
|
112
|
+
session: mockSession,
|
|
113
|
+
requestHash: "sha256:abc123",
|
|
114
|
+
responseHash: "sha256:def456",
|
|
115
|
+
verified: "yes",
|
|
116
|
+
};
|
|
117
|
+
await disabledLogger.logAuditRecord(context);
|
|
118
|
+
(0, vitest_1.expect)(mockLogFunction).not.toHaveBeenCalled();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
(0, vitest_1.describe)("Audit Line Format", () => {
|
|
122
|
+
(0, vitest_1.it)("should format audit line with frozen format", async () => {
|
|
123
|
+
const context = {
|
|
124
|
+
identity: mockIdentity,
|
|
125
|
+
session: mockSession,
|
|
126
|
+
requestHash: "sha256:abc123",
|
|
127
|
+
responseHash: "sha256:def456",
|
|
128
|
+
verified: "yes",
|
|
129
|
+
scopeId: "orders.create",
|
|
130
|
+
};
|
|
131
|
+
await auditLogger.logAuditRecord(context);
|
|
132
|
+
const auditLine = mockLogFunction.mock.calls[0][0];
|
|
133
|
+
const parts = auditLine.split(" ");
|
|
134
|
+
(0, vitest_1.expect)(parts[0]).toBe("audit.v1");
|
|
135
|
+
(0, vitest_1.expect)(parts[1]).toMatch(/^ts=\d+$/);
|
|
136
|
+
(0, vitest_1.expect)(parts[2]).toBe("session=sess_test_123");
|
|
137
|
+
(0, vitest_1.expect)(parts[3]).toBe("audience=example.com");
|
|
138
|
+
(0, vitest_1.expect)(parts[4]).toBe("did=did:web:example.com:agents:test-agent");
|
|
139
|
+
(0, vitest_1.expect)(parts[5]).toBe("kid=key-test-123");
|
|
140
|
+
(0, vitest_1.expect)(parts[6]).toBe("reqHash=sha256:abc123");
|
|
141
|
+
(0, vitest_1.expect)(parts[7]).toBe("resHash=sha256:def456");
|
|
142
|
+
(0, vitest_1.expect)(parts[8]).toBe("verified=yes");
|
|
143
|
+
(0, vitest_1.expect)(parts[9]).toBe("scope=orders.create");
|
|
144
|
+
});
|
|
145
|
+
(0, vitest_1.it)("should include timestamp in unix seconds", async () => {
|
|
146
|
+
const beforeTime = Math.floor(Date.now() / 1000);
|
|
147
|
+
const context = {
|
|
148
|
+
identity: mockIdentity,
|
|
149
|
+
session: mockSession,
|
|
150
|
+
requestHash: "sha256:abc123",
|
|
151
|
+
responseHash: "sha256:def456",
|
|
152
|
+
verified: "yes",
|
|
153
|
+
};
|
|
154
|
+
await auditLogger.logAuditRecord(context);
|
|
155
|
+
const afterTime = Math.floor(Date.now() / 1000);
|
|
156
|
+
const auditLine = mockLogFunction.mock.calls[0][0];
|
|
157
|
+
const tsMatch = auditLine.match(/ts=(\d+)/);
|
|
158
|
+
(0, vitest_1.expect)(tsMatch).toBeTruthy();
|
|
159
|
+
const timestamp = parseInt(tsMatch[1], 10);
|
|
160
|
+
(0, vitest_1.expect)(timestamp).toBeGreaterThanOrEqual(beforeTime);
|
|
161
|
+
(0, vitest_1.expect)(timestamp).toBeLessThanOrEqual(afterTime);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
(0, vitest_1.describe)("Configuration and Statistics", () => {
|
|
165
|
+
(0, vitest_1.it)("should provide accurate statistics", async () => {
|
|
166
|
+
const context = {
|
|
167
|
+
identity: mockIdentity,
|
|
168
|
+
session: mockSession,
|
|
169
|
+
requestHash: "sha256:abc123",
|
|
170
|
+
responseHash: "sha256:def456",
|
|
171
|
+
verified: "yes",
|
|
172
|
+
};
|
|
173
|
+
const initialStats = auditLogger.getStats();
|
|
174
|
+
(0, vitest_1.expect)(initialStats.sessionsLogged).toBe(0);
|
|
175
|
+
(0, vitest_1.expect)(initialStats.enabled).toBe(true);
|
|
176
|
+
(0, vitest_1.expect)(initialStats.includePayloads).toBe(false);
|
|
177
|
+
await auditLogger.logAuditRecord(context);
|
|
178
|
+
const finalStats = auditLogger.getStats();
|
|
179
|
+
(0, vitest_1.expect)(finalStats.sessionsLogged).toBe(1);
|
|
180
|
+
});
|
|
181
|
+
(0, vitest_1.it)("should allow configuration updates", () => {
|
|
182
|
+
auditLogger.updateConfig({ enabled: false, includePayloads: true });
|
|
183
|
+
const stats = auditLogger.getStats();
|
|
184
|
+
(0, vitest_1.expect)(stats.enabled).toBe(false);
|
|
185
|
+
(0, vitest_1.expect)(stats.includePayloads).toBe(true);
|
|
186
|
+
});
|
|
187
|
+
(0, vitest_1.it)("should clear session log", async () => {
|
|
188
|
+
const context = {
|
|
189
|
+
identity: mockIdentity,
|
|
190
|
+
session: mockSession,
|
|
191
|
+
requestHash: "sha256:abc123",
|
|
192
|
+
responseHash: "sha256:def456",
|
|
193
|
+
verified: "yes",
|
|
194
|
+
};
|
|
195
|
+
await auditLogger.logAuditRecord(context);
|
|
196
|
+
(0, vitest_1.expect)(auditLogger.getStats().sessionsLogged).toBe(1);
|
|
197
|
+
auditLogger.clearSessionLog();
|
|
198
|
+
(0, vitest_1.expect)(auditLogger.getStats().sessionsLogged).toBe(0);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
(0, vitest_1.describe)("Key Rotation Audit", () => {
|
|
203
|
+
let mockLogFunction;
|
|
204
|
+
let mockIdentity;
|
|
205
|
+
(0, vitest_1.beforeEach)(() => {
|
|
206
|
+
mockLogFunction = vitest_1.vi.fn();
|
|
207
|
+
mockIdentity = {
|
|
208
|
+
did: "did:web:example.com:agents:test-agent",
|
|
209
|
+
keyId: "key-new-456",
|
|
210
|
+
privateKey: "test-private-key",
|
|
211
|
+
publicKey: "test-public-key",
|
|
212
|
+
createdAt: new Date().toISOString(),
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
(0, vitest_1.it)("should log key rotation audit record", () => {
|
|
216
|
+
const context = {
|
|
217
|
+
identity: mockIdentity,
|
|
218
|
+
oldKeyId: "key-old-123",
|
|
219
|
+
newKeyId: "key-new-456",
|
|
220
|
+
mode: "dev",
|
|
221
|
+
delegated: "no",
|
|
222
|
+
force: "no",
|
|
223
|
+
};
|
|
224
|
+
(0, audit_js_1.logKeyRotationAudit)(context, mockLogFunction);
|
|
225
|
+
(0, vitest_1.expect)(mockLogFunction).toHaveBeenCalledOnce();
|
|
226
|
+
const auditLine = mockLogFunction.mock.calls[0][0];
|
|
227
|
+
(0, vitest_1.expect)(auditLine).toContain("keys.rotate.v1");
|
|
228
|
+
(0, vitest_1.expect)(auditLine).toContain("did=did:web:example.com:agents:test-agent");
|
|
229
|
+
(0, vitest_1.expect)(auditLine).toContain("oldKid=key-old-123");
|
|
230
|
+
(0, vitest_1.expect)(auditLine).toContain("newKid=key-new-456");
|
|
231
|
+
(0, vitest_1.expect)(auditLine).toContain("mode=dev");
|
|
232
|
+
(0, vitest_1.expect)(auditLine).toContain("delegated=no");
|
|
233
|
+
(0, vitest_1.expect)(auditLine).toContain("force=no");
|
|
234
|
+
});
|
|
235
|
+
(0, vitest_1.it)("should log production key rotation with delegation", () => {
|
|
236
|
+
const context = {
|
|
237
|
+
identity: mockIdentity,
|
|
238
|
+
oldKeyId: "key-old-123",
|
|
239
|
+
newKeyId: "key-new-456",
|
|
240
|
+
mode: "prod",
|
|
241
|
+
delegated: "yes",
|
|
242
|
+
force: "no",
|
|
243
|
+
};
|
|
244
|
+
(0, audit_js_1.logKeyRotationAudit)(context, mockLogFunction);
|
|
245
|
+
const auditLine = mockLogFunction.mock.calls[0][0];
|
|
246
|
+
(0, vitest_1.expect)(auditLine).toContain("mode=prod");
|
|
247
|
+
(0, vitest_1.expect)(auditLine).toContain("delegated=yes");
|
|
248
|
+
});
|
|
249
|
+
(0, vitest_1.it)("should log forced key rotation", () => {
|
|
250
|
+
const context = {
|
|
251
|
+
identity: mockIdentity,
|
|
252
|
+
oldKeyId: "key-old-123",
|
|
253
|
+
newKeyId: "key-new-456",
|
|
254
|
+
mode: "prod",
|
|
255
|
+
delegated: "no",
|
|
256
|
+
force: "yes",
|
|
257
|
+
};
|
|
258
|
+
(0, audit_js_1.logKeyRotationAudit)(context, mockLogFunction);
|
|
259
|
+
const auditLine = mockLogFunction.mock.calls[0][0];
|
|
260
|
+
(0, vitest_1.expect)(auditLine).toContain("force=yes");
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
(0, vitest_1.describe)("Audit Line Parsing", () => {
|
|
264
|
+
(0, vitest_1.it)("should parse valid audit line", () => {
|
|
265
|
+
const auditLine = "audit.v1 ts=1640995200 session=sess_test_123 audience=example.com did=did:web:example.com:agents:test-agent kid=key-test-123 reqHash=sha256:abc123 resHash=sha256:def456 verified=yes scope=orders.create";
|
|
266
|
+
const record = (0, audit_js_1.parseAuditLine)(auditLine);
|
|
267
|
+
(0, vitest_1.expect)(record).toBeTruthy();
|
|
268
|
+
(0, vitest_1.expect)(record.version).toBe("audit.v1");
|
|
269
|
+
(0, vitest_1.expect)(record.ts).toBe(1640995200);
|
|
270
|
+
(0, vitest_1.expect)(record.session).toBe("sess_test_123");
|
|
271
|
+
(0, vitest_1.expect)(record.audience).toBe("example.com");
|
|
272
|
+
(0, vitest_1.expect)(record.did).toBe("did:web:example.com:agents:test-agent");
|
|
273
|
+
(0, vitest_1.expect)(record.kid).toBe("key-test-123");
|
|
274
|
+
(0, vitest_1.expect)(record.reqHash).toBe("sha256:abc123");
|
|
275
|
+
(0, vitest_1.expect)(record.resHash).toBe("sha256:def456");
|
|
276
|
+
(0, vitest_1.expect)(record.verified).toBe("yes");
|
|
277
|
+
(0, vitest_1.expect)(record.scope).toBe("orders.create");
|
|
278
|
+
});
|
|
279
|
+
(0, vitest_1.it)("should parse audit line with no scope", () => {
|
|
280
|
+
const auditLine = "audit.v1 ts=1640995200 session=sess_test_123 audience=example.com did=did:web:example.com:agents:test-agent kid=key-test-123 reqHash=sha256:abc123 resHash=sha256:def456 verified=no scope=-";
|
|
281
|
+
const record = (0, audit_js_1.parseAuditLine)(auditLine);
|
|
282
|
+
(0, vitest_1.expect)(record).toBeTruthy();
|
|
283
|
+
(0, vitest_1.expect)(record.verified).toBe("no");
|
|
284
|
+
(0, vitest_1.expect)(record.scope).toBe("-");
|
|
285
|
+
});
|
|
286
|
+
(0, vitest_1.it)("should return null for invalid audit line", () => {
|
|
287
|
+
const invalidLines = [
|
|
288
|
+
"invalid line",
|
|
289
|
+
"audit.v1 incomplete",
|
|
290
|
+
"wrong.version ts=123 session=test",
|
|
291
|
+
"audit.v1 ts=invalid session=test audience=test",
|
|
292
|
+
];
|
|
293
|
+
for (const line of invalidLines) {
|
|
294
|
+
(0, vitest_1.expect)((0, audit_js_1.parseAuditLine)(line)).toBeNull();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
(0, vitest_1.describe)("Audit Record Validation", () => {
|
|
299
|
+
(0, vitest_1.it)("should validate correct audit record", () => {
|
|
300
|
+
const validRecord = {
|
|
301
|
+
version: "audit.v1",
|
|
302
|
+
ts: 1640995200,
|
|
303
|
+
session: "sess_test_123",
|
|
304
|
+
audience: "example.com",
|
|
305
|
+
did: "did:web:example.com:agents:test-agent",
|
|
306
|
+
kid: "key-test-123",
|
|
307
|
+
reqHash: "sha256:abc123",
|
|
308
|
+
resHash: "sha256:def456",
|
|
309
|
+
verified: "yes",
|
|
310
|
+
scope: "orders.create",
|
|
311
|
+
};
|
|
312
|
+
(0, vitest_1.expect)((0, audit_js_1.validateAuditRecord)(validRecord)).toBe(true);
|
|
313
|
+
});
|
|
314
|
+
(0, vitest_1.it)("should reject invalid audit records", () => {
|
|
315
|
+
const invalidRecords = [
|
|
316
|
+
null,
|
|
317
|
+
undefined,
|
|
318
|
+
{},
|
|
319
|
+
{ version: "wrong.version" },
|
|
320
|
+
{ version: "audit.v1", ts: "invalid" },
|
|
321
|
+
{ version: "audit.v1", ts: 123, verified: "maybe" },
|
|
322
|
+
{ version: "audit.v1", ts: 123, reqHash: "invalid-hash" },
|
|
323
|
+
];
|
|
324
|
+
for (const record of invalidRecords) {
|
|
325
|
+
(0, vitest_1.expect)((0, audit_js_1.validateAuditRecord)(record)).toBe(false);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
});
|