@frontmcp/plugin-approval 0.0.1 → 0.7.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/approval/errors.d.ts +149 -0
- package/approval/errors.d.ts.map +1 -0
- package/approval/factories.d.ts +251 -0
- package/approval/factories.d.ts.map +1 -0
- package/approval/guards.d.ts +61 -0
- package/approval/guards.d.ts.map +1 -0
- package/approval/index.d.ts +43 -0
- package/approval/index.d.ts.map +1 -0
- package/approval/schemas.d.ts +179 -0
- package/approval/schemas.d.ts.map +1 -0
- package/approval/types.d.ts +252 -0
- package/approval/types.d.ts.map +1 -0
- package/approval.context-extension.d.ts +21 -0
- package/approval.context-extension.d.ts.map +1 -0
- package/approval.plugin.d.ts +128 -0
- package/approval.plugin.d.ts.map +1 -0
- package/approval.symbols.d.ts +22 -0
- package/approval.symbols.d.ts.map +1 -0
- package/esm/index.mjs +1228 -0
- package/esm/package.json +66 -0
- package/flows/index.d.ts +9 -0
- package/flows/index.d.ts.map +1 -0
- package/hooks/approval-check.hook.d.ts +25 -0
- package/hooks/approval-check.hook.d.ts.map +1 -0
- package/hooks/index.d.ts +7 -0
- package/hooks/index.d.ts.map +1 -0
- package/index.d.ts +44 -0
- package/index.d.ts.map +1 -0
- package/index.js +1279 -0
- package/package.json +1 -1
- package/services/approval.service.d.ts +85 -0
- package/services/approval.service.d.ts.map +1 -0
- package/services/challenge.service.d.ts +115 -0
- package/services/challenge.service.d.ts.map +1 -0
- package/services/index.d.ts +8 -0
- package/services/index.d.ts.map +1 -0
- package/stores/approval-storage.store.d.ts +71 -0
- package/stores/approval-storage.store.d.ts.map +1 -0
- package/stores/approval-store.interface.d.ts +121 -0
- package/stores/approval-store.interface.d.ts.map +1 -0
- package/stores/index.d.ts +8 -0
- package/stores/index.d.ts.map +1 -0
- package/types/approval.types.d.ts +98 -0
- package/types/approval.types.d.ts.map +1 -0
- package/types/index.d.ts +7 -0
- package/types/index.d.ts.map +1 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for approval operations.
|
|
3
|
+
*
|
|
4
|
+
* These are standalone error classes that can be extended by plugins
|
|
5
|
+
* for MCP-specific error handling.
|
|
6
|
+
*
|
|
7
|
+
* @module @frontmcp/utils/approval
|
|
8
|
+
*/
|
|
9
|
+
import type { ApprovalScope } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Base class for approval-related errors.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ApprovalError extends Error {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown when tool approval is required but not granted.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ApprovalRequiredError extends ApprovalError {
|
|
20
|
+
readonly details: {
|
|
21
|
+
/** Tool identifier */
|
|
22
|
+
toolId: string;
|
|
23
|
+
/** Current approval state */
|
|
24
|
+
state: 'pending' | 'denied' | 'expired';
|
|
25
|
+
/** User-facing message */
|
|
26
|
+
message: string;
|
|
27
|
+
/** Available approval options (for UI) */
|
|
28
|
+
approvalOptions?: {
|
|
29
|
+
allowedScopes?: ApprovalScope[];
|
|
30
|
+
defaultScope?: ApprovalScope;
|
|
31
|
+
maxTtlMs?: number;
|
|
32
|
+
category?: string;
|
|
33
|
+
riskLevel?: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
constructor(details: {
|
|
37
|
+
/** Tool identifier */
|
|
38
|
+
toolId: string;
|
|
39
|
+
/** Current approval state */
|
|
40
|
+
state: 'pending' | 'denied' | 'expired';
|
|
41
|
+
/** User-facing message */
|
|
42
|
+
message: string;
|
|
43
|
+
/** Available approval options (for UI) */
|
|
44
|
+
approvalOptions?: {
|
|
45
|
+
allowedScopes?: ApprovalScope[];
|
|
46
|
+
defaultScope?: ApprovalScope;
|
|
47
|
+
maxTtlMs?: number;
|
|
48
|
+
category?: string;
|
|
49
|
+
riskLevel?: string;
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Convert to a JSON-RPC compatible error structure.
|
|
54
|
+
*/
|
|
55
|
+
toJsonRpcError(): {
|
|
56
|
+
code: number;
|
|
57
|
+
message: string;
|
|
58
|
+
data: {
|
|
59
|
+
type: string;
|
|
60
|
+
toolId: string;
|
|
61
|
+
state: "pending" | "denied" | "expired";
|
|
62
|
+
options: {
|
|
63
|
+
allowedScopes?: ApprovalScope[];
|
|
64
|
+
defaultScope?: ApprovalScope;
|
|
65
|
+
maxTtlMs?: number;
|
|
66
|
+
category?: string;
|
|
67
|
+
riskLevel?: string;
|
|
68
|
+
} | undefined;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Error thrown when approval operation fails.
|
|
74
|
+
*/
|
|
75
|
+
export declare class ApprovalOperationError extends ApprovalError {
|
|
76
|
+
readonly operation: 'grant' | 'revoke' | 'query';
|
|
77
|
+
readonly reason: string;
|
|
78
|
+
constructor(operation: 'grant' | 'revoke' | 'query', reason: string);
|
|
79
|
+
/**
|
|
80
|
+
* Convert to a JSON-RPC compatible error structure.
|
|
81
|
+
*/
|
|
82
|
+
toJsonRpcError(): {
|
|
83
|
+
code: number;
|
|
84
|
+
message: string;
|
|
85
|
+
data: {
|
|
86
|
+
type: string;
|
|
87
|
+
operation: "grant" | "revoke" | "query";
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Error thrown when approval scope is not allowed.
|
|
93
|
+
*/
|
|
94
|
+
export declare class ApprovalScopeNotAllowedError extends ApprovalError {
|
|
95
|
+
readonly requestedScope: ApprovalScope;
|
|
96
|
+
readonly allowedScopes: ApprovalScope[];
|
|
97
|
+
constructor(requestedScope: ApprovalScope, allowedScopes: ApprovalScope[]);
|
|
98
|
+
/**
|
|
99
|
+
* Convert to a JSON-RPC compatible error structure.
|
|
100
|
+
*/
|
|
101
|
+
toJsonRpcError(): {
|
|
102
|
+
code: number;
|
|
103
|
+
message: string;
|
|
104
|
+
data: {
|
|
105
|
+
type: string;
|
|
106
|
+
requestedScope: ApprovalScope;
|
|
107
|
+
allowedScopes: ApprovalScope[];
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Error thrown when approval has expired.
|
|
113
|
+
*/
|
|
114
|
+
export declare class ApprovalExpiredError extends ApprovalError {
|
|
115
|
+
readonly toolId: string;
|
|
116
|
+
readonly expiredAt: number;
|
|
117
|
+
constructor(toolId: string, expiredAt: number);
|
|
118
|
+
/**
|
|
119
|
+
* Convert to a JSON-RPC compatible error structure.
|
|
120
|
+
*/
|
|
121
|
+
toJsonRpcError(): {
|
|
122
|
+
code: number;
|
|
123
|
+
message: string;
|
|
124
|
+
data: {
|
|
125
|
+
type: string;
|
|
126
|
+
toolId: string;
|
|
127
|
+
expiredAt: number;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Error thrown when PKCE challenge validation fails.
|
|
133
|
+
*/
|
|
134
|
+
export declare class ChallengeValidationError extends ApprovalError {
|
|
135
|
+
readonly reason: 'invalid' | 'expired' | 'not_found' | 'already_used';
|
|
136
|
+
constructor(reason?: 'invalid' | 'expired' | 'not_found' | 'already_used', message?: string);
|
|
137
|
+
/**
|
|
138
|
+
* Convert to a JSON-RPC compatible error structure.
|
|
139
|
+
*/
|
|
140
|
+
toJsonRpcError(): {
|
|
141
|
+
code: number;
|
|
142
|
+
message: string;
|
|
143
|
+
data: {
|
|
144
|
+
type: string;
|
|
145
|
+
reason: "expired" | "invalid" | "not_found" | "already_used";
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/approval/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;G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Q,GAAG,OAAO;aAAkB,MAAM,EAAE,MAAM;gBAAvE,SAAS,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,EAAkB,MAAM,EAAE,MAAM;IAKnG;;OAEG;IACH,cAAc;;;;;;;;CAUf;AAED;;GAEG;AACH,qBAAa,4BAA6B,SAAQ,aAAa;aACjC,cAAc,EAAE,aAAa;aAAkB,aAAa,EAAE,aAAa,EAAE;gBAA7E,cAAc,EAAE,aAAa,EAAkB,aAAa,EAAE,aAAa,EAAE;IAQzG;;OAEG;IACH,cAAc;;;;;;;;;CAWf;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;aACzB,MAAM,EAAE,MAAM;aAAkB,SAAS,EAAE,MAAM;gBAAjD,MAAM,EAAE,MAAM,EAAkB,SAAS,EAAE,MAAM;IAK7E;;OAEG;IACH,cAAc;;;;;;;;;CAWf;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,aAAa;aAEvC,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,cAAc;gBAA5D,MAAM,GAAE,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,cAA0B,EACxF,OAAO,CAAC,EAAE,MAAM;IAMlB;;OAEG;IACH,cAAc;;;;;;;;CAUf"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory functions for creating approval grantors and revokers.
|
|
3
|
+
*
|
|
4
|
+
* These helpers make it easy to create properly-typed grantor/revoker objects
|
|
5
|
+
* for common scenarios.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { userGrantor, testGrantor, policyGrantor } from '@frontmcp/utils';
|
|
10
|
+
*
|
|
11
|
+
* // In tests
|
|
12
|
+
* await store.grantApproval({
|
|
13
|
+
* toolId: 'my-tool',
|
|
14
|
+
* scope: ApprovalScope.SESSION,
|
|
15
|
+
* grantedBy: testGrantor(),
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // In production
|
|
19
|
+
* await store.grantApproval({
|
|
20
|
+
* toolId: 'my-tool',
|
|
21
|
+
* scope: ApprovalScope.SESSION,
|
|
22
|
+
* grantedBy: userGrantor('user-123', 'John Doe'),
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @module @frontmcp/utils/approval
|
|
27
|
+
*/
|
|
28
|
+
import type { ApprovalGrantor, ApprovalRevoker, ApprovalSourceType, RevocationSourceType, DelegationContext, ApprovalMethod } from './types';
|
|
29
|
+
/**
|
|
30
|
+
* Create a user grantor for interactive approvals.
|
|
31
|
+
*
|
|
32
|
+
* @param userId - The user's unique identifier
|
|
33
|
+
* @param displayName - Human-readable name for display
|
|
34
|
+
* @param options - Additional options (method, origin)
|
|
35
|
+
* @returns ApprovalGrantor object
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* grantedBy: userGrantor('user-123', 'John Doe')
|
|
40
|
+
* // => { source: 'user', identifier: 'user-123', displayName: 'John Doe', method: 'interactive' }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function userGrantor(userId: string, displayName?: string, options?: {
|
|
44
|
+
method?: ApprovalMethod;
|
|
45
|
+
origin?: string;
|
|
46
|
+
}): ApprovalGrantor;
|
|
47
|
+
/**
|
|
48
|
+
* Create a policy grantor for auto-approved tools.
|
|
49
|
+
*
|
|
50
|
+
* @param policyId - The policy's unique identifier
|
|
51
|
+
* @param policyName - Human-readable policy name
|
|
52
|
+
* @returns ApprovalGrantor object
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* grantedBy: policyGrantor('safe-list', 'Safe Tools Policy')
|
|
57
|
+
* // => { source: 'policy', identifier: 'safe-list', displayName: 'Safe Tools Policy', method: 'implicit' }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function policyGrantor(policyId: string, policyName?: string): ApprovalGrantor;
|
|
61
|
+
/**
|
|
62
|
+
* Create an admin grantor for administrator overrides.
|
|
63
|
+
*
|
|
64
|
+
* @param adminId - The admin's unique identifier
|
|
65
|
+
* @param displayName - Human-readable name for display
|
|
66
|
+
* @param options - Additional options (method, origin)
|
|
67
|
+
* @returns ApprovalGrantor object
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* grantedBy: adminGrantor('admin-456', 'Super Admin')
|
|
72
|
+
* // => { source: 'admin', identifier: 'admin-456', displayName: 'Super Admin', method: 'interactive' }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function adminGrantor(adminId: string, displayName?: string, options?: {
|
|
76
|
+
method?: ApprovalMethod;
|
|
77
|
+
origin?: string;
|
|
78
|
+
}): ApprovalGrantor;
|
|
79
|
+
/**
|
|
80
|
+
* Create a system grantor for system-level approvals.
|
|
81
|
+
*
|
|
82
|
+
* @param systemId - Optional system identifier (defaults to 'system')
|
|
83
|
+
* @returns ApprovalGrantor object
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* grantedBy: systemGrantor()
|
|
88
|
+
* // => { source: 'system', identifier: 'system', method: 'implicit' }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function systemGrantor(systemId?: string): ApprovalGrantor;
|
|
92
|
+
/**
|
|
93
|
+
* Create an agent grantor for AI agents with delegated authority.
|
|
94
|
+
*
|
|
95
|
+
* @param agentId - The agent's unique identifier
|
|
96
|
+
* @param delegationContext - Who authorized the agent and constraints
|
|
97
|
+
* @param displayName - Human-readable agent name
|
|
98
|
+
* @returns ApprovalGrantor object
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* grantedBy: agentGrantor('claude-code', {
|
|
103
|
+
* delegatorId: 'user-123',
|
|
104
|
+
* delegateId: 'claude-code',
|
|
105
|
+
* purpose: 'code editing',
|
|
106
|
+
* constraints: { paths: ['/home/user/project'] },
|
|
107
|
+
* }, 'Claude Code Assistant')
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function agentGrantor(agentId: string, delegationContext: DelegationContext, displayName?: string): ApprovalGrantor;
|
|
111
|
+
/**
|
|
112
|
+
* Create an API grantor for external API integrations.
|
|
113
|
+
*
|
|
114
|
+
* @param apiKeyPrefix - Prefix of the API key (for audit, not full key)
|
|
115
|
+
* @param serviceName - Name of the external service
|
|
116
|
+
* @returns ApprovalGrantor object
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* grantedBy: apiGrantor('sk_live_...abc', 'GitHub Actions')
|
|
121
|
+
* // => { source: 'api', identifier: 'sk_live_...abc', displayName: 'GitHub Actions', method: 'api' }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function apiGrantor(apiKeyPrefix: string, serviceName?: string): ApprovalGrantor;
|
|
125
|
+
/**
|
|
126
|
+
* Create an OAuth grantor for OAuth token grants.
|
|
127
|
+
*
|
|
128
|
+
* @param tokenId - Token identifier or subject
|
|
129
|
+
* @param provider - OAuth provider name
|
|
130
|
+
* @returns ApprovalGrantor object
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* grantedBy: oauthGrantor('token-xyz', 'Google')
|
|
135
|
+
* // => { source: 'oauth', identifier: 'token-xyz', displayName: 'Google', method: 'api', origin: 'oauth' }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare function oauthGrantor(tokenId: string, provider?: string): ApprovalGrantor;
|
|
139
|
+
/**
|
|
140
|
+
* Create a test grantor for test environments.
|
|
141
|
+
* Use this in tests to avoid TypeScript errors with the old hardcoded types.
|
|
142
|
+
*
|
|
143
|
+
* @returns ApprovalGrantor object
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* // In tests
|
|
148
|
+
* await store.grantApproval({
|
|
149
|
+
* toolId: 'tool-1',
|
|
150
|
+
* scope: ApprovalScope.SESSION,
|
|
151
|
+
* grantedBy: testGrantor(),
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function testGrantor(): ApprovalGrantor;
|
|
156
|
+
/**
|
|
157
|
+
* Create a custom grantor for vendor-specific sources.
|
|
158
|
+
*
|
|
159
|
+
* @param source - Custom source type string
|
|
160
|
+
* @param identifier - Optional identifier
|
|
161
|
+
* @param options - Additional options
|
|
162
|
+
* @returns ApprovalGrantor object
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* // Vendor-specific RBAC
|
|
167
|
+
* grantedBy: customGrantor('frontcloud-rbac', 'role:admin', {
|
|
168
|
+
* displayName: 'Admin Role',
|
|
169
|
+
* method: 'implicit',
|
|
170
|
+
* origin: 'frontcloud-iam',
|
|
171
|
+
* })
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export declare function customGrantor(source: string, identifier?: string, options?: {
|
|
175
|
+
displayName?: string;
|
|
176
|
+
method?: ApprovalMethod;
|
|
177
|
+
origin?: string;
|
|
178
|
+
delegationContext?: DelegationContext;
|
|
179
|
+
}): ApprovalGrantor;
|
|
180
|
+
/**
|
|
181
|
+
* Create a user revoker for interactive revocations.
|
|
182
|
+
*
|
|
183
|
+
* @param userId - The user's unique identifier
|
|
184
|
+
* @param displayName - Human-readable name for display
|
|
185
|
+
* @returns ApprovalRevoker object
|
|
186
|
+
*/
|
|
187
|
+
export declare function userRevoker(userId: string, displayName?: string): ApprovalRevoker;
|
|
188
|
+
/**
|
|
189
|
+
* Create an admin revoker for administrator revocations.
|
|
190
|
+
*
|
|
191
|
+
* @param adminId - The admin's unique identifier
|
|
192
|
+
* @param displayName - Human-readable name for display
|
|
193
|
+
* @returns ApprovalRevoker object
|
|
194
|
+
*/
|
|
195
|
+
export declare function adminRevoker(adminId: string, displayName?: string): ApprovalRevoker;
|
|
196
|
+
/**
|
|
197
|
+
* Create an expiry revoker for TTL-based revocations.
|
|
198
|
+
*
|
|
199
|
+
* @returns ApprovalRevoker object
|
|
200
|
+
*/
|
|
201
|
+
export declare function expiryRevoker(): ApprovalRevoker;
|
|
202
|
+
/**
|
|
203
|
+
* Create a session end revoker for session cleanup.
|
|
204
|
+
*
|
|
205
|
+
* @param sessionId - The session that ended
|
|
206
|
+
* @returns ApprovalRevoker object
|
|
207
|
+
*/
|
|
208
|
+
export declare function sessionEndRevoker(sessionId?: string): ApprovalRevoker;
|
|
209
|
+
/**
|
|
210
|
+
* Create a policy revoker for policy-based revocations.
|
|
211
|
+
*
|
|
212
|
+
* @param policyId - The policy's unique identifier
|
|
213
|
+
* @param policyName - Human-readable policy name
|
|
214
|
+
* @returns ApprovalRevoker object
|
|
215
|
+
*/
|
|
216
|
+
export declare function policyRevoker(policyId: string, policyName?: string): ApprovalRevoker;
|
|
217
|
+
/**
|
|
218
|
+
* Normalize a grantedBy input to the structured ApprovalGrantor format.
|
|
219
|
+
* Accepts either a simple string source type or a full ApprovalGrantor object.
|
|
220
|
+
*
|
|
221
|
+
* @param input - String source type or ApprovalGrantor object
|
|
222
|
+
* @returns Normalized ApprovalGrantor object
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* normalizeGrantor('user')
|
|
227
|
+
* // => { source: 'user' }
|
|
228
|
+
*
|
|
229
|
+
* normalizeGrantor({ source: 'user', identifier: 'user-123' })
|
|
230
|
+
* // => { source: 'user', identifier: 'user-123' }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export declare function normalizeGrantor(input: ApprovalGrantor | ApprovalSourceType | undefined): ApprovalGrantor;
|
|
234
|
+
/**
|
|
235
|
+
* Normalize a revokedBy input to the structured ApprovalRevoker format.
|
|
236
|
+
* Accepts either a simple string source type or a full ApprovalRevoker object.
|
|
237
|
+
*
|
|
238
|
+
* @param input - String source type or ApprovalRevoker object
|
|
239
|
+
* @returns Normalized ApprovalRevoker object
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* normalizeRevoker('expiry')
|
|
244
|
+
* // => { source: 'expiry' }
|
|
245
|
+
*
|
|
246
|
+
* normalizeRevoker({ source: 'admin', identifier: 'admin-456' })
|
|
247
|
+
* // => { source: 'admin', identifier: 'admin-456' }
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
export declare function normalizeRevoker(input: ApprovalRevoker | RevocationSourceType | undefined): ApprovalRevoker;
|
|
251
|
+
//# sourceMappingURL=factories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../../src/approval/factories.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAC;AAMjB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,cAAc,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD,eAAe,CAQjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,eAAe,CAOpF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,cAAc,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD,eAAe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aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,eAAe,CAOpF;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,kBAAkB,GAAG,SAAS,GAAG,eAAe,CAQzG;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,GAAG,oBAAoB,GAAG,SAAS,GAAG,eAAe,CAQ3G"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guards for approval types.
|
|
3
|
+
*
|
|
4
|
+
* @module @frontmcp/utils/approval
|
|
5
|
+
*/
|
|
6
|
+
import type { ApprovalGrantor, ApprovalSourceType } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Check if a grantor is of a specific source type.
|
|
9
|
+
*
|
|
10
|
+
* @param grantor - The grantor to check
|
|
11
|
+
* @param source - The source type to check for
|
|
12
|
+
* @returns true if the grantor matches the source type
|
|
13
|
+
*/
|
|
14
|
+
export declare function isGrantorSource(grantor: ApprovalGrantor, source: ApprovalSourceType): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a grantor was granted by a human (user or admin).
|
|
17
|
+
*
|
|
18
|
+
* @param grantor - The grantor to check
|
|
19
|
+
* @returns true if granted by a human
|
|
20
|
+
*/
|
|
21
|
+
export declare function isHumanGrantor(grantor: ApprovalGrantor): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a grantor was auto-granted (policy, system, test).
|
|
24
|
+
*
|
|
25
|
+
* @param grantor - The grantor to check
|
|
26
|
+
* @returns true if auto-granted
|
|
27
|
+
*/
|
|
28
|
+
export declare function isAutoGrantor(grantor: ApprovalGrantor): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a grantor was delegated (agent with delegation context).
|
|
31
|
+
*
|
|
32
|
+
* @param grantor - The grantor to check
|
|
33
|
+
* @returns true if delegated
|
|
34
|
+
*/
|
|
35
|
+
export declare function isDelegatedGrantor(grantor: ApprovalGrantor): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Check if a grantor is from an API source (api or oauth).
|
|
38
|
+
*
|
|
39
|
+
* @param grantor - The grantor to check
|
|
40
|
+
* @returns true if from API
|
|
41
|
+
*/
|
|
42
|
+
export declare function isApiGrantor(grantor: ApprovalGrantor): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Check if a grantor has an identifier.
|
|
45
|
+
*
|
|
46
|
+
* @param grantor - The grantor to check
|
|
47
|
+
* @returns true if has identifier
|
|
48
|
+
*/
|
|
49
|
+
export declare function hasGrantorIdentifier(grantor: ApprovalGrantor): grantor is ApprovalGrantor & {
|
|
50
|
+
identifier: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Check if a grantor has display name.
|
|
54
|
+
*
|
|
55
|
+
* @param grantor - The grantor to check
|
|
56
|
+
* @returns true if has display name
|
|
57
|
+
*/
|
|
58
|
+
export declare function hasGrantorDisplayName(grantor: ApprovalGrantor): grantor is ApprovalGrantor & {
|
|
59
|
+
displayName: string;
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/approval/guards.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEnE;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAE7F;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEhE;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAE/D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,IAAI,eAAe,GAAG;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,CAElH;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,IAAI,eAAe,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,CAEpH"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Approval utilities for tool authorization flows.
|
|
3
|
+
*
|
|
4
|
+
* Provides types, schemas, factories, guards, and errors for implementing
|
|
5
|
+
* tool approval systems with full audit trail support.
|
|
6
|
+
*
|
|
7
|
+
* @module @frontmcp/plugin-approval
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import {
|
|
12
|
+
* ApprovalScope,
|
|
13
|
+
* ApprovalState,
|
|
14
|
+
* userGrantor,
|
|
15
|
+
* testGrantor,
|
|
16
|
+
* isHumanGrantor,
|
|
17
|
+
* approvalRecordSchema,
|
|
18
|
+
* } from '@frontmcp/plugin-approval';
|
|
19
|
+
*
|
|
20
|
+
* // Create an approval record
|
|
21
|
+
* const record = {
|
|
22
|
+
* toolId: 'file_write',
|
|
23
|
+
* state: ApprovalState.APPROVED,
|
|
24
|
+
* scope: ApprovalScope.SESSION,
|
|
25
|
+
* grantedAt: Date.now(),
|
|
26
|
+
* grantedBy: userGrantor('user-123', 'John Doe'),
|
|
27
|
+
* };
|
|
28
|
+
*
|
|
29
|
+
* // Validate with Zod
|
|
30
|
+
* const validated = approvalRecordSchema.parse(record);
|
|
31
|
+
*
|
|
32
|
+
* // Check grantor type
|
|
33
|
+
* if (isHumanGrantor(record.grantedBy)) {
|
|
34
|
+
* console.log('Approved by human');
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export { ApprovalScope, ApprovalState, type ApprovalContext, type ApprovalSourceType, type ApprovalMethod, type DelegationContext, type ApprovalGrantor, type RevocationSourceType, type RevocationMethod, type ApprovalRevoker, type ApprovalRecord, type ApprovalCategory, type RiskLevel, type ToolApprovalRequirement, } from './types';
|
|
39
|
+
export { approvalScopeSchema, approvalStateSchema, approvalMethodSchema, approvalSourceTypeSchema, revocationMethodSchema, approvalCategorySchema, riskLevelSchema, approvalContextSchema, delegationContextSchema, approvalGrantorSchema, approvalRevokerSchema, approvalRecordSchema, toolApprovalRequirementSchema, type ApprovalContextInput, type DelegationContextInput, type ApprovalGrantorInput, type ApprovalRevokerInput, type ApprovalRecordInput, type ToolApprovalRequirementInput, } from './schemas';
|
|
40
|
+
export { userGrantor, policyGrantor, adminGrantor, systemGrantor, agentGrantor, apiGrantor, oauthGrantor, testGrantor, customGrantor, userRevoker, adminRevoker, expiryRevoker, sessionEndRevoker, policyRevoker, normalizeGrantor, normalizeRevoker, } from './factories';
|
|
41
|
+
export { isGrantorSource, isHumanGrantor, isAutoGrantor, isDelegatedGrantor, isApiGrantor, hasGrantorIdentifier, hasGrantorDisplayName, } from './guards';
|
|
42
|
+
export { ApprovalError, ApprovalRequiredError, ApprovalOperationError, ApprovalScopeNotAllowedError, ApprovalExpiredError, ChallengeValidationError, } from './errors';
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/approval/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAGH,OAAO,EAEL,aAAa,EACb,aAAa,EAEb,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,uBAAuB,GAC7B,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,6BAA6B,EAE7B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,4BAA4B,GAClC,MAAM,WAAW,CAAC;AAGnB,OAAO,EAEL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,WAAW,EACX,aAAa,EAEb,WAAW,EACX,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,aAAa,EAEb,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,sBAAsB,EACtB,4BAA4B,EAC5B,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,UAAU,CAAC"}
|