Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting the accounts info command to TS #1342

Merged
merged 17 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions commands/account/info.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
// @ts-nocheck
const { logger } = require('@hubspot/local-dev-lib/logger');
const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
const { getAccessToken } = require('@hubspot/local-dev-lib/personalAccessKey');
const { addConfigOptions } = require('../../lib/commonOpts');
const { i18n } = require('../../lib/lang');
const { getTableContents } = require('../../lib/ui/table');
import { Argv } from 'yargs';
import { logger } from '@hubspot/local-dev-lib/logger';
import { getAccountConfig } from '@hubspot/local-dev-lib/config';
import { getAccessToken } from '@hubspot/local-dev-lib/personalAccessKey';
import { addConfigOptions } from '../../lib/commonOpts';
import { i18n } from '../../lib/lang';
import { getTableContents } from '../../lib/ui/table';
import { CommonOptions } from '../../types/Yargs';

const i18nKey = 'commands.account.subcommands.info';
exports.describe = i18n(`${i18nKey}.describe`);
const describe = i18n(`${i18nKey}.describe`);

exports.command = 'info [account]';
const command = 'info [account]';

exports.handler = async options => {
async function handler(options: CommonOptions): Promise<void> {
const { derivedAccountId } = options;
const config = getAccountConfig(derivedAccountId);
// check if the provided account is using a personal access key, if not, show an error
if (config && config.authType === 'personalaccesskey') {
const { name, personalAccessKey, env } = config;
let scopeGroups: string[][] = [];

const response = await getAccessToken(
personalAccessKey,
env,
derivedAccountId
);
if (personalAccessKey) {
const response = await getAccessToken(
brandenrodgers marked this conversation as resolved.
Show resolved Hide resolved
personalAccessKey,
env,
derivedAccountId
);

const scopeGroups = response.scopeGroups.map(s => [s]);
scopeGroups = response.scopeGroups.map(s => [s]);
}

logger.log(i18n(`${i18nKey}.name`, { name }));
if (name) {
logger.log(i18n(`${i18nKey}.name`, { name }));
}
logger.log(i18n(`${i18nKey}.accountId`, { accountId: derivedAccountId }));
logger.log(i18n(`${i18nKey}.scopeGroups`));
logger.log(getTableContents(scopeGroups, { border: { bodyLeft: ' ' } }));
} else {
logger.log(i18n(`${i18nKey}.errors.notUsingPersonalAccessKey`));
}
};
}

exports.builder = yargs => {
function builder(yargs: Argv): Argv {
addConfigOptions(yargs);
brandenrodgers marked this conversation as resolved.
Show resolved Hide resolved

yargs.example([
Expand All @@ -45,4 +51,14 @@ exports.builder = yargs => {
]);

return yargs;
}

const yargsCommand = {
describe,
command,
handler,
builder,
};

export default yargsCommand;
module.exports = yargsCommand;
10 changes: 10 additions & 0 deletions types/Yargs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Arguments } from 'yargs';

export type CommonOptions<T = object> = Arguments<
brandenrodgers marked this conversation as resolved.
Show resolved Hide resolved
T & {
derivedAccountId: number;
providedAccountId?: number;
d: boolean;
debug: boolean;
}
>;
Loading