@kya-os/mcp-i-runtime 1.2.5 → 1.3.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/.turbo/turbo-build.log +1 -1
- package/dist/auth/types.d.ts +2 -2
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/config/remote-config.d.ts +3 -3
- package/dist/config/remote-config.js +6 -6
- package/dist/config/remote-config.js.map +1 -1
- package/dist/identity/user-did-manager.d.ts +4 -4
- package/dist/identity/user-did-manager.js +5 -5
- package/dist/identity/user-did-manager.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/runtime/audit.d.ts.map +1 -1
- package/dist/runtime/audit.js +22 -0
- package/dist/runtime/audit.js.map +1 -1
- package/dist/runtime/base.d.ts +14 -11
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +51 -29
- package/dist/runtime/base.js.map +1 -1
- package/dist/runtime/delegation-denial.d.ts +43 -0
- package/dist/runtime/delegation-denial.d.ts.map +1 -0
- package/dist/runtime/delegation-denial.js +83 -0
- package/dist/runtime/delegation-denial.js.map +1 -0
- package/dist/runtime/verified-delegation.d.ts +30 -0
- package/dist/runtime/verified-delegation.d.ts.map +1 -0
- package/dist/runtime/verified-delegation.js +62 -0
- package/dist/runtime/verified-delegation.js.map +1 -0
- package/dist/services/access-control.service.d.ts +4 -4
- package/dist/services/access-control.service.d.ts.map +1 -1
- package/dist/services/access-control.service.js +34 -34
- package/dist/services/access-control.service.js.map +1 -1
- package/dist/services/delegation-error-formatter.d.ts +15 -0
- package/dist/services/delegation-error-formatter.d.ts.map +1 -1
- package/dist/services/delegation-error-formatter.js +27 -1
- package/dist/services/delegation-error-formatter.js.map +1 -1
- package/dist/services/oauth-config.service.d.ts +4 -4
- package/dist/services/oauth-config.service.d.ts.map +1 -1
- package/dist/services/oauth-config.service.js +8 -8
- package/dist/services/oauth-config.service.js.map +1 -1
- package/dist/services/oauth-provider-registry.d.ts +6 -4
- package/dist/services/oauth-provider-registry.d.ts.map +1 -1
- package/dist/services/oauth-provider-registry.js +9 -5
- package/dist/services/oauth-provider-registry.js.map +1 -1
- package/dist/services/oauth-service.d.ts +17 -10
- package/dist/services/oauth-service.d.ts.map +1 -1
- package/dist/services/oauth-service.js +14 -14
- package/dist/services/oauth-service.js.map +1 -1
- package/dist/services/oauth-token-retrieval.service.d.ts +6 -6
- package/dist/services/oauth-token-retrieval.service.d.ts.map +1 -1
- package/dist/services/oauth-token-retrieval.service.js +5 -5
- package/dist/services/provider-resolver.d.ts +1 -1
- package/dist/services/provider-resolver.js +7 -7
- package/dist/services/provider-resolver.js.map +1 -1
- package/dist/services/session-registration.service.d.ts +5 -5
- package/dist/services/session-registration.service.d.ts.map +1 -1
- package/dist/services/session-registration.service.js +9 -9
- package/dist/services/session-registration.service.js.map +1 -1
- package/dist/services/tool-protection.service.d.ts +15 -15
- package/dist/services/tool-protection.service.js +18 -18
- package/dist/services/tool-protection.service.js.map +1 -1
- package/dist/types/tool-protection.d.ts +11 -4
- package/dist/types/tool-protection.d.ts.map +1 -1
- package/dist/types/tool-protection.js +8 -1
- package/dist/types/tool-protection.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/config/provider-runtime-config.test.ts +1 -1
- package/src/__tests__/config.test.ts +3 -3
- package/src/__tests__/index.test.ts +12 -0
- package/src/__tests__/integration/full-flow.test.ts +4 -4
- package/src/__tests__/regression/phase2-regression.test.ts +2 -2
- package/src/__tests__/runtime/audit-contracts-compat.test.ts +54 -0
- package/src/__tests__/runtime/audit.test.ts +172 -0
- package/src/__tests__/runtime/delegation-denial.test.ts +115 -0
- package/src/__tests__/runtime/process-tool-call-security.test.ts +326 -9
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +25 -10
- package/src/__tests__/runtime/verified-delegation.test.ts +129 -0
- package/src/__tests__/services/access-control-retry.test.ts +2 -2
- package/src/__tests__/services/cache-busting.test.ts +1 -1
- package/src/__tests__/services/{agentshield-integration.test.ts → checkpoint-integration.test.ts} +3 -3
- package/src/__tests__/services/former-names.test.ts +114 -0
- package/src/__tests__/services/oauth-service-errors.test.ts +5 -5
- package/src/__tests__/services/oauth-service-pkce.test.ts +2 -2
- package/src/__tests__/services/oauth-service-secret-resolution.test.ts +15 -15
- package/src/__tests__/services/provider-resolver-edge-cases.test.ts +11 -11
- package/src/__tests__/services/tool-protection.service.test.ts +1 -1
- package/src/auth/types.ts +2 -2
- package/src/config/remote-config.ts +6 -6
- package/src/identity/user-did-manager.ts +5 -5
- package/src/index.ts +15 -0
- package/src/runtime/audit.ts +26 -0
- package/src/runtime/base.ts +63 -32
- package/src/runtime/delegation-denial.ts +107 -0
- package/src/runtime/verified-delegation.ts +66 -0
- package/src/services/__tests__/access-control.integration.test.ts +3 -3
- package/src/services/__tests__/access-control.proof-response-validation.test.ts +15 -15
- package/src/services/__tests__/access-control.service.test.ts +14 -14
- package/src/services/__tests__/delegation-error-formatter.test.ts +156 -0
- package/src/services/__tests__/oauth-config.service.test.ts +2 -2
- package/src/services/__tests__/oauth-provider-registry.test.ts +11 -11
- package/src/services/__tests__/provider-resolution.integration.test.ts +6 -6
- package/src/services/__tests__/provider-resolver.test.ts +1 -1
- package/src/services/__tests__/session-registration.service.test.ts +1 -1
- package/src/services/access-control.service.ts +31 -31
- package/src/services/delegation-error-formatter.ts +42 -1
- package/src/services/oauth-config.service.d.ts +4 -4
- package/src/services/oauth-config.service.ts +9 -9
- package/src/services/oauth-provider-registry.d.ts +4 -2
- package/src/services/oauth-provider-registry.ts +10 -5
- package/src/services/oauth-service.ts +30 -19
- package/src/services/oauth-token-retrieval.service.ts +8 -8
- package/src/services/provider-resolver.ts +7 -7
- package/src/services/session-registration.service.ts +10 -10
- package/src/services/tool-protection.service.ts +19 -19
- package/src/types/tool-protection.ts +13 -4
- package/vitest.config.mts +1 -1
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
AccessControlApiService,
|
|
12
12
|
authorizationMatches,
|
|
13
13
|
} from "../access-control.service.js";
|
|
14
|
-
import {
|
|
14
|
+
import { CheckpointAPIError } from "@kya-os/contracts/checkpoint-api";
|
|
15
15
|
import type { FetchProvider } from "../../providers/base.js";
|
|
16
16
|
import type {
|
|
17
17
|
VerifyDelegationRequest,
|
|
18
18
|
ToolProtectionConfigAPIResponse,
|
|
19
19
|
ProofSubmissionRequest,
|
|
20
|
-
} from "@kya-os/contracts/
|
|
20
|
+
} from "@kya-os/contracts/checkpoint-api";
|
|
21
21
|
|
|
22
22
|
describe("AccessControlApiService", () => {
|
|
23
23
|
let service: AccessControlApiService;
|
|
@@ -109,7 +109,7 @@ describe("AccessControlApiService", () => {
|
|
|
109
109
|
|
|
110
110
|
await expect(
|
|
111
111
|
service.fetchConfig({ agentDid: "did:key:z123" })
|
|
112
|
-
).rejects.toThrow(
|
|
112
|
+
).rejects.toThrow(CheckpointAPIError);
|
|
113
113
|
|
|
114
114
|
const metrics = service.getMetrics();
|
|
115
115
|
expect(metrics.errorCount).toBe(1);
|
|
@@ -161,12 +161,12 @@ describe("AccessControlApiService", () => {
|
|
|
161
161
|
|
|
162
162
|
await expect(
|
|
163
163
|
service.fetchConfig({ agentDid: "did:key:z123" })
|
|
164
|
-
).rejects.toThrow(
|
|
164
|
+
).rejects.toThrow(CheckpointAPIError);
|
|
165
165
|
|
|
166
166
|
const error = await service
|
|
167
167
|
.fetchConfig({ agentDid: "did:key:z123" })
|
|
168
168
|
.catch((e) => e);
|
|
169
|
-
expect(error).toBeInstanceOf(
|
|
169
|
+
expect(error).toBeInstanceOf(CheckpointAPIError);
|
|
170
170
|
expect(error.code).toBe("invalid_response");
|
|
171
171
|
});
|
|
172
172
|
});
|
|
@@ -379,7 +379,7 @@ describe("AccessControlApiService", () => {
|
|
|
379
379
|
);
|
|
380
380
|
|
|
381
381
|
await expect(service.verifyDelegation(invalidRequest)).rejects.toThrow(
|
|
382
|
-
|
|
382
|
+
CheckpointAPIError
|
|
383
383
|
);
|
|
384
384
|
|
|
385
385
|
const error = await service
|
|
@@ -428,7 +428,7 @@ describe("AccessControlApiService", () => {
|
|
|
428
428
|
);
|
|
429
429
|
|
|
430
430
|
await expect(service.verifyDelegation(request)).rejects.toThrow(
|
|
431
|
-
|
|
431
|
+
CheckpointAPIError
|
|
432
432
|
);
|
|
433
433
|
|
|
434
434
|
const error = await service.verifyDelegation(request).catch((e) => e);
|
|
@@ -640,9 +640,9 @@ describe("AccessControlApiService", () => {
|
|
|
640
640
|
);
|
|
641
641
|
|
|
642
642
|
const error = await service.submitProofs(request).catch((e) => e);
|
|
643
|
-
expect(error).toBeInstanceOf(
|
|
644
|
-
expect((error as
|
|
645
|
-
expect((error as
|
|
643
|
+
expect(error).toBeInstanceOf(CheckpointAPIError);
|
|
644
|
+
expect((error as CheckpointAPIError).code).toBe("invalid_response");
|
|
645
|
+
expect((error as CheckpointAPIError).message).toBe(
|
|
646
646
|
"Response validation failed"
|
|
647
647
|
);
|
|
648
648
|
|
|
@@ -803,8 +803,8 @@ describe("AccessControlApiService", () => {
|
|
|
803
803
|
);
|
|
804
804
|
|
|
805
805
|
const error = await service.submitProofs(request).catch((e) => e);
|
|
806
|
-
expect(error).toBeInstanceOf(
|
|
807
|
-
expect((error as
|
|
806
|
+
expect(error).toBeInstanceOf(CheckpointAPIError);
|
|
807
|
+
expect((error as CheckpointAPIError).code).toBe("invalid_response");
|
|
808
808
|
});
|
|
809
809
|
|
|
810
810
|
it("should validate request schema", async () => {
|
|
@@ -814,7 +814,7 @@ describe("AccessControlApiService", () => {
|
|
|
814
814
|
} as ProofSubmissionRequest;
|
|
815
815
|
|
|
816
816
|
await expect(service.submitProofs(invalidRequest)).rejects.toThrow(
|
|
817
|
-
|
|
817
|
+
CheckpointAPIError
|
|
818
818
|
);
|
|
819
819
|
|
|
820
820
|
const error = await service.submitProofs(invalidRequest).catch((e) => e);
|
|
@@ -872,7 +872,7 @@ describe("AccessControlApiService", () => {
|
|
|
872
872
|
|
|
873
873
|
await expect(
|
|
874
874
|
service.fetchConfig({ agentDid: "did:key:z123" })
|
|
875
|
-
).rejects.toThrow(
|
|
875
|
+
).rejects.toThrow(CheckpointAPIError);
|
|
876
876
|
|
|
877
877
|
expect(mockFetchProvider.fetch).toHaveBeenCalledTimes(1);
|
|
878
878
|
expect(mockSleepFn).not.toHaveBeenCalled();
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
createDelegationErrorFormatter,
|
|
17
17
|
} from "../delegation-error-formatter";
|
|
18
18
|
import type { ClientMessagesConfig } from "../delegation-error-formatter";
|
|
19
|
+
import { toDelegationDenial } from "../../runtime/delegation-denial";
|
|
19
20
|
|
|
20
21
|
describe("DelegationErrorFormatter", () => {
|
|
21
22
|
describe("default behavior (no config)", () => {
|
|
@@ -459,6 +460,161 @@ describe("DelegationErrorFormatter", () => {
|
|
|
459
460
|
});
|
|
460
461
|
});
|
|
461
462
|
|
|
463
|
+
describe("verifier denials", () => {
|
|
464
|
+
const consentUrl = "https://example.com/consent?resume=abc";
|
|
465
|
+
const revoked = toDelegationDenial("delegation_revoked");
|
|
466
|
+
// Today's default output, pinned so a denial without configuration
|
|
467
|
+
// provably changes nothing.
|
|
468
|
+
const todaysMessage = `Authorization required for "place_order".
|
|
469
|
+
|
|
470
|
+
Authorization URL: ${consentUrl}
|
|
471
|
+
|
|
472
|
+
Share this URL with the user so they can authorize in their browser, then retry.`;
|
|
473
|
+
|
|
474
|
+
it("puts the configured denial line first and keeps the consent URL", () => {
|
|
475
|
+
const formatter = new DelegationErrorFormatter({
|
|
476
|
+
default: {
|
|
477
|
+
denialMessages: {
|
|
478
|
+
delegation_revoked:
|
|
479
|
+
"Your approval for {toolName} was revoked in the dashboard.",
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
const result = formatter.format({
|
|
485
|
+
toolName: "place_order",
|
|
486
|
+
consentUrl,
|
|
487
|
+
denial: revoked,
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
expect(result.message).toBe(
|
|
491
|
+
`Your approval for place_order was revoked in the dashboard.\n\n${todaysMessage}`
|
|
492
|
+
);
|
|
493
|
+
expect(result.consentUrl).toBe(consentUrl);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it("prefers the client's denial message over the default template's", () => {
|
|
497
|
+
const formatter = new DelegationErrorFormatter({
|
|
498
|
+
default: {
|
|
499
|
+
denialMessages: { delegation_revoked: "Default: revoked." },
|
|
500
|
+
},
|
|
501
|
+
clients: {
|
|
502
|
+
claude: {
|
|
503
|
+
denialMessages: { delegation_revoked: "Claude: revoked." },
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
const claudeResult = formatter.format({
|
|
509
|
+
toolName: "place_order",
|
|
510
|
+
consentUrl,
|
|
511
|
+
clientId: "claude",
|
|
512
|
+
denial: revoked,
|
|
513
|
+
});
|
|
514
|
+
const cursorResult = formatter.format({
|
|
515
|
+
toolName: "place_order",
|
|
516
|
+
consentUrl,
|
|
517
|
+
clientId: "cursor",
|
|
518
|
+
denial: revoked,
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
expect(claudeResult.message.startsWith("Claude: revoked.\n\n")).toBe(true);
|
|
522
|
+
expect(cursorResult.message.startsWith("Default: revoked.\n\n")).toBe(true);
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it("falls back to the default template per code when the client template lacks that code", () => {
|
|
526
|
+
const formatter = new DelegationErrorFormatter({
|
|
527
|
+
default: {
|
|
528
|
+
denialMessages: { delegation_revoked: "Default: revoked." },
|
|
529
|
+
},
|
|
530
|
+
clients: {
|
|
531
|
+
claude: {
|
|
532
|
+
denialMessages: { agent_mismatch: "Claude: wrong agent." },
|
|
533
|
+
},
|
|
534
|
+
},
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
const result = formatter.format({
|
|
538
|
+
toolName: "place_order",
|
|
539
|
+
consentUrl,
|
|
540
|
+
clientId: "claude",
|
|
541
|
+
denial: revoked,
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
expect(result.message.startsWith("Default: revoked.\n\n")).toBe(true);
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
it("is byte-identical to today when a denial has no configured message", () => {
|
|
548
|
+
const formatter = new DelegationErrorFormatter({
|
|
549
|
+
default: { denialMessages: { agent_mismatch: "Wrong agent." } },
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
const withDenial = formatter.format({
|
|
553
|
+
toolName: "place_order",
|
|
554
|
+
consentUrl,
|
|
555
|
+
denial: revoked,
|
|
556
|
+
});
|
|
557
|
+
const withoutDenial = formatter.format({
|
|
558
|
+
toolName: "place_order",
|
|
559
|
+
consentUrl,
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
expect(withDenial.message).toBe(todaysMessage);
|
|
563
|
+
expect(withoutDenial.message).toBe(todaysMessage);
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
it("is byte-identical to today with no config at all", () => {
|
|
567
|
+
const result = new DelegationErrorFormatter().format({
|
|
568
|
+
toolName: "place_order",
|
|
569
|
+
consentUrl,
|
|
570
|
+
denial: revoked,
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
expect(result.message).toBe(todaysMessage);
|
|
574
|
+
expect(result.message).not.toContain(revoked!.message);
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
it("prepends the denial line to the no-URL message too", () => {
|
|
578
|
+
const formatter = new DelegationErrorFormatter({
|
|
579
|
+
default: { denialMessages: { delegation_revoked: "Revoked." } },
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
const result = formatter.format({
|
|
583
|
+
toolName: "place_order",
|
|
584
|
+
denial: revoked,
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
expect(result.message).toBe(
|
|
588
|
+
`Revoked.\n\nAuthorization required for "place_order" but no consent URL is available.
|
|
589
|
+
|
|
590
|
+
Please contact the administrator to configure delegation for this tool.`
|
|
591
|
+
);
|
|
592
|
+
expect(result.consentUrl).toBeUndefined();
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
it("still strips markdown links, including in the denial line, for clients without markdown", () => {
|
|
596
|
+
const formatter = new DelegationErrorFormatter({
|
|
597
|
+
default: {
|
|
598
|
+
message: "[Authorize {toolName}]({consentUrl})",
|
|
599
|
+
denialMessages: {
|
|
600
|
+
delegation_revoked: "Revoked. [Review grants](https://example.com/grants)",
|
|
601
|
+
},
|
|
602
|
+
supportsMarkdown: false,
|
|
603
|
+
},
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
const result = formatter.format({
|
|
607
|
+
toolName: "place_order",
|
|
608
|
+
consentUrl,
|
|
609
|
+
denial: revoked,
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
expect(result.message).toBe(
|
|
613
|
+
`Revoked. Review grants: https://example.com/grants\n\nAuthorize place_order: ${consentUrl}`
|
|
614
|
+
);
|
|
615
|
+
});
|
|
616
|
+
});
|
|
617
|
+
|
|
462
618
|
describe("formatOAuth", () => {
|
|
463
619
|
describe("default behavior (no config)", () => {
|
|
464
620
|
it("should format OAuth message with URL using default template", () => {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Tests for OAuthConfigService
|
|
3
3
|
*
|
|
4
4
|
* Covers:
|
|
5
|
-
* - OAuth config fetching from
|
|
5
|
+
* - OAuth config fetching from Checkpoint API
|
|
6
6
|
* - Caching behavior
|
|
7
7
|
* - Error handling
|
|
8
8
|
* - snake_case to camelCase mapping
|
|
@@ -175,7 +175,7 @@ describe("OAuthConfigService", () => {
|
|
|
175
175
|
// OAuthService.resolveClientSecret could not resolve a confidential
|
|
176
176
|
// provider's secret from secure storage (it keys off
|
|
177
177
|
// `metadata.clientSecretName`). It then fell back to the inline
|
|
178
|
-
// `clientSecret` — which the
|
|
178
|
+
// `clientSecret` — which the Checkpoint /providers response
|
|
179
179
|
// intentionally OMITS — so the worker sent an empty secret and the
|
|
180
180
|
// OAuth token exchange failed with "client_id and/or client_secret
|
|
181
181
|
// incorrect".
|
|
@@ -44,9 +44,9 @@ describe("OAuthProviderRegistry", () => {
|
|
|
44
44
|
registry = new OAuthProviderRegistry(mockConfigService);
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
describe("
|
|
48
|
-
it("should load providers from
|
|
49
|
-
await registry.
|
|
47
|
+
describe("loadFromCheckpoint", () => {
|
|
48
|
+
it("should load providers from Checkpoint config", async () => {
|
|
49
|
+
await registry.loadFromCheckpoint("test-project");
|
|
50
50
|
|
|
51
51
|
expect(mockConfigService.getOAuthConfig).toHaveBeenCalledWith(
|
|
52
52
|
"test-project"
|
|
@@ -56,7 +56,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
it("should clear existing providers before loading new ones", async () => {
|
|
59
|
-
await registry.
|
|
59
|
+
await registry.loadFromCheckpoint("test-project");
|
|
60
60
|
expect(registry.getAllProviders().length).toBe(2);
|
|
61
61
|
|
|
62
62
|
const newConfig: OAuthConfig = {
|
|
@@ -72,7 +72,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
(mockConfigService.getOAuthConfig as any).mockResolvedValueOnce(newConfig);
|
|
75
|
-
await registry.
|
|
75
|
+
await registry.loadFromCheckpoint("test-project-2");
|
|
76
76
|
|
|
77
77
|
expect(registry.getAllProviders().length).toBe(1);
|
|
78
78
|
expect(registry.hasProvider("github")).toBe(false);
|
|
@@ -82,7 +82,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
82
82
|
|
|
83
83
|
describe("getProvider", () => {
|
|
84
84
|
it("should return provider by name", async () => {
|
|
85
|
-
await registry.
|
|
85
|
+
await registry.loadFromCheckpoint("test-project");
|
|
86
86
|
|
|
87
87
|
const githubProvider = registry.getProvider("github");
|
|
88
88
|
expect(githubProvider).toBeDefined();
|
|
@@ -90,7 +90,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
it("should return null for non-existent provider", async () => {
|
|
93
|
-
await registry.
|
|
93
|
+
await registry.loadFromCheckpoint("test-project");
|
|
94
94
|
|
|
95
95
|
const provider = registry.getProvider("nonexistent");
|
|
96
96
|
expect(provider).toBeNull();
|
|
@@ -99,7 +99,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
99
99
|
|
|
100
100
|
describe("getAllProviders", () => {
|
|
101
101
|
it("should return all providers", async () => {
|
|
102
|
-
await registry.
|
|
102
|
+
await registry.loadFromCheckpoint("test-project");
|
|
103
103
|
|
|
104
104
|
const providers = registry.getAllProviders();
|
|
105
105
|
expect(providers.length).toBe(2);
|
|
@@ -115,14 +115,14 @@ describe("OAuthProviderRegistry", () => {
|
|
|
115
115
|
|
|
116
116
|
describe("hasProvider", () => {
|
|
117
117
|
it("should return true for existing provider", async () => {
|
|
118
|
-
await registry.
|
|
118
|
+
await registry.loadFromCheckpoint("test-project");
|
|
119
119
|
|
|
120
120
|
expect(registry.hasProvider("github")).toBe(true);
|
|
121
121
|
expect(registry.hasProvider("google")).toBe(true);
|
|
122
122
|
});
|
|
123
123
|
|
|
124
124
|
it("should return false for non-existent provider", async () => {
|
|
125
|
-
await registry.
|
|
125
|
+
await registry.loadFromCheckpoint("test-project");
|
|
126
126
|
|
|
127
127
|
expect(registry.hasProvider("nonexistent")).toBe(false);
|
|
128
128
|
});
|
|
@@ -130,7 +130,7 @@ describe("OAuthProviderRegistry", () => {
|
|
|
130
130
|
|
|
131
131
|
describe("getProviderNames", () => {
|
|
132
132
|
it("should return all provider names", async () => {
|
|
133
|
-
await registry.
|
|
133
|
+
await registry.loadFromCheckpoint("test-project");
|
|
134
134
|
|
|
135
135
|
const names = registry.getProviderNames();
|
|
136
136
|
expect(names).toContain("github");
|
|
@@ -57,7 +57,7 @@ describe("Provider Resolution Integration", () => {
|
|
|
57
57
|
|
|
58
58
|
describe("End-to-end provider resolution", () => {
|
|
59
59
|
it("should resolve provider for tool with oauthProvider field", async () => {
|
|
60
|
-
await providerRegistry.
|
|
60
|
+
await providerRegistry.loadFromCheckpoint("test-project");
|
|
61
61
|
|
|
62
62
|
const toolProtection: ToolProtection = {
|
|
63
63
|
requiresDelegation: true,
|
|
@@ -74,7 +74,7 @@ describe("Provider Resolution Integration", () => {
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
it("should resolve provider via scope inference when oauthProvider not specified", async () => {
|
|
77
|
-
await providerRegistry.
|
|
77
|
+
await providerRegistry.loadFromCheckpoint("test-project");
|
|
78
78
|
|
|
79
79
|
const toolProtection: ToolProtection = {
|
|
80
80
|
requiresDelegation: true,
|
|
@@ -98,7 +98,7 @@ describe("Provider Resolution Integration", () => {
|
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
it("should fall back to configuredProvider for Phase 1 compatibility", async () => {
|
|
101
|
-
await providerRegistry.
|
|
101
|
+
await providerRegistry.loadFromCheckpoint("test-project");
|
|
102
102
|
|
|
103
103
|
const toolProtection: ToolProtection = {
|
|
104
104
|
requiresDelegation: true,
|
|
@@ -125,7 +125,7 @@ describe("Provider Resolution Integration", () => {
|
|
|
125
125
|
|
|
126
126
|
describe("Backward compatibility", () => {
|
|
127
127
|
it("should work with Phase 1 tools (no oauthProvider field)", async () => {
|
|
128
|
-
await providerRegistry.
|
|
128
|
+
await providerRegistry.loadFromCheckpoint("test-project");
|
|
129
129
|
|
|
130
130
|
const toolProtection: ToolProtection = {
|
|
131
131
|
requiresDelegation: true,
|
|
@@ -144,7 +144,7 @@ describe("Provider Resolution Integration", () => {
|
|
|
144
144
|
});
|
|
145
145
|
|
|
146
146
|
it("should handle tools with empty requiredScopes", async () => {
|
|
147
|
-
await providerRegistry.
|
|
147
|
+
await providerRegistry.loadFromCheckpoint("test-project");
|
|
148
148
|
|
|
149
149
|
const toolProtection: ToolProtection = {
|
|
150
150
|
requiresDelegation: true,
|
|
@@ -171,7 +171,7 @@ describe("Provider Resolution Integration", () => {
|
|
|
171
171
|
|
|
172
172
|
describe("Multi-provider scenarios", () => {
|
|
173
173
|
it("should resolve different providers for different tools", async () => {
|
|
174
|
-
await providerRegistry.
|
|
174
|
+
await providerRegistry.loadFromCheckpoint("test-project");
|
|
175
175
|
|
|
176
176
|
const githubTool: ToolProtection = {
|
|
177
177
|
requiresDelegation: true,
|
|
@@ -44,7 +44,7 @@ describe("ProviderResolver", () => {
|
|
|
44
44
|
hasProvider: vi.fn(),
|
|
45
45
|
getAllProviders: vi.fn().mockReturnValue([]),
|
|
46
46
|
getProviderNames: vi.fn().mockReturnValue([]),
|
|
47
|
-
|
|
47
|
+
loadFromCheckpoint: vi.fn().mockResolvedValue(undefined),
|
|
48
48
|
getConfiguredProvider: vi.fn().mockReturnValue(null), // New method for configuredProvider
|
|
49
49
|
} as any;
|
|
50
50
|
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
createSessionRegistrationService,
|
|
15
15
|
} from "../session-registration.service";
|
|
16
16
|
import type { FetchProvider } from "../../providers/base";
|
|
17
|
-
import type { RegisterSessionRequest } from "@kya-os/contracts/
|
|
17
|
+
import type { RegisterSessionRequest } from "@kya-os/contracts/checkpoint-api";
|
|
18
18
|
|
|
19
19
|
describe("SessionRegistrationService", () => {
|
|
20
20
|
let mockFetchProvider: FetchProvider;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Access Control API Service
|
|
3
3
|
*
|
|
4
4
|
* Brand-neutral service for interacting with access-control APIs
|
|
5
|
-
* (currently
|
|
5
|
+
* (currently Checkpoint/bouncer, but designed to be provider-agnostic).
|
|
6
6
|
*
|
|
7
7
|
* This service provides:
|
|
8
8
|
* - Delegation verification
|
|
@@ -18,19 +18,19 @@ import type {
|
|
|
18
18
|
ToolProtectionConfigAPIResponse,
|
|
19
19
|
ProofSubmissionRequest,
|
|
20
20
|
ProofSubmissionResponse,
|
|
21
|
-
} from "@kya-os/contracts/
|
|
21
|
+
} from "@kya-os/contracts/checkpoint-api";
|
|
22
22
|
import {
|
|
23
23
|
verifyDelegationRequestSchema,
|
|
24
24
|
verifyDelegationAPIResponseSchema,
|
|
25
25
|
toolProtectionConfigAPIResponseSchema,
|
|
26
26
|
proofSubmissionRequestSchema,
|
|
27
27
|
proofSubmissionResponseSchema,
|
|
28
|
-
} from "@kya-os/contracts/
|
|
29
|
-
import {
|
|
28
|
+
} from "@kya-os/contracts/checkpoint-api";
|
|
29
|
+
import { CheckpointAPIError } from "@kya-os/contracts/checkpoint-api";
|
|
30
30
|
import type { FetchProvider } from "../providers/base";
|
|
31
31
|
|
|
32
32
|
// Type for error response
|
|
33
|
-
type
|
|
33
|
+
type CheckpointAPIErrorResponse = {
|
|
34
34
|
code: string;
|
|
35
35
|
message: string;
|
|
36
36
|
details?: Record<string, unknown>;
|
|
@@ -98,7 +98,7 @@ function generateCorrelationId(): string {
|
|
|
98
98
|
/**
|
|
99
99
|
* Access Control API Service
|
|
100
100
|
*
|
|
101
|
-
* Handles all interactions with the access-control API (
|
|
101
|
+
* Handles all interactions with the access-control API (Checkpoint/bouncer).
|
|
102
102
|
* Designed to be brand-neutral and work with any access-control provider.
|
|
103
103
|
*/
|
|
104
104
|
export class AccessControlApiService {
|
|
@@ -170,7 +170,7 @@ export class AccessControlApiService {
|
|
|
170
170
|
const parsed =
|
|
171
171
|
toolProtectionConfigAPIResponseSchema.safeParse(responseData);
|
|
172
172
|
if (!parsed.success) {
|
|
173
|
-
throw new
|
|
173
|
+
throw new CheckpointAPIError(
|
|
174
174
|
"invalid_response",
|
|
175
175
|
"Response validation failed",
|
|
176
176
|
{ zodErrors: parsed.error.errors }
|
|
@@ -249,7 +249,7 @@ export class AccessControlApiService {
|
|
|
249
249
|
|
|
250
250
|
// Validate the cleaned request body
|
|
251
251
|
// Note: Workaround for Zod schema issue where .optional() doesn't properly handle omitted fields
|
|
252
|
-
// See
|
|
252
|
+
// See CHECKPOINT_MCPI_COMPLIANCE_REVIEW.md for details
|
|
253
253
|
const validationResult =
|
|
254
254
|
verifyDelegationRequestSchema.safeParse(cleanedRequestBody);
|
|
255
255
|
if (!validationResult.success) {
|
|
@@ -258,15 +258,15 @@ export class AccessControlApiService {
|
|
|
258
258
|
(e) => e.path.includes("scopes") && e.message === "Required"
|
|
259
259
|
);
|
|
260
260
|
if (scopesError && !("scopes" in cleanedRequestBody)) {
|
|
261
|
-
// This is a known Zod schema issue in
|
|
261
|
+
// This is a known Zod schema issue in Checkpoint - scopes is optional but Zod treats it as required
|
|
262
262
|
// Skip validation for this case since the field is correctly omitted
|
|
263
|
-
// TODO: Remove this workaround once
|
|
263
|
+
// TODO: Remove this workaround once Checkpoint fixes their schema
|
|
264
264
|
} else {
|
|
265
265
|
this.config.logger(`[AccessControl] Validation failed:`, {
|
|
266
266
|
errors: validationResult.error.errors,
|
|
267
267
|
requestBody: requestBody,
|
|
268
268
|
});
|
|
269
|
-
throw new
|
|
269
|
+
throw new CheckpointAPIError(
|
|
270
270
|
"validation_error",
|
|
271
271
|
"Request validation failed",
|
|
272
272
|
{ zodErrors: validationResult.error.errors }
|
|
@@ -306,7 +306,7 @@ export class AccessControlApiService {
|
|
|
306
306
|
// Validate and parse success response
|
|
307
307
|
const parsed = verifyDelegationAPIResponseSchema.safeParse(responseData);
|
|
308
308
|
if (!parsed.success) {
|
|
309
|
-
throw new
|
|
309
|
+
throw new CheckpointAPIError(
|
|
310
310
|
"invalid_response",
|
|
311
311
|
"Response validation failed",
|
|
312
312
|
{ zodErrors: parsed.error.errors }
|
|
@@ -348,7 +348,7 @@ export class AccessControlApiService {
|
|
|
348
348
|
request: JSON.stringify(request, null, 2),
|
|
349
349
|
}
|
|
350
350
|
);
|
|
351
|
-
throw new
|
|
351
|
+
throw new CheckpointAPIError(
|
|
352
352
|
"validation_error",
|
|
353
353
|
`Request validation failed: ${errorDetails}`,
|
|
354
354
|
{ zodErrors: validationResult.error.errors }
|
|
@@ -412,7 +412,7 @@ export class AccessControlApiService {
|
|
|
412
412
|
if (!httpResponse.ok) {
|
|
413
413
|
const errorData = responseData as {
|
|
414
414
|
success?: boolean;
|
|
415
|
-
error?:
|
|
415
|
+
error?: CheckpointAPIErrorResponse;
|
|
416
416
|
};
|
|
417
417
|
|
|
418
418
|
if (errorData.error) {
|
|
@@ -450,7 +450,7 @@ export class AccessControlApiService {
|
|
|
450
450
|
}
|
|
451
451
|
|
|
452
452
|
// If validation fails, log and throw error
|
|
453
|
-
throw new
|
|
453
|
+
throw new CheckpointAPIError(
|
|
454
454
|
"invalid_response",
|
|
455
455
|
"Error response validation failed",
|
|
456
456
|
{ zodErrors: validated.error.errors }
|
|
@@ -462,7 +462,7 @@ export class AccessControlApiService {
|
|
|
462
462
|
...(errorData.error.details || {}),
|
|
463
463
|
status: httpResponse.status,
|
|
464
464
|
};
|
|
465
|
-
throw new
|
|
465
|
+
throw new CheckpointAPIError(
|
|
466
466
|
errorCode,
|
|
467
467
|
errorData.error.message || `API error: ${httpResponse.status}`,
|
|
468
468
|
errorDetails
|
|
@@ -479,7 +479,7 @@ export class AccessControlApiService {
|
|
|
479
479
|
: "session_not_found";
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
-
throw new
|
|
482
|
+
throw new CheckpointAPIError(
|
|
483
483
|
errorCode,
|
|
484
484
|
`API request failed: ${httpResponse.status} ${httpResponse.statusText}`,
|
|
485
485
|
{ status: httpResponse.status, responseData }
|
|
@@ -529,7 +529,7 @@ export class AccessControlApiService {
|
|
|
529
529
|
const clonedData = JSON.parse(JSON.stringify(rawData));
|
|
530
530
|
|
|
531
531
|
if (typeof clonedData !== "object" || clonedData === null) {
|
|
532
|
-
throw new
|
|
532
|
+
throw new CheckpointAPIError(
|
|
533
533
|
"invalid_response",
|
|
534
534
|
"Response data is not an object after cloning",
|
|
535
535
|
{
|
|
@@ -542,10 +542,10 @@ export class AccessControlApiService {
|
|
|
542
542
|
|
|
543
543
|
dataToValidate = clonedData as Record<string, unknown>;
|
|
544
544
|
} catch (cloneError) {
|
|
545
|
-
if (cloneError instanceof
|
|
545
|
+
if (cloneError instanceof CheckpointAPIError) {
|
|
546
546
|
throw cloneError;
|
|
547
547
|
}
|
|
548
|
-
throw new
|
|
548
|
+
throw new CheckpointAPIError(
|
|
549
549
|
"invalid_response",
|
|
550
550
|
"Failed to clone response data",
|
|
551
551
|
{
|
|
@@ -634,7 +634,7 @@ export class AccessControlApiService {
|
|
|
634
634
|
originalResponseData: JSON.stringify(responseData, null, 2),
|
|
635
635
|
}
|
|
636
636
|
);
|
|
637
|
-
throw new
|
|
637
|
+
throw new CheckpointAPIError(
|
|
638
638
|
"invalid_response",
|
|
639
639
|
"Response data missing required fields (accepted/rejected)",
|
|
640
640
|
{
|
|
@@ -717,7 +717,7 @@ export class AccessControlApiService {
|
|
|
717
717
|
);
|
|
718
718
|
// CRITICAL: Throw error instead of falling through to direct parsing
|
|
719
719
|
// The response is wrapped, so direct parsing will also fail
|
|
720
|
-
throw new
|
|
720
|
+
throw new CheckpointAPIError(
|
|
721
721
|
"invalid_response",
|
|
722
722
|
"Response validation failed",
|
|
723
723
|
{ zodErrors: dataParsed.error.errors, responseData }
|
|
@@ -782,7 +782,7 @@ export class AccessControlApiService {
|
|
|
782
782
|
`[AccessControl] ❌ ACTUAL RESPONSE DATA:`,
|
|
783
783
|
JSON.stringify(responseData, null, 2)
|
|
784
784
|
);
|
|
785
|
-
throw new
|
|
785
|
+
throw new CheckpointAPIError(
|
|
786
786
|
"invalid_response",
|
|
787
787
|
"Response validation failed",
|
|
788
788
|
{ zodErrors: parsed.error.errors, responseData }
|
|
@@ -867,8 +867,8 @@ export class AccessControlApiService {
|
|
|
867
867
|
return true;
|
|
868
868
|
}
|
|
869
869
|
|
|
870
|
-
//
|
|
871
|
-
if (error instanceof
|
|
870
|
+
// CheckpointAPIError with 5xx status codes are retryable
|
|
871
|
+
if (error instanceof CheckpointAPIError) {
|
|
872
872
|
// Check error code for server errors
|
|
873
873
|
if (error.code === "server_error") {
|
|
874
874
|
return true;
|
|
@@ -918,7 +918,7 @@ export class AccessControlApiService {
|
|
|
918
918
|
// Handle non-JSON error responses (e.g., plain text "Internal Server Error")
|
|
919
919
|
if (!response.ok) {
|
|
920
920
|
const errorCode = this.mapStatusToErrorCode(response.status);
|
|
921
|
-
throw new
|
|
921
|
+
throw new CheckpointAPIError(
|
|
922
922
|
errorCode,
|
|
923
923
|
`API request failed: ${response.status} ${response.statusText}`,
|
|
924
924
|
{
|
|
@@ -928,7 +928,7 @@ export class AccessControlApiService {
|
|
|
928
928
|
);
|
|
929
929
|
}
|
|
930
930
|
// For success responses that aren't JSON, throw invalid_response error
|
|
931
|
-
throw new
|
|
931
|
+
throw new CheckpointAPIError(
|
|
932
932
|
"invalid_response",
|
|
933
933
|
`Failed to parse response: ${error instanceof Error ? error.message : String(error)}`,
|
|
934
934
|
{ responseText: responseText.substring(0, 500) }
|
|
@@ -955,7 +955,7 @@ export class AccessControlApiService {
|
|
|
955
955
|
}
|
|
956
956
|
|
|
957
957
|
/**
|
|
958
|
-
* Handle error responses and throw appropriate
|
|
958
|
+
* Handle error responses and throw appropriate CheckpointAPIError
|
|
959
959
|
*
|
|
960
960
|
* @internal
|
|
961
961
|
*/
|
|
@@ -965,7 +965,7 @@ export class AccessControlApiService {
|
|
|
965
965
|
): never {
|
|
966
966
|
const errorData = responseData as {
|
|
967
967
|
success?: boolean;
|
|
968
|
-
error?:
|
|
968
|
+
error?: CheckpointAPIErrorResponse;
|
|
969
969
|
};
|
|
970
970
|
|
|
971
971
|
if (errorData.error) {
|
|
@@ -975,7 +975,7 @@ export class AccessControlApiService {
|
|
|
975
975
|
...(errorData.error.details || {}),
|
|
976
976
|
status: response.status,
|
|
977
977
|
};
|
|
978
|
-
throw new
|
|
978
|
+
throw new CheckpointAPIError(
|
|
979
979
|
errorCode,
|
|
980
980
|
errorData.error.message || `API error: ${response.status}`,
|
|
981
981
|
errorDetails
|
|
@@ -987,7 +987,7 @@ export class AccessControlApiService {
|
|
|
987
987
|
response.status,
|
|
988
988
|
response.statusText
|
|
989
989
|
);
|
|
990
|
-
throw new
|
|
990
|
+
throw new CheckpointAPIError(
|
|
991
991
|
errorCode,
|
|
992
992
|
`API request failed: ${response.status} ${response.statusText}`,
|
|
993
993
|
{ status: response.status, responseData }
|