@donotdev/cli 0.3.6 → 0.3.8

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.
@@ -8782,6 +8782,103 @@ var init_create_utils = __esm({
8782
8782
  }
8783
8783
  });
8784
8784
 
8785
+ // packages/tooling/src/apps/vercel-api.ts
8786
+ function formatVercelError(status, body, context) {
8787
+ let vercelCode;
8788
+ let vercelMessage;
8789
+ try {
8790
+ const parsed = JSON.parse(body);
8791
+ const err = parsed.error ?? parsed;
8792
+ vercelCode = err.code;
8793
+ vercelMessage = err.message;
8794
+ } catch {
8795
+ }
8796
+ let message;
8797
+ switch (status) {
8798
+ case 401:
8799
+ message = "Vercel token is invalid or expired. Generate a new one at https://vercel.com/account/tokens and update .dndev.secrets";
8800
+ break;
8801
+ case 403:
8802
+ if (vercelCode === "team_unauthorized" || body.includes("teamId")) {
8803
+ message = "Vercel token does not have access to this team. Hobby/free accounts: remove VERCEL_ORG_ID from your .env (it causes 403). Team accounts: ensure the token is scoped to the correct team.";
8804
+ } else {
8805
+ message = `Vercel access denied: ${vercelMessage ?? "check token scope and permissions"}`;
8806
+ }
8807
+ break;
8808
+ case 404:
8809
+ message = "Vercel project not found. Check VERCEL_PROJECT_ID in apps/<app>/.env \u2014 it should match the Project ID from Vercel Dashboard > Project > Settings > General.";
8810
+ break;
8811
+ case 400:
8812
+ if (vercelCode === "invalid_project_name") {
8813
+ message = "Vercel rejected the project name. This is a framework bug \u2014 please report it.";
8814
+ } else {
8815
+ message = `Vercel rejected the request: ${vercelMessage ?? body}`;
8816
+ }
8817
+ break;
8818
+ case 429:
8819
+ message = "Vercel rate limit hit. Wait a few minutes and try again.";
8820
+ break;
8821
+ default:
8822
+ message = `Vercel API error during ${context} (${status}): ${vercelMessage ?? body}`;
8823
+ }
8824
+ return new DoNotDevError(message, DO_NOT_DEV_ERROR_CODES.VERCEL_API_ERROR, {
8825
+ context: { status, vercelCode, context }
8826
+ });
8827
+ }
8828
+ async function validateToken(token) {
8829
+ const res = await fetch(`${VERCEL_API}/v2/user`, {
8830
+ headers: { Authorization: `Bearer ${token}` }
8831
+ });
8832
+ if (!res.ok) {
8833
+ const body = await res.text();
8834
+ throw formatVercelError(res.status, body, "validate token");
8835
+ }
8836
+ const data = await res.json();
8837
+ return { username: data.user.username, email: data.user.email };
8838
+ }
8839
+ function teamQuery(orgId) {
8840
+ return orgId ? `?teamId=${encodeURIComponent(orgId)}` : "";
8841
+ }
8842
+ async function findProject(token, projectId, orgId) {
8843
+ const res = await fetch(
8844
+ `${VERCEL_API}/v9/projects/${encodeURIComponent(projectId)}${teamQuery(orgId)}`,
8845
+ {
8846
+ headers: { Authorization: `Bearer ${token}` }
8847
+ }
8848
+ );
8849
+ if (res.status === 404) return null;
8850
+ if (!res.ok) {
8851
+ const body = await res.text();
8852
+ throw formatVercelError(res.status, body, "validate project");
8853
+ }
8854
+ const data = await res.json();
8855
+ return {
8856
+ projectName: data.name,
8857
+ link: data.link ?? null,
8858
+ framework: data.framework ?? null,
8859
+ rootDirectory: data.rootDirectory ?? null,
8860
+ outputDirectory: data.outputDirectory ?? null
8861
+ };
8862
+ }
8863
+ async function fetchProjectDetails(token, projectId, orgId) {
8864
+ const details = await findProject(token, projectId, orgId);
8865
+ if (!details) throw formatVercelError(404, "", "validate project");
8866
+ return details;
8867
+ }
8868
+ async function validateProject(token, projectId, orgId) {
8869
+ const details = await fetchProjectDetails(token, projectId, orgId);
8870
+ return { projectName: details.projectName };
8871
+ }
8872
+ var VERCEL_API;
8873
+ var init_vercel_api = __esm({
8874
+ "packages/tooling/src/apps/vercel-api.ts"() {
8875
+ "use strict";
8876
+ init_utils2();
8877
+ init_errors();
8878
+ VERCEL_API = "https://api.vercel.com";
8879
+ }
8880
+ });
8881
+
8785
8882
  // packages/tooling/src/utils/secrets-resolver.ts
