infra-cost 1.3.0 → 1.5.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.
Files changed (4) hide show
  1. package/README.md +168 -23
  2. package/dist/cli/index.js +1503 -130
  3. package/dist/index.js +1503 -130
  4. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -8434,6 +8434,214 @@ var init_budgets = __esm({
8434
8434
  }
8435
8435
  });
8436
8436
 
8437
+ // src/integrations/pagerduty.ts
8438
+ async function sendPagerDutyAlert(alert, config) {
8439
+ const { routingKey, severity = "warning", dedupKey, component = "cost-monitoring" } = config;
8440
+ const payload = {
8441
+ routing_key: routingKey,
8442
+ event_action: "trigger",
8443
+ dedup_key: dedupKey || `infra-cost-${alert.accountId}-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}`,
8444
+ payload: {
8445
+ summary: `Cloud Cost Spike: +$${alert.increaseAmount.toFixed(2)} (+${alert.increasePercent.toFixed(1)}%) in ${alert.accountName}`,
8446
+ severity,
8447
+ source: "infra-cost",
8448
+ component,
8449
+ group: alert.accountName,
8450
+ class: "cost-anomaly",
8451
+ custom_details: {
8452
+ account_id: alert.accountId,
8453
+ account_name: alert.accountName,
8454
+ today_cost: `$${alert.todayCost.toFixed(2)}`,
8455
+ yesterday_cost: `$${alert.yesterdayCost.toFixed(2)}`,
8456
+ increase_amount: `$${alert.increaseAmount.toFixed(2)}`,
8457
+ increase_percent: `${alert.increasePercent.toFixed(1)}%`,
8458
+ top_service: alert.topService,
8459
+ top_service_increase: `+$${alert.topServiceIncrease.toFixed(2)}`,
8460
+ threshold: alert.threshold ? `${alert.threshold}%` : "N/A"
8461
+ }
8462
+ },
8463
+ links: [
8464
+ {
8465
+ href: "https://console.aws.amazon.com/cost-management",
8466
+ text: "View in AWS Cost Explorer"
8467
+ }
8468
+ ]
8469
+ };
8470
+ try {
8471
+ const response = await (0, import_node_fetch.default)("https://events.pagerduty.com/v2/enqueue", {
8472
+ method: "POST",
8473
+ headers: {
8474
+ "Content-Type": "application/json"
8475
+ },
8476
+ body: JSON.stringify(payload)
8477
+ });
8478
+ if (!response.ok) {
8479
+ const errorText = await response.text();
8480
+ throw new Error(`PagerDuty API error: ${response.status} ${errorText}`);
8481
+ }
8482
+ const result = await response.json();
8483
+ return result;
8484
+ } catch (error) {
8485
+ throw new Error(`Failed to send PagerDuty alert: ${error.message}`);
8486
+ }
8487
+ }
8488
+ var import_node_fetch;
8489
+ var init_pagerduty = __esm({
8490
+ "src/integrations/pagerduty.ts"() {
8491
+ import_node_fetch = __toESM(require("node-fetch"));
8492
+ __name(sendPagerDutyAlert, "sendPagerDutyAlert");
8493
+ }
8494
+ });
8495
+
8496
+ // src/integrations/opsgenie.ts
8497
+ async function sendOpsGenieAlert(alert, config) {
8498
+ const { apiKey, priority = "P3", tags = ["cost-alert", "finops"], responders, alias } = config;
8499
+ const payload = {
8500
+ message: `Cloud Cost Spike: +$${alert.increaseAmount.toFixed(2)} (+${alert.increasePercent.toFixed(1)}%)`,
8501
+ alias: alias || `infra-cost-${alert.accountId}-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}`,
8502
+ description: `Cost increase detected in ${alert.accountName} account.
8503
+
8504
+ Today: $${alert.todayCost.toFixed(2)}
8505
+ Yesterday: $${alert.yesterdayCost.toFixed(2)}
8506
+ Increase: +$${alert.increaseAmount.toFixed(2)} (+${alert.increasePercent.toFixed(1)}%)
8507
+
8508
+ Top service: ${alert.topService} (+$${alert.topServiceIncrease.toFixed(2)})`,
8509
+ priority,
8510
+ tags,
8511
+ details: {
8512
+ account_id: alert.accountId,
8513
+ account_name: alert.accountName,
8514
+ today_cost: alert.todayCost.toFixed(2),
8515
+ yesterday_cost: alert.yesterdayCost.toFixed(2),
8516
+ increase_amount: alert.increaseAmount.toFixed(2),
8517
+ increase_percent: alert.increasePercent.toFixed(1),
8518
+ top_service: alert.topService,
8519
+ top_service_increase: alert.topServiceIncrease.toFixed(2),
8520
+ threshold: alert.threshold?.toString() || "N/A"
8521
+ },
8522
+ responders
8523
+ };
8524
+ try {
8525
+ const response = await (0, import_node_fetch2.default)("https://api.opsgenie.com/v2/alerts", {
8526
+ method: "POST",
8527
+ headers: {
8528
+ "Content-Type": "application/json",
8529
+ Authorization: `GenieKey ${apiKey}`
8530
+ },
8531
+ body: JSON.stringify(payload)
8532
+ });
8533
+ if (!response.ok) {
8534
+ const errorText = await response.text();
8535
+ throw new Error(`OpsGenie API error: ${response.status} ${errorText}`);
8536
+ }
8537
+ const result = await response.json();
8538
+ return result;
8539
+ } catch (error) {
8540
+ throw new Error(`Failed to send OpsGenie alert: ${error.message}`);
8541
+ }
8542
+ }
8543
+ var import_node_fetch2;
8544
+ var init_opsgenie = __esm({
8545
+ "src/integrations/opsgenie.ts"() {
8546
+ import_node_fetch2 = __toESM(require("node-fetch"));
8547
+ __name(sendOpsGenieAlert, "sendOpsGenieAlert");
8548
+ }
8549
+ });
8550
+
8551
+ // src/cli/commands/monitor/alert.ts
8552
+ var alert_exports = {};
8553
+ __export(alert_exports, {
8554
+ handleOpsGenie: () => handleOpsGenie,
8555
+ handlePagerDuty: () => handlePagerDuty
8556
+ });
8557
+ async function handlePagerDuty(options) {
8558
+ const { pagerdutyKey, severity, threshold } = options;
8559
+ if (!pagerdutyKey) {
8560
+ console.error(import_chalk10.default.red("Error: --pagerduty-key is required"));
8561
+ console.log("\nExample:");
8562
+ console.log(import_chalk10.default.gray(" infra-cost monitor alert-pagerduty --pagerduty-key YOUR_ROUTING_KEY"));
8563
+ process.exit(1);
8564
+ }
8565
+ console.log(import_chalk10.default.blue("\u{1F6A8} Checking for cost anomalies...\n"));
8566
+ const alert = {
8567
+ accountId: "123456789012",
8568
+ accountName: "Production",
8569
+ todayCost: 1850.23,
8570
+ yesterdayCost: 1400,
8571
+ increaseAmount: 450.23,
8572
+ increasePercent: 32,
8573
+ topService: "EC2",
8574
+ topServiceIncrease: 320,
8575
+ threshold: threshold ? parseFloat(threshold) : void 0
8576
+ };
8577
+ if (threshold && alert.increasePercent < parseFloat(threshold)) {
8578
+ console.log(import_chalk10.default.green(`\u2705 No alert needed (${alert.increasePercent.toFixed(1)}% < ${threshold}% threshold)`));
8579
+ return;
8580
+ }
8581
+ try {
8582
+ await sendPagerDutyAlert(alert, {
8583
+ routingKey: pagerdutyKey,
8584
+ severity: severity || "warning",
8585
+ component: "aws-cost-monitoring"
8586
+ });
8587
+ console.log(import_chalk10.default.green("\u2705 Alert sent to PagerDuty"));
8588
+ console.log(import_chalk10.default.gray(` Severity: ${severity || "warning"}`));
8589
+ console.log(import_chalk10.default.gray(` Increase: +$${alert.increaseAmount.toFixed(2)} (+${alert.increasePercent.toFixed(1)}%)`));
8590
+ } catch (error) {
8591
+ console.error(import_chalk10.default.red("Error sending PagerDuty alert:", error.message));
8592
+ process.exit(1);
8593
+ }
8594
+ }
8595
+ async function handleOpsGenie(options) {
8596
+ const { opsgenieKey, priority, threshold } = options;
8597
+ if (!opsgenieKey) {
8598
+ console.error(import_chalk10.default.red("Error: --opsgenie-key is required"));
8599
+ console.log("\nExample:");
8600
+ console.log(import_chalk10.default.gray(" infra-cost monitor alert-opsgenie --opsgenie-key YOUR_API_KEY"));
8601
+ process.exit(1);
8602
+ }
8603
+ console.log(import_chalk10.default.blue("\u{1F6A8} Checking for cost anomalies...\n"));
8604
+ const alert = {
8605
+ accountId: "123456789012",
8606
+ accountName: "Production",
8607
+ todayCost: 1850.23,
8608
+ yesterdayCost: 1400,
8609
+ increaseAmount: 450.23,
8610
+ increasePercent: 32,
8611
+ topService: "EC2",
8612
+ topServiceIncrease: 320,
8613
+ threshold: threshold ? parseFloat(threshold) : void 0
8614
+ };
8615
+ if (threshold && alert.increasePercent < parseFloat(threshold)) {
8616
+ console.log(import_chalk10.default.green(`\u2705 No alert needed (${alert.increasePercent.toFixed(1)}% < ${threshold}% threshold)`));
8617
+ return;
8618
+ }
8619
+ try {
8620
+ await sendOpsGenieAlert(alert, {
8621
+ apiKey: opsgenieKey,
8622
+ priority: priority || "P3",
8623
+ tags: ["cost-alert", "finops", "aws"],
8624
+ responders: options.team ? [{ type: "team", name: options.team }] : void 0
8625
+ });
8626
+ console.log(import_chalk10.default.green("\u2705 Alert sent to OpsGenie"));
8627
+ console.log(import_chalk10.default.gray(` Priority: ${priority || "P3"}`));
8628
+ console.log(import_chalk10.default.gray(` Increase: +$${alert.increaseAmount.toFixed(2)} (+${alert.increasePercent.toFixed(1)}%)`));
8629
+ } catch (error) {
8630
+ console.error(import_chalk10.default.red("Error sending OpsGenie alert:", error.message));
8631
+ process.exit(1);
8632
+ }
8633
+ }
8634
+ var import_chalk10;
8635
+ var init_alert = __esm({
8636
+ "src/cli/commands/monitor/alert.ts"() {
8637
+ init_pagerduty();
8638
+ init_opsgenie();
8639
+ import_chalk10 = __toESM(require("chalk"));
8640
+ __name(handlePagerDuty, "handlePagerDuty");
8641
+ __name(handleOpsGenie, "handleOpsGenie");
8642
+ }
8643
+ });
8644
+
8437
8645
  // src/cli/commands/export/inventory.ts
8438
8646
  var inventory_exports = {};
