@kya-os/contracts 1.5.4-canary.3 → 1.6.1

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.
@@ -9,11 +9,13 @@
9
9
  * @module @kya-os/contracts/tool-protection
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DelegationRequiredErrorDataSchema = exports.ToolProtectionResponseSchema = exports.ToolProtectionMapSchema = exports.ToolProtectionSchema = void 0;
12
+ exports.DelegationRequiredErrorDataSchema = exports.ToolProtectionResponseSchema = exports.ToolProtectionMapSchema = exports.ToolProtectionSchema = exports.AuthorizationRequirementSchema = void 0;
13
13
  exports.isToolProtection = isToolProtection;
14
14
  exports.isToolProtectionMap = isToolProtectionMap;
15
15
  exports.isToolProtectionResponse = isToolProtectionResponse;
16
16
  exports.isDelegationRequiredErrorData = isDelegationRequiredErrorData;
17
+ exports.isAuthorizationRequirement = isAuthorizationRequirement;
18
+ exports.hasOAuthAuthorization = hasOAuthAuthorization;
17
19
  exports.validateToolProtection = validateToolProtection;
18
20
  exports.validateToolProtectionMap = validateToolProtectionMap;
19
21
  exports.validateToolProtectionResponse = validateToolProtectionResponse;
@@ -22,14 +24,42 @@ exports.toolRequiresDelegation = toolRequiresDelegation;
22
24
  exports.getToolRequiredScopes = getToolRequiredScopes;
23
25
  exports.getToolRiskLevel = getToolRiskLevel;
24
26
  exports.createDelegationRequiredError = createDelegationRequiredError;
27
+ exports.normalizeToolProtection = normalizeToolProtection;
25
28
  const zod_1 = require("zod");
26
29
  /**
27
30
  * Zod Schemas for Validation
28
31
  */
32
+ exports.AuthorizationRequirementSchema = zod_1.z.discriminatedUnion('type', [
33
+ zod_1.z.object({
34
+ type: zod_1.z.literal('oauth'),
35
+ provider: zod_1.z.string(),
36
+ requiredScopes: zod_1.z.array(zod_1.z.string()).optional(),
37
+ }),
38
+ zod_1.z.object({
39
+ type: zod_1.z.literal('mdl'),
40
+ issuer: zod_1.z.string(),
41
+ credentialType: zod_1.z.string().optional(),
42
+ }),
43
+ zod_1.z.object({
44
+ type: zod_1.z.literal('idv'),
45
+ provider: zod_1.z.string(),
46
+ verificationLevel: zod_1.z.enum(['basic', 'enhanced', 'loa3']).optional(),
47
+ }),
48
+ zod_1.z.object({
49
+ type: zod_1.z.literal('credential'),
50
+ credentialType: zod_1.z.string(),
51
+ issuer: zod_1.z.string().optional(),
52
+ }),
53
+ zod_1.z.object({
54
+ type: zod_1.z.literal('none'),
55
+ }),
56
+ ]);
29
57
  exports.ToolProtectionSchema = zod_1.z.object({
30
58
  requiresDelegation: zod_1.z.boolean(),
31
59
  requiredScopes: zod_1.z.array(zod_1.z.string()),
32
- riskLevel: zod_1.z.enum(['low', 'medium', 'high', 'critical']).optional()
60
+ riskLevel: zod_1.z.enum(['low', 'medium', 'high', 'critical']).optional(),
61
+ oauthProvider: zod_1.z.string().optional(), // Phase 2: Tool-specific OAuth provider
62
+ authorization: exports.AuthorizationRequirementSchema.optional(),
33
63
  });
34
64
  exports.ToolProtectionMapSchema = zod_1.z.record(zod_1.z.string(), exports.ToolProtectionSchema);
