@lintsure/core 0.3.1 → 0.3.3

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.
@@ -11,7 +11,7 @@ export { rules };
11
11
  export * from "./guidance.js";
12
12
  export { toAssessmentHtml } from "./assessment.js";
13
13
  export * from "./knowledge/index.js";
14
- export declare const RULES_VERSION = "0.3.1";
14
+ export declare const RULES_VERSION = "0.3.3";
15
15
  /** Shown with every result, in every interface. Lintsure prepares; people decide. */
16
16
  export declare const DISCLAIMER: string;
17
17
  /** What a report must never be read as. Used in the report and by the MCP server. */
package/dist/src/index.js CHANGED
@@ -17,7 +17,7 @@ export { rules };
17
17
  export * from "./guidance.js";
18
18
  export { toAssessmentHtml } from "./assessment.js";
19
19
  export * from "./knowledge/index.js";
20
- export const RULES_VERSION = "0.3.1";
20
+ export const RULES_VERSION = "0.3.3";
21
21
  /** Shown with every result, in every interface. Lintsure prepares; people decide. */
22
22
  export const DISCLAIMER = "Lintsure is a readiness tool, not an audit, a certification or legal advice. " +
23
23
  "Its rules reflect our reading of the publicly available text of each framework, and they check code only. " +
@@ -89,5 +89,5 @@ export const owaspTop10 = {
89
89
  "Lintsure reads one line or one file at a time. Data passed through helpers in other files won't be followed, so some problems will be missed.",
90
90
  "Saying an app is 'OWASP compliant' isn't meaningful. Describe what was checked and what wasn't.",
91
91
  ],
92
- checkedOn: "2026-11-09",
92
+ checkedOn: "2026-11-08",
93
93
  };
@@ -59,7 +59,7 @@ export const soc2 = {
59
59
  "A SOC 2 report is about your controls, not a pass or fail certificate. Exceptions are normal and get described.",
60
60
  "Type I looks at one day. Type II covers a period, often 3 to 12 months, so start collecting evidence early.",
61
61
  "Using AI in your service can bring AI-specific risks into scope. Auditors may ask how you oversee it.",
62
- "The AICPA has proposed updated criteria. Check which version your auditor uses.",
62
+ "The AICPA published a draft of updated criteria in October 2026. It is open for comment until 15 January 2027 and, if approved, would apply from engagements starting on or after 31 December 2027. The criterion numbers in Lintsure follow the current criteria. Check which version your auditor uses.",
63
63
  ],
