paygate-mcp 10.22.0 → 10.24.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.
Files changed (37) hide show
  1. package/dist/credit-ledger-reconciler.d.ts +95 -0
  2. package/dist/credit-ledger-reconciler.d.ts.map +1 -0
  3. package/dist/credit-ledger-reconciler.js +169 -0
  4. package/dist/credit-ledger-reconciler.js.map +1 -0
  5. package/dist/credit-pool.d.ts +102 -0
  6. package/dist/credit-pool.d.ts.map +1 -0
  7. package/dist/credit-pool.js +230 -0
  8. package/dist/credit-pool.js.map +1 -0
  9. package/dist/index.d.ts +16 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +19 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/key-audit-log.d.ts +80 -0
  14. package/dist/key-audit-log.d.ts.map +1 -0
  15. package/dist/key-audit-log.js +135 -0
  16. package/dist/key-audit-log.js.map +1 -0
  17. package/dist/key-deprecation.d.ts +94 -0
  18. package/dist/key-deprecation.d.ts.map +1 -0
  19. package/dist/key-deprecation.js +189 -0
  20. package/dist/key-deprecation.js.map +1 -0
  21. package/dist/request-dedup-engine.d.ts +79 -0
  22. package/dist/request-dedup-engine.d.ts.map +1 -0
  23. package/dist/request-dedup-engine.js +194 -0
  24. package/dist/request-dedup-engine.js.map +1 -0
  25. package/dist/request-priority-router.d.ts +94 -0
  26. package/dist/request-priority-router.d.ts.map +1 -0
  27. package/dist/request-priority-router.js +188 -0
  28. package/dist/request-priority-router.js.map +1 -0
  29. package/dist/webhook-payload-transform.d.ts +97 -0
  30. package/dist/webhook-payload-transform.d.ts.map +1 -0
  31. package/dist/webhook-payload-transform.js +192 -0
  32. package/dist/webhook-payload-transform.js.map +1 -0
  33. package/dist/webhook-rate-limiter.d.ts +79 -0
  34. package/dist/webhook-rate-limiter.d.ts.map +1 -0
  35. package/dist/webhook-rate-limiter.js +174 -0
  36. package/dist/webhook-rate-limiter.js.map +1 -0
  37. package/package.json +1 -1
