pnpm-shield 1.0.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.
@@ -0,0 +1,123 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * selector.js — Raw TTY interactive list selector (no external deps).
5
+ *
6
+ * Redraw strategy:
7
+ * - First render: write content normally.
8
+ * - Subsequent renders: move cursor up exactly (items + 4) lines,
9
+ * then erase to end of screen with \x1b[J, then redraw.
10
+ *
11
+ * This avoids the \x1b[s / \x1b[u save-restore approach, which breaks
12
+ * when the terminal scrolls (saved position drifts off-screen).
13
+ *
14
+ * showSelector(items, opts) → Promise<number[]>
15
+ */
16
+
17
+ const c = require('./colors');
18
+
19
+ function showSelector(items, opts = {}) {
20
+ const { multi = false, title = 'Select an item:', initialCursor = 0 } = opts;
21
+
22
+ // Lines written per render:
23
+ // 1 blank line (\n before title)
24
+ // 1 title line (title\n)
25
+ // N item lines (one per item)
26
+ // 1 blank line (\n before hint)
27
+ // 1 hint line (hint\n)
28
+ // ──────────────────────
29
+ // N + 4 total
30
+ const totalLines = items.length + 4;
31
+
32
+ return new Promise((resolve) => {
33
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
34
+ resolve([]);
35
+ return;
36
+ }
37
+
38
+ const selected = new Set();
39
+ let cursor = Math.min(Math.max(0, initialCursor), items.length - 1);
40
+ let rendered = false;
41
+
42
+ function render() {
43
+ if (rendered) {
44
+ // Move up to the first line we wrote, erase everything below
45
+ process.stdout.write(`\x1b[${totalLines}A\x1b[J`);
46
+ }
47
+ rendered = true;
48
+
49
+ // Blank + title
50
+ process.stdout.write(`\n ${c.bold}${title}${c.reset}\n`);
51
+
52
+ // Items
53
+ for (let i = 0; i < items.length; i++) {
54
+ const isCursor = i === cursor;
55
+ const isChecked = selected.has(i);
56
+
57
+ const arrow = isCursor ? `${c.cyan}❯${c.reset}` : ' ';
58
+ let mark;
59
+ if (multi) {
60
+ mark = isChecked ? `${c.green}◉${c.reset}` : `${c.dim}○${c.reset}`;
61
+ } else {
62
+ mark = isCursor ? `${c.cyan}◉${c.reset}` : `${c.dim}○${c.reset}`;
63
+ }
64
+ const label = isCursor
65
+ ? `${c.bold}${items[i].label}${c.reset}`
66
+ : `${c.dim}${items[i].label}${c.reset}`;
67
+
68
+ process.stdout.write(` ${arrow} ${mark} ${label}\n`);
69
+ }
70
+
71
+ // Blank + hint with position counter
72
+ const pos = `${c.dim}${cursor + 1} / ${items.length}${c.reset}`;
73
+ if (multi) {
74
+ process.stdout.write(`\n ${c.dim}↑↓ navigate Space select/deselect Enter confirm q cancel ${c.reset}${pos}\n`);
75
+ } else {
76
+ process.stdout.write(`\n ${c.dim}↑↓ navigate Enter open q cancel ${c.reset}${pos}\n`);
77
+ }
78
+ }
79
+
80
+ // Hide cursor to prevent flicker
81
+ process.stdout.write('\x1b[?25l');
82
+ render();
83
+
84
+ process.stdin.setRawMode(true);
85
+ process.stdin.resume();
86
+ process.stdin.setEncoding('utf8');
87
+
88
+ function done(indices) {
89
+ process.stdout.write('\x1b[?25h'); // restore cursor
90
+ process.stdin.setRawMode(false);
91
+ process.stdin.pause();
92
+ process.stdin.removeListener('data', onData);
93
+ resolve(indices);
94
+ }
95
+
96
+ function onData(key) {
97
+ if (key === '\x03') { process.stdout.write('\x1b[?25h'); process.exit(0); }
98
+ if (key === 'q' || key === '\x1b') { done([]); return; }
99
+
100
+ if (key === '\x1b[A') { // up
101
+ cursor = (cursor - 1 + items.length) % items.length;
102
+ render(); return;
103
+ }
104
+ if (key === '\x1b[B') { // down
105
+ cursor = (cursor + 1) % items.length;
106
+ render(); return;
107
+ }
108
+ if (key === ' ' && multi) { // toggle
109
+ if (selected.has(cursor)) selected.delete(cursor);
110
+ else selected.add(cursor);
111
+ render(); return;
112
+ }
113
+ if (key === '\r' || key === '\n') { // confirm
114
+ done(multi ? [...selected].sort((a, b) => a - b) : [cursor]);
115
+ return;
116
+ }
117
+ }
118
+
119
+ process.stdin.on('data', onData);
120
+ });
121
+ }
122
+
123
+ module.exports = { showSelector };
package/lib/ui.js ADDED
@@ -0,0 +1,117 @@
1
+ 'use strict';
2
+
3
+ const c = require('./colors');
4
+ const { DOCS } = require('./docs');
5
+
6
+ const SEVERITY = {
7
+ CRITICAL: { label: 'CRITICAL', badge: `${'\x1b[41m'}${'\x1b[97m'}${'\x1b[1m'}` },
8
+ HIGH: { label: 'HIGH ', badge: `${'\x1b[38;5;208m'}${'\x1b[1m'}` },
9
+ MEDIUM: { label: 'MEDIUM ', badge: `${'\x1b[33m'}${'\x1b[1m'}` },
10
+ LOW: { label: 'LOW ', badge: `${'\x1b[36m'}` },
11
+ };
12
+
13
+ // ─── Header ───────────────────────────────────────────────────────────────────
14
+ function printHeader(version = '') {
15
+ const ver = version ? ` v${version}` : '';
16
+ console.log('');
17
+ console.log(`${c.bold}${c.cyan}╔══════════════════════════════════════════════════════╗${c.reset}`);
18
+ console.log(`${c.bold}${c.cyan}║${c.reset} ${c.bold}🛡️ pnpm-shield${ver} — Supply Chain Audit${c.reset} ${c.cyan}║${c.reset}`);
19
+ console.log(`${c.bold}${c.cyan}╚══════════════════════════════════════════════════════╝${c.reset}`);
20
+ console.log(`${c.dim} Project : ${process.cwd()}`);
21
+ console.log(` Node : ${process.version} Platform: ${process.platform}${c.reset}`);
22
+ }
23
+
24
+ // ─── Section header ───────────────────────────────────────────────────────────
25
+ function sectionHeader(icon, title) {
26
+ const line = '─'.repeat(54 - title.length);
27
+ console.log(`\n${c.bold}${c.cyan} ${icon} ${title} ${line}${c.reset}`);
28
+ }
29
+
30
+ // ─── Single result row ────────────────────────────────────────────────────────
31
+ function printCheck(r, idx) {
32
+ const sev = SEVERITY[r.severity] || SEVERITY.LOW;
33
+ const badge = `${sev.badge} ${r.severity.padEnd(8)} ${c.reset}`;
34
+ const num = `${c.dim}[${String(idx + 1).padStart(2)}]${c.reset}`;
35
+
36
+ if (r.status === 'pass') {
37
+ const detail = r.detail ? ` ${c.dim}${r.detail}${c.reset}` : '';
38
+ console.log(`${num} ${c.green}✅${c.reset} ${badge} ${r.label}${detail}`);
39
+ } else if (r.status === 'fail') {
40
+ console.log(`${num} ${c.red}❌${c.reset} ${badge} ${c.bold}${r.label}${c.reset}`);
41
+ if (r.tip) console.log(` ${c.yellow}↳ ${r.tip}${c.reset}`);
42
+ } else {
43
+ console.log(`${num} ${c.yellow}⚠️ ${c.reset} ${badge} ${r.label}`);
44
+ if (r.tip) console.log(` ${c.dim}↳ ${r.tip}${c.reset}`);
45
+ }
46
+ }
47
+
48
+ // ─── Doc panel ────────────────────────────────────────────────────────────────
49
+ function printDoc(docKey, checkLabel) {
50
+ const doc = DOCS[docKey];
51
+ if (!doc) {
52
+ console.log(`\n${c.dim} No documentation available for this check.${c.reset}\n`);
53
+ return;
54
+ }
55
+
56
+ const title = doc.title || checkLabel || docKey;
57
+ console.log(`\n${c.bold}${c.cyan}┌─ 📖 ${title}${c.reset}`);
58
+ console.log(`${c.cyan}│${c.reset}`);
59
+
60
+ console.log(`${c.cyan}│${c.reset} ${c.bold}Why it matters${c.reset}`);
61
+ doc.why.split('\n').forEach(l => console.log(`${c.cyan}│${c.reset} ${l}`));
62
+ console.log(`${c.cyan}│${c.reset}`);
63
+
64
+ console.log(`${c.cyan}│${c.reset} ${c.bold}${c.red}Attack vector${c.reset}`);
65
+ doc.attack.split('\n').forEach(l => console.log(`${c.cyan}│${c.reset} ${c.red}${l}${c.reset}`));
66
+ console.log(`${c.cyan}│${c.reset}`);
67
+
68
+ console.log(`${c.cyan}│${c.reset} ${c.bold}${c.green}How to fix${c.reset}`);
69
+ doc.fix.split('\n').forEach(l => console.log(`${c.cyan}│${c.reset} ${c.green}${l}${c.reset}`));
70
+
71
+ if (doc.refs && doc.refs.length > 0) {
72
+ console.log(`${c.cyan}│${c.reset}`);
73
+ console.log(`${c.cyan}│${c.reset} ${c.bold}${c.blue}Official references${c.reset}`);
74
+ doc.refs.forEach(r => {
75
+ console.log(`${c.cyan}│${c.reset} ${c.blue}• ${r.label}${c.reset}`);
76
+ console.log(`${c.cyan}│${c.reset} ${c.dim}${r.url}${c.reset}`);
77
+ });
78
+ }
79
+
80
+ console.log(`${c.cyan}└${'─'.repeat(56)}${c.reset}\n`);
81
+ }
82
+
83
+ // ─── Summary box ──────────────────────────────────────────────────────────────
84
+ function printSummary(results, startMs) {
85
+ const total = results.length;
86
+ const passes = results.filter(r => r.status === 'pass').length;
87
+ const warnings = results.filter(r => r.status === 'warn').length;
88
+ const failures = results.filter(r => r.status === 'fail').length;
89
+ const score = passes + Math.round(warnings * 0.5);
90
+ const scoreMax = total;
91
+ const elapsed = ((Date.now() - startMs) / 1000).toFixed(2);
92
+
93
+ console.log('');
94
+ console.log(`${c.bold}${c.cyan}╔══════════════════════════════════════════════════════╗${c.reset}`);
95
+ console.log(`${c.bold}${c.cyan}║${c.reset}${c.bold} AUDIT SUMMARY ${c.cyan}║${c.reset}`);
96
+ console.log(`${c.bold}${c.cyan}╠══════════════════════════════════════════════════════╣${c.reset}`);
97
+ console.log(`${c.cyan}║${c.reset} Checks run : ${String(total).padEnd(38)}${c.cyan}║${c.reset}`);
98
+ console.log(`${c.cyan}║${c.reset} ${c.green}✅ Passed${c.reset} : ${c.green}${String(passes).padEnd(38)}${c.reset}${c.cyan}║${c.reset}`);
99
+ console.log(`${c.cyan}║${c.reset} ${c.yellow}⚠️ Warnings${c.reset} : ${c.yellow}${String(warnings).padEnd(37)}${c.reset}${c.cyan}║${c.reset}`);
100
+ console.log(`${c.cyan}║${c.reset} ${c.red}❌ Failures${c.reset} : ${c.red}${String(failures).padEnd(38)}${c.reset}${c.cyan}║${c.reset}`);
101
+ console.log(`${c.cyan}║${c.reset} Elapsed : ${String(elapsed + 's').padEnd(38)}${c.cyan}║${c.reset}`);
102
+ console.log(`${c.bold}${c.cyan}╚══════════════════════════════════════════════════════╝${c.reset}`);
103
+
104
+ const pct = score / scoreMax;
105
+ const filled = Math.round(pct * 20);
106
+ const barColor = pct >= 0.85 ? c.green : pct >= 0.65 ? c.yellow : c.red;
107
+ const bar = `${barColor}${'█'.repeat(filled)}${c.dim}${'░'.repeat(20 - filled)}${c.reset}`;
108
+ const gradeStr = pct >= 0.92 ? `${c.green}${c.bold}A+` : pct >= 0.84 ? `${c.green}${c.bold}A ` :
109
+ pct >= 0.76 ? `${c.yellow}${c.bold}B ` : pct >= 0.60 ? `${c.orange}${c.bold}C ` :
110
+ `${c.red}${c.bold}D `;
111
+
112
+ console.log(` Score: ${score}/${scoreMax} Grade: ${gradeStr}${c.reset} [${bar}] ${barColor}${c.bold}${Math.round(pct * 100)}%${c.reset}`);
113
+
114
+ return { passes, warnings, failures, score, scoreMax };
115
+ }
116
+
117
+ module.exports = { printHeader, sectionHeader, printCheck, printDoc, printSummary, SEVERITY };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "pnpm-shield",
3
+ "version": "1.0.0",
4
+ "description": "Supply chain attack protection audit tool for pnpm projects",
5
+ "keywords": [
6
+ "pnpm",
7
+ "security",
8
+ "supply-chain",
9
+ "npm-audit",
10
+ "devops",
11
+ "hardening"
12
+ ],
13
+ "homepage": "https://github.com/manuxstack/pnpm-shield#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/manuxstack/pnpm-shield/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/manuxstack/pnpm-shield.git"
20
+ },
21
+ "license": "MIT",
22
+ "author": "manuxstack",
23
+ "bin": {
24
+ "pnpm-shield": "./pnpm-shield.js",
25
+ "pnpm-check": "./pnpm-shield.js"
26
+ },
27
+ "files": [
28
+ "pnpm-shield.js",
29
+ "lib/"
30
+ ],
31
+ "engines": {
32
+ "node": ">=18"
33
+ }
34
+ }
package/pnpm-shield.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * pnpm-shield — Supply chain attack protection tool.
6
+ *
7
+ * Entry point. All logic lives in lib/.
8
+ * lib/colors.js — ANSI color constants
9
+ * lib/docs.js — Per-check documentation + official references
10
+ * lib/checks.js — Runs all 13 security checks
11
+ * lib/ui.js — Terminal output helpers (header, results, doc panel)
12
+ * lib/selector.js — Raw TTY arrow-key interactive selector
13
+ * lib/fixes.js — Auto-applies selected fixes
14
+ * lib/runner.js — Orchestrates the full audit + interactive menu
15
+ */
16
+
17
+ const { run } = require('./lib/runner');
18
+
19
+ run().catch(err => {
20
+ const c = require('./lib/colors');
21
+ console.error(`\n${c.red}${c.bold}Fatal error:${c.reset} ${c.red}${err.message}${c.reset}\n`);
22
+ process.exit(2);
23
+ });