35
65
  exports.ToolProtectionResponseSchema = zod_1.z.object({
@@ -62,6 +92,18 @@ function isToolProtectionResponse(obj) {
62
92
  function isDelegationRequiredErrorData(obj) {
63
93
  return exports.DelegationRequiredErrorDataSchema.safeParse(obj).success;
64
94
  }
95
+ /**
96
+ * Type guard to check if an object is a valid AuthorizationRequirement
97
+ */
98
+ function isAuthorizationRequirement(obj) {
99
+ return exports.AuthorizationRequirementSchema.safeParse(obj).success;
100
+ }
101
+ /**
102
+ * Type guard to check if a ToolProtection has OAuth authorization
103
+ */
104
+ function hasOAuthAuthorization(protection) {
105
+ return protection.authorization?.type === 'oauth';
106
+ }
65
107
  /**
66
108
  * Validation Functions
67
109
  */
@@ -111,3 +153,48 @@ function createDelegationRequiredError(toolName, requiredScopes, consentUrl) {
111
153
  authorizationUrl: consentUrl // Include both for compatibility
112
154
  };
113
155
  }
156
+ /**
157
+ * Normalize tool protection configuration
158
+ * Migrates legacy oauthProvider field to authorization object
159
+ *
160
+ * - Migrates `oauthProvider` → `authorization: { type: 'oauth', provider: ... }`
161
+ * - Ensures `authorization` field is present when `requiresDelegation=true`
162
+ * - Returns fully normalized ToolProtection object
163
+ *
164
+ * @param raw - Raw tool protection data (may have legacy fields or be partial)
165
+ * @returns Normalized ToolProtection object
166
+ *
167
+ * // TODO: Remove normalizeToolProtection() when all tools migrated (target: Phase 3)
168
+ */
169
+ function normalizeToolProtection(raw) {
170
+ // Ensure we have required fields (provide defaults for partial input)
171
+ const normalized = {
172
+ requiresDelegation: raw.requiresDelegation ?? false,
173
+ requiredScopes: raw.requiredScopes ?? [],
174
+ ...(raw.riskLevel && { riskLevel: raw.riskLevel }),
175
+ ...(raw.oauthProvider && { oauthProvider: raw.oauthProvider }),
176
+ };
177
+ // If authorization is already present, use it
178
+ if (raw.authorization) {
179
+ normalized.authorization = raw.authorization;
180
+ return normalized;
181
+ }
182
+ // Migrate oauthProvider to authorization
183
+ if (raw.oauthProvider) {
184
+ normalized.authorization = {
185
+ type: 'oauth',
186
+ provider: raw.oauthProvider,
187
+ };
188
+ // Keep oauthProvider for backward compatibility until Phase 3
189
+ return normalized;
190
+ }
191
+ // Default for requiresDelegation=true without specific auth: type='none' (consent only)
192
+ // But ONLY if authorization is missing entirely
193
+ if (normalized.requiresDelegation && !normalized.authorization && !normalized.oauthProvider) {
194
+ // We don't automatically set type='none' here to allow
195
+ // ProviderResolver to do its scope inference fallback logic.
196
+ // The fallback logic will eventually be moved into an AuthorizationService.
197
+ return normalized;
198
+ }
199
+ return normalized;
200
+ }
@@ -0,0 +1 @@
1
+ export * from "../verifier";
@@ -0,0 +1,18 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Re-export everything from the main verifier file
18
+ __exportStar(require("../verifier"), exports);
@@ -209,12 +209,12 @@ export declare const AgentDocumentSchema: z.ZodObject<{
209
209
  description?: string | undefined;
210
210
  }>>;
211
211
  }, "strip", z.ZodTypeAny, {
212
- id: string;
213
212
  capabilities: {
214
213
  'mcp-i': ("handshake" | "signing" | "verification" | "delegation" | "proof-generation")[];
215
214
  } & {
216
215
  [k: string]: string[];
217
216
  };
217
+ id: string;
218
218
  metadata?: {
219
219
  version?: string | undefined;
220
220
  name?: string | undefined;
@@ -222,12 +222,12 @@ export declare const AgentDocumentSchema: z.ZodObject<{
222
222
  description?: string | undefined;
223
223
  } | undefined;
224
224
  }, {
225
- id: string;
226
225
  capabilities: {
227
226
  'mcp-i': ("handshake" | "signing" | "verification" | "delegation" | "proof-generation")[];
228
227
  } & {
229
228
  [k: string]: string[];
230
229
  };
230
+ id: string;
231
231
  metadata?: {
232
232
  version?: string | undefined;
233
233
  name?: string | undefined;
package/package.json CHANGED
@@ -1,156 +1,99 @@
1
1
  {
2
2
  "name": "@kya-os/contracts",
3
- "version": "1.5.4-canary.3",
4
- "description": "Shared types and schemas for XMCP-I ecosystem",
5
- "type": "commonjs",
6
- "sideEffects": false,
7
- "main": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
3
+ "version": "1.6.1",
4
+ "description": "Shared contracts, types, and schemas for MCP-I framework",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
9
7
  "exports": {
10
8
  ".": {
11
9
  "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.js"
14
- },
15
- "./handshake": {
16
- "types": "./dist/handshake.d.ts",
17
- "import": "./dist/handshake.js",
18
- "require": "./dist/handshake.js"
19
- },
20
- "./proof": {
21
- "types": "./dist/proof/index.d.ts",
22
- "import": "./dist/proof/index.js",
23
- "require": "./dist/proof/index.js"
24
- },
25
- "./verifier": {
26
- "types": "./dist/verifier.d.ts",
27
- "import": "./dist/verifier.js",
28
- "require": "./dist/verifier.js"
29
- },
30
- "./registry": {
31
- "types": "./dist/registry.d.ts",
32
- "import": "./dist/registry.js",
33
- "require": "./dist/registry.js"
34
- },
35
- "./cli": {
36
- "types": "./dist/cli.d.ts",
37
- "import": "./dist/cli.js",
38
- "require": "./dist/cli.js"
10
+ "default": "./dist/index.js"
39
11
  },
40
- "./test": {
41
- "types": "./dist/test.d.ts",
42
- "import": "./dist/test.js",
43
- "require": "./dist/test.js"
44
- },
45
- "./did": {
46
- "types": "./dist/did/index.d.ts",
47
- "import": "./dist/did/index.js",
48
- "require": "./dist/did/index.js"
49
- },
50
- "./vc": {
51
- "types": "./dist/vc/index.d.ts",
52
- "import": "./dist/vc/index.js",
53
- "require": "./dist/vc/index.js"
12
+ "./consent": {
13
+ "types": "./dist/consent/index.d.ts",
14
+ "default": "./dist/consent/index.js"
54
15
  },
55
16
  "./delegation": {
56
17
  "types": "./dist/delegation/index.d.ts",
57
- "import": "./dist/delegation/index.js",
58
- "require": "./dist/delegation/index.js"
18
+ "default": "./dist/delegation/index.js"
19
+ },
20
+ "./agentshield-api": {
21
+ "types": "./dist/agentshield-api/index.d.ts",
22
+ "default": "./dist/agentshield-api/index.js"
59
23
  },
60
24
  "./runtime": {
61
25
  "types": "./dist/runtime/index.d.ts",
62
- "import": "./dist/runtime/index.js",
63
- "require": "./dist/runtime/index.js"
64
- },
65
- "./tlkrc": {
66
- "types": "./dist/tlkrc/index.d.ts",
67
- "import": "./dist/tlkrc/index.js",
68
- "require": "./dist/tlkrc/index.js"
26
+ "default": "./dist/runtime/index.js"
69
27
  },
70
- "./env": {
71
- "types": "./dist/env/index.d.ts",
72
- "import": "./dist/env/index.js",
73
- "require": "./dist/env/index.js"
74
- },
75
- "./agentshield-api": {
76
- "types": "./dist/agentshield-api/index.d.ts",
77
- "import": "./dist/agentshield-api/index.js",
78
- "require": "./dist/agentshield-api/index.js"
28
+ "./proof": {
29
+ "types": "./dist/proof/index.d.ts",
30
+ "default": "./dist/proof/index.js"
79
31
  },
80
32
  "./tool-protection": {
81
33
  "types": "./dist/tool-protection/index.d.ts",
82
- "import": "./dist/tool-protection/index.js",
83
- "require": "./dist/tool-protection/index.js"
34
+ "default": "./dist/tool-protection/index.js"
35
+ },
36
+ "./config": {
37
+ "types": "./dist/config/index.d.ts",
38
+ "default": "./dist/config/index.js"
39
+ },
40
+ "./audit": {
41
+ "types": "./dist/audit/index.d.ts",
42
+ "default": "./dist/audit/index.js"
43
+ },
44
+ "./verifier": {
45
+ "types": "./dist/verifier/index.d.ts",
46
+ "default": "./dist/verifier/index.js"
47
+ },
48
+ "./handshake": {
49
+ "types": "./dist/handshake.d.ts",
50
+ "default": "./dist/handshake.js"
84
51
  },
85
52
  "./well-known": {
86
53
  "types": "./dist/well-known/index.d.ts",
87
- "import": "./dist/well-known/index.js",
88
- "require": "./dist/well-known/index.js"
54
+ "default": "./dist/well-known/index.js"
89
55
  },
90
- "./config": {
91
- "types": "./dist/config/index.d.ts",
92
- "import": "./dist/config/index.js",
93
- "require": "./dist/config/index.js"
56
+ "./cli": {
57
+ "types": "./dist/cli.d.ts",
58
+ "default": "./dist/cli.js"
94
59
  },
95
- "./dashboard-config": {
96
- "types": "./dist/dashboard-config/index.d.ts",
97
- "import": "./dist/dashboard-config/index.js",
98
- "require": "./dist/dashboard-config/index.js"
60
+ "./test": {
61
+ "types": "./dist/test.d.ts",
62
+ "default": "./dist/test.js"
99
63
  },
100
- "./consent": {
101
- "types": "./dist/consent/index.d.ts",
102
- "import": "./dist/consent/index.js",
103
- "require": "./dist/consent/index.js"
64
+ "./registry": {
65
+ "types": "./dist/registry.d.ts",
66
+ "default": "./dist/registry.js"
104
67
  }
105
68
  },
106
- "files": [
107
- "dist/**/*.js",
108
- "dist/**/*.d.ts",
109
- "!dist/**/*.map",
110
- "!dist/**/__tests__/**",
111
- "!dist/**/__fixtures__/**",
112
- "!dist/**/*.spec.*",
113
- "!dist/**/*.test.*",
114
- "!README.md",
115
- "!*.md",
116
- "!CHANGELOG.md"
117
- ],
118
69
  "scripts": {
119
70
  "build": "tsc -p tsconfig.build.json && npm run emit-schemas",
120
71
  "emit-schemas": "node scripts/emit-schemas.js",
121
- "clean": "rm -rf dist && rm -f *.tsbuildinfo",
122
- "dev": "tsc -p tsconfig.build.json --watch",
123
- "type-check": "tsc --noEmit",
124
72
  "test": "vitest run",
125
- "test:watch": "vitest",
126
73
  "test:coverage": "vitest run --coverage",
127
- "prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-dependencies.js"
74
+ "test:watch": "vitest",
75
+ "lint": "eslint .",
76
+ "format": "prettier --write \"src/**/*.{ts,tsx}\"",
77
+ "clean": "rm -rf dist .turbo node_modules",
78
+ "prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-no-workspace.js"
79
+ },
80
+ "sideEffects": false,
81
+ "dependencies": {
82
+ "zod": "^3.23.8"
128
83
  },
129
84
  "devDependencies": {
130
- "@types/node": "^20.0.0",
85
+ "@types/node": "^20.14.9",
131
86
  "@vitest/coverage-v8": "^4.0.5",
132
- "ajv": "^8.12.0",
133
- "ajv-formats": "^2.1.1",
134
- "fast-check": "^3.15.0",
135
- "typescript": "^5.0.0",
136
- "vitest": "^4.0.5",
137
- "zod-to-json-schema": "^3.22.0"
87
+ "eslint": "^8.57.0",
88
+ "typescript": "^5.5.3",
89
+ "vitest": "^4.0.5"
138
90
  },
139
- "dependencies": {
140
- "zod": "^3.22.0"
141
- },
142
- "keywords": [
143
- "xmcp",
144
- "mcp",
145
- "identity",
146
- "types",
147
- "contracts"
91
+ "files": [
92
+ "dist",
93
+ "package.json",
94
+ "README.md"
148
95
  ],
149
- "author": "KYA OS",
150
- "license": "MIT",
151
- "repository": {
152
- "type": "git",
153
- "url": "https://github.com/kya-os/xmcp-i.git",
154
- "directory": "packages/contracts"
96
+ "publishConfig": {
97
+ "access": "public"
155
98
  }
156
99
  }