8786
8883
  function parseEnvFile(filePath) {
8787
8884
  if (!pathExists(filePath)) return {};
@@ -8897,92 +8994,6 @@ var init_secrets_resolver = __esm({
8897
8994
  }
8898
8995
  });
8899
8996
 
8900
- // packages/tooling/src/apps/vercel-api.ts
8901
- function formatVercelError(status, body, context) {
8902
- let vercelCode;
8903
- let vercelMessage;
8904
- try {
8905
- const parsed = JSON.parse(body);
8906
- const err = parsed.error ?? parsed;
8907
- vercelCode = err.code;
8908
- vercelMessage = err.message;
8909
- } catch {
8910
- }
8911
- let message;
8912
- switch (status) {
8913
- case 401:
8914
- message = "Vercel token is invalid or expired. Generate a new one at https://vercel.com/account/tokens and update .dndev.secrets";
8915
- break;
8916
- case 403:
8917
- if (vercelCode === "team_unauthorized" || body.includes("teamId")) {
8918
- message = "Vercel token does not have access to this team. Hobby/free accounts: remove VERCEL_ORG_ID from your .env (it causes 403). Team accounts: ensure the token is scoped to the correct team.";
8919
- } else {
8920
- message = `Vercel access denied: ${vercelMessage ?? "check token scope and permissions"}`;
8921
- }
8922
- break;
8923
- case 404:
8924
- message = "Vercel project not found. Check VERCEL_PROJECT_ID in apps/<app>/.env \u2014 it should match the Project ID from Vercel Dashboard > Project > Settings > General.";
8925
- break;
8926
- case 400:
8927
- if (vercelCode === "invalid_project_name") {
8928
- message = "Vercel rejected the project name. This is a framework bug \u2014 please report it.";
8929
- } else {
8930
- message = `Vercel rejected the request: ${vercelMessage ?? body}`;
8931
- }
8932
- break;
8933
- case 429:
8934
- message = "Vercel rate limit hit. Wait a few minutes and try again.";
8935
- break;
8936
- default:
8937
- message = `Vercel API error during ${context} (${status}): ${vercelMessage ?? body}`;
8938
- }
8939
- return new DoNotDevError(message, DO_NOT_DEV_ERROR_CODES.VERCEL_API_ERROR, {
8940
- context: { status, vercelCode, context }
8941
- });
8942
- }
8943
- async function validateToken(token) {
8944
- const res = await fetch(`${VERCEL_API}/v2/user`, {
8945
- headers: { Authorization: `Bearer ${token}` }
8946
- });
8947
- if (!res.ok) {
8948
- const body = await res.text();
8949
- throw formatVercelError(res.status, body, "validate token");
8950
- }
8951
- const data = await res.json();
8952
- return { username: data.user.username, email: data.user.email };
8953
- }
8954
- async function fetchProjectDetails(token, projectId, orgId) {
8955
- const q = orgId ? `?teamId=${encodeURIComponent(orgId)}` : "";
8956
- const res = await fetch(
8957
- `${VERCEL_API}/v9/projects/${encodeURIComponent(projectId)}${q}`,
8958
- {
8959
- headers: { Authorization: `Bearer ${token}` }
8960
- }
8961
- );
8962
- if (!res.ok) {
8963
- const body = await res.text();
8964
- throw formatVercelError(res.status, body, "validate project");
8965
- }
8966
- const data = await res.json();
8967
- return {
8968
- projectName: data.name,
8969
- link: data.link ?? null
8970
- };
8971
- }
8972
- async function validateProject(token, projectId, orgId) {
8973
- const details = await fetchProjectDetails(token, projectId, orgId);
8974
- return { projectName: details.projectName };
8975
- }
8976
- var VERCEL_API;
8977
- var init_vercel_api = __esm({
8978
- "packages/tooling/src/apps/vercel-api.ts"() {
8979
- "use strict";
8980
- init_utils2();
8981
- init_errors();
8982
- VERCEL_API = "https://api.vercel.com";
8983
- }
8984
- });
8985
-
8986
8997
  // packages/tooling/src/cli/setup/vercel-token.ts
