gateops-core 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/dist/bin/gateops-init.js +570 -0
- package/dist/bin/gateops-init.js.map +1 -0
- package/dist/index.d.mts +725 -0
- package/dist/index.d.ts +725 -0
- package/dist/index.js +1227 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1176 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
import { BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
3
|
+
import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
|
|
4
|
+
import * as express_serve_static_core from 'express-serve-static-core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Traffic log entry stored in database and sent to Panel
|
|
8
|
+
*/
|
|
9
|
+
interface TrafficLog {
|
|
10
|
+
id?: number;
|
|
11
|
+
trace_id: string;
|
|
12
|
+
endpoint: string;
|
|
13
|
+
method: string;
|
|
14
|
+
status: number;
|
|
15
|
+
duration_ms: number;
|
|
16
|
+
req_headers?: string;
|
|
17
|
+
req_body?: string;
|
|
18
|
+
res_headers?: string;
|
|
19
|
+
res_body?: string;
|
|
20
|
+
query_params?: string;
|
|
21
|
+
ip_address?: string;
|
|
22
|
+
user_agent?: string;
|
|
23
|
+
created_at: Date;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Discovered endpoint/route information
|
|
27
|
+
*/
|
|
28
|
+
interface EndpointInfo {
|
|
29
|
+
id?: number;
|
|
30
|
+
path: string;
|
|
31
|
+
method: string;
|
|
32
|
+
detected_schema?: string;
|
|
33
|
+
middleware_names?: string;
|
|
34
|
+
last_seen: Date;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* GateOps SDK initialization options
|
|
38
|
+
*/
|
|
39
|
+
interface GateOpsOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Enable/disable the SDK (default: true)
|
|
42
|
+
* Can also be set via GATEOPS_ENABLED env var
|
|
43
|
+
*/
|
|
44
|
+
enabled?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Custom database path (default: .gateops/data.sqlite)
|
|
47
|
+
* Can also be set via GATEOPS_DB_PATH env var
|
|
48
|
+
*/
|
|
49
|
+
dbPath?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Buffer size before auto-flush (default: 50)
|
|
52
|
+
*/
|
|
53
|
+
bufferSize?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Buffer flush interval in ms (default: 10000)
|
|
56
|
+
*/
|
|
57
|
+
flushInterval?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Max body size to capture in bytes (default: 10KB)
|
|
60
|
+
*/
|
|
61
|
+
maxBodySize?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Additional fields to redact (merged with defaults)
|
|
64
|
+
*/
|
|
65
|
+
sensitiveFields?: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Paths to exclude from logging (e.g., ['/health', '/metrics'])
|
|
68
|
+
*/
|
|
69
|
+
excludePaths?: string[];
|
|
70
|
+
/**
|
|
71
|
+
* Enable exposed routes for Panel queries (default: true)
|
|
72
|
+
*/
|
|
73
|
+
exposeRoutes?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Disable sending logs to Panel (local-only mode)
|
|
76
|
+
*/
|
|
77
|
+
localOnly?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Custom Panel URL (default: https://gateops.sleeksoulsmedia.com)
|
|
80
|
+
*/
|
|
81
|
+
panelUrl?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Route layer from Express router stack
|
|
85
|
+
*/
|
|
86
|
+
interface RouteLayer {
|
|
87
|
+
name: string;
|
|
88
|
+
handle: Function;
|
|
89
|
+
regexp: RegExp;
|
|
90
|
+
route?: {
|
|
91
|
+
path: string;
|
|
92
|
+
methods: Record<string, boolean>;
|
|
93
|
+
stack: RouteLayer[];
|
|
94
|
+
};
|
|
95
|
+
keys?: {
|
|
96
|
+
name: string;
|
|
97
|
+
}[];
|
|
98
|
+
path?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Express app with internal router access
|
|
102
|
+
*/
|
|
103
|
+
interface ExpressApp {
|
|
104
|
+
_router?: {
|
|
105
|
+
stack: RouteLayer[];
|
|
106
|
+
};
|
|
107
|
+
use: Function;
|
|
108
|
+
listen: Function;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Panel API response for verification
|
|
112
|
+
*/
|
|
113
|
+
interface VerifyResponse {
|
|
114
|
+
success: boolean;
|
|
115
|
+
message?: string;
|
|
116
|
+
projectId?: string;
|
|
117
|
+
projectName?: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Panel API response for log submission
|
|
121
|
+
*/
|
|
122
|
+
interface LogSubmitResponse {
|
|
123
|
+
success: boolean;
|
|
124
|
+
received: number;
|
|
125
|
+
message?: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Sanitize data by redacting sensitive fields
|
|
130
|
+
*
|
|
131
|
+
* - Recursively traverses objects and arrays
|
|
132
|
+
* - Redacts fields matching sensitive patterns
|
|
133
|
+
* - Masks credit card numbers and SSNs
|
|
134
|
+
* - Truncates large payloads
|
|
135
|
+
*/
|
|
136
|
+
declare function sanitize(data: unknown, maxSize?: number, customFields?: string[]): unknown;
|
|
137
|
+
/**
|
|
138
|
+
* Safely stringify an object, handling circular references
|
|
139
|
+
*/
|
|
140
|
+
declare function safeStringify(obj: unknown, maxSize?: number): string | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Extract safe headers (remove sensitive ones)
|
|
143
|
+
*/
|
|
144
|
+
declare function sanitizeHeaders(headers: Record<string, string | string[] | undefined>): Record<string, string | string[] | undefined>;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Traffic logs table - stores all captured API requests/responses
|
|
148
|
+
*
|
|
149
|
+
* TTL: 15 days (cleanup handled by SDK)
|
|
150
|
+
*/
|
|
151
|
+
declare const trafficLogs: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
152
|
+
name: "gateops_traffic_logs";
|
|
153
|
+
schema: undefined;
|
|
154
|
+
columns: {
|
|
155
|
+
id: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
156
|
+
name: "id";
|
|
157
|
+
tableName: "gateops_traffic_logs";
|
|
158
|
+
dataType: "number";
|
|
159
|
+
columnType: "SQLiteInteger";
|
|
160
|
+
data: number;
|
|
161
|
+
driverParam: number;
|
|
162
|
+
notNull: true;
|
|
163
|
+
hasDefault: true;
|
|
164
|
+
enumValues: undefined;
|
|
165
|
+
baseColumn: never;
|
|
166
|
+
}, object>;
|
|
167
|
+
trace_id: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
168
|
+
name: "trace_id";
|
|
169
|
+
tableName: "gateops_traffic_logs";
|
|
170
|
+
dataType: "string";
|
|
171
|
+
columnType: "SQLiteText";
|
|
172
|
+
data: string;
|
|
173
|
+
driverParam: string;
|
|
174
|
+
notNull: true;
|
|
175
|
+
hasDefault: false;
|
|
176
|
+
enumValues: [string, ...string[]];
|
|
177
|
+
baseColumn: never;
|
|
178
|
+
}, object>;
|
|
179
|
+
endpoint: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
180
|
+
name: "endpoint";
|
|
181
|
+
tableName: "gateops_traffic_logs";
|
|
182
|
+
dataType: "string";
|
|
183
|
+
columnType: "SQLiteText";
|
|
184
|
+
data: string;
|
|
185
|
+
driverParam: string;
|
|
186
|
+
notNull: true;
|
|
187
|
+
hasDefault: false;
|
|
188
|
+
enumValues: [string, ...string[]];
|
|
189
|
+
baseColumn: never;
|
|
190
|
+
}, object>;
|
|
191
|
+
method: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
192
|
+
name: "method";
|
|
193
|
+
tableName: "gateops_traffic_logs";
|
|
194
|
+
dataType: "string";
|
|
195
|
+
columnType: "SQLiteText";
|
|
196
|
+
data: string;
|
|
197
|
+
driverParam: string;
|
|
198
|
+
notNull: true;
|
|
199
|
+
hasDefault: false;
|
|
200
|
+
enumValues: [string, ...string[]];
|
|
201
|
+
baseColumn: never;
|
|
202
|
+
}, object>;
|
|
203
|
+
status: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
204
|
+
name: "status";
|
|
205
|
+
tableName: "gateops_traffic_logs";
|
|
206
|
+
dataType: "number";
|
|
207
|
+
columnType: "SQLiteInteger";
|
|
208
|
+
data: number;
|
|
209
|
+
driverParam: number;
|
|
210
|
+
notNull: true;
|
|
211
|
+
hasDefault: false;
|
|
212
|
+
enumValues: undefined;
|
|
213
|
+
baseColumn: never;
|
|
214
|
+
}, object>;
|
|
215
|
+
duration_ms: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
216
|
+
name: "duration_ms";
|
|
217
|
+
tableName: "gateops_traffic_logs";
|
|
218
|
+
dataType: "number";
|
|
219
|
+
columnType: "SQLiteInteger";
|
|
220
|
+
data: number;
|
|
221
|
+
driverParam: number;
|
|
222
|
+
notNull: true;
|
|
223
|
+
hasDefault: false;
|
|
224
|
+
enumValues: undefined;
|
|
225
|
+
baseColumn: never;
|
|
226
|
+
}, object>;
|
|
227
|
+
req_headers: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
228
|
+
name: "req_headers";
|
|
229
|
+
tableName: "gateops_traffic_logs";
|
|
230
|
+
dataType: "string";
|
|
231
|
+
columnType: "SQLiteText";
|
|
232
|
+
data: string;
|
|
233
|
+
driverParam: string;
|
|
234
|
+
notNull: false;
|
|
235
|
+
hasDefault: false;
|
|
236
|
+
enumValues: [string, ...string[]];
|
|
237
|
+
baseColumn: never;
|
|
238
|
+
}, object>;
|
|
239
|
+
res_headers: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
240
|
+
name: "res_headers";
|
|
241
|
+
tableName: "gateops_traffic_logs";
|
|
242
|
+
dataType: "string";
|
|
243
|
+
columnType: "SQLiteText";
|
|
244
|
+
data: string;
|
|
245
|
+
driverParam: string;
|
|
246
|
+
notNull: false;
|
|
247
|
+
hasDefault: false;
|
|
248
|
+
enumValues: [string, ...string[]];
|
|
249
|
+
baseColumn: never;
|
|
250
|
+
}, object>;
|
|
251
|
+
req_body: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
252
|
+
name: "req_body";
|
|
253
|
+
tableName: "gateops_traffic_logs";
|
|
254
|
+
dataType: "string";
|
|
255
|
+
columnType: "SQLiteText";
|
|
256
|
+
data: string;
|
|
257
|
+
driverParam: string;
|
|
258
|
+
notNull: false;
|
|
259
|
+
hasDefault: false;
|
|
260
|
+
enumValues: [string, ...string[]];
|
|
261
|
+
baseColumn: never;
|
|
262
|
+
}, object>;
|
|
263
|
+
res_body: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
264
|
+
name: "res_body";
|
|
265
|
+
tableName: "gateops_traffic_logs";
|
|
266
|
+
dataType: "string";
|
|
267
|
+
columnType: "SQLiteText";
|
|
268
|
+
data: string;
|
|
269
|
+
driverParam: string;
|
|
270
|
+
notNull: false;
|
|
271
|
+
hasDefault: false;
|
|
272
|
+
enumValues: [string, ...string[]];
|
|
273
|
+
baseColumn: never;
|
|
274
|
+
}, object>;
|
|
275
|
+
query_params: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
276
|
+
name: "query_params";
|
|
277
|
+
tableName: "gateops_traffic_logs";
|
|
278
|
+
dataType: "string";
|
|
279
|
+
columnType: "SQLiteText";
|
|
280
|
+
data: string;
|
|
281
|
+
driverParam: string;
|
|
282
|
+
notNull: false;
|
|
283
|
+
hasDefault: false;
|
|
284
|
+
enumValues: [string, ...string[]];
|
|
285
|
+
baseColumn: never;
|
|
286
|
+
}, object>;
|
|
287
|
+
ip_address: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
288
|
+
name: "ip_address";
|
|
289
|
+
tableName: "gateops_traffic_logs";
|
|
290
|
+
dataType: "string";
|
|
291
|
+
columnType: "SQLiteText";
|
|
292
|
+
data: string;
|
|
293
|
+
driverParam: string;
|
|
294
|
+
notNull: false;
|
|
295
|
+
hasDefault: false;
|
|
296
|
+
enumValues: [string, ...string[]];
|
|
297
|
+
baseColumn: never;
|
|
298
|
+
}, object>;
|
|
299
|
+
user_agent: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
300
|
+
name: "user_agent";
|
|
301
|
+
tableName: "gateops_traffic_logs";
|
|
302
|
+
dataType: "string";
|
|
303
|
+
columnType: "SQLiteText";
|
|
304
|
+
data: string;
|
|
305
|
+
driverParam: string;
|
|
306
|
+
notNull: false;
|
|
307
|
+
hasDefault: false;
|
|
308
|
+
enumValues: [string, ...string[]];
|
|
309
|
+
baseColumn: never;
|
|
310
|
+
}, object>;
|
|
311
|
+
created_at: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
312
|
+
name: "created_at";
|
|
313
|
+
tableName: "gateops_traffic_logs";
|
|
314
|
+
dataType: "date";
|
|
315
|
+
columnType: "SQLiteTimestamp";
|
|
316
|
+
data: Date;
|
|
317
|
+
driverParam: number;
|
|
318
|
+
notNull: true;
|
|
319
|
+
hasDefault: false;
|
|
320
|
+
enumValues: undefined;
|
|
321
|
+
baseColumn: never;
|
|
322
|
+
}, object>;
|
|
323
|
+
};
|
|
324
|
+
dialect: "sqlite";
|
|
325
|
+
}>;
|
|
326
|
+
/**
|
|
327
|
+
* Endpoints table - stores discovered routes for documentation
|
|
328
|
+
*
|
|
329
|
+
* Updated on each app startup + when new routes are hit
|
|
330
|
+
*/
|
|
331
|
+
declare const endpoints: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
332
|
+
name: "gateops_endpoints";
|
|
333
|
+
schema: undefined;
|
|
334
|
+
columns: {
|
|
335
|
+
id: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
336
|
+
name: "id";
|
|
337
|
+
tableName: "gateops_endpoints";
|
|
338
|
+
dataType: "number";
|
|
339
|
+
columnType: "SQLiteInteger";
|
|
340
|
+
data: number;
|
|
341
|
+
driverParam: number;
|
|
342
|
+
notNull: true;
|
|
343
|
+
hasDefault: true;
|
|
344
|
+
enumValues: undefined;
|
|
345
|
+
baseColumn: never;
|
|
346
|
+
}, object>;
|
|
347
|
+
path: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
348
|
+
name: "path";
|
|
349
|
+
tableName: "gateops_endpoints";
|
|
350
|
+
dataType: "string";
|
|
351
|
+
columnType: "SQLiteText";
|
|
352
|
+
data: string;
|
|
353
|
+
driverParam: string;
|
|
354
|
+
notNull: true;
|
|
355
|
+
hasDefault: false;
|
|
356
|
+
enumValues: [string, ...string[]];
|
|
357
|
+
baseColumn: never;
|
|
358
|
+
}, object>;
|
|
359
|
+
method: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
360
|
+
name: "method";
|
|
361
|
+
tableName: "gateops_endpoints";
|
|
362
|
+
dataType: "string";
|
|
363
|
+
columnType: "SQLiteText";
|
|
364
|
+
data: string;
|
|
365
|
+
driverParam: string;
|
|
366
|
+
notNull: true;
|
|
367
|
+
hasDefault: false;
|
|
368
|
+
enumValues: [string, ...string[]];
|
|
369
|
+
baseColumn: never;
|
|
370
|
+
}, object>;
|
|
371
|
+
detected_schema: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
372
|
+
name: "detected_schema";
|
|
373
|
+
tableName: "gateops_endpoints";
|
|
374
|
+
dataType: "string";
|
|
375
|
+
columnType: "SQLiteText";
|
|
376
|
+
data: string;
|
|
377
|
+
driverParam: string;
|
|
378
|
+
notNull: false;
|
|
379
|
+
hasDefault: false;
|
|
380
|
+
enumValues: [string, ...string[]];
|
|
381
|
+
baseColumn: never;
|
|
382
|
+
}, object>;
|
|
383
|
+
middleware_names: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
384
|
+
name: "middleware_names";
|
|
385
|
+
tableName: "gateops_endpoints";
|
|
386
|
+
dataType: "string";
|
|
387
|
+
columnType: "SQLiteText";
|
|
388
|
+
data: string;
|
|
389
|
+
driverParam: string;
|
|
390
|
+
notNull: false;
|
|
391
|
+
hasDefault: false;
|
|
392
|
+
enumValues: [string, ...string[]];
|
|
393
|
+
baseColumn: never;
|
|
394
|
+
}, object>;
|
|
395
|
+
last_seen: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
396
|
+
name: "last_seen";
|
|
397
|
+
tableName: "gateops_endpoints";
|
|
398
|
+
dataType: "date";
|
|
399
|
+
columnType: "SQLiteTimestamp";
|
|
400
|
+
data: Date;
|
|
401
|
+
driverParam: number;
|
|
402
|
+
notNull: true;
|
|
403
|
+
hasDefault: false;
|
|
404
|
+
enumValues: undefined;
|
|
405
|
+
baseColumn: never;
|
|
406
|
+
}, object>;
|
|
407
|
+
};
|
|
408
|
+
dialect: "sqlite";
|
|
409
|
+
}>;
|
|
410
|
+
/**
|
|
411
|
+
* Config table - key/value store for SDK configuration
|
|
412
|
+
*
|
|
413
|
+
* Used for storing latency rules, custom settings, etc.
|
|
414
|
+
*/
|
|
415
|
+
declare const config: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
|
|
416
|
+
name: "gateops_config";
|
|
417
|
+
schema: undefined;
|
|
418
|
+
columns: {
|
|
419
|
+
key: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
420
|
+
name: "key";
|
|
421
|
+
tableName: "gateops_config";
|
|
422
|
+
dataType: "string";
|
|
423
|
+
columnType: "SQLiteText";
|
|
424
|
+
data: string;
|
|
425
|
+
driverParam: string;
|
|
426
|
+
notNull: true;
|
|
427
|
+
hasDefault: false;
|
|
428
|
+
enumValues: [string, ...string[]];
|
|
429
|
+
baseColumn: never;
|
|
430
|
+
}, object>;
|
|
431
|
+
value: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
432
|
+
name: "value";
|
|
433
|
+
tableName: "gateops_config";
|
|
434
|
+
dataType: "string";
|
|
435
|
+
columnType: "SQLiteText";
|
|
436
|
+
data: string;
|
|
437
|
+
driverParam: string;
|
|
438
|
+
notNull: true;
|
|
439
|
+
hasDefault: false;
|
|
440
|
+
enumValues: [string, ...string[]];
|
|
441
|
+
baseColumn: never;
|
|
442
|
+
}, object>;
|
|
443
|
+
updated_at: drizzle_orm_sqlite_core.SQLiteColumn<{
|
|
444
|
+
name: "updated_at";
|
|
445
|
+
tableName: "gateops_config";
|
|
446
|
+
dataType: "date";
|
|
447
|
+
columnType: "SQLiteTimestamp";
|
|
448
|
+
data: Date;
|
|
449
|
+
driverParam: number;
|
|
450
|
+
notNull: false;
|
|
451
|
+
hasDefault: false;
|
|
452
|
+
enumValues: undefined;
|
|
453
|
+
baseColumn: never;
|
|
454
|
+
}, object>;
|
|
455
|
+
};
|
|
456
|
+
dialect: "sqlite";
|
|
457
|
+
}>;
|
|
458
|
+
type TrafficLogInsert = typeof trafficLogs.$inferInsert;
|
|
459
|
+
type TrafficLogSelect = typeof trafficLogs.$inferSelect;
|
|
460
|
+
type EndpointInsert = typeof endpoints.$inferInsert;
|
|
461
|
+
type EndpointSelect = typeof endpoints.$inferSelect;
|
|
462
|
+
type ConfigInsert = typeof config.$inferInsert;
|
|
463
|
+
type ConfigSelect = typeof config.$inferSelect;
|
|
464
|
+
|
|
465
|
+
type schema_ConfigInsert = ConfigInsert;
|
|
466
|
+
type schema_ConfigSelect = ConfigSelect;
|
|
467
|
+
type schema_EndpointInsert = EndpointInsert;
|
|
468
|
+
type schema_EndpointSelect = EndpointSelect;
|
|
469
|
+
type schema_TrafficLogInsert = TrafficLogInsert;
|
|
470
|
+
type schema_TrafficLogSelect = TrafficLogSelect;
|
|
471
|
+
declare const schema_config: typeof config;
|
|
472
|
+
declare const schema_endpoints: typeof endpoints;
|
|
473
|
+
declare const schema_trafficLogs: typeof trafficLogs;
|
|
474
|
+
declare namespace schema {
|
|
475
|
+
export { type schema_ConfigInsert as ConfigInsert, type schema_ConfigSelect as ConfigSelect, type schema_EndpointInsert as EndpointInsert, type schema_EndpointSelect as EndpointSelect, type schema_TrafficLogInsert as TrafficLogInsert, type schema_TrafficLogSelect as TrafficLogSelect, schema_config as config, schema_endpoints as endpoints, schema_trafficLogs as trafficLogs };
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Get or create the database connection
|
|
480
|
+
*/
|
|
481
|
+
declare function getDatabase(dbPath?: string): BetterSQLite3Database<typeof schema>;
|
|
482
|
+
/**
|
|
483
|
+
* Initialize database schema (create tables if not exist)
|
|
484
|
+
*/
|
|
485
|
+
declare function initializeSchema(database?: BetterSQLite3Database<typeof schema>): void;
|
|
486
|
+
/**
|
|
487
|
+
* Close database connection
|
|
488
|
+
*/
|
|
489
|
+
declare function closeDatabase(): void;
|
|
490
|
+
/**
|
|
491
|
+
* Clean up old logs based on TTL
|
|
492
|
+
*/
|
|
493
|
+
declare function cleanupOldLogs(ttlDays?: number): number;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Route Scanner - Discovery Engine
|
|
497
|
+
*
|
|
498
|
+
* Scans Express app router stack to extract all registered routes.
|
|
499
|
+
* Runs on app startup to populate the endpoints table.
|
|
500
|
+
*/
|
|
501
|
+
/**
|
|
502
|
+
* Scan all routes from an Express app
|
|
503
|
+
*/
|
|
504
|
+
declare function scanRoutes(app: Express | ExpressApp): EndpointInfo[];
|
|
505
|
+
/**
|
|
506
|
+
* Sync discovered routes to database
|
|
507
|
+
*/
|
|
508
|
+
declare function syncRoutesToDatabase(routes: EndpointInfo[]): Promise<void>;
|
|
509
|
+
/**
|
|
510
|
+
* Get all endpoints from database
|
|
511
|
+
*/
|
|
512
|
+
declare function getEndpoints(): Promise<EndpointInfo[]>;
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Panel Sync Module
|
|
516
|
+
*
|
|
517
|
+
* Handles communication with the GateOps Panel API.
|
|
518
|
+
*/
|
|
519
|
+
/**
|
|
520
|
+
* Verify credentials with the Panel
|
|
521
|
+
*/
|
|
522
|
+
declare function verifyCredentials(username: string, apiKey: string): Promise<VerifyResponse>;
|
|
523
|
+
/**
|
|
524
|
+
* Send logs to the Panel
|
|
525
|
+
*/
|
|
526
|
+
declare function sendLogs(logs: TrafficLog[], username: string, apiKey: string, retryCount?: number): Promise<LogSubmitResponse>;
|
|
527
|
+
/**
|
|
528
|
+
* Send discovered endpoints to the Panel
|
|
529
|
+
*/
|
|
530
|
+
declare function sendEndpoints(routes: EndpointInfo[], username: string, apiKey: string): Promise<boolean>;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Buffer Manager - handles in-memory buffering with disk overflow
|
|
534
|
+
*
|
|
535
|
+
* Features:
|
|
536
|
+
* - In-memory buffer with configurable size
|
|
537
|
+
* - Auto-flush on size threshold or interval
|
|
538
|
+
* - Dual write: local DB + Panel API
|
|
539
|
+
* - Disk persistence for crash recovery
|
|
540
|
+
*/
|
|
541
|
+
declare class BufferManager {
|
|
542
|
+
private buffer;
|
|
543
|
+
private flushInterval;
|
|
544
|
+
private isInitialized;
|
|
545
|
+
private isFlushing;
|
|
546
|
+
private maxSize;
|
|
547
|
+
private intervalMs;
|
|
548
|
+
private localOnly;
|
|
549
|
+
private username;
|
|
550
|
+
private apiKey;
|
|
551
|
+
constructor();
|
|
552
|
+
/**
|
|
553
|
+
* Initialize the buffer manager
|
|
554
|
+
*/
|
|
555
|
+
initialize(options?: {
|
|
556
|
+
maxSize?: number;
|
|
557
|
+
intervalMs?: number;
|
|
558
|
+
localOnly?: boolean;
|
|
559
|
+
username?: string;
|
|
560
|
+
apiKey?: string;
|
|
561
|
+
}): void;
|
|
562
|
+
/**
|
|
563
|
+
* Push a log entry to the buffer
|
|
564
|
+
*/
|
|
565
|
+
push(log: TrafficLog): void;
|
|
566
|
+
/**
|
|
567
|
+
* Flush the buffer to database and Panel
|
|
568
|
+
*/
|
|
569
|
+
flush(): Promise<void>;
|
|
570
|
+
/**
|
|
571
|
+
* Write logs to local SQLite database
|
|
572
|
+
*/
|
|
573
|
+
private writeToDatabase;
|
|
574
|
+
/**
|
|
575
|
+
* Send logs to Panel API
|
|
576
|
+
*/
|
|
577
|
+
private sendToPanel;
|
|
578
|
+
/**
|
|
579
|
+
* Recover logs from disk buffer
|
|
580
|
+
*/
|
|
581
|
+
private recoverFromDisk;
|
|
582
|
+
/**
|
|
583
|
+
* Start the periodic flush interval
|
|
584
|
+
*/
|
|
585
|
+
private startFlushInterval;
|
|
586
|
+
/**
|
|
587
|
+
* Register handlers for graceful shutdown
|
|
588
|
+
*/
|
|
589
|
+
private registerShutdownHandlers;
|
|
590
|
+
/**
|
|
591
|
+
* Get current buffer size
|
|
592
|
+
*/
|
|
593
|
+
getSize(): number;
|
|
594
|
+
/**
|
|
595
|
+
* Shutdown the buffer manager
|
|
596
|
+
*/
|
|
597
|
+
shutdown(): void;
|
|
598
|
+
}
|
|
599
|
+
declare const buffer: BufferManager;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* GateOps Exposed Routes
|
|
603
|
+
*
|
|
604
|
+
* Routes exposed on the user's Express app for Panel to query.
|
|
605
|
+
* All routes are prefixed with /.well-known/gateops/
|
|
606
|
+
*
|
|
607
|
+
* Authentication: x-gateops-username + x-gateops-api-key headers
|
|
608
|
+
*/
|
|
609
|
+
declare const router: express_serve_static_core.Router;
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Panel API Endpoints
|
|
613
|
+
*
|
|
614
|
+
* Modify these paths if the Panel API structure changes.
|
|
615
|
+
* All paths are relative to PANEL_BASE_URL.
|
|
616
|
+
*/
|
|
617
|
+
declare const PANEL_ENDPOINTS: {
|
|
618
|
+
readonly VERIFY: "/api/sdk/verify";
|
|
619
|
+
readonly LOGS: "/api/sdk/logs";
|
|
620
|
+
readonly CONFIG: "/api/sdk/config";
|
|
621
|
+
readonly ENDPOINTS: "/api/sdk/endpoints";
|
|
622
|
+
readonly HEARTBEAT: "/api/sdk/heartbeat";
|
|
623
|
+
};
|
|
624
|
+
/**
|
|
625
|
+
* SDK Default Configuration
|
|
626
|
+
*/
|
|
627
|
+
declare const SDK_DEFAULTS: {
|
|
628
|
+
readonly BUFFER_MAX_SIZE: 50;
|
|
629
|
+
readonly BUFFER_FLUSH_INTERVAL: 10000;
|
|
630
|
+
readonly MAX_BODY_SIZE: 10240;
|
|
631
|
+
readonly LOG_TTL_DAYS: 15;
|
|
632
|
+
readonly MAX_RETRY_ATTEMPTS: 3;
|
|
633
|
+
readonly RETRY_DELAY_BASE: 1000;
|
|
634
|
+
readonly DEFAULT_DB_PATH: ".gateops/data.sqlite";
|
|
635
|
+
readonly BUFFER_FILE_PATH: ".gateops/buffer.json";
|
|
636
|
+
readonly ROUTE_PREFIX: "/.well-known/gateops";
|
|
637
|
+
};
|
|
638
|
+
/**
|
|
639
|
+
* Get full Panel endpoint URL
|
|
640
|
+
*/
|
|
641
|
+
declare function getPanelUrl(endpoint: keyof typeof PANEL_ENDPOINTS): string;
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* GateOps SDK - Lightweight API Observability for Express.js
|
|
645
|
+
*
|
|
646
|
+
* @packageDocumentation
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```typescript
|
|
650
|
+
* import gateops from 'gateops-core';
|
|
651
|
+
*
|
|
652
|
+
* const app = express();
|
|
653
|
+
*
|
|
654
|
+
* // Initialize GateOps middleware
|
|
655
|
+
* app.use(gateops.init());
|
|
656
|
+
*
|
|
657
|
+
* // Your routes...
|
|
658
|
+
* app.get('/api/users', (req, res) => { ... });
|
|
659
|
+
*
|
|
660
|
+
* app.listen(3000);
|
|
661
|
+
* ```
|
|
662
|
+
*/
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Initialize GateOps SDK
|
|
666
|
+
*
|
|
667
|
+
* Returns an Express middleware that captures all API traffic.
|
|
668
|
+
*
|
|
669
|
+
* @param options - Configuration options
|
|
670
|
+
* @returns Express middleware function
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* ```typescript
|
|
674
|
+
* // Basic usage
|
|
675
|
+
* app.use(gateops.init());
|
|
676
|
+
*
|
|
677
|
+
* // With options
|
|
678
|
+
* app.use(gateops.init({
|
|
679
|
+
* excludePaths: ['/health', '/metrics'],
|
|
680
|
+
* sensitiveFields: ['customSecret'],
|
|
681
|
+
* localOnly: true // Don't send to Panel
|
|
682
|
+
* }));
|
|
683
|
+
* ```
|
|
684
|
+
*/
|
|
685
|
+
declare function init(options?: GateOpsOptions): (req: any, res: any, next: any) => void;
|
|
686
|
+
/**
|
|
687
|
+
* Scan and register all routes from an Express app
|
|
688
|
+
*
|
|
689
|
+
* Call this after all routes are registered, typically
|
|
690
|
+
* right before `app.listen()`.
|
|
691
|
+
*
|
|
692
|
+
* @param app - Express application instance
|
|
693
|
+
*
|
|
694
|
+
* @example
|
|
695
|
+
* ```typescript
|
|
696
|
+
* // Register routes first
|
|
697
|
+
* app.use('/api', apiRouter);
|
|
698
|
+
*
|
|
699
|
+
* // Then scan
|
|
700
|
+
* gateops.scan(app);
|
|
701
|
+
*
|
|
702
|
+
* app.listen(3000);
|
|
703
|
+
* ```
|
|
704
|
+
*/
|
|
705
|
+
declare function scan(app: Express): Promise<void>;
|
|
706
|
+
/**
|
|
707
|
+
* Manually flush the log buffer
|
|
708
|
+
*
|
|
709
|
+
* Useful for testing or before graceful shutdown.
|
|
710
|
+
*/
|
|
711
|
+
declare function flush(): Promise<void>;
|
|
712
|
+
/**
|
|
713
|
+
* Shutdown GateOps SDK
|
|
714
|
+
*
|
|
715
|
+
* Call this before application exit for graceful shutdown.
|
|
716
|
+
*/
|
|
717
|
+
declare function shutdown(): void;
|
|
718
|
+
declare const gateops: {
|
|
719
|
+
init: typeof init;
|
|
720
|
+
scan: typeof scan;
|
|
721
|
+
flush: typeof flush;
|
|
722
|
+
shutdown: typeof shutdown;
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
export { type EndpointInfo, type GateOpsOptions, PANEL_ENDPOINTS, SDK_DEFAULTS, type TrafficLog, buffer, cleanupOldLogs, closeDatabase, gateops as default, flush, router as gateopsRouter, getDatabase, getEndpoints, getPanelUrl, init, initializeSchema, safeStringify, sanitize, sanitizeHeaders, scan, scanRoutes, sendEndpoints, sendLogs, shutdown, syncRoutesToDatabase, verifyCredentials };
|