azdo-cli 0.19.0-feature-040-auth-token.718 → 0.19.0-feature-040-auth-token.722

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/README.md CHANGED
@@ -19,7 +19,7 @@ Azure DevOps CLI focused on work item read/write workflows.
19
19
  - Feed long PR titles, descriptions and comment bodies from a file or a pipe instead of the shell (`--title-file`, `--description-file`, `--file`; `-` reads standard input)
20
20
  - Persist org/project/default fields in local config (`config`)
21
21
  - List all fields of a work item (`list-fields`)
22
- - Authenticate per Azure DevOps organization with `azdo auth login` — OAuth (Microsoft Entra) by default, or a Personal Access Token via `--use-pat` (or the `AZDO_PAT` env var). Credentials are stored in the OS credential store. Inspect with `azdo auth status`, remove with `azdo auth logout`. Diagnose auth problems with `azdo auth diagnose`. See [docs/authentication.md](docs/authentication.md).
22
+ - Authenticate per Azure DevOps organization with `azdo auth login` — OAuth (Microsoft Entra) by default, or a Personal Access Token via `--use-pat` (or the `AZDO_PAT` env var). Credentials are stored in the OS credential store. Inspect with `azdo auth status`, remove with `azdo auth logout`. Diagnose auth problems with `azdo auth diagnose`. Print the credential the CLI itself would use, for API calls the CLI does not yet wrap, with `azdo auth token`. See [docs/authentication.md](docs/authentication.md).
23
23
  - Trace all HTTP requests to a local file with `--trace <filepath>` (sensitive headers and tokens are automatically redacted).
24
24
 
25
25
  ## Installation
@@ -825,10 +825,18 @@ function entryFor(account) {
825
825
  return wrapUnavailable(() => new Entry(SERVICE, account));
826
826
  }
827
827
  var legacyUnsetNoticeEmitted = false;
828
+ var noticesSuppressed = false;
829
+ function suppressCredentialStoreNotices(suppressed) {
830
+ noticesSuppressed = suppressed;
831
+ }
832
+ function writeNotice(message) {
833
+ if (noticesSuppressed) return;
834
+ process.stderr.write(message);
835
+ }
828
836
  function emitLegacyUnsetNoticeOnce() {
829
837
  if (legacyUnsetNoticeEmitted) return;
830
838
  legacyUnsetNoticeEmitted = true;
831
- process.stderr.write(
839
+ writeNotice(
832
840
  'A legacy PAT exists in the OS vault from a previous azdo-cli version, but no "org" is set in config. Run `azdo auth --org <name>` to re-store it under the per-org key, then `azdo clear-pat` to remove the legacy slot.\n'
833
841
  );
834
842
  }
@@ -925,7 +933,7 @@ async function maybeMigrateLegacy(targetOrg) {
925
933
  backend: probeBackend(),
926
934
  masked_pat: maskedDisplay(legacy)
927
935
  });