@@ -0,0 +1,95 @@
1
+ /**
2
+ * CreditLedgerReconciler — Reconcile credit ledger entries with expected balances.
3
+ *
4
+ * Track credit operations (grants, debits, adjustments) and
5
+ * detect discrepancies between ledger totals and reported balances.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const reconciler = new CreditLedgerReconciler();
10
+ *
11
+ * reconciler.recordGrant('k1', 1000, 'initial');
12
+ * reconciler.recordDebit('k1', 200, 'tool_call');
13
+ *
14
+ * const result = reconciler.reconcile('k1', 800); // expected balance
15
+ * // { balanced: true, ledgerBalance: 800, reportedBalance: 800 }
16
+ * ```
17
+ */
18
+ export type LedgerEntryType = 'grant' | 'debit' | 'adjustment' | 'refund';
19
+ export interface LedgerEntry {
20
+ id: string;
21
+ key: string;
22
+ type: LedgerEntryType;
23
+ amount: number;
24
+ reason: string;
25
+ timestamp: number;
26
+ balanceAfter: number;
27
+ }
28
+ export interface ReconciliationResult {
29
+ key: string;
30
+ balanced: boolean;
31
+ ledgerBalance: number;
32
+ reportedBalance: number;
33
+ discrepancy: number;
34
+ entryCount: number;
35
+ lastEntry: LedgerEntry | null;
36
+ reconciledAt: number;
37
+ }
38
+ export interface CreditLedgerReconcilerConfig {
39
+ /** Max tracked keys. Default 10000. */
40
+ maxKeys?: number;
41
+ /** Max entries per key. Default 5000. */
42
+ maxEntriesPerKey?: number;
43
+ }
44
+ export interface CreditLedgerReconcilerStats {
45
+ trackedKeys: number;
46
+ totalEntries: number;
47
+ totalGrants: number;
48
+ totalDebits: number;
49
+ totalAdjustments: number;
50
+ totalRefunds: number;
51
+ reconciliationCount: number;
52
+ discrepancyCount: number;
53
+ }
54
+ export declare class CreditLedgerReconciler {
55
+ private ledgers;
56
+ private nextId;
57
+ private maxKeys;
58
+ private maxEntriesPerKey;
59
+ private totalGrants;
60
+ private totalDebits;
61
+ private totalAdjustments;
62
+ private totalRefunds;
63
+ private reconciliationCount;
64
+ private discrepancyCount;
65
+ constructor(config?: CreditLedgerReconcilerConfig);
66
+ /** Record a credit grant. */
67
+ recordGrant(key: string, amount: number, reason: string): LedgerEntry;
68
+ /** Record a credit debit. */
69
+ recordDebit(key: string, amount: number, reason: string): LedgerEntry;
70
+ /** Record a manual adjustment. */
71
+ recordAdjustment(key: string, amount: number, reason: string): LedgerEntry;
72
+ /** Record a refund. */
73
+ recordRefund(key: string, amount: number, reason: string): LedgerEntry;
74
+ /** Reconcile ledger balance with reported balance. */
75
+ reconcile(key: string, reportedBalance: number): ReconciliationResult;
76
+ /** Get ledger balance for a key. */
77
+ getBalance(key: string): number;
78
+ /** Get ledger entries for a key. */
79
+ getEntries(key: string, limit?: number): LedgerEntry[];
80
+ /** Get entries by type for a key. */
81
+ getEntriesByType(key: string, type: LedgerEntryType): LedgerEntry[];
82
+ /** Get all tracked keys with balances. */
83
+ getAllBalances(): {
84
+ key: string;
85
+ balance: number;
86
+ entryCount: number;
87
+ }[];
88
+ /** Remove a key's ledger. */
89
+ removeKey(key: string): boolean;
90
+ getStats(): CreditLedgerReconcilerStats;
91
+ /** Clear all data. */
92
+ destroy(): void;
93
+ private addEntry;
94
+ }
95
+ //# sourceMappingURL=credit-ledger-reconciler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credit-ledger-reconciler.d.ts","sourceRoot":"","sources":["../src/credit-ledger-reconciler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,YAAY,GAAG,QAAQ,CAAC;AAE1E,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CA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,GAAG,WAAW;IAMrE,kCAAkC;IAClC,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW;IAK1E,uBAAuB;IACvB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW;IAQtE,sDAAsD;IACtD,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,oBAAoB;IAuBrE,oCAAoC;IACpC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAI/B,oCAAoC;IACpC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE;IAMtD,qCAAqC;IACrC,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,WAAW,EAAE;IAMnE,0CAA0C;IAC1C,cAAc,IAAI;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE;IAQxE,6BAA6B;IAC7B,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAM/B,QAAQ,IAAI,2BAA2B;IAgBvC,sBAAsB;IACtB,OAAO,IAAI,IAAI;IAYf,OAAO,CAAC,QAAQ;CA2BjB"}
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ /**
3
+ * CreditLedgerReconciler — Reconcile credit ledger entries with expected balances.
4
+ *
5
+ * Track credit operations (grants, debits, adjustments) and
6
+ * detect discrepancies between ledger totals and reported balances.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const reconciler = new CreditLedgerReconciler();
11
+ *
12
+ * reconciler.recordGrant('k1', 1000, 'initial');
13
+ * reconciler.recordDebit('k1', 200, 'tool_call');
14
+ *
15
+ * const result = reconciler.reconcile('k1', 800); // expected balance
16
+ * // { balanced: true, ledgerBalance: 800, reportedBalance: 800 }
17
+ * ```
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.CreditLedgerReconciler = void 0;
21
+ class CreditLedgerReconciler {
22
+ ledgers = new Map();
23
+ nextId = 1;
24
+ maxKeys;
25
+ maxEntriesPerKey;
26
+ // Stats
27
+ totalGrants = 0;
28
+ totalDebits = 0;
29
+ totalAdjustments = 0;
30
+ totalRefunds = 0;
31
+ reconciliationCount = 0;
32
+ discrepancyCount = 0;
33
+ constructor(config = {}) {
34
+ this.maxKeys = config.maxKeys ?? 10_000;
35
+ this.maxEntriesPerKey = config.maxEntriesPerKey ?? 5000;
36
+ }
37
+ // ── Ledger Operations ──────────────────────────────────────────
38
+ /** Record a credit grant. */
39
+ recordGrant(key, amount, reason) {
40
+ if (amount <= 0)
41
+ throw new Error('Grant amount must be positive');
42
+ this.totalGrants++;
43
+ return this.addEntry(key, 'grant', amount, reason);
44
+ }
45
+ /** Record a credit debit. */
46
+ recordDebit(key, amount, reason) {
47
+ if (amount <= 0)
48
+ throw new Error('Debit amount must be positive');
49
+ this.totalDebits++;
50
+ return this.addEntry(key, 'debit', -amount, reason);
51
+ }
52
+ /** Record a manual adjustment. */
53
+ recordAdjustment(key, amount, reason) {
54
+ this.totalAdjustments++;
55
+ return this.addEntry(key, 'adjustment', amount, reason);
56
+ }
57
+ /** Record a refund. */
58
+ recordRefund(key, amount, reason) {
59
+ if (amount <= 0)
60
+ throw new Error('Refund amount must be positive');
61
+ this.totalRefunds++;
62
+ return this.addEntry(key, 'refund', amount, reason);
63
+ }
64
+ // ── Reconciliation ─────────────────────────────────────────────
65
+ /** Reconcile ledger balance with reported balance. */
66
+ reconcile(key, reportedBalance) {
67
+ const ledger = this.ledgers.get(key);
68
+ const ledgerBalance = ledger?.balance ?? 0;
69
+ const discrepancy = Math.abs(ledgerBalance - reportedBalance);
70
+ const balanced = discrepancy === 0;
71
+ this.reconciliationCount++;
72
+ if (!balanced)
73
+ this.discrepancyCount++;
74
+ return {
75
+ key,
76
+ balanced,
77
+ ledgerBalance,
78
+ reportedBalance,
79
+ discrepancy,
80
+ entryCount: ledger?.entries.length ?? 0,
81
+ lastEntry: ledger?.entries[ledger.entries.length - 1] ?? null,
82
+ reconciledAt: Date.now(),
83
+ };
84
+ }
85
+ // ── Query ──────────────────────────────────────────────────────
86
+ /** Get ledger balance for a key. */
87
+ getBalance(key) {
88
+ return this.ledgers.get(key)?.balance ?? 0;
89
+ }
90
+ /** Get ledger entries for a key. */
91
+ getEntries(key, limit) {
92
+ const ledger = this.ledgers.get(key);
93
+ if (!ledger)
94
+ return [];
95
+ return ledger.entries.slice(-(limit ?? 100));
96
+ }
97
+ /** Get entries by type for a key. */
98
+ getEntriesByType(key, type) {
99
+ const ledger = this.ledgers.get(key);
100
+ if (!ledger)
101
+ return [];
102
+ return ledger.entries.filter(e => e.type === type);
103
+ }
104
+ /** Get all tracked keys with balances. */
105
+ getAllBalances() {
106
+ return [...this.ledgers.entries()].map(([key, ledger]) => ({
107
+ key,
108
+ balance: ledger.balance,
109
+ entryCount: ledger.entries.length,
110
+ }));
111
+ }
112
+ /** Remove a key's ledger. */
113
+ removeKey(key) {
114
+ return this.ledgers.delete(key);
115
+ }
116
+ // ── Stats ──────────────────────────────────────────────────────
117
+ getStats() {
118
+ let totalEntries = 0;
119
+ for (const ledger of this.ledgers.values())
120
+ totalEntries += ledger.entries.length;
121
+ return {
122
+ trackedKeys: this.ledgers.size,
123
+ totalEntries,
124
+ totalGrants: this.totalGrants,
125
+ totalDebits: this.totalDebits,
126
+ totalAdjustments: this.totalAdjustments,
127
+ totalRefunds: this.totalRefunds,
128
+ reconciliationCount: this.reconciliationCount,
129
+ discrepancyCount: this.discrepancyCount,
130
+ };
131
+ }
132
+ /** Clear all data. */
133
+ destroy() {
134
+ this.ledgers.clear();
135
+ this.totalGrants = 0;
136
+ this.totalDebits = 0;
137
+ this.totalAdjustments = 0;
138
+ this.totalRefunds = 0;
139
+ this.reconciliationCount = 0;
140
+ this.discrepancyCount = 0;
141
+ }
142
+ // ── Private ────────────────────────────────────────────────────
143
+ addEntry(key, type, amount, reason) {
144
+ let ledger = this.ledgers.get(key);
145
+ if (!ledger) {
146
+ if (this.ledgers.size >= this.maxKeys)
147
+ throw new Error(`Maximum ${this.maxKeys} keys reached`);
148
+ ledger = { entries: [], balance: 0 };
149
+ this.ledgers.set(key, ledger);
150
+ }
151
+ ledger.balance += amount;
152
+ const entry = {
153
+ id: `le_${this.nextId++}`,
154
+ key,
155
+ type,
156
+ amount,
157
+ reason,
158
+ timestamp: Date.now(),
159
+ balanceAfter: ledger.balance,
160
+ };
161
+ ledger.entries.push(entry);
162
+ if (ledger.entries.length > this.maxEntriesPerKey) {
163
+ ledger.entries.splice(0, ledger.entries.length - this.maxEntriesPerKey);
164
+ }
165
+ return entry;
166
+ }
167
+ }
168
+ exports.CreditLedgerReconciler = CreditLedgerReconciler;
169
+ //# sourceMappingURL=credit-ledger-reconciler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credit-ledger-reconciler.js","sourceRoot":"","sources":["../src/credit-ledger-reconciler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAoDH,MAAa,sBAAsB;IACzB,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;IACvC,MAAM,GAAG,CAAC,CAAC;IACX,OAAO,CAAS;IAChB,gBAAgB,CAAS;IAEjC,QAAQ;IACA,WAAW,GAAG,CAAC,CAAC;IAChB,WAAW,GAAG,CAAC,CAAC;IAChB,gBAAgB,GAAG,CAAC,CAAC;IACrB,YAAY,GAAG,CAAC,CAAC;IACjB,mBAAmB,GAAG,CAAC,CAAC;IACxB,gBAAgB,GAAG,CAAC,CAAC;IAE7B,YAAY,SAAuC,EAAE;QACnD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC;QACxC,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAA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f,CAAC;CACF;AArKD,wDAqKC"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * CreditPoolManager — Shared credit pools across multiple API keys.
3
+ *
4
+ * Create named pools with credit budgets and allow multiple keys
5
+ * to draw from the same pool.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const pools = new CreditPoolManager();
10
+ *
11
+ * pools.createPool({ name: 'team-budget', credits: 10000 });
12
+ * pools.addMember('pool_1', 'key_a');
13
+ * pools.addMember('pool_1', 'key_b');
14
+ *
15
+ * pools.consume('pool_1', 'key_a', 500);
16
+ * ```
17
+ */
18
+ export interface CreditPool {
19
+ id: string;
20
+ name: string;
21
+ totalCredits: number;
22
+ usedCredits: number;
23
+ members: string[];
24
+ createdAt: number;
25
+ updatedAt: number;
26
+ }
27
+ export interface CreditPoolCreateParams {
28
+ name: string;
29
+ credits: number;
30
+ }
31
+ export interface PoolConsumption {
32
+ id: string;
33
+ poolId: string;
34
+ key: string;
35
+ amount: number;
36
+ balanceBefore: number;
37
+ balanceAfter: number;
38
+ timestamp: number;
39
+ }
40
+ export interface PoolStatus {
41
+ id: string;
42
+ name: string;
43
+ totalCredits: number;
44
+ usedCredits: number;
45
+ remainingCredits: number;
46
+ percentUsed: number;
47
+ memberCount: number;
48
+ }
49
+ export interface CreditPoolConfig {
50
+ /** Max pools. Default 500. */
51
+ maxPools?: number;
52
+ /** Max members per pool. Default 500. */
53
+ maxMembersPerPool?: number;
54
+ /** Max consumption history. Default 10000. */
55
+ maxHistory?: number;
56
+ }
57
+ export interface CreditPoolStats {
58
+ totalPools: number;
59
+ totalMembers: number;
60
+ totalCreditsAllocated: number;
61
+ totalCreditsUsed: number;
62
+ avgUtilization: number;
63
+ }
64
+ export declare class CreditPoolManager {
65
+ private pools;
66
+ private keyToPools;
67
+ private history;
68
+ private nextPoolId;
69
+ private nextConsumptionId;
70
+ private maxPools;
71
+ private maxMembersPerPool;
72
+ private maxHistory;
73
+ constructor(config?: CreditPoolConfig);
74
+ /** Create a credit pool. */
75
+ createPool(params: CreditPoolCreateParams): CreditPool;
76
+ /** Get a pool by ID. */
77
+ getPool(id: string): CreditPool | null;
78
+ /** Delete a pool. */
79
+ deletePool(id: string): boolean;
80
+ /** Add credits to a pool. */
81
+ addCredits(poolId: string, amount: number): CreditPool | null;
82
+ /** Add a key to a pool. */
83
+ addMember(poolId: string, key: string): boolean;
84
+ /** Remove a key from a pool. */
85
+ removeMember(poolId: string, key: string): boolean;
86
+ /** Get all pools a key belongs to. */
87
+ getKeyPools(key: string): CreditPool[];
88
+ /** Consume credits from a pool. */
89
+ consume(poolId: string, key: string, amount: number): PoolConsumption | null;
90
+ /** Get remaining credits in a pool. */
91
+ getRemaining(poolId: string): number;
92
+ /** Get pool status. */
93
+ getPoolStatus(poolId: string): PoolStatus | null;
94
+ /** Get consumption history for a pool. */
95
+ getHistory(poolId: string, limit?: number): PoolConsumption[];
96
+ /** List all pools. */
97
+ listPools(): CreditPool[];
98
+ getStats(): CreditPoolStats;
99
+ /** Clear all data. */
100
+ destroy(): void;
101
+ }
102
+ //# sourceMappingURL=credit-pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credit-pool.d.ts","sourceRoot":"","sources":["../src/credit-pool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAA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AC,EAAE,EAAE,MAAM,GAAG,OAAO;IAe/B,6BAA6B;IAC7B,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAW7D,2BAA2B;IAC3B,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAqB/C,gCAAgC;IAChC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAmBlD,sCAAsC;IACtC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE;IAQtC,mCAAmC;IACnC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IA+B5E,uCAAuC;IACvC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAQpC,uBAAuB;IACvB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAgBhD,0CAA0C;IAC1C,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,eAAe,EAAE;IAM7D,sBAAsB;IACtB,SAAS,IAAI,UAAU,EAAE;IAMzB,QAAQ,IAAI,eAAe;IAoB3B,sBAAsB;IACtB,OAAO,IAAI,IAAI;CAKhB"}
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ /**
3
+ * CreditPoolManager — Shared credit pools across multiple API keys.
4
+ *
5
+ * Create named pools with credit budgets and allow multiple keys
6
+ * to draw from the same pool.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const pools = new CreditPoolManager();
11
+ *
12
+ * pools.createPool({ name: 'team-budget', credits: 10000 });
13
+ * pools.addMember('pool_1', 'key_a');
14
+ * pools.addMember('pool_1', 'key_b');
15
+ *
16
+ * pools.consume('pool_1', 'key_a', 500);
17
+ * ```
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.CreditPoolManager = void 0;
21
+ // ── Implementation ───────────────────────────────────────────────────
22
+ class CreditPoolManager {
23
+ pools = new Map();
24
+ keyToPools = new Map(); // key -> pool IDs
25
+ history = [];
26
+ nextPoolId = 1;
27
+ nextConsumptionId = 1;
28
+ maxPools;
29
+ maxMembersPerPool;
30
+ maxHistory;
31
+ constructor(config = {}) {
32
+ this.maxPools = config.maxPools ?? 500;
33
+ this.maxMembersPerPool = config.maxMembersPerPool ?? 500;
34
+ this.maxHistory = config.maxHistory ?? 10_000;
35
+ }
36
+ // ── Pool Management ────────────────────────────────────────────
37
+ /** Create a credit pool. */
38
+ createPool(params) {
39
+ if (!params.name)
40
+ throw new Error('Pool name is required');
41
+ if (params.credits <= 0)
42
+ throw new Error('Credits must be positive');
43
+ if (this.pools.size >= this.maxPools)
44
+ throw new Error(`Maximum ${this.maxPools} pools reached`);
45
+ // Check duplicate names
46
+ for (const p of this.pools.values()) {
47
+ if (p.name === params.name)
48
+ throw new Error(`Pool '${params.name}' already exists`);
49
+ }
50
+ const now = Date.now();
51
+ const pool = {
52
+ id: `pool_${this.nextPoolId++}`,
53
+ name: params.name,
54
+ totalCredits: params.credits,
55
+ usedCredits: 0,
56
+ members: [],
57
+ createdAt: now,
58
+ updatedAt: now,
59
+ };
60
+ this.pools.set(pool.id, pool);
61
+ return pool;
62
+ }
63
+ /** Get a pool by ID. */
64
+ getPool(id) {
65
+ return this.pools.get(id) ?? null;
66
+ }
67
+ /** Delete a pool. */
68
+ deletePool(id) {
69
+ const pool = this.pools.get(id);
70
+ if (!pool)
71
+ return false;
72
+ for (const key of pool.members) {
73
+ const pools = this.keyToPools.get(key);
74
+ if (pools) {
75
+ pools.delete(id);
76
+ if (pools.size === 0)
77
+ this.keyToPools.delete(key);
78
+ }
79
+ }
80
+ return this.pools.delete(id);
81
+ }
82
+ /** Add credits to a pool. */
83
+ addCredits(poolId, amount) {
84
+ const pool = this.pools.get(poolId);
85
+ if (!pool)
86
+ return null;
87
+ if (amount <= 0)
88
+ throw new Error('Amount must be positive');
89
+ pool.totalCredits += amount;
90
+ pool.updatedAt = Date.now();
91
+ return pool;
92
+ }
93
+ // ── Membership ─────────────────────────────────────────────────
94
+ /** Add a key to a pool. */
95
+ addMember(poolId, key) {
96
+ const pool = this.pools.get(poolId);
97
+ if (!pool)
98
+ throw new Error(`Pool '${poolId}' not found`);
99
+ if (pool.members.includes(key))
100
+ return false;
101
+ if (pool.members.length >= this.maxMembersPerPool) {
102
+ throw new Error(`Maximum ${this.maxMembersPerPool} members per pool reached`);
103
+ }
104
+ pool.members.push(key);
105
+ pool.updatedAt = Date.now();
106
+ let pools = this.keyToPools.get(key);
107
+ if (!pools) {
108
+ pools = new Set();
109
+ this.keyToPools.set(key, pools);
110
+ }
111
+ pools.add(poolId);
112
+ return true;
113
+ }
114
+ /** Remove a key from a pool. */
115
+ removeMember(poolId, key) {
116
+ const pool = this.pools.get(poolId);
117
+ if (!pool)
118
+ return false;
119
+ const idx = pool.members.indexOf(key);
120
+ if (idx === -1)
121
+ return false;
122
+ pool.members.splice(idx, 1);
123
+ pool.updatedAt = Date.now();
124
+ const pools = this.keyToPools.get(key);
125
+ if (pools) {
126
+ pools.delete(poolId);
127
+ if (pools.size === 0)
128
+ this.keyToPools.delete(key);
129
+ }
130
+ return true;
131
+ }
132
+ /** Get all pools a key belongs to. */
133
+ getKeyPools(key) {
134
+ const poolIds = this.keyToPools.get(key);
135
+ if (!poolIds)
136
+ return [];
137
+ return [...poolIds].map(id => this.pools.get(id)).filter(Boolean);
138
+ }
139
+ // ── Credit Operations ──────────────────────────────────────────
140
+ /** Consume credits from a pool. */
141
+ consume(poolId, key, amount) {
142
+ const pool = this.pools.get(poolId);
143
+ if (!pool)
144
+ return null;
145
+ if (!pool.members.includes(key))
146
+ return null;
147
+ if (amount <= 0)
148
+ throw new Error('Amount must be positive');
149
+ const remaining = pool.totalCredits - pool.usedCredits;
150
+ if (amount > remaining)
151
+ return null; // insufficient
152
+ const balanceBefore = remaining;
153
+ pool.usedCredits += amount;
154
+ pool.updatedAt = Date.now();
155
+ const consumption = {
156
+ id: `pc_${this.nextConsumptionId++}`,
157
+ poolId,
158
+ key,
159
+ amount,
160
+ balanceBefore,
161
+ balanceAfter: pool.totalCredits - pool.usedCredits,
162
+ timestamp: Date.now(),
163
+ };
164
+ this.history.push(consumption);
165
+ if (this.history.length > this.maxHistory) {
166
+ this.history.splice(0, this.history.length - this.maxHistory);
167
+ }
168
+ return consumption;
169
+ }
170
+ /** Get remaining credits in a pool. */
171
+ getRemaining(poolId) {
172
+ const pool = this.pools.get(poolId);
173
+ if (!pool)
174
+ return 0;
175
+ return Math.max(0, pool.totalCredits - pool.usedCredits);
176
+ }
177
+ // ── Query ──────────────────────────────────────────────────────
178
+ /** Get pool status. */
179
+ getPoolStatus(poolId) {
180
+ const pool = this.pools.get(poolId);
181
+ if (!pool)
182
+ return null;
183
+ const remaining = pool.totalCredits - pool.usedCredits;
184
+ return {
185
+ id: pool.id,
186
+ name: pool.name,
187
+ totalCredits: pool.totalCredits,
188
+ usedCredits: pool.usedCredits,
189
+ remainingCredits: Math.max(0, remaining),
190
+ percentUsed: Math.round((pool.usedCredits / pool.totalCredits) * 10000) / 100,
191
+ memberCount: pool.members.length,
192
+ };
193
+ }
194
+ /** Get consumption history for a pool. */
195
+ getHistory(poolId, limit) {
196
+ return this.history
197
+ .filter(h => h.poolId === poolId)
198
+ .slice(-(limit ?? 50));
199
+ }
200
+ /** List all pools. */
201
+ listPools() {
202
+ return [...this.pools.values()];
203
+ }
204
+ // ── Stats ──────────────────────────────────────────────────────
205
+ getStats() {
206
+ let totalMembers = 0;
207
+ let totalAllocated = 0;
208
+ let totalUsed = 0;
209
+ for (const pool of this.pools.values()) {
210
+ totalMembers += pool.members.length;
211
+ totalAllocated += pool.totalCredits;
212
+ totalUsed += pool.usedCredits;
213
+ }
214
+ return {
215
+ totalPools: this.pools.size,
216
+ totalMembers,
217
+ totalCreditsAllocated: totalAllocated,
218
+ totalCreditsUsed: totalUsed,
219
+ avgUtilization: totalAllocated > 0 ? Math.round((totalUsed / totalAllocated) * 10000) / 100 : 0,
220
+ };
221
+ }
222
+ /** Clear all data. */
223
+ destroy() {
224
+ this.pools.clear();
225
+ this.keyToPools.clear();
226
+ this.history = [];
227
+ }
228
+ }
229
+ exports.CreditPoolManager = CreditPoolManager;
230
+ //# sourceMappingURL=credit-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credit-pool.js","sourceRoot":"","sources":["../src/credit-pool.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAwDH,wEAAwE;AAExE,MAAa,iBAAiB;IACpB,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IACtC,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAC,CAAC,kBAAkB;IAC/D,OAAO,GAAsB,EAAE,CAAC;IAChC,UAAU,GAAG,CAAC,CAAC;IACf,iBAAiB,GAAG,CAAC,CAAC;IACtB,QAAQ,CAAS;IACjB,iBAAiB,CAAS;IAC1B,UAAU,CAAS;IAE3B,YAAY,SAA2B,EAAE;QACvC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,GAAG,CAAC;QACvC,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,IAAI,GAAG,CAAC;QACzD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC;IAChD,CAAC;IAED,kEAAkE;IAElE,4BAA4B;IAC5B,UAAU,CAAC,MAA8B;QACvC,IAAI,CAAC,MAAM,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC3D,IAAI,MAAM,CAAC,OAAO,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QACrE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ;YAAE,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,CAAC,MAAM,KAAK,MAAM,CAAC;aAChC,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,sBAAsB;IACtB,SAAS;QACP,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAClC,CAAC;IAED,kEAAkE;IAElE,QAAQ;QACN,IAAI,YAAY,GAAG,CAAC,CAAC;QACrB,IAAI,cAAc,GAAG,CAAC,CAAC;QACvB,IAAI,SAAS,GAAG,CAAC,CAAC;QAElB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;YACvC,YAAY,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;YACpC,cAAc,IAAI,IAAI,CAAC,YAAY,CAAC;YACpC,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC;QAChC,CAAC;QAED,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;YAC3B,YAAY;YACZ,qBAAqB,EAAE,cAAc;YACrC,gBAAgB,EAAE,SAAS;YAC3B,cAAc,EAAE,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,cAAc,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;SAChG,CAAC;IACJ,CAAC;IAED,sBAAsB;IACtB,OAAO;QACL,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;CACF;AAlOD,8CAkOC"}
package/dist/index.d.ts CHANGED
@@ -271,6 +271,22 @@ export { KeyGroupManager as KeyGroupAdmin } from './key-group-manager';
271
271
  export type { KeyGroup, KeyGroupCreateParams, KeyGroupQuery, KeyGroupManagerConfig, KeyGroupManagerStats } from './key-group-manager';
