Skip to content

Commit

Permalink
Merge branch 'main' into br/port-lib-tests-to-ts-1
Browse files Browse the repository at this point in the history
  • Loading branch information
brandenrodgers committed Jan 21, 2025
2 parents 89a44d4 + 565ad32 commit 44a9979
Show file tree
Hide file tree
Showing 31 changed files with 706 additions and 577 deletions.
12 changes: 4 additions & 8 deletions commands/account/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
getConfigPath,
deleteAccount,
getConfigDefaultAccount,
getAccountId: getAccountIdFromConfig,
getAccountId,
updateDefaultAccount,
} = require('@hubspot/local-dev-lib/config');

Expand All @@ -23,7 +23,7 @@ exports.handler = async options => {
const { account } = options;
let accountToRemove = account;

if (accountToRemove && !getAccountIdFromConfig(accountToRemove)) {
if (accountToRemove && !getAccountId(accountToRemove)) {
logger.error(
i18n(`${i18nKey}.errors.accountNotFound`, {
specifiedAccount: accountToRemove,
Expand All @@ -32,17 +32,13 @@ exports.handler = async options => {
);
}

if (!accountToRemove || !getAccountIdFromConfig(accountToRemove)) {
if (!accountToRemove || !getAccountId(accountToRemove)) {
accountToRemove = await selectAccountFromConfig(
i18n(`${i18nKey}.prompts.selectAccountToRemove`)
);
}

trackCommandUsage(
'accounts-remove',
null,
getAccountIdFromConfig(accountToRemove)
);
trackCommandUsage('accounts-remove', null, getAccountId(accountToRemove));

const currentDefaultAccount = getConfigDefaultAccount();

Expand Down
10 changes: 3 additions & 7 deletions commands/account/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { logger } = require('@hubspot/local-dev-lib/logger');
const {
getConfigPath,
updateDefaultAccount,
getAccountId: getAccountIdFromConfig,
getAccountId,
} = require('@hubspot/local-dev-lib/config');

const { trackCommandUsage } = require('../../lib/usageTracking');
Expand All @@ -20,7 +20,7 @@ exports.handler = async options => {

if (!newDefaultAccount) {
newDefaultAccount = await selectAccountFromConfig();
} else if (!getAccountIdFromConfig(newDefaultAccount)) {
} else if (!getAccountId(newDefaultAccount)) {
logger.error(
i18n(`${i18nKey}.errors.accountNotFound`, {
specifiedAccount: newDefaultAccount,
Expand All @@ -30,11 +30,7 @@ exports.handler = async options => {
newDefaultAccount = await selectAccountFromConfig();
}

trackCommandUsage(
'accounts-use',
null,
getAccountIdFromConfig(newDefaultAccount)
);
trackCommandUsage('accounts-use', null, getAccountId(newDefaultAccount));

updateDefaultAccount(newDefaultAccount);

Expand Down
4 changes: 2 additions & 2 deletions commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
getConfigPath,
loadConfig,
getConfigDefaultAccount,
getAccountId,
} = require('@hubspot/local-dev-lib/config');
const {
commaSeparatedValues,
Expand All @@ -39,7 +40,6 @@ const {
const {
addConfigOptions,
setLogLevel,
getAccountId,
addTestingOptions,
addGlobalOptions,
} = require('../lib/commonOpts');
Expand Down Expand Up @@ -197,7 +197,7 @@ exports.handler = async options => {
'accountsListCommand',
]);

const accountId = getAccountId({ account: accountName });
const accountId = getAccountId(accountName);
await trackAuthAction('auth', authType, TRACKING_STATUS.COMPLETE, accountId);

process.exit(EXIT_CODES.SUCCESS);
Expand Down
8 changes: 1 addition & 7 deletions commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ const endpointLog = async (accountId, functionPath, options) => {
}
};

await tailLogs({
accountId,
compact,
tailCall,
fetchLatest,
name: functionPath,
});
await tailLogs(accountId, functionPath, fetchLatest, tailCall, compact);
} else if (latest) {
try {
const { data } = await getLatestFunctionLog(accountId, functionPath);
Expand Down
5 changes: 1 addition & 4 deletions commands/project/__tests__/installDeps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const { logger } = require('@hubspot/local-dev-lib/logger');
const { getProjectConfig } = require('../../../lib/projects');
const { EXIT_CODES } = require('../../../lib/enums/exitCodes');
const { trackCommandUsage } = require('../../../lib/usageTracking');
const { getAccountId } = require('../../../lib/commonOpts');
const {
installPackages,
getProjectPackageJsonLocations,
Expand Down Expand Up @@ -56,10 +55,8 @@ describe('commands/project/installDeps', () => {

it('should track the command usage', async () => {
const accountId = 999999;
getAccountId.mockReturnValue(accountId);
await installDepsCommand.handler({});
await installDepsCommand.handler({ derivedAccountId: accountId });

expect(getAccountId).toHaveBeenCalledTimes(1);
expect(trackCommandUsage).toHaveBeenCalledTimes(1);
expect(trackCommandUsage).toHaveBeenCalledWith(
'project-install-deps',
Expand Down
6 changes: 2 additions & 4 deletions commands/project/installDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const { promptUser } = require('../../lib/prompts/promptUtils');
const path = require('path');
const { i18n } = require('../../lib/lang');
const { trackCommandUsage } = require('../../lib/usageTracking');
const { getAccountId } = require('../../lib/commonOpts');
const { uiBetaTag } = require('../../lib/ui');

const i18nKey = `commands.project.subcommands.installDeps`;
Expand All @@ -19,10 +18,9 @@ exports.command = 'install-deps [packages..]';
exports.describe = uiBetaTag(i18n(`${i18nKey}.help.describe`), false);

exports.handler = async options => {
const { packages } = options || {};
const { derivedAccountId, packages } = options || {};
try {
const accountId = getAccountId(options);
trackCommandUsage('project-install-deps', null, accountId);
trackCommandUsage('project-install-deps', null, derivedAccountId);

const projectConfig = await getProjectConfig();
if (!projectConfig || !projectConfig.projectDir) {
Expand Down
8 changes: 4 additions & 4 deletions commands/project/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ exports.handler = async options => {
});

try {
const result = await handleProjectUpload(
const { result, uploadError } = await handleProjectUpload(
derivedAccountId,
projectConfig,
projectDir,
pollProjectBuildAndDeploy,
message
);

if (result.uploadError) {
if (uploadError) {
if (
isSpecifiedError(result.uploadError, {
isSpecifiedError(uploadError, {
subCategory: PROJECT_ERROR_TYPES.PROJECT_LOCKED,
})
) {
Expand All @@ -67,7 +67,7 @@ exports.handler = async options => {
logger.log();
} else {
logError(
result.uploadError,
uploadError,
new ApiErrorContext({
accountId: derivedAccountId,
request: 'project upload',
Expand Down
8 changes: 4 additions & 4 deletions commands/project/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ exports.handler = async options => {

// Upload all files if no build exists for this project yet
if (initialUpload || hasNoBuilds) {
const result = await handleProjectUpload(
const { uploadError } = await handleProjectUpload(
derivedAccountId,
projectConfig,
projectDir,
startWatching
);

if (result.uploadError) {
if (uploadError) {
if (
isSpecifiedError(result.uploadError, {
isSpecifiedError(uploadError, {
subCategory: PROJECT_ERROR_TYPES.PROJECT_LOCKED,
})
) {
Expand All @@ -131,7 +131,7 @@ exports.handler = async options => {
logger.log();
} else {
logError(
result.uploadError,
uploadError,
new ApiErrorContext({
accountId: derivedAccountId,
request: 'project upload',
Expand Down
12 changes: 6 additions & 6 deletions commands/sandbox/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const {
HUBSPOT_ACCOUNT_TYPES,
HUBSPOT_ACCOUNT_TYPE_STRINGS,
} = require('@hubspot/local-dev-lib/constants/config');
const { buildNewAccount } = require('../../lib/buildAccount');
const { buildSandbox } = require('../../lib/buildAccount');
const {
hubspotAccountNamePrompt,
} = require('../../lib/prompts/accountNamePrompt');
Expand Down Expand Up @@ -130,13 +130,13 @@ exports.handler = async options => {
}

try {
const { result } = await buildNewAccount({
name: sandboxName,
accountType: sandboxType,
const result = await buildSandbox(
sandboxName,
accountConfig,
sandboxType,
env,
force,
});
force
);

const sandboxAccountConfig = getAccountConfig(result.sandbox.sandboxHubId);
// For v1 sandboxes, keep sync here. Once we migrate to v2, this will be handled by BE automatically
Expand Down
18 changes: 7 additions & 11 deletions commands/sandbox/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const {
addAccountOptions,
addConfigOptions,
addUseEnvironmentOptions,
getAccountId,
addTestingOptions,
} = require('../../lib/commonOpts');
const { logger } = require('@hubspot/local-dev-lib/logger');
Expand All @@ -17,7 +16,7 @@ const {
getEnv,
removeSandboxAccountFromConfig,
updateDefaultAccount,
getConfigDefaultAccount,
getAccountId,
getConfigAccounts,
} = require('@hubspot/local-dev-lib/config');
const {
Expand Down Expand Up @@ -61,11 +60,10 @@ exports.handler = async options => {
}
}

const sandboxAccountId = getAccountId({
account: providedAccountId || accountPrompt.account,
});
const isDefaultAccount =
sandboxAccountId === getAccountId(getConfigDefaultAccount());
const sandboxAccountId = getAccountId(
providedAccountId || accountPrompt.account
);
const isDefaultAccount = sandboxAccountId === getAccountId();

const baseUrl = getHubSpotWebsiteOrigin(
getValidEnv(getEnv(sandboxAccountId))
Expand All @@ -79,9 +77,7 @@ exports.handler = async options => {
parentAccountId = portal.parentAccountId;
} else if (!force) {
const parentAccountPrompt = await deleteSandboxPrompt(true);
parentAccountId = getAccountId({
account: parentAccountPrompt.account,
});
parentAccountId = getAccountId(parentAccountPrompt.account);
} else {
logger.error(i18n(`${i18nKey}.failure.noParentAccount`));
process.exit(EXIT_CODES.ERROR);
Expand All @@ -94,7 +90,7 @@ exports.handler = async options => {
getEnv(sandboxAccountId) === 'qa' ? '--qa' : ''
} --account=${parentAccountId}`;

if (parentAccountId && !getAccountId({ account: parentAccountId })) {
if (parentAccountId && !getAccountId(parentAccountId)) {
logger.log('');
logger.error(
i18n(`${i18nKey}.failure.noParentPortalAvailable`, {
Expand Down
9 changes: 6 additions & 3 deletions lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ en:
convertFields:
describe: "If true, converts any javascript fields files contained in module folder or project root."
clean:
describe: "Will cause upload to delete files in your HubSpot account that are not found locally."
describe: "Will delete the destination directory and its contents before uploading. This will also clear the global content associated with any global partial templates and modules."
force:
describe: "Skips confirmation prompts when doing a clean upload."
previewUrl: "To preview this theme, visit: {{ previewUrl }}"
Expand All @@ -987,7 +987,7 @@ en:
uploading: "Uploading files from \"{{ src }}\" to \"{{ dest }}\" in the Design Manager of account {{ accountId }}"
notUploaded: "There was an error processing \"{{ src }}\". The file has not been uploaded."
cleaning: "Removing \"{{ filePath }}\" from account {{ accountId }} and uploading local..."
confirmCleanUpload: "You are about to remove any remote files in \"{{ filePath }}\" on HubSpot account {{ accountId }} that don't exist locally. Are you sure you want to do this?"
confirmCleanUpload: "You are about to delete the directory \"{{ filePath }}\" and its contents on HubSpot account {{ accountId }} before uploading. This will also clear the global content associated with any global partial templates and modules. Are you sure you want to do this?"
watch:
describe: "Watch a directory on your computer for changes and upload the changed files to the HubSpot CMS."
errors:
Expand Down Expand Up @@ -1075,6 +1075,7 @@ en:
fileChangeError: "Failed to notify local dev server of file change: {{ message }}"
localDev:
confirmDefaultAccountIsTarget:
configError: "An error occurred while reading the default account from your config. Run {{ authCommand }} to re-auth this account"
declineDefaultAccountExplanation: "To develop on a different account, run {{ useCommand }} to change your default account, then re-run {{ devCommand }}."
checkIfDefaultAccountIsSupported:
publicApp: "This project contains a public app. Local development of public apps is only supported on developer accounts and developer test accounts. Change your default account using {{ useCommand }}, or link a new account with {{ authCommand }}."
Expand All @@ -1095,6 +1096,7 @@ en:
createInitialBuildForNewProject:
initialUploadMessage: "HubSpot Local Dev Server Startup"
projectLockedError: "Your project is locked. This may mean that another user is running the {{#bold}}`hs project watch`{{/bold}} command for this project. If this is you, unlock the project in Projects UI."
genericError: "An error occurred while creating the initial build for this project. Run {{ uploadCommand }} to try again."
checkIfParentAccountIsAuthed:
notAuthedError: "To develop this project locally, run {{ authCommand }} to authenticate the App Developer Account {{ accountId }} associated with {{ accountIdentifier }}."
projects:
Expand Down Expand Up @@ -1421,6 +1423,7 @@ en:
invalidUser: "Couldn't create {{#bold}}{{ accountName }}{{/bold}} because your account has been removed from {{#bold}}{{ parentAccountName }}{{/bold}} or your permission set doesn't allow you to create the sandbox. To update your permissions, contact a super admin in {{#bold}}{{ parentAccountName }}{{/bold}}."
403Gating: "Couldn't create {{#bold}}{{ accountName }}{{/bold}} because {{#bold}}{{ parentAccountName }}{{/bold}} does not have access to development sandboxes. To opt in to the CRM Development Beta and use development sandboxes, visit https://app.hubspot.com/l/product-updates/in-beta?update=13899236."
usageLimitsFetch: "Unable to fetch sandbox usage limits. Please try again."
generic: "An error occurred while creating a new sandbox. Please try again."
limit:
developer:
one: "{{#bold}}{{ accountName }}{{/bold}} reached the limit of {{ limit }} development sandbox.
Expand Down Expand Up @@ -1499,7 +1502,7 @@ en:
missingScopeError: "Couldn't execute the {{ request }} because the access key for {{ accountName }} is missing required scopes. To update scopes, run {{ authCommand }}. Then deactivate the existing key and generate a new one that includes the missing scopes."
serverless:
verifyAccessKeyAndUserAccess:
fetchScopeDataError: "Error verifying access of scopeGroup {{ scopeGroup }}: {{ error }}"
fetchScopeDataError: "Error verifying access of scopeGroup {{ scopeGroup }}:"
portalMissingScope: "Your account does not have access to this action. Talk to an account admin to request it."
userMissingScope: "You don't have access to this action. Ask an account admin to change your permissions in Users & Teams settings."
genericMissingScope: "Your access key does not allow this action. Please generate a new access key by running `hs auth personalaccesskey`."
Expand Down
Loading

0 comments on commit 44a9979

Please sign in to comment.