infra-cost 1.6.0 → 1.8.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.
- package/dist/cli/index.js +1687 -356
- package/dist/index.js +1683 -351
- package/package.json +8 -1
package/dist/index.js
CHANGED
|
@@ -9,6 +9,9 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
9
9
|
var __esm = (fn, res) => function __init() {
|
|
10
10
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
11
|
};
|
|
12
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
13
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
14
|
+
};
|
|
12
15
|
var __export = (target, all) => {
|
|
13
16
|
for (var name in all)
|
|
14
17
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -29,6 +32,172 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
32
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
33
|
mod
|
|
31
34
|
));
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
|
|
37
|
+
// package.json
|
|
38
|
+
var require_package = __commonJS({
|
|
39
|
+
"package.json"(exports, module2) {
|
|
40
|
+
module2.exports = {
|
|
41
|
+
name: "infra-cost",
|
|
42
|
+
version: "1.8.0",
|
|
43
|
+
description: "Multi-cloud FinOps CLI tool for comprehensive cost analysis and infrastructure optimization across AWS, GCP, Azure, Alibaba Cloud, and Oracle Cloud",
|
|
44
|
+
keywords: [
|
|
45
|
+
"aws",
|
|
46
|
+
"gcp",
|
|
47
|
+
"azure",
|
|
48
|
+
"cloud-cost",
|
|
49
|
+
"finops",
|
|
50
|
+
"cost-optimization",
|
|
51
|
+
"multi-cloud",
|
|
52
|
+
"cost-analysis",
|
|
53
|
+
"infrastructure",
|
|
54
|
+
"cloud-billing",
|
|
55
|
+
"cost-management",
|
|
56
|
+
"devops",
|
|
57
|
+
"cli-tool",
|
|
58
|
+
"cost-monitoring",
|
|
59
|
+
"budget-tracking"
|
|
60
|
+
],
|
|
61
|
+
author: {
|
|
62
|
+
name: "Code Collab",
|
|
63
|
+
email: "codecollab.co@gmail.com",
|
|
64
|
+
url: "https://github.com/codecollab-co/infra-cost"
|
|
65
|
+
},
|
|
66
|
+
files: [
|
|
67
|
+
"!tests/**/*",
|
|
68
|
+
"dist/**/*",
|
|
69
|
+
"!dist/**/*.js.map",
|
|
70
|
+
"bin/**/*"
|
|
71
|
+
],
|
|
72
|
+
bin: {
|
|
73
|
+
"infra-cost": "./bin/index.js",
|
|
74
|
+
"aws-cost": "./bin/index.js"
|
|
75
|
+
},
|
|
76
|
+
main: "./dist/index.js",
|
|
77
|
+
scripts: {
|
|
78
|
+
prebuild: "run-s clean",
|
|
79
|
+
build: "tsup",
|
|
80
|
+
clean: "rm -rf dist",
|
|
81
|
+
typecheck: "tsc --noEmit",
|
|
82
|
+
lint: "eslint src --ext .ts",
|
|
83
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
84
|
+
test: "jest",
|
|
85
|
+
"test:watch": "jest --watch",
|
|
86
|
+
"test:coverage": "jest --coverage",
|
|
87
|
+
dev: "tsup --watch",
|
|
88
|
+
"version:check": `echo "Current version: $(npm pkg get version | tr -d '"')"`,
|
|
89
|
+
"version:next": "npm version patch --no-git-tag-version",
|
|
90
|
+
"version:bump:patch": "npm version patch",
|
|
91
|
+
"version:bump:minor": "npm version minor",
|
|
92
|
+
"version:bump:major": "npm version major",
|
|
93
|
+
"publish:dry": "npm publish --dry-run",
|
|
94
|
+
"publish:latest": "npm publish",
|
|
95
|
+
"publish:beta": "npm publish --tag beta",
|
|
96
|
+
"prepare-release": "npm run build && npm run test && npm run version:bump:patch",
|
|
97
|
+
postpublish: 'echo "\u{1F389} Published $(npm pkg get name)@$(npm pkg get version) to npm!"',
|
|
98
|
+
prepublishOnly: "npm run build"
|
|
99
|
+
},
|
|
100
|
+
repository: {
|
|
101
|
+
type: "git",
|
|
102
|
+
url: "https://github.com/codecollab-co/infra-cost.git"
|
|
103
|
+
},
|
|
104
|
+
bugs: {
|
|
105
|
+
url: "https://github.com/codecollab-co/infra-cost/issues"
|
|
106
|
+
},
|
|
107
|
+
homepage: "https://github.com/codecollab-co/infra-cost#readme",
|
|
108
|
+
license: "MIT",
|
|
109
|
+
engines: {
|
|
110
|
+
node: ">=20.0.0",
|
|
111
|
+
npm: ">=10.0.0"
|
|
112
|
+
},
|
|
113
|
+
dependencies: {
|
|
114
|
+
"@alicloud/bssopenapi20171214": "^2.0.1",
|
|
115
|
+
"@alicloud/cs20151215": "^4.0.1",
|
|
116
|
+
"@alicloud/ecs20140526": "^4.0.3",
|
|
117
|
+
"@alicloud/oss20190517": "^1.0.6",
|
|
118
|
+
"@alicloud/rds20140815": "^3.0.2",
|
|
119
|
+
"@alicloud/tea-util": "^1.4.7",
|
|
120
|
+
"@aws-sdk/client-budgets": "^3.975.0",
|
|
121
|
+
"@aws-sdk/client-cost-explorer": "^3.975.0",
|
|
122
|
+
"@aws-sdk/client-ec2": "^3.975.0",
|
|
123
|
+
"@aws-sdk/client-elastic-load-balancing-v2": "^3.975.0",
|
|
124
|
+
"@aws-sdk/client-iam": "^3.975.0",
|
|
125
|
+
"@aws-sdk/client-lambda": "^3.975.0",
|
|
126
|
+
"@aws-sdk/client-rds": "^3.975.0",
|
|
127
|
+
"@aws-sdk/client-s3": "^3.975.0",
|
|
128
|
+
"@aws-sdk/client-sts": "^3.975.0",
|
|
129
|
+
"@aws-sdk/credential-providers": "^3.975.0",
|
|
130
|
+
"@azure/arm-compute": "^23.3.0",
|
|
131
|
+
"@azure/arm-consumption": "^9.2.1",
|
|
132
|
+
"@azure/arm-containerservice": "^24.1.0",
|
|
133
|
+
"@azure/arm-costmanagement": "^1.0.0-beta.2",
|
|
134
|
+
"@azure/arm-network": "^35.0.0",
|
|
135
|
+
"@azure/arm-sql": "^10.0.0",
|
|
136
|
+
"@azure/arm-storage": "^19.1.0",
|
|
137
|
+
"@azure/arm-subscriptions": "^6.0.0",
|
|
138
|
+
"@azure/identity": "^4.13.0",
|
|
139
|
+
"@google-cloud/bigquery": "^8.1.1",
|
|
140
|
+
"@google-cloud/billing": "^5.1.1",
|
|
141
|
+
"@google-cloud/compute": "^6.7.0",
|
|
142
|
+
"@google-cloud/container": "^6.6.0",
|
|
143
|
+
"@google-cloud/monitoring": "^5.3.1",
|
|
144
|
+
"@google-cloud/resource-manager": "^6.2.1",
|
|
145
|
+
"@google-cloud/sql": "^0.24.0",
|
|
146
|
+
"@google-cloud/storage": "^7.18.0",
|
|
147
|
+
"@slack/web-api": "^7.5.0",
|
|
148
|
+
callsites: "^3.1.0",
|
|
149
|
+
chalk: "^4.1.2",
|
|
150
|
+
"cli-progress": "^3.12.0",
|
|
151
|
+
"cli-table3": "^0.6.5",
|
|
152
|
+
commander: "^12.1.0",
|
|
153
|
+
cors: "^2.8.6",
|
|
154
|
+
dayjs: "^1.11.19",
|
|
155
|
+
exceljs: "^4.4.0",
|
|
156
|
+
express: "^5.2.1",
|
|
157
|
+
"express-rate-limit": "^8.2.1",
|
|
158
|
+
"fd-slicer": "^1.1.0",
|
|
159
|
+
"google-auth-library": "^10.5.0",
|
|
160
|
+
googleapis: "^171.0.0",
|
|
161
|
+
helmet: "^8.1.0",
|
|
162
|
+
ini: "^6.0.0",
|
|
163
|
+
ink: "^6.6.0",
|
|
164
|
+
moment: "^2.30.1",
|
|
165
|
+
"node-fetch": "^2.7.0",
|
|
166
|
+
"oci-budget": "^2.88.0",
|
|
167
|
+
"oci-common": "^2.88.0",
|
|
168
|
+
"oci-containerengine": "^2.88.0",
|
|
169
|
+
"oci-core": "^2.88.0",
|
|
170
|
+
"oci-database": "^2.88.0",
|
|
171
|
+
"oci-identity": "^2.88.0",
|
|
172
|
+
"oci-objectstorage": "^2.88.0",
|
|
173
|
+
"oci-usageapi": "^2.88.0",
|
|
174
|
+
ora: "^9.1.0",
|
|
175
|
+
pako: "^2.1.0",
|
|
176
|
+
pend: "^1.2.0",
|
|
177
|
+
react: "^19.2.4",
|
|
178
|
+
"swagger-jsdoc": "^6.2.8",
|
|
179
|
+
"swagger-ui-express": "^5.0.1",
|
|
180
|
+
yauzl: "^3.0.0",
|
|
181
|
+
zod: "^3.23.8"
|
|
182
|
+
},
|
|
183
|
+
devDependencies: {
|
|
184
|
+
"@types/cors": "^2.8.19",
|
|
185
|
+
"@types/express": "^5.0.6",
|
|
186
|
+
"@types/jest": "^29.5.12",
|
|
187
|
+
"@types/node": "^22.5.4",
|
|
188
|
+
"@types/yauzl": "^2.10.3",
|
|
189
|
+
"@typescript-eslint/eslint-plugin": "^8.5.0",
|
|
190
|
+
"@typescript-eslint/parser": "^8.5.0",
|
|
191
|
+
eslint: "^8.57.0",
|
|
192
|
+
jest: "^29.7.0",
|
|
193
|
+
"npm-run-all": "^4.1.5",
|
|
194
|
+
"ts-jest": "^29.2.5",
|
|
195
|
+
tsup: "^6.7.0",
|
|
196
|
+
typescript: "^5.6.2"
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
});
|
|
32
201
|
|
|
33
202
|
// src/core/logging/structured-logger.ts
|
|
34
203
|
function initializeLogger(config) {
|
|
@@ -565,6 +734,209 @@ var init_schema = __esm({
|
|
|
565
734
|
}
|
|
566
735
|
});
|
|
567
736
|
|
|
737
|
+
// src/core/config/loader.ts
|
|
738
|
+
function discoverConfigFile() {
|
|
739
|
+
for (const configPath of CONFIG_PATHS) {
|
|
740
|
+
if ((0, import_fs.existsSync)(configPath)) {
|
|
741
|
+
return configPath;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
return null;
|
|
745
|
+
}
|
|
746
|
+
function loadConfigFile(configPath) {
|
|
747
|
+
try {
|
|
748
|
+
const content = (0, import_fs.readFileSync)(configPath, "utf8");
|
|
749
|
+
const config = JSON.parse(content);
|
|
750
|
+
if (config.profiles && config.defaults?.profile) {
|
|
751
|
+
const activeProfile = config.profiles[config.defaults.profile];
|
|
752
|
+
if (activeProfile) {
|
|
753
|
+
return mergeConfigs(config.defaults, activeProfile);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return config.defaults || config;
|
|
757
|
+
} catch (error) {
|
|
758
|
+
console.warn(`Warning: Could not load config from ${configPath}: ${error.message}`);
|
|
759
|
+
return {};
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
function resolveEnvVars(config) {
|
|
763
|
+
const resolved = JSON.parse(JSON.stringify(config));
|
|
764
|
+
if (process.env.AWS_ACCESS_KEY_ID) {
|
|
765
|
+
resolved.accessKey = process.env.AWS_ACCESS_KEY_ID;
|
|
766
|
+
}
|
|
767
|
+
if (process.env.AWS_SECRET_ACCESS_KEY) {
|
|
768
|
+
resolved.secretKey = process.env.AWS_SECRET_ACCESS_KEY;
|
|
769
|
+
}
|
|
770
|
+
if (process.env.AWS_SESSION_TOKEN) {
|
|
771
|
+
resolved.sessionToken = process.env.AWS_SESSION_TOKEN;
|
|
772
|
+
}
|
|
773
|
+
if (process.env.AWS_REGION) {
|
|
774
|
+
resolved.region = process.env.AWS_REGION;
|
|
775
|
+
}
|
|
776
|
+
if (process.env.AWS_PROFILE) {
|
|
777
|
+
resolved.profile = process.env.AWS_PROFILE;
|
|
778
|
+
}
|
|
779
|
+
if (process.env.SLACK_TOKEN || process.env.SLACK_CHANNEL) {
|
|
780
|
+
resolved.slack = {
|
|
781
|
+
...resolved.slack,
|
|
782
|
+
token: process.env.SLACK_TOKEN ?? resolved.slack?.token,
|
|
783
|
+
channel: process.env.SLACK_CHANNEL ?? resolved.slack?.channel,
|
|
784
|
+
enabled: true
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
return resolved;
|
|
788
|
+
}
|
|
789
|
+
function mergeConfigs(...configs) {
|
|
790
|
+
const result = {};
|
|
791
|
+
for (const config of configs) {
|
|
792
|
+
for (const [key, value] of Object.entries(config)) {
|
|
793
|
+
if (value === void 0 || value === null) {
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
797
|
+
result[key] = { ...result[key], ...value };
|
|
798
|
+
} else {
|
|
799
|
+
result[key] = value;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
return result;
|
|
804
|
+
}
|
|
805
|
+
function autoLoadConfig(cliOptions = {}) {
|
|
806
|
+
let config = { ...DEFAULT_CONFIG2 };
|
|
807
|
+
const configPath = cliOptions.configFile || discoverConfigFile();
|
|
808
|
+
if (configPath) {
|
|
809
|
+
const fileConfig = loadConfigFile(configPath);
|
|
810
|
+
config = mergeConfigs(config, fileConfig);
|
|
811
|
+
}
|
|
812
|
+
config = mergeConfigs(config, resolveEnvVars(config));
|
|
813
|
+
const cliConfig = mapCliOptionsToConfig(cliOptions);
|
|
814
|
+
config = mergeConfigs(config, cliConfig);
|
|
815
|
+
return config;
|
|
816
|
+
}
|
|
817
|
+
function mapCliOptionsToConfig(options) {
|
|
818
|
+
const config = {};
|
|
819
|
+
if (options.provider)
|
|
820
|
+
config.provider = options.provider;
|
|
821
|
+
if (options.profile)
|
|
822
|
+
config.profile = options.profile;
|
|
823
|
+
if (options.region)
|
|
824
|
+
config.region = options.region;
|
|
825
|
+
if (options.accessKey)
|
|
826
|
+
config.accessKey = options.accessKey;
|
|
827
|
+
if (options.secretKey)
|
|
828
|
+
config.secretKey = options.secretKey;
|
|
829
|
+
if (options.sessionToken)
|
|
830
|
+
config.sessionToken = options.sessionToken;
|
|
831
|
+
if (options.json || options.text || options.summary) {
|
|
832
|
+
config.output = config.output || {};
|
|
833
|
+
if (options.json)
|
|
834
|
+
config.output.format = "json";
|
|
835
|
+
if (options.text)
|
|
836
|
+
config.output.format = "text";
|
|
837
|
+
if (options.summary)
|
|
838
|
+
config.output.summary = true;
|
|
839
|
+
}
|
|
840
|
+
if (options.delta !== void 0) {
|
|
841
|
+
config.output = config.output || {};
|
|
842
|
+
config.output.showDelta = options.delta;
|
|
843
|
+
}
|
|
844
|
+
if (options.deltaThreshold) {
|
|
845
|
+
config.output = config.output || {};
|
|
846
|
+
config.output.deltaThreshold = parseFloat(options.deltaThreshold);
|
|
847
|
+
}
|
|
848
|
+
if (options.quickWins !== void 0) {
|
|
849
|
+
config.output = config.output || {};
|
|
850
|
+
config.output.showQuickWins = options.quickWins;
|
|
851
|
+
}
|
|
852
|
+
if (options.quickWinsCount) {
|
|
853
|
+
config.output = config.output || {};
|
|
854
|
+
config.output.quickWinsCount = parseInt(options.quickWinsCount, 10);
|
|
855
|
+
}
|
|
856
|
+
if (options.cache !== void 0 || options.noCache !== void 0) {
|
|
857
|
+
config.cache = config.cache || {};
|
|
858
|
+
config.cache.enabled = options.cache === true || options.noCache !== true;
|
|
859
|
+
}
|
|
860
|
+
if (options.cacheTtl) {
|
|
861
|
+
config.cache = config.cache || {};
|
|
862
|
+
config.cache.ttl = options.cacheTtl;
|
|
863
|
+
}
|
|
864
|
+
if (options.cacheType) {
|
|
865
|
+
config.cache = config.cache || {};
|
|
866
|
+
config.cache.type = options.cacheType;
|
|
867
|
+
}
|
|
868
|
+
if (options.slackToken || options.slackChannel) {
|
|
869
|
+
config.slack = config.slack || {};
|
|
870
|
+
if (options.slackToken)
|
|
871
|
+
config.slack.token = options.slackToken;
|
|
872
|
+
if (options.slackChannel)
|
|
873
|
+
config.slack.channel = options.slackChannel;
|
|
874
|
+
config.slack.enabled = true;
|
|
875
|
+
}
|
|
876
|
+
if (options.logLevel || options.verbose || options.quiet) {
|
|
877
|
+
config.logging = config.logging || {};
|
|
878
|
+
if (options.logLevel)
|
|
879
|
+
config.logging.level = options.logLevel;
|
|
880
|
+
if (options.verbose)
|
|
881
|
+
config.logging.level = "debug";
|
|
882
|
+
if (options.quiet)
|
|
883
|
+
config.logging.level = "error";
|
|
884
|
+
}
|
|
885
|
+
return config;
|
|
886
|
+
}
|
|
887
|
+
var import_fs, import_path, import_os, CONFIG_PATHS, DEFAULT_CONFIG2;
|
|
888
|
+
var init_loader = __esm({
|
|
889
|
+
"src/core/config/loader.ts"() {
|
|
890
|
+
import_fs = require("fs");
|
|
891
|
+
import_path = require("path");
|
|
892
|
+
import_os = require("os");
|
|
893
|
+
CONFIG_PATHS = [
|
|
894
|
+
(0, import_path.join)(process.cwd(), "infra-cost.config.json"),
|
|
895
|
+
// Project-specific
|
|
896
|
+
(0, import_path.join)(process.cwd(), ".infra-cost.config.json"),
|
|
897
|
+
// Project-specific (hidden)
|
|
898
|
+
(0, import_path.join)(process.cwd(), ".infra-cost", "config.json"),
|
|
899
|
+
// Project directory
|
|
900
|
+
(0, import_path.join)((0, import_os.homedir)(), ".infra-cost", "config.json"),
|
|
901
|
+
// User global
|
|
902
|
+
(0, import_path.join)((0, import_os.homedir)(), ".config", "infra-cost", "config.json")
|
|
903
|
+
// XDG standard
|
|
904
|
+
];
|
|
905
|
+
DEFAULT_CONFIG2 = {
|
|
906
|
+
provider: "aws",
|
|
907
|
+
profile: "default",
|
|
908
|
+
region: "us-east-1",
|
|
909
|
+
output: {
|
|
910
|
+
format: "fancy",
|
|
911
|
+
summary: false,
|
|
912
|
+
showDelta: true,
|
|
913
|
+
// NEW: Show delta by default
|
|
914
|
+
showQuickWins: true,
|
|
915
|
+
// NEW: Show quick wins by default
|
|
916
|
+
deltaThreshold: 10,
|
|
917
|
+
quickWinsCount: 3
|
|
918
|
+
},
|
|
919
|
+
cache: {
|
|
920
|
+
enabled: true,
|
|
921
|
+
// NEW: Cache enabled by default
|
|
922
|
+
ttl: "4h",
|
|
923
|
+
type: "file"
|
|
924
|
+
},
|
|
925
|
+
logging: {
|
|
926
|
+
level: "info",
|
|
927
|
+
format: "pretty",
|
|
928
|
+
auditEnabled: false
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
__name(discoverConfigFile, "discoverConfigFile");
|
|
932
|
+
__name(loadConfigFile, "loadConfigFile");
|
|
933
|
+
__name(resolveEnvVars, "resolveEnvVars");
|
|
934
|
+
__name(mergeConfigs, "mergeConfigs");
|
|
935
|
+
__name(autoLoadConfig, "autoLoadConfig");
|
|
936
|
+
__name(mapCliOptionsToConfig, "mapCliOptionsToConfig");
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
|
|
568
940
|
// src/types/providers.ts
|
|
569
941
|
var CloudProviderAdapter, ResourceType;
|
|
570
942
|
var init_providers = __esm({
|
|
@@ -10208,366 +10580,669 @@ var init_multicloud = __esm({
|
|
|
10208
10580
|
}
|
|
10209
10581
|
});
|
|
10210
10582
|
|
|
10211
|
-
// src/
|
|
10212
|
-
|
|
10583
|
+
// src/api/utils.ts
|
|
10584
|
+
async function getProviderFromConfig() {
|
|
10585
|
+
const config = autoLoadConfig();
|
|
10586
|
+
const factory = new CloudProviderFactory();
|
|
10587
|
+
return factory.createProvider(config);
|
|
10588
|
+
}
|
|
10589
|
+
function getConfig2() {
|
|
10590
|
+
return autoLoadConfig();
|
|
10591
|
+
}
|
|
10592
|
+
var init_utils = __esm({
|
|
10593
|
+
"src/api/utils.ts"() {
|
|
10594
|
+
init_factory();
|
|
10595
|
+
init_loader();
|
|
10596
|
+
__name(getProviderFromConfig, "getProviderFromConfig");
|
|
10597
|
+
__name(getConfig2, "getConfig");
|
|
10598
|
+
}
|
|
10599
|
+
});
|
|
10213
10600
|
|
|
10214
|
-
//
|
|
10215
|
-
var
|
|
10216
|
-
|
|
10217
|
-
|
|
10218
|
-
|
|
10219
|
-
|
|
10220
|
-
|
|
10221
|
-
|
|
10222
|
-
"
|
|
10223
|
-
|
|
10224
|
-
|
|
10225
|
-
|
|
10226
|
-
"
|
|
10227
|
-
|
|
10228
|
-
|
|
10229
|
-
|
|
10230
|
-
|
|
10231
|
-
|
|
10232
|
-
|
|
10233
|
-
|
|
10234
|
-
|
|
10235
|
-
|
|
10236
|
-
|
|
10237
|
-
|
|
10238
|
-
|
|
10239
|
-
|
|
10240
|
-
|
|
10241
|
-
|
|
10242
|
-
|
|
10243
|
-
|
|
10244
|
-
|
|
10245
|
-
|
|
10246
|
-
|
|
10247
|
-
|
|
10248
|
-
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
|
|
10257
|
-
|
|
10258
|
-
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
|
|
10262
|
-
|
|
10263
|
-
|
|
10264
|
-
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
|
|
10273
|
-
|
|
10274
|
-
|
|
10275
|
-
|
|
10276
|
-
|
|
10277
|
-
|
|
10278
|
-
|
|
10279
|
-
|
|
10280
|
-
|
|
10281
|
-
|
|
10282
|
-
|
|
10283
|
-
|
|
10284
|
-
|
|
10285
|
-
|
|
10286
|
-
|
|
10287
|
-
|
|
10288
|
-
|
|
10289
|
-
|
|
10290
|
-
|
|
10291
|
-
|
|
10292
|
-
|
|
10293
|
-
|
|
10294
|
-
|
|
10295
|
-
|
|
10296
|
-
|
|
10297
|
-
|
|
10298
|
-
|
|
10299
|
-
|
|
10300
|
-
"
|
|
10301
|
-
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10327
|
-
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10349
|
-
|
|
10350
|
-
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10357
|
-
|
|
10358
|
-
|
|
10359
|
-
|
|
10360
|
-
jest: "^29.7.0",
|
|
10361
|
-
"npm-run-all": "^4.1.5",
|
|
10362
|
-
"ts-jest": "^29.2.5",
|
|
10363
|
-
tsup: "^6.7.0",
|
|
10364
|
-
typescript: "^5.6.2"
|
|
10601
|
+
// src/api/routes/costs.ts
|
|
10602
|
+
var costs_exports2 = {};
|
|
10603
|
+
__export(costs_exports2, {
|
|
10604
|
+
default: () => costs_default
|
|
10605
|
+
});
|
|
10606
|
+
var import_express, router, costs_default;
|
|
10607
|
+
var init_costs2 = __esm({
|
|
10608
|
+
"src/api/routes/costs.ts"() {
|
|
10609
|
+
import_express = require("express");
|
|
10610
|
+
init_utils();
|
|
10611
|
+
init_server();
|
|
10612
|
+
router = (0, import_express.Router)();
|
|
10613
|
+
router.get("/", async (req, res) => {
|
|
10614
|
+
try {
|
|
10615
|
+
const config = getConfig2();
|
|
10616
|
+
const provider = await getProviderFromConfig();
|
|
10617
|
+
const today = /* @__PURE__ */ new Date();
|
|
10618
|
+
const todayStart = new Date(today.setHours(0, 0, 0, 0));
|
|
10619
|
+
const todayEnd = new Date(today.setHours(23, 59, 59, 999));
|
|
10620
|
+
const monthStart = new Date(today.getFullYear(), today.getMonth(), 1);
|
|
10621
|
+
const monthEnd = new Date(today.getFullYear(), today.getMonth() + 1, 0);
|
|
10622
|
+
const [todayCosts, mtdCosts] = await Promise.all([
|
|
10623
|
+
provider.getCostBreakdown(todayStart, todayEnd, "SERVICE"),
|
|
10624
|
+
provider.getCostBreakdown(monthStart, monthEnd, "SERVICE")
|
|
10625
|
+
]);
|
|
10626
|
+
const serviceBreakdown = {};
|
|
10627
|
+
todayCosts.breakdown.forEach((item) => {
|
|
10628
|
+
serviceBreakdown[item.service] = item.cost;
|
|
10629
|
+
});
|
|
10630
|
+
const accountInfo = await provider.getAccountInfo();
|
|
10631
|
+
const response = {
|
|
10632
|
+
account: {
|
|
10633
|
+
id: accountInfo.accountId,
|
|
10634
|
+
name: accountInfo.accountAlias || accountInfo.accountId,
|
|
10635
|
+
provider: config.provider
|
|
10636
|
+
},
|
|
10637
|
+
costs: {
|
|
10638
|
+
today: {
|
|
10639
|
+
total: todayCosts.totalCost,
|
|
10640
|
+
currency: "USD",
|
|
10641
|
+
byService: serviceBreakdown
|
|
10642
|
+
},
|
|
10643
|
+
mtd: {
|
|
10644
|
+
total: mtdCosts.totalCost,
|
|
10645
|
+
projected: mtdCosts.totalCost * (30 / today.getDate())
|
|
10646
|
+
},
|
|
10647
|
+
delta: {
|
|
10648
|
+
vsYesterday: 0,
|
|
10649
|
+
// Would need historical data
|
|
10650
|
+
vsLastWeek: 0
|
|
10651
|
+
// Would need historical data
|
|
10652
|
+
}
|
|
10653
|
+
},
|
|
10654
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
10655
|
+
};
|
|
10656
|
+
res.json(createApiResponse(response));
|
|
10657
|
+
} catch (error) {
|
|
10658
|
+
res.status(500).json(createErrorResponse("FETCH_ERROR", error.message));
|
|
10659
|
+
}
|
|
10660
|
+
});
|
|
10661
|
+
router.get("/services", async (req, res) => {
|
|
10662
|
+
try {
|
|
10663
|
+
const provider = await getProviderFromConfig();
|
|
10664
|
+
const { startDate, endDate } = req.query;
|
|
10665
|
+
const start = startDate ? new Date(startDate) : /* @__PURE__ */ new Date();
|
|
10666
|
+
const end = endDate ? new Date(endDate) : /* @__PURE__ */ new Date();
|
|
10667
|
+
const breakdown = await provider.getCostBreakdown(start, end, "SERVICE");
|
|
10668
|
+
const services = breakdown.breakdown.map((item) => ({
|
|
10669
|
+
service: item.service,
|
|
10670
|
+
cost: item.cost,
|
|
10671
|
+
percentage: item.cost / breakdown.totalCost * 100
|
|
10672
|
+
}));
|
|
10673
|
+
res.json(
|
|
10674
|
+
createApiResponse({
|
|
10675
|
+
total: breakdown.totalCost,
|
|
10676
|
+
services,
|
|
10677
|
+
period: {
|
|
10678
|
+
start: start.toISOString(),
|
|
10679
|
+
end: end.toISOString()
|
|
10680
|
+
}
|
|
10681
|
+
})
|
|
10682
|
+
);
|
|
10683
|
+
} catch (error) {
|
|
10684
|
+
res.status(500).json(createErrorResponse("FETCH_ERROR", error.message));
|
|
10685
|
+
}
|
|
10686
|
+
});
|
|
10687
|
+
router.get("/daily", async (req, res) => {
|
|
10688
|
+
try {
|
|
10689
|
+
const provider = await getProviderFromConfig();
|
|
10690
|
+
const { days = 30 } = req.query;
|
|
10691
|
+
const daysNum = parseInt(days, 10);
|
|
10692
|
+
const end = /* @__PURE__ */ new Date();
|
|
10693
|
+
const start = /* @__PURE__ */ new Date();
|
|
10694
|
+
start.setDate(start.getDate() - daysNum);
|
|
10695
|
+
const breakdown = await provider.getCostBreakdown(start, end, "DAILY");
|
|
10696
|
+
const dailyCosts = breakdown.breakdown.map((item) => ({
|
|
10697
|
+
date: item.date,
|
|
10698
|
+
cost: item.cost
|
|
10699
|
+
}));
|
|
10700
|
+
res.json(
|
|
10701
|
+
createApiResponse({
|
|
10702
|
+
total: breakdown.totalCost,
|
|
10703
|
+
daily: dailyCosts,
|
|
10704
|
+
period: {
|
|
10705
|
+
start: start.toISOString(),
|
|
10706
|
+
end: end.toISOString(),
|
|
10707
|
+
days: daysNum
|
|
10708
|
+
}
|
|
10709
|
+
})
|
|
10710
|
+
);
|
|
10711
|
+
} catch (error) {
|
|
10712
|
+
res.status(500).json(createErrorResponse("FETCH_ERROR", error.message));
|
|
10713
|
+
}
|
|
10714
|
+
});
|
|
10715
|
+
router.get("/trends", async (req, res) => {
|
|
10716
|
+
try {
|
|
10717
|
+
const provider = await getProviderFromConfig();
|
|
10718
|
+
const end = /* @__PURE__ */ new Date();
|
|
10719
|
+
const start = /* @__PURE__ */ new Date();
|
|
10720
|
+
start.setMonth(start.getMonth() - 3);
|
|
10721
|
+
const breakdown = await provider.getCostBreakdown(start, end, "MONTHLY");
|
|
10722
|
+
const trends = breakdown.breakdown.map((item, index, arr) => {
|
|
10723
|
+
const previousMonth = index > 0 ? arr[index - 1].cost : null;
|
|
10724
|
+
const changePercent = previousMonth ? (item.cost - previousMonth) / previousMonth * 100 : 0;
|
|
10725
|
+
return {
|
|
10726
|
+
month: item.date,
|
|
10727
|
+
cost: item.cost,
|
|
10728
|
+
change: item.cost - (previousMonth || 0),
|
|
10729
|
+
changePercent
|
|
10730
|
+
};
|
|
10731
|
+
});
|
|
10732
|
+
res.json(
|
|
10733
|
+
createApiResponse({
|
|
10734
|
+
trends,
|
|
10735
|
+
average: breakdown.totalCost / breakdown.breakdown.length,
|
|
10736
|
+
period: {
|
|
10737
|
+
start: start.toISOString(),
|
|
10738
|
+
end: end.toISOString()
|
|
10739
|
+
}
|
|
10740
|
+
})
|
|
10741
|
+
);
|
|
10742
|
+
} catch (error) {
|
|
10743
|
+
res.status(500).json(createErrorResponse("FETCH_ERROR", error.message));
|
|
10744
|
+
}
|
|
10745
|
+
});
|
|
10746
|
+
costs_default = router;
|
|
10365
10747
|
}
|
|
10366
|
-
};
|
|
10748
|
+
});
|
|
10367
10749
|
|
|
10368
|
-
// src/
|
|
10369
|
-
|
|
10750
|
+
// src/api/routes/inventory.ts
|
|
10751
|
+
var inventory_exports2 = {};
|
|
10752
|
+
__export(inventory_exports2, {
|
|
10753
|
+
default: () => inventory_default
|
|
10754
|
+
});
|
|
10755
|
+
var import_express2, router2, inventory_default;
|
|
10756
|
+
var init_inventory6 = __esm({
|
|
10757
|
+
"src/api/routes/inventory.ts"() {
|
|
10758
|
+
import_express2 = require("express");
|
|
10759
|
+
init_utils();
|
|
10760
|
+
init_server();
|
|
10761
|
+
router2 = (0, import_express2.Router)();
|
|
10762
|
+
router2.get("/", async (req, res) => {
|
|
10763
|
+
try {
|
|
10764
|
+
const provider = await getProviderFromConfig();
|
|
10765
|
+
const inventory = await provider.getResourceInventory();
|
|
10766
|
+
const summary = {
|
|
10767
|
+
totalResources: inventory.resources.length,
|
|
10768
|
+
byType: inventory.resources.reduce((acc, resource) => {
|
|
10769
|
+
acc[resource.type] = (acc[resource.type] || 0) + 1;
|
|
10770
|
+
return acc;
|
|
10771
|
+
}, {}),
|
|
10772
|
+
byRegion: inventory.resources.reduce((acc, resource) => {
|
|
10773
|
+
const region = resource.region || "global";
|
|
10774
|
+
acc[region] = (acc[region] || 0) + 1;
|
|
10775
|
+
return acc;
|
|
10776
|
+
}, {})
|
|
10777
|
+
};
|
|
10778
|
+
res.json(
|
|
10779
|
+
createApiResponse({
|
|
10780
|
+
summary,
|
|
10781
|
+
resources: inventory.resources
|
|
10782
|
+
})
|
|
10783
|
+
);
|
|
10784
|
+
} catch (error) {
|
|
10785
|
+
res.status(500).json(createErrorResponse("FETCH_ERROR", error.message));
|
|
10786
|
+
}
|
|
10787
|
+
});
|
|
10788
|
+
inventory_default = router2;
|
|
10789
|
+
}
|
|
10790
|
+
});
|
|
10370
10791
|
|
|
10371
|
-
// src/
|
|
10372
|
-
|
|
10792
|
+
// src/api/routes/optimization.ts
|
|
10793
|
+
var optimization_exports = {};
|
|
10794
|
+
__export(optimization_exports, {
|
|
10795
|
+
default: () => optimization_default
|
|
10796
|
+
});
|
|
10797
|
+
var import_express3, router3, optimization_default;
|
|
10798
|
+
var init_optimization = __esm({
|
|
10799
|
+
"src/api/routes/optimization.ts"() {
|
|
10800
|
+
import_express3 = require("express");
|
|
10801
|
+
init_utils();
|
|
10802
|
+
init_server();
|
|
10803
|
+
router3 = (0, import_express3.Router)();
|
|
10804
|
+
router3.get("/", async (req, res) => {
|
|
10805
|
+
try {
|
|
10806
|
+
const provider = await getProviderFromConfig();
|
|
10807
|
+
const recommendations = await provider.getOptimizationRecommendations();
|
|
10808
|
+
const summary = {
|
|
10809
|
+
totalSavings: recommendations.reduce((sum, rec) => sum + (rec.estimatedMonthlySavings || 0), 0),
|
|
10810
|
+
recommendationCount: recommendations.length,
|
|
10811
|
+
byCategory: recommendations.reduce((acc, rec) => {
|
|
10812
|
+
const category = rec.category || "other";
|
|
10813
|
+
acc[category] = (acc[category] || 0) + 1;
|
|
10814
|
+
return acc;
|
|
10815
|
+
}, {})
|
|
10816
|
+
};
|
|
10817
|
+
res.json(
|
|
10818
|
+
createApiResponse({
|
|
10819
|
+
summary,
|
|
10820
|
+
recommendations
|
|
10821
|
+
})
|
|
10822
|
+
);
|
|
10823
|
+
} catch (error) {
|
|
10824
|
+
res.status(500).json(createErrorResponse("FETCH_ERROR", error.message));
|
|
10825
|
+
}
|
|
10826
|
+
});
|
|
10827
|
+
optimization_default = router3;
|
|
10828
|
+
}
|
|
10829
|
+
});
|
|
10373
10830
|
|
|
10374
|
-
// src/
|
|
10375
|
-
var
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
|
|
10380
|
-
|
|
10381
|
-
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
|
|
10385
|
-
|
|
10386
|
-
|
|
10387
|
-
|
|
10388
|
-
|
|
10389
|
-
|
|
10390
|
-
|
|
10391
|
-
|
|
10392
|
-
|
|
10393
|
-
|
|
10394
|
-
|
|
10395
|
-
|
|
10396
|
-
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
|
|
10400
|
-
|
|
10401
|
-
|
|
10402
|
-
|
|
10403
|
-
|
|
10404
|
-
|
|
10405
|
-
|
|
10406
|
-
|
|
10407
|
-
|
|
10408
|
-
|
|
10409
|
-
|
|
10410
|
-
logging: {
|
|
10411
|
-
level: "info",
|
|
10412
|
-
format: "pretty",
|
|
10413
|
-
auditEnabled: false
|
|
10414
|
-
}
|
|
10415
|
-
};
|
|
10416
|
-
function discoverConfigFile() {
|
|
10417
|
-
for (const configPath of CONFIG_PATHS) {
|
|
10418
|
-
if ((0, import_fs.existsSync)(configPath)) {
|
|
10419
|
-
return configPath;
|
|
10420
|
-
}
|
|
10421
|
-
}
|
|
10422
|
-
return null;
|
|
10423
|
-
}
|
|
10424
|
-
__name(discoverConfigFile, "discoverConfigFile");
|
|
10425
|
-
function loadConfigFile(configPath) {
|
|
10426
|
-
try {
|
|
10427
|
-
const content = (0, import_fs.readFileSync)(configPath, "utf8");
|
|
10428
|
-
const config = JSON.parse(content);
|
|
10429
|
-
if (config.profiles && config.defaults?.profile) {
|
|
10430
|
-
const activeProfile = config.profiles[config.defaults.profile];
|
|
10431
|
-
if (activeProfile) {
|
|
10432
|
-
return mergeConfigs(config.defaults, activeProfile);
|
|
10831
|
+
// src/api/routes/chargeback.ts
|
|
10832
|
+
var chargeback_exports = {};
|
|
10833
|
+
__export(chargeback_exports, {
|
|
10834
|
+
default: () => chargeback_default
|
|
10835
|
+
});
|
|
10836
|
+
var import_express4, router4, chargeback_default;
|
|
10837
|
+
var init_chargeback = __esm({
|
|
10838
|
+
"src/api/routes/chargeback.ts"() {
|
|
10839
|
+
import_express4 = require("express");
|
|
10840
|
+
init_utils();
|
|
10841
|
+
init_server();
|
|
10842
|
+
router4 = (0, import_express4.Router)();
|
|
10843
|
+
router4.get("/", async (req, res) => {
|
|
10844
|
+
try {
|
|
10845
|
+
const provider = await getProviderFromConfig();
|
|
10846
|
+
const { groupBy = "tag" } = req.query;
|
|
10847
|
+
const now = /* @__PURE__ */ new Date();
|
|
10848
|
+
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
10849
|
+
const breakdown = await provider.getCostBreakdown(
|
|
10850
|
+
monthStart,
|
|
10851
|
+
now,
|
|
10852
|
+
groupBy === "tag" ? "TAG" : "SERVICE"
|
|
10853
|
+
);
|
|
10854
|
+
res.json(
|
|
10855
|
+
createApiResponse({
|
|
10856
|
+
total: breakdown.totalCost,
|
|
10857
|
+
breakdown: breakdown.breakdown,
|
|
10858
|
+
period: {
|
|
10859
|
+
start: monthStart.toISOString(),
|
|
10860
|
+
end: now.toISOString()
|
|
10861
|
+
},
|
|
10862
|
+
groupBy
|
|
10863
|
+
})
|
|
10864
|
+
);
|
|
10865
|
+
} catch (error) {
|
|
10866
|
+
res.status(500).json(createErrorResponse("FETCH_ERROR", error.message));
|
|
10433
10867
|
}
|
|
10434
|
-
}
|
|
10435
|
-
|
|
10436
|
-
} catch (error) {
|
|
10437
|
-
console.warn(`Warning: Could not load config from ${configPath}: ${error.message}`);
|
|
10438
|
-
return {};
|
|
10439
|
-
}
|
|
10440
|
-
}
|
|
10441
|
-
__name(loadConfigFile, "loadConfigFile");
|
|
10442
|
-
function resolveEnvVars(config) {
|
|
10443
|
-
const resolved = JSON.parse(JSON.stringify(config));
|
|
10444
|
-
if (process.env.AWS_ACCESS_KEY_ID) {
|
|
10445
|
-
resolved.accessKey = process.env.AWS_ACCESS_KEY_ID;
|
|
10446
|
-
}
|
|
10447
|
-
if (process.env.AWS_SECRET_ACCESS_KEY) {
|
|
10448
|
-
resolved.secretKey = process.env.AWS_SECRET_ACCESS_KEY;
|
|
10449
|
-
}
|
|
10450
|
-
if (process.env.AWS_SESSION_TOKEN) {
|
|
10451
|
-
resolved.sessionToken = process.env.AWS_SESSION_TOKEN;
|
|
10452
|
-
}
|
|
10453
|
-
if (process.env.AWS_REGION) {
|
|
10454
|
-
resolved.region = process.env.AWS_REGION;
|
|
10455
|
-
}
|
|
10456
|
-
if (process.env.AWS_PROFILE) {
|
|
10457
|
-
resolved.profile = process.env.AWS_PROFILE;
|
|
10868
|
+
});
|
|
10869
|
+
chargeback_default = router4;
|
|
10458
10870
|
}
|
|
10459
|
-
|
|
10460
|
-
|
|
10461
|
-
|
|
10462
|
-
|
|
10463
|
-
|
|
10464
|
-
|
|
10465
|
-
|
|
10871
|
+
});
|
|
10872
|
+
|
|
10873
|
+
// src/api/routes/forecast.ts
|
|
10874
|
+
var forecast_exports = {};
|
|
10875
|
+
__export(forecast_exports, {
|
|
10876
|
+
default: () => forecast_default
|
|
10877
|
+
});
|
|
10878
|
+
var import_express5, router5, forecast_default;
|
|
10879
|
+
var init_forecast = __esm({
|
|
10880
|
+
"src/api/routes/forecast.ts"() {
|
|
10881
|
+
import_express5 = require("express");
|
|
10882
|
+
init_server();
|
|
10883
|
+
router5 = (0, import_express5.Router)();
|
|
10884
|
+
router5.get("/", async (req, res) => {
|
|
10885
|
+
try {
|
|
10886
|
+
const { days = 30 } = req.query;
|
|
10887
|
+
const daysNum = parseInt(days, 10);
|
|
10888
|
+
const currentDailyAverage = 150;
|
|
10889
|
+
const projectedDaily = currentDailyAverage * 1.05;
|
|
10890
|
+
const forecast = [];
|
|
10891
|
+
for (let i = 1; i <= daysNum; i++) {
|
|
10892
|
+
const date = /* @__PURE__ */ new Date();
|
|
10893
|
+
date.setDate(date.getDate() + i);
|
|
10894
|
+
forecast.push({
|
|
10895
|
+
date: date.toISOString().split("T")[0],
|
|
10896
|
+
projected: projectedDaily,
|
|
10897
|
+
confidence: Math.max(0.9 - i * 0.01, 0.5)
|
|
10898
|
+
// Decreasing confidence
|
|
10899
|
+
});
|
|
10900
|
+
}
|
|
10901
|
+
const totalProjected = projectedDaily * daysNum;
|
|
10902
|
+
res.json(
|
|
10903
|
+
createApiResponse({
|
|
10904
|
+
forecast,
|
|
10905
|
+
summary: {
|
|
10906
|
+
totalProjected,
|
|
10907
|
+
averageDaily: projectedDaily,
|
|
10908
|
+
period: {
|
|
10909
|
+
days: daysNum,
|
|
10910
|
+
start: (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
10911
|
+
end: forecast[forecast.length - 1].date
|
|
10912
|
+
}
|
|
10913
|
+
},
|
|
10914
|
+
model: "linear-growth",
|
|
10915
|
+
confidence: 0.75
|
|
10916
|
+
})
|
|
10917
|
+
);
|
|
10918
|
+
} catch (error) {
|
|
10919
|
+
res.status(500).json(createErrorResponse("FORECAST_ERROR", error.message));
|
|
10920
|
+
}
|
|
10921
|
+
});
|
|
10922
|
+
forecast_default = router5;
|
|
10466
10923
|
}
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10924
|
+
});
|
|
10925
|
+
|
|
10926
|
+
// src/api/routes/accounts.ts
|
|
10927
|
+
var accounts_exports = {};
|
|
10928
|
+
__export(accounts_exports, {
|
|
10929
|
+
default: () => accounts_default
|
|
10930
|
+
});
|
|
10931
|
+
var import_express6, router6, accounts_default;
|
|
10932
|
+
var init_accounts = __esm({
|
|
10933
|
+
"src/api/routes/accounts.ts"() {
|
|
10934
|
+
import_express6 = require("express");
|
|
10935
|
+
init_utils();
|
|
10936
|
+
init_server();
|
|
10937
|
+
router6 = (0, import_express6.Router)();
|
|
10938
|
+
router6.get("/", async (req, res) => {
|
|
10939
|
+
try {
|
|
10940
|
+
const config = getConfig2();
|
|
10941
|
+
const provider = await getProviderFromConfig();
|
|
10942
|
+
const accountInfo = await provider.getAccountInfo();
|
|
10943
|
+
const accounts = [
|
|
10944
|
+
{
|
|
10945
|
+
id: accountInfo.accountId,
|
|
10946
|
+
name: accountInfo.accountAlias || accountInfo.accountId,
|
|
10947
|
+
provider: config.provider,
|
|
10948
|
+
region: accountInfo.region
|
|
10949
|
+
}
|
|
10950
|
+
];
|
|
10951
|
+
res.json(
|
|
10952
|
+
createApiResponse({
|
|
10953
|
+
accounts,
|
|
10954
|
+
count: accounts.length
|
|
10955
|
+
})
|
|
10956
|
+
);
|
|
10957
|
+
} catch (error) {
|
|
10958
|
+
res.status(500).json(createErrorResponse("FETCH_ERROR", error.message));
|
|
10476
10959
|
}
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10960
|
+
});
|
|
10961
|
+
router6.get("/:id/costs", async (req, res) => {
|
|
10962
|
+
try {
|
|
10963
|
+
const config = getConfig2();
|
|
10964
|
+
const provider = await getProviderFromConfig();
|
|
10965
|
+
const { id } = req.params;
|
|
10966
|
+
const accountInfo = await provider.getAccountInfo();
|
|
10967
|
+
if (accountInfo.accountId !== id) {
|
|
10968
|
+
return res.status(404).json(createErrorResponse("NOT_FOUND", `Account ${id} not found`));
|
|
10969
|
+
}
|
|
10970
|
+
const now = /* @__PURE__ */ new Date();
|
|
10971
|
+
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
10972
|
+
const costs = await provider.getCostBreakdown(monthStart, now, "SERVICE");
|
|
10973
|
+
res.json(
|
|
10974
|
+
createApiResponse({
|
|
10975
|
+
accountId: id,
|
|
10976
|
+
costs: {
|
|
10977
|
+
total: costs.totalCost,
|
|
10978
|
+
breakdown: costs.breakdown
|
|
10979
|
+
},
|
|
10980
|
+
period: {
|
|
10981
|
+
start: monthStart.toISOString(),
|
|
10982
|
+
end: now.toISOString()
|
|
10983
|
+
}
|
|
10984
|
+
})
|
|
10985
|
+
);
|
|
10986
|
+
} catch (error) {
|
|
10987
|
+
res.status(500).json(createErrorResponse("FETCH_ERROR", error.message));
|
|
10481
10988
|
}
|
|
10482
|
-
}
|
|
10989
|
+
});
|
|
10990
|
+
accounts_default = router6;
|
|
10483
10991
|
}
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10992
|
+
});
|
|
10993
|
+
|
|
10994
|
+
// src/api/routes/reports.ts
|
|
10995
|
+
var reports_exports2 = {};
|
|
10996
|
+
__export(reports_exports2, {
|
|
10997
|
+
default: () => reports_default
|
|
10998
|
+
});
|
|
10999
|
+
var import_express7, router7, reports_default;
|
|
11000
|
+
var init_reports2 = __esm({
|
|
11001
|
+
"src/api/routes/reports.ts"() {
|
|
11002
|
+
import_express7 = require("express");
|
|
11003
|
+
init_utils();
|
|
11004
|
+
init_server();
|
|
11005
|
+
router7 = (0, import_express7.Router)();
|
|
11006
|
+
router7.post("/generate", async (req, res) => {
|
|
11007
|
+
try {
|
|
11008
|
+
const {
|
|
11009
|
+
reportType = "summary",
|
|
11010
|
+
startDate,
|
|
11011
|
+
endDate,
|
|
11012
|
+
format = "json",
|
|
11013
|
+
groupBy = "service"
|
|
11014
|
+
} = req.body;
|
|
11015
|
+
const config = getConfig2();
|
|
11016
|
+
const provider = await getProviderFromConfig();
|
|
11017
|
+
const start = startDate ? new Date(startDate) : /* @__PURE__ */ new Date();
|
|
11018
|
+
const end = endDate ? new Date(endDate) : /* @__PURE__ */ new Date();
|
|
11019
|
+
let groupByType = "SERVICE";
|
|
11020
|
+
if (groupBy === "tag")
|
|
11021
|
+
groupByType = "TAG";
|
|
11022
|
+
else if (groupBy === "daily")
|
|
11023
|
+
groupByType = "DAILY";
|
|
11024
|
+
else if (groupBy === "monthly")
|
|
11025
|
+
groupByType = "MONTHLY";
|
|
11026
|
+
const breakdown = await provider.getCostBreakdown(start, end, groupByType);
|
|
11027
|
+
const report = {
|
|
11028
|
+
reportType,
|
|
11029
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
11030
|
+
period: {
|
|
11031
|
+
start: start.toISOString(),
|
|
11032
|
+
end: end.toISOString()
|
|
11033
|
+
},
|
|
11034
|
+
data: {
|
|
11035
|
+
total: breakdown.totalCost,
|
|
11036
|
+
breakdown: breakdown.breakdown,
|
|
11037
|
+
groupBy
|
|
11038
|
+
},
|
|
11039
|
+
format
|
|
11040
|
+
};
|
|
11041
|
+
res.json(createApiResponse(report));
|
|
11042
|
+
} catch (error) {
|
|
11043
|
+
res.status(500).json(createErrorResponse("REPORT_ERROR", error.message));
|
|
11044
|
+
}
|
|
11045
|
+
});
|
|
11046
|
+
reports_default = router7;
|
|
10493
11047
|
}
|
|
10494
|
-
|
|
10495
|
-
|
|
10496
|
-
|
|
10497
|
-
|
|
11048
|
+
});
|
|
11049
|
+
|
|
11050
|
+
// src/api/server.ts
|
|
11051
|
+
function createApiResponse(data) {
|
|
11052
|
+
return {
|
|
11053
|
+
status: "success",
|
|
11054
|
+
data,
|
|
11055
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
11056
|
+
};
|
|
10498
11057
|
}
|
|
10499
|
-
|
|
10500
|
-
|
|
10501
|
-
|
|
10502
|
-
|
|
10503
|
-
|
|
10504
|
-
|
|
10505
|
-
config.profile = options.profile;
|
|
10506
|
-
if (options.region)
|
|
10507
|
-
config.region = options.region;
|
|
10508
|
-
if (options.accessKey)
|
|
10509
|
-
config.accessKey = options.accessKey;
|
|
10510
|
-
if (options.secretKey)
|
|
10511
|
-
config.secretKey = options.secretKey;
|
|
10512
|
-
if (options.sessionToken)
|
|
10513
|
-
config.sessionToken = options.sessionToken;
|
|
10514
|
-
if (options.json || options.text || options.summary) {
|
|
10515
|
-
config.output = config.output || {};
|
|
10516
|
-
if (options.json)
|
|
10517
|
-
config.output.format = "json";
|
|
10518
|
-
if (options.text)
|
|
10519
|
-
config.output.format = "text";
|
|
10520
|
-
if (options.summary)
|
|
10521
|
-
config.output.summary = true;
|
|
10522
|
-
}
|
|
10523
|
-
if (options.delta !== void 0) {
|
|
10524
|
-
config.output = config.output || {};
|
|
10525
|
-
config.output.showDelta = options.delta;
|
|
10526
|
-
}
|
|
10527
|
-
if (options.deltaThreshold) {
|
|
10528
|
-
config.output = config.output || {};
|
|
10529
|
-
config.output.deltaThreshold = parseFloat(options.deltaThreshold);
|
|
10530
|
-
}
|
|
10531
|
-
if (options.quickWins !== void 0) {
|
|
10532
|
-
config.output = config.output || {};
|
|
10533
|
-
config.output.showQuickWins = options.quickWins;
|
|
10534
|
-
}
|
|
10535
|
-
if (options.quickWinsCount) {
|
|
10536
|
-
config.output = config.output || {};
|
|
10537
|
-
config.output.quickWinsCount = parseInt(options.quickWinsCount, 10);
|
|
10538
|
-
}
|
|
10539
|
-
if (options.cache !== void 0 || options.noCache !== void 0) {
|
|
10540
|
-
config.cache = config.cache || {};
|
|
10541
|
-
config.cache.enabled = options.cache === true || options.noCache !== true;
|
|
10542
|
-
}
|
|
10543
|
-
if (options.cacheTtl) {
|
|
10544
|
-
config.cache = config.cache || {};
|
|
10545
|
-
config.cache.ttl = options.cacheTtl;
|
|
10546
|
-
}
|
|
10547
|
-
if (options.cacheType) {
|
|
10548
|
-
config.cache = config.cache || {};
|
|
10549
|
-
config.cache.type = options.cacheType;
|
|
10550
|
-
}
|
|
10551
|
-
if (options.slackToken || options.slackChannel) {
|
|
10552
|
-
config.slack = config.slack || {};
|
|
10553
|
-
if (options.slackToken)
|
|
10554
|
-
config.slack.token = options.slackToken;
|
|
10555
|
-
if (options.slackChannel)
|
|
10556
|
-
config.slack.channel = options.slackChannel;
|
|
10557
|
-
config.slack.enabled = true;
|
|
10558
|
-
}
|
|
10559
|
-
if (options.logLevel || options.verbose || options.quiet) {
|
|
10560
|
-
config.logging = config.logging || {};
|
|
10561
|
-
if (options.logLevel)
|
|
10562
|
-
config.logging.level = options.logLevel;
|
|
10563
|
-
if (options.verbose)
|
|
10564
|
-
config.logging.level = "debug";
|
|
10565
|
-
if (options.quiet)
|
|
10566
|
-
config.logging.level = "error";
|
|
10567
|
-
}
|
|
10568
|
-
return config;
|
|
11058
|
+
function createErrorResponse(code, message) {
|
|
11059
|
+
return {
|
|
11060
|
+
status: "error",
|
|
11061
|
+
error: { code, message },
|
|
11062
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
11063
|
+
};
|
|
10569
11064
|
}
|
|
10570
|
-
|
|
11065
|
+
var import_express8, import_cors, import_express_rate_limit, import_helmet, cache, ApiServer;
|
|
11066
|
+
var init_server = __esm({
|
|
11067
|
+
"src/api/server.ts"() {
|
|
11068
|
+
import_express8 = __toESM(require("express"));
|
|
11069
|
+
import_cors = __toESM(require("cors"));
|
|
11070
|
+
import_express_rate_limit = __toESM(require("express-rate-limit"));
|
|
11071
|
+
import_helmet = __toESM(require("helmet"));
|
|
11072
|
+
cache = /* @__PURE__ */ new Map();
|
|
11073
|
+
ApiServer = class {
|
|
11074
|
+
constructor(config) {
|
|
11075
|
+
this.config = config;
|
|
11076
|
+
this.app = (0, import_express8.default)();
|
|
11077
|
+
this.setupMiddleware();
|
|
11078
|
+
this.setupRoutes();
|
|
11079
|
+
}
|
|
11080
|
+
setupMiddleware() {
|
|
11081
|
+
this.app.use((0, import_helmet.default)());
|
|
11082
|
+
this.app.use(import_express8.default.json());
|
|
11083
|
+
if (this.config.cors.enabled) {
|
|
11084
|
+
this.app.use(
|
|
11085
|
+
(0, import_cors.default)({
|
|
11086
|
+
origin: this.config.cors.origins || "*",
|
|
11087
|
+
methods: ["GET", "POST", "PUT", "DELETE"],
|
|
11088
|
+
credentials: true
|
|
11089
|
+
})
|
|
11090
|
+
);
|
|
11091
|
+
}
|
|
11092
|
+
if (this.config.rateLimit.enabled) {
|
|
11093
|
+
const limiter = (0, import_express_rate_limit.default)({
|
|
11094
|
+
windowMs: this.config.rateLimit.windowMs,
|
|
11095
|
+
max: this.config.rateLimit.max,
|
|
11096
|
+
message: {
|
|
11097
|
+
status: "error",
|
|
11098
|
+
error: {
|
|
11099
|
+
code: "RATE_LIMIT_EXCEEDED",
|
|
11100
|
+
message: "Too many requests, please try again later."
|
|
11101
|
+
},
|
|
11102
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
11103
|
+
}
|
|
11104
|
+
});
|
|
11105
|
+
this.app.use("/api/", limiter);
|
|
11106
|
+
}
|
|
11107
|
+
this.app.use("/api/", this.authMiddleware.bind(this));
|
|
11108
|
+
if (this.config.cache.enabled) {
|
|
11109
|
+
this.app.use("/api/", this.cacheMiddleware.bind(this));
|
|
11110
|
+
}
|
|
11111
|
+
}
|
|
11112
|
+
authMiddleware(req, res, next) {
|
|
11113
|
+
if (req.path === "/api/v1/health") {
|
|
11114
|
+
return next();
|
|
11115
|
+
}
|
|
11116
|
+
if (this.config.auth.type === "none") {
|
|
11117
|
+
return next();
|
|
11118
|
+
}
|
|
11119
|
+
if (this.config.auth.type === "api-key") {
|
|
11120
|
+
const apiKey = req.headers["x-api-key"] || req.query.apiKey;
|
|
11121
|
+
if (!apiKey || !this.config.auth.apiKeys?.includes(apiKey)) {
|
|
11122
|
+
return res.status(401).json({
|
|
11123
|
+
status: "error",
|
|
11124
|
+
error: {
|
|
11125
|
+
code: "UNAUTHORIZED",
|
|
11126
|
+
message: "Invalid or missing API key"
|
|
11127
|
+
},
|
|
11128
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
11129
|
+
});
|
|
11130
|
+
}
|
|
11131
|
+
}
|
|
11132
|
+
next();
|
|
11133
|
+
}
|
|
11134
|
+
cacheMiddleware(req, res, next) {
|
|
11135
|
+
if (req.method !== "GET") {
|
|
11136
|
+
return next();
|
|
11137
|
+
}
|
|
11138
|
+
const key = `${req.method}:${req.path}:${JSON.stringify(req.query)}`;
|
|
11139
|
+
const cached = cache.get(key);
|
|
11140
|
+
if (cached && cached.expiry > Date.now()) {
|
|
11141
|
+
return res.json(cached.data);
|
|
11142
|
+
}
|
|
11143
|
+
const originalJson = res.json.bind(res);
|
|
11144
|
+
res.json = (body) => {
|
|
11145
|
+
if (res.statusCode === 200) {
|
|
11146
|
+
cache.set(key, {
|
|
11147
|
+
data: body,
|
|
11148
|
+
expiry: Date.now() + this.config.cache.ttl * 1e3
|
|
11149
|
+
});
|
|
11150
|
+
}
|
|
11151
|
+
return originalJson(body);
|
|
11152
|
+
};
|
|
11153
|
+
next();
|
|
11154
|
+
}
|
|
11155
|
+
setupRoutes() {
|
|
11156
|
+
this.app.get("/api/v1/health", (_req, res) => {
|
|
11157
|
+
res.json({
|
|
11158
|
+
status: "success",
|
|
11159
|
+
data: {
|
|
11160
|
+
healthy: true,
|
|
11161
|
+
version: require_package().version,
|
|
11162
|
+
uptime: process.uptime()
|
|
11163
|
+
},
|
|
11164
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
11165
|
+
});
|
|
11166
|
+
});
|
|
11167
|
+
this.app.use("/api/v1/costs", (init_costs2(), __toCommonJS(costs_exports2)).default);
|
|
11168
|
+
this.app.use("/api/v1/inventory", (init_inventory6(), __toCommonJS(inventory_exports2)).default);
|
|
11169
|
+
this.app.use("/api/v1/optimization", (init_optimization(), __toCommonJS(optimization_exports)).default);
|
|
11170
|
+
this.app.use("/api/v1/chargeback", (init_chargeback(), __toCommonJS(chargeback_exports)).default);
|
|
11171
|
+
this.app.use("/api/v1/forecast", (init_forecast(), __toCommonJS(forecast_exports)).default);
|
|
11172
|
+
this.app.use("/api/v1/accounts", (init_accounts(), __toCommonJS(accounts_exports)).default);
|
|
11173
|
+
this.app.use("/api/v1/reports", (init_reports2(), __toCommonJS(reports_exports2)).default);
|
|
11174
|
+
this.app.use((_req, res) => {
|
|
11175
|
+
res.status(404).json({
|
|
11176
|
+
status: "error",
|
|
11177
|
+
error: {
|
|
11178
|
+
code: "NOT_FOUND",
|
|
11179
|
+
message: "API endpoint not found"
|
|
11180
|
+
},
|
|
11181
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
11182
|
+
});
|
|
11183
|
+
});
|
|
11184
|
+
this.app.use((err, _req, res, _next) => {
|
|
11185
|
+
console.error("API Error:", err);
|
|
11186
|
+
res.status(500).json({
|
|
11187
|
+
status: "error",
|
|
11188
|
+
error: {
|
|
11189
|
+
code: "INTERNAL_ERROR",
|
|
11190
|
+
message: err.message || "Internal server error"
|
|
11191
|
+
},
|
|
11192
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
11193
|
+
});
|
|
11194
|
+
});
|
|
11195
|
+
}
|
|
11196
|
+
async start() {
|
|
11197
|
+
return new Promise((resolve2, reject) => {
|
|
11198
|
+
try {
|
|
11199
|
+
this.server = this.app.listen(this.config.port, this.config.host, () => {
|
|
11200
|
+
console.log(
|
|
11201
|
+
`\u2705 API Server running at http://${this.config.host}:${this.config.port}`
|
|
11202
|
+
);
|
|
11203
|
+
console.log(`\u{1F4D6} API Documentation: http://${this.config.host}:${this.config.port}/api/docs`);
|
|
11204
|
+
resolve2();
|
|
11205
|
+
});
|
|
11206
|
+
this.server.on("error", reject);
|
|
11207
|
+
} catch (error) {
|
|
11208
|
+
reject(error);
|
|
11209
|
+
}
|
|
11210
|
+
});
|
|
11211
|
+
}
|
|
11212
|
+
async stop() {
|
|
11213
|
+
return new Promise((resolve2, reject) => {
|
|
11214
|
+
if (!this.server) {
|
|
11215
|
+
resolve2();
|
|
11216
|
+
return;
|
|
11217
|
+
}
|
|
11218
|
+
this.server.close((err) => {
|
|
11219
|
+
if (err) {
|
|
11220
|
+
reject(err);
|
|
11221
|
+
} else {
|
|
11222
|
+
console.log("API Server stopped");
|
|
11223
|
+
resolve2();
|
|
11224
|
+
}
|
|
11225
|
+
});
|
|
11226
|
+
});
|
|
11227
|
+
}
|
|
11228
|
+
getApp() {
|
|
11229
|
+
return this.app;
|
|
11230
|
+
}
|
|
11231
|
+
};
|
|
11232
|
+
__name(ApiServer, "ApiServer");
|
|
11233
|
+
__name(createApiResponse, "createApiResponse");
|
|
11234
|
+
__name(createErrorResponse, "createErrorResponse");
|
|
11235
|
+
}
|
|
11236
|
+
});
|
|
11237
|
+
|
|
11238
|
+
// src/cli/index.ts
|
|
11239
|
+
var import_commander = require("commander");
|
|
11240
|
+
var import_package = __toESM(require_package());
|
|
11241
|
+
init_logging();
|
|
11242
|
+
|
|
11243
|
+
// src/core/config/index.ts
|
|
11244
|
+
init_schema();
|
|
11245
|
+
init_loader();
|
|
10571
11246
|
|
|
10572
11247
|
// src/core/config/discovery.ts
|
|
10573
11248
|
var import_chalk2 = __toESM(require("chalk"));
|
|
@@ -13881,6 +14556,661 @@ function registerPluginCommands(program) {
|
|
|
13881
14556
|
}
|
|
13882
14557
|
__name(registerPluginCommands, "registerPluginCommands");
|
|
13883
14558
|
|
|
14559
|
+
// src/cli/commands/server/index.ts
|
|
14560
|
+
var import_chalk22 = __toESM(require("chalk"));
|
|
14561
|
+
var import_fs8 = require("fs");
|
|
14562
|
+
var import_path7 = require("path");
|
|
14563
|
+
var import_os7 = require("os");
|
|
14564
|
+
init_server();
|
|
14565
|
+
var CONFIG_DIR4 = (0, import_path7.join)((0, import_os7.homedir)(), ".infra-cost");
|
|
14566
|
+
var SERVER_CONFIG_PATH = (0, import_path7.join)(CONFIG_DIR4, "server-config.json");
|
|
14567
|
+
var PID_FILE2 = (0, import_path7.join)(CONFIG_DIR4, "server.pid");
|
|
14568
|
+
var DEFAULT_CONFIG3 = {
|
|
14569
|
+
port: 3e3,
|
|
14570
|
+
host: "127.0.0.1",
|
|
14571
|
+
cors: {
|
|
14572
|
+
enabled: true,
|
|
14573
|
+
origins: ["*"]
|
|
14574
|
+
},
|
|
14575
|
+
auth: {
|
|
14576
|
+
type: "none"
|
|
14577
|
+
},
|
|
14578
|
+
rateLimit: {
|
|
14579
|
+
enabled: true,
|
|
14580
|
+
windowMs: 6e4,
|
|
14581
|
+
max: 100
|
|
14582
|
+
},
|
|
14583
|
+
cache: {
|
|
14584
|
+
enabled: true,
|
|
14585
|
+
ttl: 300
|
|
14586
|
+
// 5 minutes
|
|
14587
|
+
}
|
|
14588
|
+
};
|
|
14589
|
+
function loadServerConfig() {
|
|
14590
|
+
if ((0, import_fs8.existsSync)(SERVER_CONFIG_PATH)) {
|
|
14591
|
+
const config = JSON.parse((0, import_fs8.readFileSync)(SERVER_CONFIG_PATH, "utf-8"));
|
|
14592
|
+
return { ...DEFAULT_CONFIG3, ...config };
|
|
14593
|
+
}
|
|
14594
|
+
return DEFAULT_CONFIG3;
|
|
14595
|
+
}
|
|
14596
|
+
__name(loadServerConfig, "loadServerConfig");
|
|
14597
|
+
function saveServerConfig(config) {
|
|
14598
|
+
(0, import_fs8.writeFileSync)(SERVER_CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
14599
|
+
}
|
|
14600
|
+
__name(saveServerConfig, "saveServerConfig");
|
|
14601
|
+
async function handleStart2(options) {
|
|
14602
|
+
try {
|
|
14603
|
+
if ((0, import_fs8.existsSync)(PID_FILE2)) {
|
|
14604
|
+
const pid = parseInt((0, import_fs8.readFileSync)(PID_FILE2, "utf-8").trim(), 10);
|
|
14605
|
+
try {
|
|
14606
|
+
process.kill(pid, 0);
|
|
14607
|
+
console.log(import_chalk22.default.yellow("\u26A0\uFE0F Server is already running"));
|
|
14608
|
+
console.log(import_chalk22.default.gray(` PID: ${pid}`));
|
|
14609
|
+
return;
|
|
14610
|
+
} catch {
|
|
14611
|
+
require("fs").unlinkSync(PID_FILE2);
|
|
14612
|
+
}
|
|
14613
|
+
}
|
|
14614
|
+
const config = loadServerConfig();
|
|
14615
|
+
if (options.port)
|
|
14616
|
+
config.port = parseInt(options.port, 10);
|
|
14617
|
+
if (options.host)
|
|
14618
|
+
config.host = options.host;
|
|
14619
|
+
if (options.apiKey) {
|
|
14620
|
+
config.auth = {
|
|
14621
|
+
type: "api-key",
|
|
14622
|
+
apiKeys: [options.apiKey]
|
|
14623
|
+
};
|
|
14624
|
+
}
|
|
14625
|
+
if (options.apiKeyRequired && !options.apiKey) {
|
|
14626
|
+
console.log(import_chalk22.default.red("\u274C --api-key is required when --api-key-required is set"));
|
|
14627
|
+
process.exit(1);
|
|
14628
|
+
}
|
|
14629
|
+
const server = new ApiServer(config);
|
|
14630
|
+
if (options.daemon) {
|
|
14631
|
+
console.log(import_chalk22.default.blue("Starting server in daemon mode..."));
|
|
14632
|
+
const { spawn } = require("child_process");
|
|
14633
|
+
const child = spawn(
|
|
14634
|
+
process.argv[0],
|
|
14635
|
+
[process.argv[1], "server", "start", "--port", config.port.toString(), "--host", config.host],
|
|
14636
|
+
{
|
|
14637
|
+
detached: true,
|
|
14638
|
+
stdio: "ignore"
|
|
14639
|
+
}
|
|
14640
|
+
);
|
|
14641
|
+
child.unref();
|
|
14642
|
+
(0, import_fs8.writeFileSync)(PID_FILE2, child.pid.toString());
|
|
14643
|
+
console.log(import_chalk22.default.green("\u2705 Server started in background"));
|
|
14644
|
+
console.log(import_chalk22.default.gray(` PID: ${child.pid}`));
|
|
14645
|
+
console.log(import_chalk22.default.gray(` URL: http://${config.host}:${config.port}`));
|
|
14646
|
+
return;
|
|
14647
|
+
}
|
|
14648
|
+
await server.start();
|
|
14649
|
+
(0, import_fs8.writeFileSync)(PID_FILE2, process.pid.toString());
|
|
14650
|
+
console.log();
|
|
14651
|
+
console.log(import_chalk22.default.bold("Server Configuration:"));
|
|
14652
|
+
console.log(import_chalk22.default.gray(` Port: ${config.port}`));
|
|
14653
|
+
console.log(import_chalk22.default.gray(` Host: ${config.host}`));
|
|
14654
|
+
console.log(import_chalk22.default.gray(` Auth: ${config.auth.type}`));
|
|
14655
|
+
console.log(import_chalk22.default.gray(` Rate Limit: ${config.rateLimit.enabled ? "enabled" : "disabled"}`));
|
|
14656
|
+
console.log(import_chalk22.default.gray(` Cache: ${config.cache.enabled ? `${config.cache.ttl}s` : "disabled"}`));
|
|
14657
|
+
console.log();
|
|
14658
|
+
if (config.auth.type === "api-key") {
|
|
14659
|
+
console.log(import_chalk22.default.yellow("\u26A0\uFE0F API Key Authentication Enabled"));
|
|
14660
|
+
console.log(import_chalk22.default.gray(" Use header: X-API-Key: your-api-key"));
|
|
14661
|
+
console.log();
|
|
14662
|
+
}
|
|
14663
|
+
console.log(import_chalk22.default.green("Press Ctrl+C to stop the server"));
|
|
14664
|
+
const shutdown = /* @__PURE__ */ __name(async () => {
|
|
14665
|
+
console.log(import_chalk22.default.yellow("\n\nShutting down server..."));
|
|
14666
|
+
await server.stop();
|
|
14667
|
+
if ((0, import_fs8.existsSync)(PID_FILE2)) {
|
|
14668
|
+
require("fs").unlinkSync(PID_FILE2);
|
|
14669
|
+
}
|
|
14670
|
+
process.exit(0);
|
|
14671
|
+
}, "shutdown");
|
|
14672
|
+
process.on("SIGINT", shutdown);
|
|
14673
|
+
process.on("SIGTERM", shutdown);
|
|
14674
|
+
} catch (error) {
|
|
14675
|
+
console.error(import_chalk22.default.red("\u274C Failed to start server:"), error.message);
|
|
14676
|
+
process.exit(1);
|
|
14677
|
+
}
|
|
14678
|
+
}
|
|
14679
|
+
__name(handleStart2, "handleStart");
|
|
14680
|
+
async function handleStop2() {
|
|
14681
|
+
try {
|
|
14682
|
+
if (!(0, import_fs8.existsSync)(PID_FILE2)) {
|
|
14683
|
+
console.log(import_chalk22.default.yellow("\u26A0\uFE0F Server is not running"));
|
|
14684
|
+
return;
|
|
14685
|
+
}
|
|
14686
|
+
const pid = parseInt((0, import_fs8.readFileSync)(PID_FILE2, "utf-8").trim(), 10);
|
|
14687
|
+
try {
|
|
14688
|
+
process.kill(pid, "SIGTERM");
|
|
14689
|
+
console.log(import_chalk22.default.green("\u2705 Server stopped"));
|
|
14690
|
+
setTimeout(() => {
|
|
14691
|
+
if ((0, import_fs8.existsSync)(PID_FILE2)) {
|
|
14692
|
+
require("fs").unlinkSync(PID_FILE2);
|
|
14693
|
+
}
|
|
14694
|
+
}, 1e3);
|
|
14695
|
+
} catch {
|
|
14696
|
+
console.log(import_chalk22.default.yellow("\u26A0\uFE0F Server process not found"));
|
|
14697
|
+
if ((0, import_fs8.existsSync)(PID_FILE2)) {
|
|
14698
|
+
require("fs").unlinkSync(PID_FILE2);
|
|
14699
|
+
}
|
|
14700
|
+
}
|
|
14701
|
+
} catch (error) {
|
|
14702
|
+
console.error(import_chalk22.default.red("\u274C Failed to stop server:"), error.message);
|
|
14703
|
+
process.exit(1);
|
|
14704
|
+
}
|
|
14705
|
+
}
|
|
14706
|
+
__name(handleStop2, "handleStop");
|
|
14707
|
+
async function handleStatus3() {
|
|
14708
|
+
try {
|
|
14709
|
+
if (!(0, import_fs8.existsSync)(PID_FILE2)) {
|
|
14710
|
+
console.log(import_chalk22.default.yellow("\u26A0\uFE0F Server is not running"));
|
|
14711
|
+
return;
|
|
14712
|
+
}
|
|
14713
|
+
const pid = parseInt((0, import_fs8.readFileSync)(PID_FILE2, "utf-8").trim(), 10);
|
|
14714
|
+
try {
|
|
14715
|
+
process.kill(pid, 0);
|
|
14716
|
+
const config = loadServerConfig();
|
|
14717
|
+
console.log(import_chalk22.default.green("\u2705 Server is running"));
|
|
14718
|
+
console.log(import_chalk22.default.gray(` PID: ${pid}`));
|
|
14719
|
+
console.log(import_chalk22.default.gray(` URL: http://${config.host}:${config.port}`));
|
|
14720
|
+
console.log(import_chalk22.default.gray(` Docs: http://${config.host}:${config.port}/api/docs`));
|
|
14721
|
+
} catch {
|
|
14722
|
+
console.log(import_chalk22.default.yellow("\u26A0\uFE0F Server is not running (stale PID file)"));
|
|
14723
|
+
require("fs").unlinkSync(PID_FILE2);
|
|
14724
|
+
}
|
|
14725
|
+
} catch (error) {
|
|
14726
|
+
console.error(import_chalk22.default.red("\u274C Failed to check status:"), error.message);
|
|
14727
|
+
process.exit(1);
|
|
14728
|
+
}
|
|
14729
|
+
}
|
|
14730
|
+
__name(handleStatus3, "handleStatus");
|
|
14731
|
+
async function handleConfigure2(options) {
|
|
14732
|
+
try {
|
|
14733
|
+
const config = loadServerConfig();
|
|
14734
|
+
if (options.port)
|
|
14735
|
+
config.port = parseInt(options.port, 10);
|
|
14736
|
+
if (options.host)
|
|
14737
|
+
config.host = options.host;
|
|
14738
|
+
if (options.enableCors !== void 0)
|
|
14739
|
+
config.cors.enabled = options.enableCors === "true";
|
|
14740
|
+
if (options.cacheEnabled !== void 0)
|
|
14741
|
+
config.cache.enabled = options.cacheEnabled === "true";
|
|
14742
|
+
if (options.cacheTtl)
|
|
14743
|
+
config.cache.ttl = parseInt(options.cacheTtl, 10);
|
|
14744
|
+
saveServerConfig(config);
|
|
14745
|
+
console.log(import_chalk22.default.green("\u2705 Server configuration updated"));
|
|
14746
|
+
console.log();
|
|
14747
|
+
console.log(JSON.stringify(config, null, 2));
|
|
14748
|
+
} catch (error) {
|
|
14749
|
+
console.error(import_chalk22.default.red("\u274C Failed to configure server:"), error.message);
|
|
14750
|
+
process.exit(1);
|
|
14751
|
+
}
|
|
14752
|
+
}
|
|
14753
|
+
__name(handleConfigure2, "handleConfigure");
|
|
14754
|
+
function registerServerCommands(program) {
|
|
14755
|
+
const server = program.command("server").description("API server mode for REST API access");
|
|
14756
|
+
server.command("start").description("Start the API server").option("-p, --port <port>", "Port to listen on", "3000").option("-h, --host <host>", "Host to bind to", "127.0.0.1").option("--api-key <key>", "API key for authentication").option("--api-key-required", "Require API key authentication").option("-d, --daemon", "Run in background/daemon mode").action(handleStart2);
|
|
14757
|
+
server.command("stop").description("Stop the running API server").action(handleStop2);
|
|
14758
|
+
server.command("status").description("Check server status").action(handleStatus3);
|
|
14759
|
+
server.command("configure").description("Configure server settings").option("-p, --port <port>", "Default port").option("-h, --host <host>", "Default host").option("--enable-cors <boolean>", "Enable/disable CORS").option("--cache-enabled <boolean>", "Enable/disable caching").option("--cache-ttl <seconds>", "Cache TTL in seconds").action(handleConfigure2);
|
|
14760
|
+
}
|
|
14761
|
+
__name(registerServerCommands, "registerServerCommands");
|
|
14762
|
+
|
|
14763
|
+
// src/cli/commands/scorecard/index.ts
|
|
14764
|
+
var import_chalk23 = __toESM(require("chalk"));
|
|
14765
|
+
var import_cli_table32 = __toESM(require("cli-table3"));
|
|
14766
|
+
|
|
14767
|
+
// src/core/scorecard.ts
|
|
14768
|
+
var DEFAULT_SCORECARD_CONFIG = {
|
|
14769
|
+
enabled: true,
|
|
14770
|
+
categories: {
|
|
14771
|
+
budgetAdherence: { weight: 25, target: 80 },
|
|
14772
|
+
costEfficiency: { weight: 20, target: 0 },
|
|
14773
|
+
taggingCompliance: { weight: 15, target: 90 },
|
|
14774
|
+
reservedCoverage: { weight: 15, target: 70 },
|
|
14775
|
+
wasteElimination: { weight: 15, target: 80 },
|
|
14776
|
+
optimizationActions: { weight: 10, target: 80 }
|
|
14777
|
+
},
|
|
14778
|
+
gradingScale: {
|
|
14779
|
+
A: 90,
|
|
14780
|
+
B: 80,
|
|
14781
|
+
C: 70,
|
|
14782
|
+
D: 60
|
|
14783
|
+
},
|
|
14784
|
+
notifications: {
|
|
14785
|
+
weekly: true,
|
|
14786
|
+
monthlyReport: true,
|
|
14787
|
+
awardBadges: true
|
|
14788
|
+
}
|
|
14789
|
+
};
|
|
14790
|
+
function calculateCategoryScore(currentValue, target, weight, isInverse = false) {
|
|
14791
|
+
const maxScore = weight;
|
|
14792
|
+
let performance;
|
|
14793
|
+
if (isInverse) {
|
|
14794
|
+
performance = target === 0 ? currentValue <= 0 ? 100 : 0 : Math.max(0, 100 - currentValue / target * 100);
|
|
14795
|
+
} else {
|
|
14796
|
+
performance = currentValue / target * 100;
|
|
14797
|
+
}
|
|
14798
|
+
performance = Math.min(100, Math.max(0, performance));
|
|
14799
|
+
const score = performance / 100 * maxScore;
|
|
14800
|
+
let status;
|
|
14801
|
+
if (performance >= 95)
|
|
14802
|
+
status = "excellent";
|
|
14803
|
+
else if (performance >= 80)
|
|
14804
|
+
status = "good";
|
|
14805
|
+
else if (performance >= 60)
|
|
14806
|
+
status = "warning";
|
|
14807
|
+
else
|
|
14808
|
+
status = "critical";
|
|
14809
|
+
return { score, status };
|
|
14810
|
+
}
|
|
14811
|
+
__name(calculateCategoryScore, "calculateCategoryScore");
|
|
14812
|
+
function calculateGrade(score, config) {
|
|
14813
|
+
if (score >= config.gradingScale.A)
|
|
14814
|
+
return "A";
|
|
14815
|
+
if (score >= config.gradingScale.B)
|
|
14816
|
+
return "B+";
|
|
14817
|
+
if (score >= config.gradingScale.C)
|
|
14818
|
+
return "C+";
|
|
14819
|
+
if (score >= config.gradingScale.D)
|
|
14820
|
+
return "D";
|
|
14821
|
+
return "F";
|
|
14822
|
+
}
|
|
14823
|
+
__name(calculateGrade, "calculateGrade");
|
|
14824
|
+
function generateQuickWins2(categories) {
|
|
14825
|
+
const quickWins = [];
|
|
14826
|
+
categories.forEach((category) => {
|
|
14827
|
+
if (category.status === "warning" || category.status === "critical") {
|
|
14828
|
+
const gap = category.target - category.currentValue;
|
|
14829
|
+
const potentialPoints = gap / category.target * category.maxScore;
|
|
14830
|
+
if (category.name === "Reserved Coverage") {
|
|
14831
|
+
quickWins.push({
|
|
14832
|
+
description: `Increase RI coverage by ${gap.toFixed(0)}%`,
|
|
14833
|
+
pointsGain: Math.round(potentialPoints),
|
|
14834
|
+
estimatedSavings: gap * 100,
|
|
14835
|
+
// Rough estimate
|
|
14836
|
+
difficulty: "medium"
|
|
14837
|
+
});
|
|
14838
|
+
} else if (category.name === "Tagging Compliance") {
|
|
14839
|
+
const missingTags = Math.round(gap / 100 * 100);
|
|
14840
|
+
quickWins.push({
|
|
14841
|
+
description: `Add missing tags to ~${missingTags} resources`,
|
|
14842
|
+
pointsGain: Math.round(potentialPoints),
|
|
14843
|
+
difficulty: "easy"
|
|
14844
|
+
});
|
|
14845
|
+
} else if (category.name === "Waste Elimination") {
|
|
14846
|
+
quickWins.push({
|
|
14847
|
+
description: `Clean up unused resources (${gap.toFixed(0)}% remaining)`,
|
|
14848
|
+
pointsGain: Math.round(potentialPoints),
|
|
14849
|
+
estimatedSavings: gap * 50,
|
|
14850
|
+
difficulty: "easy"
|
|
14851
|
+
});
|
|
14852
|
+
}
|
|
14853
|
+
}
|
|
14854
|
+
});
|
|
14855
|
+
return quickWins.sort((a, b) => b.pointsGain - a.pointsGain).slice(0, 5);
|
|
14856
|
+
}
|
|
14857
|
+
__name(generateQuickWins2, "generateQuickWins");
|
|
14858
|
+
function checkBadges(scorecard, historicalData) {
|
|
14859
|
+
const badges = [];
|
|
14860
|
+
const today = (/* @__PURE__ */ new Date()).toISOString();
|
|
14861
|
+
const budgetCategory = scorecard.categories.find((c) => c.name === "Budget Adherence");
|
|
14862
|
+
if (budgetCategory && budgetCategory.currentValue >= budgetCategory.target) {
|
|
14863
|
+
const last3Months = historicalData.slice(-3);
|
|
14864
|
+
if (last3Months.length === 3 && last3Months.every((m) => m.score >= 80)) {
|
|
14865
|
+
badges.push({
|
|
14866
|
+
name: "Budget Champion",
|
|
14867
|
+
emoji: "\u{1F3C5}",
|
|
14868
|
+
description: "Under budget for 3 consecutive months",
|
|
14869
|
+
awardedDate: today
|
|
14870
|
+
});
|
|
14871
|
+
}
|
|
14872
|
+
}
|
|
14873
|
+
const taggingCategory = scorecard.categories.find((c) => c.name === "Tagging Compliance");
|
|
14874
|
+
if (taggingCategory && taggingCategory.currentValue >= 100) {
|
|
14875
|
+
badges.push({
|
|
14876
|
+
name: "Tagging Star",
|
|
14877
|
+
emoji: "\u2B50",
|
|
14878
|
+
description: "100% tagging compliance",
|
|
14879
|
+
awardedDate: today
|
|
14880
|
+
});
|
|
14881
|
+
}
|
|
14882
|
+
const costCategory = scorecard.categories.find((c) => c.name === "Cost Efficiency");
|
|
14883
|
+
if (costCategory && costCategory.currentValue <= -20) {
|
|
14884
|
+
badges.push({
|
|
14885
|
+
name: "Green Team",
|
|
14886
|
+
emoji: "\u{1F331}",
|
|
14887
|
+
description: "Reduced costs 20% this quarter",
|
|
14888
|
+
awardedDate: today
|
|
14889
|
+
});
|
|
14890
|
+
}
|
|
14891
|
+
if (scorecard.totalScore >= 90) {
|
|
14892
|
+
const last6Months = historicalData.slice(-6);
|
|
14893
|
+
if (last6Months.length === 6 && last6Months.every((m) => m.score >= 90)) {
|
|
14894
|
+
badges.push({
|
|
14895
|
+
name: "Efficiency Expert",
|
|
14896
|
+
emoji: "\u{1F48E}",
|
|
14897
|
+
description: "Score above 90 for 6 months",
|
|
14898
|
+
awardedDate: today
|
|
14899
|
+
});
|
|
14900
|
+
}
|
|
14901
|
+
}
|
|
14902
|
+
return badges;
|
|
14903
|
+
}
|
|
14904
|
+
__name(checkBadges, "checkBadges");
|
|
14905
|
+
function buildTeamScorecard(teamName, metrics, config = DEFAULT_SCORECARD_CONFIG, historicalData = []) {
|
|
14906
|
+
const categories = [];
|
|
14907
|
+
const budgetTarget = config.categories.budgetAdherence.target;
|
|
14908
|
+
const budgetScore = calculateCategoryScore(
|
|
14909
|
+
Math.min(metrics.budgetUsage, 100),
|
|
14910
|
+
budgetTarget,
|
|
14911
|
+
config.categories.budgetAdherence.weight,
|
|
14912
|
+
false
|
|
14913
|
+
);
|
|
14914
|
+
categories.push({
|
|
14915
|
+
name: "Budget Adherence",
|
|
14916
|
+
weight: config.categories.budgetAdherence.weight,
|
|
14917
|
+
target: budgetTarget,
|
|
14918
|
+
currentValue: metrics.budgetUsage,
|
|
14919
|
+
score: budgetScore.score,
|
|
14920
|
+
maxScore: config.categories.budgetAdherence.weight,
|
|
14921
|
+
status: budgetScore.status
|
|
14922
|
+
});
|
|
14923
|
+
const costEffScore = calculateCategoryScore(
|
|
14924
|
+
Math.abs(metrics.costTrend),
|
|
14925
|
+
Math.abs(config.categories.costEfficiency.target),
|
|
14926
|
+
config.categories.costEfficiency.weight,
|
|
14927
|
+
true
|
|
14928
|
+
);
|
|
14929
|
+
categories.push({
|
|
14930
|
+
name: "Cost Efficiency",
|
|
14931
|
+
weight: config.categories.costEfficiency.weight,
|
|
14932
|
+
target: config.categories.costEfficiency.target,
|
|
14933
|
+
currentValue: metrics.costTrend,
|
|
14934
|
+
score: costEffScore.score,
|
|
14935
|
+
maxScore: config.categories.costEfficiency.weight,
|
|
14936
|
+
status: costEffScore.status
|
|
14937
|
+
});
|
|
14938
|
+
const taggingScore = calculateCategoryScore(
|
|
14939
|
+
metrics.taggingCompliance,
|
|
14940
|
+
config.categories.taggingCompliance.target,
|
|
14941
|
+
config.categories.taggingCompliance.weight
|
|
14942
|
+
);
|
|
14943
|
+
categories.push({
|
|
14944
|
+
name: "Tagging Compliance",
|
|
14945
|
+
weight: config.categories.taggingCompliance.weight,
|
|
14946
|
+
target: config.categories.taggingCompliance.target,
|
|
14947
|
+
currentValue: metrics.taggingCompliance,
|
|
14948
|
+
score: taggingScore.score,
|
|
14949
|
+
maxScore: config.categories.taggingCompliance.weight,
|
|
14950
|
+
status: taggingScore.status
|
|
14951
|
+
});
|
|
14952
|
+
const reservedScore = calculateCategoryScore(
|
|
14953
|
+
metrics.reservedCoverage,
|
|
14954
|
+
config.categories.reservedCoverage.target,
|
|
14955
|
+
config.categories.reservedCoverage.weight
|
|
14956
|
+
);
|
|
14957
|
+
categories.push({
|
|
14958
|
+
name: "Reserved Coverage",
|
|
14959
|
+
weight: config.categories.reservedCoverage.weight,
|
|
14960
|
+
target: config.categories.reservedCoverage.target,
|
|
14961
|
+
currentValue: metrics.reservedCoverage,
|
|
14962
|
+
score: reservedScore.score,
|
|
14963
|
+
maxScore: config.categories.reservedCoverage.weight,
|
|
14964
|
+
status: reservedScore.status
|
|
14965
|
+
});
|
|
14966
|
+
const wasteScore = calculateCategoryScore(
|
|
14967
|
+
100 - metrics.wastePercentage,
|
|
14968
|
+
config.categories.wasteElimination.target,
|
|
14969
|
+
config.categories.wasteElimination.weight
|
|
14970
|
+
);
|
|
14971
|
+
categories.push({
|
|
14972
|
+
name: "Waste Elimination",
|
|
14973
|
+
weight: config.categories.wasteElimination.weight,
|
|
14974
|
+
target: config.categories.wasteElimination.target,
|
|
14975
|
+
currentValue: 100 - metrics.wastePercentage,
|
|
14976
|
+
score: wasteScore.score,
|
|
14977
|
+
maxScore: config.categories.wasteElimination.weight,
|
|
14978
|
+
status: wasteScore.status
|
|
14979
|
+
});
|
|
14980
|
+
const optActionsPercent = metrics.optimizationsActed / Math.max(metrics.totalOptimizations, 1) * 100;
|
|
14981
|
+
const optScore = calculateCategoryScore(
|
|
14982
|
+
optActionsPercent,
|
|
14983
|
+
config.categories.optimizationActions.target,
|
|
14984
|
+
config.categories.optimizationActions.weight
|
|
14985
|
+
);
|
|
14986
|
+
categories.push({
|
|
14987
|
+
name: "Optimization Actions",
|
|
14988
|
+
weight: config.categories.optimizationActions.weight,
|
|
14989
|
+
target: config.categories.optimizationActions.target,
|
|
14990
|
+
currentValue: optActionsPercent,
|
|
14991
|
+
score: optScore.score,
|
|
14992
|
+
maxScore: config.categories.optimizationActions.weight,
|
|
14993
|
+
status: optScore.status
|
|
14994
|
+
});
|
|
14995
|
+
const totalScore = Math.round(categories.reduce((sum, cat) => sum + cat.score, 0));
|
|
14996
|
+
const grade = calculateGrade(totalScore, config);
|
|
14997
|
+
const lastMonthScore = historicalData.length > 0 ? historicalData[historicalData.length - 1].score : totalScore;
|
|
14998
|
+
const trend = totalScore - lastMonthScore;
|
|
14999
|
+
const quickWins = generateQuickWins2(categories);
|
|
15000
|
+
const scorecard = {
|
|
15001
|
+
teamName,
|
|
15002
|
+
totalScore,
|
|
15003
|
+
grade,
|
|
15004
|
+
trend,
|
|
15005
|
+
categories,
|
|
15006
|
+
quickWins,
|
|
15007
|
+
badges: [],
|
|
15008
|
+
monthlyHistory: historicalData
|
|
15009
|
+
};
|
|
15010
|
+
scorecard.badges = checkBadges(scorecard, historicalData);
|
|
15011
|
+
return scorecard;
|
|
15012
|
+
}
|
|
15013
|
+
__name(buildTeamScorecard, "buildTeamScorecard");
|
|
15014
|
+
function generateLeaderboard(scorecards) {
|
|
15015
|
+
return scorecards.map((sc, index) => ({
|
|
15016
|
+
rank: index + 1,
|
|
15017
|
+
teamName: sc.teamName,
|
|
15018
|
+
score: sc.totalScore,
|
|
15019
|
+
grade: sc.grade,
|
|
15020
|
+
trend: sc.trend,
|
|
15021
|
+
savings: sc.quickWins.reduce((sum, qw) => sum + (qw.estimatedSavings || 0), 0)
|
|
15022
|
+
})).sort((a, b) => b.score - a.score).map((entry, index) => ({ ...entry, rank: index + 1 }));
|
|
15023
|
+
}
|
|
15024
|
+
__name(generateLeaderboard, "generateLeaderboard");
|
|
15025
|
+
|
|
15026
|
+
// src/cli/commands/scorecard/index.ts
|
|
15027
|
+
function getMockTeamMetrics(teamName) {
|
|
15028
|
+
const teams = {
|
|
15029
|
+
"Backend Engineering": {
|
|
15030
|
+
budgetUsage: 85,
|
|
15031
|
+
costTrend: -5,
|
|
15032
|
+
taggingCompliance: 92,
|
|
15033
|
+
reservedCoverage: 65,
|
|
15034
|
+
wastePercentage: 22,
|
|
15035
|
+
optimizationsActed: 4,
|
|
15036
|
+
totalOptimizations: 5
|
|
15037
|
+
},
|
|
15038
|
+
"Platform Team": {
|
|
15039
|
+
budgetUsage: 75,
|
|
15040
|
+
costTrend: -8,
|
|
15041
|
+
taggingCompliance: 98,
|
|
15042
|
+
reservedCoverage: 85,
|
|
15043
|
+
wastePercentage: 8,
|
|
15044
|
+
optimizationsActed: 5,
|
|
15045
|
+
totalOptimizations: 5
|
|
15046
|
+
},
|
|
15047
|
+
"Data Engineering": {
|
|
15048
|
+
budgetUsage: 82,
|
|
15049
|
+
costTrend: -3,
|
|
15050
|
+
taggingCompliance: 90,
|
|
15051
|
+
reservedCoverage: 70,
|
|
15052
|
+
wastePercentage: 15,
|
|
15053
|
+
optimizationsActed: 4,
|
|
15054
|
+
totalOptimizations: 5
|
|
15055
|
+
},
|
|
15056
|
+
"Frontend Team": {
|
|
15057
|
+
budgetUsage: 88,
|
|
15058
|
+
costTrend: 2,
|
|
15059
|
+
taggingCompliance: 85,
|
|
15060
|
+
reservedCoverage: 60,
|
|
15061
|
+
wastePercentage: 25,
|
|
15062
|
+
optimizationsActed: 3,
|
|
15063
|
+
totalOptimizations: 5
|
|
15064
|
+
},
|
|
15065
|
+
"ML Team": {
|
|
15066
|
+
budgetUsage: 95,
|
|
15067
|
+
costTrend: 5,
|
|
15068
|
+
taggingCompliance: 78,
|
|
15069
|
+
reservedCoverage: 55,
|
|
15070
|
+
wastePercentage: 30,
|
|
15071
|
+
optimizationsActed: 2,
|
|
15072
|
+
totalOptimizations: 5
|
|
15073
|
+
}
|
|
15074
|
+
};
|
|
15075
|
+
return teams[teamName] || teams["Backend Engineering"];
|
|
15076
|
+
}
|
|
15077
|
+
__name(getMockTeamMetrics, "getMockTeamMetrics");
|
|
15078
|
+
function getStatusEmoji(status) {
|
|
15079
|
+
switch (status) {
|
|
15080
|
+
case "excellent":
|
|
15081
|
+
return "\u2705";
|
|
15082
|
+
case "good":
|
|
15083
|
+
return "\u2705";
|
|
15084
|
+
case "warning":
|
|
15085
|
+
return "\u26A0\uFE0F";
|
|
15086
|
+
case "critical":
|
|
15087
|
+
return "\u274C";
|
|
15088
|
+
default:
|
|
15089
|
+
return "\u2022";
|
|
15090
|
+
}
|
|
15091
|
+
}
|
|
15092
|
+
__name(getStatusEmoji, "getStatusEmoji");
|
|
15093
|
+
function formatTrendArrow(trend) {
|
|
15094
|
+
if (trend > 0)
|
|
15095
|
+
return import_chalk23.default.green(`\u2B06\uFE0F +${trend}`);
|
|
15096
|
+
if (trend < 0)
|
|
15097
|
+
return import_chalk23.default.red(`\u2B07\uFE0F ${trend}`);
|
|
15098
|
+
return import_chalk23.default.gray("\u2192 0");
|
|
15099
|
+
}
|
|
15100
|
+
__name(formatTrendArrow, "formatTrendArrow");
|
|
15101
|
+
async function handleScorecard(options) {
|
|
15102
|
+
try {
|
|
15103
|
+
const teamName = options.team || "Backend Engineering";
|
|
15104
|
+
const metrics = getMockTeamMetrics(teamName);
|
|
15105
|
+
const historicalData = [
|
|
15106
|
+
{ month: "July 2025", score: 77, grade: "B" },
|
|
15107
|
+
{ month: "August 2025", score: 79, grade: "B" },
|
|
15108
|
+
{ month: "September 2025", score: 80, grade: "B+" }
|
|
15109
|
+
];
|
|
15110
|
+
const scorecard = buildTeamScorecard(teamName, metrics, DEFAULT_SCORECARD_CONFIG, historicalData);
|
|
15111
|
+
console.log();
|
|
15112
|
+
console.log(import_chalk23.default.bold.blue("\u2550".repeat(70)));
|
|
15113
|
+
console.log(import_chalk23.default.bold.white(` \u{1F3C6} FinOps Scorecard - ${(/* @__PURE__ */ new Date()).toLocaleDateString("en-US", { month: "long", year: "numeric" })}`));
|
|
15114
|
+
console.log(import_chalk23.default.bold.blue("\u2550".repeat(70)));
|
|
15115
|
+
console.log();
|
|
15116
|
+
console.log(import_chalk23.default.bold.white(`Team: ${scorecard.teamName}`));
|
|
15117
|
+
console.log(
|
|
15118
|
+
import_chalk23.default.bold.cyan(
|
|
15119
|
+
`Score: ${scorecard.totalScore}/100 (Grade: ${scorecard.grade}) ${formatTrendArrow(scorecard.trend)} from last month`
|
|
15120
|
+
)
|
|
15121
|
+
);
|
|
15122
|
+
console.log(import_chalk23.default.gray("\u2500".repeat(70)));
|
|
15123
|
+
console.log();
|
|
15124
|
+
console.log(import_chalk23.default.bold("\u{1F4CA} Metrics:"));
|
|
15125
|
+
scorecard.categories.forEach((category) => {
|
|
15126
|
+
const emoji = getStatusEmoji(category.status);
|
|
15127
|
+
const percentage = (category.score / category.maxScore * 100).toFixed(0);
|
|
15128
|
+
const value = category.name === "Cost Efficiency" ? `${category.currentValue >= 0 ? "+" : ""}${category.currentValue}%` : category.name === "Optimization Actions" ? `${Math.round(category.currentValue)}%` : `${category.currentValue.toFixed(0)}%`;
|
|
15129
|
+
console.log(
|
|
15130
|
+
`\u251C\u2500\u2500 ${import_chalk23.default.white(category.name.padEnd(22))} ${value.padEnd(8)} ${emoji} (target: ${category.target}${category.name.includes("Efficiency") || category.name.includes("Actions") ? "%" : "%"}) [${Math.round(category.score)}/${category.maxScore} pts]`
|
|
15131
|
+
);
|
|
15132
|
+
});
|
|
15133
|
+
console.log();
|
|
15134
|
+
if (scorecard.quickWins.length > 0) {
|
|
15135
|
+
console.log(import_chalk23.default.bold("\u{1F3AF} Quick Wins to Improve Score:"));
|
|
15136
|
+
scorecard.quickWins.forEach((qw) => {
|
|
15137
|
+
const savingsText = qw.estimatedSavings ? import_chalk23.default.green(` (save ~$${qw.estimatedSavings.toFixed(0)})`) : "";
|
|
15138
|
+
console.log(`\u2022 ${qw.description} \u2192 +${qw.pointsGain} points${savingsText}`);
|
|
15139
|
+
});
|
|
15140
|
+
console.log();
|
|
15141
|
+
}
|
|
15142
|
+
if (scorecard.badges.length > 0) {
|
|
15143
|
+
console.log(import_chalk23.default.bold("\u{1F3C5} Badges Earned:"));
|
|
15144
|
+
scorecard.badges.forEach((badge) => {
|
|
15145
|
+
console.log(`${badge.emoji} ${import_chalk23.default.yellow(badge.name)} - ${import_chalk23.default.gray(badge.description)}`);
|
|
15146
|
+
});
|
|
15147
|
+
console.log();
|
|
15148
|
+
}
|
|
15149
|
+
console.log(import_chalk23.default.bold.blue("\u2550".repeat(70)));
|
|
15150
|
+
} catch (error) {
|
|
15151
|
+
console.error(import_chalk23.default.red("\u274C Failed to generate scorecard:"), error.message);
|
|
15152
|
+
process.exit(1);
|
|
15153
|
+
}
|
|
15154
|
+
}
|
|
15155
|
+
__name(handleScorecard, "handleScorecard");
|
|
15156
|
+
async function handleLeaderboard() {
|
|
15157
|
+
try {
|
|
15158
|
+
const teamNames = ["Platform Team", "Data Engineering", "Backend Engineering", "Frontend Team", "ML Team"];
|
|
15159
|
+
const scorecards = teamNames.map((name) => {
|
|
15160
|
+
const metrics = getMockTeamMetrics(name);
|
|
15161
|
+
return buildTeamScorecard(name, metrics);
|
|
15162
|
+
});
|
|
15163
|
+
const leaderboard = generateLeaderboard(scorecards);
|
|
15164
|
+
console.log();
|
|
15165
|
+
console.log(import_chalk23.default.bold.blue("\u2550".repeat(80)));
|
|
15166
|
+
console.log(import_chalk23.default.bold.white(` \u{1F3C6} FinOps Leaderboard - ${(/* @__PURE__ */ new Date()).toLocaleDateString("en-US", { month: "long", year: "numeric" })}`));
|
|
15167
|
+
console.log(import_chalk23.default.bold.blue("\u2550".repeat(80)));
|
|
15168
|
+
console.log();
|
|
15169
|
+
const table = new import_cli_table32.default({
|
|
15170
|
+
head: [
|
|
15171
|
+
import_chalk23.default.bold("Rank"),
|
|
15172
|
+
import_chalk23.default.bold("Team"),
|
|
15173
|
+
import_chalk23.default.bold("Score"),
|
|
15174
|
+
import_chalk23.default.bold("Grade"),
|
|
15175
|
+
import_chalk23.default.bold("Trend"),
|
|
15176
|
+
import_chalk23.default.bold("Savings")
|
|
15177
|
+
],
|
|
15178
|
+
colWidths: [8, 25, 10, 10, 12, 15]
|
|
15179
|
+
});
|
|
15180
|
+
leaderboard.forEach((entry) => {
|
|
15181
|
+
const rankEmoji = entry.rank === 1 ? "\u{1F947}" : entry.rank === 2 ? "\u{1F948}" : entry.rank === 3 ? "\u{1F949}" : ` ${entry.rank}`;
|
|
15182
|
+
table.push([
|
|
15183
|
+
rankEmoji,
|
|
15184
|
+
entry.teamName,
|
|
15185
|
+
entry.score.toString(),
|
|
15186
|
+
entry.grade,
|
|
15187
|
+
formatTrendArrow(entry.trend),
|
|
15188
|
+
import_chalk23.default.green(`$${entry.savings.toLocaleString()}`)
|
|
15189
|
+
]);
|
|
15190
|
+
});
|
|
15191
|
+
console.log(table.toString());
|
|
15192
|
+
console.log();
|
|
15193
|
+
const mostImproved = leaderboard.reduce((max, entry) => entry.trend > max.trend ? entry : max, leaderboard[0]);
|
|
15194
|
+
const biggestSaver = leaderboard.reduce((max, entry) => entry.savings > max.savings ? entry : max, leaderboard[0]);
|
|
15195
|
+
console.log(import_chalk23.default.bold.blue("\u2550".repeat(80)));
|
|
15196
|
+
console.log(import_chalk23.default.yellow(`\u{1F396}\uFE0F Most Improved: ${mostImproved.teamName} (${formatTrendArrow(mostImproved.trend)} points)`));
|
|
15197
|
+
console.log(import_chalk23.default.green(`\u{1F4B0} Biggest Saver: ${biggestSaver.teamName} ($${biggestSaver.savings.toLocaleString()})`));
|
|
15198
|
+
console.log(import_chalk23.default.bold.blue("\u2550".repeat(80)));
|
|
15199
|
+
console.log();
|
|
15200
|
+
} catch (error) {
|
|
15201
|
+
console.error(import_chalk23.default.red("\u274C Failed to generate leaderboard:"), error.message);
|
|
15202
|
+
process.exit(1);
|
|
15203
|
+
}
|
|
15204
|
+
}
|
|
15205
|
+
__name(handleLeaderboard, "handleLeaderboard");
|
|
15206
|
+
function registerScorecardCommand(program) {
|
|
15207
|
+
const scorecard = program.command("scorecard").description("FinOps team performance scorecards and leaderboards");
|
|
15208
|
+
scorecard.command("show").description("Show team scorecard").option("-t, --team <name>", "Team name", "Backend Engineering").action(handleScorecard);
|
|
15209
|
+
scorecard.command("leaderboard").description("Show organization leaderboard").action(handleLeaderboard);
|
|
15210
|
+
scorecard.action(handleScorecard);
|
|
15211
|
+
}
|
|
15212
|
+
__name(registerScorecardCommand, "registerScorecardCommand");
|
|
15213
|
+
|
|
13884
15214
|
// src/cli/middleware/auth.ts
|
|
13885
15215
|
async function authMiddleware(thisCommand, actionCommand) {
|
|
13886
15216
|
const isConfigCommand = actionCommand.name() === "config" || actionCommand.parent?.name() === "config";
|
|
@@ -13909,7 +15239,7 @@ async function validationMiddleware(thisCommand, actionCommand) {
|
|
|
13909
15239
|
__name(validationMiddleware, "validationMiddleware");
|
|
13910
15240
|
|
|
13911
15241
|
// src/cli/middleware/error-handler.ts
|
|
13912
|
-
var
|
|
15242
|
+
var import_chalk24 = __toESM(require("chalk"));
|
|
13913
15243
|
function errorHandler(error) {
|
|
13914
15244
|
const message = error?.message ?? String(error);
|
|
13915
15245
|
const stack = error?.stack;
|
|
@@ -13917,15 +15247,15 @@ function errorHandler(error) {
|
|
|
13917
15247
|
return;
|
|
13918
15248
|
}
|
|
13919
15249
|
console.error("");
|
|
13920
|
-
console.error(
|
|
15250
|
+
console.error(import_chalk24.default.red("\u2716"), import_chalk24.default.bold("Error:"), message);
|
|
13921
15251
|
if (process.env.DEBUG || process.env.VERBOSE) {
|
|
13922
15252
|
console.error("");
|
|
13923
15253
|
if (stack) {
|
|
13924
|
-
console.error(
|
|
15254
|
+
console.error(import_chalk24.default.gray(stack));
|
|
13925
15255
|
}
|
|
13926
15256
|
} else {
|
|
13927
15257
|
console.error("");
|
|
13928
|
-
console.error(
|
|
15258
|
+
console.error(import_chalk24.default.gray("Run with --verbose for detailed error information"));
|
|
13929
15259
|
}
|
|
13930
15260
|
console.error("");
|
|
13931
15261
|
}
|
|
@@ -13935,7 +15265,7 @@ __name(errorHandler, "errorHandler");
|
|
|
13935
15265
|
function createCLI() {
|
|
13936
15266
|
const program = new import_commander.Command();
|
|
13937
15267
|
program.exitOverride();
|
|
13938
|
-
program.name("infra-cost").description(
|
|
15268
|
+
program.name("infra-cost").description(import_package.default.description).version(import_package.default.version);
|
|
13939
15269
|
program.option("--provider <provider>", "Cloud provider (aws, gcp, azure, alibaba, oracle)", "aws").option("-p, --profile <profile>", "Cloud provider profile", "default").option("-r, --region <region>", "Cloud provider region", "us-east-1").option("-k, --access-key <key>", "Access key for cloud provider").option("-s, --secret-key <key>", "Secret key for cloud provider").option("-T, --session-token <token>", "Session token").option("--project-id <id>", "GCP Project ID").option("--key-file <path>", "Path to service account key file (GCP/Oracle)").option("--subscription-id <id>", "Azure Subscription ID").option("--tenant-id <id>", "Azure Tenant ID").option("--client-id <id>", "Azure Client ID").option("--client-secret <secret>", "Azure Client Secret").option("--user-id <id>", "Oracle User OCID").option("--tenancy-id <id>", "Oracle Tenancy OCID").option("--fingerprint <fp>", "Oracle Public Key Fingerprint").option("--config-file <path>", "Path to configuration file").option("--config-profile <name>", "Use named profile from config").option("--output <format>", "Output format (json, text, fancy, table)", "fancy").option("--no-color", "Disable colored output").option("--quiet", "Quiet mode - minimal output").option("--verbose", "Verbose output with debug information").option("--no-cache", "Disable caching").option("--cache-ttl <duration>", "Cache TTL (e.g., 4h, 30m)", "4h").option("--log-level <level>", "Logging level (debug, info, warn, error)", "info").option("--log-format <format>", "Log format (pretty, json)", "pretty");
|
|
13940
15270
|
registerNowCommand(program);
|
|
13941
15271
|
registerFreeTierCommand(program);
|
|
@@ -13954,6 +15284,8 @@ function createCLI() {
|
|
|
13954
15284
|
registerRBACCommands(program);
|
|
13955
15285
|
registerSSOCommands(program);
|
|
13956
15286
|
registerPluginCommands(program);
|
|
15287
|
+
registerServerCommands(program);
|
|
15288
|
+
registerScorecardCommand(program);
|
|
13957
15289
|
program.hook("preAction", async (thisCommand, actionCommand) => {
|
|
13958
15290
|
const opts = thisCommand.opts();
|
|
13959
15291
|
const logLevel = opts.verbose ? "debug" : opts.quiet ? "error" : opts.logLevel;
|