paygate-mcp 3.3.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Key Groups — Policy templates for API keys.
3
+ *
4
+ * Groups define shared policies (ACL, rate limits, pricing, quotas, IP rules)
5
+ * that are inherited by all member keys. Key-level settings override group defaults.
6
+ *
7
+ * Unlike Teams (which share budgets), Groups share *policies*:
8
+ * - Tool ACL (allowedTools / deniedTools)
9
+ * - Rate limit override (calls per minute)
10
+ * - Per-tool pricing overrides
11
+ * - Quota defaults (daily/monthly limits)
12
+ * - IP allowlist
13
+ * - Metadata tags
14
+ */
15
+ import { QuotaConfig, ToolPricing } from './types';
16
+ export interface KeyGroupRecord {
17
+ /** Unique group ID (grp_ prefix + 16 hex chars) */
18
+ id: string;
19
+ /** Human-readable group name (unique) */
20
+ name: string;
21
+ /** Group description */
22
+ description: string;
23
+ /** Tool whitelist (inherited by member keys if their list is empty). */
24
+ allowedTools: string[];
25
+ /** Tool blacklist (merged with member key's denied tools). */
26
+ deniedTools: string[];
27
+ /** Rate limit override (calls per minute). 0 = use global default. */
28
+ rateLimitPerMin: number;
29
+ /** Per-tool pricing overrides (merged with global, group wins for conflicts). */
30
+ toolPricing: Record<string, ToolPricing>;
31
+ /** Quota defaults for member keys (used when key has no per-key quota). */
32
+ quota?: QuotaConfig;
33
+ /** IP allowlist (merged with key-level allowlist). */
34
+ ipAllowlist: string[];
35
+ /** Default credits for new keys assigned to this group. 0 = use /keys default. */
36
+ defaultCredits: number;
37
+ /** Max spending limit for member keys. 0 = unlimited. */
38
+ maxSpendingLimit: number;
39
+ /** Arbitrary metadata tags. */
40
+ tags: Record<string, string>;
41
+ /** ISO timestamp when group was created. */
42
+ createdAt: string;
43
+ /** Whether group is active. */
44
+ active: boolean;
45
+ }
46
+ /** Resolved policy: the merged result of group + key settings. */
47
+ export interface ResolvedPolicy {
48
+ allowedTools: string[];
49
+ deniedTools: string[];
50
+ rateLimitPerMin: number;
51
+ quota?: QuotaConfig;
52
+ ipAllowlist: string[];
53
+ toolPricing: Record<string, ToolPricing>;
54
+ maxSpendingLimit: number;
55
+ }
56
+ export interface KeyGroupInfo {
57
+ id: string;
58
+ name: string;
59
+ description: string;
60
+ memberCount: number;
61
+ allowedTools: string[];
62
+ deniedTools: string[];
63
+ rateLimitPerMin: number;
64
+ quota?: QuotaConfig;
65
+ ipAllowlist: string[];
66
+ defaultCredits: number;
67
+ maxSpendingLimit: number;
68
+ tags: Record<string, string>;
69
+ createdAt: string;
70
+ active: boolean;
71
+ }
72
+ export declare class KeyGroupManager {
73
+ private groups;
74
+ /** Reverse index: apiKey → groupId */
75
+ private keyToGroup;
76
+ createGroup(params: {
77
+ name: string;
78
+ description?: string;
79
+ allowedTools?: string[];
80
+ deniedTools?: string[];
81
+ rateLimitPerMin?: number;
82
+ toolPricing?: Record<string, ToolPricing>;
83
+ quota?: QuotaConfig;
84
+ ipAllowlist?: string[];
85
+ defaultCredits?: number;
86
+ maxSpendingLimit?: number;
87
+ tags?: Record<string, string>;
88
+ }): KeyGroupRecord;
89
+ getGroup(id: string): KeyGroupRecord | undefined;
90
+ getGroupByName(name: string): KeyGroupRecord | undefined;
91
+ updateGroup(id: string, updates: {
92
+ name?: string;
93
+ description?: string;
94
+ allowedTools?: string[];
95
+ deniedTools?: string[];
96
+ rateLimitPerMin?: number;
97
+ toolPricing?: Record<string, ToolPricing>;
98
+ quota?: QuotaConfig | null;
99
+ ipAllowlist?: string[];
100
+ defaultCredits?: number;
101
+ maxSpendingLimit?: number;
102
+ tags?: Record<string, string>;
103
+ }): KeyGroupRecord;
104
+ deleteGroup(id: string): boolean;
105
+ listGroups(): KeyGroupInfo[];
106
+ assignKey(apiKey: string, groupId: string): void;
107
+ removeKey(apiKey: string): boolean;
108
+ getKeyGroup(apiKey: string): KeyGroupRecord | undefined;
109
+ getKeyGroupId(apiKey: string): string | undefined;
110
+ getGroupMembers(groupId: string): string[];
111
+ /**
112
+ * Resolve the effective policy for a key, merging group defaults with key overrides.
113
+ *
114
+ * Resolution rules:
115
+ * - allowedTools: key-level wins if non-empty, else group default
116
+ * - deniedTools: union of group + key (both applied)
117
+ * - rateLimitPerMin: key-level wins if set, else group default
118
+ * - quota: key-level wins if set, else group default
119
+ * - ipAllowlist: union of group + key (both applied)
120
+ * - toolPricing: group pricing is base, key-level (if any) would need external handling
121
+ * - maxSpendingLimit: group's maxSpendingLimit is a cap on the key's spending limit
122
+ */
123
+ resolvePolicy(apiKey: string, keyRecord: {
124
+ allowedTools: string[];
125
+ deniedTools: string[];
126
+ ipAllowlist: string[];
127
+ quota?: QuotaConfig;
128
+ spendingLimit: number;
129
+ }): ResolvedPolicy | null;
130
+ serialize(): {
131
+ groups: [string, KeyGroupRecord][];
132
+ assignments: [string, string][];
133
+ };
134
+ load(data: {
135
+ groups: [string, KeyGroupRecord][];
136
+ assignments: [string, string][];
137
+ }): void;
138
+ get count(): number;
139
+ }
140
+ //# sourceMappingURL=groups.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groups.d.ts","sourceRoot":"","sources":["../src/groups.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAInD,MAAM,WAAW,cAAc;IAC7B,mDAAmD;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,8DAA8D;IAC9D,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,sEAAsE;IACtE,eAAe,EAAE,MAAM,CAAC;IACxB,iFAAiF;IACjF,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACzC,2EAA2E;IAC3E,KAAK,CAAC,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;IA+BlB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAchC,UAAU,IAAI,YAAY,EAAE;IA2B5B,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAMhD,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIlC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAWvD,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAWjD,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAU1C;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE;QACvC,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,KAAK,CAAC,EAAE,WAAW,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;KACvB,GAAG,cAAc,GAAG,IAAI;IA0CzB,SAAS,IAAI;QAAE,MAAM,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC;QAAC,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;KAAE;IAOpF,IAAI,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC;QAAC,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;KAAE,GAAG,IAAI;IAiBzF,IAAI,KAAK,IAAI,MAAM,CAMlB;CACF"}
package/dist/groups.js ADDED
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ /**
3
+ * Key Groups — Policy templates for API keys.
4
+ *
5
+ * Groups define shared policies (ACL, rate limits, pricing, quotas, IP rules)
6
+ * that are inherited by all member keys. Key-level settings override group defaults.
7
+ *
8
+ * Unlike Teams (which share budgets), Groups share *policies*:
9
+ * - Tool ACL (allowedTools / deniedTools)
10
+ * - Rate limit override (calls per minute)
11
+ * - Per-tool pricing overrides
12
+ * - Quota defaults (daily/monthly limits)
13
+ * - IP allowlist
14
+ * - Metadata tags
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.KeyGroupManager = void 0;
18
+ const crypto_1 = require("crypto");
19
+ // ─── KeyGroupManager ─────────────────────────────────────────────────────────
20
+ class KeyGroupManager {
21
+ groups = new Map();
22
+ /** Reverse index: apiKey → groupId */
23
+ keyToGroup = new Map();
24
+ // ─── CRUD ────────────────────────────────────────────────────────────────
25
+ createGroup(params) {
26
+ const name = String(params.name || '').trim();
27
+ if (!name)
28
+ throw new Error('Group must have a name');
29
+ // Enforce unique names
30
+ for (const g of this.groups.values()) {
31
+ if (g.active && g.name === name) {
32
+ throw new Error(`Group '${name}' already exists`);
33
+ }
34
+ }
35
+ const id = 'grp_' + (0, crypto_1.randomBytes)(8).toString('hex');
36
+ const record = {
37
+ id,
38
+ name,
39
+ description: String(params.description || ''),
40
+ allowedTools: params.allowedTools || [],
41
+ deniedTools: params.deniedTools || [],
42
+ rateLimitPerMin: Math.max(0, Math.floor(Number(params.rateLimitPerMin) || 0)),
43
+ toolPricing: params.toolPricing || {},
44
+ quota: params.quota,
45
+ ipAllowlist: params.ipAllowlist || [],
46
+ defaultCredits: Math.max(0, Math.floor(Number(params.defaultCredits) || 0)),
47
+ maxSpendingLimit: Math.max(0, Math.floor(Number(params.maxSpendingLimit) || 0)),
48
+ tags: params.tags || {},
49
+ createdAt: new Date().toISOString(),
50
+ active: true,
51
+ };
52
+ this.groups.set(id, record);
53
+ return record;
54
+ }
55
+ getGroup(id) {
56
+ return this.groups.get(id);
57
+ }
58
+ getGroupByName(name) {
59
+ for (const g of this.groups.values()) {
60
+ if (g.active && g.name === name)
61
+ return g;
62
+ }
63
+ return undefined;
64
+ }
65
+ updateGroup(id, updates) {
66
+ const group = this.groups.get(id);
67
+ if (!group || !group.active)
68
+ throw new Error(`Group '${id}' not found`);
69
+ // Check name uniqueness if name is being changed
70
+ if (updates.name !== undefined && updates.name !== group.name) {
71
+ const name = String(updates.name).trim();
72
+ if (!name)
73
+ throw new Error('Group must have a name');
74
+ for (const g of this.groups.values()) {
75
+ if (g.active && g.id !== id && g.name === name) {
76
+ throw new Error(`Group '${name}' already exists`);
77
+ }
78
+ }
79
+ group.name = name;
80
+ }
81
+ if (updates.description !== undefined)
82
+ group.description = String(updates.description);
83
+ if (updates.allowedTools !== undefined)
84
+ group.allowedTools = updates.allowedTools;
85
+ if (updates.deniedTools !== undefined)
86
+ group.deniedTools = updates.deniedTools;
87
+ if (updates.rateLimitPerMin !== undefined)
88
+ group.rateLimitPerMin = Math.max(0, Math.floor(Number(updates.rateLimitPerMin) || 0));
89
+ if (updates.toolPricing !== undefined)
90
+ group.toolPricing = updates.toolPricing;
91
+ if (updates.quota === null)
92
+ delete group.quota;
93
+ else if (updates.quota !== undefined)
94
+ group.quota = updates.quota;
95
+ if (updates.ipAllowlist !== undefined)
96
+ group.ipAllowlist = updates.ipAllowlist;
97
+ if (updates.defaultCredits !== undefined)
98
+ group.defaultCredits = Math.max(0, Math.floor(Number(updates.defaultCredits) || 0));
99
+ if (updates.maxSpendingLimit !== undefined)
100
+ group.maxSpendingLimit = Math.max(0, Math.floor(Number(updates.maxSpendingLimit) || 0));
101
+ if (updates.tags !== undefined)
102
+ group.tags = { ...group.tags, ...updates.tags };
103
+ return group;
104
+ }
105
+ deleteGroup(id) {
106
+ const group = this.groups.get(id);
107
+ if (!group || !group.active)
108
+ return false;
109
+ group.active = false;
110
+ // Remove all key assignments for this group
111
+ for (const [key, gid] of this.keyToGroup.entries()) {
112
+ if (gid === id)
113
+ this.keyToGroup.delete(key);
114
+ }
115
+ return true;
116
+ }
117
+ listGroups() {
118
+ const result = [];
119
+ for (const g of this.groups.values()) {
120
+ if (!g.active)
121
+ continue;
122
+ const memberCount = this.getGroupMembers(g.id).length;
123
+ result.push({
124
+ id: g.id,
125
+ name: g.name,
126
+ description: g.description,
127
+ memberCount,
128
+ allowedTools: g.allowedTools,
129
+ deniedTools: g.deniedTools,
130
+ rateLimitPerMin: g.rateLimitPerMin,
131
+ quota: g.quota,
132
+ ipAllowlist: g.ipAllowlist,
133
+ defaultCredits: g.defaultCredits,
134
+ maxSpendingLimit: g.maxSpendingLimit,
135
+ tags: g.tags,
136
+ createdAt: g.createdAt,
137
+ active: g.active,
138
+ });
139
+ }
140
+ return result;
141
+ }
142
+ // ─── Key Membership ──────────────────────────────────────────────────────
143
+ assignKey(apiKey, groupId) {
144
+ const group = this.groups.get(groupId);
145
+ if (!group || !group.active)
146
+ throw new Error(`Group '${groupId}' not found`);
147
+ this.keyToGroup.set(apiKey, groupId);
148
+ }
149
+ removeKey(apiKey) {
150
+ return this.keyToGroup.delete(apiKey);
151
+ }
152
+ getKeyGroup(apiKey) {
153
+ const groupId = this.keyToGroup.get(apiKey);
154
+ if (!groupId)
155
+ return undefined;
156
+ const group = this.groups.get(groupId);
157
+ if (!group || !group.active) {
158
+ this.keyToGroup.delete(apiKey);
159
+ return undefined;
160
+ }
161
+ return group;
162
+ }
163
+ getKeyGroupId(apiKey) {
164
+ const groupId = this.keyToGroup.get(apiKey);
165
+ if (!groupId)
166
+ return undefined;
167
+ const group = this.groups.get(groupId);
168
+ if (!group || !group.active) {
169
+ this.keyToGroup.delete(apiKey);
170
+ return undefined;
171
+ }
172
+ return groupId;
173
+ }
174
+ getGroupMembers(groupId) {
175
+ const members = [];
176
+ for (const [key, gid] of this.keyToGroup.entries()) {
177
+ if (gid === groupId)
178
+ members.push(key);
179
+ }
180
+ return members;
181
+ }
182
+ // ─── Policy Resolution ───────────────────────────────────────────────────
183
+ /**
184
+ * Resolve the effective policy for a key, merging group defaults with key overrides.
185
+ *
186
+ * Resolution rules:
187
+ * - allowedTools: key-level wins if non-empty, else group default
188
+ * - deniedTools: union of group + key (both applied)
189
+ * - rateLimitPerMin: key-level wins if set, else group default
190
+ * - quota: key-level wins if set, else group default
191
+ * - ipAllowlist: union of group + key (both applied)
192
+ * - toolPricing: group pricing is base, key-level (if any) would need external handling
193
+ * - maxSpendingLimit: group's maxSpendingLimit is a cap on the key's spending limit
194
+ */
195
+ resolvePolicy(apiKey, keyRecord) {
196
+ const group = this.getKeyGroup(apiKey);
197
+ if (!group)
198
+ return null;
199
+ // Allowed tools: key wins if non-empty, else group
200
+ const allowedTools = keyRecord.allowedTools.length > 0
201
+ ? keyRecord.allowedTools
202
+ : group.allowedTools;
203
+ // Denied tools: union (both applied)
204
+ const deniedSet = new Set([...group.deniedTools, ...keyRecord.deniedTools]);
205
+ const deniedTools = Array.from(deniedSet);
206
+ // Rate limit: group default (0 = use global)
207
+ const rateLimitPerMin = group.rateLimitPerMin;
208
+ // Quota: key wins if set, else group
209
+ const quota = keyRecord.quota || group.quota;
210
+ // IP allowlist: union
211
+ const ipSet = new Set([...group.ipAllowlist, ...keyRecord.ipAllowlist]);
212
+ const ipAllowlist = Array.from(ipSet);
213
+ // Tool pricing: group overrides
214
+ const toolPricing = group.toolPricing;
215
+ // Spending limit: cap to group's max if group has one set and key's limit is higher (or unlimited)
216
+ let maxSpendingLimit = group.maxSpendingLimit;
217
+ return {
218
+ allowedTools,
219
+ deniedTools,
220
+ rateLimitPerMin,
221
+ quota,
222
+ ipAllowlist,
223
+ toolPricing,
224
+ maxSpendingLimit,
225
+ };
226
+ }
227
+ // ─── Serialization (for state file persistence) ──────────────────────────
228
+ serialize() {
229
+ return {
230
+ groups: Array.from(this.groups.entries()),
231
+ assignments: Array.from(this.keyToGroup.entries()),
232
+ };
233
+ }
234
+ load(data) {
235
+ this.groups.clear();
236
+ this.keyToGroup.clear();
237
+ if (data.groups) {
238
+ for (const [id, record] of data.groups) {
239
+ this.groups.set(id, record);
240
+ }
241
+ }
242
+ if (data.assignments) {
243
+ for (const [key, groupId] of data.assignments) {
244
+ this.keyToGroup.set(key, groupId);
245
+ }
246
+ }
247
+ }
248
+ get count() {
249
+ let count = 0;
250
+ for (const g of this.groups.values()) {
251
+ if (g.active)
252
+ count++;
253
+ }
254
+ return count;
255
+ }
256
+ }
257
+ exports.KeyGroupManager = KeyGroupManager;
258
+ //# sourceMappingURL=groups.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groups.js","sourceRoot":"","sources":["../src/groups.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAEH,mCAAqC;AAgErC,gFAAgF;AAEhF,MAAa,eAAe;IAClB,MAAM,GAAG,IAAI,GAAG,EAA0B,CAAC;IACnD,sCAAsC;IAC9B,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE/C,4EAA4E;IAE5E,WAAW,CAAC,MAYX;QACC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9C,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAErD,uBAAuB;QACvB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;YACrC,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CAAC,UAAU,IAAI,kBAAkB,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,MAAM,EAAE,GAAG,MAAM,GAAG,IAAA,oBAAW,EAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnD,MAAM,MAAM,GAAmB;YAC7B,EAAE;YACF,IAAI;YACJ,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC;YAC7C,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,EAAE;YACvC,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;YACrC,eAAe,EAAE,IAAI,CAAC,GAAG,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export type { TokenPayload, TokenValidation, TokenCreateOptions, RevokedTokenEntry } from './tokens';
56
56
  export { AdminKeyManager, ROLE_HIERARCHY, VALID_ROLES } from './admin-keys';
