@hubspot/cli 7.3.0-experimental.2 → 7.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/migrate.d.ts +61 -0
- package/api/migrate.js +44 -0
- package/bin/cli.js +10 -241
- package/commands/account/auth.d.ts +10 -0
- package/commands/account/auth.js +168 -0
- package/commands/account/clean.js +45 -13
- package/commands/account/createOverride.d.ts +10 -0
- package/commands/account/createOverride.js +104 -0
- package/commands/account/info.js +43 -11
- package/commands/account/list.js +27 -10
- package/commands/account/remove.js +42 -9
- package/commands/account/removeOverride.d.ts +10 -0
- package/commands/account/removeOverride.js +76 -0
- package/commands/account/rename.js +4 -5
- package/commands/account/use.js +29 -8
- package/commands/account.js +7 -2
- package/commands/app/migrate.d.ts +7 -0
- package/commands/app/migrate.js +95 -0
- package/commands/app.d.ts +6 -0
- package/commands/app.js +23 -0
- package/commands/auth.js +6 -2
- package/commands/cms/convertFields.js +5 -6
- package/commands/cms/getReactModule.js +7 -8
- package/commands/cms/lighthouseScore.js +19 -16
- package/commands/config/migrate.d.ts +10 -0
- package/commands/config/migrate.js +84 -0
- package/commands/config/set.d.ts +10 -0
- package/commands/config/set.js +34 -30
- package/commands/config.d.ts +4 -1
- package/commands/config.js +45 -11
- package/commands/create/api-sample.js +8 -7
- package/commands/create/module.js +1 -2
- package/commands/create/template.js +1 -2
- package/commands/customObject/create.js +8 -9
- package/commands/customObject/schema/create.js +5 -6
- package/commands/customObject/schema/delete.js +12 -10
- package/commands/customObject/schema/fetch-all.js +8 -8
- package/commands/customObject/schema/fetch.js +10 -10
- package/commands/customObject/schema/list.js +2 -3
- package/commands/customObject/schema/update.js +7 -8
- package/commands/customObject/schema.js +1 -2
- package/commands/filemanager/fetch.js +5 -6
- package/commands/filemanager/upload.js +12 -13
- package/commands/function/deploy.js +9 -10
- package/commands/function/list.js +4 -5
- package/commands/function/server.js +7 -8
- package/commands/init.js +9 -10
- package/commands/project/cloneApp.d.ts +9 -1
- package/commands/project/cloneApp.js +91 -76
- package/commands/project/create.js +1 -0
- package/commands/project/migrateApp.d.ts +9 -1
- package/commands/project/migrateApp.js +43 -170
- package/commands/project/watch.js +12 -0
- package/lang/en.js +11 -3
- package/lang/en.lyaml +125 -10
- package/lib/DevServerManagerV2.d.ts +1 -2
- package/lib/DevServerManagerV2.js +1 -2
- package/lib/LocalDevManagerV2.js +10 -15
- package/lib/app/migrate.d.ts +5 -0
- package/lib/app/migrate.js +242 -0
- package/lib/app/migrate_legacy.d.ts +4 -0
- package/lib/app/migrate_legacy.js +129 -0
- package/lib/configMigrate.d.ts +2 -0
- package/lib/configMigrate.js +104 -0
- package/lib/dependencyManagement.d.ts +5 -0
- package/lib/dependencyManagement.js +47 -22
- package/lib/doctor/Diagnosis.d.ts +1 -2
- package/lib/doctor/Diagnosis.js +10 -6
- package/lib/doctor/DiagnosticInfoBuilder.d.ts +1 -0
- package/lib/doctor/DiagnosticInfoBuilder.js +1 -0
- package/lib/doctor/Doctor.d.ts +1 -0
- package/lib/doctor/Doctor.js +19 -2
- package/lib/middleware/__test__/configMiddleware.test.d.ts +1 -0
- package/lib/middleware/__test__/configMiddleware.test.js +194 -0
- package/lib/middleware/__test__/gitMiddleware.test.d.ts +1 -0
- package/lib/middleware/__test__/gitMiddleware.test.js +76 -0
- package/lib/middleware/__test__/notificationsMiddleware.test.d.ts +1 -0
- package/lib/middleware/__test__/notificationsMiddleware.test.js +10 -0
- package/lib/middleware/__test__/requestMiddleware.test.d.ts +1 -0
- package/lib/middleware/__test__/requestMiddleware.test.js +20 -0
- package/lib/middleware/__test__/utils.test.d.ts +1 -0
- package/lib/middleware/__test__/utils.test.js +53 -0
- package/lib/middleware/__test__/yargsChecksMiddleware.test.d.ts +1 -0
- package/lib/middleware/__test__/yargsChecksMiddleware.test.js +81 -0
- package/lib/middleware/configMiddleware.d.ts +13 -0
- package/lib/middleware/configMiddleware.js +109 -0
- package/lib/middleware/fireAlarmMiddleware.d.ts +4 -0
- package/lib/middleware/fireAlarmMiddleware.js +137 -0
- package/lib/middleware/gitMiddleware.d.ts +2 -0
- package/lib/middleware/gitMiddleware.js +14 -0
- package/lib/middleware/notificationsMiddleware.d.ts +1 -0
- package/lib/middleware/notificationsMiddleware.js +38 -0
- package/lib/middleware/requestMiddleware.d.ts +1 -0
- package/lib/middleware/requestMiddleware.js +11 -0
- package/lib/middleware/utils.d.ts +8 -0
- package/lib/middleware/utils.js +17 -0
- package/lib/middleware/yargsChecksMiddleware.d.ts +4 -0
- package/lib/middleware/yargsChecksMiddleware.js +24 -0
- package/lib/polling.d.ts +4 -0
- package/lib/polling.js +3 -3
- package/lib/projects/structure.d.ts +1 -2
- package/lib/projects/structure.js +0 -4
- package/lib/prompts/promptUtils.d.ts +6 -4
- package/lib/prompts/promptUtils.js +3 -1
- package/lib/ui/SpinniesManager.d.ts +1 -1
- package/lib/ui/index.d.ts +3 -2
- package/lib/ui/index.js +11 -5
- package/lib/ui/spinniesUtils.d.ts +5 -5
- package/package.json +8 -7
- package/types/ProjectComponents.d.ts +0 -15
- package/types/Prompts.d.ts +2 -2
- package/types/Yargs.d.ts +10 -0
- package/lib/npm.d.ts +0 -9
- package/lib/npm.js +0 -36
package/api/migrate.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { HubSpotPromise } from '@hubspot/local-dev-lib/types/Http';
|
|
2
|
+
import { UNMIGRATABLE_REASONS } from '@hubspot/local-dev-lib/constants/projects';
|
|
3
|
+
import { MIGRATION_STATUS } from '@hubspot/local-dev-lib/types/Migration';
|
|
4
|
+
interface BaseMigrationApp {
|
|
5
|
+
appId: number;
|
|
6
|
+
appName: string;
|
|
7
|
+
isMigratable: boolean;
|
|
8
|
+
migrationComponents: ListAppsMigrationComponent[];
|
|
9
|
+
projectName?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MigratableApp extends BaseMigrationApp {
|
|
12
|
+
isMigratable: true;
|
|
13
|
+
}
|
|
14
|
+
export interface UnmigratableApp extends BaseMigrationApp {
|
|
15
|
+
isMigratable: false;
|
|
16
|
+
unmigratableReason: keyof typeof UNMIGRATABLE_REASONS;
|
|
17
|
+
}
|
|
18
|
+
export type MigrationApp = MigratableApp | UnmigratableApp;
|
|
19
|
+
export interface ListAppsResponse {
|
|
20
|
+
migratableApps: MigratableApp[];
|
|
21
|
+
unmigratableApps: UnmigratableApp[];
|
|
22
|
+
}
|
|
23
|
+
export interface InitializeMigrationResponse {
|
|
24
|
+
migrationId: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ListAppsMigrationComponent {
|
|
27
|
+
id: string;
|
|
28
|
+
componentType: string;
|
|
29
|
+
isSupported: boolean;
|
|
30
|
+
}
|
|
31
|
+
export type ContinueMigrationResponse = {
|
|
32
|
+
migrationId: number;
|
|
33
|
+
};
|
|
34
|
+
export interface MigrationBaseStatus {
|
|
35
|
+
id: number;
|
|
36
|
+
}
|
|
37
|
+
export interface MigrationInProgress extends MigrationBaseStatus {
|
|
38
|
+
status: typeof MIGRATION_STATUS.IN_PROGRESS;
|
|
39
|
+
}
|
|
40
|
+
export interface MigrationInputRequired extends MigrationBaseStatus {
|
|
41
|
+
status: typeof MIGRATION_STATUS.INPUT_REQUIRED;
|
|
42
|
+
componentsRequiringUids: Record<string, {
|
|
43
|
+
componentType: string;
|
|
44
|
+
componentHint: string;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
export interface MigrationSuccess extends MigrationBaseStatus {
|
|
48
|
+
status: typeof MIGRATION_STATUS.SUCCESS;
|
|
49
|
+
buildId: number;
|
|
50
|
+
}
|
|
51
|
+
export interface MigrationFailed extends MigrationBaseStatus {
|
|
52
|
+
status: typeof MIGRATION_STATUS.FAILURE;
|
|
53
|
+
projectErrorsDetail?: string;
|
|
54
|
+
componentErrorDetails: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
export type MigrationStatus = MigrationInProgress | MigrationInputRequired | MigrationSuccess | MigrationFailed;
|
|
57
|
+
export declare function listAppsForMigration(accountId: number): HubSpotPromise<ListAppsResponse>;
|
|
58
|
+
export declare function initializeMigration(accountId: number, applicationId: number, platformVersion: string): HubSpotPromise<InitializeMigrationResponse>;
|
|
59
|
+
export declare function continueMigration(portalId: number, migrationId: number, componentUids: Record<string, string>, projectName: string): HubSpotPromise<ContinueMigrationResponse>;
|
|
60
|
+
export declare function checkMigrationStatusV2(accountId: number, id: number): HubSpotPromise<MigrationStatus>;
|
|
61
|
+
export {};
|
package/api/migrate.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listAppsForMigration = listAppsForMigration;
|
|
4
|
+
exports.initializeMigration = initializeMigration;
|
|
5
|
+
exports.continueMigration = continueMigration;
|
|
6
|
+
exports.checkMigrationStatusV2 = checkMigrationStatusV2;
|
|
7
|
+
const projects_1 = require("@hubspot/local-dev-lib/constants/projects");
|
|
8
|
+
const http_1 = require("@hubspot/local-dev-lib/http");
|
|
9
|
+
const MIGRATIONS_API_PATH_V2 = 'dfs/migrations/v2';
|
|
10
|
+
async function listAppsForMigration(accountId) {
|
|
11
|
+
return http_1.http.get(accountId, {
|
|
12
|
+
url: `${MIGRATIONS_API_PATH_V2}/list-apps`,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function mapPlatformVersionToEnum(platformVersion) {
|
|
16
|
+
if (platformVersion === projects_1.PLATFORM_VERSIONS.unstable) {
|
|
17
|
+
return projects_1.PLATFORM_VERSIONS.unstable.toUpperCase();
|
|
18
|
+
}
|
|
19
|
+
return `V${platformVersion.replace('.', '_')}`;
|
|
20
|
+
}
|
|
21
|
+
async function initializeMigration(accountId, applicationId, platformVersion) {
|
|
22
|
+
return http_1.http.post(accountId, {
|
|
23
|
+
url: `${MIGRATIONS_API_PATH_V2}/migrations`,
|
|
24
|
+
data: {
|
|
25
|
+
applicationId,
|
|
26
|
+
platformVersion: mapPlatformVersionToEnum(platformVersion),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function continueMigration(portalId, migrationId, componentUids, projectName) {
|
|
31
|
+
return http_1.http.post(portalId, {
|
|
32
|
+
url: `${MIGRATIONS_API_PATH_V2}/migrations/continue`,
|
|
33
|
+
data: {
|
|
34
|
+
migrationId,
|
|
35
|
+
projectName,
|
|
36
|
+
componentUids,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function checkMigrationStatusV2(accountId, id) {
|
|
41
|
+
return http_1.http.get(accountId, {
|
|
42
|
+
url: `${MIGRATIONS_API_PATH_V2}/migrations/${id}/status`,
|
|
43
|
+
});
|
|
44
|
+
}
|
package/bin/cli.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
const yargs = require('yargs');
|
|
4
|
-
const updateNotifier = require('update-notifier');
|
|
5
|
-
const chalk = require('chalk');
|
|
6
4
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
7
|
-
const { addUserAgentHeader } = require('@hubspot/local-dev-lib/http');
|
|
8
|
-
const { loadConfig, getAccountId, configFileExists, getConfigPath, validateConfig, } = require('@hubspot/local-dev-lib/config');
|
|
9
5
|
const { logError } = require('../lib/errorHandlers/index');
|
|
10
6
|
const { setLogLevel, getCommandName } = require('../lib/commonOpts');
|
|
11
|
-
const { validateAccount } = require('../lib/validation');
|
|
12
7
|
const { trackHelpUsage, trackConvertFieldsUsage, } = require('../lib/usageTracking');
|
|
13
|
-
const { getIsInProject } = require('../lib/projects');
|
|
14
|
-
const pkg = require('../package.json');
|
|
15
|
-
const { i18n } = require('../lib/lang');
|
|
16
8
|
const { EXIT_CODES } = require('../lib/enums/exitCodes');
|
|
17
|
-
const {
|
|
18
|
-
const {
|
|
19
|
-
const
|
|
20
|
-
const {
|
|
9
|
+
const { loadConfigMiddleware, injectAccountIdMiddleware, validateAccountOptions, handleDeprecatedEnvVariables, } = require('../lib/middleware/configMiddleware');
|
|
10
|
+
const { notifyAboutUpdates, } = require('../lib/middleware/notificationsMiddleware');
|
|
11
|
+
const { checkAndWarnGitInclusionMiddleware, } = require('../lib/middleware/gitMiddleware');
|
|
12
|
+
const { performChecks } = require('../lib/middleware/yargsChecksMiddleware');
|
|
13
|
+
const { setRequestHeaders } = require('../lib/middleware/requestMiddleware');
|
|
14
|
+
const { checkFireAlarms } = require('../lib/middleware/fireAlarmMiddleware');
|
|
21
15
|
const removeCommand = require('../commands/remove');
|
|
22
16
|
const initCommand = require('../commands/init');
|
|
23
17
|
const logsCommand = require('../commands/logs');
|
|
@@ -45,36 +39,8 @@ const cmsCommand = require('../commands/cms');
|
|
|
45
39
|
const feedbackCommand = require('../commands/feedback');
|
|
46
40
|
const doctorCommand = require('../commands/doctor');
|
|
47
41
|
const completionCommand = require('../commands/completion');
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
distTag: 'latest',
|
|
51
|
-
shouldNotifyInNpmScript: true,
|
|
52
|
-
});
|
|
53
|
-
const i18nKey = 'commands.generalErrors';
|
|
54
|
-
const CMS_CLI_PACKAGE_NAME = '@hubspot/cms-cli';
|
|
55
|
-
const showUpdateNotification = () => {
|
|
56
|
-
notifier.notify({
|
|
57
|
-
message: pkg.name === CMS_CLI_PACKAGE_NAME
|
|
58
|
-
? i18n(`${i18nKey}.updateNotify.cmsUpdateNotification`, {
|
|
59
|
-
packageName: CMS_CLI_PACKAGE_NAME,
|
|
60
|
-
updateCommand: uiCommandReference('{updateCommand}'),
|
|
61
|
-
})
|
|
62
|
-
: i18n(`${i18nKey}.updateNotify.cliUpdateNotification`, {
|
|
63
|
-
updateCommand: uiCommandReference('{updateCommand}'),
|
|
64
|
-
}),
|
|
65
|
-
defer: false,
|
|
66
|
-
boxenOptions: {
|
|
67
|
-
borderColor: UI_COLORS.MARIGOLD_DARK,
|
|
68
|
-
margin: 1,
|
|
69
|
-
padding: 1,
|
|
70
|
-
textAlignment: 'center',
|
|
71
|
-
borderStyle: 'round',
|
|
72
|
-
title: pkg.name === CMS_CLI_PACKAGE_NAME
|
|
73
|
-
? null
|
|
74
|
-
: chalk.bold(i18n(`${i18nKey}.updateNotify.notifyTitle`)),
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
};
|
|
42
|
+
const appCommand = require('../commands/app');
|
|
43
|
+
notifyAboutUpdates();
|
|
78
44
|
const getTerminalWidth = () => {
|
|
79
45
|
const width = yargs.terminalWidth();
|
|
80
46
|
if (width >= 100)
|
|
@@ -96,216 +62,18 @@ const handleFailure = (msg, err, yargs) => {
|
|
|
96
62
|
process.exit(EXIT_CODES.ERROR);
|
|
97
63
|
}
|
|
98
64
|
};
|
|
99
|
-
const performChecks = argv => {
|
|
100
|
-
// "hs config set default-account" has moved to "hs accounts use"
|
|
101
|
-
if (argv._[0] === 'config' &&
|
|
102
|
-
argv._[1] === 'set' &&
|
|
103
|
-
argv._[2] === 'default-account') {
|
|
104
|
-
logger.error(i18n(`${i18nKey}.setDefaultAccountMoved`));
|
|
105
|
-
process.exit(EXIT_CODES.ERROR);
|
|
106
|
-
}
|
|
107
|
-
// Require "project" command when running upload/watch inside of a project
|
|
108
|
-
if (argv._.length === 1 && ['upload', 'watch'].includes(argv._[0])) {
|
|
109
|
-
if (getIsInProject(argv.src)) {
|
|
110
|
-
logger.error(i18n(`${i18nKey}.srcIsProject`, {
|
|
111
|
-
src: argv.src || './',
|
|
112
|
-
command: argv._.join(' '),
|
|
113
|
-
}));
|
|
114
|
-
process.exit(EXIT_CODES.ERROR);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const setRequestHeaders = () => {
|
|
125
|
-
addUserAgentHeader('HubSpot CLI', pkg.version);
|
|
126
|
-
};
|
|
127
|
-
const updateCLIVersion = async () => {
|
|
128
|
-
logger.debug('Checking for CLI updates', notifier);
|
|
129
|
-
if (!process.env.SKIP_HUBSPOT_CLI_AUTO_UPDATES &&
|
|
130
|
-
notifier &&
|
|
131
|
-
notifier.update) {
|
|
132
|
-
let updateInfo;
|
|
133
|
-
try {
|
|
134
|
-
updateInfo = await notifier.fetchInfo();
|
|
135
|
-
}
|
|
136
|
-
catch (e) {
|
|
137
|
-
logger.debug('Error fetching update info', e);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
// Update if the current version is not the latest version.
|
|
141
|
-
// Don't auto-update if the current version is a pre-release
|
|
142
|
-
// or if this would be a major version update
|
|
143
|
-
if (!updateInfo.current.includes('-') &&
|
|
144
|
-
!['major', 'latest'].includes(updateInfo.type)) {
|
|
145
|
-
SpinniesManager.init({
|
|
146
|
-
succeedColor: 'white',
|
|
147
|
-
});
|
|
148
|
-
SpinniesManager.add('cliAutoUpdate', {
|
|
149
|
-
text: `New HubSpot CLI version available. Updating to version ${updateInfo.latest}`,
|
|
150
|
-
});
|
|
151
|
-
let showManualInstallHelp = false;
|
|
152
|
-
try {
|
|
153
|
-
if (await isGloballyInstalled()) {
|
|
154
|
-
await executeInstall(['@hubspot/cli@latest'], '-g');
|
|
155
|
-
SpinniesManager.succeed('cliAutoUpdate', {
|
|
156
|
-
text: `Successfully updated HubSpot CLI to version ${updateInfo.latest}`,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
SpinniesManager.fail('cliAutoUpdate', {
|
|
161
|
-
text: `Cannot auto-update the HubSpot CLI if it is not globall installed with NPM`,
|
|
162
|
-
});
|
|
163
|
-
showManualInstallHelp = true;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
catch (e) {
|
|
167
|
-
logger.debug('Error updating CLI', e);
|
|
168
|
-
SpinniesManager.fail('cliAutoUpdate', {
|
|
169
|
-
text: `Failed to update HubSpot CLI to version ${updateInfo.latest}`,
|
|
170
|
-
});
|
|
171
|
-
showManualInstallHelp = true;
|
|
172
|
-
}
|
|
173
|
-
if (showManualInstallHelp) {
|
|
174
|
-
showUpdateNotification();
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
const isTargetedCommand = (options, commandMap) => {
|
|
180
|
-
const checkCommand = (options, commandMap) => {
|
|
181
|
-
const currentCommand = options._[0];
|
|
182
|
-
if (!commandMap[currentCommand]) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
if (commandMap[currentCommand].target) {
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
188
|
-
const subCommands = commandMap[currentCommand].subCommands || {};
|
|
189
|
-
if (options._.length > 1) {
|
|
190
|
-
return checkCommand({ _: options._.slice(1) }, subCommands);
|
|
191
|
-
}
|
|
192
|
-
return false;
|
|
193
|
-
};
|
|
194
|
-
return checkCommand(options, commandMap);
|
|
195
|
-
};
|
|
196
|
-
const SKIP_CONFIG_VALIDATION = {
|
|
197
|
-
init: { target: true },
|
|
198
|
-
auth: { target: true },
|
|
199
|
-
};
|
|
200
|
-
const handleDeprecatedEnvVariables = options => {
|
|
201
|
-
// HUBSPOT_PORTAL_ID is deprecated, but we'll still support it for now
|
|
202
|
-
// The HubSpot GH Deploy Action still uses HUBSPOT_PORTAL_ID
|
|
203
|
-
if (options.useEnv &&
|
|
204
|
-
process.env.HUBSPOT_PORTAL_ID &&
|
|
205
|
-
!process.env.HUBSPOT_ACCOUNT_ID) {
|
|
206
|
-
uiDeprecatedTag(i18n(`${i18nKey}.handleDeprecatedEnvVariables.portalEnvVarDeprecated`, {
|
|
207
|
-
configPath: getConfigPath(),
|
|
208
|
-
}));
|
|
209
|
-
process.env.HUBSPOT_ACCOUNT_ID = process.env.HUBSPOT_PORTAL_ID;
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
/**
|
|
213
|
-
* Auto-injects the derivedAccountId flag into all commands
|
|
214
|
-
*/
|
|
215
|
-
const injectAccountIdMiddleware = async (options) => {
|
|
216
|
-
const { account } = options;
|
|
217
|
-
// Preserves the original --account flag for certain commands.
|
|
218
|
-
options.providedAccountId = account;
|
|
219
|
-
if (options.useEnv && process.env.HUBSPOT_ACCOUNT_ID) {
|
|
220
|
-
options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10);
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
options.derivedAccountId = getAccountId(account);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
const loadConfigMiddleware = async (options) => {
|
|
227
|
-
// Skip this when no command is provided
|
|
228
|
-
if (!options._.length) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const maybeValidateConfig = () => {
|
|
232
|
-
if (!isTargetedCommand(options, SKIP_CONFIG_VALIDATION) &&
|
|
233
|
-
!validateConfig()) {
|
|
234
|
-
process.exit(EXIT_CODES.ERROR);
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
if (configFileExists(true) && options.config) {
|
|
238
|
-
logger.error(i18n(`${i18nKey}.loadConfigMiddleware.configFileExists`, {
|
|
239
|
-
configPath: getConfigPath(),
|
|
240
|
-
}));
|
|
241
|
-
process.exit(EXIT_CODES.ERROR);
|
|
242
|
-
}
|
|
243
|
-
else if (!isTargetedCommand(options, { init: { target: true } })) {
|
|
244
|
-
const { config: configPath } = options;
|
|
245
|
-
const config = loadConfig(configPath, options);
|
|
246
|
-
// We don't run validateConfig() for auth because users should be able to run it when
|
|
247
|
-
// no accounts are configured, but we still want to exit if the config file is not found
|
|
248
|
-
if (isTargetedCommand(options, { auth: { target: true } }) && !config) {
|
|
249
|
-
process.exit(EXIT_CODES.ERROR);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
maybeValidateConfig();
|
|
253
|
-
};
|
|
254
|
-
const checkAndWarnGitInclusionMiddleware = options => {
|
|
255
|
-
// Skip this when no command is provided
|
|
256
|
-
if (!options._.length) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
checkAndWarnGitInclusion(getConfigPath());
|
|
260
|
-
};
|
|
261
|
-
const accountsSubCommands = {
|
|
262
|
-
target: false,
|
|
263
|
-
subCommands: {
|
|
264
|
-
clean: { target: true },
|
|
265
|
-
list: { target: true },
|
|
266
|
-
ls: { target: true },
|
|
267
|
-
remove: { target: true },
|
|
268
|
-
},
|
|
269
|
-
};
|
|
270
|
-
const sandboxesSubCommands = {
|
|
271
|
-
target: false,
|
|
272
|
-
subCommands: {
|
|
273
|
-
delete: { target: true },
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
const SKIP_ACCOUNT_VALIDATION = {
|
|
277
|
-
init: { target: true },
|
|
278
|
-
auth: { target: true },
|
|
279
|
-
account: accountsSubCommands,
|
|
280
|
-
accounts: accountsSubCommands,
|
|
281
|
-
sandbox: sandboxesSubCommands,
|
|
282
|
-
sandboxes: sandboxesSubCommands,
|
|
283
|
-
};
|
|
284
|
-
const validateAccountOptions = async (options) => {
|
|
285
|
-
// Skip this when no command is provided
|
|
286
|
-
if (!options._.length) {
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
let validAccount = true;
|
|
290
|
-
if (!isTargetedCommand(options, SKIP_ACCOUNT_VALIDATION)) {
|
|
291
|
-
validAccount = await validateAccount(options);
|
|
292
|
-
}
|
|
293
|
-
if (!validAccount) {
|
|
294
|
-
process.exit(EXIT_CODES.ERROR);
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
65
|
const argv = yargs
|
|
298
66
|
.usage('The command line interface to interact with HubSpot.')
|
|
299
67
|
// loadConfigMiddleware loads the new hidden config for all commands
|
|
300
68
|
.middleware([
|
|
301
69
|
setLogLevel,
|
|
302
|
-
updateCLIVersion,
|
|
303
70
|
setRequestHeaders,
|
|
304
71
|
handleDeprecatedEnvVariables,
|
|
305
72
|
loadConfigMiddleware,
|
|
306
73
|
injectAccountIdMiddleware,
|
|
307
74
|
checkAndWarnGitInclusionMiddleware,
|
|
308
75
|
validateAccountOptions,
|
|
76
|
+
checkFireAlarms,
|
|
309
77
|
])
|
|
310
78
|
.exitProcess(false)
|
|
311
79
|
.fail(handleFailure)
|
|
@@ -352,6 +120,7 @@ const argv = yargs
|
|
|
352
120
|
.command(feedbackCommand)
|
|
353
121
|
.command(doctorCommand)
|
|
354
122
|
.command(completionCommand)
|
|
123
|
+
.command(appCommand)
|
|
355
124
|
.help()
|
|
356
125
|
.alias('h', 'help')
|
|
357
126
|
.recommendCommands()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Argv, ArgumentsCamelCase } from 'yargs';
|
|
2
|
+
import { CommonArgs, ConfigArgs } from '../../types/Yargs';
|
|
3
|
+
export declare const describe: string;
|
|
4
|
+
export declare const command = "auth";
|
|
5
|
+
type AccountAuthArgs = CommonArgs & ConfigArgs & {
|
|
6
|
+
disableTracking?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function handler(args: ArgumentsCamelCase<AccountAuthArgs>): Promise<void>;
|
|
9
|
+
export declare function builder(yargs: Argv): Argv<AccountAuthArgs>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = exports.describe = void 0;
|
|
4
|
+
exports.handler = handler;
|
|
5
|
+
exports.builder = builder;
|
|
6
|
+
const config_1 = require("@hubspot/local-dev-lib/config");
|
|
7
|
+
const migrate_1 = require("@hubspot/local-dev-lib/config/migrate");
|
|
8
|
+
const getAccountIdentifier_1 = require("@hubspot/local-dev-lib/config/getAccountIdentifier");
|
|
9
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
10
|
+
const personalAccessKey_1 = require("@hubspot/local-dev-lib/personalAccessKey");
|
|
11
|
+
const environments_1 = require("@hubspot/local-dev-lib/constants/environments");
|
|
12
|
+
const text_1 = require("@hubspot/local-dev-lib/text");
|
|
13
|
+
const auth_1 = require("@hubspot/local-dev-lib/constants/auth");
|
|
14
|
+
const commonOpts_1 = require("../../lib/commonOpts");
|
|
15
|
+
const configMigrate_1 = require("../../lib/configMigrate");
|
|
16
|
+
const process_1 = require("../../lib/process");
|
|
17
|
+
const index_1 = require("../../lib/errorHandlers/index");
|
|
18
|
+
const lang_1 = require("../../lib/lang");
|
|
19
|
+
const usageTracking_1 = require("../../lib/usageTracking");
|
|
20
|
+
const personalAccessKeyPrompt_1 = require("../../lib/prompts/personalAccessKeyPrompt");
|
|
21
|
+
const accountNamePrompt_1 = require("../../lib/prompts/accountNamePrompt");
|
|
22
|
+
const setAsDefaultAccountPrompt_1 = require("../../lib/prompts/setAsDefaultAccountPrompt");
|
|
23
|
+
const index_2 = require("../../lib/errorHandlers/index");
|
|
24
|
+
const usageTracking_2 = require("../../lib/usageTracking");
|
|
25
|
+
const exitCodes_1 = require("../../lib/enums/exitCodes");
|
|
26
|
+
const ui_1 = require("../../lib/ui");
|
|
27
|
+
const TRACKING_STATUS = {
|
|
28
|
+
STARTED: 'started',
|
|
29
|
+
ERROR: 'error',
|
|
30
|
+
COMPLETE: 'complete',
|
|
31
|
+
};
|
|
32
|
+
async function updateConfig(env, doesConfigExist, disableTracking, authType, account) {
|
|
33
|
+
try {
|
|
34
|
+
const { personalAccessKey } = await (0, personalAccessKeyPrompt_1.personalAccessKeyPrompt)({
|
|
35
|
+
env,
|
|
36
|
+
account,
|
|
37
|
+
});
|
|
38
|
+
const token = await (0, personalAccessKey_1.getAccessToken)(personalAccessKey, env);
|
|
39
|
+
const defaultName = token.hubName ? (0, text_1.toKebabCase)(token.hubName) : undefined;
|
|
40
|
+
const name = doesConfigExist
|
|
41
|
+
? undefined
|
|
42
|
+
: (await (0, accountNamePrompt_1.cliAccountNamePrompt)(defaultName)).name;
|
|
43
|
+
const updatedConfig = await (0, personalAccessKey_1.updateConfigWithAccessToken)(token, personalAccessKey, env, name, !doesConfigExist);
|
|
44
|
+
if (!updatedConfig)
|
|
45
|
+
return null;
|
|
46
|
+
if (doesConfigExist && !updatedConfig.name) {
|
|
47
|
+
updatedConfig.name = (await (0, accountNamePrompt_1.cliAccountNamePrompt)(defaultName)).name;
|
|
48
|
+
(0, config_1.updateAccountConfig)({
|
|
49
|
+
...updatedConfig,
|
|
50
|
+
});
|
|
51
|
+
(0, config_1.writeConfig)();
|
|
52
|
+
}
|
|
53
|
+
return updatedConfig;
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
if (!disableTracking) {
|
|
57
|
+
await (0, usageTracking_1.trackAuthAction)('account-auth', authType, TRACKING_STATUS.ERROR);
|
|
58
|
+
}
|
|
59
|
+
(0, index_1.debugError)(e);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.describe = (0, lang_1.i18n)('commands.account.subcommands.auth.describe');
|
|
64
|
+
exports.command = 'auth';
|
|
65
|
+
async function handler(args) {
|
|
66
|
+
const { providedAccountId, disableTracking } = args;
|
|
67
|
+
const authType = auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value;
|
|
68
|
+
const deprecatedConfigExists = (0, migrate_1.configFileExists)(false);
|
|
69
|
+
const globalConfigExists = (0, migrate_1.configFileExists)(true);
|
|
70
|
+
if (deprecatedConfigExists) {
|
|
71
|
+
if (globalConfigExists) {
|
|
72
|
+
try {
|
|
73
|
+
await (0, configMigrate_1.handleMerge)(providedAccountId);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
(0, index_2.logError)(error);
|
|
77
|
+
(0, usageTracking_2.trackCommandMetadataUsage)('account-auth', {
|
|
78
|
+
command: 'hs account auth',
|
|
79
|
+
type: 'Merge configs',
|
|
80
|
+
successful: false,
|
|
81
|
+
}, providedAccountId);
|
|
82
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
try {
|
|
87
|
+
await (0, configMigrate_1.handleMigration)(providedAccountId);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
(0, index_2.logError)(error);
|
|
91
|
+
(0, usageTracking_2.trackCommandMetadataUsage)('account-auth', {
|
|
92
|
+
command: 'hs account auth',
|
|
93
|
+
type: 'Migrate a single config',
|
|
94
|
+
successful: false,
|
|
95
|
+
}, providedAccountId);
|
|
96
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!disableTracking) {
|
|
101
|
+
(0, usageTracking_1.trackCommandUsage)('account-auth', {}, providedAccountId);
|
|
102
|
+
await (0, usageTracking_1.trackAuthAction)('account-auth', authType, TRACKING_STATUS.STARTED);
|
|
103
|
+
}
|
|
104
|
+
const env = args.qa ? environments_1.ENVIRONMENTS.QA : environments_1.ENVIRONMENTS.PROD;
|
|
105
|
+
const configAlreadyExists = (0, migrate_1.configFileExists)(true);
|
|
106
|
+
if (!configAlreadyExists) {
|
|
107
|
+
(0, config_1.createEmptyConfigFile)({}, true);
|
|
108
|
+
}
|
|
109
|
+
(0, config_1.loadConfig)('');
|
|
110
|
+
(0, process_1.handleExit)(config_1.deleteEmptyConfigFile);
|
|
111
|
+
const updatedConfig = await updateConfig(env, configAlreadyExists, disableTracking, authType, providedAccountId);
|
|
112
|
+
if (!updatedConfig) {
|
|
113
|
+
logger_1.logger.error((0, lang_1.i18n)('commands.account.subcommands.auth.errors.failedToUpdateConfig'));
|
|
114
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
115
|
+
}
|
|
116
|
+
const { name } = updatedConfig;
|
|
117
|
+
const accountId = (0, getAccountIdentifier_1.getAccountIdentifier)(updatedConfig);
|
|
118
|
+
// If the config file was just created, we don't need to prompt the user to set as default
|
|
119
|
+
if (!configAlreadyExists) {
|
|
120
|
+
logger_1.logger.log('');
|
|
121
|
+
logger_1.logger.success((0, lang_1.i18n)('commands.account.subcommands.auth.success.configFileCreated', {
|
|
122
|
+
configPath: (0, config_1.getConfigPath)('', true),
|
|
123
|
+
}));
|
|
124
|
+
logger_1.logger.success((0, lang_1.i18n)('commands.account.subcommands.auth.success.configFileUpdated', {
|
|
125
|
+
account: name || accountId || '',
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
const setAsDefault = await (0, setAsDefaultAccountPrompt_1.setAsDefaultAccountPrompt)(name);
|
|
130
|
+
logger_1.logger.log('');
|
|
131
|
+
if (setAsDefault) {
|
|
132
|
+
logger_1.logger.success((0, lang_1.i18n)(`lib.prompts.setAsDefaultAccountPrompt.setAsDefaultAccount`, {
|
|
133
|
+
accountName: name,
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
logger_1.logger.info((0, lang_1.i18n)(`lib.prompts.setAsDefaultAccountPrompt.keepingCurrentDefault`, {
|
|
138
|
+
accountName: (0, config_1.getConfigDefaultAccount)(),
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
(0, ui_1.uiFeatureHighlight)([
|
|
143
|
+
'helpCommand',
|
|
144
|
+
'accountAuthCommand',
|
|
145
|
+
'accountsListCommand',
|
|
146
|
+
]);
|
|
147
|
+
if (!disableTracking) {
|
|
148
|
+
await (0, usageTracking_1.trackAuthAction)('account-auth', authType, TRACKING_STATUS.COMPLETE, accountId);
|
|
149
|
+
}
|
|
150
|
+
process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
151
|
+
}
|
|
152
|
+
function builder(yargs) {
|
|
153
|
+
yargs.options({
|
|
154
|
+
account: {
|
|
155
|
+
describe: (0, lang_1.i18n)('commands.account.subcommands.auth.options.account.describe'),
|
|
156
|
+
type: 'string',
|
|
157
|
+
alias: 'a',
|
|
158
|
+
},
|
|
159
|
+
'disable-tracking': {
|
|
160
|
+
type: 'boolean',
|
|
161
|
+
hidden: true,
|
|
162
|
+
default: false,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
(0, commonOpts_1.addTestingOptions)(yargs);
|
|
166
|
+
(0, commonOpts_1.addGlobalOptions)(yargs);
|
|
167
|
+
return yargs;
|
|
168
|
+
}
|