928
- process.stderr.write(`Migrated legacy PAT to org ${targetOrg}.
936
+ writeNotice(`Migrated legacy PAT to org ${targetOrg}.
929
937
  `);
930
938
  return legacy;
931
939
  }
@@ -990,7 +998,7 @@ async function deletePat(org) {
990
998
  }
991
999
  try {
992
1000
  const { unlinkSync: unlinkSync2 } = await import("fs");
993
- const { lockPath: lockPath2 } = await import("./oauth-token-refresh-C6UTL2OJ.js");
1001
+ const { lockPath: lockPath2 } = await import("./oauth-token-refresh-PXUQE5JE.js");
994
1002
  unlinkSync2(lockPath2(org));
995
1003
  } catch {
996
1004
  }
@@ -1212,6 +1220,7 @@ export {
1212
1220
  refreshIfNeeded,
1213
1221
  _resetInFlight,
1214
1222
  probeBackend,
1223
+ suppressCredentialStoreNotices,
1215
1224
  getPat,
1216
1225
  getStoredCredential,
1217
1226
  storePat,
package/dist/index.js CHANGED
@@ -33,12 +33,13 @@ import {
33
33
  setOrgScopedValue,
34
34
  storeOAuthCredential,
35
35
  storePat,
36
+ suppressCredentialStoreNotices,
36
37
  tokenResponseToCredential,
37
38
  unsetConfigValue,
38
39
  unsetOrgScopedValue
39
- } from "./chunk-FHXLWD6S.js";
40
+ } from "./chunk-K2CKMY72.js";
40
41
 
41
- // src/index.ts
42
+ // src/program.ts
42
43
  import { Command as Command19 } from "commander";
43
44
 
44
45
  // src/version.ts
@@ -1166,28 +1167,28 @@ function findDotEnvPat(startDir = process.cwd()) {
1166
1167
  return null;
1167
1168
  }
1168
1169
  async function resolveAuthCredential(org) {
1169
- const envPat = process.env.AZDO_PAT;
1170
- if (envPat && envPat.length > 0) {
1171
- return { pat: envPat, source: "env", kind: "pat" };
1172
- }
1173
- const stored = await getStoredCredential(org);
1174
- if (stored !== null) {
1175
- if (stored.kind === "pat") {
1176
- return { pat: stored.token, source: "credential-store", kind: "pat" };
1170
+ let cred;
1171
+ try {
1172
+ cred = await exportCredential(org);
1173
+ } catch (err) {
1174
+ if (err instanceof CredentialMissingError) {
1175
+ return null;
1177
1176
  }
1178
- const fresh = await refreshIfNeeded(org, stored);
1177
+ throw err;
1178
+ }
1179
+ if (cred.kind === "oauth") {
1179
1180
  return {
1180
- pat: fresh.accessToken,
1181
+ pat: cred.token,
1181
1182
  source: "credential-store",
1182
1183
  kind: "oauth",
1183
- accountId: fresh.accountId
1184
+ accountId: cred.accountId
1184
1185
  };
1185
1186
  }
1186
- const dotEnvPat = findDotEnvPat();
1187
- if (dotEnvPat !== null) {
1188
- return { pat: dotEnvPat, source: "env", kind: "pat" };
1189
- }
1190
- return null;
1187
+ return {
1188
+ pat: cred.token,
1189
+ source: cred.source === "credential-store" ? "credential-store" : "env",
1190
+ kind: "pat"
1191
+ };
1191
1192
  }
1192
1193
  var lastResolvedCredential = null;
1193
1194
  async function requireAuthCredential(org) {
@@ -2437,6 +2438,8 @@ async function handleToken(orgFromGlobal) {
2437
2438
  return;
2438
2439
  }
2439
2440
  const org = resolved.org;
2441
+ const stderrIsTty = Boolean(process.stderr.isTTY);
2442
+ suppressCredentialStoreNotices(!stderrIsTty);
2440
2443
  let cred;
2441
2444
  try {
2442
2445
  cred = await exportCredential(org);
@@ -2450,7 +2453,7 @@ async function handleToken(orgFromGlobal) {
2450
2453
  backend: probeBackend(),
2451
2454
  ...cred.kind === "oauth" ? { accountId: cred.accountId } : {}
2452
2455
  });
2453
- if (process.stderr.isTTY) {
2456
+ if (stderrIsTty) {
2454
2457
  process.stderr.write(describeExportedCredential(cred, org));
2455
2458
  }
2456
2459
  process.stdout.write(`${cred.token}
@@ -2540,7 +2543,9 @@ Note: \`azdo auth\` (no subcommand) preserves the legacy PAT-prompt entry point;
2540
2543
  const globals = logoutCmd.optsWithGlobals();
2541
2544
  await handleLogout(options, globals.org);
2542
2545
  });
2543
- const tokenCmd = command.command("token").description("Print the access token the CLI uses for an org to stdout (for scripted API calls)").option("--org <name>", "Azure DevOps organization (defaults: git remote -> config)");
2546
+ const tokenCmd = command.command("token").description(
2547
+ "Print the credential the CLI uses for an org \u2014 a PAT or an OAuth access token \u2014 to stdout (for scripted API calls)"
2548
+ ).option("--org <name>", "Azure DevOps organization (defaults: git remote -> config)");
2544
2549
  tokenCmd.action(async () => {
2545
2550
  const globals = tokenCmd.optsWithGlobals();
2546
2551
  await handleToken(globals.org);
@@ -7209,6 +7214,18 @@ import os from "os";
7209
7214
  var THROTTLE_MS = 10 * 60 * 1e3;
7210
7215
  var FETCH_TIMEOUT_MS = 1500;
7211
7216
  var REGISTRY_URL = "https://registry.npmjs.org/azdo-cli/latest";
7217
+ var UPDATE_CHECK_EXEMPT_COMMANDS = /* @__PURE__ */ new Set(["auth token"]);
7218
+ function commandPathOf(command) {
7219
+ const names = [];
7220
+ for (let node = command; node !== null; node = node.parent) {
7221
+ names.unshift(node.name());
7222
+ }
7223
+ return names;
7224
+ }
7225
+ function skipsUpdateCheck(commandPath) {
7226
+ const withoutRoot = commandPath.slice(1);
7227
+ return UPDATE_CHECK_EXEMPT_COMMANDS.has(withoutRoot.join(" "));
7228
+ }
7212
7229
  function getCachePath() {
7213
7230
  return path2.join(os.homedir(), ".azdo", "update-check.json");
7214
7231
  }
@@ -7306,6 +7323,49 @@ async function getUpdateNotice(opts) {
7306
7323
  }
7307
7324
  }
7308
7325
 
7326
+ // src/program.ts
7327
+ function createProgram() {
7328
+ const program2 = new Command19();
7329
+ program2.name("azdo").description("Azure DevOps CLI tool").version(version, "-v, --version");
7330
+ program2.option("--no-update-check", "Skip the check for a newer published version");
7331
+ program2.option("--trace <filepath>", "Append redacted HTTP request/response trace to a file (owner-read-only permissions)");
7332
+ program2.addCommand(createGetItemCommand());
7333
+ program2.addCommand(createAuthCommand());
7334
+ program2.addCommand(createClearPatCommand());
7335
+ program2.addCommand(createConfigCommand());
7336
+ program2.addCommand(createSetStateCommand());
7337
+ program2.addCommand(createAssignCommand());
7338
+ program2.addCommand(createSetFieldCommand());
7339
+ program2.addCommand(createGetMdFieldCommand());
7340
+ program2.addCommand(createSetMdFieldCommand());
7341
+ program2.addCommand(createUpsertCommand());
7342
+ program2.addCommand(createListFieldsCommand());
7343
+ program2.addCommand(createPrCommand());
7344
+ program2.addCommand(createPipelineCommand());
7345
+ program2.addCommand(createCommentsCommand());
7346
+ program2.addCommand(createDownloadAttachmentCommand());
7347
+ program2.addCommand(createAddAttachmentCommand());
7348
+ program2.addCommand(createDeleteAttachmentCommand());
7349
+ program2.addCommand(createRelationsCommand());
7350
+ program2.showHelpAfterError();
7351
+ program2.hook("preAction", () => {
7352
+ const { trace } = program2.opts();
7353
+ if (trace) {
7354
+ initTraceWriter(trace);
7355
+ }
7356
+ });
7357
+ program2.hook("postAction", async (_thisCommand, actionCommand) => {
7358
+ if (skipsUpdateCheck(commandPathOf(actionCommand))) {
7359
+ return;
7360
+ }
7361
+ const notice = await getUpdateNotice({ enabled: program2.opts().updateCheck });
7362
+ if (notice) {
7363
+ process.stderr.write(notice + "\n");
7364
+ }
7365
+ });
7366
+ return program2;
7367
+ }
7368
+
7309
7369
  // src/index.ts
7310
7370
  function exitOnEpipe(err) {
7311
7371
  if (err.code === "EPIPE") {
@@ -7315,41 +7375,7 @@ function exitOnEpipe(err) {
7315
7375
  }
7316
7376
  process.stdout.on("error", exitOnEpipe);
7317
7377
  process.stderr.on("error", exitOnEpipe);
7318
- var program = new Command19();
7319
- program.name("azdo").description("Azure DevOps CLI tool").version(version, "-v, --version");
7320
- program.option("--no-update-check", "Skip the check for a newer published version");
7321
- program.option("--trace <filepath>", "Append redacted HTTP request/response trace to a file (owner-read-only permissions)");
7322
- program.addCommand(createGetItemCommand());
7323
- program.addCommand(createAuthCommand());
7324
- program.addCommand(createClearPatCommand());
7325
- program.addCommand(createConfigCommand());
7326
- program.addCommand(createSetStateCommand());
7327
- program.addCommand(createAssignCommand());
7328
- program.addCommand(createSetFieldCommand());
7329
- program.addCommand(createGetMdFieldCommand());
7330
- program.addCommand(createSetMdFieldCommand());
7331
- program.addCommand(createUpsertCommand());
7332
- program.addCommand(createListFieldsCommand());
7333
- program.addCommand(createPrCommand());
7334
- program.addCommand(createPipelineCommand());
7335
- program.addCommand(createCommentsCommand());
7336
- program.addCommand(createDownloadAttachmentCommand());
7337
- program.addCommand(createAddAttachmentCommand());
7338
- program.addCommand(createDeleteAttachmentCommand());
7339
- program.addCommand(createRelationsCommand());
7340
- program.showHelpAfterError();
7341
- program.hook("preAction", () => {
7342
- const { trace } = program.opts();
7343
- if (trace) {
7344
- initTraceWriter(trace);
7345
- }
7346
- });
7347
- program.hook("postAction", async () => {
7348
- const notice = await getUpdateNotice({ enabled: program.opts().updateCheck });
7349
- if (notice) {
7350
- process.stderr.write(notice + "\n");
7351
- }
7352
- });
7378
+ var program = createProgram();
7353
7379
  await program.parseAsync();
7354
7380
  if (process.argv.length <= 2) {
7355
7381
  program.help();
@@ -5,7 +5,7 @@ import {
5
5
  lockPath,
6
6
  locksDir,
7
7
  refreshIfNeeded
8
- } from "./chunk-FHXLWD6S.js";
8
+ } from "./chunk-K2CKMY72.js";
9
9
  export {
10
10
  _resetInFlight,
11
11
  classifyRefreshFailure,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azdo-cli",
3
- "version": "0.19.0-feature-040-auth-token.718",
3
+ "version": "0.19.0-feature-040-auth-token.722",
4
4
  "description": "Azure DevOps CLI tool",
5
5
  "type": "module",
6
6
  "bin": {