@cubocicloide/stack-react-fastapi 13.2.0 → 13.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,8 +1,14 @@
1
1
  // src/index.ts
2
- import { existsSync as existsSync12, readFileSync as readFileSync9 } from "fs";
2
+ import { existsSync as existsSync13, readFileSync as readFileSync9 } from "fs";
3
3
  import path15 from "pathe";
4
4
  import yaml2 from "yaml";
5
- import { defineStack, renderTemplateTree, defineCheatsheetCommand, defineDocsCommand } from "@cubocicloide/dude";
5
+ import {
6
+ defineStack,
7
+ renderTemplateTree,
8
+ defineCheatsheetCommand,
9
+ defineDocsCommand,
10
+ defineExplainCommand
11
+ } from "@cubocicloide/dude";
6
12
 
7
13
  // src/commands/api/index.ts
8
14
  import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "fs";
@@ -876,12 +882,13 @@ var iacBootstrapCommand = {
876
882
 
877
883
  // src/commands/iac/providers/aws-eks/lib/images.ts
878
884
  import { spawnSync as spawnSync5 } from "child_process";
885
+ import { createHash as createHash2 } from "crypto";
879
886
  import { existsSync as existsSync5 } from "fs";
880
887
  import path7 from "pathe";
881
888
  var tagArg = {
882
889
  tag: {
883
890
  type: "string",
884
- description: "Image tag (default: git short SHA, with -dirty if uncommitted changes)."
891
+ description: "Image tag (default: git short SHA, plus -dirty-<hash> if there are uncommitted changes)."
885
892
  }
886
893
  };
887
894
  var platformArg = {
@@ -941,10 +948,38 @@ function resolveTag(projectRoot, args) {
941
948
  );
942
949
  return null;
943
950
  }
944
- let tag = sha.stdout.trim();
951
+ const tag = sha.stdout.trim();
952
+ const dirt = workingTreeDigest(projectRoot);
953
+ return dirt ? `${tag}-dirty-${dirt}` : tag;
954
+ }
955
+ function workingTreeDigest(projectRoot) {
945
956
  const status = capture2("git", ["status", "--porcelain"], projectRoot);
946
- if (status.status === 0 && status.stdout.trim() !== "") tag += "-dirty";
947
- return tag;
957
+ if (status.status !== 0 || status.stdout.trim() === "") return null;
958
+ const diff = capture2("git", ["diff", "HEAD"], projectRoot);
959
+ return createHash2("sha256").update(status.stdout).update(diff.status === 0 ? diff.stdout : "").digest("hex").slice(0, 8);
960
+ }
961
+ function repoName(repositoryUrl) {
962
+ return repositoryUrl.split("/").slice(1).join("/");
963
+ }
964
+ function ecrTagExists(projectRoot, profile, repositoryUrl, tag, region) {
965
+ const r = capture2(
966
+ "aws",
967
+ [
968
+ "ecr",
969
+ "describe-images",
970
+ "--repository-name",
971
+ repoName(repositoryUrl),
972
+ "--image-ids",
973
+ `imageTag=${tag}`,
974
+ "--region",
975
+ region,
976
+ "--output",
977
+ "json"
978
+ ],
979
+ projectRoot,
980
+ profile
981
+ );
982
+ return r.status === 0 && r.stdout.includes("imageDigest");
948
983
  }
949
984
  function dockerLogin(host, region, projectRoot, profile) {
950
985
  const pw = capture2("aws", ["ecr", "get-login-password", "--region", region], projectRoot, profile);
@@ -1003,7 +1038,28 @@ function doBuild(projectRoot, profile, tag, repos, project, platform) {
1003
1038
  );
1004
1039
  return code;
1005
1040
  }