272
272
  export { RequestThrottleQueue } from './request-throttle';
273
273
  export type { ThrottleTicket, ThrottleQueueEntry, ThrottleResult, KeyThrottleStatus, RequestThrottleConfig, RequestThrottleStats } from './request-throttle';
274
+ export { APIKeyAuditLog } from './key-audit-log';
275
+ export type { AuditAction, AuditEntry as KeyAuditEntry, AuditRecordParams as KeyAuditRecordParams, AuditQuery as KeyAuditQuery, APIKeyAuditLogConfig, APIKeyAuditLogStats } from './key-audit-log';
276
+ export { WebhookRateLimiter } from './webhook-rate-limiter';
277
+ export type { WebhookRateLimit, WebhookRateLimitOverride, WebhookRateLimiterConfig, WebhookRateLimiterStats } from './webhook-rate-limiter';
278
+ export { CreditPoolManager } from './credit-pool';
279
+ export type { CreditPool, CreditPoolCreateParams, PoolConsumption, PoolStatus, CreditPoolConfig, CreditPoolStats } from './credit-pool';
280
+ export { RequestPriorityRouter } from './request-priority-router';
281
+ export type { PriorityTier as RoutingPriorityTier, PriorityRequest, PriorityEnqueueParams, TierConfig, TierStatus, RequestPriorityRouterConfig, RequestPriorityRouterStats } from './request-priority-router';
282
+ export { APIKeyDeprecation } from './key-deprecation';
283
+ export type { DeprecationStatus, DeprecationRecord, DeprecateKeyParams, DeprecationKeyStatus, DeprecationQuery, APIKeyDeprecationConfig, APIKeyDeprecationStats } from './key-deprecation';
284
+ export { WebhookPayloadTransform } from './webhook-payload-transform';
285
+ export type { TransformType, TransformRule as PayloadTransformRule, TransformRuleCreateParams as PayloadTransformCreateParams, TransformResult, WebhookPayloadTransformConfig, WebhookPayloadTransformStats } from './webhook-payload-transform';
286
+ export { CreditLedgerReconciler } from './credit-ledger-reconciler';
287
+ export type { LedgerEntryType, LedgerEntry, ReconciliationResult, CreditLedgerReconcilerConfig, CreditLedgerReconcilerStats } from './credit-ledger-reconciler';
288
+ export { RequestDeduplicator as RequestDedupEngine } from './request-dedup-engine';
289
+ export type { DedupRecord, DedupCheckResult, RequestDeduplicatorConfig as DedupEngineConfig, RequestDeduplicatorStats as DedupEngineStats } from './request-dedup-engine';
274
290
  export type { PayGateConfig, JsonRpcRequest, JsonRpcResponse, JsonRpcError, ToolCallParams, ToolInfo, ToolPricing, ServerBackendConfig, ApiKeyRecord, UsageEvent, UsageSummary, GateDecision, QuotaConfig, SpendCapConfig, X402Config, BatchToolCall, BatchGateResult, WebhookFilterRule, KeyListQuery, KeyListResult, } from './types';
275
291
  export { DEFAULT_CONFIG } from './types';
276
292
  //# sourceMappingURL=index.d.ts.map