infrawise 0.1.2 → 0.2.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.
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.log = void 0;
40
+ exports.readAWSProfiles = readAWSProfiles;
41
+ exports.detectAWSRegion = detectAWSRegion;
42
+ exports.detectRepoType = detectRepoType;
43
+ exports.printBanner = printBanner;
44
+ exports.printHeader = printHeader;
45
+ exports.printFinding = printFinding;
46
+ exports.printSummaryBox = printSummaryBox;
47
+ const fs = __importStar(require("fs"));
48
+ const path = __importStar(require("path"));
49
+ const os = __importStar(require("os"));
50
+ const chalk_1 = __importDefault(require("chalk"));
51
+ // ─── AWS helpers ─────────────────────────────────────────────────────────────
52
+ function readAWSProfiles() {
53
+ const credentialsPath = path.join(os.homedir(), '.aws', 'credentials');
54
+ const configPath = path.join(os.homedir(), '.aws', 'config');
55
+ const profiles = new Set();
56
+ function parseFile(filePath) {
57
+ if (!fs.existsSync(filePath))
58
+ return;
59
+ for (const line of fs.readFileSync(filePath, 'utf-8').split('\n')) {
60
+ const match = line.match(/^\[(.+)\]$/);
61
+ if (match?.[1]) {
62
+ let name = match[1];
63
+ if (name.startsWith('profile '))
64
+ name = name.slice(8);
65
+ profiles.add(name);
66
+ }
67
+ }
68
+ }
69
+ parseFile(credentialsPath);
70
+ parseFile(configPath);
71
+ return profiles.size > 0 ? [...profiles] : ['default'];
72
+ }
73
+ function detectAWSRegion() {
74
+ if (process.env.AWS_DEFAULT_REGION)
75
+ return process.env.AWS_DEFAULT_REGION;
76
+ if (process.env.AWS_REGION)
77
+ return process.env.AWS_REGION;
78
+ const configPath = path.join(os.homedir(), '.aws', 'config');
79
+ if (fs.existsSync(configPath)) {
80
+ const match = fs.readFileSync(configPath, 'utf-8').match(/region\s*=\s*(.+)/);
81
+ if (match?.[1])
82
+ return match[1].trim();
83
+ }
84
+ return 'us-east-1';
85
+ }
86
+ function detectRepoType(repoPath) {
87
+ if (fs.existsSync(path.join(repoPath, 'tsconfig.json')))
88
+ return 'typescript';
89
+ if (fs.existsSync(path.join(repoPath, 'package.json')))
90
+ return 'javascript';
91
+ return 'unknown';
92
+ }
93
+ // ─── Banner ──────────────────────────────────────────────────────────────────
94
+ function readVersion() {
95
+ try {
96
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'), 'utf-8'));
97
+ return pkg.version;
98
+ }
99
+ catch {
100
+ return 'unknown';
101
+ }
102
+ }
103
+ function printBanner() {
104
+ const line1 = chalk_1.default.bold.hex('#6366f1')(' infrawise');
105
+ const version = chalk_1.default.dim(` v${readVersion()}`);
106
+ const tagline = chalk_1.default.dim(' Infrastructure Intelligence Platform\n');
107
+ console.log(`\n${line1}${version}`);
108
+ console.log(tagline);
109
+ }
110
+ // ─── Section header ──────────────────────────────────────────────────────────
111
+ function printHeader(title) {
112
+ console.log(chalk_1.default.bold(`\n${title}`));
113
+ console.log(chalk_1.default.dim('─'.repeat(title.length + 2)));
114
+ }
115
+ // ─── Status lines ────────────────────────────────────────────────────────────
116
+ exports.log = {
117
+ success: (msg, detail) => {
118
+ console.log(` ${chalk_1.default.green('✓')} ${msg}${detail ? chalk_1.default.dim(` ${detail}`) : ''}`);
119
+ },
120
+ fail: (msg, detail) => {
121
+ console.log(` ${chalk_1.default.red('✗')} ${chalk_1.default.red(msg)}${detail ? chalk_1.default.dim(`\n ${detail}`) : ''}`);
122
+ },
123
+ warn: (msg, detail) => {
124
+ console.log(` ${chalk_1.default.yellow('⚠')} ${chalk_1.default.yellow(msg)}${detail ? chalk_1.default.dim(`\n ${detail}`) : ''}`);
125
+ },
126
+ skip: (msg, detail) => {
127
+ console.log(` ${chalk_1.default.dim('−')} ${chalk_1.default.dim(msg)}${detail ? chalk_1.default.dim(` ${detail}`) : ''}`);
128
+ },
129
+ info: (msg) => {
130
+ console.log(` ${chalk_1.default.cyan('›')} ${msg}`);
131
+ },
132
+ dim: (msg) => {
133
+ console.log(chalk_1.default.dim(` ${msg}`));
134
+ },
135
+ };
136
+ // ─── Findings ────────────────────────────────────────────────────────────────
137
+ function severityBadge(severity) {
138
+ switch (severity) {
139
+ case 'high': return chalk_1.default.bgRed.white.bold(` HIGH `);
140
+ case 'medium': return chalk_1.default.bgYellow.black.bold(` MED `);
141
+ case 'low': return chalk_1.default.bgCyan.black.bold(` LOW `);
142
+ }
143
+ }
144
+ function printFinding(finding, index) {
145
+ const badge = severityBadge(finding.severity);
146
+ const num = chalk_1.default.dim(`${index + 1}.`);
147
+ console.log(`\n ${num} ${badge} ${chalk_1.default.bold(finding.issue)}`);
148
+ console.log(chalk_1.default.dim(` ${finding.description}`));
149
+ console.log(` ${chalk_1.default.green('→')} ${finding.recommendation}`);
150
+ }
151
+ function printSummaryBox(findings) {
152
+ const high = findings.filter((f) => f.severity === 'high').length;
153
+ const medium = findings.filter((f) => f.severity === 'medium').length;
154
+ const low = findings.filter((f) => f.severity === 'low').length;
155
+ console.log('');
156
+ console.log(chalk_1.default.dim(' ┌─────────────────────────────┐'));
157
+ console.log(chalk_1.default.dim(' │') + chalk_1.default.bold(' Analysis Summary ') + chalk_1.default.dim('│'));
158
+ console.log(chalk_1.default.dim(' ├─────────────────────────────┤'));
159
+ console.log(chalk_1.default.dim(' │') + ` ${chalk_1.default.red('●')} High ${chalk_1.default.red.bold(String(high).padStart(3))} ` + chalk_1.default.dim('│'));
160
+ console.log(chalk_1.default.dim(' │') + ` ${chalk_1.default.yellow('●')} Medium ${chalk_1.default.yellow.bold(String(medium).padStart(3))} ` + chalk_1.default.dim('│'));
161
+ console.log(chalk_1.default.dim(' │') + ` ${chalk_1.default.cyan('●')} Low ${chalk_1.default.cyan.bold(String(low).padStart(3))} ` + chalk_1.default.dim('│'));
162
+ console.log(chalk_1.default.dim(' ├─────────────────────────────┤'));
163
+ console.log(chalk_1.default.dim(' │') + ` Total ${chalk_1.default.bold(String(findings.length).padStart(3))} ` + chalk_1.default.dim('│'));
164
+ console.log(chalk_1.default.dim(' └─────────────────────────────┘'));
165
+ }