oculon 0.1.6 → 0.1.7
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/README.md +24 -8
- package/dist/cli/main.js +82 -0
- package/dist/core/calls.d.ts +63 -0
- package/dist/core/calls.js +120 -0
- package/dist/core/http.d.ts +11 -0
- package/dist/core/http.js +110 -30
- package/dist/core/pdf.d.ts +51 -0
- package/dist/core/pdf.js +211 -0
- package/dist/core/verdict.d.ts +30 -0
- package/dist/core/verdict.js +164 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +29 -0
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +129 -5
- package/dist/modules/checks.d.ts +59 -0
- package/dist/modules/checks.js +134 -0
- package/dist/modules/doc.d.ts +61 -0
- package/dist/modules/doc.js +715 -0
- package/dist/modules/utility.d.ts +27 -1
- package/dist/modules/utility.js +108 -11
- package/dist/report-pdf.d.ts +7 -0
- package/dist/report-pdf.js +81 -0
- package/dist/web/card.d.ts +28 -0
- package/dist/web/card.js +75 -0
- package/dist/web/index.html +76 -4
- package/dist/web/openapi.js +2 -0
- package/dist/web/pages.d.ts +24 -0
- package/dist/web/pages.js +139 -0
- package/dist/web/public.js +2 -0
- package/dist/web/server.js +84 -10
- package/dist/web/token.html +2 -1
- package/dist/web/utility.html +40 -14
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small PDF writer for reports, no dependencies: A4 pages, the standard Helvetica and Courier fonts
|
|
3
|
+
* (WinAnsi), headings, paragraphs with word wrap, bullet lists, key-value rows, coloured verdict bars and links.
|
|
4
|
+
* Characters outside WinAnsi are replaced, so any input gives a valid file.
|
|
5
|
+
*/
|
|
6
|
+
type RGB = [number, number, number];
|
|
7
|
+
export type Block = {
|
|
8
|
+
t: 'title';
|
|
9
|
+
text: string;
|
|
10
|
+
} | {
|
|
11
|
+
t: 'h';
|
|
12
|
+
text: string;
|
|
13
|
+
} | {
|
|
14
|
+
t: 'p';
|
|
15
|
+
text: string;
|
|
16
|
+
size?: number;
|
|
17
|
+
color?: RGB;
|
|
18
|
+
} | {
|
|
19
|
+
t: 'mono';
|
|
20
|
+
text: string;
|
|
21
|
+
} | {
|
|
22
|
+
t: 'bullets';
|
|
23
|
+
items: string[];
|
|
24
|
+
color?: RGB;
|
|
25
|
+
} | {
|
|
26
|
+
t: 'kv';
|
|
27
|
+
rows: [string, string][];
|
|
28
|
+
} | {
|
|
29
|
+
t: 'bar';
|
|
30
|
+
label: string;
|
|
31
|
+
text: string;
|
|
32
|
+
color: RGB;
|
|
33
|
+
} | {
|
|
34
|
+
t: 'link';
|
|
35
|
+
text: string;
|
|
36
|
+
url: string;
|
|
37
|
+
} | {
|
|
38
|
+
t: 'table';
|
|
39
|
+
head: string[];
|
|
40
|
+
rows: string[][];
|
|
41
|
+
widths: number[];
|
|
42
|
+
} | {
|
|
43
|
+
t: 'gap';
|
|
44
|
+
h?: number;
|
|
45
|
+
};
|
|
46
|
+
/** WinAnsi-safe text: common punctuation mapped, anything else outside Latin-1 becomes '?'. */
|
|
47
|
+
export declare function ansi(s: string): string;
|
|
48
|
+
/** Render blocks to a PDF file. `footer` is printed on every page. */
|
|
49
|
+
export declare function renderPdf(blocks: Block[], footer: string): Buffer;
|
|
50
|
+
export declare const TONE_RGB: Record<string, RGB>;
|
|
51
|
+
export {};
|
package/dist/core/pdf.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small PDF writer for reports, no dependencies: A4 pages, the standard Helvetica and Courier fonts
|
|
3
|
+
* (WinAnsi), headings, paragraphs with word wrap, bullet lists, key-value rows, coloured verdict bars and links.
|
|
4
|
+
* Characters outside WinAnsi are replaced, so any input gives a valid file.
|
|
5
|
+
*/
|
|
6
|
+
const W = 595, H = 842, M = 50, CW = W - 2 * M;
|
|
7
|
+
const INK = [0.08, 0.1, 0.11], MUTE = [0.42, 0.47, 0.49], ACCENT = [0, 0.48, 0.53];
|
|
8
|
+
// Helvetica widths (per 1000 em) for ASCII 32-126; other characters use 556.
|
|
9
|
+
const HELV = [278, 278, 355, 556, 556, 889, 667, 191, 333, 333, 389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, 278, 278, 584, 584, 584, 556, 1015, 667, 667, 722, 722, 667, 611, 778, 722, 278, 500, 667, 556, 833, 722, 778, 667, 778, 722, 667, 611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556, 333, 556, 556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556, 556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334, 584];
|
|
10
|
+
const BOLD_EXTRA = 1.06;
|
|
11
|
+
function width(s, size, font) {
|
|
12
|
+
if (font === 'F3')
|
|
13
|
+
return s.length * 600 * size / 1000;
|
|
14
|
+
let w = 0;
|
|
15
|
+
for (const ch of s) {
|
|
16
|
+
const c = ch.charCodeAt(0);
|
|
17
|
+
w += c >= 32 && c <= 126 ? HELV[c - 32] : 556;
|
|
18
|
+
}
|
|
19
|
+
return (w * size / 1000) * (font === 'F2' ? BOLD_EXTRA : 1);
|
|
20
|
+
}
|
|
21
|
+
/** WinAnsi-safe text: common punctuation mapped, anything else outside Latin-1 becomes '?'. */
|
|
22
|
+
export function ansi(s) {
|
|
23
|
+
return s
|
|
24
|
+
.replace(/[‘’]/g, "'").replace(/[“”]/g, '"').replace(/[–—]/g, '-').replace(/…/g, '...').replace(/→/g, '->').replace(/•/g, '-')
|
|
25
|
+
.replace(/[\r\t]/g, ' ')
|
|
26
|
+
.replace(/[^\n\x20-\x7e\xa0-\xff]/g, '?');
|
|
27
|
+
}
|
|
28
|
+
const esc = (s) => s.replace(/\\/g, '\\\\').replace(/\(/g, '\\(').replace(/\)/g, '\\)');
|
|
29
|
+
function wrap(text, size, font, max) {
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const para of ansi(text).split('\n')) {
|
|
32
|
+
let line = '';
|
|
33
|
+
for (const word of para.split(/ +/)) {
|
|
34
|
+
const tryLine = line ? `${line} ${word}` : word;
|
|
35
|
+
if (width(tryLine, size, font) <= max) {
|
|
36
|
+
line = tryLine;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (line)
|
|
40
|
+
out.push(line);
|
|
41
|
+
// A single word wider than the line (a hash, a URL) is cut into pieces.
|
|
42
|
+
let w = word;
|
|
43
|
+
while (width(w, size, font) > max) {
|
|
44
|
+
let n = w.length;
|
|
45
|
+
while (n > 1 && width(w.slice(0, n), size, font) > max)
|
|
46
|
+
n--;
|
|
47
|
+
out.push(w.slice(0, n));
|
|
48
|
+
w = w.slice(n);
|
|
49
|
+
}
|
|
50
|
+
line = w;
|
|
51
|
+
}
|
|
52
|
+
out.push(line);
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
class Doc {
|
|
57
|
+
footer;
|
|
58
|
+
pages = [];
|
|
59
|
+
links = [];
|
|
60
|
+
y = 0;
|
|
61
|
+
constructor(footer) {
|
|
62
|
+
this.footer = footer;
|
|
63
|
+
this.page();
|
|
64
|
+
}
|
|
65
|
+
get ops() { return this.pages[this.pages.length - 1]; }
|
|
66
|
+
page() {
|
|
67
|
+
this.pages.push([]);
|
|
68
|
+
this.links.push([]);
|
|
69
|
+
this.y = H - M;
|
|
70
|
+
}
|
|
71
|
+
need(h) { if (this.y - h < M + 24)
|
|
72
|
+
this.page(); }
|
|
73
|
+
text(x, y, s, size, font, color = INK) {
|
|
74
|
+
this.ops.push(`BT /${font} ${size} Tf ${color.map((c) => c.toFixed(3)).join(' ')} rg ${x.toFixed(1)} ${y.toFixed(1)} Td (${esc(s)}) Tj ET`);
|
|
75
|
+
}
|
|
76
|
+
rect(x, y, w, h, color) {
|
|
77
|
+
this.ops.push(`${color.map((c) => c.toFixed(3)).join(' ')} rg ${x.toFixed(1)} ${y.toFixed(1)} ${w.toFixed(1)} ${h.toFixed(1)} re f`);
|
|
78
|
+
}
|
|
79
|
+
line(y, color = [0.85, 0.87, 0.88]) {
|
|
80
|
+
this.ops.push(`${color.map((c) => c.toFixed(3)).join(' ')} RG 0.8 w ${M} ${y.toFixed(1)} m ${W - M} ${y.toFixed(1)} l S`);
|
|
81
|
+
}
|
|
82
|
+
para(s, size, font, color = INK, indent = 0, lead = 1.45) {
|
|
83
|
+
for (const l of wrap(s, size, font, CW - indent)) {
|
|
84
|
+
this.need(size * lead);
|
|
85
|
+
this.y -= size * lead;
|
|
86
|
+
this.text(M + indent, this.y, l, size, font, color);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
build() {
|
|
90
|
+
const objs = [];
|
|
91
|
+
const add = (s) => { objs.push(s); return objs.length; };
|
|
92
|
+
add('<< /Type /Catalog /Pages 2 0 R >>');
|
|
93
|
+
add('PAGES');
|
|
94
|
+
const f1 = add('<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >>');
|
|
95
|
+
const f2 = add('<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >>');
|
|
96
|
+
const f3 = add('<< /Type /Font /Subtype /Type1 /BaseFont /Courier /Encoding /WinAnsiEncoding >>');
|
|
97
|
+
const kids = [];
|
|
98
|
+
this.pages.forEach((ops, i) => {
|
|
99
|
+
const foot = `BT /F1 8 Tf ${MUTE.join(' ')} rg ${M} 28 Td (${esc(ansi(this.footer))}) Tj ET BT /F1 8 Tf ${MUTE.join(' ')} rg ${W - M - 40} 28 Td (Page ${i + 1} of ${this.pages.length}) Tj ET`;
|
|
100
|
+
const content = [...ops, foot].join('\n');
|
|
101
|
+
const c = add(`<< /Length ${Buffer.byteLength(content, 'latin1')} >>\nstream\n${content}\nendstream`);
|
|
102
|
+
const annots = this.links[i].map((l) => add(`<< /Type /Annot /Subtype /Link /Rect [${l.rect.map((n) => n.toFixed(1)).join(' ')}] /Border [0 0 0] /A << /S /URI /URI (${esc(ansi(l.url))}) >> >>`));
|
|
103
|
+
kids.push(add(`<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${W} ${H}] /Resources << /Font << /F1 ${f1} 0 R /F2 ${f2} 0 R /F3 ${f3} 0 R >> >> /Contents ${c} 0 R${annots.length ? ` /Annots [${annots.map((a) => `${a} 0 R`).join(' ')}]` : ''} >>`));
|
|
104
|
+
});
|
|
105
|
+
objs[1] = `<< /Type /Pages /Kids [${kids.map((k) => `${k} 0 R`).join(' ')}] /Count ${kids.length} >>`;
|
|
106
|
+
add('<< /Producer (Oculon) /Title (Oculon report) >>');
|
|
107
|
+
return Buffer.from(rebuild(objs), 'latin1');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function rebuild(objs) {
|
|
111
|
+
let out = '%PDF-1.4\n%\xe2\xe3\xcf\xd3\n';
|
|
112
|
+
const offsets = [];
|
|
113
|
+
objs.forEach((o, i) => {
|
|
114
|
+
offsets.push(Buffer.byteLength(out, 'latin1'));
|
|
115
|
+
out += `${i + 1} 0 obj\n${o}\nendobj\n`;
|
|
116
|
+
});
|
|
117
|
+
const xref = Buffer.byteLength(out, 'latin1');
|
|
118
|
+
out += `xref\n0 ${objs.length + 1}\n0000000000 65535 f \n${offsets.map((o) => `${String(o).padStart(10, '0')} 00000 n \n`).join('')}`;
|
|
119
|
+
out += `trailer\n<< /Size ${objs.length + 1} /Root 1 0 R /Info ${objs.length} 0 R >>\nstartxref\n${xref}\n%%EOF\n`;
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
/** Render blocks to a PDF file. `footer` is printed on every page. */
|
|
123
|
+
export function renderPdf(blocks, footer) {
|
|
124
|
+
const d = new Doc(footer);
|
|
125
|
+
for (const b of blocks) {
|
|
126
|
+
switch (b.t) {
|
|
127
|
+
case 'title':
|
|
128
|
+
d.text(M, d.y - 10, 'OCULON', 9, 'F2', ACCENT);
|
|
129
|
+
d.y -= 22;
|
|
130
|
+
d.para(b.text, 20, 'F2', INK, 0, 1.25);
|
|
131
|
+
d.y -= 8;
|
|
132
|
+
d.line(d.y);
|
|
133
|
+
d.y -= 6;
|
|
134
|
+
break;
|
|
135
|
+
case 'h':
|
|
136
|
+
d.need(40);
|
|
137
|
+
d.y -= 14;
|
|
138
|
+
d.para(b.text.toUpperCase(), 9.5, 'F2', ACCENT, 0, 1.6);
|
|
139
|
+
d.y -= 2;
|
|
140
|
+
break;
|
|
141
|
+
case 'p':
|
|
142
|
+
d.para(b.text, b.size ?? 10.5, 'F1', b.color ?? INK);
|
|
143
|
+
break;
|
|
144
|
+
case 'mono':
|
|
145
|
+
d.para(b.text, 8.5, 'F3', INK, 0, 1.4);
|
|
146
|
+
break;
|
|
147
|
+
case 'bullets':
|
|
148
|
+
for (const it of b.items) {
|
|
149
|
+
const lines = wrap(it, 10.5, 'F1', CW - 14);
|
|
150
|
+
lines.forEach((l, i) => {
|
|
151
|
+
d.need(15);
|
|
152
|
+
d.y -= 15;
|
|
153
|
+
if (i === 0)
|
|
154
|
+
d.text(M, d.y, '-', 10.5, 'F2', b.color ?? ACCENT);
|
|
155
|
+
d.text(M + 14, d.y, l, 10.5, 'F1');
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
case 'kv':
|
|
160
|
+
for (const [k, v] of b.rows) {
|
|
161
|
+
const lines = wrap(v, 10, 'F1', CW - 150);
|
|
162
|
+
lines.forEach((l, i) => {
|
|
163
|
+
d.need(15);
|
|
164
|
+
d.y -= 15;
|
|
165
|
+
if (i === 0)
|
|
166
|
+
d.text(M, d.y, ansi(k), 9, 'F2', MUTE);
|
|
167
|
+
d.text(M + 150, d.y, l, 10, 'F1');
|
|
168
|
+
});
|
|
169
|
+
d.y -= 3;
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
case 'bar': {
|
|
173
|
+
d.need(48);
|
|
174
|
+
d.y -= 42;
|
|
175
|
+
d.rect(M, d.y, CW, 36, b.color);
|
|
176
|
+
d.text(M + 14, d.y + 22, ansi(b.label), 8, 'F2', [1, 1, 1]);
|
|
177
|
+
d.text(M + 14, d.y + 8, ansi(b.text).slice(0, 70), 14, 'F2', [1, 1, 1]);
|
|
178
|
+
d.y -= 4;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
case 'link': {
|
|
182
|
+
d.need(15);
|
|
183
|
+
d.y -= 15;
|
|
184
|
+
const s = ansi(b.text);
|
|
185
|
+
d.text(M, d.y, s, 10, 'F1', ACCENT);
|
|
186
|
+
d.links[d.pages.length - 1].push({ page: d.pages.length - 1, rect: [M, d.y - 2, M + width(s, 10, 'F1'), d.y + 10], url: b.url });
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case 'table': {
|
|
190
|
+
const xs = b.widths.reduce((a, w, i) => [...a, (a[i - 1] ?? M) + (i ? b.widths[i - 1] : 0)], []).map((x, i) => (i === 0 ? M : x));
|
|
191
|
+
const row = (cells, font, color) => {
|
|
192
|
+
const wrapped = cells.map((c, i) => wrap(c, 8.5, font, b.widths[i] - 6));
|
|
193
|
+
const h = Math.max(...wrapped.map((w) => w.length)) * 11 + 4;
|
|
194
|
+
d.need(h);
|
|
195
|
+
wrapped.forEach((ls, i) => ls.forEach((l, j) => d.text(xs[i], d.y - 11 - j * 11, l, 8.5, font, color)));
|
|
196
|
+
d.y -= h;
|
|
197
|
+
d.line(d.y + 1);
|
|
198
|
+
};
|
|
199
|
+
row(b.head, 'F2', MUTE);
|
|
200
|
+
for (const r of b.rows)
|
|
201
|
+
row(r, 'F1', INK);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case 'gap':
|
|
205
|
+
d.y -= b.h ?? 8;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return d.build();
|
|
210
|
+
}
|
|
211
|
+
export const TONE_RGB = { bad: [0.78, 0.18, 0.24], warn: [0.79, 0.52, 0.06], ok: [0.1, 0.55, 0.35], info: [0.25, 0.32, 0.36] };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One plain verdict from any check result: what it says, how bad, and why. Used by the verdict cards in AI chat
|
|
3
|
+
* apps, PDF reports, "seen before" changes and brief mode, so every check gets them without its own code.
|
|
4
|
+
* Results differ per module; this reads the fields they share (verdict, risk, level, reasons, flags, warnings).
|
|
5
|
+
*/
|
|
6
|
+
export type Tone = 'bad' | 'warn' | 'ok' | 'info';
|
|
7
|
+
export interface Verdict {
|
|
8
|
+
/** What was checked, as shown to people. */
|
|
9
|
+
title: string;
|
|
10
|
+
verdict: string | null;
|
|
11
|
+
tone: Tone;
|
|
12
|
+
risk: number | null;
|
|
13
|
+
points: string[];
|
|
14
|
+
sources: {
|
|
15
|
+
live: number;
|
|
16
|
+
cached: number;
|
|
17
|
+
failed: number;
|
|
18
|
+
names: string[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare function toneOf(verdict: string | null, risk: number | null): Tone;
|
|
22
|
+
/** The verdict of a module result (or the compact form the API returns). */
|
|
23
|
+
export declare function verdictOf(out: unknown, label?: string): Verdict;
|
|
24
|
+
/** What changed between two verdicts of the same target, in plain words. Empty when nothing did. */
|
|
25
|
+
export declare function verdictChanges(before: Verdict, now: Verdict): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Brief mode: a short answer for agents. Verdict, risk, top points, which sources answered, and the check id
|
|
28
|
+
* for the full result. Results without a verdict are trimmed instead (first items of long lists, no long text).
|
|
29
|
+
*/
|
|
30
|
+
export declare function briefOf(out: unknown, extra?: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One plain verdict from any check result: what it says, how bad, and why. Used by the verdict cards in AI chat
|
|
3
|
+
* apps, PDF reports, "seen before" changes and brief mode, so every check gets them without its own code.
|
|
4
|
+
* Results differ per module; this reads the fields they share (verdict, risk, level, reasons, flags, warnings).
|
|
5
|
+
*/
|
|
6
|
+
const BAD = /\b(likely scam|scam|malicious|danger|dangerous|spoof|spoofed|high|critical|not valid|invalid|leaked|likely edited|edited|sanction|sanctioned|honeypot|cannot sell|vulnerable|exploited|unprotected|not protected|fake|fraud)\b/i;
|
|
7
|
+
const WARN = /\b(suspicious|caution|medium|moderate|partly|warn|warning|signs of|unknown|unverified|elevated|risky|check)\b/i;
|
|
8
|
+
const OK = /\b(ok|safe|valid|protected|clean|low|no known|not found|none found|no signs|legit|genuine|active|operational|no recalls)\b/i;
|
|
9
|
+
export function toneOf(verdict, risk) {
|
|
10
|
+
if (verdict) {
|
|
11
|
+
// "no signs of editing", "no known threats": a negated finding is good news, whatever words follow.
|
|
12
|
+
if (/^(no|nothing|none)\b|\b(not found|none found)\b/i.test(verdict.trim()))
|
|
13
|
+
return 'ok';
|
|
14
|
+
if (BAD.test(verdict) && !/\bno\b|not (a )?scam/i.test(verdict))
|
|
15
|
+
return 'bad';
|
|
16
|
+
if (WARN.test(verdict))
|
|
17
|
+
return 'warn';
|
|
18
|
+
if (OK.test(verdict))
|
|
19
|
+
return 'ok';
|
|
20
|
+
}
|
|
21
|
+
if (risk !== null)
|
|
22
|
+
return risk >= 70 ? 'bad' : risk >= 35 ? 'warn' : 'ok';
|
|
23
|
+
return 'info';
|
|
24
|
+
}
|
|
25
|
+
const text = (v) => {
|
|
26
|
+
if (typeof v === 'string')
|
|
27
|
+
return v.trim() || null;
|
|
28
|
+
if (v && typeof v === 'object') {
|
|
29
|
+
const o = v;
|
|
30
|
+
for (const k of ['text', 'title', 'reason', 'message', 'detail', 'name'])
|
|
31
|
+
if (typeof o[k] === 'string' && o[k].trim())
|
|
32
|
+
return o[k].trim();
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
function pickVerdict(x) {
|
|
37
|
+
for (const k of ['verdict', 'status', 'level', 'grade', 'assessment']) {
|
|
38
|
+
const v = x[k];
|
|
39
|
+
if (typeof v === 'string' && v.trim() && v.length < 60)
|
|
40
|
+
return k === 'level' && !/risk/i.test(v) ? `${v} risk` : v.trim();
|
|
41
|
+
}
|
|
42
|
+
if (typeof x.risk === 'string' && x.risk.length < 30)
|
|
43
|
+
return `${x.risk} risk`;
|
|
44
|
+
if (typeof x.valid === 'boolean')
|
|
45
|
+
return x.valid ? 'valid' : 'not valid';
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
function pickRisk(x) {
|
|
49
|
+
for (const k of ['risk', 'riskScore', 'score']) {
|
|
50
|
+
const v = x[k];
|
|
51
|
+
if (typeof v === 'number' && Number.isFinite(v) && v >= 0 && v <= 100)
|
|
52
|
+
return Math.round(v);
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
function pickPoints(x) {
|
|
57
|
+
for (const k of ['reasons', 'flags', 'warnings', 'findings', 'points', 'issues']) {
|
|
58
|
+
const arr = x[k];
|
|
59
|
+
if (Array.isArray(arr) && arr.length) {
|
|
60
|
+
const pts = arr.map(text).filter((t) => Boolean(t));
|
|
61
|
+
if (pts.length)
|
|
62
|
+
return pts.slice(0, 12);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
function sourcesOf(out) {
|
|
68
|
+
const s = { live: 0, cached: 0, failed: 0, names: [] };
|
|
69
|
+
const prov = out?.provenance;
|
|
70
|
+
if (Array.isArray(prov)) {
|
|
71
|
+
for (const p of prov) {
|
|
72
|
+
if (p.status === 'LIVE')
|
|
73
|
+
s.live++;
|
|
74
|
+
else if (p.status === 'CACHED')
|
|
75
|
+
s.cached++;
|
|
76
|
+
else
|
|
77
|
+
s.failed++;
|
|
78
|
+
if (!s.names.includes(p.source))
|
|
79
|
+
s.names.push(p.source);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (prov && typeof prov === 'object' && prov.sources) {
|
|
83
|
+
// The compact { sources: { name: { LIVE: n } } } summary used by the web API and MCP.
|
|
84
|
+
for (const [name, counts] of Object.entries(prov.sources)) {
|
|
85
|
+
s.names.push(name);
|
|
86
|
+
s.live += counts.LIVE ?? 0;
|
|
87
|
+
s.cached += counts.CACHED ?? 0;
|
|
88
|
+
s.failed += (counts.ERROR ?? 0) + (counts.UNAVAILABLE ?? 0);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return s;
|
|
92
|
+
}
|
|
93
|
+
/** The verdict of a module result (or the compact form the API returns). */
|
|
94
|
+
export function verdictOf(out, label) {
|
|
95
|
+
const o = (out ?? {});
|
|
96
|
+
const x = (o.result && typeof o.result === 'object' && !Array.isArray(o.result) ? o.result : o);
|
|
97
|
+
const verdict = pickVerdict(x);
|
|
98
|
+
const risk = pickRisk(x);
|
|
99
|
+
let points = pickPoints(x);
|
|
100
|
+
if (!points.length && Array.isArray(o.signals))
|
|
101
|
+
points = o.signals.map((s) => text(s)).filter((t) => Boolean(t)).slice(0, 8);
|
|
102
|
+
const title = label ?? (typeof o.input === 'string' && o.input ? o.input : typeof x.input === 'string' ? x.input : '');
|
|
103
|
+
return { title: title.slice(0, 160), verdict, tone: toneOf(verdict, risk), risk, points, sources: sourcesOf(o) };
|
|
104
|
+
}
|
|
105
|
+
/** What changed between two verdicts of the same target, in plain words. Empty when nothing did. */
|
|
106
|
+
export function verdictChanges(before, now) {
|
|
107
|
+
const out = [];
|
|
108
|
+
if ((before.verdict ?? '') !== (now.verdict ?? ''))
|
|
109
|
+
out.push(`verdict: ${before.verdict ?? 'none'} -> ${now.verdict ?? 'none'}`);
|
|
110
|
+
if (before.risk !== now.risk && before.risk !== null && now.risk !== null)
|
|
111
|
+
out.push(`risk ${before.risk} -> ${now.risk}`);
|
|
112
|
+
const was = new Set(before.points), is = new Set(now.points);
|
|
113
|
+
for (const p of now.points)
|
|
114
|
+
if (!was.has(p))
|
|
115
|
+
out.push(`new: ${p}`);
|
|
116
|
+
for (const p of before.points)
|
|
117
|
+
if (!is.has(p))
|
|
118
|
+
out.push(`gone: ${p}`);
|
|
119
|
+
return out.slice(0, 12);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Brief mode: a short answer for agents. Verdict, risk, top points, which sources answered, and the check id
|
|
123
|
+
* for the full result. Results without a verdict are trimmed instead (first items of long lists, no long text).
|
|
124
|
+
*/
|
|
125
|
+
export function briefOf(out, extra = {}) {
|
|
126
|
+
const v = verdictOf(out);
|
|
127
|
+
if (v.verdict || v.risk !== null) {
|
|
128
|
+
return {
|
|
129
|
+
...(v.title ? { target: v.title } : {}),
|
|
130
|
+
verdict: v.verdict,
|
|
131
|
+
...(v.risk !== null ? { risk: v.risk } : {}),
|
|
132
|
+
points: v.points.slice(0, 5),
|
|
133
|
+
sources: `${v.sources.live} live, ${v.sources.cached} cached, ${v.sources.failed} failed${v.sources.names.length ? ` (${v.sources.names.slice(0, 8).join(', ')})` : ''}`,
|
|
134
|
+
...extra,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return { ...trim(out, 0), ...extra };
|
|
138
|
+
}
|
|
139
|
+
function trim(v, depth) {
|
|
140
|
+
if (typeof v === 'string')
|
|
141
|
+
return v.length > 280 ? `${v.slice(0, 277)}...` : v;
|
|
142
|
+
if (Array.isArray(v)) {
|
|
143
|
+
const head = v.slice(0, 5).map((x) => trim(x, depth + 1));
|
|
144
|
+
return v.length > 5 ? [...head, `(${v.length - 5} more)`] : head;
|
|
145
|
+
}
|
|
146
|
+
if (v && typeof v === 'object') {
|
|
147
|
+
if (depth > 3)
|
|
148
|
+
return '(...)';
|
|
149
|
+
const o = {};
|
|
150
|
+
for (const [k, x] of Object.entries(v)) {
|
|
151
|
+
if (k === 'provenance' && x && typeof x === 'object' && !Array.isArray(x)) {
|
|
152
|
+
o.sources = Object.keys(x.sources ?? {}).join(', ');
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (k === 'provenance' && Array.isArray(x)) {
|
|
156
|
+
o.sources = [...new Set(x.map((p) => p.source))].join(', ');
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
o[k] = trim(x, depth + 1);
|
|
160
|
+
}
|
|
161
|
+
return o;
|
|
162
|
+
}
|
|
163
|
+
return v;
|
|
164
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -256,6 +256,28 @@ export declare class Oculon {
|
|
|
256
256
|
}): Promise<ModuleResult<import("./modules/iban.js").IbanCheck>>;
|
|
257
257
|
/** Raw email headers: SPF, DKIM and DMARC results, the delivery path, the origin IP and spoofing signs. */
|
|
258
258
|
headerCheck(rawHeaders: string): Promise<ModuleResult<import("./modules/headers.js").HeaderReport>>;
|
|
259
|
+
/** Was this invoice, bank statement or screenshot edited? PDF, JPEG or PNG bytes; IBANs in the text are checked. */
|
|
260
|
+
docCheck(file: Buffer, name?: string): Promise<ModuleResult<import("./modules/doc.js").DocResult>>;
|
|
261
|
+
/** Run a check and keep it: returns the value plus a check id, a replay link and what changed since the last check of the same target. */
|
|
262
|
+
recordCheck<T>(kind: string, target: string, run: () => Promise<T>, opts?: {
|
|
263
|
+
label?: string;
|
|
264
|
+
}): Promise<{
|
|
265
|
+
value: T;
|
|
266
|
+
check: import("./modules/checks.js").CheckMeta;
|
|
267
|
+
}>;
|
|
268
|
+
/** A stored check: verdict, every source call it made (the replay log) and the full result. */
|
|
269
|
+
check(id: string): import("./modules/checks.js").CheckRecord | null;
|
|
270
|
+
/** Earlier checks of the same target as check `id`, newest first. */
|
|
271
|
+
checkHistory(id: string, limit?: number): {
|
|
272
|
+
id: string;
|
|
273
|
+
at: string;
|
|
274
|
+
verdict: string | null;
|
|
275
|
+
risk: number | null;
|
|
276
|
+
}[];
|
|
277
|
+
/** One stored check as a PDF report. */
|
|
278
|
+
checkPdf(id: string, baseUrl?: string): Buffer<ArrayBufferLike> | null;
|
|
279
|
+
/** Which sources are up, slow or down: live calls of the last `hours`. */
|
|
280
|
+
sourceStatus(hours?: number): import("./core/calls.js").SourceStatus[];
|
|
259
281
|
/** Lookalike domains of a brand that exist in DNS, and new certificates naming the brand (crt.sh). */
|
|
260
282
|
lookalikes(domain: string): Promise<ModuleResult<import("./modules/lookalike.js").LookalikeReport>>;
|
|
261
283
|
/** Can this token be sold? Buy and sell simulation with taxes (honeypot.is): Ethereum, BNB Chain, Base. */
|
package/dist/index.js
CHANGED
|
@@ -71,6 +71,10 @@ import { breaches, passwordCheck, pwnedRange } from './modules/breach.js';
|
|
|
71
71
|
import { phoneCheck } from './modules/phone.js';
|
|
72
72
|
import { ibanCheck } from './modules/iban.js';
|
|
73
73
|
import { headerCheck } from './modules/headers.js';
|
|
74
|
+
import { docCheck } from './modules/doc.js';
|
|
75
|
+
import { checkHistory, getCheck, recordCheck } from './modules/checks.js';
|
|
76
|
+
import { sourceStatus } from './core/calls.js';
|
|
77
|
+
import { reportPdf } from './report-pdf.js';
|
|
74
78
|
import { lookalikes } from './modules/lookalike.js';
|
|
75
79
|
import { honeypotCheck } from './modules/honeypot.js';
|
|
76
80
|
import { addressCheck } from './modules/address.js';
|
|
@@ -404,6 +408,31 @@ export class Oculon {
|
|
|
404
408
|
headerCheck(rawHeaders) {
|
|
405
409
|
return headerCheck(this.ctx, rawHeaders);
|
|
406
410
|
}
|
|
411
|
+
/** Was this invoice, bank statement or screenshot edited? PDF, JPEG or PNG bytes; IBANs in the text are checked. */
|
|
412
|
+
docCheck(file, name) {
|
|
413
|
+
return docCheck(this.ctx, file, name);
|
|
414
|
+
}
|
|
415
|
+
/** Run a check and keep it: returns the value plus a check id, a replay link and what changed since the last check of the same target. */
|
|
416
|
+
recordCheck(kind, target, run, opts = {}) {
|
|
417
|
+
return recordCheck(this.ctx, kind, target, run, opts);
|
|
418
|
+
}
|
|
419
|
+
/** A stored check: verdict, every source call it made (the replay log) and the full result. */
|
|
420
|
+
check(id) {
|
|
421
|
+
return getCheck(this.ctx, id);
|
|
422
|
+
}
|
|
423
|
+
/** Earlier checks of the same target as check `id`, newest first. */
|
|
424
|
+
checkHistory(id, limit = 10) {
|
|
425
|
+
return checkHistory(this.ctx, id, limit);
|
|
426
|
+
}
|
|
427
|
+
/** One stored check as a PDF report. */
|
|
428
|
+
checkPdf(id, baseUrl) {
|
|
429
|
+
const c = getCheck(this.ctx, id);
|
|
430
|
+
return c ? reportPdf(c, checkHistory(this.ctx, id), baseUrl) : null;
|
|
431
|
+
}
|
|
432
|
+
/** Which sources are up, slow or down: live calls of the last `hours`. */
|
|
433
|
+
sourceStatus(hours = 24) {
|
|
434
|
+
return sourceStatus(this.ctx.store, hours);
|
|
435
|
+
}
|
|
407
436
|
/** Lookalike domains of a brand that exist in DNS, and new certificates naming the brand (crt.sh). */
|
|
408
437
|
lookalikes(domain) {
|
|
409
438
|
return lookalikes(this.ctx, domain);
|