@staff0rd/assist 0.165.1 → 0.166.1
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/index.js +61 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Command } from "commander";
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@staff0rd/assist",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.166.1",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -3788,6 +3788,7 @@ var allowCache;
|
|
|
3788
3788
|
var denyCache;
|
|
3789
3789
|
var TOOL_RE = /^(Bash|PowerShell)\((.+?)(:.*)?\)$/;
|
|
3790
3790
|
var SHELL_TOOLS = ["Bash", "PowerShell"];
|
|
3791
|
+
var DOTSLASH_RE = /^\.[\\/]/;
|
|
3791
3792
|
function loadPerms(key) {
|
|
3792
3793
|
return parsePerms(readSettingsPerms(key));
|
|
3793
3794
|
}
|
|
@@ -3797,9 +3798,13 @@ function shellEntries(map, toolName) {
|
|
|
3797
3798
|
}
|
|
3798
3799
|
return map.get(toolName) ?? [];
|
|
3799
3800
|
}
|
|
3801
|
+
function normCmd(cmd) {
|
|
3802
|
+
return cmd.replace(DOTSLASH_RE, "");
|
|
3803
|
+
}
|
|
3800
3804
|
function findMatch(entries, command) {
|
|
3805
|
+
const norm = normCmd(command);
|
|
3801
3806
|
return entries.find(
|
|
3802
|
-
(e) => e.wildcard ?
|
|
3807
|
+
(e) => e.wildcard ? norm === e.command || norm.startsWith(`${e.command} `) : norm === e.command
|
|
3803
3808
|
)?.command;
|
|
3804
3809
|
}
|
|
3805
3810
|
function matchesAllow(toolName, command) {
|
|
@@ -3816,7 +3821,7 @@ function parsePerms(entries) {
|
|
|
3816
3821
|
const m = entry.match(TOOL_RE);
|
|
3817
3822
|
if (m) {
|
|
3818
3823
|
const tool = m[1];
|
|
3819
|
-
const command = m[2];
|
|
3824
|
+
const command = normCmd(m[2]);
|
|
3820
3825
|
const wildcard = m[3] !== void 0;
|
|
3821
3826
|
const list4 = map.get(tool) ?? [];
|
|
3822
3827
|
list4.push({ command, wildcard });
|
|
@@ -9092,10 +9097,10 @@ var seqAuth = createConnectionAuth({
|
|
|
9092
9097
|
// src/commands/seq/seqQuery.ts
|
|
9093
9098
|
import chalk111 from "chalk";
|
|
9094
9099
|
|
|
9095
|
-
// src/commands/seq/
|
|
9100
|
+
// src/commands/seq/fetchSeq.ts
|
|
9096
9101
|
import chalk108 from "chalk";
|
|
9097
|
-
async function
|
|
9098
|
-
const url = `${conn.url}
|
|
9102
|
+
async function fetchSeq(conn, path50, params) {
|
|
9103
|
+
const url = `${conn.url}${path50}?${params}`;
|
|
9099
9104
|
const response = await fetch(url, {
|
|
9100
9105
|
headers: {
|
|
9101
9106
|
Accept: "application/json",
|
|
@@ -9107,6 +9112,52 @@ async function fetchSeqEvents(conn, params) {
|
|
|
9107
9112
|
console.error(chalk108.red(`Seq returned ${response.status}: ${body}`));
|
|
9108
9113
|
process.exit(1);
|
|
9109
9114
|
}
|
|
9115
|
+
return response;
|
|
9116
|
+
}
|
|
9117
|
+
|
|
9118
|
+
// src/commands/seq/filterToSql.ts
|
|
9119
|
+
function filterToSql(filter) {
|
|
9120
|
+
return filter.replace(/==/g, "=").replace(/"([^"]*)"/g, "'$1'");
|
|
9121
|
+
}
|
|
9122
|
+
|
|
9123
|
+
// src/commands/seq/fetchSeqData.ts
|
|
9124
|
+
async function fetchSeqData(conn, filter, count, from) {
|
|
9125
|
+
const sqlFilter = filterToSql(filter);
|
|
9126
|
+
const sql = `select @Timestamp, @Level, @Exception, @Message from stream where ${sqlFilter} order by @Timestamp desc limit ${count}`;
|
|
9127
|
+
const params = new URLSearchParams({ q: sql, fromDateUtc: from });
|
|
9128
|
+
const response = await fetchSeq(conn, "/api/data", params);
|
|
9129
|
+
const data = await response.json();
|
|
9130
|
+
return mapDataToEvents(data);
|
|
9131
|
+
}
|
|
9132
|
+
function ticksToIso(value) {
|
|
9133
|
+
if (typeof value === "string") return value;
|
|
9134
|
+
const ticks = Number(value);
|
|
9135
|
+
const epochTicks = 621355968e9;
|
|
9136
|
+
return new Date((ticks - epochTicks) / 1e4).toISOString();
|
|
9137
|
+
}
|
|
9138
|
+
function mapDataToEvents(data) {
|
|
9139
|
+
const colIndex = new Map(data.Columns.map((c, i) => [c, i]));
|
|
9140
|
+
function col(name) {
|
|
9141
|
+
const idx = colIndex.get(name) ?? colIndex.get(`@${name}`);
|
|
9142
|
+
if (idx === void 0) throw new Error(`Missing column: ${name}`);
|
|
9143
|
+
return idx;
|
|
9144
|
+
}
|
|
9145
|
+
const tsIdx = col("Timestamp");
|
|
9146
|
+
const levelIdx = col("Level");
|
|
9147
|
+
const exIdx = col("Exception");
|
|
9148
|
+
const msgIdx = col("Message");
|
|
9149
|
+
return data.Rows.map((row) => ({
|
|
9150
|
+
Timestamp: ticksToIso(row[tsIdx]),
|
|
9151
|
+
Level: String(row[levelIdx] ?? ""),
|
|
9152
|
+
Exception: row[exIdx] != null ? String(row[exIdx]) : void 0,
|
|
9153
|
+
Properties: [],
|
|
9154
|
+
MessageTemplateTokens: [{ Text: String(row[msgIdx] ?? "") }]
|
|
9155
|
+
}));
|
|
9156
|
+
}
|
|
9157
|
+
|
|
9158
|
+
// src/commands/seq/fetchSeqEvents.ts
|
|
9159
|
+
async function fetchSeqEvents(conn, params) {
|
|
9160
|
+
const response = await fetchSeq(conn, "/api/events", params);
|
|
9110
9161
|
return response.json();
|
|
9111
9162
|
}
|
|
9112
9163
|
|
|
@@ -9202,11 +9253,10 @@ function resolveConnection2(name) {
|
|
|
9202
9253
|
async function seqQuery(filter, options2) {
|
|
9203
9254
|
const conn = resolveConnection2(options2.connection);
|
|
9204
9255
|
const count = Number.parseInt(options2.count ?? "1000", 10);
|
|
9205
|
-
const
|
|
9206
|
-
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
const events = await fetchSeqEvents(conn, params);
|
|
9256
|
+
const events = options2.from ? await fetchSeqData(conn, filter, count, options2.from) : await fetchSeqEvents(
|
|
9257
|
+
conn,
|
|
9258
|
+
new URLSearchParams({ filter, count: String(count) })
|
|
9259
|
+
);
|
|
9210
9260
|
if (events.length === 0) {
|
|
9211
9261
|
console.log(chalk111.yellow("No events found."));
|
|
9212
9262
|
return;
|