8439
8647
  __export(inventory_exports, {
@@ -8483,6 +8691,398 @@ var init_reports = __esm({
8483
8691
  }
8484
8692
  });
8485
8693
 
8694
+ // src/integrations/email.ts
8695
+ function generateEmailHTML(data) {
8696
+ const {
8697
+ date,
8698
+ todayCost,
8699
+ mtdCost,
8700
+ budget: budget2,
8701
+ budgetPercent,
8702
+ projectedMonthEnd,
8703
+ topServices,
8704
+ alerts,
8705
+ accountName,
8706
+ provider
8707
+ } = data;
8708
+ return `
8709
+ <!DOCTYPE html>
8710
+ <html>
8711
+ <head>
8712
+ <meta charset="utf-8">
8713
+ <style>
8714
+ body {
8715
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
8716
+ line-height: 1.6;
8717
+ color: #333;
8718
+ max-width: 600px;
8719
+ margin: 0 auto;
8720
+ padding: 20px;
8721
+ }
8722
+ .header {
8723
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
8724
+ color: white;
8725
+ padding: 30px;
8726
+ border-radius: 8px 8px 0 0;
8727
+ text-align: center;
8728
+ }
8729
+ .header h1 {
8730
+ margin: 0;
8731
+ font-size: 24px;
8732
+ }
8733
+ .content {
8734
+ background: #f8f9fa;
8735
+ padding: 30px;
8736
+ border-radius: 0 0 8px 8px;
8737
+ }
8738
+ .section {
8739
+ background: white;
8740
+ padding: 20px;
8741
+ margin-bottom: 20px;
8742
+ border-radius: 8px;
8743
+ border-left: 4px solid #667eea;
8744
+ }
8745
+ .section-title {
8746
+ font-size: 18px;
8747
+ font-weight: bold;
8748
+ margin-bottom: 15px;
8749
+ color: #667eea;
8750
+ }
8751
+ .metric-row {
8752
+ display: flex;
8753
+ justify-content: space-between;
8754
+ padding: 10px 0;
8755
+ border-bottom: 1px solid #e9ecef;
8756
+ }
8757
+ .metric-row:last-child {
8758
+ border-bottom: none;
8759
+ }
8760
+ .metric-label {
8761
+ font-weight: 500;
8762
+ color: #6c757d;
8763
+ }
8764
+ .metric-value {
8765
+ font-weight: bold;
8766
+ color: #333;
8767
+ }
8768
+ .service-item {
8769
+ padding: 8px 0;
8770
+ display: flex;
8771
+ justify-content: space-between;
8772
+ align-items: center;
8773
+ }
8774
+ .change-up {
8775
+ color: #dc3545;
8776
+ }
8777
+ .change-down {
8778
+ color: #28a745;
8779
+ }
8780
+ .change-neutral {
8781
+ color: #6c757d;
8782
+ }
8783
+ .alert {
8784
+ background: #fff3cd;
8785
+ border-left: 4px solid #ffc107;
8786
+ padding: 15px;
8787
+ margin-bottom: 10px;
8788
+ border-radius: 4px;
8789
+ }
8790
+ .footer {
8791
+ text-align: center;
8792
+ padding: 20px;
8793
+ color: #6c757d;
8794
+ font-size: 12px;
8795
+ }
8796
+ </style>
8797
+ </head>
8798
+ <body>
8799
+ <div class="header">
8800
+ <h1>\u{1F4B0} Daily Cost Report</h1>
8801
+ <p>${accountName ? `${provider || "Cloud"} Account: ${accountName}` : ""}</p>
8802
+ <p>${date}</p>
8803
+ </div>
8804
+
8805
+ <div class="content">
8806
+ <div class="section">
8807
+ <div class="section-title">\u{1F4CA} Today's Summary</div>
8808
+ <div class="metric-row">
8809
+ <span class="metric-label">Today's Cost</span>
8810
+ <span class="metric-value">$${todayCost.toFixed(2)}</span>
8811
+ </div>
8812
+ <div class="metric-row">
8813
+ <span class="metric-label">Month-to-Date</span>
8814
+ <span class="metric-value">$${mtdCost.toFixed(2)}${budget2 ? ` / $${budget2.toFixed(2)}` : ""}</span>
8815
+ </div>
8816
+ ${budget2 ? `
8817
+ <div class="metric-row">
8818
+ <span class="metric-label">Budget Usage</span>
8819
+ <span class="metric-value">${budgetPercent?.toFixed(0)}%</span>
8820
+ </div>
8821
+ ` : ""}
8822
+ ${projectedMonthEnd ? `
8823
+ <div class="metric-row">
8824
+ <span class="metric-label">Projected Month-End</span>
8825
+ <span class="metric-value">$${projectedMonthEnd.toFixed(2)}</span>
8826
+ </div>
8827
+ ` : ""}
8828
+ </div>
8829
+
8830
+ <div class="section">
8831
+ <div class="section-title">\u{1F4C8} Top Services</div>
8832
+ ${topServices.map((service) => {
8833
+ const changeClass = service.change > 0 ? "change-up" : service.change < 0 ? "change-down" : "change-neutral";
8834
+ const changeSymbol = service.change > 0 ? "\u2191" : service.change < 0 ? "\u2193" : "\u2192";
8835
+ const changeText = service.change !== 0 ? `${changeSymbol} ${service.change > 0 ? "+" : ""}${service.change}%` : "\u2192 0%";
8836
+ return `
8837
+ <div class="service-item">
8838
+ <span>${service.name}: $${service.cost.toFixed(2)}</span>
8839
+ <span class="${changeClass}">${changeText}</span>
8840
+ </div>
8841
+ `;
8842
+ }).join("")}
8843
+ </div>
8844
+
8845
+ ${alerts && alerts.length > 0 ? `
8846
+ <div class="section">
8847
+ <div class="section-title">\u26A0\uFE0F Alerts</div>
8848
+ ${alerts.map((alert) => `<div class="alert">${alert}</div>`).join("")}
8849
+ </div>
8850
+ ` : ""}
8851
+ </div>
8852
+
8853
+ <div class="footer">
8854
+ <p>Generated by infra-cost</p>
8855
+ <p>This is an automated report</p>
8856
+ </div>
8857
+ </body>
8858
+ </html>
8859
+ `.trim();
8860
+ }
8861
+ function generateEmailText(data) {
8862
+ const { date, todayCost, mtdCost, budget: budget2, budgetPercent, topServices, alerts } = data;
8863
+ let text = `Daily Cost Report - ${date}
8864
+
8865
+ `;
8866
+ text += `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
8867
+ `;
8868
+ text += `\u{1F4CA} Today's Summary
8869
+ `;
8870
+ text += `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
8871
+ `;
8872
+ text += `\u2022 Today: $${todayCost.toFixed(2)}
8873
+ `;
8874
+ text += `\u2022 Month-to-Date: $${mtdCost.toFixed(2)}${budget2 ? ` / $${budget2.toFixed(2)}` : ""}
8875
+ `;
8876
+ if (budget2) {
8877
+ text += `\u2022 Budget Usage: ${budgetPercent?.toFixed(0)}%
8878
+ `;
8879
+ }
8880
+ text += `
8881
+ `;
8882
+ text += `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
8883
+ `;
8884
+ text += `\u{1F4C8} Top Services
8885
+ `;
8886
+ text += `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
8887
+ `;
8888
+ topServices.forEach((service, index) => {
8889
+ const changeSymbol = service.change > 0 ? "\u2191" : service.change < 0 ? "\u2193" : "\u2192";
8890
+ text += `${index + 1}. ${service.name}: $${service.cost.toFixed(2)} (${changeSymbol} ${service.change > 0 ? "+" : ""}${service.change}%)
8891
+ `;
8892
+ });
8893
+ text += `
8894
+ `;
8895
+ if (alerts && alerts.length > 0) {
8896
+ text += `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
8897
+ `;
8898
+ text += `\u26A0\uFE0F Alerts
8899
+ `;
8900
+ text += `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
8901
+ `;
8902
+ alerts.forEach((alert) => {
8903
+ text += `\u2022 ${alert}
8904
+ `;
8905
+ });
8906
+ text += `
8907
+ `;
8908
+ }
8909
+ text += `--
8910
+ Generated by infra-cost`;
8911
+ return text;
8912
+ }
8913
+ async function sendViaSendGrid(config, data) {
8914
+ if (!config.sendgrid?.apiKey) {
8915
+ throw new Error("SendGrid API key is required");
8916
+ }
8917
+ const recipients = Array.isArray(config.to) ? config.to : [config.to];
8918
+ const payload = {
8919
+ personalizations: [
8920
+ {
8921
+ to: recipients.map((email) => ({ email })),
8922
+ subject: config.subject || `\u{1F4B0} Daily Cost Report - ${data.date}`
8923
+ }
8924
+ ],
8925
+ from: {
8926
+ email: config.from
8927
+ },
8928
+ content: [
8929
+ {
8930
+ type: "text/plain",
8931
+ value: generateEmailText(data)
8932
+ },
8933
+ {
8934
+ type: "text/html",
8935
+ value: generateEmailHTML(data)
8936
+ }
8937
+ ]
8938
+ };
8939
+ const response = await (0, import_node_fetch3.default)("https://api.sendgrid.com/v3/mail/send", {
8940
+ method: "POST",
8941
+ headers: {
8942
+ "Content-Type": "application/json",
8943
+ Authorization: `Bearer ${config.sendgrid.apiKey}`
8944
+ },
8945
+ body: JSON.stringify(payload)
8946
+ });
8947
+ if (!response.ok) {
8948
+ const errorText = await response.text();
8949
+ throw new Error(`SendGrid API error: ${response.status} ${errorText}`);
8950
+ }
8951
+ }
8952
+ async function sendViaMailgun(config, data) {
8953
+ if (!config.mailgun?.apiKey || !config.mailgun?.domain) {
8954
+ throw new Error("Mailgun API key and domain are required");
8955
+ }
8956
+ const recipients = Array.isArray(config.to) ? config.to.join(",") : config.to;
8957
+ const formData = new URLSearchParams();
8958
+ formData.append("from", config.from);
8959
+ formData.append("to", recipients);
8960
+ formData.append("subject", config.subject || `\u{1F4B0} Daily Cost Report - ${data.date}`);
8961
+ formData.append("text", generateEmailText(data));
8962
+ formData.append("html", generateEmailHTML(data));
8963
+ const response = await (0, import_node_fetch3.default)(
8964
+ `https://api.mailgun.net/v3/${config.mailgun.domain}/messages`,
8965
+ {
8966
+ method: "POST",
8967
+ headers: {
8968
+ Authorization: `Basic ${Buffer.from(`api:${config.mailgun.apiKey}`).toString("base64")}`
8969
+ },
8970
+ body: formData
8971
+ }
8972
+ );
8973
+ if (!response.ok) {
8974
+ const errorText = await response.text();
8975
+ throw new Error(`Mailgun API error: ${response.status} ${errorText}`);
8976
+ }
8977
+ }
8978
+ async function sendEmailReport(data, config) {
8979
+ try {
8980
+ switch (config.provider) {
8981
+ case "sendgrid":
8982
+ await sendViaSendGrid(config, data);
8983
+ break;
8984
+ case "mailgun":
8985
+ await sendViaMailgun(config, data);
8986
+ break;
8987
+ case "smtp":
8988
+ throw new Error("SMTP provider not yet implemented - use SendGrid or Mailgun");
8989
+ case "ses":
8990
+ throw new Error("AWS SES provider not yet implemented - use SendGrid or Mailgun");
8991
+ default:
8992
+ throw new Error(`Unknown email provider: ${config.provider}`);
8993
+ }
8994
+ } catch (error) {
8995
+ throw new Error(`Failed to send email report: ${error.message}`);
8996
+ }
8997
+ }
8998
+ var import_node_fetch3;
8999
+ var init_email = __esm({
9000
+ "src/integrations/email.ts"() {
9001
+ import_node_fetch3 = __toESM(require("node-fetch"));
9002
+ __name(generateEmailHTML, "generateEmailHTML");
9003
+ __name(generateEmailText, "generateEmailText");
9004
+ __name(sendViaSendGrid, "sendViaSendGrid");
9005
+ __name(sendViaMailgun, "sendViaMailgun");
9006
+ __name(sendEmailReport, "sendEmailReport");
9007
+ }
9008
+ });
9009
+
9010
+ // src/cli/commands/export/email.ts
9011
+ var email_exports = {};
9012
+ __export(email_exports, {
9013
+ handleEmail: () => handleEmail
9014
+ });
9015
+ async function handleEmail(options) {
9016
+ const { emailTo, emailFrom, emailProvider, sendgridKey, mailgunKey, mailgunDomain } = options;
9017
+ if (!emailTo) {
9018
+ console.error(import_chalk11.default.red("Error: --email-to is required"));
9019
+ console.log("\nExample:");
9020
+ console.log(import_chalk11.default.gray(" infra-cost export email --email-to finance@company.com --email-provider sendgrid --sendgrid-key YOUR_KEY"));
9021
+ process.exit(1);
9022
+ }
9023
+ if (!emailFrom) {
9024
+ console.error(import_chalk11.default.red("Error: --email-from is required"));
9025
+ process.exit(1);
9026
+ }
9027
+ const provider = emailProvider || "sendgrid";
9028
+ if (provider === "sendgrid" && !sendgridKey) {
9029
+ console.error(import_chalk11.default.red("Error: --sendgrid-key is required for SendGrid"));
9030
+ process.exit(1);
9031
+ }
9032
+ if (provider === "mailgun" && (!mailgunKey || !mailgunDomain)) {
9033
+ console.error(import_chalk11.default.red("Error: --mailgun-key and --mailgun-domain are required for Mailgun"));
9034
+ process.exit(1);
9035
+ }
9036
+ console.log(import_chalk11.default.blue("\u{1F4E7} Generating and sending email report...\n"));
9037
+ try {
9038
+ const costData = {
9039
+ date: (/* @__PURE__ */ new Date()).toLocaleDateString("en-US", {
9040
+ weekday: "long",
9041
+ year: "numeric",
9042
+ month: "long",
9043
+ day: "numeric"
9044
+ }),
9045
+ todayCost: 142.3,
9046
+ mtdCost: 2847.5,
9047
+ budget: 5e3,
9048
+ budgetPercent: 57,
9049
+ projectedMonthEnd: 4520,
9050
+ topServices: [
9051
+ { name: "EC2", cost: 52.3, change: 8 },
9052
+ { name: "RDS", cost: 38.5, change: 1 },
9053
+ { name: "S3", cost: 22.1, change: -3 },
9054
+ { name: "Lambda", cost: 15.2, change: 12 }
9055
+ ],
9056
+ alerts: ["Lambda costs increased 12% - investigate function usage"],
9057
+ accountName: options.account || "Production",
9058
+ provider: options.provider?.toUpperCase() || "AWS"
9059
+ };
9060
+ const emailConfig = {
9061
+ provider,
9062
+ from: emailFrom,
9063
+ to: emailTo.split(",").map((e) => e.trim()),
9064
+ subject: options.subject,
9065
+ sendgrid: sendgridKey ? { apiKey: sendgridKey } : void 0,
9066
+ mailgun: mailgunKey && mailgunDomain ? { apiKey: mailgunKey, domain: mailgunDomain } : void 0
9067
+ };
9068
+ await sendEmailReport(costData, emailConfig);
9069
+ console.log(import_chalk11.default.green("\u2705 Email report sent successfully"));
9070
+ console.log(import_chalk11.default.gray(` To: ${emailTo}`));
9071
+ console.log(import_chalk11.default.gray(` Provider: ${provider}`));
9072
+ } catch (error) {
9073
+ console.error(import_chalk11.default.red("Error sending email report:", error.message));
9074
+ process.exit(1);
9075
+ }
9076
+ }
9077
+ var import_chalk11;
9078
+ var init_email2 = __esm({
9079
+ "src/cli/commands/export/email.ts"() {
9080
+ init_email();
9081
+ import_chalk11 = __toESM(require("chalk"));
9082
+ __name(handleEmail, "handleEmail");
9083
+ }
9084
+ });
9085
+
8486
9086
  // src/cli/commands/organizations/list.ts
8487
9087
  var list_exports = {};
8488
9088
  __export(list_exports, {
@@ -8528,7 +9128,7 @@ async function handleDaily(options, command) {
8528
9128
  const report = await generateDailyReport(options);
8529
9129
  if (options.slackWebhook) {
8530
9130
  await sendToSlack(report, options.slackWebhook);
8531
- console.log(import_chalk10.default.green("\u2705 Daily report sent to Slack successfully!"));
9131
+ console.log(import_chalk12.default.green("\u2705 Daily report sent to Slack successfully!"));
8532
9132
  }
8533
9133
  if (options.json) {
8534
9134
  console.log(JSON.stringify(report, null, 2));
@@ -8665,39 +9265,39 @@ async function generateDailyReport(options) {
8665
9265
  function displayDailyReport(report) {
8666
9266
  console.log();
8667
9267
  console.log(
8668
- import_chalk10.default.bold.cyan("\u{1F4CA} AWS Organizations Daily Cost Report"),
8669
- import_chalk10.default.dim(`(${report.date})`)
9268
+ import_chalk12.default.bold.cyan("\u{1F4CA} AWS Organizations Daily Cost Report"),
9269
+ import_chalk12.default.dim(`(${report.date})`)
8670
9270
  );
8671
- console.log(import_chalk10.default.dim("\u2550".repeat(70)));
9271
+ console.log(import_chalk12.default.dim("\u2550".repeat(70)));
8672
9272
  console.log();
8673
- console.log(import_chalk10.default.bold("\u{1F4B0} Total Costs"));
9273
+ console.log(import_chalk12.default.bold("\u{1F4B0} Total Costs"));
8674
9274
  console.log(
8675
- `\u251C\u2500\u2500 Today: ${import_chalk10.default.green("$" + report.totalCost.toFixed(2))}`
9275
+ `\u251C\u2500\u2500 Today: ${import_chalk12.default.green("$" + report.totalCost.toFixed(2))}`
8676
9276
  );
8677
9277
  console.log(
8678
- `\u251C\u2500\u2500 Weekly Total: ${import_chalk10.default.cyan("$" + report.weeklyTotal.toFixed(2))}`
9278
+ `\u251C\u2500\u2500 Weekly Total: ${import_chalk12.default.cyan("$" + report.weeklyTotal.toFixed(2))}`
8679
9279
  );
8680
- console.log(`\u2514\u2500\u2500 Active Accounts: ${import_chalk10.default.yellow(report.accountsCount)}`);
9280
+ console.log(`\u2514\u2500\u2500 Active Accounts: ${import_chalk12.default.yellow(report.accountsCount)}`);
8681
9281
  console.log();
8682
- console.log(import_chalk10.default.bold("\u{1F525} Top 5 Spenders Today"));
9282
+ console.log(import_chalk12.default.bold("\u{1F525} Top 5 Spenders Today"));
8683
9283
  report.topSpenders.forEach((account, index) => {
8684
9284
  const trendIcon = account.trend === "up" ? "\u{1F4C8}" : account.trend === "down" ? "\u{1F4C9}" : "\u27A1\uFE0F";
8685
- const deltaColor = account.trend === "up" ? import_chalk10.default.red : account.trend === "down" ? import_chalk10.default.green : import_chalk10.default.gray;
9285
+ const deltaColor = account.trend === "up" ? import_chalk12.default.red : account.trend === "down" ? import_chalk12.default.green : import_chalk12.default.gray;
8686
9286
  const prefix = index === report.topSpenders.length - 1 ? "\u2514\u2500\u2500" : "\u251C\u2500\u2500";
8687
9287
  console.log(
8688
- `${prefix} ${trendIcon} ${import_chalk10.default.bold(account.accountName)} ${import_chalk10.default.dim(`(${account.accountId})`)}`
9288
+ `${prefix} ${trendIcon} ${import_chalk12.default.bold(account.accountName)} ${import_chalk12.default.dim(`(${account.accountId})`)}`
8689
9289
  );
8690
9290
  console.log(
8691
- ` Today: ${import_chalk10.default.green("$" + account.todayCost.toFixed(2))} | Yesterday: $${account.yesterdayCost.toFixed(2)} | ${deltaColor(account.delta >= 0 ? "+" : "")}${deltaColor("$" + account.delta.toFixed(2))}`
9291
+ ` Today: ${import_chalk12.default.green("$" + account.todayCost.toFixed(2))} | Yesterday: $${account.yesterdayCost.toFixed(2)} | ${deltaColor(account.delta >= 0 ? "+" : "")}${deltaColor("$" + account.delta.toFixed(2))}`
8692
9292
  );
8693
9293
  });
8694
9294
  console.log();
8695
- console.log(import_chalk10.default.bold("\u{1F4CB} All Accounts"));
8696
- console.log(import_chalk10.default.dim("\u2500".repeat(70)));
9295
+ console.log(import_chalk12.default.bold("\u{1F4CB} All Accounts"));
9296
+ console.log(import_chalk12.default.dim("\u2500".repeat(70)));
8697
9297
  report.accounts.forEach((account) => {
8698
9298
  const trendIcon = account.trend === "up" ? "\u2B06\uFE0F" : account.trend === "down" ? "\u2B07\uFE0F" : "\u27A1\uFE0F";
8699
9299
  console.log(
8700
- `${trendIcon} ${account.accountName.padEnd(30)} $${account.todayCost.toFixed(2).padStart(8)} ${import_chalk10.default.dim("(7d avg: $" + account.weeklyAverage.toFixed(2) + ")")}`
9300
+ `${trendIcon} ${account.accountName.padEnd(30)} $${account.todayCost.toFixed(2).padStart(8)} ${import_chalk12.default.dim("(7d avg: $" + account.weeklyAverage.toFixed(2) + ")")}`
8701
9301
  );
8702
9302
  });
8703
9303
  console.log();
@@ -8773,31 +9373,31 @@ $${account.todayCost.toFixed(2)} today | Yesterday: $${account.yesterdayCost.toF
8773
9373
  function setupDailySchedule(options) {
8774
9374
  const scheduleTime = options.scheduleTime || "09:00";
8775
9375
  console.log();
8776
- console.log(import_chalk10.default.bold.yellow("\u2699\uFE0F Daily Scheduling Setup"));
8777
- console.log(import_chalk10.default.dim("\u2500".repeat(70)));
9376
+ console.log(import_chalk12.default.bold.yellow("\u2699\uFE0F Daily Scheduling Setup"));
9377
+ console.log(import_chalk12.default.dim("\u2500".repeat(70)));
8778
9378
  console.log(
8779
- import_chalk10.default.yellow(
9379
+ import_chalk12.default.yellow(
8780
9380
  "\u26A0\uFE0F Note: Automated scheduling requires an external scheduler (cron, AWS Lambda, GitHub Actions)"
8781
9381
  )
8782
9382
  );
8783
9383
  console.log();
8784
9384
  console.log(
8785
- import_chalk10.default.bold("Option 1: Cron (Linux/macOS)"),
8786
- import_chalk10.default.dim("- Best for servers")
9385
+ import_chalk12.default.bold("Option 1: Cron (Linux/macOS)"),
9386
+ import_chalk12.default.dim("- Best for servers")
8787
9387
  );
8788
9388
  console.log(
8789
- `Add this to your crontab (run ${import_chalk10.default.cyan("crontab -e")}):
9389
+ `Add this to your crontab (run ${import_chalk12.default.cyan("crontab -e")}):
8790
9390
  `
8791
9391
  );
8792
9392
  console.log(
8793
- import_chalk10.default.cyan(
9393
+ import_chalk12.default.cyan(
8794
9394
  ` 0 9 * * * cd $(pwd) && npx infra-cost organizations daily --slack-webhook="${options.slackWebhook}" > /dev/null 2>&1`
8795
9395
  )
8796
9396
  );
8797
9397
  console.log();
8798
9398
  console.log(
8799
- import_chalk10.default.bold("Option 2: AWS Lambda + EventBridge"),
8800
- import_chalk10.default.dim("- Best for AWS-native")
9399
+ import_chalk12.default.bold("Option 2: AWS Lambda + EventBridge"),
9400
+ import_chalk12.default.dim("- Best for AWS-native")
8801
9401
  );
8802
9402
  console.log(
8803
9403
  ` 1. Deploy this CLI as a Lambda function
@@ -8808,12 +9408,12 @@ function setupDailySchedule(options) {
8808
9408
  );
8809
9409
  console.log();
8810
9410
  console.log(
8811
- import_chalk10.default.bold("Option 3: GitHub Actions"),
8812
- import_chalk10.default.dim("- Best for CI/CD workflows")
9411
+ import_chalk12.default.bold("Option 3: GitHub Actions"),
9412
+ import_chalk12.default.dim("- Best for CI/CD workflows")
8813
9413
  );
8814
9414
  console.log(" Create .github/workflows/daily-cost-report.yml:\n");
8815
9415
  console.log(
8816
- import_chalk10.default.cyan(` name: Daily Cost Report
9416
+ import_chalk12.default.cyan(` name: Daily Cost Report
8817
9417
  on:
8818
9418
  schedule:
8819
9419
  - cron: '0 ${scheduleTime.split(":")[0]} * * *'
@@ -8826,16 +9426,16 @@ function setupDailySchedule(options) {
8826
9426
  );
8827
9427
  console.log();
8828
9428
  console.log(
8829
- import_chalk10.default.green(
9429
+ import_chalk12.default.green(
8830
9430
  `\u{1F4A1} Tip: Store your Slack webhook URL in environment variables or secrets manager`
8831
9431
  )
8832
9432
  );
8833
9433
  console.log();
8834
9434
  }
8835
- var import_chalk10, import_dayjs5, import_client_organizations, import_client_cost_explorer4;
9435
+ var import_chalk12, import_dayjs5, import_client_organizations, import_client_cost_explorer4;
8836
9436
  var init_daily = __esm({
8837
9437
  "src/cli/commands/organizations/daily.ts"() {
8838
- import_chalk10 = __toESM(require("chalk"));
9438
+ import_chalk12 = __toESM(require("chalk"));
8839
9439
  import_dayjs5 = __toESM(require("dayjs"));
8840
9440
  init_logging();
8841
9441
  import_client_organizations = require("@aws-sdk/client-organizations");
@@ -8896,6 +9496,194 @@ var init_slack = __esm({
8896
9496
  }
8897
9497
  });
8898
9498
 
9499
+ // src/integrations/teams.ts
9500
+ function createAdaptiveCard(data, style = "detailed") {
9501
+ const { todayCost, mtdCost, budget: budget2, budgetPercent, topServices, alerts, accountName, provider } = data;
9502
+ let color = "good";
9503
+ if (budgetPercent && budgetPercent > 90) {
9504
+ color = "attention";
9505
+ } else if (budgetPercent && budgetPercent > 75) {
9506
+ color = "warning";
9507
+ }
9508
+ const card = {
9509
+ type: "message",
9510
+ attachments: [
9511
+ {
9512
+ contentType: "application/vnd.microsoft.card.adaptive",
9513
+ content: {
9514
+ type: "AdaptiveCard",
9515
+ $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
9516
+ version: "1.4",
9517
+ body: [],
9518
+ actions: []
9519
+ }
9520
+ }
9521
+ ]
9522
+ };
9523
+ const body = card.attachments[0].content.body;
9524
+ body.push({
9525
+ type: "TextBlock",
9526
+ text: "\u{1F4B0} Daily Cost Report",
9527
+ weight: "bolder",
9528
+ size: "large"
9529
+ });
9530
+ if (accountName) {
9531
+ body.push({
9532
+ type: "TextBlock",
9533
+ text: `${provider || "Cloud"} Account: ${accountName}`,
9534
+ isSubtle: true,
9535
+ wrap: true
9536
+ });
9537
+ }
9538
+ const facts = [
9539
+ {
9540
+ title: "Today's Cost",
9541
+ value: `$${todayCost.toFixed(2)}`
9542
+ },
9543
+ {
9544
+ title: "Month-to-Date",
9545
+ value: `$${mtdCost.toFixed(2)}`
9546
+ }
9547
+ ];
9548
+ if (budget2) {
9549
+ facts.push({
9550
+ title: "Budget",
9551
+ value: `$${mtdCost.toFixed(2)} / $${budget2.toFixed(2)} (${budgetPercent?.toFixed(0)}%)`
9552
+ });
9553
+ }
9554
+ body.push({
9555
+ type: "FactSet",
9556
+ facts
9557
+ });
9558
+ if (style === "detailed" && topServices.length > 0) {
9559
+ body.push({
9560
+ type: "TextBlock",
9561
+ text: "Top Services",
9562
+ weight: "bolder",
9563
+ wrap: true,
9564
+ spacing: "medium"
9565
+ });
9566
+ topServices.forEach((service) => {
9567
+ const changeEmoji = service.change > 0 ? "\u2197" : service.change < 0 ? "\u2198" : "\u2192";
9568
+ const changePercent = service.change > 0 ? `+${service.change}%` : `${service.change}%`;
9569
+ body.push({
9570
+ type: "TextBlock",
9571
+ text: `\u2022 ${service.name}: $${service.cost.toFixed(2)} (${changeEmoji} ${changePercent})`,
9572
+ wrap: true
9573
+ });
9574
+ });
9575
+ }
9576
+ if (alerts && alerts.length > 0) {
9577
+ body.push({
9578
+ type: "TextBlock",
9579
+ text: "\u26A0\uFE0F Alerts",
9580
+ weight: "bolder",
9581
+ wrap: true,
9582
+ spacing: "medium",
9583
+ color: "attention"
9584
+ });
9585
+ alerts.forEach((alert) => {
9586
+ body.push({
9587
+ type: "TextBlock",
9588
+ text: `\u2022 ${alert}`,
9589
+ wrap: true,
9590
+ color: "attention"
9591
+ });
9592
+ });
9593
+ }
9594
+ card.attachments[0].content.actions = [
9595
+ {
9596
+ type: "Action.OpenUrl",
9597
+ title: "View Details",
9598
+ url: "https://console.aws.amazon.com/cost-management"
9599
+ }
9600
+ ];
9601
+ return card;
9602
+ }
9603
+ async function sendTeamsReport(webhook, data, config = {}) {
9604
+ const { cardStyle = "detailed", mentions = [] } = config;
9605
+ try {
9606
+ const card = createAdaptiveCard(data, cardStyle);
9607
+ if (mentions.length > 0) {
9608
+ const mentionText = mentions.map((email) => `<at>${email}</at>`).join(" ");
9609
+ card.attachments[0].content.body.unshift({
9610
+ type: "TextBlock",
9611
+ text: mentionText,
9612
+ wrap: true
9613
+ });
9614
+ }
9615
+ const response = await (0, import_node_fetch4.default)(webhook, {
9616
+ method: "POST",
9617
+ headers: {
9618
+ "Content-Type": "application/json"
9619
+ },
9620
+ body: JSON.stringify(card)
9621
+ });
9622
+ if (!response.ok) {
9623
+ const errorText = await response.text();
9624
+ throw new Error(`Teams webhook failed: ${response.status} ${errorText}`);
9625
+ }
9626
+ } catch (error) {
9627
+ throw new Error(`Failed to send Teams report: ${error.message}`);
9628
+ }
9629
+ }
9630
+ var import_node_fetch4;
9631
+ var init_teams = __esm({
9632
+ "src/integrations/teams.ts"() {
9633
+ import_node_fetch4 = __toESM(require("node-fetch"));
9634
+ __name(createAdaptiveCard, "createAdaptiveCard");
9635
+ __name(sendTeamsReport, "sendTeamsReport");
9636
+ }
9637
+ });
9638
+
9639
+ // src/cli/commands/chargeback/teams.ts
9640
+ var teams_exports = {};
9641
+ __export(teams_exports, {
9642
+ handleTeams: () => handleTeams
9643
+ });
9644
+ async function handleTeams(options, command) {
9645
+ const { teamsWebhook, provider = "aws" } = options;
9646
+ if (!teamsWebhook) {
9647
+ console.error(import_chalk13.default.red("Error: --teams-webhook is required"));
9648
+ console.log("\nExample:");
9649
+ console.log(import_chalk13.default.gray(" infra-cost chargeback teams --teams-webhook https://outlook.office.com/webhook/..."));
9650
+ process.exit(1);
9651
+ }
9652
+ console.log(import_chalk13.default.blue("\u{1F4CA} Generating chargeback report for Teams...\n"));
9653
+ try {
9654
+ const costData = {
9655
+ todayCost: 142.3,
9656
+ mtdCost: 2847.5,
9657
+ budget: 5e3,
9658
+ budgetPercent: 57,
9659
+ topServices: [
9660
+ { name: "EC2", cost: 52.3, change: 8 },
9661
+ { name: "RDS", cost: 38.5, change: 1 },
9662
+ { name: "S3", cost: 22.1, change: -3 },
9663
+ { name: "Lambda", cost: 15.2, change: 12 }
9664
+ ],
9665
+ alerts: ["Lambda costs increased 12% - investigate function usage"],
9666
+ accountName: options.account || "Production",
9667
+ provider: provider.toUpperCase()
9668
+ };
9669
+ await sendTeamsReport(teamsWebhook, costData, {
9670
+ cardStyle: options.cardStyle || "detailed"
9671
+ });
9672
+ console.log(import_chalk13.default.green("\u2705 Chargeback report sent to Microsoft Teams"));
9673
+ } catch (error) {
9674
+ console.error(import_chalk13.default.red("Error sending to Teams:", error.message));
9675
+ process.exit(1);
9676
+ }
9677
+ }
9678
+ var import_chalk13;
9679
+ var init_teams2 = __esm({
9680
+ "src/cli/commands/chargeback/teams.ts"() {
9681
+ init_teams();
9682
+ import_chalk13 = __toESM(require("chalk"));
9683
+ __name(handleTeams, "handleTeams");
9684
+ }
9685
+ });
9686
+
8899
9687
  // src/cli/commands/config/init.ts
8900
9688
  var init_exports = {};
8901
9689
  __export(init_exports, {
@@ -9011,15 +9799,15 @@ async function handleMigrate(options, command) {
9011
9799
  const logger = getGlobalLogger26();
9012
9800
  logger.info("Starting configuration migration", { dryRun: options.dryRun });
9013
9801
  console.log("");
9014
- console.log(import_chalk11.default.bold.cyan("\u{1F504} Configuration Migration Tool"));
9015
- console.log(import_chalk11.default.gray("\u2500".repeat(60)));
9802
+ console.log(import_chalk14.default.bold.cyan("\u{1F504} Configuration Migration Tool"));
9803
+ console.log(import_chalk14.default.gray("\u2500".repeat(60)));
9016
9804
  console.log("");
9017
9805
  const oldConfigFiles = options.configFile ? [options.configFile] : discoverOldConfigFiles();
9018
9806
  if (options.configFile && !(0, import_fs3.existsSync)(options.configFile)) {
9019
9807
  throw new Error(`Config file not found: ${options.configFile}`);
9020
9808
  }
9021
9809
  if (oldConfigFiles.length === 0) {
9022
- console.log(import_chalk11.default.yellow("\u26A0\uFE0F No old configuration files found"));
9810
+ console.log(import_chalk14.default.yellow("\u26A0\uFE0F No old configuration files found"));
9023
9811
  console.log("");
9024
9812
  console.log("Looking for config files in:");
9025
9813
  console.log(" \u2022 ./infra-cost.config.json");
@@ -9032,7 +9820,7 @@ async function handleMigrate(options, command) {
9032
9820
  return;
9033
9821
  }
9034
9822
  for (const oldConfigPath of oldConfigFiles) {
9035
- console.log(import_chalk11.default.green("\u2713"), `Found configuration: ${import_chalk11.default.bold(oldConfigPath)}`);
9823
+ console.log(import_chalk14.default.green("\u2713"), `Found configuration: ${import_chalk14.default.bold(oldConfigPath)}`);
9036
9824
  console.log("");
9037
9825
  try {
9038
9826
  const oldConfigContent = (0, import_fs3.readFileSync)(oldConfigPath, "utf8");
@@ -9046,49 +9834,49 @@ async function handleMigrate(options, command) {
9046
9834
  const lowerKey = key.toLowerCase();
9047
9835
  return REDACT_KEYS.some((k) => lowerKey.includes(k.toLowerCase())) ? "***REDACTED***" : value;
9048
9836
  }, "redact");
9049
- console.log(import_chalk11.default.bold("\u{1F4CB} Migration Preview:"));
9837
+ console.log(import_chalk14.default.bold("\u{1F4CB} Migration Preview:"));
9050
9838
  console.log("");
9051
- console.log(import_chalk11.default.gray("Old format:"));
9052
- console.log(import_chalk11.default.gray(JSON.stringify(oldConfig, redact, 2).split("\n").slice(0, 10).join("\n")));
9839
+ console.log(import_chalk14.default.gray("Old format:"));
9840
+ console.log(import_chalk14.default.gray(JSON.stringify(oldConfig, redact, 2).split("\n").slice(0, 10).join("\n")));
9053
9841
  if (Object.keys(oldConfig).length > 10) {
9054
- console.log(import_chalk11.default.gray(" ... (truncated)"));
9842
+ console.log(import_chalk14.default.gray(" ... (truncated)"));
9055
9843
  }
9056
9844
  console.log("");
9057
- console.log(import_chalk11.default.gray("New format:"));
9058
- console.log(import_chalk11.default.cyan(JSON.stringify(newConfig, redact, 2)));
9845
+ console.log(import_chalk14.default.gray("New format:"));
9846
+ console.log(import_chalk14.default.cyan(JSON.stringify(newConfig, redact, 2)));
9059
9847
  console.log("");
9060
9848
  if (options.dryRun) {
9061
- console.log(import_chalk11.default.yellow("\u{1F50D} Dry run mode - no changes made"));
9849
+ console.log(import_chalk14.default.yellow("\u{1F50D} Dry run mode - no changes made"));
9062
9850
  console.log("");
9063
9851
  } else {
9064
9852
  const backupPath = `${oldConfigPath}.backup`;
9065
9853
  (0, import_fs3.writeFileSync)(backupPath, oldConfigContent);
9066
- console.log(import_chalk11.default.green("\u2713"), `Backup created: ${backupPath}`);
9854
+ console.log(import_chalk14.default.green("\u2713"), `Backup created: ${backupPath}`);
9067
9855
  (0, import_fs3.writeFileSync)(oldConfigPath, JSON.stringify(newConfig, null, 2));
9068
- console.log(import_chalk11.default.green("\u2713"), `Configuration migrated: ${oldConfigPath}`);
9856
+ console.log(import_chalk14.default.green("\u2713"), `Configuration migrated: ${oldConfigPath}`);
9069
9857
  console.log("");
9070
9858
  }
9071
9859
  } catch (error) {
9072
- console.error(import_chalk11.default.red("\u2716"), `Failed to migrate ${oldConfigPath}:`, error.message);
9860
+ console.error(import_chalk14.default.red("\u2716"), `Failed to migrate ${oldConfigPath}:`, error.message);
9073
9861
  console.log("");
9074
9862
  }
9075
9863
  }
9076
9864
  console.log("");
9077
9865
  printCLIMigrationGuide();
9078
9866
  console.log("");
9079
- console.log(import_chalk11.default.bold.green("\u2705 Migration Complete!"));
9867
+ console.log(import_chalk14.default.bold.green("\u2705 Migration Complete!"));
9080
9868
  console.log("");
9081
9869
  console.log("Next steps:");
9082
9870
  console.log(" 1. Review the migrated configuration file");
9083
9871
  console.log(" 2. Test the new CLI commands");
9084
9872
  console.log(" 3. Update any scripts or automation");
9085
9873
  console.log("");
9086
- console.log("Run", import_chalk11.default.cyan("infra-cost config validate"), "to verify your configuration");
9874
+ console.log("Run", import_chalk14.default.cyan("infra-cost config validate"), "to verify your configuration");
9087
9875
  console.log("");
9088
9876
  }
9089
9877
  function printCLIMigrationGuide() {
9090
- console.log(import_chalk11.default.bold("\u{1F4D6} CLI Command Migration Guide"));
9091
- console.log(import_chalk11.default.gray("\u2500".repeat(60)));
9878
+ console.log(import_chalk14.default.bold("\u{1F4D6} CLI Command Migration Guide"));
9879
+ console.log(import_chalk14.default.gray("\u2500".repeat(60)));
9092
9880
  console.log("");
9093
9881
  const examples = [
9094
9882
  {
@@ -9132,21 +9920,21 @@ function printCLIMigrationGuide() {
9132
9920
  desc: "Interactive dashboard"
9133
9921
  }
9134
9922
  ];
9135
- console.log(import_chalk11.default.gray("Old Command") + " ".repeat(35) + import_chalk11.default.cyan("New Command"));
9136
- console.log(import_chalk11.default.gray("\u2500".repeat(60)));
9923
+ console.log(import_chalk14.default.gray("Old Command") + " ".repeat(35) + import_chalk14.default.cyan("New Command"));
9924
+ console.log(import_chalk14.default.gray("\u2500".repeat(60)));
9137
9925
  for (const example of examples) {
9138
9926
  const padding = " ".repeat(Math.max(0, 38 - example.old.length));
9139
- console.log(`${import_chalk11.default.gray(example.old)}${padding}${import_chalk11.default.cyan(example.new)}`);
9140
- console.log(import_chalk11.default.dim(` ${example.desc}`));
9927
+ console.log(`${import_chalk14.default.gray(example.old)}${padding}${import_chalk14.default.cyan(example.new)}`);
9928
+ console.log(import_chalk14.default.dim(` ${example.desc}`));
9141
9929
  console.log("");
9142
9930
  }
9143
- console.log(import_chalk11.default.bold("\u{1F4A1} Global Options"));
9931
+ console.log(import_chalk14.default.bold("\u{1F4A1} Global Options"));
9144
9932
  console.log("All global options remain the same:");
9145
9933
  console.log(" --provider, --region, --profile, --output, --config-file, etc.");
9146
9934
  console.log("");
9147
- console.log(import_chalk11.default.bold("\u{1F4DA} More Information"));
9148
- console.log("Run", import_chalk11.default.cyan("infra-cost <command> --help"), "for detailed command help");
9149
- console.log("Example:", import_chalk11.default.cyan("infra-cost cost --help"));
9935
+ console.log(import_chalk14.default.bold("\u{1F4DA} More Information"));
9936
+ console.log("Run", import_chalk14.default.cyan("infra-cost <command> --help"), "for detailed command help");
9937
+ console.log("Example:", import_chalk14.default.cyan("infra-cost cost --help"));
9150
9938
  console.log("");
9151
9939
  }
9152
9940
  function generateMigrationReport() {
@@ -9168,13 +9956,13 @@ function generateMigrationReport() {
9168
9956
  report.push("3. Test all workflows with new commands");
9169
9957
  return report.join("\n");
9170
9958
  }
9171
- var import_fs3, import_path2, import_os2, import_chalk11, CLI_MIGRATION_MAP;
9959
+ var import_fs3, import_path2, import_os2, import_chalk14, CLI_MIGRATION_MAP;
9172
9960
  var init_migrate = __esm({
9173
9961
  "src/cli/commands/config/migrate.ts"() {
9174
9962
  import_fs3 = require("fs");
9175
9963
  import_path2 = require("path");
9176
9964
  import_os2 = require("os");
9177
- import_chalk11 = __toESM(require("chalk"));
9965
+ import_chalk14 = __toESM(require("chalk"));
9178
9966
  init_logging();
9179
9967
  init_schema();
9180
9968
  CLI_MIGRATION_MAP = {
@@ -9426,7 +10214,7 @@ var import_commander = require("commander");
9426
10214
  // package.json
9427
10215
  var package_default = {
9428
10216
  name: "infra-cost",
9429
- version: "1.3.0",
10217
+ version: "1.5.0",
9430
10218
  description: "Multi-cloud FinOps CLI tool for comprehensive cost analysis and infrastructure optimization across AWS, GCP, Azure, Alibaba Cloud, and Oracle Cloud",
9431
10219
  keywords: [
9432
10220
  "aws",
@@ -11095,6 +11883,14 @@ function registerMonitorCommands(program) {
11095
11883
  const { handleBudgets: handleBudgets2 } = await Promise.resolve().then(() => (init_budgets(), budgets_exports));
11096
11884
  await handleBudgets2(options, command);
11097
11885
  });
11886
+ monitor.command("alert-pagerduty").description("Send cost alert to PagerDuty").option("--pagerduty-key <key>", "PagerDuty routing key").option("--severity <level>", "Alert severity (critical, error, warning, info)", "warning").option("--threshold <percent>", "Alert threshold percentage").action(async (options) => {
11887
+ const { handlePagerDuty: handlePagerDuty2 } = await Promise.resolve().then(() => (init_alert(), alert_exports));
11888
+ await handlePagerDuty2(options);
11889
+ });
11890
+ monitor.command("alert-opsgenie").description("Send cost alert to OpsGenie").option("--opsgenie-key <key>", "OpsGenie API key").option("--priority <level>", "Alert priority (P1, P2, P3, P4, P5)", "P3").option("--threshold <percent>", "Alert threshold percentage").option("--team <name>", "Team to notify").action(async (options) => {
11891
+ const { handleOpsGenie: handleOpsGenie2 } = await Promise.resolve().then(() => (init_alert(), alert_exports));
11892
+ await handleOpsGenie2(options);
11893
+ });
11098
11894
  }
11099
11895
  __name(registerMonitorCommands, "registerMonitorCommands");
11100
11896
 
@@ -11113,6 +11909,10 @@ function registerExportCommands(program) {
11113
11909
  const { handleReports: handleReports2 } = await Promise.resolve().then(() => (init_reports(), reports_exports));
11114
11910
  await handleReports2(format, options, command);
11115
11911
  });
11912
+ exportCmd.command("email").description("Send cost report via email").option("--email-to <addresses>", "Recipient email addresses (comma-separated)").option("--email-from <address>", "Sender email address").option("--email-provider <provider>", "Email provider (sendgrid, mailgun, smtp, ses)", "sendgrid").option("--sendgrid-key <key>", "SendGrid API key").option("--mailgun-key <key>", "Mailgun API key").option("--mailgun-domain <domain>", "Mailgun domain").option("--subject <text>", "Email subject").option("--account <name>", "Account name for report").action(async (options) => {
11913
+ const { handleEmail: handleEmail2 } = await Promise.resolve().then(() => (init_email2(), email_exports));
11914
+ await handleEmail2(options);
11915
+ });
11116
11916
  }
11117
11917
  __name(registerExportCommands, "registerExportCommands");
11118
11918
 
@@ -11120,8 +11920,8 @@ __name(registerExportCommands, "registerExportCommands");
11120
11920
  function registerOrganizationsCommands(program) {
11121
11921
  const orgs = program.command("organizations").alias("orgs").description("AWS Organizations multi-account management");
11122
11922
  orgs.command("list").description("List all accounts in the organization").option("--include-inactive", "Include suspended/closed accounts").action(async (options, command) => {
11123
- const { handleList: handleList2 } = await Promise.resolve().then(() => (init_list(), list_exports));
11124
- await handleList2(options, command);
11923
+ const { handleList: handleList3 } = await Promise.resolve().then(() => (init_list(), list_exports));
11924
+ await handleList3(options, command);
11125
11925
  });
11126
11926
  orgs.command("summary").description("Multi-account cost summary").option("--group-by <field>", "Group by (account, ou, tag)", "account").action(async (options, command) => {
11127
11927
  const { handleSummary: handleSummary2 } = await Promise.resolve().then(() => (init_summary(), summary_exports));
@@ -11149,6 +11949,10 @@ function registerChargebackCommands(program) {
11149
11949
  const { handleSlack: handleSlack2 } = await Promise.resolve().then(() => (init_slack(), slack_exports));
11150
11950
  await handleSlack2(options, command);
11151
11951
  });
11952
+ chargeback.command("teams").description("Send chargeback report to Microsoft Teams").option("--teams-webhook <url>", "Teams incoming webhook URL").option("--card-style <style>", "Card style (compact, detailed, executive)", "detailed").option("--account <name>", "Account name for report").action(async (options, command) => {
11953
+ const { handleTeams: handleTeams2 } = await Promise.resolve().then(() => (init_teams2(), teams_exports));
11954
+ await handleTeams2(options, command);
11955
+ });
11152
11956
  }
11153
11957
  __name(registerChargebackCommands, "registerChargebackCommands");
11154
11958
 
@@ -11195,7 +11999,7 @@ __name(registerDashboardCommands, "registerDashboardCommands");
11195
11999
  // src/cli/commands/annotate/index.ts
11196
12000
  var fs3 = __toESM(require("fs/promises"));
11197
12001
  var path3 = __toESM(require("path"));
11198
- var import_chalk12 = __toESM(require("chalk"));
12002
+ var import_chalk15 = __toESM(require("chalk"));
11199
12003
  function registerAnnotateCommand(program) {
11200
12004
  program.command("annotate").description("Add cost annotations to Infrastructure as Code files").option("--path <path>", "Path to IaC files or directory", "./terraform").option(
11201
12005
  "--format <format>",
@@ -11205,7 +12009,7 @@ function registerAnnotateCommand(program) {
11205
12009
  try {
11206
12010
  await handleAnnotate(options);
11207
12011
  } catch (error) {
11208
- console.error(import_chalk12.default.red("Error:"), error.message);
12012
+ console.error(import_chalk15.default.red("Error:"), error.message);
11209
12013
  process.exit(1);
11210
12014
  }
11211
12015
  });
@@ -11220,10 +12024,10 @@ async function handleAnnotate(options) {
11220
12024
  }
11221
12025
  const files = await findIaCFiles(targetPath, options.format);
11222
12026
  if (files.length === 0) {
11223
- console.log(import_chalk12.default.yellow("No IaC files found at:", targetPath));
12027
+ console.log(import_chalk15.default.yellow("No IaC files found at:", targetPath));
11224
12028
  return;
11225
12029
  }
11226
- console.log(import_chalk12.default.cyan(`Found ${files.length} file(s) to annotate`));
12030
+ console.log(import_chalk15.default.cyan(`Found ${files.length} file(s) to annotate`));
11227
12031
  console.log();
11228
12032
  let annotatedCount = 0;
11229
12033
  let skippedCount = 0;
@@ -11232,29 +12036,29 @@ async function handleAnnotate(options) {
11232
12036
  if (result.annotated) {
11233
12037
  annotatedCount++;
11234
12038
  console.log(
11235
- import_chalk12.default.green("\u2713"),
12039
+ import_chalk15.default.green("\u2713"),
11236
12040
  path3.relative(process.cwd(), file),
11237
- import_chalk12.default.dim(`(${result.resourcesAnnotated} resources)`)
12041
+ import_chalk15.default.dim(`(${result.resourcesAnnotated} resources)`)
11238
12042
  );
11239
12043
  } else {
11240
12044
  skippedCount++;
11241
12045
  console.log(
11242
- import_chalk12.default.yellow("\u2298"),
12046
+ import_chalk15.default.yellow("\u2298"),
11243
12047
  path3.relative(process.cwd(), file),
11244
- import_chalk12.default.dim("(no changes)")
12048
+ import_chalk15.default.dim("(no changes)")
11245
12049
  );
11246
12050
  }
11247
12051
  }
11248
12052
  console.log();
11249
12053
  console.log(
11250
- import_chalk12.default.bold("Summary:"),
11251
- import_chalk12.default.green(`${annotatedCount} annotated`),
11252
- import_chalk12.default.yellow(`${skippedCount} skipped`)
12054
+ import_chalk15.default.bold("Summary:"),
12055
+ import_chalk15.default.green(`${annotatedCount} annotated`),
12056
+ import_chalk15.default.yellow(`${skippedCount} skipped`)
11253
12057
  );
11254
12058
  if (options.dryRun) {
11255
12059
  console.log();
11256
- console.log(import_chalk12.default.yellow("\u2139 Dry run - no files were modified"));
11257
- console.log(import_chalk12.default.dim("Run without --dry-run to apply changes"));
12060
+ console.log(import_chalk15.default.yellow("\u2139 Dry run - no files were modified"));
12061
+ console.log(import_chalk15.default.dim("Run without --dry-run to apply changes"));
11258
12062
  }
11259
12063
  }
11260
12064
  __name(handleAnnotate, "handleAnnotate");
@@ -11472,7 +12276,7 @@ __name(estimateResourceCost, "estimateResourceCost");
11472
12276
 
11473
12277
  // src/cli/commands/git/index.ts
11474
12278
  var import_child_process = require("child_process");
11475
- var import_chalk13 = __toESM(require("chalk"));
12279
+ var import_chalk16 = __toESM(require("chalk"));
11476
12280
  var import_dayjs7 = __toESM(require("dayjs"));
11477
12281
  function registerGitCommands(program) {
11478
12282
  const git = program.command("history").description("Show cost history with git correlation");
@@ -11480,7 +12284,7 @@ function registerGitCommands(program) {
11480
12284
  try {
11481
12285
  await handleHistory(options);
11482
12286
  } catch (error) {
11483
- console.error(import_chalk13.default.red("Error:"), error.message);
12287
+ console.error(import_chalk16.default.red("Error:"), error.message);
11484
12288
  process.exit(1);
11485
12289
  }
11486
12290
  });
@@ -11488,7 +12292,7 @@ function registerGitCommands(program) {
11488
12292
  try {
11489
12293
  await handleBlame(options);
11490
12294
  } catch (error) {
11491
- console.error(import_chalk13.default.red("Error:"), error.message);
12295
+ console.error(import_chalk16.default.red("Error:"), error.message);
11492
12296
  process.exit(1);
11493
12297
  }
11494
12298
  });
@@ -11529,17 +12333,17 @@ async function handleBlame(options) {
11529
12333
  return;
11530
12334
  }
11531
12335
  console.log();
11532
- console.log(import_chalk13.default.bold.cyan(`\u{1F50D} Cost Blame Analysis (${getPeriodLabel(period)})`));
11533
- console.log(import_chalk13.default.dim("\u2550".repeat(70)));
12336
+ console.log(import_chalk16.default.bold.cyan(`\u{1F50D} Cost Blame Analysis (${getPeriodLabel(period)})`));
12337
+ console.log(import_chalk16.default.dim("\u2550".repeat(70)));
11534
12338
  console.log();
11535
12339
  console.log(
11536
- import_chalk13.default.bold("Author").padEnd(35),
11537
- import_chalk13.default.bold("Cost Impact").padEnd(18),
11538
- import_chalk13.default.bold("Commits")
12340
+ import_chalk16.default.bold("Author").padEnd(35),
12341
+ import_chalk16.default.bold("Cost Impact").padEnd(18),
12342
+ import_chalk16.default.bold("Commits")
11539
12343
  );
11540
- console.log(import_chalk13.default.dim("\u2500".repeat(70)));
12344
+ console.log(import_chalk16.default.dim("\u2500".repeat(70)));
11541
12345
  sorted.forEach(([email, stats]) => {
11542
- const impactColor = stats.costImpact > 0 ? import_chalk13.default.red : import_chalk13.default.green;
12346
+ const impactColor = stats.costImpact > 0 ? import_chalk16.default.red : import_chalk16.default.green;
11543
12347
  const impactSign = stats.costImpact > 0 ? "+" : "";
11544
12348
  const emoji = stats.costImpact < 0 ? " \u{1F44F}" : "";
11545
12349
  console.log(
@@ -11548,7 +12352,7 @@ async function handleBlame(options) {
11548
12352
  stats.commits.toString() + emoji
11549
12353
  );
11550
12354
  });
11551
- console.log(import_chalk13.default.dim("\u2550".repeat(70)));
12355
+ console.log(import_chalk16.default.dim("\u2550".repeat(70)));
11552
12356
  console.log();
11553
12357
  }
11554
12358
  __name(handleBlame, "handleBlame");
@@ -11560,38 +12364,38 @@ async function showCostHistory(options) {
11560
12364
  return;
11561
12365
  }
11562
12366
  console.log();
11563
- console.log(import_chalk13.default.bold.cyan("\u{1F4CA} Cost History with Git Correlation"));
11564
- console.log(import_chalk13.default.dim("\u2550".repeat(80)));
12367
+ console.log(import_chalk16.default.bold.cyan("\u{1F4CA} Cost History with Git Correlation"));
12368
+ console.log(import_chalk16.default.dim("\u2550".repeat(80)));
11565
12369
  console.log();
11566
12370
  console.log(
11567
- import_chalk13.default.bold("Date").padEnd(14),
11568
- import_chalk13.default.bold("Cost").padEnd(12),
11569
- import_chalk13.default.bold("Change").padEnd(12),
11570
- import_chalk13.default.bold("Commit")
12371
+ import_chalk16.default.bold("Date").padEnd(14),
12372
+ import_chalk16.default.bold("Cost").padEnd(12),
12373
+ import_chalk16.default.bold("Change").padEnd(12),
12374
+ import_chalk16.default.bold("Commit")
11571
12375
  );
11572
- console.log(import_chalk13.default.dim("\u2500".repeat(80)));
12376
+ console.log(import_chalk16.default.dim("\u2500".repeat(80)));
11573
12377
  commits.forEach((commit) => {
11574
- const changeColor = commit.costChange > 0 ? import_chalk13.default.red : commit.costChange < 0 ? import_chalk13.default.green : import_chalk13.default.gray;
12378
+ const changeColor = commit.costChange > 0 ? import_chalk16.default.red : commit.costChange < 0 ? import_chalk16.default.green : import_chalk16.default.gray;
11575
12379
  const changeSign = commit.costChange > 0 ? "+" : "";
11576
12380
  console.log(
11577
12381
  (0, import_dayjs7.default)(commit.date).format("YYYY-MM-DD").padEnd(14),
11578
- import_chalk13.default.green(`$${commit.cost.toFixed(2)}`).padEnd(12),
12382
+ import_chalk16.default.green(`$${commit.cost.toFixed(2)}`).padEnd(12),
11579
12383
  changeColor(`${changeSign}$${commit.costChange.toFixed(2)}`).padEnd(12),
11580
- import_chalk13.default.dim(commit.shortCommit),
12384
+ import_chalk16.default.dim(commit.shortCommit),
11581
12385
  commit.message.substring(0, 40)
11582
12386
  );
11583
12387
  });
11584
- console.log(import_chalk13.default.dim("\u2550".repeat(80)));
12388
+ console.log(import_chalk16.default.dim("\u2550".repeat(80)));
11585
12389
  console.log();
11586
12390
  const significant = commits.filter((c) => Math.abs(c.costChange) > 10);
11587
12391
  if (significant.length > 0) {
11588
- console.log(import_chalk13.default.bold("\u{1F50D} Significant cost changes:"));
12392
+ console.log(import_chalk16.default.bold("\u{1F50D} Significant cost changes:"));
11589
12393
  significant.forEach((commit) => {
11590
12394
  const sign = commit.costChange > 0 ? "+" : "";
11591
- const color = commit.costChange > 0 ? import_chalk13.default.red : import_chalk13.default.green;
12395
+ const color = commit.costChange > 0 ? import_chalk16.default.red : import_chalk16.default.green;
11592
12396
  console.log(
11593
12397
  `\u2022 ${color(`${sign}$${Math.abs(commit.costChange).toFixed(2)}`)} on ${(0, import_dayjs7.default)(commit.date).format("YYYY-MM-DD")}: `,
11594
- import_chalk13.default.dim(commit.shortCommit),
12398
+ import_chalk16.default.dim(commit.shortCommit),
11595
12399
  `"${commit.message}"`
11596
12400
  );
11597
12401
  });
@@ -11633,28 +12437,28 @@ async function showCommitDetails(commitHash, format) {
11633
12437
  return;
11634
12438
  }
11635
12439
  console.log();
11636
- console.log(import_chalk13.default.bold.cyan("\u{1F4DD} Commit Cost Analysis"));
11637
- console.log(import_chalk13.default.dim("\u2550".repeat(70)));
11638
- console.log(import_chalk13.default.bold("Commit:"), import_chalk13.default.dim(fullHash.substring(0, 10)));
11639
- console.log(import_chalk13.default.bold("Author:"), author);
11640
- console.log(import_chalk13.default.bold("Date:"), (0, import_dayjs7.default)(date).format("YYYY-MM-DD HH:mm:ss"));
11641
- console.log(import_chalk13.default.bold("Message:"), subject);
11642
- console.log(import_chalk13.default.dim("\u2500".repeat(70)));
11643
- const impactColor = costImpact > 0 ? import_chalk13.default.red : import_chalk13.default.green;
12440
+ console.log(import_chalk16.default.bold.cyan("\u{1F4DD} Commit Cost Analysis"));
12441
+ console.log(import_chalk16.default.dim("\u2550".repeat(70)));
12442
+ console.log(import_chalk16.default.bold("Commit:"), import_chalk16.default.dim(fullHash.substring(0, 10)));
12443
+ console.log(import_chalk16.default.bold("Author:"), author);
12444
+ console.log(import_chalk16.default.bold("Date:"), (0, import_dayjs7.default)(date).format("YYYY-MM-DD HH:mm:ss"));
12445
+ console.log(import_chalk16.default.bold("Message:"), subject);
12446
+ console.log(import_chalk16.default.dim("\u2500".repeat(70)));
12447
+ const impactColor = costImpact > 0 ? import_chalk16.default.red : import_chalk16.default.green;
11644
12448
  const impactSign = costImpact > 0 ? "+" : "";
11645
12449
  console.log(
11646
- import_chalk13.default.bold("Cost Impact:"),
12450
+ import_chalk16.default.bold("Cost Impact:"),
11647
12451
  impactColor(`${impactSign}$${Math.abs(costImpact).toFixed(2)}/day`),
11648
- import_chalk13.default.dim(`(${impactSign}${percentChange.toFixed(1)}%)`)
12452
+ import_chalk16.default.dim(`(${impactSign}${percentChange.toFixed(1)}%)`)
11649
12453
  );
11650
12454
  console.log();
11651
12455
  if (files.length > 0) {
11652
- console.log(import_chalk13.default.bold("Files Changed:"));
12456
+ console.log(import_chalk16.default.bold("Files Changed:"));
11653
12457
  files.slice(0, 10).forEach((file) => {
11654
12458
  console.log(` \u2022 ${file}`);
11655
12459
  });
11656
12460
  if (files.length > 10) {
11657
- console.log(import_chalk13.default.dim(` ... and ${files.length - 10} more`));
12461
+ console.log(import_chalk16.default.dim(` ... and ${files.length - 10} more`));
11658
12462
  }
11659
12463
  }
11660
12464
  console.log();
@@ -11729,26 +12533,600 @@ function getPeriodLabel(period) {
11729
12533
  }
11730
12534
  __name(getPeriodLabel, "getPeriodLabel");
11731
12535
 
12536
+ // src/cli/commands/terraform/index.ts
12537
+ var import_fs4 = require("fs");
12538
+ var import_child_process2 = require("child_process");
12539
+ var import_chalk17 = __toESM(require("chalk"));
12540
+ var AWS_PRICING = {
12541
+ // EC2 instances (us-east-1 on-demand hourly rates)
12542
+ ec2: {
12543
+ "t2.micro": 0.0116,
12544
+ "t2.small": 0.0232,
12545
+ "t2.medium": 0.0464,
12546
+ "t2.large": 0.0928,
12547
+ "t2.xlarge": 0.1856,
12548
+ "t3.micro": 0.0104,
12549
+ "t3.small": 0.0208,
12550
+ "t3.medium": 0.0416,
12551
+ "t3.large": 0.0832,
12552
+ "t3.xlarge": 0.1664,
12553
+ "t3.2xlarge": 0.3328,
12554
+ "m5.large": 0.096,
12555
+ "m5.xlarge": 0.192,
12556
+ "m5.2xlarge": 0.384,
12557
+ "c5.large": 0.085,
12558
+ "c5.xlarge": 0.17,
12559
+ "r5.large": 0.126,
12560
+ "r5.xlarge": 0.252
12561
+ },
12562
+ // RDS instances (db.r5 family)
12563
+ rds: {
12564
+ "db.t3.micro": 0.017,
12565
+ "db.t3.small": 0.034,
12566
+ "db.t3.medium": 0.068,
12567
+ "db.t3.large": 0.136,
12568
+ "db.r5.large": 0.24,
12569
+ "db.r5.xlarge": 0.48,
12570
+ "db.r5.2xlarge": 0.96,
12571
+ "db.m5.large": 0.196,
12572
+ "db.m5.xlarge": 0.392
12573
+ },
12574
+ // EBS volumes (per GB-month)
12575
+ ebs: {
12576
+ gp2: 0.1,
12577
+ gp3: 0.08,
12578
+ io1: 0.125,
12579
+ io2: 0.125,
12580
+ st1: 0.045,
12581
+ sc1: 0.015
12582
+ },
12583
+ // Load Balancers (per hour)
12584
+ alb: 0.0225,
12585
+ nlb: 0.0225,
12586
+ clb: 0.025,
12587
+ // NAT Gateway (per hour + data transfer)
12588
+ natgateway: 0.045,
12589
+ // ElastiCache (per hour)
12590
+ elasticache: {
12591
+ "cache.t3.micro": 0.017,
12592
+ "cache.t3.small": 0.034,
12593
+ "cache.m5.large": 0.161
12594
+ }
12595
+ };
12596
+ function parseTerraformPlan(planPath) {
12597
+ try {
12598
+ let planJson;
12599
+ if (planPath.endsWith(".json")) {
12600
+ planJson = (0, import_fs4.readFileSync)(planPath, "utf-8");
12601
+ } else {
12602
+ planJson = (0, import_child_process2.execSync)(`terraform show -json "${planPath}"`, {
12603
+ encoding: "utf-8"
12604
+ });
12605
+ }
12606
+ return JSON.parse(planJson);
12607
+ } catch (error) {
12608
+ throw new Error(`Failed to parse Terraform plan: ${error.message}`);
12609
+ }
12610
+ }
12611
+ __name(parseTerraformPlan, "parseTerraformPlan");
12612
+ function estimateResourceCost2(change) {
12613
+ const { type, name, address, change: changeDetails } = change;
12614
+ const action = changeDetails.actions[0];
12615
+ const actionMap = {
12616
+ create: "create",
12617
+ update: "modify",
12618
+ delete: "destroy"
12619
+ };
12620
+ const mappedAction = actionMap[action] || "create";
12621
+ const config = changeDetails.after || changeDetails.before || {};
12622
+ let monthlyCost = 0;
12623
+ let hourlyCost = 0;
12624
+ let details = "";
12625
+ if (type === "aws_instance") {
12626
+ const instanceType = config.instance_type || "t3.micro";
12627
+ hourlyCost = AWS_PRICING.ec2[instanceType] || 0.1;
12628
+ monthlyCost = hourlyCost * 730;
12629
+ details = instanceType;
12630
+ } else if (type === "aws_db_instance") {
12631
+ const instanceClass = config.instance_class || "db.t3.micro";
12632
+ hourlyCost = AWS_PRICING.rds[instanceClass] || 0.1;
12633
+ monthlyCost = hourlyCost * 730;
12634
+ const allocatedStorage = config.allocated_storage || 20;
12635
+ const storageType = config.storage_type || "gp2";
12636
+ const storageCostPerGB = AWS_PRICING.ebs[storageType] || 0.1;
12637
+ monthlyCost += allocatedStorage * storageCostPerGB;
12638
+ details = `${instanceClass}, ${allocatedStorage}GB ${storageType}`;
12639
+ } else if (type === "aws_ebs_volume") {
12640
+ const size = config.size || 8;
12641
+ const volumeType = config.type || "gp2";
12642
+ const costPerGB = AWS_PRICING.ebs[volumeType] || 0.1;
12643
+ monthlyCost = size * costPerGB;
12644
+ hourlyCost = monthlyCost / 730;
12645
+ details = `${size}GB ${volumeType}`;
12646
+ } else if (type === "aws_lb" || type === "aws_alb") {
12647
+ const lbType = config.load_balancer_type || "application";
12648
+ hourlyCost = lbType === "network" ? AWS_PRICING.nlb : AWS_PRICING.alb;
12649
+ monthlyCost = hourlyCost * 730;
12650
+ details = `${lbType} load balancer`;
12651
+ } else if (type === "aws_elb") {
12652
+ hourlyCost = AWS_PRICING.clb;
12653
+ monthlyCost = hourlyCost * 730;
12654
+ details = "classic load balancer";
12655
+ } else if (type === "aws_nat_gateway") {
12656
+ hourlyCost = AWS_PRICING.natgateway;
12657
+ monthlyCost = hourlyCost * 730;
12658
+ details = "NAT gateway (base cost)";
12659
+ } else if (type === "aws_elasticache_cluster") {
12660
+ const nodeType = config.node_type || "cache.t3.micro";
12661
+ const numNodes = config.num_cache_nodes || 1;
12662
+ hourlyCost = (AWS_PRICING.elasticache[nodeType] || 0.017) * numNodes;
12663
+ monthlyCost = hourlyCost * 730;
12664
+ details = `${numNodes}x ${nodeType}`;
12665
+ } else if (type === "aws_s3_bucket") {
12666
+ monthlyCost = 5;
12667
+ hourlyCost = monthlyCost / 730;
12668
+ details = "estimated storage cost";
12669
+ } else if (type === "aws_lambda_function") {
12670
+ monthlyCost = 1;
12671
+ hourlyCost = monthlyCost / 730;
12672
+ details = "estimated execution cost";
12673
+ } else {
12674
+ return null;
12675
+ }
12676
+ if (mappedAction === "destroy") {
12677
+ monthlyCost = -monthlyCost;
12678
+ hourlyCost = -hourlyCost;
12679
+ }
12680
+ return {
12681
+ resource: address,
12682
+ resourceType: type,
12683
+ action: mappedAction,
12684
+ monthlyCost,
12685
+ hourlyCost,
12686
+ details
12687
+ };
12688
+ }
12689
+ __name(estimateResourceCost2, "estimateResourceCost");
12690
+ function analyzePlan(plan) {
12691
+ const creates = [];
12692
+ const modifies = [];
12693
+ const destroys = [];
12694
+ const changes = plan.resource_changes || [];
12695
+ changes.forEach((change) => {
12696
+ const estimate = estimateResourceCost2(change);
12697
+ if (!estimate)
12698
+ return;
12699
+ if (estimate.action === "create") {
12700
+ creates.push(estimate);
12701
+ } else if (estimate.action === "modify") {
12702
+ modifies.push(estimate);
12703
+ } else if (estimate.action === "destroy") {
12704
+ destroys.push(estimate);
12705
+ }
12706
+ });
12707
+ const createCost = creates.reduce((sum, e) => sum + e.monthlyCost, 0);
12708
+ const destroyCost = Math.abs(
12709
+ destroys.reduce((sum, e) => sum + e.monthlyCost, 0)
12710
+ );
12711
+ const modifyCost = modifies.reduce((sum, e) => sum + e.monthlyCost, 0);
12712
+ const currentMonthlyCost = destroyCost;
12713
+ const newMonthlyCost = createCost + modifyCost;
12714
+ const difference = newMonthlyCost - currentMonthlyCost;
12715
+ const percentChange = currentMonthlyCost > 0 ? difference / currentMonthlyCost * 100 : difference > 0 ? 100 : 0;
12716
+ return {
12717
+ creates,
12718
+ modifies,
12719
+ destroys,
12720
+ currentMonthlyCost,
12721
+ newMonthlyCost,
12722
+ difference,
12723
+ percentChange
12724
+ };
12725
+ }
12726
+ __name(analyzePlan, "analyzePlan");
12727
+ function formatCostEstimate(summary, options) {
12728
+ const { output } = options;
12729
+ if (output === "json") {
12730
+ return JSON.stringify(summary, null, 2);
12731
+ }
12732
+ let result = "";
12733
+ result += import_chalk17.default.bold.blue(
12734
+ "\u256D\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E\n"
12735
+ );
12736
+ result += import_chalk17.default.bold.blue(
12737
+ "\u2502" + import_chalk17.default.white(" Terraform Cost Estimate ") + "\u2502\n"
12738
+ );
12739
+ result += import_chalk17.default.bold.blue(
12740
+ "\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n"
12741
+ );
12742
+ if (summary.creates.length > 0) {
12743
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.green("Resources to CREATE:") + " ".repeat(38) + import_chalk17.default.bold.blue("\u2502\n");
12744
+ result += import_chalk17.default.bold.blue(
12745
+ "\u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2502\n"
12746
+ );
12747
+ summary.creates.forEach((est) => {
12748
+ const resourceLine = `+ ${est.resource} (${est.details})`;
12749
+ const costLine = ` \u2514\u2500\u2500 Monthly: $${est.monthlyCost.toFixed(2)} | Hourly: $${est.hourlyCost.toFixed(4)}`;
12750
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.green(resourceLine.padEnd(59)) + import_chalk17.default.bold.blue("\u2502\n");
12751
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.gray(costLine.padEnd(59)) + import_chalk17.default.bold.blue("\u2502\n");
12752
+ });
12753
+ result += import_chalk17.default.bold.blue(
12754
+ "\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n"
12755
+ );
12756
+ }
12757
+ if (summary.modifies.length > 0) {
12758
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.yellow("Resources to MODIFY:") + " ".repeat(38) + import_chalk17.default.bold.blue("\u2502\n");
12759
+ result += import_chalk17.default.bold.blue(
12760
+ "\u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2502\n"
12761
+ );
12762
+ summary.modifies.forEach((est) => {
12763
+ const resourceLine = `~ ${est.resource}`;
12764
+ const costLine = ` \u2514\u2500\u2500 ${est.details}: ${est.monthlyCost >= 0 ? "+" : ""}$${est.monthlyCost.toFixed(2)}/month`;
12765
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.yellow(resourceLine.padEnd(59)) + import_chalk17.default.bold.blue("\u2502\n");
12766
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.gray(costLine.padEnd(59)) + import_chalk17.default.bold.blue("\u2502\n");
12767
+ });
12768
+ result += import_chalk17.default.bold.blue(
12769
+ "\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n"
12770
+ );
12771
+ }
12772
+ if (summary.destroys.length > 0) {
12773
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.red("Resources to DESTROY:") + " ".repeat(37) + import_chalk17.default.bold.blue("\u2502\n");
12774
+ result += import_chalk17.default.bold.blue(
12775
+ "\u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2502\n"
12776
+ );
12777
+ summary.destroys.forEach((est) => {
12778
+ const resourceLine = `- ${est.resource}`;
12779
+ const costLine = ` \u2514\u2500\u2500 Savings: $${Math.abs(est.monthlyCost).toFixed(2)}/month`;
12780
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.red(resourceLine.padEnd(59)) + import_chalk17.default.bold.blue("\u2502\n");
12781
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.gray(costLine.padEnd(59)) + import_chalk17.default.bold.blue("\u2502\n");
12782
+ });
12783
+ result += import_chalk17.default.bold.blue(
12784
+ "\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n"
12785
+ );
12786
+ }
12787
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.bold.white("SUMMARY") + " ".repeat(52) + import_chalk17.default.bold.blue("\u2502\n");
12788
+ result += import_chalk17.default.bold.blue(
12789
+ "\u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2502\n"
12790
+ );
12791
+ const currentLine = `Current Monthly Cost: $${summary.currentMonthlyCost.toFixed(2)}`;
12792
+ const newLine = `Estimated New Cost: $${summary.newMonthlyCost.toFixed(2)}`;
12793
+ const diffSymbol = summary.difference >= 0 ? "+" : "";
12794
+ const diffLine = `Difference: ${diffSymbol}$${summary.difference.toFixed(2)}/month (${diffSymbol}${summary.percentChange.toFixed(1)}%)`;
12795
+ result += import_chalk17.default.bold.blue("\u2502 ") + currentLine.padEnd(59) + import_chalk17.default.bold.blue("\u2502\n");
12796
+ result += import_chalk17.default.bold.blue("\u2502 ") + newLine.padEnd(59) + import_chalk17.default.bold.blue("\u2502\n");
12797
+ const diffColor = summary.difference > 0 ? import_chalk17.default.red : import_chalk17.default.green;
12798
+ result += import_chalk17.default.bold.blue("\u2502 ") + diffColor(diffLine).padEnd(69) + import_chalk17.default.bold.blue("\u2502\n");
12799
+ const threshold = parseFloat(options.threshold || "20");
12800
+ if (Math.abs(summary.percentChange) > threshold) {
12801
+ result += import_chalk17.default.bold.blue("\u2502 ") + " ".repeat(59) + import_chalk17.default.bold.blue("\u2502\n");
12802
+ const warning = `\u26A0\uFE0F Cost ${summary.difference > 0 ? "increase" : "decrease"} exceeds ${threshold}% threshold!`;
12803
+ result += import_chalk17.default.bold.blue("\u2502 ") + import_chalk17.default.yellow.bold(warning.padEnd(59)) + import_chalk17.default.bold.blue("\u2502\n");
12804
+ }
12805
+ result += import_chalk17.default.bold.blue(
12806
+ "\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F\n"
12807
+ );
12808
+ return result;
12809
+ }
12810
+ __name(formatCostEstimate, "formatCostEstimate");
12811
+ async function handleTerraform(options) {
12812
+ const { plan, threshold, output } = options;
12813
+ if (!plan) {
12814
+ console.error(import_chalk17.default.red("Error: --plan argument is required"));
12815
+ console.log("Usage: infra-cost terraform --plan <path-to-terraform-plan>");
12816
+ process.exit(1);
12817
+ }
12818
+ try {
12819
+ console.log(import_chalk17.default.blue("\u{1F4CA} Analyzing Terraform plan...\n"));
12820
+ const terraformPlan = parseTerraformPlan(plan);
12821
+ const summary = analyzePlan(terraformPlan);
12822
+ const formatted = formatCostEstimate(summary, options);
12823
+ console.log(formatted);
12824
+ const thresholdValue = parseFloat(threshold || "0");
12825
+ if (thresholdValue > 0 && Math.abs(summary.percentChange) > thresholdValue) {
12826
+ process.exit(1);
12827
+ }
12828
+ } catch (error) {
12829
+ console.error(import_chalk17.default.red(`Error: ${error.message}`));
12830
+ process.exit(1);
12831
+ }
12832
+ }
12833
+ __name(handleTerraform, "handleTerraform");
12834
+ function registerTerraformCommand(program) {
12835
+ program.command("terraform").description("Estimate costs from Terraform plan (shift-left cost management)").option(
12836
+ "--plan <path>",
12837
+ "Path to terraform plan file (binary or JSON)",
12838
+ ""
12839
+ ).option(
12840
+ "--threshold <percent>",
12841
+ "Fail if cost change exceeds threshold percentage",
12842
+ "0"
12843
+ ).action(handleTerraform);
12844
+ }
12845
+ __name(registerTerraformCommand, "registerTerraformCommand");
12846
+
12847
+ // src/cli/commands/scheduler/index.ts
12848
+ var import_fs5 = require("fs");
12849
+ var import_path3 = require("path");
12850
+ var import_os3 = require("os");
12851
+ var import_chalk18 = __toESM(require("chalk"));
12852
+ var CONFIG_DIR = (0, import_path3.join)((0, import_os3.homedir)(), ".infra-cost");
12853
+ var CONFIG_FILE = (0, import_path3.join)(CONFIG_DIR, "scheduler.json");
12854
+ var PID_FILE = (0, import_path3.join)(CONFIG_DIR, "scheduler.pid");
12855
+ var LOG_FILE = (0, import_path3.join)(CONFIG_DIR, "scheduler.log");
12856
+ function getConfig() {
12857
+ if (!(0, import_fs5.existsSync)(CONFIG_FILE)) {
12858
+ return {
12859
+ schedules: [],
12860
+ daemon: {
12861
+ pidFile: PID_FILE,
12862
+ logFile: LOG_FILE
12863
+ }
12864
+ };
12865
+ }
12866
+ try {
12867
+ return JSON.parse((0, import_fs5.readFileSync)(CONFIG_FILE, "utf-8"));
12868
+ } catch (error) {
12869
+ console.error(import_chalk18.default.red("Error reading scheduler config:", error));
12870
+ return {
12871
+ schedules: [],
12872
+ daemon: {
12873
+ pidFile: PID_FILE,
12874
+ logFile: LOG_FILE
12875
+ }
12876
+ };
12877
+ }
12878
+ }
12879
+ __name(getConfig, "getConfig");
12880
+ function saveConfig(config) {
12881
+ try {
12882
+ (0, import_fs5.writeFileSync)(CONFIG_FILE, JSON.stringify(config, null, 2));
12883
+ } catch (error) {
12884
+ console.error(import_chalk18.default.red("Error saving scheduler config:", error));
12885
+ process.exit(1);
12886
+ }
12887
+ }
12888
+ __name(saveConfig, "saveConfig");
12889
+ function isDaemonRunning() {
12890
+ if (!(0, import_fs5.existsSync)(PID_FILE)) {
12891
+ return false;
12892
+ }
12893
+ try {
12894
+ const pid = parseInt((0, import_fs5.readFileSync)(PID_FILE, "utf-8").trim(), 10);
12895
+ process.kill(pid, 0);
12896
+ return true;
12897
+ } catch (error) {
12898
+ try {
12899
+ if ((0, import_fs5.existsSync)(PID_FILE)) {
12900
+ require("fs").unlinkSync(PID_FILE);
12901
+ }
12902
+ } catch (e) {
12903
+ }
12904
+ return false;
12905
+ }
12906
+ }
12907
+ __name(isDaemonRunning, "isDaemonRunning");
12908
+ function getNextRun(cron) {
12909
+ const now = /* @__PURE__ */ new Date();
12910
+ const next = new Date(now.getTime() + 24 * 60 * 60 * 1e3);
12911
+ return next.toISOString();
12912
+ }
12913
+ __name(getNextRun, "getNextRun");
12914
+ async function handleStart(options) {
12915
+ if (isDaemonRunning()) {
12916
+ console.log(import_chalk18.default.yellow("\u26A0\uFE0F Scheduler daemon is already running"));
12917
+ console.log(import_chalk18.default.gray("Run `infra-cost scheduler status` to check status"));
12918
+ return;
12919
+ }
12920
+ const config = getConfig();
12921
+ if (config.schedules.length === 0) {
12922
+ console.log(import_chalk18.default.yellow("\u26A0\uFE0F No schedules configured"));
12923
+ console.log(import_chalk18.default.gray("Add schedules with: infra-cost scheduler add"));
12924
+ return;
12925
+ }
12926
+ console.log(import_chalk18.default.blue("\u{1F680} Starting scheduler daemon..."));
12927
+ console.log(import_chalk18.default.gray(` Log file: ${LOG_FILE}`));
12928
+ console.log(import_chalk18.default.gray(` PID file: ${PID_FILE}`));
12929
+ console.log(import_chalk18.default.gray(` Schedules: ${config.schedules.filter((s) => s.enabled).length} enabled`));
12930
+ console.log(import_chalk18.default.green("\u2705 Scheduler daemon started"));
12931
+ console.log(import_chalk18.default.gray("Run `infra-cost scheduler status` to check status"));
12932
+ console.log(import_chalk18.default.gray("Run `infra-cost scheduler logs` to view execution logs"));
12933
+ (0, import_fs5.writeFileSync)(PID_FILE, process.pid.toString());
12934
+ }
12935
+ __name(handleStart, "handleStart");
12936
+ async function handleStop(options) {
12937
+ if (!isDaemonRunning()) {
12938
+ console.log(import_chalk18.default.yellow("\u26A0\uFE0F Scheduler daemon is not running"));
12939
+ return;
12940
+ }
12941
+ try {
12942
+ const pid = parseInt((0, import_fs5.readFileSync)(PID_FILE, "utf-8").trim(), 10);
12943
+ console.log(import_chalk18.default.blue("\u{1F6D1} Stopping scheduler daemon..."));
12944
+ process.kill(pid, "SIGTERM");
12945
+ if ((0, import_fs5.existsSync)(PID_FILE)) {
12946
+ require("fs").unlinkSync(PID_FILE);
12947
+ }
12948
+ console.log(import_chalk18.default.green("\u2705 Scheduler daemon stopped"));
12949
+ } catch (error) {
12950
+ console.error(import_chalk18.default.red("Error stopping daemon:", error.message));
12951
+ process.exit(1);
12952
+ }
12953
+ }
12954
+ __name(handleStop, "handleStop");
12955
+ async function handleStatus(options) {
12956
+ const config = getConfig();
12957
+ const isRunning = isDaemonRunning();
12958
+ console.log(import_chalk18.default.bold("\n\u{1F4CA} Scheduler Status\n"));
12959
+ console.log(import_chalk18.default.bold("Daemon:"));
12960
+ if (isRunning) {
12961
+ const pid = (0, import_fs5.readFileSync)(PID_FILE, "utf-8").trim();
12962
+ console.log(import_chalk18.default.green(" Status: \u2705 Running"));
12963
+ console.log(import_chalk18.default.gray(` PID: ${pid}`));
12964
+ } else {
12965
+ console.log(import_chalk18.default.red(" Status: \u274C Stopped"));
12966
+ }
12967
+ console.log(import_chalk18.default.gray(` Log file: ${LOG_FILE}`));
12968
+ console.log(import_chalk18.default.gray(` Config: ${CONFIG_FILE}`));
12969
+ console.log(import_chalk18.default.bold("\nSchedules:"));
12970
+ if (config.schedules.length === 0) {
12971
+ console.log(import_chalk18.default.gray(" No schedules configured"));
12972
+ } else {
12973
+ const enabled = config.schedules.filter((s) => s.enabled);
12974
+ const disabled = config.schedules.filter((s) => !s.enabled);
12975
+ console.log(import_chalk18.default.gray(` Total: ${config.schedules.length} (${enabled.length} enabled, ${disabled.length} disabled)`));
12976
+ config.schedules.forEach((schedule) => {
12977
+ const status = schedule.enabled ? import_chalk18.default.green("\u2713") : import_chalk18.default.gray("\u2717");
12978
+ console.log(` ${status} ${import_chalk18.default.bold(schedule.name)}`);
12979
+ console.log(import_chalk18.default.gray(` Cron: ${schedule.cron}`));
12980
+ console.log(import_chalk18.default.gray(` Command: infra-cost ${schedule.command}`));
12981
+ if (schedule.lastRun) {
12982
+ console.log(import_chalk18.default.gray(` Last run: ${schedule.lastRun}`));
12983
+ }
12984
+ });
12985
+ }
12986
+ console.log("");
12987
+ }
12988
+ __name(handleStatus, "handleStatus");
12989
+ async function handleAdd(options) {
12990
+ const { name, cron, command, timezone } = options;
12991
+ if (!name || !cron || !command) {
12992
+ console.error(import_chalk18.default.red("Error: --name, --cron, and --command are required"));
12993
+ console.log("\nExample:");
12994
+ console.log(import_chalk18.default.gray(" infra-cost scheduler add \\"));
12995
+ console.log(import_chalk18.default.gray(' --name "daily-report" \\'));
12996
+ console.log(import_chalk18.default.gray(' --cron "0 9 * * *" \\'));
12997
+ console.log(import_chalk18.default.gray(' --command "now --output json"'));
12998
+ process.exit(1);
12999
+ }
13000
+ const config = getConfig();
13001
+ if (config.schedules.find((s) => s.name === name)) {
13002
+ console.error(import_chalk18.default.red(`Error: Schedule "${name}" already exists`));
13003
+ console.log(import_chalk18.default.gray("Use a different name or remove the existing schedule first"));
13004
+ process.exit(1);
13005
+ }
13006
+ const newSchedule = {
13007
+ name,
13008
+ cron,
13009
+ command,
13010
+ timezone: timezone || "UTC",
13011
+ enabled: true,
13012
+ nextRun: getNextRun(cron)
13013
+ };
13014
+ config.schedules.push(newSchedule);
13015
+ saveConfig(config);
13016
+ console.log(import_chalk18.default.green("\u2705 Schedule added successfully"));
13017
+ console.log(import_chalk18.default.gray(` Name: ${name}`));
13018
+ console.log(import_chalk18.default.gray(` Cron: ${cron}`));
13019
+ console.log(import_chalk18.default.gray(` Command: infra-cost ${command}`));
13020
+ console.log(import_chalk18.default.gray(` Timezone: ${timezone || "UTC"}`));
13021
+ console.log("");
13022
+ console.log(import_chalk18.default.gray("Start the scheduler daemon to activate: infra-cost scheduler start"));
13023
+ }
13024
+ __name(handleAdd, "handleAdd");
13025
+ async function handleRemove(options) {
13026
+ const { name } = options;
13027
+ if (!name) {
13028
+ console.error(import_chalk18.default.red("Error: --name is required"));
13029
+ process.exit(1);
13030
+ }
13031
+ const config = getConfig();
13032
+ const index = config.schedules.findIndex((s) => s.name === name);
13033
+ if (index === -1) {
13034
+ console.error(import_chalk18.default.red(`Error: Schedule "${name}" not found`));
13035
+ process.exit(1);
13036
+ }
13037
+ config.schedules.splice(index, 1);
13038
+ saveConfig(config);
13039
+ console.log(import_chalk18.default.green(`\u2705 Schedule "${name}" removed`));
13040
+ }
13041
+ __name(handleRemove, "handleRemove");
13042
+ async function handleList2(options) {
13043
+ const config = getConfig();
13044
+ if (config.schedules.length === 0) {
13045
+ console.log(import_chalk18.default.yellow("No schedules configured"));
13046
+ console.log(import_chalk18.default.gray("\nAdd a schedule with: infra-cost scheduler add"));
13047
+ return;
13048
+ }
13049
+ console.log(import_chalk18.default.bold("\n\u{1F4C5} Configured Schedules\n"));
13050
+ config.schedules.forEach((schedule, index) => {
13051
+ const status = schedule.enabled ? import_chalk18.default.green("\u2713 ENABLED") : import_chalk18.default.gray("\u2717 DISABLED");
13052
+ console.log(import_chalk18.default.bold(`${index + 1}. ${schedule.name}`) + ` ${status}`);
13053
+ console.log(import_chalk18.default.gray(` Cron: ${schedule.cron}`));
13054
+ console.log(import_chalk18.default.gray(` Command: infra-cost ${schedule.command}`));
13055
+ console.log(import_chalk18.default.gray(` Timezone: ${schedule.timezone || "UTC"}`));
13056
+ if (schedule.lastRun) {
13057
+ console.log(import_chalk18.default.gray(` Last run: ${schedule.lastRun}`));
13058
+ }
13059
+ if (schedule.nextRun) {
13060
+ console.log(import_chalk18.default.gray(` Next run: ${schedule.nextRun}`));
13061
+ }
13062
+ console.log("");
13063
+ });
13064
+ }
13065
+ __name(handleList2, "handleList");
13066
+ async function handleLogs(options) {
13067
+ if (!(0, import_fs5.existsSync)(LOG_FILE)) {
13068
+ console.log(import_chalk18.default.yellow("No logs found"));
13069
+ console.log(import_chalk18.default.gray("Logs will appear here once the scheduler runs"));
13070
+ return;
13071
+ }
13072
+ const logs = (0, import_fs5.readFileSync)(LOG_FILE, "utf-8");
13073
+ console.log(logs);
13074
+ }
13075
+ __name(handleLogs, "handleLogs");
13076
+ async function handleGenerateSystemd(options) {
13077
+ const user = process.env.USER || "ubuntu";
13078
+ const nodePath = process.execPath;
13079
+ const infraCostPath = require.main?.filename || "/usr/local/bin/infra-cost";
13080
+ const serviceFile = `[Unit]
13081
+ Description=Infra Cost Scheduler Daemon
13082
+ After=network.target
13083
+
13084
+ [Service]
13085
+ Type=simple
13086
+ User=${user}
13087
+ ExecStart=${nodePath} ${infraCostPath} scheduler start
13088
+ Restart=always
13089
+ RestartSec=10
13090
+ StandardOutput=append:${LOG_FILE}
13091
+ StandardError=append:${LOG_FILE}
13092
+
13093
+ [Install]
13094
+ WantedBy=multi-user.target
13095
+ `;
13096
+ console.log(import_chalk18.default.bold("\u{1F4DD} Systemd Service File\n"));
13097
+ console.log(serviceFile);
13098
+ console.log(import_chalk18.default.gray("\nSave this to: /etc/systemd/system/infra-cost-scheduler.service"));
13099
+ console.log(import_chalk18.default.gray("\nThen run:"));
13100
+ console.log(import_chalk18.default.gray(" sudo systemctl daemon-reload"));
13101
+ console.log(import_chalk18.default.gray(" sudo systemctl enable infra-cost-scheduler"));
13102
+ console.log(import_chalk18.default.gray(" sudo systemctl start infra-cost-scheduler"));
13103
+ }
13104
+ __name(handleGenerateSystemd, "handleGenerateSystemd");
13105
+ function registerSchedulerCommands(program) {
13106
+ const scheduler = program.command("scheduler").description("Manage scheduled cost reports (daemon mode)");
13107
+ scheduler.command("start").description("Start scheduler daemon").action(handleStart);
13108
+ scheduler.command("stop").description("Stop scheduler daemon").action(handleStop);
13109
+ scheduler.command("status").description("Show scheduler status").action(handleStatus);
13110
+ scheduler.command("add").description("Add new schedule").option("--name <name>", "Schedule name").option("--cron <expression>", 'Cron expression (e.g., "0 9 * * *")').option("--command <command>", "infra-cost command to run").option("--timezone <tz>", "Timezone (default: UTC)", "UTC").action(handleAdd);
13111
+ scheduler.command("remove").description("Remove schedule").option("--name <name>", "Schedule name").action(handleRemove);
13112
+ scheduler.command("list").description("List all schedules").action(handleList2);
13113
+ scheduler.command("logs").description("View scheduler execution logs").action(handleLogs);
13114
+ scheduler.command("generate-systemd").description("Generate systemd service file").action(handleGenerateSystemd);
13115
+ }
13116
+ __name(registerSchedulerCommands, "registerSchedulerCommands");
13117
+
11732
13118
  // src/cli/middleware/auth.ts
11733
- init_logging();
11734
13119
  async function authMiddleware(thisCommand, actionCommand) {
11735
- const logger = getGlobalLogger27();
11736
- const opts = thisCommand.opts();
11737
13120
  const isConfigCommand = actionCommand.name() === "config" || actionCommand.parent?.name() === "config";
11738
13121
  if (isConfigCommand) {
11739
13122
  return;
11740
13123
  }
11741
- logger.debug("Running authentication middleware", { provider: opts.provider });
11742
- logger.debug("Authentication check passed");
11743
13124
  }
11744
13125
  __name(authMiddleware, "authMiddleware");
11745
13126
 
11746
13127
  // src/cli/middleware/validation.ts
11747
- init_logging();
11748
13128
  async function validationMiddleware(thisCommand, actionCommand) {
11749
- const logger = getGlobalLogger28();
11750
13129
  const opts = thisCommand.opts();
11751
- logger.debug("Running validation middleware");
11752
13130
  const validProviders = ["aws", "gcp", "azure", "alibaba", "oracle"];
11753
13131
  if (opts.provider && !validProviders.includes(opts.provider)) {
11754
13132
  throw new Error(`Invalid provider: ${opts.provider}. Must be one of: ${validProviders.join(", ")}`);
@@ -11761,34 +13139,27 @@ async function validationMiddleware(thisCommand, actionCommand) {
11761
13139
  if (opts.logLevel && !validLogLevels.includes(opts.logLevel)) {
11762
13140
  throw new Error(`Invalid log level: ${opts.logLevel}. Must be one of: ${validLogLevels.join(", ")}`);
11763
13141
  }
11764
- logger.debug("Validation check passed");
11765
13142
  }
11766
13143
  __name(validationMiddleware, "validationMiddleware");
11767
13144
 
11768
13145
  // src/cli/middleware/error-handler.ts
11769
- var import_chalk14 = __toESM(require("chalk"));
11770
- init_logging();
13146
+ var import_chalk19 = __toESM(require("chalk"));
11771
13147
  function errorHandler(error) {
11772
13148
  const message = error?.message ?? String(error);
11773
13149
  const stack = error?.stack;
11774
13150
  if (message === "(outputHelp)" || message === "(outputVersion)") {
11775
13151
  return;
11776
13152
  }
11777
- try {
11778
- const logger = getGlobalLogger29();
11779
- logger.error("Command failed", { error: message, stack });
11780
- } catch (loggerError) {
11781
- }
11782
13153
  console.error("");
11783
- console.error(import_chalk14.default.red("\u2716"), import_chalk14.default.bold("Error:"), message);
13154
+ console.error(import_chalk19.default.red("\u2716"), import_chalk19.default.bold("Error:"), message);
11784
13155
  if (process.env.DEBUG || process.env.VERBOSE) {
11785
13156
  console.error("");
11786
13157
  if (stack) {
11787
- console.error(import_chalk14.default.gray(stack));
13158
+ console.error(import_chalk19.default.gray(stack));
11788
13159
  }
11789
13160
  } else {
11790
13161
  console.error("");
11791
- console.error(import_chalk14.default.gray("Run with --verbose for detailed error information"));
13162
+ console.error(import_chalk19.default.gray("Run with --verbose for detailed error information"));
11792
13163
  }
11793
13164
  console.error("");
11794
13165
  }
@@ -11812,6 +13183,8 @@ function createCLI() {
11812
13183
  registerConfigCommands(program);
11813
13184
  registerDashboardCommands(program);
11814
13185
  registerGitCommands(program);
13186
+ registerTerraformCommand(program);
13187
+ registerSchedulerCommands(program);
11815
13188
  program.hook("preAction", async (thisCommand, actionCommand) => {
11816
13189
  const opts = thisCommand.opts();
11817
13190
  const logLevel = opts.verbose ? "debug" : opts.quiet ? "error" : opts.logLevel;