64
- checkedOn: "2026-11-07",
64
+ checkedOn: "2026-11-09",
65
65
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lintsure/core",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Lintsure engine: rules, framework knowledge and reports for readiness checks of AI-written code. Not an audit or legal advice.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -1,33 +0,0 @@
1
- /** Personal data fields, by the names code usually gives them. Order matters: first match wins. */
2
- export declare const FIELDS: [string, RegExp][];
3
- /** Destinations, grouped so the map stays readable. First match wins. */
4
- export declare const DESTINATIONS: {
5
- group: string;
6
- name: string;
7
- test: RegExp;
8
- }[];
9
- export interface DataFlow {
10
- field: string;
11
- group: string;
12
- destination: string;
13
- file: string;
14
- line: number;
15
- }
16
- export interface DataMap {
17
- filesRead: number;
18
- flows: DataFlow[];
19
- /** Fields seen anywhere in code, even when no destination was found on the same line. */
20
- fieldsSeen: string[];
21
- }
22
- /** The text of a call that starts on lines[i]: up to the closing bracket, at most 15 lines. */
23
- export declare function callSpan(lines: string[], i: number): string;
24
- /** Pure: the flows in one call (the line where a destination starts, plus the rest of that call). */
25
- export declare function flowsInLine(text: string, span?: string): {
26
- field: string;
27
- group: string;
28
- destination: string;
29
- }[];
30
- export declare function buildDataMap(root: string): Promise<DataMap>;
31
- export declare function toDataMapMarkdown(m: DataMap): string;
32
- /** A self-contained HTML page: fields on the left, destinations on the right, a line for each flow. */
33
- export declare function toDataMapHtml(m: DataMap, project: string): string;
@@ -1,169 +0,0 @@
1
- // Data map: where personal data goes in your code. For each line that mentions a personal data field
2
- // and a destination (logs, analytics, a database, an email or payment provider, an AI model...),
3
- // it records an edge: field → destination, with the file and line. Runs locally, never sends code.
4
- // It reads each call up to its closing bracket: data passed through variables or helpers in other files is missed.
5
- import { readFile } from "node:fs/promises";
6
- import { relative, sep, extname } from "node:path";
7
- import { listFiles, readConfig } from "./index.js";
8
- const CODE = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".py"]);
9
- /** Personal data fields, by the names code usually gives them. Order matters: first match wins. */
10
- export const FIELDS = [
11
- ["Email", /\b\w*e-?mail\w*\b/i],
12
- ["Phone", /\b\w*(phone|mobile|msisdn)\w*\b/i],
13
- ["Password", /\b\w*(password|passwd)\w*\b/i],
14
- ["Full name", /\b(full_?name|first_?name|last_?name|given_?name|family_?name|display_?name|username|user_?name)\b/i],
15
- ["Address", /\b(street|address_?line\d?|postcode|post_?code|zip_?code|billing_?address|shipping_?address|home_?address)\b/i],
16
- ["Date of birth", /\b(dob|date_?of_?birth|birth_?date|birthday)\b/i],
17
- ["Government ID", /\b(ssn|social_?security|passport\w*|national_?id|tax_?id|pesel|nin)\b/i],
18
- ["Payment card", /\b(card_?number|credit_?card|cc_?number|cvv|cvc|iban)\b/i],
19
- ["IP address", /\b(ip_?address|remote_?addr|client_?ip|x-forwarded-for|req\.ip)\b/i],
20
- ["Location", /\b(latitude|longitude|geo_?location|gps)\b/i],
21
- ["Health data", /\b(diagnosis|medical\w*|health_?\w+|prescription|blood_?type|mrn)\b/i],
22
- ];
23
- /** Destinations, grouped so the map stays readable. First match wins. */
24
- export const DESTINATIONS = [
25
- { group: "Logs", name: "Application logs", test: /\b(console\.(log|info|warn|error|debug)|logger\.\w+|log\.(info|warn|error|debug)|logging\.\w+)\s*\(/ },
26
- { group: "Analytics", name: "PostHog", test: /\bposthog\.\w+\(/i },
27
- { group: "Analytics", name: "Segment", test: /\b(analytics|segment)\.(identify|track|page)\(/ },
28
- { group: "Analytics", name: "Mixpanel", test: /\bmixpanel\.\w+/i },
29
- { group: "Analytics", name: "Amplitude", test: /\bamplitude\.\w+/i },
30
- { group: "Analytics", name: "Google Analytics", test: /\b(gtag|ga)\(/ },
31
- { group: "Analytics", name: "Intercom", test: /\bIntercom\(|\bintercom\.\w+/ },
32
- { group: "Error tracking", name: "Sentry", test: /\bSentry\.(setUser|captureException|captureMessage|setContext)\(/ },
33
- { group: "AI model", name: "OpenAI", test: /\bopenai\.(chat|responses|completions|embeddings)\b/i },
34
- { group: "AI model", name: "Anthropic", test: /\banthropic\.messages\b|\bclient\.messages\.create\(/i },
35
- { group: "AI model", name: "AI model", test: /\b(generateText|streamText|generateObject)\(/ },
36
- { group: "Email", name: "Resend", test: /\bresend\.emails\.send\(/i },
37
- { group: "Email", name: "SendGrid", test: /\bsgMail\.send\(|\bsendgrid\b/i },
38
- { group: "Email", name: "Postmark", test: /\bpostmark\b/i },
39
- { group: "Email", name: "Email (SMTP)", test: /\b(transporter|nodemailer)\.sendMail\(|\bsend_mail\(/ },
40
- { group: "Payments", name: "Stripe", test: /\bstripe\.(customers|checkout|paymentIntents|subscriptions|invoices)\b/i },
41
- { group: "Storage", name: "File storage", test: /\b(s3|r2|bucket|storage)\.(upload|putObject|put|from)\(|\bPutObjectCommand\b/i },
42
- { group: "Database", name: "Database", test: /\b(prisma\.\w+\.(create|update|upsert)|\.insert(One|Many)?\(|\.create\(|\.save\(|INSERT INTO|UPDATE \w+ SET|db\.(query|execute)\(|supabase\.from\()/i },
43
- { group: "Browser storage", name: "Browser storage", test: /\b(localStorage|sessionStorage)\.setItem\(|document\.cookie\s*=/ },
44
- { group: "Outside API", name: "Outside API", test: /\b(fetch|axios(\.(post|put|patch))?|requests\.(post|put|patch)|httpx\.(post|put))\s*\(/ },
45
- ];
46
- /** Known services, named from the URL an outside call goes to. */
47
- const HOSTS = [
48
- [/api\.resend\.com/, "Email", "Resend"], [/api\.sendgrid\.com/, "Email", "SendGrid"], [/api\.postmarkapp\.com/, "Email", "Postmark"],
49
- [/api\.mailgun\.net/, "Email", "Mailgun"], [/api\.stripe\.com/, "Payments", "Stripe"], [/api\.openai\.com/, "AI model", "OpenAI"],
50
- [/api\.anthropic\.com/, "AI model", "Anthropic"], [/hooks\.slack\.com|slack\.com\/api/, "Messaging", "Slack"],
51
- [/api\.hubapi\.com/, "CRM", "HubSpot"], [/api\.airtable\.com/, "Database", "Airtable"], [/googleapis\.com/, "Outside API", "Google APIs"],
52
- ];
53
- /** Drops plain text inside quotes (keeping template ${...} parts), so "Enter your email" isn't counted. */
54
- const codeOnly = (l) => l.replace(/(["'`])(?:\\.|(?!\1).)*\1/g, (s) => (s.match(/\{[^}]*\}/g) ?? []).join(" "));
55
- /** The text of a call that starts on lines[i]: up to the closing bracket, at most 15 lines. */
56
- export function callSpan(lines, i) {
57
- let depth = 0, out = "";
58
- for (let j = i; j < Math.min(lines.length, i + 15); j++) {
59
- out += lines[j] + "\n";
60
- for (const ch of codeOnly(lines[j])) {
61
- if (ch === "(" || ch === "{" || ch === "[")
62
- depth++;
63
- else if (ch === ")" || ch === "}" || ch === "]")
64
- depth--;
65
- }
66
- if (depth <= 0 && j > i - 1)
67
- break;
68
- }
69
- return out;
70
- }
71
- /** Pure: the flows in one call (the line where a destination starts, plus the rest of that call). */
72
- export function flowsInLine(text, span = text) {
73
- const dest = DESTINATIONS.find((d) => d.test.test(text));
74
- if (!dest)
75
- return [];
76
- const host = dest.name === "Outside API" ? HOSTS.find(([re]) => re.test(span)) : undefined;
77
- const named = host ? { group: host[1], name: host[2] } : { group: dest.group, name: dest.name };
78
- const code = codeOnly(span);
79
- return FIELDS.filter(([, re]) => re.test(code)).map(([field]) => ({ field, group: named.group, destination: named.name }));
80
- }
81
- export async function buildDataMap(root) {
82
- const { ignore } = await readConfig(root);
83
- const flows = [];
84
- const seen = new Set();
85
- let filesRead = 0;
86
- for (const abs of await listFiles(root, ignore)) {
87
- if (!CODE.has(extname(abs)))
88
- continue;
89
- const buf = await readFile(abs);
90
- if (buf.length > 1_000_000 || buf.includes(0))
91
- continue;
92
- const lines = buf.toString("utf8").split(/\r?\n/);
93
- if (lines.some((l) => l.length > 1000))
94
- continue; // minified or generated
95
- filesRead++;
96
- const file = relative(root, abs).split(sep).join("/");
97
- lines.forEach((text, i) => {
98
- const code = codeOnly(text);
99
- for (const [name, re] of FIELDS)
100
- if (re.test(code))
101
- seen.add(name);
102
- if (DESTINATIONS.some((d) => d.test.test(text)))
103
- for (const f of flowsInLine(text, callSpan(lines, i)))
104
- flows.push({ ...f, file, line: i + 1 });
105
- });
106
- }
107
- return { filesRead, flows, fieldsSeen: FIELDS.map(([n]) => n).filter((n) => seen.has(n)) };
108
- }
109
- const esc = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
110
- const NOTE = "This map reads code call by call. It shows where a personal data field appears inside a call to a destination. Data passed through variables, helpers or other files may be missing, and some lines may be listed that don't send personal data. Check each one. It is a starting point for your record of processing, not the record itself.";
111
- export function toDataMapMarkdown(m) {
112
- const byDest = new Map();
113
- for (const f of m.flows)
114
- byDest.set(`${f.group} · ${f.destination}`, [...(byDest.get(`${f.group} · ${f.destination}`) ?? []), f]);
115
- return [
116
- "# Lintsure data map", "",
117
- `${m.flows.length} place${m.flows.length === 1 ? "" : "s"} where personal data reaches a destination, in ${m.filesRead} files read.`, "",
118
- `> ${NOTE}`, "",
119
- ...[...byDest].flatMap(([d, fl]) => [`## ${d}`, "", ...fl.map((f) => `- **${f.field}** · \`${f.file}:${f.line}\``), ""]),
120
- `Personal data fields seen in code: ${m.fieldsSeen.join(", ") || "none"}.`, "",
121
- ].join("\n");
122
- }
123
- /** A self-contained HTML page: fields on the left, destinations on the right, a line for each flow. */
124
- export function toDataMapHtml(m, project) {
125
- const fields = [...new Set(m.flows.map((f) => f.field))];
126
- const dests = [...new Set(m.flows.map((f) => `${f.group}|${f.destination}`))];
127
- const rowH = 54, top = 60, h = Math.max(fields.length, dests.length) * rowH + top + 30, w = 900;
128
- const fy = (i) => top + i * rowH + (Math.max(0, dests.length - fields.length) * rowH) / 2;
129
- const dy = (i) => top + i * rowH + (Math.max(0, fields.length - dests.length) * rowH) / 2;
130
- const pairs = new Map();
131
- for (const f of m.flows) {
132
- const k = `${f.field}→${f.group}|${f.destination}`;
133
- pairs.set(k, [...(pairs.get(k) ?? []), f]);
134
- }
135
- const links = [...pairs].map(([k, fl]) => {
136
- const [field, dest] = k.split("→");
137
- const y1 = fy(fields.indexOf(field)) + 18, y2 = dy(dests.indexOf(dest)) + 18;
138
- return `<path d="M260 ${y1} C 450 ${y1}, 450 ${y2}, 640 ${y2}" class="link" style="stroke-width:${Math.min(8, 1.5 + fl.length)}"><title>${esc(field)} → ${esc(dest.split("|")[1])}: ${fl.length}</title></path>`;
139
- }).join("");
140
- const box = (x, y, label, sub, cls) => `<g class="${cls}"><rect x="${x}" y="${y}" width="240" height="36" rx="9"/><text x="${x + 14}" y="${y + 23}">${esc(label)}</text>${sub ? `<text x="${x + 226}" y="${y + 23}" text-anchor="end" class="sub">${esc(sub)}</text>` : ""}</g>`;
141
- const count = (pred) => String(m.flows.filter(pred).length);
142
- const svg = `<svg viewBox="0 0 ${w} ${h}" width="100%" role="img" aria-label="Data map">
143
- <text x="20" y="34" class="head">Personal data</text><text x="880" y="34" class="head" text-anchor="end">Where it goes</text>
144
- ${links}
145
- ${fields.map((f, i) => box(20, fy(i), f, count((x) => x.field === f), "field")).join("")}
146
- ${dests.map((d, i) => { const [g, n] = d.split("|"); return box(640, dy(i), n, g === n ? "" : g, "dest"); }).join("")}
147
- </svg>`;
148
- const rows = m.flows.map((f) => `<tr><td>${esc(f.field)}</td><td>${esc(f.destination)} <span class="g">${esc(f.group)}</span></td><td><code>${esc(f.file)}:${f.line}</code></td></tr>`).join("");
149
- return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
150
- <title>Lintsure data map · ${esc(project)}</title>
151
- <style>
152
- :root{--ink:#141413;--muted:#5E5D59;--faint:#8A8984;--line:#E4E2DD;--canvas:#FBFBF9;--accent:#0B6E4F}
153
- body{margin:0;background:var(--canvas);color:var(--ink);font:15px/1.55 -apple-system,"Segoe UI",Helvetica,Arial,sans-serif}
154
- main{max-width:980px;margin:0 auto;padding:48px 24px 80px}h1{font-size:34px;letter-spacing:-.03em;margin:0}
155
- .lead{color:var(--muted);margin:8px 0 24px}.card{background:#fff;border:1px solid var(--line);border-radius:16px;padding:16px;margin:20px 0}
156
- svg text{font:14px -apple-system,"Segoe UI",Helvetica,Arial,sans-serif;fill:var(--ink)}svg .head{font-size:12px;font-weight:600;letter-spacing:.06em;fill:var(--faint);text-transform:uppercase}
157
- .field rect{fill:#fff;stroke:var(--ink)}.dest rect{fill:#F5F4F1;stroke:var(--line)}svg .sub{fill:var(--faint);font-size:12px}
158
- .link{fill:none;stroke:var(--accent);opacity:.35}.link:hover{opacity:.9}
159
- table{width:100%;border-collapse:collapse;font-size:14px}td,th{border-bottom:1px solid var(--line);padding:8px 6px;text-align:left}th{font-size:12px;color:var(--faint);text-transform:uppercase;letter-spacing:.05em}
160
- code{font:13px ui-monospace,Menlo,Consolas,monospace}.g{color:var(--faint);font-size:12px}.note{font-size:13px;color:var(--muted);border-left:2px solid var(--line);padding-left:12px}
161
- </style></head><body><main>
162
- <h1>Where personal data goes</h1>
163
- <p class="lead">${esc(project)} · ${m.flows.length} place${m.flows.length === 1 ? "" : "s"} where personal data reaches a destination, in ${m.filesRead} files read.</p>
164
- ${m.flows.length ? `<div class="card">${svg}</div>` : `<p>No flows found by the current patterns. That doesn't mean there are none.</p>`}
165
- <p class="note">${esc(NOTE)}</p>
166
- ${m.flows.length ? `<h2>Every flow</h2><table><tr><th>Field</th><th>Destination</th><th>Where</th></tr>${rows}</table>` : ""}
167
- <p class="note">Made by Lintsure, an open-source readiness tool. It runs on your machine and never sends your code anywhere. Not legal advice.</p>
168
- </main></body></html>`;
169
- }