"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const color_1 = require("@heroku-cli/color"); const command_1 = require("@heroku-cli/command"); const formatRelative = require("date-fns/formatRelative"); class AuthToken extends command_1.Command { async run() { this.parse(AuthToken); if (!this.heroku.auth) this.error('not logged in'); try { const { body: tokens } = await this.heroku.get('/oauth/authorizations', { retryAuth: false }); const token = tokens.find((t) => t.access_token && t.access_token.token === this.heroku.auth); if (token && token.access_token.expires_in) { const d = new Date(); d.setSeconds(d.getSeconds() + token.access_token.expires_in); this.warn(`token will expire ${formatRelative(d, new Date())}\nUse ${color_1.default.cmd('heroku authorizations:create')} to generate a long-term token`); } } catch (err) { this.warn(err); } this.log(this.heroku.auth); } } AuthToken.description = `outputs current CLI authentication token. By default, the CLI auth token is only valid for 1 year. To generate a long-lived token, use heroku authorizations:create`; AuthToken.flags = { help: command_1.flags.help({ char: 'h' }), }; exports.default = AuthToken;