@kya-os/checkpoint-shared 1.4.0 → 1.5.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/CHANGELOG.md +32 -0
- package/dist/beacon-types/index.d.mts +441 -432
- package/dist/beacon-types/index.d.mts.map +1 -0
- package/dist/beacon-types/index.d.ts +441 -432
- package/dist/beacon-types/index.d.ts.map +1 -0
- package/dist/beacon-types/index.js +198 -182
- package/dist/beacon-types/index.mjs +197 -179
- package/dist/beacon-types/index.mjs.map +1 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +5 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +1 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +5 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +1 -0
- package/dist/browser-posture-cookie.d.mts +2 -0
- package/dist/browser-posture-cookie.d.ts +2 -0
- package/dist/browser-posture-cookie.js +1 -0
- package/dist/browser-posture-cookie.mjs +2 -0
- package/dist/browser-posture-cookie.mjs.map +1 -0
- package/dist/browser-posture-report.d.mts +48 -44
- package/dist/browser-posture-report.d.mts.map +1 -0
- package/dist/browser-posture-report.d.ts +48 -44
- package/dist/browser-posture-report.d.ts.map +1 -0
- package/dist/browser-posture-report.js +1 -1
- package/dist/browser-posture-report.mjs +2 -1
- package/dist/browser-posture-report.mjs.map +1 -0
- package/dist/browser-posture.d.mts +80 -75
- package/dist/browser-posture.d.mts.map +1 -0
- package/dist/browser-posture.d.ts +80 -75
- package/dist/browser-posture.d.ts.map +1 -0
- package/dist/browser-posture.js +159 -18993
- package/dist/browser-posture.mjs +158 -18990
- package/dist/browser-posture.mjs.map +1 -0
- package/dist/browser.d.mts +323 -316
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.d.ts +323 -316
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +2 -1
- package/dist/browser.mjs.map +1 -0
- package/dist/canonical-signer/index.d.mts +38 -33
- package/dist/canonical-signer/index.d.mts.map +1 -0
- package/dist/canonical-signer/index.d.ts +38 -33
- package/dist/canonical-signer/index.d.ts.map +1 -0
- package/dist/canonical-signer/index.js +411 -181
- package/dist/canonical-signer/index.mjs +383 -175
- package/dist/canonical-signer/index.mjs.map +1 -0
- package/dist/clearance.d.mts +30 -0
- package/dist/clearance.d.mts.map +1 -0
- package/dist/clearance.d.ts +30 -0
- package/dist/clearance.d.ts.map +1 -0
- package/dist/clearance.js +120 -0
- package/dist/clearance.mjs +112 -0
- package/dist/clearance.mjs.map +1 -0
- package/dist/client-ip-1y2iXAYW.js +237 -0
- package/dist/client-ip-HOfe6ucV.mjs +215 -0
- package/dist/client-ip-HOfe6ucV.mjs.map +1 -0
- package/dist/deploy/index.d.mts +339 -339
- package/dist/deploy/index.d.mts.map +1 -0
- package/dist/deploy/index.d.ts +339 -339
- package/dist/deploy/index.d.ts.map +1 -0
- package/dist/deploy/index.js +505 -413
- package/dist/deploy/index.mjs +504 -410
- package/dist/deploy/index.mjs.map +1 -0
- package/dist/errors/index.d.mts +101 -101
- package/dist/errors/index.d.mts.map +1 -0
- package/dist/errors/index.d.ts +101 -101
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +341 -314
- package/dist/errors/index.mjs +340 -311
- package/dist/errors/index.mjs.map +1 -0
- package/dist/external-jr_S4iSS.d.mts +4187 -0
- package/dist/external-jr_S4iSS.d.mts.map +1 -0
- package/dist/external-jr_S4iSS.d.ts +4187 -0
- package/dist/external-jr_S4iSS.d.ts.map +1 -0
- package/dist/gateway/index.d.mts +138 -132
- package/dist/gateway/index.d.mts.map +1 -0
- package/dist/gateway/index.d.ts +138 -132
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/index.js +117 -81
- package/dist/gateway/index.mjs +116 -78
- package/dist/gateway/index.mjs.map +1 -0
- package/dist/gateway-client-ip.d.mts +59 -0
- package/dist/gateway-client-ip.d.mts.map +1 -0
- package/dist/gateway-client-ip.d.ts +59 -0
- package/dist/gateway-client-ip.d.ts.map +1 -0
- package/dist/gateway-client-ip.js +149 -0
- package/dist/gateway-client-ip.mjs +139 -0
- package/dist/gateway-client-ip.mjs.map +1 -0
- package/dist/index.d.mts +14895 -14240
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +14895 -14240
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15180 -31025
- package/dist/index.mjs +15065 -30942
- package/dist/index.mjs.map +1 -0
- package/dist/mcpi/agentshield-api/index.d.mts +45 -44
- package/dist/mcpi/agentshield-api/index.d.mts.map +1 -0
- package/dist/mcpi/agentshield-api/index.d.ts +45 -44
- package/dist/mcpi/agentshield-api/index.d.ts.map +1 -0
- package/dist/mcpi/agentshield-api/index.js +0 -2
- package/dist/mcpi/agentshield-api/index.mjs +1 -1
- package/dist/mcpi/approval-grant/index.d.mts +63 -61
- package/dist/mcpi/approval-grant/index.d.mts.map +1 -0
- package/dist/mcpi/approval-grant/index.d.ts +63 -61
- package/dist/mcpi/approval-grant/index.d.ts.map +1 -0
- package/dist/mcpi/approval-grant/index.js +220 -140
- package/dist/mcpi/approval-grant/index.mjs +219 -137
- package/dist/mcpi/approval-grant/index.mjs.map +1 -0
- package/dist/mcpi/dashboard-config/index.d.mts +2323 -2318
- package/dist/mcpi/dashboard-config/index.d.mts.map +1 -0
- package/dist/mcpi/dashboard-config/index.d.ts +2323 -2318
- package/dist/mcpi/dashboard-config/index.d.ts.map +1 -0
- package/dist/mcpi/dashboard-config/index.js +605 -458
- package/dist/mcpi/dashboard-config/index.mjs +604 -455
- package/dist/mcpi/dashboard-config/index.mjs.map +1 -0
- package/dist/mcpi/multibase-ed25519.d.mts +10 -8
- package/dist/mcpi/multibase-ed25519.d.mts.map +1 -0
- package/dist/mcpi/multibase-ed25519.d.ts +10 -8
- package/dist/mcpi/multibase-ed25519.d.ts.map +1 -0
- package/dist/mcpi/multibase-ed25519.js +182 -106
- package/dist/mcpi/multibase-ed25519.mjs +181 -103
- package/dist/mcpi/multibase-ed25519.mjs.map +1 -0
- package/dist/patterns-CkRVOdtV.js +243 -0
- package/dist/patterns-DzkGy_qk.mjs +173 -0
- package/dist/patterns-DzkGy_qk.mjs.map +1 -0
- package/dist/project-verification-key-C3L5rd8a.js +41 -0
- package/dist/project-verification-key-CgSVX9_m.mjs +37 -0
- package/dist/project-verification-key-CgSVX9_m.mjs.map +1 -0
- package/dist/rolldown-runtime-iY2fYEqi.mjs +19 -0
- package/dist/schemas-BmjNLAE7.js +5677 -0
- package/dist/schemas-DxY-dk9y.mjs +5511 -0
- package/dist/schemas-DxY-dk9y.mjs.map +1 -0
- package/dist/signals/index.d.mts +125 -115
- package/dist/signals/index.d.mts.map +1 -0
- package/dist/signals/index.d.ts +125 -115
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +1693 -1536
- package/dist/signals/index.mjs +1692 -1533
- package/dist/signals/index.mjs.map +1 -0
- package/dist/test-fixtures/index.d.mts +124 -119
- package/dist/test-fixtures/index.d.mts.map +1 -0
- package/dist/test-fixtures/index.d.ts +124 -119
- package/dist/test-fixtures/index.d.ts.map +1 -0
- package/dist/test-fixtures/index.js +460 -228
- package/dist/test-fixtures/index.mjs +459 -225
- package/dist/test-fixtures/index.mjs.map +1 -0
- package/dist/tool-protection/index.d.mts +343 -343
- package/dist/tool-protection/index.d.mts.map +1 -0
- package/dist/tool-protection/index.d.ts +343 -343
- package/dist/tool-protection/index.d.ts.map +1 -0
- package/dist/tool-protection/index.js +366 -285
- package/dist/tool-protection/index.mjs +365 -282
- package/dist/tool-protection/index.mjs.map +1 -0
- package/fixtures/bot-signal-resolution.json +142 -0
- package/fixtures/browser-posture-claims.json +421 -0
- package/fixtures/browser-posture-headers.json +46 -0
- package/fixtures/detection/reason-codes.json +10 -1
- package/fixtures/kya-http/challenge.delegation.fetcher-200.json +9 -3
- package/fixtures/kya-http/challenge.delegation.full.json +9 -3
- package/fixtures/kya-http/challenge.delegation.minimal.json +9 -3
- package/fixtures/kya-http/error-codes.json +7 -2
- package/package.json +20 -6
|
@@ -1,338 +1,421 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
//#region src/tool-protection/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* KYA-OS Tool Protection Specification
|
|
6
|
+
*
|
|
7
|
+
* Core types for tool protection with delegation requirements.
|
|
8
|
+
*
|
|
9
|
+
* Consent Flow: type='none' → 2 screens, others → 3 screens (Auth→Consent→Success).
|
|
10
|
+
* DelegationCredential (VC) is created when user confirms on Consent Screen.
|
|
11
|
+
*
|
|
12
|
+
* Ported into checkpoint-shared from `@kya-os/contracts/tool-protection` as part
|
|
13
|
+
* of the E6 / C-series decommission (#2914 / #2917): checkpoint owns its product
|
|
14
|
+
* types now that the DIF `@kya-os/mcp` core is protocol-only. The single external
|
|
15
|
+
* dependency (`envVarNameSchema` from the contracts `vault` module) is inlined
|
|
16
|
+
* below so this module pulls nothing from `@kya-os/contracts`.
|
|
17
|
+
*
|
|
18
|
+
* @module @kya-os/checkpoint-shared/tool-protection
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Validates an env var name used by the `apikey` authorization requirement.
|
|
22
|
+
* Inlined from the former `@kya-os/contracts/vault` `envVarNameSchema`.
|
|
23
|
+
*/
|
|
24
|
+
const envVarNameSchema = z.string().regex(/^[A-Z][A-Z0-9_]*$/, "Must be a valid env var name (e.g., X_API_KEY)").max(255);
|
|
25
|
+
/** Canonical authorization type values for type safety */
|
|
26
|
+
const AUTHORIZATION_TYPES = {
|
|
27
|
+
/** @deprecated Use OAUTH2 instead. Will be removed in v2.0.0. */
|
|
28
|
+
OAUTH: "oauth",
|
|
29
|
+
/** OAuth 2.0 provider authentication (canonical) */
|
|
30
|
+
OAUTH2: "oauth2",
|
|
31
|
+
PASSWORD: "password",
|
|
32
|
+
MDL: "mdl",
|
|
33
|
+
IDV: "idv",
|
|
34
|
+
VERIFIABLE_CREDENTIAL: "verifiable_credential",
|
|
35
|
+
/** WebAuthn/Passkey authentication */
|
|
36
|
+
WEBAUTHN: "webauthn",
|
|
37
|
+
/** Sign-In with Ethereum (EIP-4361) */
|
|
38
|
+
SIWE: "siwe",
|
|
39
|
+
/** API Key from per-user vault */
|
|
40
|
+
APIKEY: "apikey",
|
|
41
|
+
NONE: "none"
|
|
22
42
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
const AuthRequiredErrorDataSchema = z.object({
|
|
44
|
+
error: z.literal("auth_required"),
|
|
45
|
+
type: z.enum([
|
|
46
|
+
"apikey",
|
|
47
|
+
"oauth",
|
|
48
|
+
"credential"
|
|
49
|
+
]),
|
|
50
|
+
envVarNames: z.array(z.string()).optional(),
|
|
51
|
+
configUrl: z.string(),
|
|
52
|
+
message: z.string()
|
|
29
53
|
});
|
|
54
|
+
/**
|
|
55
|
+
* Error class thrown when required auth is missing and no fallback exists.
|
|
56
|
+
*
|
|
57
|
+
* Caught by the tool-call handler in agent.ts and serialized as a
|
|
58
|
+
* machine-readable MCP tool result so clients can present actionable UI.
|
|
59
|
+
*/
|
|
30
60
|
var AuthRequiredError = class extends Error {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
type;
|
|
62
|
+
envVarNames;
|
|
63
|
+
configUrl;
|
|
64
|
+
constructor(opts) {
|
|
65
|
+
const message = opts.message ?? (opts.type === "apikey" && opts.envVarNames?.length ? `API key required: configure ${opts.envVarNames.join(", ")} in your project settings.` : "Authentication required to use this tool.");
|
|
66
|
+
super(message);
|
|
67
|
+
this.name = "AuthRequiredError";
|
|
68
|
+
this.type = opts.type;
|
|
69
|
+
this.envVarNames = opts.envVarNames;
|
|
70
|
+
this.configUrl = opts.configUrl;
|
|
71
|
+
}
|
|
72
|
+
/** Serialize to the wire format MCP clients expect */
|
|
73
|
+
toJSON() {
|
|
74
|
+
return {
|
|
75
|
+
error: "auth_required",
|
|
76
|
+
type: this.type,
|
|
77
|
+
...this.envVarNames && { envVarNames: this.envVarNames },
|
|
78
|
+
configUrl: this.configUrl,
|
|
79
|
+
message: this.message
|
|
80
|
+
};
|
|
81
|
+
}
|
|
52
82
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Zod Schemas for Validation
|
|
85
|
+
*/
|
|
86
|
+
const AuthorizationRequirementSchema = z.discriminatedUnion("type", [
|
|
87
|
+
z.object({
|
|
88
|
+
type: z.literal("oauth"),
|
|
89
|
+
provider: z.string(),
|
|
90
|
+
requiredScopes: z.array(z.string()).optional()
|
|
91
|
+
}),
|
|
92
|
+
z.object({
|
|
93
|
+
type: z.literal("oauth2"),
|
|
94
|
+
provider: z.string(),
|
|
95
|
+
requiredScopes: z.array(z.string()).optional()
|
|
96
|
+
}),
|
|
97
|
+
z.object({
|
|
98
|
+
type: z.literal("password"),
|
|
99
|
+
provider: z.string()
|
|
100
|
+
}),
|
|
101
|
+
z.object({
|
|
102
|
+
type: z.literal("mdl"),
|
|
103
|
+
issuer: z.string(),
|
|
104
|
+
credentialType: z.string().optional()
|
|
105
|
+
}),
|
|
106
|
+
z.object({
|
|
107
|
+
type: z.literal("idv"),
|
|
108
|
+
provider: z.string(),
|
|
109
|
+
verificationLevel: z.enum([
|
|
110
|
+
"basic",
|
|
111
|
+
"enhanced",
|
|
112
|
+
"loa3"
|
|
113
|
+
]).optional()
|
|
114
|
+
}),
|
|
115
|
+
z.object({
|
|
116
|
+
type: z.literal("verifiable_credential"),
|
|
117
|
+
credentialType: z.string(),
|
|
118
|
+
issuer: z.string().optional()
|
|
119
|
+
}),
|
|
120
|
+
z.object({
|
|
121
|
+
type: z.literal("credential"),
|
|
122
|
+
credentialType: z.string(),
|
|
123
|
+
issuer: z.string().optional()
|
|
124
|
+
}),
|
|
125
|
+
z.object({
|
|
126
|
+
type: z.literal("webauthn"),
|
|
127
|
+
rpId: z.string().optional(),
|
|
128
|
+
userVerification: z.enum([
|
|
129
|
+
"required",
|
|
130
|
+
"preferred",
|
|
131
|
+
"discouraged"
|
|
132
|
+
]).optional()
|
|
133
|
+
}),
|
|
134
|
+
z.object({
|
|
135
|
+
type: z.literal("siwe"),
|
|
136
|
+
chainId: z.number().optional(),
|
|
137
|
+
domain: z.string().optional()
|
|
138
|
+
}),
|
|
139
|
+
z.object({
|
|
140
|
+
type: z.literal("apikey"),
|
|
141
|
+
envVarNames: z.array(envVarNameSchema).min(1),
|
|
142
|
+
headerMapping: z.record(z.string(), z.string())
|
|
143
|
+
}),
|
|
144
|
+
z.object({ type: z.literal("none") })
|
|
114
145
|
]);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
146
|
+
const ToolProtectionSchema = z.object({
|
|
147
|
+
requiresDelegation: z.boolean(),
|
|
148
|
+
requiredScopes: z.array(z.string()),
|
|
149
|
+
riskLevel: z.enum([
|
|
150
|
+
"low",
|
|
151
|
+
"medium",
|
|
152
|
+
"high",
|
|
153
|
+
"critical"
|
|
154
|
+
]).optional(),
|
|
155
|
+
oauthProvider: z.string().optional(),
|
|
156
|
+
authorization: AuthorizationRequirementSchema.optional()
|
|
122
157
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
158
|
+
const ToolProtectionMapSchema = z.record(z.string(), ToolProtectionSchema);
|
|
159
|
+
const ToolProtectionResponseSchema = z.object({
|
|
160
|
+
toolProtections: ToolProtectionMapSchema,
|
|
161
|
+
metadata: z.object({
|
|
162
|
+
lastUpdated: z.string().optional(),
|
|
163
|
+
version: z.string().optional(),
|
|
164
|
+
source: z.string().optional()
|
|
165
|
+
}).optional()
|
|
131
166
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
167
|
+
const DelegationRequiredErrorDataSchema = z.object({
|
|
168
|
+
toolName: z.string(),
|
|
169
|
+
requiredScopes: z.array(z.string()),
|
|
170
|
+
consentUrl: z.string().optional(),
|
|
171
|
+
authorizationUrl: z.string().optional(),
|
|
172
|
+
reason: z.string().optional()
|
|
138
173
|
});
|
|
174
|
+
/**
|
|
175
|
+
* Type Guards
|
|
176
|
+
*/
|
|
139
177
|
function isToolProtection(obj) {
|
|
140
|
-
|
|
178
|
+
return ToolProtectionSchema.safeParse(obj).success;
|
|
141
179
|
}
|
|
142
180
|
function isToolProtectionMap(obj) {
|
|
143
|
-
|
|
181
|
+
return ToolProtectionMapSchema.safeParse(obj).success;
|
|
144
182
|
}
|
|
145
183
|
function isToolProtectionResponse(obj) {
|
|
146
|
-
|
|
184
|
+
return ToolProtectionResponseSchema.safeParse(obj).success;
|
|
147
185
|
}
|
|
148
186
|
function isDelegationRequiredErrorData(obj) {
|
|
149
|
-
|
|
187
|
+
return DelegationRequiredErrorDataSchema.safeParse(obj).success;
|
|
150
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Type guard to check if an object is a valid AuthorizationRequirement
|
|
191
|
+
*/
|
|
151
192
|
function isAuthorizationRequirement(obj) {
|
|
152
|
-
|
|
193
|
+
return AuthorizationRequirementSchema.safeParse(obj).success;
|
|
153
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Type guard to check if a ToolProtection has OAuth authorization
|
|
197
|
+
* Checks for both 'oauth' (deprecated) and 'oauth2' (canonical)
|
|
198
|
+
*/
|
|
154
199
|
function hasOAuthAuthorization(protection) {
|
|
155
|
-
|
|
200
|
+
return protection.authorization?.type === "oauth" || protection.authorization?.type === "oauth2";
|
|
156
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Type guard to check if a ToolProtection has password authorization
|
|
204
|
+
*/
|
|
157
205
|
function hasPasswordAuthorization(protection) {
|
|
158
|
-
|
|
206
|
+
return protection.authorization?.type === "password";
|
|
159
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Type guard to check if a ToolProtection requires a Verifiable Credential
|
|
210
|
+
*
|
|
211
|
+
* Note: Also returns true for deprecated 'credential' type (normalized to verifiable_credential)
|
|
212
|
+
*/
|
|
160
213
|
function hasVerifiableCredentialAuthorization(protection) {
|
|
161
|
-
|
|
214
|
+
return protection.authorization?.type === "verifiable_credential" || protection.authorization?.type === "credential";
|
|
162
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Type guard to check if a ToolProtection has API Key (vault) authorization
|
|
218
|
+
*/
|
|
163
219
|
function hasApiKeyAuthorization(protection) {
|
|
164
|
-
|
|
220
|
+
return protection.authorization?.type === "apikey";
|
|
165
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Validation Functions
|
|
224
|
+
*/
|
|
166
225
|
function validateToolProtection(obj) {
|
|
167
|
-
|
|
226
|
+
return ToolProtectionSchema.parse(obj);
|
|
168
227
|
}
|
|
169
228
|
function validateToolProtectionMap(obj) {
|
|
170
|
-
|
|
229
|
+
return ToolProtectionMapSchema.parse(obj);
|
|
171
230
|
}
|
|
172
231
|
function validateToolProtectionResponse(obj) {
|
|
173
|
-
|
|
232
|
+
return ToolProtectionResponseSchema.parse(obj);
|
|
174
233
|
}
|
|
175
234
|
function validateDelegationRequiredErrorData(obj) {
|
|
176
|
-
|
|
235
|
+
return DelegationRequiredErrorDataSchema.parse(obj);
|
|
177
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Utility Functions
|
|
239
|
+
*/
|
|
240
|
+
/**
|
|
241
|
+
* Check if a tool requires delegation
|
|
242
|
+
*/
|
|
178
243
|
function toolRequiresDelegation(toolName, protections) {
|
|
179
|
-
|
|
180
|
-
return protection?.requiresDelegation ?? false;
|
|
244
|
+
return protections[toolName]?.requiresDelegation ?? false;
|
|
181
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Get required scopes for a tool
|
|
248
|
+
*/
|
|
182
249
|
function getToolRequiredScopes(toolName, protections) {
|
|
183
|
-
|
|
184
|
-
return protection?.requiredScopes ?? [];
|
|
250
|
+
return protections[toolName]?.requiredScopes ?? [];
|
|
185
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Get risk level for a tool
|
|
254
|
+
*/
|
|
186
255
|
function getToolRiskLevel(toolName, protections) {
|
|
187
|
-
|
|
256
|
+
return protections[toolName]?.riskLevel;
|
|
188
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Create a delegation required error
|
|
260
|
+
*/
|
|
189
261
|
function createDelegationRequiredError(toolName, requiredScopes, consentUrl) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
};
|
|
262
|
+
return {
|
|
263
|
+
toolName,
|
|
264
|
+
requiredScopes,
|
|
265
|
+
consentUrl,
|
|
266
|
+
authorizationUrl: consentUrl
|
|
267
|
+
};
|
|
197
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Normalize tool protection configuration
|
|
271
|
+
* Migrates legacy oauthProvider field to authorization object
|
|
272
|
+
*
|
|
273
|
+
* - Migrates `oauthProvider` → `authorization: { type: 'oauth', provider: ... }`
|
|
274
|
+
* - Ensures `authorization` field is present when `requiresDelegation=true`
|
|
275
|
+
* - Returns fully normalized ToolProtection object
|
|
276
|
+
*
|
|
277
|
+
* @param raw - Raw tool protection data (may have legacy fields or be partial)
|
|
278
|
+
* @returns Normalized ToolProtection object
|
|
279
|
+
*
|
|
280
|
+
* // TODO: Remove normalizeToolProtection() when all tools migrated
|
|
281
|
+
*/
|
|
198
282
|
function normalizeToolProtection(raw) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
return normalized;
|
|
283
|
+
const normalized = {
|
|
284
|
+
requiresDelegation: raw.requiresDelegation ?? false,
|
|
285
|
+
requiredScopes: raw.requiredScopes ?? [],
|
|
286
|
+
...raw.riskLevel && { riskLevel: raw.riskLevel },
|
|
287
|
+
...raw.oauthProvider && { oauthProvider: raw.oauthProvider }
|
|
288
|
+
};
|
|
289
|
+
if (raw.authorization) {
|
|
290
|
+
normalized.authorization = raw.authorization;
|
|
291
|
+
return normalized;
|
|
292
|
+
}
|
|
293
|
+
if (raw.oauthProvider) {
|
|
294
|
+
normalized.authorization = {
|
|
295
|
+
type: "oauth",
|
|
296
|
+
provider: raw.oauthProvider
|
|
297
|
+
};
|
|
298
|
+
return normalized;
|
|
299
|
+
}
|
|
300
|
+
if (normalized.requiresDelegation && !normalized.authorization && !normalized.oauthProvider) return normalized;
|
|
301
|
+
return normalized;
|
|
220
302
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
303
|
+
/** Consent provider types - stored in delegation metadata to track auth method used */
|
|
304
|
+
const CONSENT_PROVIDER_TYPES = {
|
|
305
|
+
/** Consent-only mode - no authentication, just clickwrap agreement */
|
|
306
|
+
NONE: "none",
|
|
307
|
+
/** OAuth2 provider authentication */
|
|
308
|
+
OAUTH2: "oauth2",
|
|
309
|
+
/** Password-based authentication (email/password, username/password) */
|
|
310
|
+
PASSWORD: "password",
|
|
311
|
+
/** @deprecated Use PASSWORD instead. Alias for backward compatibility */
|
|
312
|
+
CREDENTIAL: "credential",
|
|
313
|
+
/** Email magic link authentication */
|
|
314
|
+
MAGIC_LINK: "magic_link",
|
|
315
|
+
/** One-time password (SMS/email code) */
|
|
316
|
+
OTP: "otp"
|
|
234
317
|
};
|
|
318
|
+
/**
|
|
319
|
+
* Determine consent provider type based on available identity information
|
|
320
|
+
*
|
|
321
|
+
* This is the single source of truth for consent provider type determination.
|
|
322
|
+
*
|
|
323
|
+
* @param hasOAuthIdentity - Whether OAuth identity is available
|
|
324
|
+
* @param isPasswordFlow - Whether this is a password/credential flow
|
|
325
|
+
* @param isMagicLinkFlow - Whether this is a magic link flow
|
|
326
|
+
* @param isOtpFlow - Whether this is an OTP flow
|
|
327
|
+
* @returns The consent provider type
|
|
328
|
+
*/
|
|
235
329
|
function determineConsentProviderType(hasOAuthIdentity, isPasswordFlow = false, isMagicLinkFlow = false, isOtpFlow = false) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
if (isOtpFlow) {
|
|
243
|
-
return CONSENT_PROVIDER_TYPES.OTP;
|
|
244
|
-
}
|
|
245
|
-
if (hasOAuthIdentity) {
|
|
246
|
-
return CONSENT_PROVIDER_TYPES.OAUTH2;
|
|
247
|
-
}
|
|
248
|
-
return CONSENT_PROVIDER_TYPES.NONE;
|
|
330
|
+
if (isPasswordFlow) return CONSENT_PROVIDER_TYPES.PASSWORD;
|
|
331
|
+
if (isMagicLinkFlow) return CONSENT_PROVIDER_TYPES.MAGIC_LINK;
|
|
332
|
+
if (isOtpFlow) return CONSENT_PROVIDER_TYPES.OTP;
|
|
333
|
+
if (hasOAuthIdentity) return CONSENT_PROVIDER_TYPES.OAUTH2;
|
|
334
|
+
return CONSENT_PROVIDER_TYPES.NONE;
|
|
249
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Get a human-readable label for an authorization requirement type
|
|
338
|
+
*/
|
|
250
339
|
function getAuthorizationTypeLabel(auth) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
case "webauthn":
|
|
266
|
-
return "Passkey / WebAuthn";
|
|
267
|
-
case "siwe":
|
|
268
|
-
return "Sign-In with Ethereum";
|
|
269
|
-
case "apikey":
|
|
270
|
-
return "API Key (Vault)";
|
|
271
|
-
case "none":
|
|
272
|
-
return "Consent Only";
|
|
273
|
-
default: {
|
|
274
|
-
return "Unknown";
|
|
275
|
-
}
|
|
276
|
-
}
|
|
340
|
+
switch (auth.type) {
|
|
341
|
+
case "oauth":
|
|
342
|
+
case "oauth2": return auth.provider ? auth.provider.charAt(0).toUpperCase() + auth.provider.slice(1) : "OAuth Provider";
|
|
343
|
+
case "password": return "Password Authentication";
|
|
344
|
+
case "mdl": return "Mobile Driver's License";
|
|
345
|
+
case "idv": return "Identity Verification";
|
|
346
|
+
case "verifiable_credential": return auth.credentialType || "Verifiable Credential";
|
|
347
|
+
case "credential": return auth.credentialType || "Verifiable Credential";
|
|
348
|
+
case "webauthn": return "Passkey / WebAuthn";
|
|
349
|
+
case "siwe": return "Sign-In with Ethereum";
|
|
350
|
+
case "apikey": return "API Key (Vault)";
|
|
351
|
+
case "none": return "Consent Only";
|
|
352
|
+
default: return "Unknown";
|
|
353
|
+
}
|
|
277
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Get a unique key for an authorization requirement (for React keys, caching, etc.)
|
|
357
|
+
*/
|
|
278
358
|
function getAuthorizationTypeKey(auth) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
return `vc:${auth.issuer || "any"}:${auth.credentialType || "unknown"}`;
|
|
294
|
-
case "webauthn":
|
|
295
|
-
return `webauthn:${auth.rpId || "default"}`;
|
|
296
|
-
case "siwe":
|
|
297
|
-
return `siwe:${auth.chainId || 1}:${auth.domain || "any"}`;
|
|
298
|
-
case "apikey":
|
|
299
|
-
return `apikey:${[...auth.envVarNames].sort().join(",")}`;
|
|
300
|
-
case "none":
|
|
301
|
-
return "none";
|
|
302
|
-
default: {
|
|
303
|
-
return "unknown";
|
|
304
|
-
}
|
|
305
|
-
}
|
|
359
|
+
switch (auth.type) {
|
|
360
|
+
case "oauth": return auth.provider ? `oauth:${auth.provider}` : "oauth";
|
|
361
|
+
case "oauth2": return auth.provider ? `oauth2:${auth.provider}` : "oauth2";
|
|
362
|
+
case "password": return auth.provider ? `password:${auth.provider}` : "password";
|
|
363
|
+
case "mdl": return `mdl:${auth.issuer || "unknown"}:${auth.credentialType || ""}`;
|
|
364
|
+
case "idv": return `idv:${auth.provider || "unknown"}:${auth.verificationLevel || ""}`;
|
|
365
|
+
case "verifiable_credential": return `vc:${auth.issuer || "any"}:${auth.credentialType || "unknown"}`;
|
|
366
|
+
case "credential": return `vc:${auth.issuer || "any"}:${auth.credentialType || "unknown"}`;
|
|
367
|
+
case "webauthn": return `webauthn:${auth.rpId || "default"}`;
|
|
368
|
+
case "siwe": return `siwe:${auth.chainId || 1}:${auth.domain || "any"}`;
|
|
369
|
+
case "apikey": return `apikey:${[...auth.envVarNames].sort().join(",")}`;
|
|
370
|
+
case "none": return "none";
|
|
371
|
+
default: return "unknown";
|
|
372
|
+
}
|
|
306
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* Normalize authorization requirement type
|
|
376
|
+
*
|
|
377
|
+
* Normalizes deprecated types to their canonical equivalents:
|
|
378
|
+
* - 'oauth' → 'oauth2'
|
|
379
|
+
* - 'credential' → 'verifiable_credential'
|
|
380
|
+
*
|
|
381
|
+
* This function should be called at runtime boundaries when processing
|
|
382
|
+
* authorization requirements.
|
|
383
|
+
*
|
|
384
|
+
* @param auth - Authorization requirement (may contain deprecated types)
|
|
385
|
+
* @param options - Normalization options
|
|
386
|
+
* @returns Normalized authorization requirement
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* const normalized = normalizeAuthorizationType(
|
|
391
|
+
* { type: 'oauth', provider: 'github' },
|
|
392
|
+
* { warn: true }
|
|
393
|
+
* );
|
|
394
|
+
* // Returns: { type: 'oauth2', provider: 'github' }
|
|
395
|
+
* // Logs: DEPRECATION warning
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
307
398
|
function normalizeAuthorizationType(auth, options = {}) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
const normalized = {
|
|
329
|
-
type: "verifiable_credential",
|
|
330
|
-
credentialType: auth.credentialType,
|
|
331
|
-
...auth.issuer !== void 0 && { issuer: auth.issuer }
|
|
332
|
-
};
|
|
333
|
-
return normalized;
|
|
334
|
-
}
|
|
335
|
-
return auth;
|
|
399
|
+
const { warn = true, logger = console.warn } = options;
|
|
400
|
+
if (auth.type === "oauth") {
|
|
401
|
+
if (warn) logger("DEPRECATION: Authorization type 'oauth' is deprecated and will be removed in v2.0.0. Please update to 'oauth2'. See https://github.com/modelcontextprotocol-identity/xmcp-i/blob/main/docs/migrations/oauth-to-oauth2.md");
|
|
402
|
+
return {
|
|
403
|
+
type: "oauth2",
|
|
404
|
+
provider: auth.provider,
|
|
405
|
+
...auth.requiredScopes !== void 0 && { requiredScopes: auth.requiredScopes }
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
if (auth.type === "credential") {
|
|
409
|
+
if (warn) logger("DEPRECATION: Authorization type 'credential' is deprecated and will be removed in v2.0.0. Please update to 'verifiable_credential'. See https://github.com/modelcontextprotocol-identity/xmcp-i/blob/main/docs/migrations/credential-to-verifiable_credential.md");
|
|
410
|
+
return {
|
|
411
|
+
type: "verifiable_credential",
|
|
412
|
+
credentialType: auth.credentialType,
|
|
413
|
+
...auth.issuer !== void 0 && { issuer: auth.issuer }
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return auth;
|
|
336
417
|
}
|
|
337
418
|
|
|
419
|
+
//#endregion
|
|
338
420
|
export { AUTHORIZATION_TYPES, AuthRequiredError, AuthRequiredErrorDataSchema, AuthorizationRequirementSchema, CONSENT_PROVIDER_TYPES, DelegationRequiredErrorDataSchema, ToolProtectionMapSchema, ToolProtectionResponseSchema, ToolProtectionSchema, createDelegationRequiredError, determineConsentProviderType, getAuthorizationTypeKey, getAuthorizationTypeLabel, getToolRequiredScopes, getToolRiskLevel, hasApiKeyAuthorization, hasOAuthAuthorization, hasPasswordAuthorization, hasVerifiableCredentialAuthorization, isAuthorizationRequirement, isDelegationRequiredErrorData, isToolProtection, isToolProtectionMap, isToolProtectionResponse, normalizeAuthorizationType, normalizeToolProtection, toolRequiresDelegation, validateDelegationRequiredErrorData, validateToolProtection, validateToolProtectionMap, validateToolProtectionResponse };
|
|
421
|
+
//# sourceMappingURL=index.mjs.map
|