@thymian/plugin-http-analyzer 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/analytics-api-context.d.ts +31 -0
- package/dist/analytics-api-context.d.ts.map +1 -0
- package/dist/analytics-api-context.js +167 -0
- package/dist/analytics-api-context.js.map +1 -0
- package/dist/db/http-filter-to-groupby-clause.d.ts +6 -0
- package/dist/db/http-filter-to-groupby-clause.d.ts.map +1 -0
- package/dist/db/http-filter-to-groupby-clause.js +64 -0
- package/dist/db/http-filter-to-groupby-clause.js.map +1 -0
- package/dist/db/http-filter-to-where-clause.d.ts +5 -0
- package/dist/db/http-filter-to-where-clause.d.ts.map +1 -0
- package/dist/db/http-filter-to-where-clause.js +188 -0
- package/dist/db/http-filter-to-where-clause.js.map +1 -0
- package/dist/db/http-transaction-repository.d.ts +15 -0
- package/dist/db/http-transaction-repository.d.ts.map +1 -0
- package/dist/db/http-transaction-repository.js +2 -0
- package/dist/db/http-transaction-repository.js.map +1 -0
- package/dist/db/init.sql +87 -0
- package/dist/db/sqlite-http-transaction-repository.d.ts +32 -0
- package/dist/db/sqlite-http-transaction-repository.d.ts.map +1 -0
- package/dist/db/sqlite-http-transaction-repository.js +472 -0
- package/dist/db/sqlite-http-transaction-repository.js.map +1 -0
- package/dist/db/types.d.ts +5 -0
- package/dist/db/types.d.ts.map +1 -0
- package/dist/db/types.js +2 -0
- package/dist/db/types.js.map +1 -0
- package/dist/db/utils.d.ts +6 -0
- package/dist/db/utils.d.ts.map +1 -0
- package/dist/db/utils.js +2 -0
- package/dist/db/utils.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-http-transaction-repository.d.ts","sourceRoot":"","sources":["../../src/db/sqlite-http-transaction-repository.ts"],"names":[],"mappings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B;IAyB/B,OAAO,CAAC,uBAAuB;IA6B/B,OAAO,CAAC,sBAAsB;IA6B9B,OAAO,CAAC,yBAAyB;IAmEjC,OAAO,CAAC,oBAAoB;IAgB5B,OAAO,CAAC,qBAAqB;IAkB7B,OAAO,CAAC,qBAAqB;IAgB7B,OAAO,CAAC,aAAa;IAerB,OAAO,CAAC,sBAAsB;IAkB9B,OAAO,CAAC,SAAS;IAYjB,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import SqliteDb, {} from 'better-sqlite3';
|
|
4
|
+
import { httpFilterToGroupByClause, httpFilterToGroupingKey, } from './http-filter-to-groupby-clause.js';
|
|
5
|
+
import { compileHttpFilterToWhereClause } from './http-filter-to-where-clause.js';
|
|
6
|
+
function sortTraceTransactions(transactions) {
|
|
7
|
+
const nextElementMap = new Map();
|
|
8
|
+
let currentElement;
|
|
9
|
+
transactions.forEach((item) => {
|
|
10
|
+
if (item.parent_transaction_id === null) {
|
|
11
|
+
currentElement = item;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
nextElementMap.set(item.parent_transaction_id, item);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const sortedList = [];
|
|
18
|
+
while (currentElement) {
|
|
19
|
+
sortedList.push(currentElement);
|
|
20
|
+
currentElement = nextElementMap.get(currentElement.id);
|
|
21
|
+
}
|
|
22
|
+
return sortedList;
|
|
23
|
+
}
|
|
24
|
+
export class SqliteHttpTransactionRepository {
|
|
25
|
+
logger;
|
|
26
|
+
db;
|
|
27
|
+
constructor(location = ':memory:', logger) {
|
|
28
|
+
this.logger = logger;
|
|
29
|
+
this.db = new SqliteDb(location);
|
|
30
|
+
this.db.pragma('journal_mode = WAL');
|
|
31
|
+
}
|
|
32
|
+
async init() {
|
|
33
|
+
this.logger.debug('Initializing database for HttpTransactionRepository.');
|
|
34
|
+
const init = await readFile(join(import.meta.dirname, 'init.sql'), 'utf-8');
|
|
35
|
+
this.db.exec(init);
|
|
36
|
+
}
|
|
37
|
+
*readAndGroupTransactionsByHttpFilter(filter, groupBy, role) {
|
|
38
|
+
const params = [];
|
|
39
|
+
const whereFragment = compileHttpFilterToWhereClause(filter, {
|
|
40
|
+
requests: 'req',
|
|
41
|
+
responses: 'res',
|
|
42
|
+
});
|
|
43
|
+
const groupByFragment = httpFilterToGroupByClause(groupBy, {
|
|
44
|
+
requests: 'req',
|
|
45
|
+
responses: 'res',
|
|
46
|
+
});
|
|
47
|
+
const groupingKey = httpFilterToGroupingKey(groupBy, {
|
|
48
|
+
requests: 'req',
|
|
49
|
+
responses: 'res',
|
|
50
|
+
});
|
|
51
|
+
params.push(...whereFragment.params, ...groupByFragment.params);
|
|
52
|
+
let whereClause = whereFragment.sql;
|
|
53
|
+
if (role?.length) {
|
|
54
|
+
whereClause += this.rolesToWhereClause(role);
|
|
55
|
+
params.push(...role, ...role);
|
|
56
|
+
}
|
|
57
|
+
const statement = `
|
|
58
|
+
SELECT
|
|
59
|
+
GROUP_CONCAT(t.id, ',') AS transactionIds,
|
|
60
|
+
${groupingKey} AS grouping_key,
|
|
61
|
+
${groupByFragment.sql}
|
|
62
|
+
FROM http_transaction t
|
|
63
|
+
JOIN http_request req ON req.id = t.request_id
|
|
64
|
+
JOIN http_response res ON res.id = t.response_id
|
|
65
|
+
LEFT JOIN communication_role reqRole ON req.role_id = reqRole.id
|
|
66
|
+
LEFT JOIN communication_role resRole ON res.role_id = resRole.id
|
|
67
|
+
WHERE ${whereClause}
|
|
68
|
+
GROUP BY ${groupByFragment.sql}
|
|
69
|
+
`;
|
|
70
|
+
this.logger.debug('Executing SQL query:', statement);
|
|
71
|
+
const result = this.db
|
|
72
|
+
.prepare(statement)
|
|
73
|
+
.iterate(params);
|
|
74
|
+
for (const { transactionIds, grouping_key } of result) {
|
|
75
|
+
const ids = transactionIds.split(',').map((id) => parseInt(id));
|
|
76
|
+
const transactions = ids.map((id) => {
|
|
77
|
+
const transaction = this.readTransactionById(id);
|
|
78
|
+
if (!transaction) {
|
|
79
|
+
throw new Error(`Transaction with id ${id} not found`);
|
|
80
|
+
}
|
|
81
|
+
return transaction;
|
|
82
|
+
});
|
|
83
|
+
yield [grouping_key, transactions];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
rolesToWhereClause(roles) {
|
|
87
|
+
if (!roles || roles.length === 0) {
|
|
88
|
+
return '';
|
|
89
|
+
}
|
|
90
|
+
return ` AND (reqRole.name IN (${roles.map(() => '?').join(', ')}) OR resRole.name IN (${roles.map(() => '?').join(', ')}))`;
|
|
91
|
+
}
|
|
92
|
+
*readTransactionsByHttpFilter(filter, roles) {
|
|
93
|
+
let whereClause = '';
|
|
94
|
+
const { sql, params } = compileHttpFilterToWhereClause(filter, {
|
|
95
|
+
requests: 'req',
|
|
96
|
+
responses: 'res',
|
|
97
|
+
});
|
|
98
|
+
if (roles?.length) {
|
|
99
|
+
params.push(...roles);
|
|
100
|
+
params.push(...roles);
|
|
101
|
+
whereClause = sql + this.rolesToWhereClause(roles);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
whereClause = sql;
|
|
105
|
+
}
|
|
106
|
+
const rawStatement = `
|
|
107
|
+
SELECT
|
|
108
|
+
t.id as trans_id,
|
|
109
|
+
req.id as req_id,
|
|
110
|
+
req.origin as req_origin,
|
|
111
|
+
req.path as req_path,
|
|
112
|
+
req.method as req_method,
|
|
113
|
+
req.body as req_body,
|
|
114
|
+
req.body_encoding as req_body_encoding,
|
|
115
|
+
res.id as res_id,
|
|
116
|
+
res.status_code as res_status,
|
|
117
|
+
res.duration as res_duration,
|
|
118
|
+
res.body as res_body,
|
|
119
|
+
res.body_encoding as res_body_encoding,
|
|
120
|
+
reqRole.name as req_role_name,
|
|
121
|
+
resRole.name as res_role_name
|
|
122
|
+
FROM http_transaction t
|
|
123
|
+
JOIN http_request req ON t.request_id = req.id
|
|
124
|
+
JOIN http_response res ON t.response_id = res.id
|
|
125
|
+
LEFT JOIN communication_role reqRole ON req.role_id = reqRole.id
|
|
126
|
+
LEFT JOIN communication_role resRole ON res.role_id = resRole.id
|
|
127
|
+
WHERE ${whereClause}
|
|
128
|
+
`;
|
|
129
|
+
this.logger.debug('Executing SQL query:', rawStatement);
|
|
130
|
+
const statement = this.db.prepare(rawStatement);
|
|
131
|
+
for (const row of statement.iterate(...params)) {
|
|
132
|
+
const transaction = {
|
|
133
|
+
request: {
|
|
134
|
+
data: {
|
|
135
|
+
origin: row.req_origin,
|
|
136
|
+
path: row.req_path,
|
|
137
|
+
method: row.req_method,
|
|
138
|
+
body: row.req_body || undefined,
|
|
139
|
+
bodyEncoding: row.req_body_encoding || undefined,
|
|
140
|
+
headers: this.readRequestHeadersById(row.req_id),
|
|
141
|
+
},
|
|
142
|
+
meta: {
|
|
143
|
+
role: row.req_role_name,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
response: {
|
|
147
|
+
data: {
|
|
148
|
+
statusCode: row.res_status,
|
|
149
|
+
duration: row.res_duration,
|
|
150
|
+
body: row.res_body || undefined,
|
|
151
|
+
bodyEncoding: row.res_body_encoding || undefined,
|
|
152
|
+
headers: this.readResponseHeadersById(row.res_id),
|
|
153
|
+
trailers: this.readResponseTrailersById(row.res_id),
|
|
154
|
+
},
|
|
155
|
+
meta: {
|
|
156
|
+
role: row.res_role_name,
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
yield transaction;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
insertHttpTrace(trace) {
|
|
164
|
+
const insertTrace = this.db.transaction(() => {
|
|
165
|
+
// Insert trace
|
|
166
|
+
const traceStmt = this.db.prepare('INSERT INTO http_trace DEFAULT VALUES');
|
|
167
|
+
const traceResult = traceStmt.run();
|
|
168
|
+
const traceId = traceResult.lastInsertRowid;
|
|
169
|
+
// Insert all transactions in the trace with parent-child relationships
|
|
170
|
+
let parentTransactionId = undefined;
|
|
171
|
+
for (const transaction of trace) {
|
|
172
|
+
const transactionId = this.insertTransactionForTrace(transaction, traceId, parentTransactionId);
|
|
173
|
+
parentTransactionId = transactionId;
|
|
174
|
+
}
|
|
175
|
+
return traceId;
|
|
176
|
+
});
|
|
177
|
+
return insertTrace();
|
|
178
|
+
}
|
|
179
|
+
readTraceById(id) {
|
|
180
|
+
const traceStmt = this.db.prepare('SELECT id FROM http_trace WHERE id = ?');
|
|
181
|
+
const traceRow = traceStmt.get(id);
|
|
182
|
+
if (!traceRow) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
const transactionsStmt = this.db.prepare(`
|
|
186
|
+
SELECT id, parent_transaction_id FROM http_transaction
|
|
187
|
+
WHERE trace_id = ?
|
|
188
|
+
`);
|
|
189
|
+
const transactionRows = transactionsStmt.all(traceRow.id);
|
|
190
|
+
const sortedTransactions = sortTraceTransactions(transactionRows);
|
|
191
|
+
const trace = [];
|
|
192
|
+
for (const row of sortedTransactions) {
|
|
193
|
+
const transaction = this.readTransactionById(row.id);
|
|
194
|
+
if (transaction) {
|
|
195
|
+
trace.push(transaction);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return trace.length > 0 ? trace : undefined;
|
|
199
|
+
}
|
|
200
|
+
// this could be implemented more efficiently by using a single query that joins the http_trace table with the http_transaction table
|
|
201
|
+
// but this would require a lot of refactoring of the code that reads traces and transactions
|
|
202
|
+
// so for now we just iterate over all traces and read all transactions for each trace
|
|
203
|
+
*readAllHttpTraces() {
|
|
204
|
+
const traceStmt = this.db.prepare(`
|
|
205
|
+
SELECT id FROM http_trace
|
|
206
|
+
`);
|
|
207
|
+
const traceRows = traceStmt.all();
|
|
208
|
+
for (const traceRow of traceRows) {
|
|
209
|
+
const trace = this.readTraceById(traceRow.id);
|
|
210
|
+
if (trace) {
|
|
211
|
+
yield trace;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
insertHttpTransaction(transaction) {
|
|
216
|
+
const insertTransaction = this.db.transaction(() => {
|
|
217
|
+
// Create a trace for this single transaction
|
|
218
|
+
const traceStmt = this.db.prepare('INSERT INTO http_trace DEFAULT VALUES');
|
|
219
|
+
const traceResult = traceStmt.run();
|
|
220
|
+
const traceId = traceResult.lastInsertRowid;
|
|
221
|
+
return this.insertTransactionForTrace(transaction, traceId);
|
|
222
|
+
});
|
|
223
|
+
return insertTransaction();
|
|
224
|
+
}
|
|
225
|
+
readTransactionById(id) {
|
|
226
|
+
// Get transaction
|
|
227
|
+
const transactionStmt = this.db.prepare(`
|
|
228
|
+
SELECT request_id, response_id FROM http_transaction WHERE id = ?
|
|
229
|
+
`);
|
|
230
|
+
const transactionRow = transactionStmt.get(id);
|
|
231
|
+
if (!transactionRow) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const request = this.readRequestById(transactionRow.request_id);
|
|
235
|
+
if (!request) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const response = this.readResponseById(transactionRow.response_id);
|
|
239
|
+
if (!response) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
request,
|
|
244
|
+
response,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
readResponseById(id) {
|
|
248
|
+
const responseStmt = this.db.prepare(`
|
|
249
|
+
SELECT res.*, role.name as role_name
|
|
250
|
+
FROM http_response res
|
|
251
|
+
LEFT JOIN communication_role role ON res.role_id = role.id
|
|
252
|
+
WHERE res.id = ?
|
|
253
|
+
`);
|
|
254
|
+
const responseRow = responseStmt.get(id);
|
|
255
|
+
if (!responseRow) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const responseHeaders = this.readResponseHeadersById(id);
|
|
259
|
+
const responseTrailers = this.readResponseTrailersById(id);
|
|
260
|
+
return {
|
|
261
|
+
data: {
|
|
262
|
+
statusCode: responseRow.status_code,
|
|
263
|
+
headers: responseHeaders,
|
|
264
|
+
body: responseRow.body || undefined,
|
|
265
|
+
bodyEncoding: responseRow.body_encoding || undefined,
|
|
266
|
+
trailers: responseTrailers,
|
|
267
|
+
duration: responseRow.duration,
|
|
268
|
+
},
|
|
269
|
+
meta: {
|
|
270
|
+
role: responseRow.role_name,
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
readResponseTrailersById(id) {
|
|
275
|
+
const responseTrailersStmt = this.db.prepare(`
|
|
276
|
+
SELECT name, value FROM http_response_trailer WHERE response_id = ?
|
|
277
|
+
`);
|
|
278
|
+
const responseTrailerRows = responseTrailersStmt.all(id);
|
|
279
|
+
const responseTrailers = {};
|
|
280
|
+
for (const trailer of responseTrailerRows) {
|
|
281
|
+
responseTrailers[trailer.name] = trailer.value;
|
|
282
|
+
}
|
|
283
|
+
return responseTrailers;
|
|
284
|
+
}
|
|
285
|
+
readRequestById(id) {
|
|
286
|
+
const requestStmt = this.db.prepare(`
|
|
287
|
+
SELECT req.*, role.name as role_name
|
|
288
|
+
FROM http_request req
|
|
289
|
+
LEFT JOIN communication_role role ON req.role_id = role.id
|
|
290
|
+
WHERE req.id = ?
|
|
291
|
+
`);
|
|
292
|
+
const requestRow = requestStmt.get(id);
|
|
293
|
+
if (!requestRow) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const requestHeaders = this.readRequestHeadersById(id);
|
|
297
|
+
const queryParameters = this.readQueryParametersById(id);
|
|
298
|
+
const pathValue = queryParameters
|
|
299
|
+
? new URL(requestRow.path, requestRow.origin).pathname +
|
|
300
|
+
'?' +
|
|
301
|
+
queryParameters
|
|
302
|
+
: requestRow.path;
|
|
303
|
+
return {
|
|
304
|
+
data: {
|
|
305
|
+
origin: requestRow.origin,
|
|
306
|
+
path: pathValue,
|
|
307
|
+
method: requestRow.method,
|
|
308
|
+
bodyEncoding: requestRow.body_encoding || undefined,
|
|
309
|
+
body: requestRow.body || undefined,
|
|
310
|
+
headers: requestHeaders,
|
|
311
|
+
},
|
|
312
|
+
meta: {
|
|
313
|
+
role: requestRow.role_name,
|
|
314
|
+
},
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
readQueryParametersById(id) {
|
|
318
|
+
// the ORDER BY is required to ensure that the query parameters are returned in the same order as they were inserted
|
|
319
|
+
const queryParametersStmt = this.db.prepare(`
|
|
320
|
+
SELECT name, value, id
|
|
321
|
+
FROM http_request_query_parameter
|
|
322
|
+
WHERE request_id = ?
|
|
323
|
+
ORDER BY id ASC
|
|
324
|
+
`);
|
|
325
|
+
const queryParameterRows = queryParametersStmt.all(id);
|
|
326
|
+
const queryParameters = new URLSearchParams();
|
|
327
|
+
for (const parameter of queryParameterRows) {
|
|
328
|
+
queryParameters.append(parameter.name, parameter.value);
|
|
329
|
+
}
|
|
330
|
+
if (queryParameters.size === 0) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
return queryParameters.toString();
|
|
334
|
+
}
|
|
335
|
+
readResponseHeadersById(id) {
|
|
336
|
+
const responseHeadersStmt = this.db.prepare(`
|
|
337
|
+
SELECT name, value FROM http_response_header WHERE response_id = ?
|
|
338
|
+
`);
|
|
339
|
+
const responseHeaderRows = responseHeadersStmt.all(id);
|
|
340
|
+
const responseHeaders = {};
|
|
341
|
+
for (const header of responseHeaderRows) {
|
|
342
|
+
if (responseHeaders[header.name]) {
|
|
343
|
+
const existing = responseHeaders[header.name];
|
|
344
|
+
responseHeaders[header.name] = (Array.isArray(existing)
|
|
345
|
+
? [...existing, header.value]
|
|
346
|
+
: [existing, header.value]).filter((x) => typeof x !== 'undefined');
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
responseHeaders[header.name] = header.value;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return responseHeaders;
|
|
353
|
+
}
|
|
354
|
+
readRequestHeadersById(id) {
|
|
355
|
+
const requestHeadersStmt = this.db.prepare(`
|
|
356
|
+
SELECT name, value FROM http_request_header WHERE request_id = ?
|
|
357
|
+
`);
|
|
358
|
+
const requestHeaderRows = requestHeadersStmt.all(id);
|
|
359
|
+
const requestHeaders = {};
|
|
360
|
+
for (const header of requestHeaderRows) {
|
|
361
|
+
if (requestHeaders[header.name]) {
|
|
362
|
+
const existing = requestHeaders[header.name];
|
|
363
|
+
requestHeaders[header.name] = (Array.isArray(existing)
|
|
364
|
+
? [...existing, header.value]
|
|
365
|
+
: [existing, header.value]).filter((x) => typeof x !== 'undefined');
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
requestHeaders[header.name] = header.value;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return requestHeaders;
|
|
372
|
+
}
|
|
373
|
+
insertTransactionForTrace(transaction, traceId, parentTransactionId) {
|
|
374
|
+
// Get role IDs
|
|
375
|
+
const requestRoleId = this.getRoleId(transaction.request.meta.role);
|
|
376
|
+
const responseRoleId = this.getRoleId(transaction.response.meta.role);
|
|
377
|
+
// Insert request
|
|
378
|
+
const requestStmt = this.db.prepare(`
|
|
379
|
+
INSERT INTO http_request (origin, path, method, body_encoding, body, role_id)
|
|
380
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
381
|
+
`);
|
|
382
|
+
const url = new URL(transaction.request.data.path, transaction.request.data.origin);
|
|
383
|
+
const requestResult = requestStmt.run(url.origin, url.pathname, transaction.request.data.method, transaction.request.data.bodyEncoding || null, transaction.request.data.body || null, requestRoleId);
|
|
384
|
+
const requestId = requestResult.lastInsertRowid;
|
|
385
|
+
// Insert request headers and query parameters
|
|
386
|
+
this.insertRequestHeaders(requestId, transaction.request.data.headers);
|
|
387
|
+
this.insertQueryParameters(requestId, url.searchParams);
|
|
388
|
+
// Insert response
|
|
389
|
+
const responseStmt = this.db.prepare(`
|
|
390
|
+
INSERT INTO http_response (status_code, body, body_encoding, duration, role_id)
|
|
391
|
+
VALUES (?, ?, ?, ?, ?)
|
|
392
|
+
`);
|
|
393
|
+
const responseResult = responseStmt.run(transaction.response.data.statusCode, transaction.response.data.body || null, transaction.response.data.bodyEncoding || null, transaction.response.data.duration, responseRoleId);
|
|
394
|
+
const responseId = responseResult.lastInsertRowid;
|
|
395
|
+
// Insert response headers and trailers
|
|
396
|
+
this.insertResponseHeaders(responseId, transaction.response.data.headers);
|
|
397
|
+
this.insertResponseTrailers(responseId, transaction.response.data.trailers);
|
|
398
|
+
// Insert transaction
|
|
399
|
+
const transactionStmt = this.db.prepare(`
|
|
400
|
+
INSERT INTO http_transaction (request_id, response_id, trace_id, parent_transaction_id)
|
|
401
|
+
VALUES (?, ?, ?, ?)
|
|
402
|
+
`);
|
|
403
|
+
const transactionResult = transactionStmt.run(requestId, responseId, traceId, parentTransactionId ?? null);
|
|
404
|
+
return transactionResult.lastInsertRowid;
|
|
405
|
+
}
|
|
406
|
+
insertRequestHeaders(requestId, headers) {
|
|
407
|
+
if (!headers) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const headerStmt = this.db.prepare(`
|
|
411
|
+
INSERT INTO http_request_header (request_id, name, value)
|
|
412
|
+
VALUES (?, ?, ?)
|
|
413
|
+
`);
|
|
414
|
+
this.insertHeaders(headers, headerStmt, requestId);
|
|
415
|
+
}
|
|
416
|
+
insertQueryParameters(requestId, searchParams) {
|
|
417
|
+
if (searchParams.size === 0) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const queryStmt = this.db.prepare(`
|
|
421
|
+
INSERT INTO http_request_query_parameter (request_id, name, value)
|
|
422
|
+
VALUES (?, ?, ?)
|
|
423
|
+
`);
|
|
424
|
+
for (const [name, value] of searchParams.entries()) {
|
|
425
|
+
queryStmt.run(requestId, name, value);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
insertResponseHeaders(responseId, headers) {
|
|
429
|
+
if (!headers) {
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const headerStmt = this.db.prepare(`
|
|
433
|
+
INSERT INTO http_response_header (response_id, name, value)
|
|
434
|
+
VALUES (?, ?, ?)
|
|
435
|
+
`);
|
|
436
|
+
this.insertHeaders(headers, headerStmt, responseId);
|
|
437
|
+
}
|
|
438
|
+
insertHeaders(headers, statement, id) {
|
|
439
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
440
|
+
if (value !== undefined) {
|
|
441
|
+
const values = Array.isArray(value) ? value : [value];
|
|
442
|
+
for (const v of values) {
|
|
443
|
+
statement.run(id, name, v);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
insertResponseTrailers(responseId, trailers) {
|
|
449
|
+
if (!trailers) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const trailerStmt = this.db.prepare(`
|
|
453
|
+
INSERT INTO http_response_trailer (response_id, name, value)
|
|
454
|
+
VALUES (?, ?, ?)
|
|
455
|
+
`);
|
|
456
|
+
for (const [name, value] of Object.entries(trailers)) {
|
|
457
|
+
trailerStmt.run(responseId, name, value);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
getRoleId(roleName) {
|
|
461
|
+
if (roleName === null || roleName === undefined) {
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
const stmt = this.db.prepare('SELECT id FROM communication_role WHERE name = ?');
|
|
465
|
+
const row = stmt.get(roleName);
|
|
466
|
+
return row?.id || null;
|
|
467
|
+
}
|
|
468
|
+
close() {
|
|
469
|
+
this.db.close();
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
//# sourceMappingURL=sqlite-http-transaction-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-http-transaction-repository.js","sourceRoot":"","sources":["../../src/db/sqlite-http-transaction-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAWjC,OAAO,QAAQ,EAAE,EAAiC,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EACL,yBA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AAC;QAC3C,CAAC;IACH,CAAC;IAEO,SAAS,CAAC,QAAmC;QACnD,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAChD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,OAAO,CAC1B,kDAAkD,CACnD,CAAC;QACF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAA+B,CAAC;QAC7D,OAAO,GAAG,EAAE,EAAE,IAAI,IAAI,CAAC;IACzB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/db/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
package/dist/db/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/db/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/db/utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,MAAqB,CAAC"}
|
package/dist/db/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/db/utils.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,IAAI,GAAG,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type CapturedTrace, type CapturedTransaction, type EvaluatedRuleViolation, type Rule, type RulesConfiguration, type SerializedThymianFormat, type ThymianPlugin, type ThymianReport } from '@thymian/core';
|
|
2
|
+
export { AnalyticsApiContext } from './analytics-api-context.js';
|
|
3
|
+
export type { HttpTransactionRepository } from './db/http-transaction-repository.js';
|
|
4
|
+
export { SqliteHttpTransactionRepository } from './db/sqlite-http-transaction-repository.js';
|
|
5
|
+
declare module '@thymian/core' {
|
|
6
|
+
interface ThymianActions {
|
|
7
|
+
'http-analyzer.lint-analytics': {
|
|
8
|
+
event: {
|
|
9
|
+
format?: SerializedThymianFormat;
|
|
10
|
+
transactions?: CapturedTransaction[];
|
|
11
|
+
traces?: CapturedTrace[];
|
|
12
|
+
rules?: Rule[];
|
|
13
|
+
rulesConfig?: RulesConfiguration;
|
|
14
|
+
};
|
|
15
|
+
response: {
|
|
16
|
+
reports: ThymianReport[];
|
|
17
|
+
violations: EvaluatedRuleViolation[];
|
|
18
|
+
valid: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
'http-analyzer.lint-analytics-batch': {
|
|
22
|
+
event: {
|
|
23
|
+
format?: SerializedThymianFormat;
|
|
24
|
+
rules?: Rule[];
|
|
25
|
+
rulesConfig?: RulesConfiguration;
|
|
26
|
+
};
|
|
27
|
+
response: {
|
|
28
|
+
reports: ThymianReport[];
|
|
29
|
+
violations: EvaluatedRuleViolation[];
|
|
30
|
+
valid: boolean;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface ThymianEvents {
|
|
35
|
+
'http-analyzer.transaction': CapturedTransaction;
|
|
36
|
+
'http-analyzer.trace': CapturedTrace;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export type HttpAnalyzerStorage = {
|
|
40
|
+
type: 'memory';
|
|
41
|
+
} | {
|
|
42
|
+
type: 'sqlite';
|
|
43
|
+
path?: string;
|
|
44
|
+
};
|
|
45
|
+
export type HttpAnalyzerPluginOptions = {
|
|
46
|
+
storage?: HttpAnalyzerStorage;
|
|
47
|
+
};
|
|
48
|
+
export declare function createHttpAnalyzerPlugin(pluginName?: string): ThymianPlugin<HttpAnalyzerPluginOptions>;
|
|
49
|
+
export declare const httpAnalyzerPlugin: ThymianPlugin<HttpAnalyzerPluginOptions>;
|
|
50
|
+
export default httpAnalyzerPlugin;
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAE3B,KAAK,IAAI,EAET,KAAK,kBAAkB,EAEvB,KAAK,uBAAuB,EAG5B,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAKvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,YAAY,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,+BAA+B,EAAE,MAAM,4CAA4C,CAAC;AAE7F,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,cAAc;QACtB,8BAA8B,EAAE;YAC9B,KAAK,EAAE;gBACL,MAAM,CAAC,EAAE,uBAAuB,CAAC;gBACjC,YAAY,CAAC,EAAE,mBAAmB,EAAE,CAAC;gBACrC,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;gBACzB,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;gBACf,WAAW,CAAC,EAAE,kBAAkB,CAAC;aAClC,CAAC;YACF,QAAQ,EAAE;gBACR,OAAO,EAAE,aAAa,EAAE,CAAC;gBACzB,UAAU,EAAE,sBAAsB,EAAE,CAAC;gBACrC,KAAK,EAAE,OAAO,CAAC;a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