8987
8998
  function resolvePerAppVar(appDir, varName) {
8988
8999
  const fromLocal = readEnvVar(joinPath(appDir, ".env.local"), varName);
@@ -8999,12 +9010,12 @@ function describeTokenSource(resolved, projectRoot, appDir) {
8999
9010
  }
9000
9011
  return joinPath(appDir, resolved.legacyPath);
9001
9012
  }
9002
- function resolveVercelCredentials(appDir, projectRoot) {
9013
+ function resolveVercelCredentials(appDir, projectRoot, project) {
9003
9014
  const root = projectRoot ?? getRepoRoot();
9004
9015
  const resolvedToken = resolveSecret("VERCEL_TOKEN", root, { appDir });
9005
9016
  const token = resolvedToken?.value ?? null;
9006
- const orgId = resolvePerAppVar(appDir, "VERCEL_ORG_ID");
9007
- const projectId = resolvePerAppVar(appDir, "VERCEL_PROJECT_ID");
9017
+ const orgId = project ? project.orgId ?? null : resolvePerAppVar(appDir, "VERCEL_ORG_ID");
9018
+ const projectId = project ? project.projectId : resolvePerAppVar(appDir, "VERCEL_PROJECT_ID");
9008
9019
  const missing = [];
9009
9020
  if (!token) missing.push("VERCEL_TOKEN");
9010
9021
  if (!projectId) missing.push("VERCEL_PROJECT_ID");
@@ -9339,8 +9350,8 @@ async function selectVercelAppDir(projectRoot, appName) {
9339
9350
  }
9340
9351
  return selected.path;
9341
9352
  }
9342
- async function resolveVercelCredentialsForSync(appDir, projectIdOverride, dryRun) {
9343
- const credResult = resolveVercelCredentials(appDir);
9353
+ async function resolveVercelCredentialsForSync(appDir, projectIdOverride, dryRun, uatProject) {
9354
+ const credResult = resolveVercelCredentials(appDir, void 0, uatProject);
9344
9355
  if (credResult.missing) {
9345
9356
  const hints = [];
9346
9357
  if (credResult.missing.includes("VERCEL_TOKEN")) {
@@ -9374,8 +9385,8 @@ async function resolveVercelCredentialsForSync(appDir, projectIdOverride, dryRun
9374
9385
  }
9375
9386
  return credentials;
9376
9387
  }
9377
- function readPublicAppEnv(appDir) {
9378
- const env = parseEnvFile2(joinPath(appDir, ".env"));
9388
+ function readPublicAppEnv(appDir, file = ".env") {
9389
+ const env = parseEnvFile2(joinPath(appDir, file));
9379
9390
  return Object.fromEntries(
9380
9391
  Object.entries(env).filter(
9381
9392
  ([key]) => PUBLIC_ENV_PREFIXES.some((prefix) => key.startsWith(prefix))
@@ -9384,16 +9395,18 @@ function readPublicAppEnv(appDir) {
9384
9395
  }
9385
9396
  async function syncVercelPublicEnv(appDir, options = {}) {
9386
9397
  const dryRun = options.dryRun ?? false;
9387
- const publicEnv = readPublicAppEnv(appDir);
9398
+ const envFile = options.envFile ?? ".env";
9399
+ const publicEnv = readPublicAppEnv(appDir, envFile);
9388
9400
  const keys = Object.keys(publicEnv);
9389
9401
  if (keys.length === 0) {
9390
- log2.info(`No public variables (${PUBLIC_ENV_PREFIXES.join(", ")}) in ${joinPath(appDir, ".env")}`);
9402
+ log2.info(`No public variables (${PUBLIC_ENV_PREFIXES.join(", ")}) in ${joinPath(appDir, envFile)}`);
9391
9403
  return;
9392
9404
  }
9393
9405
  const credentials = await resolveVercelCredentialsForSync(
9394
9406
  appDir,
9395
9407
  options.vercelProjectId,
9396
- dryRun
9408
+ dryRun,
9409
+ options.uatProject
9397
9410
  );
9398
9411
  log2.info(`Syncing ${keys.length} public variables to Vercel:`);
9399
9412
  for (const [key, value] of Object.entries(publicEnv)) {
@@ -9518,9 +9531,9 @@ ${errorOutput}`
9518
9531
  );
9519
9532
  }
9520
9533
  }
9521
- function uploadServiceAccountToGitHub(appDir, repo, dryRun = false, staging = false) {
9522
- const fileName = staging ? "service-account-key.staging.json" : "service-account-key.json";
9523
- const secretName = staging ? "FIREBASE_SERVICE_ACCOUNT_STAGING" : "FIREBASE_SERVICE_ACCOUNT";
9534
+ function uploadServiceAccountToGitHub(appDir, repo, dryRun = false) {
9535
+ const fileName = "service-account-key.json";
9536
+ const secretName = "FIREBASE_SERVICE_ACCOUNT";
9524
9537
  const filePath = joinPath(appDir, fileName);
9525
9538
  if (!pathExists(filePath)) {
9526
9539
  log2.debug(`No ${fileName} found in ${appDir}, skipping GitHub upload`);
@@ -9633,23 +9646,11 @@ Examples:
9633
9646
  setGitHubSecret(key, value, repo, config.dryRun);
9634
9647
  }
9635
9648
  }
9636
- if (firebaseProjectDir) {
9637
- uploadServiceAccountToGitHub(
9638
- firebaseProjectDir,
9639
- repo,
9640
- config.dryRun,
9641
- false
9642
- );
9643
- uploadServiceAccountToGitHub(
9644
- firebaseProjectDir,
9645
- repo,
9646
- config.dryRun,
9647
- true
9648
- );
9649
- } else {
9650
- uploadServiceAccountToGitHub(currentDir, repo, config.dryRun, false);
9651
- uploadServiceAccountToGitHub(currentDir, repo, config.dryRun, true);
9652
- }
9649
+ uploadServiceAccountToGitHub(
9650
+ firebaseProjectDir ?? currentDir,
9651
+ repo,
9652
+ config.dryRun
9653
+ );
9653
9654
  if (config.dryRun) {
9654
9655
  log2.success("\nDry run completed. No GitHub secrets were set.");
9655
9656
  } else {
@@ -8371,7 +8371,11 @@ var init_command_registry = __esm({
8371
8371
  appCommand: true,
8372
8372
  actionPattern: "app",
8373
8373
  options: [
8374
- { flags: "-c, --concurrency <n>", description: "set concurrency" }
8374
+ { flags: "-c, --concurrency <n>", description: "set concurrency" },
8375
+ {
8376
+ flags: "--uat",
8377
+ description: "Run locally against the UAT backend (apps/<app>/.env.uat; refuses production values)"
8378
+ }
8375
8379
  ],
8376
8380
  loader: "../apps/dev.ts",
8377
8381
  exportName: "dev"
@@ -8673,7 +8677,7 @@ var init_command_registry = __esm({
8673
8677
  options: [
8674
8678
  {
8675
8679
  flags: "-y, --yes",
8676
- description: "Accept every default answer: packages and docs, no major updates, then bun install"
8680
+ description: "Accept every default answer: packages, docs, AI harness and the demo/dndev apps already present, no major updates, then bun install"
8677
8681
  }
8678
8682
  ],
8679
8683
  loader: "../maintenance/bump.ts",
@@ -8691,7 +8695,7 @@ var init_command_registry = __esm({
8691
8695
  // ---------------------------------------------------------------------------
8692
8696
  {
8693
8697
  name: "deploy [app]",
8694
- description: "Deploy app",
8698
+ description: "Deploy app to production (UAT: uat <app>)",
8695
8699
  category: "deployment",
8696
8700
  public: true,
8697
8701
  appCommand: true,
@@ -8709,10 +8713,6 @@ var init_command_registry = __esm({
8709
8713
  flags: "--force",
8710
8714
  description: "Delete deployed Firebase functions missing from the local source (default: off; the deploy aborts and names them)"
8711
8715
  },
8712
- {
8713
- flags: "--staging",
8714
- description: "Deploy to staging (uses .env.staging and staging credentials)"
8715
- },
8716
8716
  {
8717
8717
  flags: "--scope <scope>",
8718
8718
  description: "What to deploy: frontend, functions, rules, both or all. Implies --yes"
@@ -8730,43 +8730,31 @@ var init_command_registry = __esm({
8730
8730
  exportName: "deploy"
8731
8731
  },
8732
8732
  {
8733
- name: "staging [app]",
8734
- description: "Deploy to staging/UAT (shorthand for deploy --staging)",
8735
- alias: "uat",
8733
+ name: "uat [app]",
8734
+ description: "Ship the code on this machine to UAT (Supabase + Vercel apps): apps/<app>/.env.uat, .dndev.uat.secrets; never production values; history-aware migrations, noindex",
8736
8735
  category: "deployment",
8737
8736
  public: true,
8738
8737
  appCommand: true,
8739
8738
  options: [
8740
- {
8741
- flags: "-p, --project <project>",
8742
- description: "Project ID (overrides default)"
8743
- },
8744
8739
  {
8745
8740
  flags: "--skip-build",
8746
8741
  description: "Reuse existing builds (dist/, out/, .vercel/output, functions, edge .build/). Default: build"
8747
8742
  },
8748
- {
8749
- flags: "--from-git",
8750
- description: "Next.js on Vercel: let Vercel build from linked Git (default: local vercel build + upload)"
8751
- },
8752
- {
8753
- flags: "--force",
8754
- description: "Delete deployed Firebase functions missing from the local source (default: off; the deploy aborts and names them)"
8755
- },
8756
8743
  {
8757
8744
  flags: "--scope <scope>",
8758
- description: "What to deploy: frontend, functions, rules, both or all. Implies --yes"
8745
+ description: "What to deploy: frontend, functions, both or all. Implies --yes"
8759
8746
  },
8760
8747
  {
8761
8748
  flags: "-y, --yes",
8762
8749
  description: "Non-interactive: never prompt; a missing required value fails, naming its flag (also when stdin is not a TTY)"
8763
8750
  },
8764
8751
  {
8765
- flags: "--no-sync-secrets",
8766
- description: "Skip pushing the secrets functions.yaml binds to Firebase Secret Manager (default: push changed values)"
8752
+ flags: "--refresh-data",
8753
+ description: "Copy production data into UAT (anonymized; storage incremental), then deploy; overwrites UAT data; asks for confirmation unless --yes"
8767
8754
  }
8768
8755
  ],
8769
- loader: "../apps/deploy.ts"
8756
+ loader: "../apps/uat.ts",
8757
+ exportName: "uat"
8770
8758
  },
8771
8759
  {
8772
8760
  name: "sync-secrets",
@@ -8836,10 +8824,15 @@ var init_command_registry = __esm({
8836
8824
  },
8837
8825
  {
8838
8826
  name: "setup [provider]",
8839
- description: "Set up infrastructure providers (firebase, supabase, vercel)",
8827
+ description: "Set up infrastructure providers (firebase, supabase, vercel) or the UAT environment (uat)",
8840
8828
  category: "deployment",
8841
8829
  public: true,
8842
- options: [],
8830
+ options: [
8831
+ {
8832
+ flags: "-y, --yes",
8833
+ description: "dn setup uat: create missing UAT resources without prompting"
8834
+ }
8835
+ ],
8843
8836
  loader: "../cli/setup/setup.ts",
8844
8837
  exportName: "setup"
8845
8838
  },
@@ -8853,10 +8846,6 @@ var init_command_registry = __esm({
8853
8846
  {
8854
8847
  flags: "--app <app>",
8855
8848
  description: "App name (auto-detected if single app)"
8856
- },
8857
- {
8858
- flags: "--staging",
8859
- description: "Include staging workflow generation"
8860
8849
  }
8861
8850
  ],
8862
8851
  loader: "../scaffolding/setup-cicd.ts",
@@ -9028,11 +9017,19 @@ var init_command_registry = __esm({
9028
9017
  },
9029
9018
  {
9030
9019
  flags: "--output-dir <dir>",
9031
- description: "output directory for migrations (default: supabase/migrations)"
9020
+ description: "output directory for migrations (default: supabase/migrations of the app the command runs for: the nearest folder up with supabase/config.toml, or the only app with one under apps/; fails when none)"
9032
9021
  },
9033
9022
  {
9034
9023
  flags: "--no-single-file",
9035
9024
  description: "emit one migration file per entity"
9025
+ },
9026
+ {
9027
+ flags: "--only <collections...>",
9028
+ description: "emit only these collections into ONE new migration <version>_<first>[_and_more].sql (version: now, or the latest existing + 1 so it sorts last); never touches *_entity_tables.sql (for a live app adding a feature's entities; feature-owned collections accepted)"
9029
+ },
9030
+ {
9031
+ flags: "--app-dir <dir>",
9032
+ description: "app folder whose src/config/app.ts turns framework features on (their entities are included when installed; default: the app of the output dir)"
9036
9033
  }
9037
9034
  ],
9038
9035
  loader: "../generators/sql-generator.ts"