@firstdraft.com/cli 0.7.0 → 0.8.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/src/cli.js CHANGED
@@ -8,7 +8,9 @@ import {
8
8
  } from "./application-identity.js";
9
9
  import {
10
10
  ApiAuthenticationRequiredError,
11
+ STAGING_API_URL,
11
12
  authenticateApiCommand,
13
+ environmentTokenFor,
12
14
  isAuthenticationProblem,
13
15
  } from "./api-authentication.js";
14
16
  import {
@@ -42,6 +44,14 @@ import {
42
44
  compilePlanToGitHub,
43
45
  compilePlanToDirectory,
44
46
  } from "./commands/plan-compile.js";
47
+ import {
48
+ LoginDeniedError,
49
+ LoginExpiredError,
50
+ LoginFailedError,
51
+ login,
52
+ resolveLoginOrigin,
53
+ } from "./commands/login.js";
54
+ import { LogoutFailedError, logout } from "./commands/logout.js";
45
55
  import { initializePlan } from "./commands/plan-init.js";
46
56
  import {
47
57
  PublicationCancelledError,
@@ -70,6 +80,7 @@ import {
70
80
  PlanStatusTimeoutError,
71
81
  readPlanStatus,
72
82
  } from "./commands/plan-status.js";
83
+ import { storedTokenReader } from "./credentials.js";
73
84
  import { isFileSystemError } from "./file-system.js";
74
85
  import { createPlanCompileProgressReporter } from "./plan-compile-progress.js";
75
86
  import { isUuidV7 } from "./plan-state.js";
@@ -85,6 +96,8 @@ Usage:
85
96
  Commands:
86
97
  compilation Inspect and download Compilations
87
98
  generate Generate local values
99
+ login Log in to First Draft and save a token
100
+ logout Revoke and remove the saved token
88
101
  plan Work with Foundation Plans
89
102
 
90
103
  Options:
@@ -275,6 +288,45 @@ Provide at least one of --application-key or --name. The command derives a
275
288
  missing key from the name or a missing display name from the key.
276
289
  `;
277
290
 
291
+ const LOGIN_HELP = `First Draft CLI
292
+
293
+ Usage:
294
+ firstdraft login [--interactive]
295
+
296
+ Options:
297
+ --staging Log in to staging
298
+ -i, --interactive Approve with a code on another device (no local browser)
299
+ --device Same as --interactive
300
+ -h, --help Show help
301
+
302
+ Environment:
303
+ FIRSTDRAFT_API_URL Log in to a custom API origin
304
+ XDG_CONFIG_HOME Credentials directory base (default: ~/.config)
305
+
306
+ By default the command prints a URL to open in a browser on this machine, then
307
+ waits up to five minutes for First Draft to redirect to a one-time listener on
308
+ 127.0.0.1. The token is saved for the selected origin in
309
+ firstdraft/credentials.json under the configuration directory and is never
310
+ printed. Token environment variables take precedence over a saved login.
311
+ `;
312
+
313
+ const LOGOUT_HELP = `First Draft CLI
314
+
315
+ Usage:
316
+ firstdraft logout
317
+
318
+ Options:
319
+ --staging Log out of staging
320
+ -h, --help Show help
321
+
322
+ Environment:
323
+ FIRSTDRAFT_API_URL Log out of a custom API origin
324
+
325
+ The command asks First Draft to revoke the saved token for the selected origin,
326
+ then removes it from the credentials file even if revocation is not confirmed.
327
+ Token environment variables are not changed.
328
+ `;
329
+
278
330
  const ROOT_USAGE_ERROR =
279
331
  "Invalid arguments.\nRun 'firstdraft --help' for usage.\n";
280
332
  const ROOT_UNKNOWN_COMMAND =
@@ -304,7 +356,23 @@ const PLAN_PUSH_REQUEST_OUTCOME_UNKNOWN_DETAIL =
304
356
  "The Plan may have been accepted, but the response could not be verified. Stop and reconcile before pushing again; local state was not changed.";
305
357
  const PLAN_PUSH_SERVER_REJECTED_DETAIL = "First Draft rejected the Plan.";
306
358
  const AUTHENTICATION_REQUIRED_DETAIL =
307
- "First Draft authentication is required. Set FIRSTDRAFT_API_TOKEN for production or custom origins, or FIRSTDRAFT_STAGING_API_TOKEN for staging.";
359
+ "First Draft authentication is required. Run 'firstdraft login' for the same environment, or set FIRSTDRAFT_API_TOKEN for production or custom origins, or FIRSTDRAFT_STAGING_API_TOKEN for staging.";
360
+ const LOGIN_INVALID_ARGUMENTS_DETAIL =
361
+ "Invalid arguments. Run 'firstdraft login --help' for usage.";
362
+ const LOGOUT_INVALID_ARGUMENTS_DETAIL =
363
+ "Invalid arguments. Run 'firstdraft logout --help' for usage.";
364
+ const LOGIN_DENIED_DETAIL =
365
+ "The login was denied in the browser. No credential was saved. Run 'firstdraft login' again to retry.";
366
+ const LOGIN_EXPIRED_DETAIL =
367
+ "The login was not approved before it expired. No credential was saved. Run 'firstdraft login' again to retry.";
368
+ const LOGIN_FAILED_DETAIL =
369
+ "The login could not be completed. No credential was saved. Run 'firstdraft login' again, or use 'firstdraft login --interactive' if this machine has no browser.";
370
+ const LOGIN_CREDENTIALS_DETAIL =
371
+ "The credentials file could not be read. No network request was made. Repair or remove it, then run 'firstdraft login' again.";
372
+ const CREDENTIALS_LOCKED_RECOVERY =
373
+ "if no other firstdraft command is running, delete credentials.json.lock next to credentials_path";
374
+ const LOGOUT_FAILED_DETAIL =
375
+ "The credentials file could not be read, so no token was revoked or removed. Repair or remove it, then retry.";
308
376
  const PLAN_STATUS_INVALID_ARGUMENTS_DETAIL =
309
377
  "Invalid arguments. Run 'firstdraft plan status --help' for usage.";
310
378
  const PLAN_STATUS_LOCAL_INPUT_UNREADABLE_DETAIL =
@@ -445,6 +513,14 @@ const GENERATE_APPLICATION_KEY_INVALID_ARGUMENTS_DETAIL =
445
513
  * @property {string} [apiUrl]
446
514
  * @property {string} [apiToken]
447
515
  * @property {string} [stagingApiToken]
516
+ * @property {Readonly<Record<string, string | undefined>>} [env] Locates the credentials file (XDG_CONFIG_HOME)
517
+ * @property {() => string} [homedir]
518
+ * @property {import("./credentials.js").CredentialsFileSystem} [credentialsFileSystem]
519
+ * @property {number} [credentialsLockTimeoutMs]
520
+ * @property {() => string} [hostname]
521
+ * @property {(delayMs: number, signal?: AbortSignal) => Promise<void>} [loginSleep]
522
+ * @property {() => number} [loginNow]
523
+ * @property {import("./oauth.js").StartLoopbackServer} [startLoopbackServer]
448
524
  */
449
525
 
450
526
  /**
@@ -476,6 +552,11 @@ const GENERATE_APPLICATION_KEY_INVALID_ARGUMENTS_DETAIL =
476
552
  * @property {string} [apiToken]
477
553
  * @property {string} [stagingApiToken]
478
554
  * @property {boolean} [staging]
555
+ * @property {import("./credentials.js").CredentialStore} [credentials]
556
+ * @property {() => string} [hostname]
557
+ * @property {(delayMs: number, signal?: AbortSignal) => Promise<void>} [loginSleep]
558
+ * @property {() => number} [loginNow]
559
+ * @property {import("./oauth.js").StartLoopbackServer} [startLoopbackServer]
479
560
  */
480
561
 
481
562
  /**
@@ -490,6 +571,10 @@ const GENERATE_APPLICATION_KEY_INVALID_ARGUMENTS_DETAIL =
490
571
  * @typedef {Omit<CommandOptions, "cwd" | "createProjectId" | "createUuid" | "fileSystem" | "createTemporaryId" | "planStatusSleep" | "planStatusNow" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "planCompilePush" | "planCompileReadStatus" | "planCompilePublish" | "planCompileDownload"> & {cwd?: string, getCwd: () => string}} CompilationCommandOptions
491
572
  */
492
573
 
574
+ /**
575
+ * @typedef {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "fetchFunction" | "createRequestSignal" | "credentials" | "hostname" | "loginSleep" | "loginNow" | "startLoopbackServer" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} LoginCommandOptions
576
+ */
577
+
493
578
  /** @param {RunOptions} options */
494
579
  export async function run({
495
580
  argv,
@@ -519,9 +604,43 @@ export async function run({
519
604
  apiUrl = process.env.FIRSTDRAFT_API_URL,
520
605
  apiToken = process.env.FIRSTDRAFT_API_TOKEN,
521
606
  stagingApiToken = process.env.FIRSTDRAFT_STAGING_API_TOKEN,
607
+ env = process.env,
608
+ homedir,
609
+ credentialsFileSystem,
610
+ credentialsLockTimeoutMs,
611
+ hostname,
612
+ loginSleep,
613
+ loginNow,
614
+ startLoopbackServer,
522
615
  }) {
523
616
  const staging = argv[0] === "--staging";
524
617
  if (staging) argv = argv.slice(1);
618
+ /** @type {import("./credentials.js").CredentialStore} */
619
+ const credentials = {
620
+ env,
621
+ homedir,
622
+ fileSystem: credentialsFileSystem,
623
+ lockTimeoutMs: credentialsLockTimeoutMs,
624
+ };
625
+
626
+ if (argv[0] === "login" || argv[0] === "logout") {
627
+ return (argv[0] === "login" ? runLogin : runLogout)({
628
+ argv: argv.slice(1),
629
+ stdout,
630
+ stderr,
631
+ fetchFunction,
632
+ createRequestSignal,
633
+ credentials,
634
+ hostname,
635
+ loginSleep,
636
+ loginNow,
637
+ startLoopbackServer,
638
+ apiUrl,
639
+ apiToken,
640
+ stagingApiToken,
641
+ staging,
642
+ });
643
+ }
525
644
 
526
645
  if (argv[0] === "generate") {
527
646
  return runGenerate({
@@ -561,6 +680,7 @@ export async function run({
561
680
  apiToken,
562
681
  stagingApiToken,
563
682
  staging,
683
+ credentials,
564
684
  });
565
685
  }
566
686
 
@@ -580,6 +700,7 @@ export async function run({
580
700
  apiToken,
581
701
  stagingApiToken,
582
702
  staging,
703
+ credentials,
583
704
  });
584
705
  }
585
706
 
@@ -658,6 +779,7 @@ async function runPlan({
658
779
  apiToken,
659
780
  stagingApiToken,
660
781
  staging,
782
+ credentials,
661
783
  }) {
662
784
  if (argv[0] === "init") {
663
785
  return runPlanInit({
@@ -684,6 +806,7 @@ async function runPlan({
684
806
  apiToken,
685
807
  stagingApiToken,
686
808
  staging,
809
+ credentials,
687
810
  });
688
811
  }
689
812
 
@@ -702,6 +825,7 @@ async function runPlan({
702
825
  apiToken,
703
826
  stagingApiToken,
704
827
  staging,
828
+ credentials,
705
829
  });
706
830
  }
707
831
 
@@ -729,6 +853,7 @@ async function runPlan({
729
853
  apiToken,
730
854
  stagingApiToken,
731
855
  staging,
856
+ credentials,
732
857
  });
733
858
  }
734
859
 
@@ -776,6 +901,7 @@ async function runCompilation({
776
901
  apiToken,
777
902
  stagingApiToken,
778
903
  staging,
904
+ credentials,
779
905
  }) {
780
906
  if (argv[0] === "status") {
781
907
  return runCompilationStatus({
@@ -792,6 +918,7 @@ async function runCompilation({
792
918
  apiToken,
793
919
  stagingApiToken,
794
920
  staging,
921
+ credentials,
795
922
  });
796
923
  }
797
924
 
@@ -808,6 +935,7 @@ async function runCompilation({
808
935
  apiToken,
809
936
  stagingApiToken,
810
937
  staging,
938
+ credentials,
811
939
  });
812
940
  }
813
941
 
@@ -840,7 +968,7 @@ async function runCompilation({
840
968
  }
841
969
 
842
970
  /**
843
- * @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "compilationSleep" | "compilationNow" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} options
971
+ * @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "compilationSleep" | "compilationNow" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging" | "credentials">} options
844
972
  */
845
973
  async function runCompilationStatus({
846
974
  argv,
@@ -856,6 +984,7 @@ async function runCompilationStatus({
856
984
  apiToken,
857
985
  stagingApiToken,
858
986
  staging,
987
+ credentials,
859
988
  }) {
860
989
  const parsed = parseArguments(() =>
861
990
  parseArgs({
@@ -900,6 +1029,7 @@ async function runCompilationStatus({
900
1029
  apiToken,
901
1030
  stagingApiToken,
902
1031
  staging: staging || parsed.values.staging,
1032
+ readStoredTokens: storedTokenReader(credentials),
903
1033
  });
904
1034
  if (authentication === null) {
905
1035
  writeAuthenticationRequired(stderr);
@@ -925,7 +1055,7 @@ async function runCompilationStatus({
925
1055
  }
926
1056
 
927
1057
  /**
928
- * @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} options
1058
+ * @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging" | "credentials">} options
929
1059
  */
930
1060
  async function runCompilationDownload({
931
1061
  argv,
@@ -939,6 +1069,7 @@ async function runCompilationDownload({
939
1069
  apiToken,
940
1070
  stagingApiToken,
941
1071
  staging,
1072
+ credentials,
942
1073
  }) {
943
1074
  const parsed = parseArguments(() =>
944
1075
  parseArgs({
@@ -989,6 +1120,7 @@ async function runCompilationDownload({
989
1120
  apiToken,
990
1121
  stagingApiToken,
991
1122
  staging: staging || parsed.values.staging,
1123
+ readStoredTokens: storedTokenReader(credentials),
992
1124
  });
993
1125
  if (authentication === null) {
994
1126
  writeAuthenticationRequired(stderr);
@@ -1161,6 +1293,257 @@ function writeCompilationReadError(writer, error, throwUnknown = true) {
1161
1293
  return null;
1162
1294
  }
1163
1295
 
1296
+ /** @param {LoginCommandOptions} options */
1297
+ async function runLogin({
1298
+ argv,
1299
+ stdout,
1300
+ stderr,
1301
+ fetchFunction,
1302
+ createRequestSignal,
1303
+ credentials,
1304
+ hostname,
1305
+ loginSleep,
1306
+ loginNow,
1307
+ startLoopbackServer,
1308
+ apiUrl,
1309
+ apiToken,
1310
+ stagingApiToken,
1311
+ staging,
1312
+ }) {
1313
+ const parsed = parseArguments(() =>
1314
+ parseArgs({
1315
+ args: [...argv],
1316
+ options: {
1317
+ staging: { type: "boolean" },
1318
+ interactive: { type: "boolean", short: "i" },
1319
+ device: { type: "boolean" },
1320
+ help: { type: "boolean", short: "h" },
1321
+ },
1322
+ allowPositionals: false,
1323
+ strict: true,
1324
+ tokens: true,
1325
+ }),
1326
+ );
1327
+
1328
+ if (
1329
+ !parsed ||
1330
+ repeatedValueOption(parsed.tokens) ||
1331
+ (parsed.values.interactive && parsed.values.device)
1332
+ ) {
1333
+ writeJson(stderr, {
1334
+ error: "invalid_arguments",
1335
+ detail: LOGIN_INVALID_ARGUMENTS_DETAIL,
1336
+ });
1337
+ return 2;
1338
+ }
1339
+
1340
+ if (parsed.values.help) {
1341
+ stdout.write(LOGIN_HELP);
1342
+ return 0;
1343
+ }
1344
+
1345
+ const origin = selectLoginOrigin(stderr, {
1346
+ apiUrl,
1347
+ staging: staging || parsed.values.staging,
1348
+ });
1349
+ if (origin === null) return 2;
1350
+
1351
+ try {
1352
+ await login({
1353
+ origin,
1354
+ device: parsed.values.interactive || parsed.values.device,
1355
+ prompt: (text) => stderr.write(text),
1356
+ fetchFunction,
1357
+ createRequestSignal,
1358
+ sleep: loginSleep,
1359
+ now: loginNow,
1360
+ hostname,
1361
+ startLoopback: startLoopbackServer,
1362
+ credentials,
1363
+ });
1364
+ } catch (error) {
1365
+ if (error instanceof LoginDeniedError) {
1366
+ writeJson(stderr, {
1367
+ error: "authorization_denied",
1368
+ detail: LOGIN_DENIED_DETAIL,
1369
+ });
1370
+ return 1;
1371
+ }
1372
+
1373
+ if (error instanceof LoginExpiredError) {
1374
+ writeJson(stderr, {
1375
+ error: "authorization_expired",
1376
+ detail: LOGIN_EXPIRED_DETAIL,
1377
+ });
1378
+ return 1;
1379
+ }
1380
+
1381
+ if (error instanceof LoginFailedError) {
1382
+ writeJson(stderr, {
1383
+ error: "login_failed",
1384
+ detail:
1385
+ error.credentialsPath === undefined
1386
+ ? LOGIN_FAILED_DETAIL
1387
+ : error.phase === "write"
1388
+ ? `First Draft issued a token, but it could not be saved. Revoke the new token at ${origin}/api-tokens, then ${credentialsRecovery(error.reason)} and retry login.`
1389
+ : LOGIN_CREDENTIALS_DETAIL,
1390
+ ...(error.phase === undefined ? {} : { phase: error.phase }),
1391
+ ...(error.reason === undefined ? {} : { reason: error.reason }),
1392
+ ...(error.status === undefined ? {} : { status: error.status }),
1393
+ ...(error.credentialsPath === undefined
1394
+ ? {}
1395
+ : { credentials_path: error.credentialsPath }),
1396
+ });
1397
+ return 1;
1398
+ }
1399
+
1400
+ throw error;
1401
+ }
1402
+
1403
+ stdout.write(`Logged in to ${origin}\n`);
1404
+ writeEnvironmentTokenNote(stderr, origin, { apiToken, stagingApiToken });
1405
+ return 0;
1406
+ }
1407
+
1408
+ /** @param {LoginCommandOptions} options */
1409
+ async function runLogout({
1410
+ argv,
1411
+ stdout,
1412
+ stderr,
1413
+ fetchFunction,
1414
+ createRequestSignal,
1415
+ credentials,
1416
+ apiUrl,
1417
+ apiToken,
1418
+ stagingApiToken,
1419
+ staging,
1420
+ }) {
1421
+ const parsed = parseArguments(() =>
1422
+ parseArgs({
1423
+ args: [...argv],
1424
+ options: {
1425
+ staging: { type: "boolean" },
1426
+ help: { type: "boolean", short: "h" },
1427
+ },
1428
+ allowPositionals: false,
1429
+ strict: true,
1430
+ tokens: true,
1431
+ }),
1432
+ );
1433
+
1434
+ if (!parsed || repeatedValueOption(parsed.tokens)) {
1435
+ writeJson(stderr, {
1436
+ error: "invalid_arguments",
1437
+ detail: LOGOUT_INVALID_ARGUMENTS_DETAIL,
1438
+ });
1439
+ return 2;
1440
+ }
1441
+
1442
+ if (parsed.values.help) {
1443
+ stdout.write(LOGOUT_HELP);
1444
+ return 0;
1445
+ }
1446
+
1447
+ const origin = selectLoginOrigin(stderr, {
1448
+ apiUrl,
1449
+ staging: staging || parsed.values.staging,
1450
+ });
1451
+ if (origin === null) return 2;
1452
+
1453
+ let result;
1454
+ try {
1455
+ result = await logout({
1456
+ origin,
1457
+ fetchFunction,
1458
+ createRequestSignal,
1459
+ credentials,
1460
+ });
1461
+ } catch (error) {
1462
+ if (!(error instanceof LogoutFailedError)) throw error;
1463
+
1464
+ writeJson(stderr, {
1465
+ error: "logout_failed",
1466
+ detail:
1467
+ error.phase === "read"
1468
+ ? LOGOUT_FAILED_DETAIL
1469
+ : error.revoked
1470
+ ? `First Draft confirmed token revocation, but the local credential could not be removed. To remove it, ${credentialsRecovery(error.reason)} and retry logout.`
1471
+ : `First Draft did not confirm token revocation, and the local credential could not be removed. Revoke the token at ${origin}/api-tokens, then ${credentialsRecovery(error.reason)} and retry logout.`,
1472
+ phase: error.phase,
1473
+ ...(error.revoked === undefined ? {} : { revoked: error.revoked }),
1474
+ reason: error.reason,
1475
+ credentials_path: error.credentialsPath,
1476
+ });
1477
+ return 1;
1478
+ }
1479
+
1480
+ if (!result.stored) {
1481
+ stdout.write(`Not logged in to ${origin}; no saved token was found.\n`);
1482
+ } else {
1483
+ stdout.write(`Logged out of ${origin}\n`);
1484
+ if (result.changed) {
1485
+ stderr.write(
1486
+ `The saved token for ${origin} changed while logout was running, so the current saved token was left in place. Run 'firstdraft logout' again to remove it.\n`,
1487
+ );
1488
+ }
1489
+ if (!result.revoked) {
1490
+ stderr.write(
1491
+ `First Draft did not confirm that the token was revoked. The local copy was removed; revoke the token at ${new URL("/api-tokens", origin).href} if it may still be active.\n`,
1492
+ );
1493
+ }
1494
+ }
1495
+ writeEnvironmentTokenNote(stderr, origin, { apiToken, stagingApiToken });
1496
+ return 0;
1497
+ }
1498
+
1499
+ /**
1500
+ * The recovery step after a credentials update failed, phrased to follow
1501
+ * "then" in a detail message.
1502
+ *
1503
+ * @param {string | undefined} reason
1504
+ */
1505
+ function credentialsRecovery(reason) {
1506
+ return reason === "credentials_locked"
1507
+ ? CREDENTIALS_LOCKED_RECOVERY
1508
+ : "repair the credentials file";
1509
+ }
1510
+
1511
+ /**
1512
+ * @param {Writer} stderr
1513
+ * @param {{apiUrl?: string, staging?: boolean}} options
1514
+ * @returns {string | null}
1515
+ */
1516
+ function selectLoginOrigin(stderr, options) {
1517
+ try {
1518
+ return resolveLoginOrigin(options);
1519
+ } catch (error) {
1520
+ if (!(error instanceof PlanPushConfigurationError)) throw error;
1521
+
1522
+ writeJson(stderr, {
1523
+ error: "invalid_configuration",
1524
+ detail: error.message,
1525
+ });
1526
+ return null;
1527
+ }
1528
+ }
1529
+
1530
+ /**
1531
+ * @param {Writer} stderr
1532
+ * @param {string} origin
1533
+ * @param {{apiToken?: string, stagingApiToken?: string}} tokens
1534
+ */
1535
+ function writeEnvironmentTokenNote(stderr, origin, tokens) {
1536
+ if (environmentTokenFor(origin, tokens) === undefined) return;
1537
+
1538
+ const variable =
1539
+ origin === STAGING_API_URL
1540
+ ? "FIRSTDRAFT_STAGING_API_TOKEN"
1541
+ : "FIRSTDRAFT_API_TOKEN";
1542
+ stderr.write(
1543
+ `Note: ${variable} is set and takes precedence over the saved login for ${origin}.\n`,
1544
+ );
1545
+ }
1546
+
1164
1547
  /**
1165
1548
  * @param {GenerateCommandOptions} options
1166
1549
  */
@@ -1296,7 +1679,7 @@ function runGenerateApplicationKey({ argv, stdout, stderr }) {
1296
1679
  }
1297
1680
 
1298
1681
  /**
1299
- * @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createTemporaryId" | "createRequestSignal" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} options
1682
+ * @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createTemporaryId" | "createRequestSignal" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging" | "credentials">} options
1300
1683
  */
1301
1684
  async function runPlanPush({
1302
1685
  argv,
@@ -1311,6 +1694,7 @@ async function runPlanPush({
1311
1694
  apiToken,
1312
1695
  stagingApiToken,
1313
1696
  staging,
1697
+ credentials,
1314
1698
  }) {
1315
1699
  const parsed = parseArguments(() =>
1316
1700
  parseArgs({
@@ -1346,6 +1730,7 @@ async function runPlanPush({
1346
1730
  apiToken,
1347
1731
  stagingApiToken,
1348
1732
  staging: staging || parsed.values.staging,
1733
+ readStoredTokens: storedTokenReader(credentials),
1349
1734
  });
1350
1735
  if (authentication === null) {
1351
1736
  writeAuthenticationRequired(stderr);
@@ -1441,7 +1826,7 @@ async function runPlanPush({
1441
1826
  }
1442
1827
 
1443
1828
  /**
1444
- * @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "planStatusSleep" | "planStatusNow" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} options
1829
+ * @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createRequestSignal" | "planStatusSleep" | "planStatusNow" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging" | "credentials">} options
1445
1830
  */
1446
1831
  async function runPlanStatus({
1447
1832
  argv,
@@ -1457,6 +1842,7 @@ async function runPlanStatus({
1457
1842
  apiToken,
1458
1843
  stagingApiToken,
1459
1844
  staging,
1845
+ credentials,
1460
1846
  }) {
1461
1847
  const parsed = parseArguments(() =>
1462
1848
  parseArgs({
@@ -1493,6 +1879,7 @@ async function runPlanStatus({
1493
1879
  apiToken,
1494
1880
  stagingApiToken,
1495
1881
  staging: staging || parsed.values.staging,
1882
+ readStoredTokens: storedTokenReader(credentials),
1496
1883
  });
1497
1884
  if (authentication === null) {
1498
1885
  writeAuthenticationRequired(stderr);
@@ -1605,7 +1992,7 @@ async function runPlanStatus({
1605
1992
  }
1606
1993
 
1607
1994
  /**
1608
- * @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createTemporaryId" | "createRequestSignal" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "compilationSleep" | "compilationNow" | "planCompilePush" | "planCompileReadStatus" | "planCompilePublish" | "planCompileDownload" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging">} options
1995
+ * @param {Pick<CommandOptions, "argv" | "stdout" | "stderr" | "cwd" | "fetchFunction" | "planPushFileSystem" | "createTemporaryId" | "createRequestSignal" | "planCompileSleep" | "planCompileNow" | "planPublishSleep" | "planPublishNow" | "compilationSleep" | "compilationNow" | "planCompilePush" | "planCompileReadStatus" | "planCompilePublish" | "planCompileDownload" | "apiUrl" | "apiToken" | "stagingApiToken" | "staging" | "credentials">} options
1609
1996
  */
1610
1997
  async function runPlanCompile({
1611
1998
  argv,
@@ -1630,6 +2017,7 @@ async function runPlanCompile({
1630
2017
  apiToken,
1631
2018
  stagingApiToken,
1632
2019
  staging,
2020
+ credentials,
1633
2021
  }) {
1634
2022
  const parsed = parseArguments(() =>
1635
2023
  parseArgs({
@@ -1676,6 +2064,7 @@ async function runPlanCompile({
1676
2064
  apiToken,
1677
2065
  stagingApiToken,
1678
2066
  staging: staging || parsed.values.staging,
2067
+ readStoredTokens: storedTokenReader(credentials),
1679
2068
  });
1680
2069
  if (authentication === null) {
1681
2070
  writeAuthenticationRequired(stderr);