diff --git a/src/helpers/command.ts b/src/helpers/command.ts deleted file mode 100644 index 4cd7b3f..0000000 --- a/src/helpers/command.ts +++ /dev/null @@ -1,5 +0,0 @@ -import process from "node:process"; - -export function getCommandBase() { - return process.env.IS_DEVELOPMENT_CLI_ENV ? "bun dev" : "sf"; -} diff --git a/src/helpers/errors.ts b/src/helpers/errors.ts index b3ee0f9..d3663a5 100644 --- a/src/helpers/errors.ts +++ b/src/helpers/errors.ts @@ -1,6 +1,5 @@ import process from "node:process"; import * as console from "node:console"; -import { getCommandBase } from "./command.ts"; import { clearAuthFromConfig } from "./config.ts"; export function logAndQuit(message: string): never { @@ -19,17 +18,14 @@ export function logSupportCTAAndQuit(): never { logAndQuit(supportCTA); } -const base = getCommandBase(); -const loginCommand = `${base} login`; - export function logLoginMessageAndQuit(): never { - logAndQuit(`You need to login first.\n\n\t$ ${loginCommand}\n`); + logAndQuit(`You need to login first.\n\n\t$ sf login\n`); } export async function logSessionTokenExpiredAndQuit(): Promise { await clearAuthFromConfig(); logAndQuit( - `\nYour session has expired. Please login again.\n\n\t$ ${loginCommand}\n`, + `\nYour session has expired. Please login again.\n\n\t$ sf login\n`, ); } diff --git a/src/lib/tokens.ts b/src/lib/tokens.ts index 7832eb9..e4e9f62 100644 --- a/src/lib/tokens.ts +++ b/src/lib/tokens.ts @@ -1,18 +1,17 @@ import type { Command } from "@commander-js/extra-typings"; import { confirm, input, select } from "@inquirer/prompts"; -import { gray, green, magenta, red, white } from "jsr:@std/fmt/colors"; +import { cyan, gray, green, magenta, red, white } from "jsr:@std/fmt/colors"; import Table from "cli-table3"; -import dayjs from "dayjs"; import * as console from "node:console"; import process from "node:process"; import ora from "ora"; -import { getCommandBase } from "../helpers/command.ts"; import { getAuthToken, isLoggedIn } from "../helpers/config.ts"; import { logLoginMessageAndQuit, logSessionTokenExpiredAndQuit, } from "../helpers/errors.ts"; import { getApiUrl } from "../helpers/urls.ts"; +import { formatDate } from "../helpers/format-date.ts"; export const TOKEN_EXPIRATION_SECONDS = { IN_7_DAYS: 7 * 24 * 60 * 60, @@ -138,7 +137,6 @@ async function createTokenAction() { // display token to user const data = await response.json(); loadingSpinner.succeed(gray("Access token created 🎉")); - // @ts-ignore: Deno has narrower types for fetch responses, but we know this code works atm. console.log(`${green(data.token)}\n`); // tell them they will set this in the Authorization header @@ -170,13 +168,11 @@ async function createTokenAction() { console.log("\n"); // tip user on other commands - const base = getCommandBase(); - const table = new Table({ colWidths: [20, 30], }); - table.push(["View All Tokens", magenta(`${base} tokens list`)]); - table.push(["Delete a Token", magenta(`${base} tokens delete`)]); + table.push(["View All Tokens", magenta("sf tokens list")]); + table.push(["Delete a Token", magenta("sf tokens delete")]); console.log(`${gray("And other commands you can try:")}`); console.log(table.toString()); @@ -232,11 +228,10 @@ async function listTokensAction() { console.log(`${table.toString()}\n`); // prompt user that they can generate one - const base = getCommandBase(); console.log( `${gray("Generate your first token with: ")}${ magenta( - `${base} tokens create`, + `sf tokens create`, ) }`, ); @@ -249,17 +244,15 @@ async function listTokensAction() { head: [ gray("Token ID"), gray("Name"), - // gray("Last active"), gray("Expires"), ], - colWidths: [40, 15, 25, 25], + colWidths: [40, 15, 25], }); for (const token of tokens) { tokensTable.push([ - gray(token.id), + cyan(token.id), token.name ? token.name : gray("(empty)"), - // green(formatDate(token.last_active_at)), - white(formatDate(token.expires_at)), + white(formatDate(new Date(token.expires_at))), ]); } console.log(tokensTable.toString()); @@ -267,12 +260,6 @@ async function listTokensAction() { process.exit(0); } -function formatDate(isoString: string): string { - return dayjs(isoString).format("MMM D, YYYY [at] h:mma").toLowerCase(); -} - -// -- - async function deleteTokenAction({ id, yes,