cdk-insights 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/entry.js CHANGED
@@ -78833,6 +78833,11 @@ var isServiceName = (value) => {
78833
78833
  return SPECIFIC_SERVICE_NAMES.includes(value);
78834
78834
  };
78835
78835
 
78836
+ // src/shared/auth.ts
78837
+ var crypto6 = __toESM(require("node:crypto"));
78838
+ var fs2 = __toESM(require("node:fs"));
78839
+ var path2 = __toESM(require("node:path"));
78840
+
78836
78841
  // node_modules/axios/lib/helpers/bind.js
78837
78842
  function bind(fn, thisArg) {
78838
78843
  return function wrap2() {
@@ -82444,11 +82449,6 @@ var {
82444
82449
  mergeConfig: mergeConfig2
82445
82450
  } = axios_default;
82446
82451
 
82447
- // src/shared/auth.ts
82448
- var crypto6 = __toESM(require("node:crypto"));
82449
- var fs2 = __toESM(require("node:fs"));
82450
- var path2 = __toESM(require("node:path"));
82451
-
82452
82452
  // src/shared/apiConfig.ts
82453
82453
  var normalize2 = (value) => {
82454
82454
  if (!value) return void 0;
@@ -94105,6 +94105,7 @@ var runAnalysis = async ({
94105
94105
  failOnCritical,
94106
94106
  tier,
94107
94107
  noCache = false,
94108
+ allowOveruse = false,
94108
94109
  cache: cache3,
94109
94110
  quotaValidation
94110
94111
  }) => {
@@ -94122,6 +94123,25 @@ var runAnalysis = async ({
94122
94123
  services: services || ["All services"],
94123
94124
  output: output || "table"
94124
94125
  });
94126
+ if (quotaValidation && !quotaValidation.quota.isTrial && quotaValidation.canRunAIAnalysis && allowOveruse) {
94127
+ const alreadyExceeded = quotaValidation.quota.currentResourcesAnalyzed >= quotaValidation.quota.maxResources;
94128
+ const wouldExceed = quotaValidation.quota.wouldExceed;
94129
+ if (alreadyExceeded) {
94130
+ terminal.warning(
94131
+ `\u26A0\uFE0F You have exceeded your paid allowance (${quotaValidation.quota.currentResourcesAnalyzed}/${quotaValidation.quota.maxResources} resources analyzed).`
94132
+ );
94133
+ terminal.warning(
94134
+ " Proceeding with AI analysis as --allow-overuse is enabled. Extra usage will be charged."
94135
+ );
94136
+ } else if (wouldExceed) {
94137
+ terminal.warning(
94138
+ `\u26A0\uFE0F This analysis will exceed your paid allowance (${quotaValidation.quota.currentResourcesAnalyzed}/${quotaValidation.quota.maxResources} resources analyzed).`
94139
+ );
94140
+ terminal.warning(
94141
+ " Proceeding with AI analysis as --allow-overuse is enabled. Extra usage will be charged."
94142
+ );
94143
+ }
94144
+ }
94125
94145
  const manifest = loadManifest("cdk.out");
94126
94146
  const constructRegistry = await withErrorHandling(
94127
94147
  () => loadConstructMetadata(listAvailableConstructs()),
@@ -94351,27 +94371,25 @@ var validateEnhancedLicenseQuota = async (request) => {
94351
94371
  hasUsageData: !!request.usageData
94352
94372
  });
94353
94373
  try {
94354
- if (request.usageData || request.licenseInfo && (request.licenseInfo.totalResourcesAnalyzed > 0 || request.licenseInfo.currentPeriodUsage > 0)) {
94374
+ if (request.licenseInfo || request.usageData) {
94355
94375
  let currentResources2 = 0;
94356
- if (request.usageData) {
94376
+ if (request.licenseInfo && request.licenseInfo.totalResourcesAnalyzed > 0) {
94377
+ currentResources2 = Number(request.licenseInfo.totalResourcesAnalyzed);
94378
+ cliLogger.info("\u{1F4CA} Using totalResourcesAnalyzed from license (source of truth)", context, {
94379
+ totalResourcesAnalyzed: currentResources2,
94380
+ licenseInfoSource: true
94381
+ });
94382
+ } else if (request.usageData && request.usageData.totalResourcesAnalyzed > 0) {
94357
94383
  currentResources2 = request.usageData.totalResourcesAnalyzed;
94358
- cliLogger.info("\u{1F4CA} Using usage data from login", context, {
94384
+ cliLogger.info("\u{1F4CA} Using usage data from login (fallback)", context, {
94359
94385
  totalResourcesAnalyzed: request.usageData.totalResourcesAnalyzed,
94360
94386
  totalTokens: request.usageData.totalTokens,
94361
94387
  usageCount: request.usageData.usageCount
94362
94388
  });
94363
- } else if (request.licenseInfo) {
94364
- const totalResourcesAnalyzed = Number(
94365
- request.licenseInfo.totalResourcesAnalyzed || 0
94366
- );
94367
- const currentPeriodUsage = Number(
94368
- request.licenseInfo.currentPeriodUsage || 0
94369
- );
94370
- currentResources2 = totalResourcesAnalyzed > 0 ? totalResourcesAnalyzed : currentPeriodUsage;
94371
- cliLogger.info("\u{1F4CA} Using usage data from license info", context, {
94372
- totalResourcesAnalyzed,
94373
- currentPeriodUsage,
94374
- currentResources: currentResources2
94389
+ } else if (request.licenseInfo && request.licenseInfo.currentPeriodUsage > 0) {
94390
+ currentResources2 = Number(request.licenseInfo.currentPeriodUsage);
94391
+ cliLogger.info("\u{1F4CA} Using currentPeriodUsage from license (last resort fallback)", context, {
94392
+ currentPeriodUsage: currentResources2
94375
94393
  });
94376
94394
  }
94377
94395
  let maxResources2 = 200;
@@ -94415,8 +94433,21 @@ var validateEnhancedLicenseQuota = async (request) => {
94415
94433
  canProceed = false;
94416
94434
  canRunStaticAnalysis = true;
94417
94435
  canRunAIAnalysis = false;
94418
- reason = `AI-powered analysis would exceed trial limit. You have analyzed ${currentResources2}/${maxResources2} resources and are requesting ${request.requestedResources} more.`;
94436
+ const overuseNote = request.allowOveruse ? " Note: --allow-overuse does not apply to trial licenses which have a hard usage limit." : "";
94437
+ reason = `AI-powered analysis would exceed trial limit. You have analyzed ${currentResources2}/${maxResources2} resources and are requesting ${request.requestedResources} more.${overuseNote}`;
94419
94438
  upgradePath = "https://cdkinsights.dev/pricing";
94439
+ } else if (wouldExceed2 && !isTrial2) {
94440
+ if (request.allowOveruse) {
94441
+ canProceed = true;
94442
+ canRunStaticAnalysis = true;
94443
+ canRunAIAnalysis = true;
94444
+ reason = `You have exceeded your paid allowance (${currentResources2}/${maxResources2} resources). Proceeding with AI analysis as --allow-overuse is enabled. Extra usage will be charged.`;
94445
+ } else {
94446
+ canProceed = true;
94447
+ canRunStaticAnalysis = true;
94448
+ canRunAIAnalysis = false;
94449
+ reason = `AI analysis would exceed your paid allowance (${currentResources2}/${maxResources2} resources). Extra usage will be charged. Use --allow-overuse to proceed with AI analysis.`;
94450
+ }
94420
94451
  } else if (isTrial2 && currentResources2 >= hardStopThreshold && request.requestedResources > 10) {
94421
94452
  canProceed = false;
94422
94453
  canRunStaticAnalysis = true;
@@ -94597,6 +94628,7 @@ var DEFAULT_CONFIG = {
94597
94628
  reset: false,
94598
94629
  github: false,
94599
94630
  noCache: false,
94631
+ allowOveruse: false,
94600
94632
  cache: {
94601
94633
  enabled: true,
94602
94634
  ttl: 5 * 60 * 1e3,
@@ -94707,6 +94739,10 @@ var mergeConfigWithArgs = (config2, cliArgs) => {
94707
94739
  reset: cliArgs.reset ?? DEFAULT_CONFIG.reset,
94708
94740
  github: cliArgs.github ?? DEFAULT_CONFIG.github,
94709
94741
  noCache: cliArgs.noCache ?? DEFAULT_CONFIG.noCache,
94742
+ allowOveruse: validateBoolean(
94743
+ cliArgs.allowOveruse ?? config2.allowOveruse,
94744
+ DEFAULT_CONFIG.allowOveruse
94745
+ ),
94710
94746
  cache: validateCacheConfig(
94711
94747
  cliArgs.cache ?? config2.cache ?? DEFAULT_CONFIG.cache
94712
94748
  )
@@ -94725,6 +94761,7 @@ var DEFAULT_CONFIG2 = {
94725
94761
  ruleFilter: [],
94726
94762
  failOnCritical: true,
94727
94763
  noCache: false,
94764
+ allowOveruse: false,
94728
94765
  cache: {
94729
94766
  enabled: true,
94730
94767
  ttl: 5 * 60 * 1e3,
@@ -94775,6 +94812,9 @@ var validateConfig = (config2) => {
94775
94812
  if (typeof raw.noCache === "boolean") {
94776
94813
  validated.noCache = raw.noCache;
94777
94814
  }
94815
+ if (typeof raw.allowOveruse === "boolean") {
94816
+ validated.allowOveruse = raw.allowOveruse;
94817
+ }
94778
94818
  if (raw.cache && typeof raw.cache === "object" && !Array.isArray(raw.cache)) {
94779
94819
  const cacheConfig = raw.cache;
94780
94820
  validated.cache = { ...DEFAULT_CONFIG2.cache };
@@ -95004,7 +95044,6 @@ async function runStackAnalysis(finalConfig, fingerprint, authToken, licenseInfo
95004
95044
  let canRunAIAnalysis = true;
95005
95045
  if (licenseKey) {
95006
95046
  terminal.info("\u{1F50D} Checking license quota...");
95007
- console.log("licenseInfo", licenseInfo);
95008
95047
  const isTrial = licenseInfo.licenseType === "TRIAL" || licenseInfo.status === "TRIAL";
95009
95048
  const currentResources = licenseInfo.totalResourcesAnalyzed || 0;
95010
95049
  const maxResources = licenseInfo.trialUsageLimit || licenseInfo.maxUsage || 200;
@@ -95036,11 +95075,10 @@ async function runStackAnalysis(finalConfig, fingerprint, authToken, licenseInfo
95036
95075
  " Upgrade to Pro for unlimited AI-powered recommendations"
95037
95076
  );
95038
95077
  } else {
95039
- const availableStacks = getAvailableStacks();
95040
- const estimatedResources = availableStacks.length > 0 ? 50 : 0;
95041
95078
  quotaValidation = await validateEnhancedLicenseQuota({
95042
95079
  licenseKey,
95043
- requestedResources: estimatedResources,
95080
+ requestedResources: totalResources,
95081
+ allowOveruse: finalConfig.allowOveruse,
95044
95082
  usageData,
95045
95083
  licenseInfo
95046
95084
  });
@@ -95146,6 +95184,7 @@ async function runStackAnalysis(finalConfig, fingerprint, authToken, licenseInfo
95146
95184
  quotaValidation: quotaValidation || null,
95147
95185
  // Pass quota validation info to control analysis phases
95148
95186
  noCache: finalConfig.noCache || false,
95187
+ allowOveruse: finalConfig.allowOveruse || false,
95149
95188
  onAuthRefresh
95150
95189
  };
95151
95190
  return await runAnalysis(analysisConfig);
@@ -95199,6 +95238,10 @@ var analyzeCommand = {
95199
95238
  describe: "Disable cache and force fresh analysis",
95200
95239
  type: "boolean",
95201
95240
  default: false
95241
+ }).option("allowOveruse", {
95242
+ describe: "Allow AI analysis even when exceeding paid allowance (extra usage will be charged)",
95243
+ type: "boolean",
95244
+ default: false
95202
95245
  }),
95203
95246
  handler: async (argv) => {
95204
95247
  try {
@@ -95560,6 +95603,13 @@ var CONFIG_FIELDS = {
95560
95603
  examples: ["true", "false"],
95561
95604
  validation: "Must be true or false"
95562
95605
  },
95606
+ allowOveruse: {
95607
+ type: "boolean",
95608
+ default: false,
95609
+ description: "Allow AI analysis to proceed even when it will exceed paid allowance (extra usage will be charged)",
95610
+ examples: ["true", "false"],
95611
+ validation: "Must be true or false"
95612
+ },
95563
95613
  cache: {
95564
95614
  type: "object",
95565
95615
  default: { enabled: true, ttl: 3e5, maxSize: 1e3 },
@@ -95881,6 +95931,7 @@ var createHelpTable = () => {
95881
95931
  ["--fail-on-critical", "Exit with code 1 if critical issues found"],
95882
95932
  ["--rule-filter", "Filter findings by rule IDs or categories"],
95883
95933
  ["--no-cache", "Disable cache and force fresh analysis"],
95934
+ ["--allow-overuse", "Allow AI analysis even when exceeding paid allowance (extra usage charged)"],
95884
95935
  ["", ""]
95885
95936
  );
95886
95937
  helpTable.push(
@@ -95922,6 +95973,7 @@ var configCommand = {
95922
95973
  "ruleFilter",
95923
95974
  "failOnCritical",
95924
95975
  "noCache",
95976
+ "allowOveruse",
95925
95977
  "cache"
95926
95978
  ],
95927
95979
  describe: "Configuration field to set"
@@ -95949,6 +96001,7 @@ var configCommand = {
95949
96001
  "ruleFilter",
95950
96002
  "failOnCritical",
95951
96003
  "noCache",
96004
+ "allowOveruse",
95952
96005
  "cache"
95953
96006
  ],
95954
96007
  describe: "Configuration field to remove"
@@ -17,6 +17,7 @@ export interface AnalyzeCommandArgs {
17
17
  summaryOnly?: boolean;
18
18
  synth?: boolean;
19
19
  noCache?: boolean;
20
+ allowOveruse?: boolean;
20
21
  cache?: {
21
22
  enabled?: boolean;
22
23
  ttl?: number;
@@ -35,6 +36,7 @@ export interface UserConfig {
35
36
  synth?: boolean;
36
37
  ruleFilter?: string[];
37
38
  noCache?: boolean;
39
+ allowOveruse?: boolean;
38
40
  cache?: {
39
41
  enabled?: boolean;
40
42
  ttl?: number;
package/dist/index.d.ts CHANGED
@@ -16,6 +16,7 @@ type QuotaValidation = {
16
16
  isTrial: boolean;
17
17
  currentResourcesAnalyzed: number;
18
18
  maxResources: number;
19
+ wouldExceed?: boolean;
19
20
  };
20
21
  };
21
22
  interface RunAnalysisTypes {
@@ -34,6 +35,7 @@ interface RunAnalysisTypes {
34
35
  failOnCritical?: boolean;
35
36
  tier?: Tier;
36
37
  noCache?: boolean;
38
+ allowOveruse?: boolean;
37
39
  cache?: CacheConfig;
38
40
  quotaValidation?: QuotaValidation;
39
41
  }
@@ -42,7 +44,7 @@ interface RunAnalysisTypes {
42
44
  * Main analysis entry
43
45
  * ---------------------------------------
44
46
  */
45
- export declare const runAnalysis: ({ stacks, inlineFindings, pathToLogicalId, output, recommendationMapPerStack, withIssue, services, ruleFilter, authToken, fingerprint, failOnCritical, tier, noCache, cache, quotaValidation, }: RunAnalysisTypes) => Promise<{
47
+ export declare const runAnalysis: ({ stacks, inlineFindings, pathToLogicalId, output, recommendationMapPerStack, withIssue, services, ruleFilter, authToken, fingerprint, failOnCritical, tier, noCache, allowOveruse, cache, quotaValidation, }: RunAnalysisTypes) => Promise<{
46
48
  recommendationMaps: Record<string, IssueGroup>;
47
49
  hasCriticalIssues: boolean;
48
50
  }>;
package/dist/index.js CHANGED
@@ -60463,6 +60463,7 @@ var runAnalysis = async ({
60463
60463
  failOnCritical,
60464
60464
  tier,
60465
60465
  noCache = false,
60466
+ allowOveruse = false,
60466
60467
  cache: cache3,
60467
60468
  quotaValidation
60468
60469
  }) => {
@@ -60480,6 +60481,25 @@ var runAnalysis = async ({
60480
60481
  services: services || ["All services"],
60481
60482
  output: output || "table"
60482
60483
  });
60484
+ if (quotaValidation && !quotaValidation.quota.isTrial && quotaValidation.canRunAIAnalysis && allowOveruse) {
60485
+ const alreadyExceeded = quotaValidation.quota.currentResourcesAnalyzed >= quotaValidation.quota.maxResources;
60486
+ const wouldExceed = quotaValidation.quota.wouldExceed;
60487
+ if (alreadyExceeded) {
60488
+ terminal2.warning(
60489
+ `\u26A0\uFE0F You have exceeded your paid allowance (${quotaValidation.quota.currentResourcesAnalyzed}/${quotaValidation.quota.maxResources} resources analyzed).`
60490
+ );
60491
+ terminal2.warning(
60492
+ " Proceeding with AI analysis as --allow-overuse is enabled. Extra usage will be charged."
60493
+ );
60494
+ } else if (wouldExceed) {
60495
+ terminal2.warning(
60496
+ `\u26A0\uFE0F This analysis will exceed your paid allowance (${quotaValidation.quota.currentResourcesAnalyzed}/${quotaValidation.quota.maxResources} resources analyzed).`
60497
+ );
60498
+ terminal2.warning(
60499
+ " Proceeding with AI analysis as --allow-overuse is enabled. Extra usage will be charged."
60500
+ );
60501
+ }
60502
+ }
60483
60503
  const manifest = loadManifest("cdk.out");
60484
60504
  const constructRegistry = await withErrorHandling(
60485
60505
  () => loadConstructMetadata(listAvailableConstructs()),
@@ -1,6 +1,7 @@
1
1
  export interface EnhancedQuotaValidationRequest {
2
2
  licenseKey: string;
3
3
  requestedResources: number;
4
+ allowOveruse?: boolean;
4
5
  usageData?: {
5
6
  totalTokens: number;
6
7
  totalResourcesAnalyzed: number;
@@ -16,4 +16,4 @@ export interface QuotaValidationResult {
16
16
  reason?: string;
17
17
  upgradePath?: string;
18
18
  }
19
- export declare const validateLicenseQuota: (licenseKey: string, requestedResources: number) => Promise<QuotaValidationResult>;
19
+ export declare const validateLicenseQuota: (licenseKey: string, requestedResources: number, allowOveruse?: boolean) => Promise<QuotaValidationResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cdk-insights",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "AWS CDK security and cost analysis tool with AI-powered insights",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",