1006
- function doPush(projectRoot, profile, tag, repos) {
1041
+ function tagAlreadyPushed(projectRoot, profile, tag, repos, env) {
1042
+ for (const repo of [repos.backend, repos.frontend]) {
1043
+ if (!ecrTagExists(projectRoot, profile, repo, tag, repos.region)) continue;
1044
+ process.stderr.write(
1045
+ `
1046
+ \u2717 ${repo}:${tag} already exists, and the repository is immutable.
1047
+
1048
+ The default tag is derived from your git state, so the same commit with
1049
+ the same uncommitted changes always resolves to the same tag. Either:
1050
+
1051
+ \u2022 commit your work and re-run \u2014 a new SHA gives a new tag;
1052
+ \u2022 push under a different tag: dude iac push --env ${env} --tag ${tag}.1
1053
+ \u2022 or deploy what is already there: dude iac deploy --env ${env} --tag ${tag}
1054
+
1055
+ `
1056
+ );
1057
+ return true;
1058
+ }
1059
+ return false;
1060
+ }
1061
+ function doPush(projectRoot, profile, tag, repos, env) {
1062
+ if (tagAlreadyPushed(projectRoot, profile, tag, repos, env)) return 1;
1007
1063
  let code = dockerLogin(repos.registryHost, repos.region, projectRoot, profile);
1008
1064
  if (code !== 0) return code;
1009
1065
  process.stdout.write(`
@@ -1801,7 +1857,7 @@ var iacPushCommand = {
1801
1857
  const tag = resolveTag(projectRoot, args);
1802
1858
  if (!tag) process.exit(1);
1803
1859
  const repos = requireEcrRepos(projectRoot, profile);
1804
- process.exit(doPush(projectRoot, profile, tag, repos));
1860
+ process.exit(doPush(projectRoot, profile, tag, repos, env));
1805
1861
  }
1806
1862
  };
1807
1863
 
@@ -1869,9 +1925,10 @@ var iacShipCommand = {
1869
1925
  const ns = String(args.namespace ?? env);
1870
1926
  const platform = String(args.platform ?? "linux/amd64");
1871
1927
  const project = projectName(projectRoot);
1928
+ if (tagAlreadyPushed(projectRoot, profile, tag, repos, env)) process.exit(1);
1872
1929
  let code = doBuild(projectRoot, profile, tag, repos, project, platform);
1873
1930
  if (code !== 0) process.exit(code);
1874
- code = doPush(projectRoot, profile, tag, repos);
1931
+ code = doPush(projectRoot, profile, tag, repos, env);
1875
1932
  if (code !== 0) process.exit(code);
1876
1933
  code = doDeploy(projectRoot, profile, env, ns, tag, repos);
1877
1934
  if (code === 0) {
@@ -2247,11 +2304,11 @@ var reviewCommand2 = {
2247
2304
 
2248
2305
  // src/commands/security/index.ts
2249
2306
  import { spawnSync as spawnSync10 } from "child_process";
2250
- import { cpSync as cpSync2, existsSync as existsSync10, mkdirSync as mkdirSync3, readFileSync as readFileSync8, rmSync, writeFileSync as writeFileSync5 } from "fs";
2307
+ import { cpSync as cpSync2, existsSync as existsSync11, mkdirSync as mkdirSync3, readFileSync as readFileSync8, rmSync, writeFileSync as writeFileSync5 } from "fs";
2251
2308
  import path13 from "pathe";
2252
2309
 
2253
2310
  // src/commands/security/models.ts
2254
- import { createHash as createHash2 } from "crypto";
2311
+ import { createHash as createHash3 } from "crypto";
2255
2312
  var SEV_LABEL = {
2256
2313
  [0 /* UNKNOWN */]: "UNKNOWN",
2257
2314
  [1 /* INFO */]: "INFO",
@@ -2262,7 +2319,7 @@ var SEV_LABEL = {
2262
2319
  };
2263
2320
  function fingerprint(f) {
2264
2321
  const raw = [f.tool, f.ruleId, f.file, f.title.trim().toLowerCase()].join("|");
2265
- return createHash2("sha256").update(raw, "utf8").digest("hex").slice(0, 16);
2322
+ return createHash3("sha256").update(raw, "utf8").digest("hex").slice(0, 16);
2266
2323
  }
2267
2324
  function findingToRecord(f) {
2268
2325
  return {
@@ -2355,6 +2412,7 @@ var Baseline = class _Baseline {
2355
2412
  };
2356
2413
 
2357
2414
  // src/commands/security/adapters.ts
2415
+ import { existsSync as existsSync10 } from "fs";
2358
2416
  import path12 from "pathe";
2359
2417
  function reportInContainer(projectRoot, runDir, name) {
2360
2418
  return `/src/${path12.relative(projectRoot, path12.join(runDir, `${name}.json`))}`;
@@ -2529,10 +2587,13 @@ function trivyComponent(filePath) {
2529
2587
  if (filePath.endsWith("Dockerfile") || filePath.includes("docker-compose")) return "docker";
2530
2588
  return "deps";
2531
2589
  }
2590
+ var TRIVY_SKIP_DIRS = "node_modules,private,staticfiles,e2e/reports,.venv,.terraform";
2591
+ var TRIVY_IGNORE_FILE = "security/.trivyignore.yaml";
2532
2592
  var trivyFsAdapter = {
2533
2593
  name: "trivy-fs",
2534
2594
  buildCommand(projectRoot, runDir, opts) {
2535
2595
  const report = reportInContainer(projectRoot, runDir, "trivy-fs");
2596
+ const ignoreFile = existsSync10(path12.join(projectRoot, TRIVY_IGNORE_FILE)) ? ["--ignorefile", TRIVY_IGNORE_FILE] : [];
2536
2597
  return [
2537
2598
  "docker",
2538
2599
  "run",
@@ -2552,7 +2613,14 @@ var trivyFsAdapter = {
2552
2613
  "--output",
2553
2614
  report,
2554
2615
  "--skip-dirs",
2555
- "node_modules,private,staticfiles,e2e/reports,.venv",
2616
+ TRIVY_SKIP_DIRS,
2617
+ // Terraform misconfigurations are reported against the module's *source*
2618
+ // (`git::https:/github.com/terraform-aws-modules/…`), not the local path
2619
+ // it was vendored to — so --skip-dirs cannot suppress them. Without this
2620
+ // flag the report is dominated by findings inside the upstream VPC/EKS
2621
+ // modules (AVD-AWS-0104, AVD-AWS-0130), which nobody here can act on.
2622
+ "--tf-exclude-downloaded-modules",
2623
+ ...ignoreFile,
2556
2624
  "."
2557
2625
  ];
2558
2626
  },
@@ -2846,7 +2914,7 @@ function runScan(config) {
2846
2914
  stdio: ["ignore", "pipe", "pipe"]
2847
2915
  });
2848
2916
  const reportPath = path13.join(runDir, `${name}.json`);
2849
- if (!existsSync10(reportPath)) {
2917
+ if (!existsSync11(reportPath)) {
2850
2918
  const stdout = result.stdout?.toString() ?? "";
2851
2919
  const stderr = result.stderr?.toString() ?? "";
2852
2920
  process.stderr.write(
@@ -2876,7 +2944,7 @@ function runScan(config) {
2876
2944
  path13.join(runDir, "summary.md"),
2877
2945
  config.minSeverity
2878
2946
  );
2879
- if (existsSync10(latestDir)) rmSync(latestDir, { recursive: true, force: true });
2947
+ if (existsSync11(latestDir)) rmSync(latestDir, { recursive: true, force: true });
2880
2948
  cpSync2(runDir, latestDir, { recursive: true });
2881
2949
  if (config.updateBaseline) {
2882
2950
  baseline.updateFrom(findings);
@@ -2937,7 +3005,7 @@ var securityScanCommand = {
2937
3005
  `
2938
3006
  );
2939
3007
  const summaryPath = path13.join(result.latestDir, "summary.md");
2940
- if (existsSync10(summaryPath)) {
3008
+ if (existsSync11(summaryPath)) {
2941
3009
  process.stdout.write(readFileSync8(summaryPath, "utf8"));
2942
3010
  }
2943
3011
  if (result.exitCode !== 0) process.exit(result.exitCode);
@@ -3092,7 +3160,7 @@ var shellCommand = {
3092
3160
 
3093
3161
  // src/commands/test/index.ts
3094
3162
  import { spawnSync as spawnSync12 } from "child_process";
3095
- import { existsSync as existsSync11 } from "fs";
3163
+ import { existsSync as existsSync12 } from "fs";
3096
3164
  import path14 from "pathe";
3097
3165
  function shouldUseShell4() {
3098
3166
  return process.platform === "win32";
@@ -3159,8 +3227,8 @@ var testCommand = {
3159
3227
  const runAll = !flagBackend && !flagE2e;
3160
3228
  const runBackend = flagBackend || runAll;
3161
3229
  const runE2e = flagE2e || runAll;
3162
- const hasBackend = existsSync11(backendDir);
3163
- const hasE2e = existsSync11(e2eDir);
3230
+ const hasBackend = existsSync12(backendDir);
3231
+ const hasE2e = existsSync12(e2eDir);
3164
3232
  const missing = [];
3165
3233
  if (runBackend && hasBackend && !isAvailable3("uv"))
3166
3234
  missing.push("uv \u2192 https://docs.astral.sh/uv/getting-started/installation/");
@@ -3190,7 +3258,7 @@ var testCommand = {
3190
3258
  const script = report ? "test:report" : "test";
3191
3259
  section3(`cucumber${headed ? " (headed)" : ""}${report ? " + report" : ""}`);
3192
3260
  const nmDir = path14.join(e2eDir, "node_modules");
3193
- if (!existsSync11(nmDir)) {
3261
+ if (!existsSync12(nmDir)) {
3194
3262
  process.stdout.write("node_modules not found \u2014 running pnpm install\u2026\n");
3195
3263
  const installed = exec3("pnpm", ["install"], e2eDir);
3196
3264
  if (!installed) {
@@ -3327,7 +3395,7 @@ var src_default = defineStack({
3327
3395
  await renderTemplateTree({ src: path15.join(templates, "aws-eks"), dest, data });
3328
3396
  }
3329
3397
  const openapiYamlPath = path15.join(dest, "frontend", "src", "openapi", "utils", "openapi.yaml");
3330
- if (existsSync12(openapiYamlPath)) {
3398
+ if (existsSync13(openapiYamlPath)) {
3331
3399
  const spec = yaml2.parse(readFileSync9(openapiYamlPath, "utf8"));
3332
3400
  await generateClientFromSpec(spec, path15.join(dest, "frontend", "src", "openapi"), dest);
3333
3401
  }
@@ -3382,6 +3450,7 @@ var src_default = defineStack({
3382
3450
  rules: [],
3383
3451
  commands: {
3384
3452
  cheatsheet: defineCheatsheetCommand(),
3453
+ explain: defineExplainCommand(),
3385
3454
  up: upCommand,
3386
3455
  down: downCommand,
3387
3456
  logs: logsCommand,