57
57
  export type { AdminRole, AdminKeyRecord } from './admin-keys';
58
+ export { PluginManager } from './plugin';
59
+ export type { PayGatePlugin, PluginGateContext, PluginToolContext, PluginGateOverride, PluginInfo } from './plugin';
60
+ export { KeyGroupManager } from './groups';
61
+ export type { KeyGroupRecord, KeyGroupInfo, ResolvedPolicy } from './groups';
58
62
  export type { PayGateConfig, JsonRpcRequest, JsonRpcResponse, JsonRpcError, ToolCallParams, ToolInfo, ToolPricing, ServerBackendConfig, ApiKeyRecord, UsageEvent, UsageSummary, GateDecision, QuotaConfig, BatchToolCall, BatchGateResult, } from './types';
59
63
  export { DEFAULT_CONFIG } from './types';
60
64
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAClF,OAAO,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,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACpH,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE7E,YAAY,EACV,aAAa,EACb,cAAc,EACd,eAAe,EACf,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,eAAe,GAChB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@
16
16
  * ```
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.DEFAULT_CONFIG = exports.VALID_ROLES = exports.ROLE_HIERARCHY = exports.AdminKeyManager = exports.TokenRevocationList = exports.ScopedTokenManager = exports.formatDiagnostics = exports.validateConfig = exports.PayGateError = exports.PayGateClient = exports.RedisSync = exports.RedisSubscriber = exports.parseRedisUrl = exports.RedisClient = exports.TeamManager = exports.AlertEngine = exports.AnalyticsEngine = exports.getDashboardHtml = exports.MetricsCollector = exports.ToolRegistry = exports.maskKeyForAudit = exports.AuditLogger = exports.writeSseKeepAlive = exports.writeSseEvent = exports.writeSseHeaders = exports.SessionManager = exports.OAuthProvider = exports.QuotaTracker = exports.WebhookEmitter = exports.StripeWebhookHandler = exports.RateLimiter = exports.UsageMeter = exports.KeyStore = exports.MultiServerRouter = exports.HttpMcpProxy = exports.McpProxy = exports.Gate = exports.PayGateServer = void 0;
19
+ exports.DEFAULT_CONFIG = exports.KeyGroupManager = exports.PluginManager = exports.VALID_ROLES = exports.ROLE_HIERARCHY = exports.AdminKeyManager = exports.TokenRevocationList = exports.ScopedTokenManager = exports.formatDiagnostics = exports.validateConfig = exports.PayGateError = exports.PayGateClient = exports.RedisSync = exports.RedisSubscriber = exports.parseRedisUrl = exports.RedisClient = exports.TeamManager = exports.AlertEngine = exports.AnalyticsEngine = exports.getDashboardHtml = exports.MetricsCollector = exports.ToolRegistry = exports.maskKeyForAudit = exports.AuditLogger = exports.writeSseKeepAlive = exports.writeSseEvent = exports.writeSseHeaders = exports.SessionManager = exports.OAuthProvider = exports.QuotaTracker = exports.WebhookEmitter = exports.StripeWebhookHandler = exports.RateLimiter = exports.UsageMeter = exports.KeyStore = exports.MultiServerRouter = exports.HttpMcpProxy = exports.McpProxy = exports.Gate = exports.PayGateServer = void 0;
20
20
  var server_1 = require("./server");
21
21
  Object.defineProperty(exports, "PayGateServer", { enumerable: true, get: function () { return server_1.PayGateServer; } });
22
22
  var gate_1 = require("./gate");
@@ -80,6 +80,10 @@ var admin_keys_1 = require("./admin-keys");
80
80
  Object.defineProperty(exports, "AdminKeyManager", { enumerable: true, get: function () { return admin_keys_1.AdminKeyManager; } });
81
81
  Object.defineProperty(exports, "ROLE_HIERARCHY", { enumerable: true, get: function () { return admin_keys_1.ROLE_HIERARCHY; } });
82
82
  Object.defineProperty(exports, "VALID_ROLES", { enumerable: true, get: function () { return admin_keys_1.VALID_ROLES; } });
83
+ var plugin_1 = require("./plugin");
84
+ Object.defineProperty(exports, "PluginManager", { enumerable: true, get: function () { return plugin_1.PluginManager; } });
85
+ var groups_1 = require("./groups");
86
+ Object.defineProperty(exports, "KeyGroupManager", { enumerable: true, get: function () { return groups_1.KeyGroupManager; } });
83
87
  var types_1 = require("./types");
84
88
  Object.defineProperty(exports, "DEFAULT_CONFIG", { enumerable: true, get: function () { return types_1.DEFAULT_CONFIG; } });
85
89
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,mCAAyC;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A;AAAE,6GAAA,aAAa,OAAA;AAAE,+GAAA,eAAe,OAAA;AAEpD,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAElB,mCAAuD;AAA9C,uGAAA,aAAa,OAAA;AAAE,sGAAA,YAAY,OAAA;AAEpC,uDAAuE;AAA9D,kHAAA,cAAc,OAAA;AAAE,qHAAA,iBAAiB,OAAA;AAE1C,mCAAmE;AAA1D,4GAAA,kBAAkB,OAAA;AAAE,6GAAA,mBAAmB,OAAA;AAEhD,2CAA4E;AAAnE,6GAAA,eAAe,OAAA;AAAE,4GAAA,cAAc,OAAA;AAAE,yGAAA,WAAW,OAAA;AAErD,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AAEtB,mCAA2C;AAAlC,yGAAA,eAAe,OAAA;AAqBxB,iCAAyC;AAAhC,uGAAA,cAAc,OAAA"}
@@ -0,0 +1,172 @@
1
+ /**
2
+ * Plugin System — Extensible middleware hooks for custom billing, auth,
3
+ * pricing, logging, and request handling logic.
4
+ *
5
+ * Plugins register named hook functions that run at key points in the
6
+ * request lifecycle:
7
+ *
8
+ * Gate hooks (synchronous — hot path):
9
+ * - beforeGate: Short-circuit gate evaluation (deny/allow early)
10
+ * - afterGate: Modify gate decision after evaluation
11
+ * - onDeny: Notification when a tool call is denied
12
+ * - transformPrice: Override tool pricing dynamically
13
+ *
14
+ * Tool hooks (async — wraps proxy forward):
15
+ * - beforeToolCall: Modify request before forwarding to MCP server
16
+ * - afterToolCall: Modify response after receiving from MCP server
17
+ *
18
+ * HTTP hooks (async):
19
+ * - onRequest: Handle custom HTTP endpoints before normal routing
20
+ *
21
+ * Lifecycle hooks (async):
22
+ * - onStart: Called when the server starts
23
+ * - onStop: Called when the server stops
24
+ *
25
+ * Plugins run in registration order. Gate hooks are sync to avoid adding
26
+ * latency to the critical billing path. Tool/HTTP/lifecycle hooks may be async.
27
+ */
28
+ import { GateDecision, JsonRpcRequest, JsonRpcResponse, ApiKeyRecord } from './types';
29
+ import { IncomingMessage, ServerResponse } from 'http';
30
+ /** Context passed to gate-level hooks. */
31
+ export interface PluginGateContext {
32
+ /** The API key (null if missing) */
33
+ apiKey: string | null;
34
+ /** Tool being called */
35
+ toolName: string;
36
+ /** Tool call arguments */
37
+ toolArgs?: Record<string, unknown>;
38
+ /** Client IP address */
39
+ clientIp?: string;
40
+ /** Resolved API key record (null if key is invalid) */
41
+ keyRecord?: ApiKeyRecord;
42
+ }
43
+ /** Context passed to tool-level hooks. */
44
+ export interface PluginToolContext {
45
+ /** The API key */
46
+ apiKey: string | null;
47
+ /** Tool being called */
48
+ toolName: string;
49
+ /** Tool call arguments */
50
+ toolArgs?: Record<string, unknown>;
51
+ /** The JSON-RPC request being forwarded */
52
+ request: JsonRpcRequest;
53
+ }
54
+ /** Result from a beforeGate hook that short-circuits the gate. */
55
+ export interface PluginGateOverride {
56
+ /** Whether to allow or deny the tool call */
57
+ allowed: boolean;
58
+ /** Reason for the decision */
59
+ reason?: string;
60
+ /** Credits to charge (only when allowed=true). Default: 0 */
61
+ creditsCharged?: number;
62
+ }
63
+ /** Plugin info returned by list(). */
64
+ export interface PluginInfo {
65
+ name: string;
66
+ version?: string;
67
+ hooks: string[];
68
+ }
69
+ export interface PayGatePlugin {
70
+ /** Unique plugin name (required). */
71
+ name: string;
72
+ /** Plugin version (for discovery). */
73
+ version?: string;
74
+ /** Called when the server starts. */
75
+ onStart?: () => void | Promise<void>;
76
+ /** Called when the server stops. */
77
+ onStop?: () => void | Promise<void>;
78
+ /**
79
+ * Called before gate evaluation.
80
+ * Return a PluginGateOverride to short-circuit (allow or deny without
81
+ * normal checks). Return null to continue with normal evaluation.
82
+ */
83
+ beforeGate?: (context: PluginGateContext) => PluginGateOverride | null;
84
+ /**
85
+ * Called after gate evaluation.
86
+ * Receives the context and the gate's decision. Return the (possibly
87
+ * modified) decision. Plugins run in order and each sees the previous
88
+ * plugin's output.
89
+ */
90
+ afterGate?: (context: PluginGateContext, decision: GateDecision) => GateDecision;
91
+ /**
92
+ * Called when a tool call is denied (fire-and-forget).
93
+ * Useful for logging, monitoring, or alerting.
94
+ */
95
+ onDeny?: (context: PluginGateContext, reason: string) => void;
96
+ /**
97
+ * Override tool pricing dynamically.
98
+ * Return the new price in credits, or null to use the default price.
99
+ * First plugin to return non-null wins.
100
+ */
101
+ transformPrice?: (toolName: string, basePrice: number, args?: Record<string, unknown>) => number | null;
102
+ /**
103
+ * Called before a tool call is forwarded to the MCP server.
104
+ * Can modify the request. Return the (possibly modified) request.
105
+ */
106
+ beforeToolCall?: (context: PluginToolContext) => Promise<JsonRpcRequest> | JsonRpcRequest;
107
+ /**
108
+ * Called after a tool call response is received from the MCP server.
109
+ * Can modify the response. Return the (possibly modified) response.
110
+ */
111
+ afterToolCall?: (context: PluginToolContext, response: JsonRpcResponse) => Promise<JsonRpcResponse> | JsonRpcResponse;
112
+ /**
113
+ * Called for each HTTP request before normal routing.
114
+ * Return true if the request was handled (response already sent).
115
+ * Return false to continue with normal routing.
116
+ * Use this to add custom endpoints to the server.
117
+ */
118
+ onRequest?: (req: IncomingMessage, res: ServerResponse) => boolean | Promise<boolean>;
119
+ }
120
+ export declare class PluginManager {
121
+ private plugins;
122
+ /** Register a plugin. Plugins run in registration order. */
123
+ register(plugin: PayGatePlugin): void;
124
+ /** Unregister a plugin by name. Returns true if found and removed. */
125
+ unregister(name: string): boolean;
126
+ /** List all registered plugins with their hooks. */
127
+ list(): PluginInfo[];
128
+ /** Number of registered plugins. */
129
+ get count(): number;
130
+ /**
131
+ * Execute beforeGate hooks in order.
132
+ * First non-null result short-circuits the gate.
133
+ */
134
+ executeBeforeGate(context: PluginGateContext): PluginGateOverride | null;
135
+ /**
136
+ * Execute afterGate hooks in order.
137
+ * Each plugin can modify the decision; changes cascade through.
138
+ */
139
+ executeAfterGate(context: PluginGateContext, decision: GateDecision): GateDecision;
140
+ /**
141
+ * Execute onDeny hooks (fire-and-forget).
142
+ */
143
+ executeOnDeny(context: PluginGateContext, reason: string): void;
144
+ /**
145
+ * Execute transformPrice hooks. First non-null result wins.
146
+ */
147
+ executeTransformPrice(toolName: string, basePrice: number, args?: Record<string, unknown>): number;
148
+ /**
149
+ * Execute beforeToolCall hooks in order.
150
+ * Each can modify the request; changes cascade.
151
+ */
152
+ executeBeforeToolCall(context: PluginToolContext): Promise<JsonRpcRequest>;
153
+ /**
154
+ * Execute afterToolCall hooks in order.
155
+ * Each can modify the response; changes cascade.
156
+ */
157
+ executeAfterToolCall(context: PluginToolContext, response: JsonRpcResponse): Promise<JsonRpcResponse>;
158
+ /**
159
+ * Execute onRequest hooks. First handler returning true wins.
160
+ */
161
+ executeOnRequest(req: IncomingMessage, res: ServerResponse): Promise<boolean>;
162
+ /**
163
+ * Execute onStart hooks for all plugins.
164
+ */
165
+ executeStart(): Promise<void>;
166
+ /**
167
+ * Execute onStop hooks for all plugins (in reverse order for clean teardown).
168
+ */
169
+ executeStop(): Promise<void>;
170
+ private getPluginHooks;
171
+ }
172
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAIvD,0CAA0C;AAC1C,MAAM,WAAW,iBAAiB;IAChC,oCAAoC;IACpC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,wBAAwB;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,wBAAwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B;AAED,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