@kya-os/contracts 1.3.5 → 1.4.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/dist/agentshield-api/endpoints.d.ts +50 -0
- package/dist/agentshield-api/endpoints.js +46 -0
- package/dist/agentshield-api/index.d.ts +13 -0
- package/dist/agentshield-api/index.js +38 -0
- package/dist/agentshield-api/schemas.d.ts +9914 -0
- package/dist/agentshield-api/schemas.js +165 -0
- package/dist/agentshield-api/types.d.ts +168 -0
- package/dist/agentshield-api/types.js +27 -0
- package/dist/cli.d.ts +13 -0
- package/dist/cli.js +13 -1
- package/dist/config/base.d.ts +96 -0
- package/dist/config/base.js +11 -0
- package/dist/config/delegation.d.ts +194 -0
- package/dist/config/delegation.js +10 -0
- package/dist/config/identity.d.ts +117 -0
- package/dist/config/identity.js +11 -0
- package/dist/config/index.d.ts +33 -0
- package/dist/config/index.js +11 -0
- package/dist/config/proofing.d.ts +120 -0
- package/dist/config/proofing.js +10 -0
- package/dist/config/tool-protection.d.ts +139 -0
- package/dist/config/tool-protection.js +10 -0
- package/dist/dashboard-config/index.d.ts +10 -0
- package/dist/dashboard-config/index.js +31 -0
- package/dist/dashboard-config/schemas.d.ts +5847 -0
- package/dist/dashboard-config/schemas.js +251 -0
- package/dist/dashboard-config/types.d.ts +331 -0
- package/dist/dashboard-config/types.js +11 -0
- package/dist/delegation/constraints.d.ts +991 -0
- package/dist/delegation/constraints.js +209 -0
- package/dist/delegation/index.d.ts +7 -0
- package/dist/delegation/index.js +23 -0
- package/dist/delegation/schemas.d.ts +8381 -0
- package/dist/delegation/schemas.js +475 -0
- package/dist/did/index.d.ts +8 -0
- package/dist/did/index.js +24 -0
- package/dist/did/resolve-contract.d.ts +219 -0
- package/dist/did/resolve-contract.js +31 -0
- package/dist/did/schemas.d.ts +112 -0
- package/dist/did/schemas.js +172 -0
- package/dist/did/types.d.ts +163 -0
- package/dist/did/types.js +70 -0
- package/dist/env/constants.d.ts +57 -0
- package/dist/env/constants.js +59 -0
- package/dist/env/index.d.ts +4 -0
- package/dist/env/index.js +20 -0
- package/dist/handshake.d.ts +20 -0
- package/dist/handshake.js +10 -3
- package/dist/index.d.ts +14 -0
- package/dist/index.js +28 -0
- package/dist/proof/index.d.ts +8 -0
- package/dist/proof/index.js +24 -0
- package/dist/proof/proof-record.d.ts +837 -0
- package/dist/proof/proof-record.js +133 -0
- package/dist/proof/signing-spec.d.ts +146 -0
- package/dist/proof/signing-spec.js +122 -0
- package/dist/proof.d.ts +53 -16
- package/dist/proof.js +27 -3
- package/dist/registry.d.ts +16 -0
- package/dist/registry.js +29 -9
- package/dist/runtime/errors.d.ts +347 -0
- package/dist/runtime/errors.js +119 -0
- package/dist/runtime/headers.d.ts +83 -0
- package/dist/runtime/headers.js +81 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.js +21 -0
- package/dist/test.d.ts +36 -0
- package/dist/test.js +36 -0
- package/dist/tlkrc/index.d.ts +4 -0
- package/dist/tlkrc/index.js +20 -0
- package/dist/tlkrc/rotation.d.ts +245 -0
- package/dist/tlkrc/rotation.js +126 -0
- package/dist/tool-protection/index.d.ts +227 -0
- package/dist/tool-protection/index.js +113 -0
- package/dist/utils/validation.d.ts +16 -0
- package/dist/utils/validation.js +13 -0
- package/dist/vc/index.d.ts +7 -0
- package/dist/vc/index.js +23 -0
- package/dist/vc/schemas.d.ts +2483 -0
- package/dist/vc/schemas.js +224 -0
- package/dist/vc/statuslist.d.ts +493 -0
- package/dist/vc/statuslist.js +132 -0
- package/dist/verifier.d.ts +3 -0
- package/dist/verifier.js +7 -0
- package/dist/well-known/index.d.ts +308 -0
- package/dist/well-known/index.js +134 -0
- package/package.json +6 -1
package/dist/proof.js
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ProofSubmissionRequestSchema = exports.ProofSubmissionContextSchema = exports.ToolCallContextSchema = exports.AUDIT_VERSION = exports.HASH_ALGORITHM = exports.JWS_ALGORITHM = exports.AuditRecordSchema = exports.CanonicalHashesSchema = exports.DetachedProofSchema = exports.ProofMetaSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Proof and signature schemas for MCP-I
|
|
7
|
+
*
|
|
8
|
+
* Note: The type name "DetachedProof" is maintained for backward compatibility,
|
|
9
|
+
* but the JWS format is actually FULL compact JWS (header.payload.signature),
|
|
10
|
+
* not detached format (header..signature).
|
|
11
|
+
*
|
|
12
|
+
* The JWS payload contains JWT standard claims (aud, sub, iss) plus custom
|
|
13
|
+
* proof claims (requestHash, responseHash, nonce, etc.).
|
|
14
|
+
*/
|
|
5
15
|
exports.ProofMetaSchema = zod_1.z.object({
|
|
6
16
|
did: zod_1.z.string().min(1),
|
|
7
17
|
kid: zod_1.z.string().min(1),
|
|
@@ -13,10 +23,11 @@ exports.ProofMetaSchema = zod_1.z.object({
|
|
|
13
23
|
responseHash: zod_1.z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
14
24
|
scopeId: zod_1.z.string().optional(),
|
|
15
25
|
delegationRef: zod_1.z.string().optional(),
|
|
26
|
+
clientDid: zod_1.z.string().optional(), // Optional for backward compatibility
|
|
16
27
|
});
|
|
17
28
|
exports.DetachedProofSchema = zod_1.z.object({
|
|
18
|
-
jws: zod_1.z.string().min(1),
|
|
19
|
-
meta: exports.ProofMetaSchema,
|
|
29
|
+
jws: zod_1.z.string().min(1), // Full compact JWS format (header.payload.signature)
|
|
30
|
+
meta: exports.ProofMetaSchema, // Convenience metadata (duplicates signed payload data)
|
|
20
31
|
});
|
|
21
32
|
exports.CanonicalHashesSchema = zod_1.z.object({
|
|
22
33
|
requestHash: zod_1.z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
@@ -32,11 +43,16 @@ exports.AuditRecordSchema = zod_1.z.object({
|
|
|
32
43
|
reqHash: zod_1.z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
33
44
|
resHash: zod_1.z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
34
45
|
verified: zod_1.z.enum(["yes", "no"]),
|
|
35
|
-
scope: zod_1.z.string().min(1),
|
|
46
|
+
scope: zod_1.z.string().min(1), // "-" for no scope
|
|
36
47
|
});
|
|
48
|
+
// Constants
|
|
37
49
|
exports.JWS_ALGORITHM = "EdDSA";
|
|
38
50
|
exports.HASH_ALGORITHM = "sha256";
|
|
39
51
|
exports.AUDIT_VERSION = "audit.v1";
|
|
52
|
+
/**
|
|
53
|
+
* Tool call context for AgentShield dashboard integration
|
|
54
|
+
* Provides plaintext tool execution data alongside cryptographic proofs
|
|
55
|
+
*/
|
|
40
56
|
exports.ToolCallContextSchema = zod_1.z.object({
|
|
41
57
|
tool: zod_1.z.string().min(1),
|
|
42
58
|
args: zod_1.z.record(zod_1.z.unknown()),
|
|
@@ -44,10 +60,17 @@ exports.ToolCallContextSchema = zod_1.z.object({
|
|
|
44
60
|
scopeId: zod_1.z.string(),
|
|
45
61
|
userId: zod_1.z.string().optional(),
|
|
46
62
|
});
|
|
63
|
+
/**
|
|
64
|
+
* Proof submission context for AgentShield API
|
|
65
|
+
* Includes tool calls and optional MCP server URL for tool discovery
|
|
66
|
+
*/
|
|
47
67
|
exports.ProofSubmissionContextSchema = zod_1.z.object({
|
|
48
68
|
toolCalls: zod_1.z.array(exports.ToolCallContextSchema),
|
|
49
69
|
mcpServerUrl: zod_1.z.string().url().optional(),
|
|
50
70
|
});
|
|
71
|
+
/**
|
|
72
|
+
* Complete proof submission request to AgentShield
|
|
73
|
+
*/
|
|
51
74
|
exports.ProofSubmissionRequestSchema = zod_1.z.object({
|
|
52
75
|
session_id: zod_1.z.string().min(1),
|
|
53
76
|
delegation_id: zod_1.z.string().nullable().optional(),
|
|
@@ -57,3 +80,4 @@ exports.ProofSubmissionRequestSchema = zod_1.z.object({
|
|
|
57
80
|
})),
|
|
58
81
|
context: exports.ProofSubmissionContextSchema.optional(),
|
|
59
82
|
});
|
|
83
|
+
//# sourceMappingURL=proof.js.map
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Registry integration schemas (Know-That-AI and MCP Registry)
|
|
4
|
+
*/
|
|
2
5
|
export declare const RegistrationInputSchema: z.ZodObject<{
|
|
3
6
|
agentDID: z.ZodString;
|
|
4
7
|
agentURL: z.ZodString;
|
|
@@ -122,6 +125,9 @@ export declare const AgentStatusSchema: z.ZodObject<{
|
|
|
122
125
|
};
|
|
123
126
|
lastHandshake?: number | undefined;
|
|
124
127
|
}>;
|
|
128
|
+
/**
|
|
129
|
+
* Delegation schemas for verifiable credentials
|
|
130
|
+
*/
|
|
125
131
|
export declare const DelegationSchema: z.ZodObject<{
|
|
126
132
|
issuer: z.ZodString;
|
|
127
133
|
subject: z.ZodString;
|
|
@@ -163,7 +169,14 @@ export declare const DelegationRequestSchema: z.ZodObject<{
|
|
|
163
169
|
audience?: string | undefined;
|
|
164
170
|
duration?: number | undefined;
|
|
165
171
|
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Storage mode configuration for verifiable credentials and delegations
|
|
174
|
+
*/
|
|
166
175
|
export declare const StorageModeSchema: z.ZodEnum<["ktaEncrypted", "hybridReceiptsOnly", "selfHostedAuthoritative"]>;
|
|
176
|
+
/**
|
|
177
|
+
* Receipt object returned by KTA for verifiable operations
|
|
178
|
+
* Schema ID: https://schemas.kya-os.ai/mcpi/receipt/v1.0.0.json
|
|
179
|
+
*/
|
|
167
180
|
export declare const ReceiptSchema: z.ZodObject<{
|
|
168
181
|
$schema: z.ZodOptional<z.ZodLiteral<"https://schemas.kya-os.ai/mcpi/receipt/v1.0.0.json">>;
|
|
169
182
|
ref: z.ZodString;
|
|
@@ -290,6 +303,9 @@ export declare const DelegationResponseSchema: z.ZodObject<{
|
|
|
290
303
|
};
|
|
291
304
|
encryptedPayload?: string | undefined;
|
|
292
305
|
}>;
|
|
306
|
+
/**
|
|
307
|
+
* Storage configuration for different deployment modes
|
|
308
|
+
*/
|
|
293
309
|
export declare const StorageConfigSchema: z.ZodObject<{
|
|
294
310
|
mode: z.ZodEnum<["ktaEncrypted", "hybridReceiptsOnly", "selfHostedAuthoritative"]>;
|
|
295
311
|
encryptionEnabled: z.ZodDefault<z.ZodBoolean>;
|
package/dist/registry.js
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CONTENT_HASH_REGEX = exports.RECEIPT_SCHEMA_ID = exports.STORAGE_MODE_ENV_VAR = exports.DEFAULT_STORAGE_MODE = exports.KTA_BASE_URL = exports.CLAIM_TOKEN_TTL_HOURS = exports.MCP_I_CAPABILITIES = exports.StorageConfigSchema = exports.DelegationResponseSchema = exports.ReceiptSchema = exports.StorageModeSchema = exports.DelegationRequestSchema = exports.DelegationSchema = exports.AgentStatusSchema = exports.MirrorStatusSchema = exports.ClaimTokenSchema = exports.RegistrationResultSchema = exports.RegistrationInputSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Registry integration schemas (Know-That-AI and MCP Registry)
|
|
7
|
+
*/
|
|
5
8
|
exports.RegistrationInputSchema = zod_1.z.object({
|
|
6
9
|
agentDID: zod_1.z.string().min(1),
|
|
7
10
|
agentURL: zod_1.z.string().url(),
|
|
@@ -42,26 +45,36 @@ exports.AgentStatusSchema = zod_1.z.object({
|
|
|
42
45
|
mirrorStatus: exports.MirrorStatusSchema,
|
|
43
46
|
lastHandshake: zod_1.z.number().int().positive().optional(),
|
|
44
47
|
});
|
|
48
|
+
/**
|
|
49
|
+
* Delegation schemas for verifiable credentials
|
|
50
|
+
*/
|
|
45
51
|
exports.DelegationSchema = zod_1.z.object({
|
|
46
|
-
issuer: zod_1.z.string().min(1),
|
|
47
|
-
subject: zod_1.z.string().min(1),
|
|
52
|
+
issuer: zod_1.z.string().min(1), // DID of the issuer
|
|
53
|
+
subject: zod_1.z.string().min(1), // DID of the subject
|
|
48
54
|
scopes: zod_1.z.array(zod_1.z.string()),
|
|
49
|
-
nbf: zod_1.z.number().int().positive(),
|
|
50
|
-
exp: zod_1.z.number().int().positive(),
|
|
51
|
-
aud: zod_1.z.string().optional(),
|
|
52
|
-
delegationRef: zod_1.z.string().optional(),
|
|
55
|
+
nbf: zod_1.z.number().int().positive(), // Not before (unix timestamp)
|
|
56
|
+
exp: zod_1.z.number().int().positive(), // Expires (unix timestamp)
|
|
57
|
+
aud: zod_1.z.string().optional(), // Audience (optional)
|
|
58
|
+
delegationRef: zod_1.z.string().optional(), // Reference to parent delegation
|
|
53
59
|
});
|
|
54
60
|
exports.DelegationRequestSchema = zod_1.z.object({
|
|
55
61
|
subject: zod_1.z.string().min(1),
|
|
56
62
|
scopes: zod_1.z.array(zod_1.z.string()),
|
|
57
|
-
duration: zod_1.z.number().int().positive().optional(),
|
|
63
|
+
duration: zod_1.z.number().int().positive().optional(), // Duration in seconds
|
|
58
64
|
audience: zod_1.z.string().optional(),
|
|
59
65
|
});
|
|
66
|
+
/**
|
|
67
|
+
* Storage mode configuration for verifiable credentials and delegations
|
|
68
|
+
*/
|
|
60
69
|
exports.StorageModeSchema = zod_1.z.enum([
|
|
61
70
|
"ktaEncrypted",
|
|
62
71
|
"hybridReceiptsOnly",
|
|
63
72
|
"selfHostedAuthoritative",
|
|
64
73
|
]);
|
|
74
|
+
/**
|
|
75
|
+
* Receipt object returned by KTA for verifiable operations
|
|
76
|
+
* Schema ID: https://schemas.kya-os.ai/mcpi/receipt/v1.0.0.json
|
|
77
|
+
*/
|
|
65
78
|
exports.ReceiptSchema = zod_1.z.object({
|
|
66
79
|
$schema: zod_1.z
|
|
67
80
|
.literal("https://schemas.kya-os.ai/mcpi/receipt/v1.0.0.json")
|
|
@@ -69,6 +82,7 @@ exports.ReceiptSchema = zod_1.z.object({
|
|
|
69
82
|
ref: zod_1.z.string().min(1),
|
|
70
83
|
contentHash: zod_1.z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
71
84
|
action: zod_1.z.enum(["issue", "revoke"]),
|
|
85
|
+
// Back-compat: accept ISO string (preferred) or legacy epoch number
|
|
72
86
|
ts: zod_1.z.union([zod_1.z.string().datetime(), zod_1.z.number().int().positive()]),
|
|
73
87
|
logIndex: zod_1.z.number().int().nonnegative(),
|
|
74
88
|
logRoot: zod_1.z.string().min(1),
|
|
@@ -77,22 +91,28 @@ exports.ReceiptSchema = zod_1.z.object({
|
|
|
77
91
|
exports.DelegationResponseSchema = zod_1.z.object({
|
|
78
92
|
delegation: exports.DelegationSchema,
|
|
79
93
|
receipt: exports.ReceiptSchema,
|
|
80
|
-
encryptedPayload: zod_1.z.string().optional(),
|
|
94
|
+
encryptedPayload: zod_1.z.string().optional(), // For ktaEncrypted mode
|
|
81
95
|
});
|
|
96
|
+
/**
|
|
97
|
+
* Storage configuration for different deployment modes
|
|
98
|
+
*/
|
|
82
99
|
exports.StorageConfigSchema = zod_1.z.object({
|
|
83
100
|
mode: exports.StorageModeSchema,
|
|
84
101
|
encryptionEnabled: zod_1.z.boolean().default(false),
|
|
85
102
|
receiptVerificationEnabled: zod_1.z.boolean().default(true),
|
|
86
103
|
ktaBaseURL: zod_1.z.string().url().default("https://knowthat.ai"),
|
|
87
104
|
});
|
|
105
|
+
// Constants
|
|
88
106
|
exports.MCP_I_CAPABILITIES = [
|
|
89
107
|
"handshake",
|
|
90
108
|
"signing",
|
|
91
109
|
"verification",
|
|
92
110
|
];
|
|
93
111
|
exports.CLAIM_TOKEN_TTL_HOURS = 24;
|
|
94
|
-
exports.KTA_BASE_URL = "https://knowthat.ai";
|
|
112
|
+
exports.KTA_BASE_URL = "https://knowthat.ai"; // Placeholder for docs/tests
|
|
113
|
+
// Storage mode constants
|
|
95
114
|
exports.DEFAULT_STORAGE_MODE = "ktaEncrypted";
|
|
96
115
|
exports.STORAGE_MODE_ENV_VAR = "MCPI_STORAGE_MODE";
|
|
116
|
+
// Receipt schema constants
|
|
97
117
|
exports.RECEIPT_SCHEMA_ID = "https://schemas.kya-os.ai/mcpi/receipt/v1.0.0.json";
|
|
98
118
|
exports.CONTENT_HASH_REGEX = /^sha256:[a-f0-9]{64}$/;
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Error Contracts
|
|
3
|
+
*
|
|
4
|
+
* Error types and schemas for runtime errors, especially authorization errors
|
|
5
|
+
*
|
|
6
|
+
* Related Spec: MCP-I §6
|
|
7
|
+
* Python Reference: Core-Documentation.md
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
/**
|
|
11
|
+
* Display hint types for authorization UI
|
|
12
|
+
*/
|
|
13
|
+
export declare const DisplayHintSchema: z.ZodEnum<["link", "qr", "code"]>;
|
|
14
|
+
export type DisplayHint = z.infer<typeof DisplayHintSchema>;
|
|
15
|
+
/**
|
|
16
|
+
* Display options for authorization flow
|
|
17
|
+
*/
|
|
18
|
+
export declare const AuthorizationDisplaySchema: z.ZodObject<{
|
|
19
|
+
/** Optional title for the authorization screen */
|
|
20
|
+
title: z.ZodOptional<z.ZodString>;
|
|
21
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
22
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
23
|
+
/** Optional short authorization code */
|
|
24
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
25
|
+
/** Optional QR code URL */
|
|
26
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
28
|
+
/** Optional title for the authorization screen */
|
|
29
|
+
title: z.ZodOptional<z.ZodString>;
|
|
30
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
31
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
32
|
+
/** Optional short authorization code */
|
|
33
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
34
|
+
/** Optional QR code URL */
|
|
35
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
37
|
+
/** Optional title for the authorization screen */
|
|
38
|
+
title: z.ZodOptional<z.ZodString>;
|
|
39
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
40
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
41
|
+
/** Optional short authorization code */
|
|
42
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
43
|
+
/** Optional QR code URL */
|
|
44
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
46
|
+
export type AuthorizationDisplay = z.infer<typeof AuthorizationDisplaySchema>;
|
|
47
|
+
/**
|
|
48
|
+
* NeedsAuthorizationError Schema
|
|
49
|
+
*
|
|
50
|
+
* Error returned when a request requires authorization.
|
|
51
|
+
* Includes a resumeToken and authorizationUrl for the authorization flow.
|
|
52
|
+
*/
|
|
53
|
+
export declare const NeedsAuthorizationErrorSchema: z.ZodObject<{
|
|
54
|
+
/** Error code */
|
|
55
|
+
error: z.ZodLiteral<"needs_authorization">;
|
|
56
|
+
/** Human-readable error message */
|
|
57
|
+
message: z.ZodString;
|
|
58
|
+
/** URL for the user to authorize (includes resume token) */
|
|
59
|
+
authorizationUrl: z.ZodString;
|
|
60
|
+
/** Short-lived resume token for continuing after authorization */
|
|
61
|
+
resumeToken: z.ZodString;
|
|
62
|
+
/** Expiration timestamp for the resume token (milliseconds since epoch) */
|
|
63
|
+
expiresAt: z.ZodNumber;
|
|
64
|
+
/** Required scopes for authorization */
|
|
65
|
+
scopes: z.ZodArray<z.ZodString, "many">;
|
|
66
|
+
/** Optional display configuration for authorization UI */
|
|
67
|
+
display: z.ZodOptional<z.ZodObject<{
|
|
68
|
+
/** Optional title for the authorization screen */
|
|
69
|
+
title: z.ZodOptional<z.ZodString>;
|
|
70
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
71
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
72
|
+
/** Optional short authorization code */
|
|
73
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
74
|
+
/** Optional QR code URL */
|
|
75
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
76
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
77
|
+
/** Optional title for the authorization screen */
|
|
78
|
+
title: z.ZodOptional<z.ZodString>;
|
|
79
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
80
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
81
|
+
/** Optional short authorization code */
|
|
82
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
83
|
+
/** Optional QR code URL */
|
|
84
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
86
|
+
/** Optional title for the authorization screen */
|
|
87
|
+
title: z.ZodOptional<z.ZodString>;
|
|
88
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
89
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
90
|
+
/** Optional short authorization code */
|
|
91
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
92
|
+
/** Optional QR code URL */
|
|
93
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
94
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
95
|
+
/** Optional additional context */
|
|
96
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
97
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
98
|
+
/** Error code */
|
|
99
|
+
error: z.ZodLiteral<"needs_authorization">;
|
|
100
|
+
/** Human-readable error message */
|
|
101
|
+
message: z.ZodString;
|
|
102
|
+
/** URL for the user to authorize (includes resume token) */
|
|
103
|
+
authorizationUrl: z.ZodString;
|
|
104
|
+
/** Short-lived resume token for continuing after authorization */
|
|
105
|
+
resumeToken: z.ZodString;
|
|
106
|
+
/** Expiration timestamp for the resume token (milliseconds since epoch) */
|
|
107
|
+
expiresAt: z.ZodNumber;
|
|
108
|
+
/** Required scopes for authorization */
|
|
109
|
+
scopes: z.ZodArray<z.ZodString, "many">;
|
|
110
|
+
/** Optional display configuration for authorization UI */
|
|
111
|
+
display: z.ZodOptional<z.ZodObject<{
|
|
112
|
+
/** Optional title for the authorization screen */
|
|
113
|
+
title: z.ZodOptional<z.ZodString>;
|
|
114
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
115
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
116
|
+
/** Optional short authorization code */
|
|
117
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
118
|
+
/** Optional QR code URL */
|
|
119
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
120
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
121
|
+
/** Optional title for the authorization screen */
|
|
122
|
+
title: z.ZodOptional<z.ZodString>;
|
|
123
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
124
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
125
|
+
/** Optional short authorization code */
|
|
126
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
127
|
+
/** Optional QR code URL */
|
|
128
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
129
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
130
|
+
/** Optional title for the authorization screen */
|
|
131
|
+
title: z.ZodOptional<z.ZodString>;
|
|
132
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
133
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
134
|
+
/** Optional short authorization code */
|
|
135
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
136
|
+
/** Optional QR code URL */
|
|
137
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
138
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
139
|
+
/** Optional additional context */
|
|
140
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
141
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
142
|
+
/** Error code */
|
|
143
|
+
error: z.ZodLiteral<"needs_authorization">;
|
|
144
|
+
/** Human-readable error message */
|
|
145
|
+
message: z.ZodString;
|
|
146
|
+
/** URL for the user to authorize (includes resume token) */
|
|
147
|
+
authorizationUrl: z.ZodString;
|
|
148
|
+
/** Short-lived resume token for continuing after authorization */
|
|
149
|
+
resumeToken: z.ZodString;
|
|
150
|
+
/** Expiration timestamp for the resume token (milliseconds since epoch) */
|
|
151
|
+
expiresAt: z.ZodNumber;
|
|
152
|
+
/** Required scopes for authorization */
|
|
153
|
+
scopes: z.ZodArray<z.ZodString, "many">;
|
|
154
|
+
/** Optional display configuration for authorization UI */
|
|
155
|
+
display: z.ZodOptional<z.ZodObject<{
|
|
156
|
+
/** Optional title for the authorization screen */
|
|
157
|
+
title: z.ZodOptional<z.ZodString>;
|
|
158
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
159
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
160
|
+
/** Optional short authorization code */
|
|
161
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
162
|
+
/** Optional QR code URL */
|
|
163
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
164
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
165
|
+
/** Optional title for the authorization screen */
|
|
166
|
+
title: z.ZodOptional<z.ZodString>;
|
|
167
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
168
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
169
|
+
/** Optional short authorization code */
|
|
170
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
171
|
+
/** Optional QR code URL */
|
|
172
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
173
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
174
|
+
/** Optional title for the authorization screen */
|
|
175
|
+
title: z.ZodOptional<z.ZodString>;
|
|
176
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
177
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
178
|
+
/** Optional short authorization code */
|
|
179
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
180
|
+
/** Optional QR code URL */
|
|
181
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
182
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
183
|
+
/** Optional additional context */
|
|
184
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
185
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
186
|
+
export type NeedsAuthorizationError = z.infer<typeof NeedsAuthorizationErrorSchema>;
|
|
187
|
+
/**
|
|
188
|
+
* Generic Error Schema
|
|
189
|
+
*
|
|
190
|
+
* Standard error format for all runtime errors
|
|
191
|
+
*/
|
|
192
|
+
export declare const RuntimeErrorSchema: z.ZodObject<{
|
|
193
|
+
/** Error code */
|
|
194
|
+
error: z.ZodString;
|
|
195
|
+
/** Human-readable error message */
|
|
196
|
+
message: z.ZodString;
|
|
197
|
+
/** Optional error details */
|
|
198
|
+
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
199
|
+
/** HTTP status code (if applicable) */
|
|
200
|
+
httpStatus: z.ZodOptional<z.ZodNumber>;
|
|
201
|
+
}, "strip", z.ZodTypeAny, {
|
|
202
|
+
message: string;
|
|
203
|
+
error: string;
|
|
204
|
+
details?: Record<string, any> | undefined;
|
|
205
|
+
httpStatus?: number | undefined;
|
|
206
|
+
}, {
|
|
207
|
+
message: string;
|
|
208
|
+
error: string;
|
|
209
|
+
details?: Record<string, any> | undefined;
|
|
210
|
+
httpStatus?: number | undefined;
|
|
211
|
+
}>;
|
|
212
|
+
export type RuntimeError = z.infer<typeof RuntimeErrorSchema>;
|
|
213
|
+
/**
|
|
214
|
+
* Validation Helpers
|
|
215
|
+
*/
|
|
216
|
+
/**
|
|
217
|
+
* Validate a needs authorization error
|
|
218
|
+
*
|
|
219
|
+
* @param error - The error to validate
|
|
220
|
+
* @returns Validation result
|
|
221
|
+
*/
|
|
222
|
+
export declare function validateNeedsAuthorizationError(error: unknown): z.SafeParseReturnType<z.objectInputType<{
|
|
223
|
+
/** Error code */
|
|
224
|
+
error: z.ZodLiteral<"needs_authorization">;
|
|
225
|
+
/** Human-readable error message */
|
|
226
|
+
message: z.ZodString;
|
|
227
|
+
/** URL for the user to authorize (includes resume token) */
|
|
228
|
+
authorizationUrl: z.ZodString;
|
|
229
|
+
/** Short-lived resume token for continuing after authorization */
|
|
230
|
+
resumeToken: z.ZodString;
|
|
231
|
+
/** Expiration timestamp for the resume token (milliseconds since epoch) */
|
|
232
|
+
expiresAt: z.ZodNumber;
|
|
233
|
+
/** Required scopes for authorization */
|
|
234
|
+
scopes: z.ZodArray<z.ZodString, "many">;
|
|
235
|
+
/** Optional display configuration for authorization UI */
|
|
236
|
+
display: z.ZodOptional<z.ZodObject<{
|
|
237
|
+
/** Optional title for the authorization screen */
|
|
238
|
+
title: z.ZodOptional<z.ZodString>;
|
|
239
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
240
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
241
|
+
/** Optional short authorization code */
|
|
242
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
243
|
+
/** Optional QR code URL */
|
|
244
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
245
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
246
|
+
/** Optional title for the authorization screen */
|
|
247
|
+
title: z.ZodOptional<z.ZodString>;
|
|
248
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
249
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
250
|
+
/** Optional short authorization code */
|
|
251
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
252
|
+
/** Optional QR code URL */
|
|
253
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
254
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
255
|
+
/** Optional title for the authorization screen */
|
|
256
|
+
title: z.ZodOptional<z.ZodString>;
|
|
257
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
258
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
259
|
+
/** Optional short authorization code */
|
|
260
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
261
|
+
/** Optional QR code URL */
|
|
262
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
263
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
264
|
+
/** Optional additional context */
|
|
265
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
266
|
+
}, z.ZodTypeAny, "passthrough">, z.objectOutputType<{
|
|
267
|
+
/** Error code */
|
|
268
|
+
error: z.ZodLiteral<"needs_authorization">;
|
|
269
|
+
/** Human-readable error message */
|
|
270
|
+
message: z.ZodString;
|
|
271
|
+
/** URL for the user to authorize (includes resume token) */
|
|
272
|
+
authorizationUrl: z.ZodString;
|
|
273
|
+
/** Short-lived resume token for continuing after authorization */
|
|
274
|
+
resumeToken: z.ZodString;
|
|
275
|
+
/** Expiration timestamp for the resume token (milliseconds since epoch) */
|
|
276
|
+
expiresAt: z.ZodNumber;
|
|
277
|
+
/** Required scopes for authorization */
|
|
278
|
+
scopes: z.ZodArray<z.ZodString, "many">;
|
|
279
|
+
/** Optional display configuration for authorization UI */
|
|
280
|
+
display: z.ZodOptional<z.ZodObject<{
|
|
281
|
+
/** Optional title for the authorization screen */
|
|
282
|
+
title: z.ZodOptional<z.ZodString>;
|
|
283
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
284
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
285
|
+
/** Optional short authorization code */
|
|
286
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
287
|
+
/** Optional QR code URL */
|
|
288
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
289
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
290
|
+
/** Optional title for the authorization screen */
|
|
291
|
+
title: z.ZodOptional<z.ZodString>;
|
|
292
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
293
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
294
|
+
/** Optional short authorization code */
|
|
295
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
296
|
+
/** Optional QR code URL */
|
|
297
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
298
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
299
|
+
/** Optional title for the authorization screen */
|
|
300
|
+
title: z.ZodOptional<z.ZodString>;
|
|
301
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
302
|
+
hint: z.ZodOptional<z.ZodArray<z.ZodEnum<["link", "qr", "code"]>, "many">>;
|
|
303
|
+
/** Optional short authorization code */
|
|
304
|
+
authorizationCode: z.ZodOptional<z.ZodString>;
|
|
305
|
+
/** Optional QR code URL */
|
|
306
|
+
qrUrl: z.ZodOptional<z.ZodString>;
|
|
307
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
308
|
+
/** Optional additional context */
|
|
309
|
+
context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
310
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
311
|
+
/**
|
|
312
|
+
* Check if error is a needs authorization error
|
|
313
|
+
*
|
|
314
|
+
* @param error - The error to check
|
|
315
|
+
* @returns true if it's a needs authorization error
|
|
316
|
+
*/
|
|
317
|
+
export declare function isNeedsAuthorizationError(error: any): error is NeedsAuthorizationError;
|
|
318
|
+
/**
|
|
319
|
+
* Create a needs authorization error
|
|
320
|
+
*
|
|
321
|
+
* @param config - Configuration for the error
|
|
322
|
+
* @returns NeedsAuthorizationError instance
|
|
323
|
+
*/
|
|
324
|
+
export declare function createNeedsAuthorizationError(config: {
|
|
325
|
+
message: string;
|
|
326
|
+
authorizationUrl: string;
|
|
327
|
+
resumeToken: string;
|
|
328
|
+
expiresAt: number;
|
|
329
|
+
scopes: string[];
|
|
330
|
+
display?: AuthorizationDisplay;
|
|
331
|
+
}): NeedsAuthorizationError;
|
|
332
|
+
/**
|
|
333
|
+
* Constants
|
|
334
|
+
*/
|
|
335
|
+
/**
|
|
336
|
+
* Error codes
|
|
337
|
+
*/
|
|
338
|
+
export declare const ERROR_CODES: Readonly<{
|
|
339
|
+
readonly NEEDS_AUTHORIZATION: "needs_authorization";
|
|
340
|
+
readonly INVALID_TOKEN: "invalid_token";
|
|
341
|
+
readonly TOKEN_EXPIRED: "token_expired";
|
|
342
|
+
readonly INSUFFICIENT_SCOPE: "insufficient_scope";
|
|
343
|
+
readonly INVALID_SIGNATURE: "invalid_signature";
|
|
344
|
+
readonly DELEGATION_REVOKED: "delegation_revoked";
|
|
345
|
+
readonly CREDENTIAL_REVOKED: "credential_revoked";
|
|
346
|
+
}>;
|
|
347
|
+
export type ErrorCode = typeof ERROR_CODES[keyof typeof ERROR_CODES];
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime Error Contracts
|
|
4
|
+
*
|
|
5
|
+
* Error types and schemas for runtime errors, especially authorization errors
|
|
6
|
+
*
|
|
7
|
+
* Related Spec: MCP-I §6
|
|
8
|
+
* Python Reference: Core-Documentation.md
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.ERROR_CODES = exports.RuntimeErrorSchema = exports.NeedsAuthorizationErrorSchema = exports.AuthorizationDisplaySchema = exports.DisplayHintSchema = void 0;
|
|
12
|
+
exports.validateNeedsAuthorizationError = validateNeedsAuthorizationError;
|
|
13
|
+
exports.isNeedsAuthorizationError = isNeedsAuthorizationError;
|
|
14
|
+
exports.createNeedsAuthorizationError = createNeedsAuthorizationError;
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
/**
|
|
17
|
+
* Display hint types for authorization UI
|
|
18
|
+
*/
|
|
19
|
+
exports.DisplayHintSchema = zod_1.z.enum(['link', 'qr', 'code']);
|
|
20
|
+
/**
|
|
21
|
+
* Display options for authorization flow
|
|
22
|
+
*/
|
|
23
|
+
exports.AuthorizationDisplaySchema = zod_1.z.object({
|
|
24
|
+
/** Optional title for the authorization screen */
|
|
25
|
+
title: zod_1.z.string().optional(),
|
|
26
|
+
/** Hints for how to display authorization (link, QR code, or code) */
|
|
27
|
+
hint: zod_1.z.array(exports.DisplayHintSchema).optional(),
|
|
28
|
+
/** Optional short authorization code */
|
|
29
|
+
authorizationCode: zod_1.z.string().optional(),
|
|
30
|
+
/** Optional QR code URL */
|
|
31
|
+
qrUrl: zod_1.z.string().url().optional(),
|
|
32
|
+
}).passthrough();
|
|
33
|
+
/**
|
|
34
|
+
* NeedsAuthorizationError Schema
|
|
35
|
+
*
|
|
36
|
+
* Error returned when a request requires authorization.
|
|
37
|
+
* Includes a resumeToken and authorizationUrl for the authorization flow.
|
|
38
|
+
*/
|
|
39
|
+
exports.NeedsAuthorizationErrorSchema = zod_1.z.object({
|
|
40
|
+
/** Error code */
|
|
41
|
+
error: zod_1.z.literal('needs_authorization'),
|
|
42
|
+
/** Human-readable error message */
|
|
43
|
+
message: zod_1.z.string().min(1),
|
|
44
|
+
/** URL for the user to authorize (includes resume token) */
|
|
45
|
+
authorizationUrl: zod_1.z.string().url(),
|
|
46
|
+
/** Short-lived resume token for continuing after authorization */
|
|
47
|
+
resumeToken: zod_1.z.string().min(1),
|
|
48
|
+
/** Expiration timestamp for the resume token (milliseconds since epoch) */
|
|
49
|
+
expiresAt: zod_1.z.number().int().positive(),
|
|
50
|
+
/** Required scopes for authorization */
|
|
51
|
+
scopes: zod_1.z.array(zod_1.z.string()),
|
|
52
|
+
/** Optional display configuration for authorization UI */
|
|
53
|
+
display: exports.AuthorizationDisplaySchema.optional(),
|
|
54
|
+
/** Optional additional context */
|
|
55
|
+
context: zod_1.z.record(zod_1.z.any()).optional(),
|
|
56
|
+
}).passthrough();
|
|
57
|
+
/**
|
|
58
|
+
* Generic Error Schema
|
|
59
|
+
*
|
|
60
|
+
* Standard error format for all runtime errors
|
|
61
|
+
*/
|
|
62
|
+
exports.RuntimeErrorSchema = zod_1.z.object({
|
|
63
|
+
/** Error code */
|
|
64
|
+
error: zod_1.z.string().min(1),
|
|
65
|
+
/** Human-readable error message */
|
|
66
|
+
message: zod_1.z.string().min(1),
|
|
67
|
+
/** Optional error details */
|
|
68
|
+
details: zod_1.z.record(zod_1.z.any()).optional(),
|
|
69
|
+
/** HTTP status code (if applicable) */
|
|
70
|
+
httpStatus: zod_1.z.number().int().min(400).max(599).optional(),
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Validation Helpers
|
|
74
|
+
*/
|
|
75
|
+
/**
|
|
76
|
+
* Validate a needs authorization error
|
|
77
|
+
*
|
|
78
|
+
* @param error - The error to validate
|
|
79
|
+
* @returns Validation result
|
|
80
|
+
*/
|
|
81
|
+
function validateNeedsAuthorizationError(error) {
|
|
82
|
+
return exports.NeedsAuthorizationErrorSchema.safeParse(error);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Check if error is a needs authorization error
|
|
86
|
+
*
|
|
87
|
+
* @param error - The error to check
|
|
88
|
+
* @returns true if it's a needs authorization error
|
|
89
|
+
*/
|
|
90
|
+
function isNeedsAuthorizationError(error) {
|
|
91
|
+
return error && error.error === 'needs_authorization';
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a needs authorization error
|
|
95
|
+
*
|
|
96
|
+
* @param config - Configuration for the error
|
|
97
|
+
* @returns NeedsAuthorizationError instance
|
|
98
|
+
*/
|
|
99
|
+
function createNeedsAuthorizationError(config) {
|
|
100
|
+
return {
|
|
101
|
+
error: 'needs_authorization',
|
|
102
|
+
...config,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Constants
|
|
107
|
+
*/
|
|
108
|
+
/**
|
|
109
|
+
* Error codes
|
|
110
|
+
*/
|
|
111
|
+
exports.ERROR_CODES = Object.freeze({
|
|
112
|
+
NEEDS_AUTHORIZATION: 'needs_authorization',
|
|
113
|
+
INVALID_TOKEN: 'invalid_token',
|
|
114
|
+
TOKEN_EXPIRED: 'token_expired',
|
|
115
|
+
INSUFFICIENT_SCOPE: 'insufficient_scope',
|
|
116
|
+
INVALID_SIGNATURE: 'invalid_signature',
|
|
117
|
+
DELEGATION_REVOKED: 'delegation_revoked',
|
|
118
|
+
CREDENTIAL_REVOKED: 'credential_revoked',
|
|
119
|
+
});
|