All files / src/commands/tokens tokens.revoke.command.js

88% Statements 22/25
100% Branches 1/1
0% Functions 0/1
88% Lines 22/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x       193x 193x  
import { z } from 'zod';
import { deleteApiToken } from '../../clever-client/auth-bridge.js';
import { defineArgument } from '../../lib/define-argument.js';
import { defineCommand } from '../../lib/define-command.js';
import { styleText } from '../../lib/style-text.js';
import { Logger } from '../../logger.js';
import { sendToAuthBridge } from '../../models/send-to-api.js';
 
export const tokensRevokeCommand = defineCommand({
  description: 'Revoke an API token',
  since: '3.12.0',
  options: {},
  args: [
    defineArgument({
      schema: z.string(),
      description: 'API token ID',
      placeholder: 'api-token-id',
    }),
  ],
  async handler(_options, apiTokenId) {
    await deleteApiToken(apiTokenId).then(sendToAuthBridge);

    Logger.println(styleText('green', '✔'), 'API token successfully revoked!');
  },
});