Skip to content

Commit 46a8e72

Browse files
committed
Applied claude review comments
1 parent 855a69a commit 46a8e72

2 files changed

Lines changed: 41 additions & 35 deletions

File tree

src/commands/auth/revoke-token.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default class RevokeTokenCommand extends AblyBaseCommand {
1010
static description = "Revoke tokens by client ID or revocation key";
1111

1212
static examples = [
13-
"$ ably auth revoke-token --client-id user@example.com",
14-
"$ ably auth revoke-token --client-id user@example.com --force",
15-
"$ ably auth revoke-token --revocation-key group1",
16-
"$ ably auth revoke-token --client-id user@example.com --allow-reauth-margin",
17-
"$ ably auth revoke-token --client-id user@example.com --json --force",
13+
`$ ably auth revoke-token --client-id "userClientId"`,
14+
`$ ably auth revoke-token --client-id "userClientId" --force`,
15+
`$ ably auth revoke-token --revocation-key group1`,
16+
`$ ably auth revoke-token --client-id "userClientId" --allow-reauth-margin`,
17+
`$ ably auth revoke-token --client-id "userClientId" --json --force`,
1818
];
1919

2020
static flags = {
@@ -38,7 +38,7 @@ export default class RevokeTokenCommand extends AblyBaseCommand {
3838
"allow-reauth-margin": Flags.boolean({
3939
default: false,
4040
description:
41-
"Delay enforcement by 30s so connected clients can obtain a new token before disconnection",
41+
"[default: false] Delay enforcement by 30s so connected clients can obtain a new token before disconnection.",
4242
}),
4343
};
4444

@@ -64,15 +64,7 @@ export default class RevokeTokenCommand extends AblyBaseCommand {
6464
const targetLabel = clientId ? "Client ID" : "Revocation Key";
6565
const targetValue = (clientId ?? revocationKey)!;
6666

67-
// Get app and key
68-
const appAndKey = await this.ensureAppAndKey(flags);
69-
if (!appAndKey) {
70-
return;
71-
}
72-
73-
const { apiKey } = appAndKey;
74-
75-
// JSON mode guard
67+
// JSON mode guard — fail fast before config lookup
7668
if (!flags.force && this.shouldOutputJson(flags)) {
7769
this.fail(
7870
"The --force flag is required when using --json to confirm revocation",
@@ -81,10 +73,20 @@ export default class RevokeTokenCommand extends AblyBaseCommand {
8173
);
8274
}
8375

76+
// Get app and key
77+
const appAndKey = await this.ensureAppAndKey(flags);
78+
if (!appAndKey) {
79+
return;
80+
}
81+
82+
const { apiKey } = appAndKey;
83+
8484
// Interactive confirmation
8585
if (!flags.force && !this.shouldOutputJson(flags)) {
86-
this.log(`\nYou are about to revoke all tokens matching:`);
87-
this.log(`${formatLabel(targetLabel)} ${formatResource(targetValue)}`);
86+
this.logToStderr(`\nYou are about to revoke all tokens matching:`);
87+
this.logToStderr(
88+
`${formatLabel(targetLabel)} ${formatResource(targetValue)}`,
89+
);
8890

8991
const confirmed = await promptForConfirmation(
9092
"\nThis will permanently revoke all matching tokens, and any applications using those tokens will need to be issued new tokens. Are you sure?",

test/unit/commands/auth/revoke-token.test.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,12 @@ import { parseNdjsonLines } from "../../../helpers/ndjson.js";
1313
describe("auth:revoke-token command", () => {
1414
const mockClientId = "test-client-id";
1515
const mockRevocationKey = "group1";
16-
const originalStdin = process.stdin;
17-
18-
function mockStdinAnswer(answer: string) {
19-
const readable = new Readable({ read() {} });
20-
Object.defineProperty(process, "stdin", {
21-
value: readable,
22-
writable: true,
23-
configurable: true,
24-
});
25-
queueMicrotask(() => {
26-
for (const chunk of [`${answer}\n`, null]) readable.push(chunk);
27-
});
28-
}
2916

3017
beforeEach(() => {
3118
nock.cleanAll();
3219
});
3320

3421
afterEach(() => {
35-
Object.defineProperty(process, "stdin", {
36-
value: originalStdin,
37-
writable: true,
38-
configurable: true,
39-
});
4022
nock.cleanAll();
4123
});
4224

@@ -217,6 +199,28 @@ describe("auth:revoke-token command", () => {
217199
});
218200

219201
describe("confirmation prompt", () => {
202+
const originalStdin = process.stdin;
203+
204+
function mockStdinAnswer(answer: string) {
205+
const readable = new Readable({ read() {} });
206+
Object.defineProperty(process, "stdin", {
207+
value: readable,
208+
writable: true,
209+
configurable: true,
210+
});
211+
queueMicrotask(() => {
212+
for (const chunk of [`${answer}\n`, null]) readable.push(chunk);
213+
});
214+
}
215+
216+
afterEach(() => {
217+
Object.defineProperty(process, "stdin", {
218+
value: originalStdin,
219+
writable: true,
220+
configurable: true,
221+
});
222+
});
223+
220224
it("should require --force in JSON mode", async () => {
221225
const { stdout } = await runCommand(
222226
["auth:revoke-token", "--client-id", mockClientId, "--json"],

0 commit comments

Comments
 (0)