atproto-mcp 0.1.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/LICENSE +22 -0
- package/README.md +293 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +261 -0
- package/dist/cli.js.map +1 -0
- package/dist/health-check.d.ts +7 -0
- package/dist/health-check.d.ts.map +1 -0
- package/dist/health-check.js +57 -0
- package/dist/health-check.js.map +1 -0
- package/dist/index.d.ts +122 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +612 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts/index.d.ts +77 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +186 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/resources/index.d.ts +75 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +218 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/test/setup.d.ts +78 -0
- package/dist/test/setup.d.ts.map +1 -0
- package/dist/test/setup.js +138 -0
- package/dist/test/setup.js.map +1 -0
- package/dist/tools/implementations/advanced-social-tools.d.ts +250 -0
- package/dist/tools/implementations/advanced-social-tools.d.ts.map +1 -0
- package/dist/tools/implementations/advanced-social-tools.js +380 -0
- package/dist/tools/implementations/advanced-social-tools.js.map +1 -0
- package/dist/tools/implementations/base-tool.d.ts +73 -0
- package/dist/tools/implementations/base-tool.d.ts.map +1 -0
- package/dist/tools/implementations/base-tool.js +225 -0
- package/dist/tools/implementations/base-tool.js.map +1 -0
- package/dist/tools/implementations/content-management-tools.d.ts +81 -0
- package/dist/tools/implementations/content-management-tools.d.ts.map +1 -0
- package/dist/tools/implementations/content-management-tools.js +236 -0
- package/dist/tools/implementations/content-management-tools.js.map +1 -0
- package/dist/tools/implementations/create-post-tool.d.ts +131 -0
- package/dist/tools/implementations/create-post-tool.d.ts.map +1 -0
- package/dist/tools/implementations/create-post-tool.js +182 -0
- package/dist/tools/implementations/create-post-tool.js.map +1 -0
- package/dist/tools/implementations/follow-user-tool.d.ts +69 -0
- package/dist/tools/implementations/follow-user-tool.d.ts.map +1 -0
- package/dist/tools/implementations/follow-user-tool.js +200 -0
- package/dist/tools/implementations/follow-user-tool.js.map +1 -0
- package/dist/tools/implementations/get-user-profile-tool.d.ts +61 -0
- package/dist/tools/implementations/get-user-profile-tool.d.ts.map +1 -0
- package/dist/tools/implementations/get-user-profile-tool.js +139 -0
- package/dist/tools/implementations/get-user-profile-tool.js.map +1 -0
- package/dist/tools/implementations/index.d.ts +22 -0
- package/dist/tools/implementations/index.d.ts.map +1 -0
- package/dist/tools/implementations/index.js +32 -0
- package/dist/tools/implementations/index.js.map +1 -0
- package/dist/tools/implementations/like-post-tool.d.ts +68 -0
- package/dist/tools/implementations/like-post-tool.d.ts.map +1 -0
- package/dist/tools/implementations/like-post-tool.js +184 -0
- package/dist/tools/implementations/like-post-tool.js.map +1 -0
- package/dist/tools/implementations/media-tools.d.ts +360 -0
- package/dist/tools/implementations/media-tools.d.ts.map +1 -0
- package/dist/tools/implementations/media-tools.js +444 -0
- package/dist/tools/implementations/media-tools.js.map +1 -0
- package/dist/tools/implementations/moderation-tools.d.ts +189 -0
- package/dist/tools/implementations/moderation-tools.d.ts.map +1 -0
- package/dist/tools/implementations/moderation-tools.js +289 -0
- package/dist/tools/implementations/moderation-tools.js.map +1 -0
- package/dist/tools/implementations/oauth-tools.d.ts +108 -0
- package/dist/tools/implementations/oauth-tools.d.ts.map +1 -0
- package/dist/tools/implementations/oauth-tools.js +183 -0
- package/dist/tools/implementations/oauth-tools.js.map +1 -0
- package/dist/tools/implementations/reply-to-post-tool.d.ts +52 -0
- package/dist/tools/implementations/reply-to-post-tool.d.ts.map +1 -0
- package/dist/tools/implementations/reply-to-post-tool.js +167 -0
- package/dist/tools/implementations/reply-to-post-tool.js.map +1 -0
- package/dist/tools/implementations/repost-tool.d.ts +76 -0
- package/dist/tools/implementations/repost-tool.d.ts.map +1 -0
- package/dist/tools/implementations/repost-tool.js +181 -0
- package/dist/tools/implementations/repost-tool.js.map +1 -0
- package/dist/tools/implementations/search-posts-tool.d.ts +95 -0
- package/dist/tools/implementations/search-posts-tool.d.ts.map +1 -0
- package/dist/tools/implementations/search-posts-tool.js +208 -0
- package/dist/tools/implementations/search-posts-tool.js.map +1 -0
- package/dist/tools/implementations/social-graph-tools.d.ts +119 -0
- package/dist/tools/implementations/social-graph-tools.d.ts.map +1 -0
- package/dist/tools/implementations/social-graph-tools.js +262 -0
- package/dist/tools/implementations/social-graph-tools.js.map +1 -0
- package/dist/tools/implementations/streaming-tools.d.ts +130 -0
- package/dist/tools/implementations/streaming-tools.d.ts.map +1 -0
- package/dist/tools/implementations/streaming-tools.js +241 -0
- package/dist/tools/implementations/streaming-tools.js.map +1 -0
- package/dist/tools/implementations/timeline-tools.d.ts +69 -0
- package/dist/tools/implementations/timeline-tools.d.ts.map +1 -0
- package/dist/tools/implementations/timeline-tools.js +194 -0
- package/dist/tools/implementations/timeline-tools.js.map +1 -0
- package/dist/tools/index.d.ts +23 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +73 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types/index.d.ts +242 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +73 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/atp-client.d.ts +109 -0
- package/dist/utils/atp-client.d.ts.map +1 -0
- package/dist/utils/atp-client.js +451 -0
- package/dist/utils/atp-client.js.map +1 -0
- package/dist/utils/config.d.ts +74 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +311 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/firehose-client.d.ts +96 -0
- package/dist/utils/firehose-client.d.ts.map +1 -0
- package/dist/utils/firehose-client.js +252 -0
- package/dist/utils/firehose-client.js.map +1 -0
- package/dist/utils/logger.d.ts +74 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +142 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/oauth-client.d.ts +61 -0
- package/dist/utils/oauth-client.d.ts.map +1 -0
- package/dist/utils/oauth-client.js +224 -0
- package/dist/utils/oauth-client.js.map +1 -0
- package/dist/utils/performance.d.ts +102 -0
- package/dist/utils/performance.d.ts.map +1 -0
- package/dist/utils/performance.js +302 -0
- package/dist/utils/performance.js.map +1 -0
- package/dist/utils/security.d.ts +154 -0
- package/dist/utils/security.d.ts.map +1 -0
- package/dist/utils/security.js +358 -0
- package/dist/utils/security.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance optimization utilities for production deployment
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Simple connection pool for managing AT Protocol connections
|
|
6
|
+
*/
|
|
7
|
+
export class ConnectionPool {
|
|
8
|
+
connections = new Map();
|
|
9
|
+
activeConnections = new Set();
|
|
10
|
+
config;
|
|
11
|
+
logger;
|
|
12
|
+
constructor(config, logger) {
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.logger = logger;
|
|
15
|
+
}
|
|
16
|
+
async acquire(key) {
|
|
17
|
+
if (this.connections.has(key) && !this.activeConnections.has(key)) {
|
|
18
|
+
this.activeConnections.add(key);
|
|
19
|
+
this.logger.debug('Reusing existing connection', { key });
|
|
20
|
+
return this.connections.get(key);
|
|
21
|
+
}
|
|
22
|
+
if (this.activeConnections.size >= this.config.maxConnections) {
|
|
23
|
+
throw new Error('Connection pool exhausted');
|
|
24
|
+
}
|
|
25
|
+
// Create new connection (placeholder - would be actual AT Protocol connection)
|
|
26
|
+
const connection = { id: key, created: Date.now() };
|
|
27
|
+
this.connections.set(key, connection);
|
|
28
|
+
this.activeConnections.add(key);
|
|
29
|
+
this.logger.debug('Created new connection', { key, poolSize: this.connections.size });
|
|
30
|
+
return connection;
|
|
31
|
+
}
|
|
32
|
+
release(key) {
|
|
33
|
+
this.activeConnections.delete(key);
|
|
34
|
+
this.logger.debug('Released connection', { key, activeCount: this.activeConnections.size });
|
|
35
|
+
}
|
|
36
|
+
cleanup() {
|
|
37
|
+
const now = Date.now();
|
|
38
|
+
const toRemove = [];
|
|
39
|
+
for (const [key, connection] of this.connections.entries()) {
|
|
40
|
+
if (!this.activeConnections.has(key) &&
|
|
41
|
+
now - connection.created > this.config.idleTimeoutMs) {
|
|
42
|
+
toRemove.push(key);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
for (const key of toRemove) {
|
|
46
|
+
this.connections.delete(key);
|
|
47
|
+
this.logger.debug('Cleaned up idle connection', { key });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
getMetrics() {
|
|
51
|
+
return {
|
|
52
|
+
totalConnections: this.connections.size,
|
|
53
|
+
activeConnections: this.activeConnections.size,
|
|
54
|
+
idleConnections: this.connections.size - this.activeConnections.size,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* LRU Cache implementation for caching API responses
|
|
60
|
+
*/
|
|
61
|
+
export class LRUCache {
|
|
62
|
+
cache = new Map();
|
|
63
|
+
config;
|
|
64
|
+
logger;
|
|
65
|
+
hits = 0;
|
|
66
|
+
misses = 0;
|
|
67
|
+
constructor(config, logger) {
|
|
68
|
+
this.config = config;
|
|
69
|
+
this.logger = logger;
|
|
70
|
+
// Start cleanup interval
|
|
71
|
+
setInterval(() => this.cleanup(), config.cleanupIntervalMs);
|
|
72
|
+
}
|
|
73
|
+
get(key) {
|
|
74
|
+
const item = this.cache.get(key);
|
|
75
|
+
if (!item) {
|
|
76
|
+
this.misses++;
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
const now = Date.now();
|
|
80
|
+
if (now - item.timestamp > this.config.ttlMs) {
|
|
81
|
+
this.cache.delete(key);
|
|
82
|
+
this.misses++;
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
item.accessCount++;
|
|
86
|
+
this.hits++;
|
|
87
|
+
return item.value;
|
|
88
|
+
}
|
|
89
|
+
set(key, value) {
|
|
90
|
+
const now = Date.now();
|
|
91
|
+
// Remove oldest items if cache is full
|
|
92
|
+
if (this.cache.size >= this.config.maxSize) {
|
|
93
|
+
this.evictLRU();
|
|
94
|
+
}
|
|
95
|
+
this.cache.set(key, {
|
|
96
|
+
value,
|
|
97
|
+
timestamp: now,
|
|
98
|
+
accessCount: 1,
|
|
99
|
+
});
|
|
100
|
+
this.logger.debug('Cached item', { key, cacheSize: this.cache.size });
|
|
101
|
+
}
|
|
102
|
+
delete(key) {
|
|
103
|
+
return this.cache.delete(key);
|
|
104
|
+
}
|
|
105
|
+
clear() {
|
|
106
|
+
this.cache.clear();
|
|
107
|
+
this.hits = 0;
|
|
108
|
+
this.misses = 0;
|
|
109
|
+
this.logger.info('Cache cleared');
|
|
110
|
+
}
|
|
111
|
+
evictLRU() {
|
|
112
|
+
let oldestKey;
|
|
113
|
+
let oldestTime = Date.now();
|
|
114
|
+
for (const [key, item] of this.cache.entries()) {
|
|
115
|
+
if (item.timestamp < oldestTime) {
|
|
116
|
+
oldestTime = item.timestamp;
|
|
117
|
+
oldestKey = key;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (oldestKey) {
|
|
121
|
+
this.cache.delete(oldestKey);
|
|
122
|
+
this.logger.debug('Evicted LRU item', { key: oldestKey });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
cleanup() {
|
|
126
|
+
const now = Date.now();
|
|
127
|
+
const toRemove = [];
|
|
128
|
+
for (const [key, item] of this.cache.entries()) {
|
|
129
|
+
if (now - item.timestamp > this.config.ttlMs) {
|
|
130
|
+
toRemove.push(key);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (const key of toRemove) {
|
|
134
|
+
this.cache.delete(key);
|
|
135
|
+
}
|
|
136
|
+
if (toRemove.length > 0) {
|
|
137
|
+
this.logger.debug('Cleaned up expired cache items', { count: toRemove.length });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
getMetrics() {
|
|
141
|
+
const total = this.hits + this.misses;
|
|
142
|
+
return {
|
|
143
|
+
size: this.cache.size,
|
|
144
|
+
hits: this.hits,
|
|
145
|
+
misses: this.misses,
|
|
146
|
+
hitRate: total > 0 ? this.hits / total : 0,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* WebSocket connection manager for efficient streaming
|
|
152
|
+
*/
|
|
153
|
+
export class WebSocketManager {
|
|
154
|
+
connections = new Map();
|
|
155
|
+
reconnectAttempts = new Map();
|
|
156
|
+
logger;
|
|
157
|
+
maxReconnectAttempts = 5;
|
|
158
|
+
reconnectDelay = 1000;
|
|
159
|
+
constructor(logger) {
|
|
160
|
+
this.logger = logger;
|
|
161
|
+
}
|
|
162
|
+
async connect(url, key) {
|
|
163
|
+
if (this.connections.has(key)) {
|
|
164
|
+
const existing = this.connections.get(key);
|
|
165
|
+
if (existing.readyState === WebSocket.OPEN) {
|
|
166
|
+
return existing;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return new Promise((resolve, reject) => {
|
|
170
|
+
try {
|
|
171
|
+
// Note: In a real implementation, you'd use the 'ws' package
|
|
172
|
+
// For now, this is a placeholder structure
|
|
173
|
+
const ws = {
|
|
174
|
+
readyState: 1, // WebSocket.OPEN
|
|
175
|
+
url,
|
|
176
|
+
onopen: null,
|
|
177
|
+
onclose: null,
|
|
178
|
+
onerror: null,
|
|
179
|
+
onmessage: null,
|
|
180
|
+
send: (data) => {
|
|
181
|
+
this.logger.debug('WebSocket send', { key, dataLength: data.length });
|
|
182
|
+
},
|
|
183
|
+
close: () => {
|
|
184
|
+
this.logger.debug('WebSocket closed', { key });
|
|
185
|
+
this.connections.delete(key);
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
ws.onopen = () => {
|
|
189
|
+
this.connections.set(key, ws);
|
|
190
|
+
this.reconnectAttempts.delete(key);
|
|
191
|
+
this.logger.info('WebSocket connected', { key, url });
|
|
192
|
+
resolve(ws);
|
|
193
|
+
};
|
|
194
|
+
ws.onerror = (error) => {
|
|
195
|
+
this.logger.error('WebSocket error', error, { key, url });
|
|
196
|
+
reject(error);
|
|
197
|
+
};
|
|
198
|
+
ws.onclose = () => {
|
|
199
|
+
this.connections.delete(key);
|
|
200
|
+
void this.handleReconnect(url, key);
|
|
201
|
+
};
|
|
202
|
+
// Simulate connection
|
|
203
|
+
setTimeout(() => {
|
|
204
|
+
if (ws.onopen)
|
|
205
|
+
ws.onopen({});
|
|
206
|
+
}, 100);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
this.logger.error('Failed to create WebSocket', error, { key, url });
|
|
210
|
+
reject(error);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
async handleReconnect(url, key) {
|
|
215
|
+
const attempts = this.reconnectAttempts.get(key) || 0;
|
|
216
|
+
if (attempts >= this.maxReconnectAttempts) {
|
|
217
|
+
this.logger.error('Max reconnect attempts reached', { key, attempts });
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
this.reconnectAttempts.set(key, attempts + 1);
|
|
221
|
+
setTimeout(() => {
|
|
222
|
+
void (async () => {
|
|
223
|
+
try {
|
|
224
|
+
await this.connect(url, key);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
this.logger.error('Reconnect failed', error, { key, attempt: attempts + 1 });
|
|
228
|
+
}
|
|
229
|
+
})();
|
|
230
|
+
}, this.reconnectDelay * Math.pow(2, attempts)); // Exponential backoff
|
|
231
|
+
}
|
|
232
|
+
disconnect(key) {
|
|
233
|
+
const ws = this.connections.get(key);
|
|
234
|
+
if (ws) {
|
|
235
|
+
ws.close();
|
|
236
|
+
this.connections.delete(key);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
disconnectAll() {
|
|
240
|
+
for (const ws of this.connections.values()) {
|
|
241
|
+
ws.close();
|
|
242
|
+
}
|
|
243
|
+
this.connections.clear();
|
|
244
|
+
this.reconnectAttempts.clear();
|
|
245
|
+
}
|
|
246
|
+
getMetrics() {
|
|
247
|
+
return {
|
|
248
|
+
activeConnections: this.connections.size,
|
|
249
|
+
reconnectAttempts: Array.from(this.reconnectAttempts.values()).reduce((a, b) => a + b, 0),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Performance monitor for tracking system metrics
|
|
255
|
+
*/
|
|
256
|
+
export class PerformanceMonitor {
|
|
257
|
+
logger;
|
|
258
|
+
startTime;
|
|
259
|
+
connectionPool;
|
|
260
|
+
cache;
|
|
261
|
+
wsManager;
|
|
262
|
+
constructor(logger) {
|
|
263
|
+
this.logger = logger;
|
|
264
|
+
this.startTime = Date.now();
|
|
265
|
+
}
|
|
266
|
+
setConnectionPool(pool) {
|
|
267
|
+
this.connectionPool = pool;
|
|
268
|
+
}
|
|
269
|
+
setCache(cache) {
|
|
270
|
+
this.cache = cache;
|
|
271
|
+
}
|
|
272
|
+
setWebSocketManager(wsManager) {
|
|
273
|
+
this.wsManager = wsManager;
|
|
274
|
+
}
|
|
275
|
+
getMetrics() {
|
|
276
|
+
const memoryUsage = process.memoryUsage();
|
|
277
|
+
const uptime = Date.now() - this.startTime;
|
|
278
|
+
const poolMetrics = this.connectionPool?.getMetrics() || {
|
|
279
|
+
totalConnections: 0,
|
|
280
|
+
activeConnections: 0,
|
|
281
|
+
};
|
|
282
|
+
const cacheMetrics = this.cache?.getMetrics() || { size: 0, hitRate: 0 };
|
|
283
|
+
return {
|
|
284
|
+
connectionPoolSize: poolMetrics.totalConnections,
|
|
285
|
+
activeConnections: poolMetrics.activeConnections,
|
|
286
|
+
cacheHitRate: cacheMetrics.hitRate,
|
|
287
|
+
cacheSize: cacheMetrics.size,
|
|
288
|
+
memoryUsage,
|
|
289
|
+
uptime,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
logMetrics() {
|
|
293
|
+
const metrics = this.getMetrics();
|
|
294
|
+
this.logger.info('Performance metrics', metrics);
|
|
295
|
+
}
|
|
296
|
+
startPeriodicLogging(intervalMs = 60000) {
|
|
297
|
+
return setInterval(() => {
|
|
298
|
+
this.logMetrics();
|
|
299
|
+
}, intervalMs);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=performance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance.js","sourceRoot":"","sources":["../../src/utils/performance.ts"],"names":[],"mappings":"AAAA;;GAEG;AA2BH;;GAEG;AACH,MAAM,OAAO,cAAc;IACjB,WAAW,GAAqB,IAAI,GAAG,EAAE,CAAC;IAC1C,iBAAiB,GAAgB,IAAI,GAAG,EAAE,CAAC;IAC3C,MAAM,CAAwB;IAC9B,MAAM,CAAS;IAEvB,YAAY,MAA6B,EAAE,MAAc;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW;QACvB,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClE,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;QAED,IAAI,IAAI,CAAC,iBAAiB,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC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EAAE,CAAC;YACnB,iBAAiB,EAAE,CAAC;SACrB,CAAC;QACF,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;QAEzE,OAAO;YACL,kBAAkB,EAAE,WAAW,CAAC,gBAAgB;YAChD,iBAAiB,EAAE,WAAW,CAAC,iBAAiB;YAChD,YAAY,EAAE,YAAY,CAAC,OAAO;YAClC,SAAS,EAAE,YAAY,CAAC,IAAI;YAC5B,WAAW;YACX,MAAM;SACP,CAAC;IACJ,CAAC;IAED,UAAU;QACR,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,oBAAoB,CAAC,aAAqB,KAAK;QAC7C,OAAO,WAAW,CAAC,GAAG,EAAE;YACtB,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC,EAAE,UAAU,CAAC,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security utilities for production deployment
|
|
3
|
+
*/
|
|
4
|
+
import type { Logger } from './logger.js';
|
|
5
|
+
export interface IRateLimitConfig {
|
|
6
|
+
windowMs: number;
|
|
7
|
+
maxRequests: number;
|
|
8
|
+
skipSuccessfulRequests?: boolean;
|
|
9
|
+
skipFailedRequests?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ISecurityConfig {
|
|
12
|
+
enableInputSanitization: boolean;
|
|
13
|
+
enableRateLimit: boolean;
|
|
14
|
+
enableErrorSanitization: boolean;
|
|
15
|
+
maxInputLength: number;
|
|
16
|
+
allowedOrigins: string[];
|
|
17
|
+
trustedProxies: string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Input sanitizer to prevent injection attacks
|
|
21
|
+
*/
|
|
22
|
+
export declare class InputSanitizer {
|
|
23
|
+
private logger;
|
|
24
|
+
private maxLength;
|
|
25
|
+
constructor(maxLength: number, logger: Logger);
|
|
26
|
+
/**
|
|
27
|
+
* Sanitize string input by removing potentially dangerous characters
|
|
28
|
+
*/
|
|
29
|
+
sanitizeString(input: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Sanitize object by recursively sanitizing all string values
|
|
32
|
+
*/
|
|
33
|
+
sanitizeObject(obj: any): any;
|
|
34
|
+
/**
|
|
35
|
+
* Validate AT Protocol identifiers (DIDs, handles, etc.)
|
|
36
|
+
*/
|
|
37
|
+
validateAtProtoIdentifier(identifier: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Validate URI format
|
|
40
|
+
*/
|
|
41
|
+
validateUri(uri: string): boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Rate limiter to prevent abuse
|
|
45
|
+
*/
|
|
46
|
+
export declare class RateLimiter {
|
|
47
|
+
private requests;
|
|
48
|
+
private config;
|
|
49
|
+
private logger;
|
|
50
|
+
constructor(config: IRateLimitConfig, logger: Logger);
|
|
51
|
+
/**
|
|
52
|
+
* Check if request is allowed for the given identifier
|
|
53
|
+
*/
|
|
54
|
+
isAllowed(identifier: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Get remaining requests for identifier
|
|
57
|
+
*/
|
|
58
|
+
getRemaining(identifier: string): number;
|
|
59
|
+
/**
|
|
60
|
+
* Get reset time for identifier
|
|
61
|
+
*/
|
|
62
|
+
getResetTime(identifier: string): number;
|
|
63
|
+
/**
|
|
64
|
+
* Clean up old entries
|
|
65
|
+
*/
|
|
66
|
+
private cleanup;
|
|
67
|
+
/**
|
|
68
|
+
* Get rate limiter metrics
|
|
69
|
+
*/
|
|
70
|
+
getMetrics(): {
|
|
71
|
+
trackedIdentifiers: number;
|
|
72
|
+
totalRequests: number;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Error sanitizer to prevent information leakage
|
|
77
|
+
*/
|
|
78
|
+
export declare class ErrorSanitizer {
|
|
79
|
+
private logger;
|
|
80
|
+
private isDevelopment;
|
|
81
|
+
constructor(logger: Logger, isDevelopment?: boolean);
|
|
82
|
+
/**
|
|
83
|
+
* Sanitize error for client response
|
|
84
|
+
*/
|
|
85
|
+
sanitizeError(error: Error | any): {
|
|
86
|
+
message: string;
|
|
87
|
+
code?: number;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Sanitize stack trace for logging
|
|
91
|
+
*/
|
|
92
|
+
sanitizeStackTrace(error: Error): string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Credential manager for secure storage
|
|
96
|
+
*/
|
|
97
|
+
export declare class CredentialManager {
|
|
98
|
+
private logger;
|
|
99
|
+
private credentials;
|
|
100
|
+
constructor(logger: Logger);
|
|
101
|
+
/**
|
|
102
|
+
* Store credential securely (in production, this would use proper encryption)
|
|
103
|
+
*/
|
|
104
|
+
store(key: string, value: string): void;
|
|
105
|
+
/**
|
|
106
|
+
* Retrieve credential
|
|
107
|
+
*/
|
|
108
|
+
retrieve(key: string): string | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Delete credential
|
|
111
|
+
*/
|
|
112
|
+
delete(key: string): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Clear all credentials
|
|
115
|
+
*/
|
|
116
|
+
clear(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Get credential count (for monitoring)
|
|
119
|
+
*/
|
|
120
|
+
getCount(): number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Security manager that coordinates all security components
|
|
124
|
+
*/
|
|
125
|
+
export declare class SecurityManager {
|
|
126
|
+
private inputSanitizer;
|
|
127
|
+
private rateLimiter;
|
|
128
|
+
private errorSanitizer;
|
|
129
|
+
private credentialManager;
|
|
130
|
+
private config;
|
|
131
|
+
private logger;
|
|
132
|
+
constructor(config: ISecurityConfig, logger: Logger);
|
|
133
|
+
getInputSanitizer(): InputSanitizer;
|
|
134
|
+
getRateLimiter(): RateLimiter;
|
|
135
|
+
getErrorSanitizer(): ErrorSanitizer;
|
|
136
|
+
getCredentialManager(): CredentialManager;
|
|
137
|
+
/**
|
|
138
|
+
* Get security metrics
|
|
139
|
+
*/
|
|
140
|
+
getMetrics(): {
|
|
141
|
+
rateLimiter: {
|
|
142
|
+
trackedIdentifiers: number;
|
|
143
|
+
totalRequests: number;
|
|
144
|
+
};
|
|
145
|
+
credentialCount: number;
|
|
146
|
+
config: {
|
|
147
|
+
inputSanitizationEnabled: boolean;
|
|
148
|
+
rateLimitEnabled: boolean;
|
|
149
|
+
errorSanitizationEnabled: boolean;
|
|
150
|
+
maxInputLength: number;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/utils/security.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,uBAAuB,EAAE,OAAO,CAAC;IACjC,eAAe,EAAE,OAAO,CAAC;IACzB,uBAAuB,EAAE,OAAO,CAAC;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;gBAEd,SAAS,EAAE,MAAM,EAAE,MA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