@hubspot/cli 7.4.2-experimental.0 → 7.4.2
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 +62 -0
- package/api/migrate.js +61 -0
- package/bin/cli.js +8 -183
- package/commands/account/auth.d.ts +10 -0
- package/commands/account/auth.js +168 -0
- package/commands/account/clean.js +38 -5
- package/commands/account/createOverride.d.ts +10 -0
- package/commands/account/createOverride.js +104 -0
- package/commands/account/info.js +38 -4
- package/commands/account/list.js +23 -5
- package/commands/account/remove.js +36 -2
- package/commands/account/removeOverride.d.ts +10 -0
- package/commands/account/removeOverride.js +76 -0
- package/commands/account/use.js +25 -3
- package/commands/account.js +7 -2
- package/commands/app/migrate.d.ts +4 -4
- package/commands/app/migrate.js +10 -4
- package/commands/auth.js +6 -2
- package/commands/cms/lighthouseScore.js +6 -2
- 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 -29
- package/commands/config.d.ts +4 -1
- package/commands/config.js +45 -11
- package/commands/create/api-sample.js +3 -1
- package/commands/customObject/schema/delete.js +4 -1
- package/commands/customObject/schema/fetch-all.js +2 -1
- package/commands/customObject/schema/fetch.js +2 -1
- package/commands/init.js +9 -10
- package/commands/project/cloneApp.d.ts +5 -1
- package/commands/project/cloneApp.js +1 -1
- package/commands/project/dev/index.js +1 -1
- package/commands/project/installDeps.d.ts +9 -1
- package/commands/project/installDeps.js +43 -30
- package/commands/project/logs.d.ts +13 -1
- package/commands/project/logs.js +69 -62
- package/commands/project/migrate.d.ts +11 -0
- package/commands/project/migrate.js +54 -0
- package/commands/project/migrateApp.d.ts +4 -4
- package/commands/project/upload.d.ts +12 -0
- package/commands/project/upload.js +62 -49
- package/commands/project/watch.js +12 -0
- package/commands/project.js +2 -0
- package/lang/en.d.ts +2840 -0
- package/lang/en.js +2647 -3301
- package/lang/en.lyaml +100 -40
- package/lib/app/migrate.d.ts +10 -6
- package/lib/app/migrate.js +157 -232
- package/lib/app/migrate_legacy.d.ts +4 -0
- package/lib/app/migrate_legacy.js +131 -0
- package/lib/configMigrate.d.ts +2 -0
- package/lib/configMigrate.js +104 -0
- 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 +18 -0
- 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 +116 -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/projects/ProjectLogsManager.d.ts +1 -1
- package/lib/projects/ProjectLogsManager.js +1 -1
- package/lib/projects/index.d.ts +4 -3
- package/lib/projects/upload.d.ts +1 -1
- package/lib/ui/SpinniesManager.d.ts +1 -1
- package/lib/ui/index.d.ts +1 -0
- package/lib/ui/index.js +5 -0
- package/lib/ui/spinniesUtils.d.ts +5 -5
- package/package.json +7 -6
- package/types/Yargs.d.ts +0 -10
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleMigration = handleMigration;
|
|
4
|
+
exports.handleMerge = handleMerge;
|
|
5
|
+
const migrate_1 = require("@hubspot/local-dev-lib/config/migrate");
|
|
6
|
+
const config_1 = require("@hubspot/local-dev-lib/constants/config");
|
|
7
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
8
|
+
const promptUtils_1 = require("./prompts/promptUtils");
|
|
9
|
+
const lang_1 = require("./lang");
|
|
10
|
+
const usageTracking_1 = require("./usageTracking");
|
|
11
|
+
async function handleMigration(accountId, configPath) {
|
|
12
|
+
const { shouldMigrateConfig } = await (0, promptUtils_1.promptUser)({
|
|
13
|
+
name: 'shouldMigrateConfig',
|
|
14
|
+
type: 'confirm',
|
|
15
|
+
message: (0, lang_1.i18n)('lib.configMigrate.migrateConfigPrompt', {
|
|
16
|
+
deprecatedConfigPath: (0, migrate_1.getConfigPath)(configPath, false) ||
|
|
17
|
+
config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
18
|
+
globalConfigPath: config_1.GLOBAL_CONFIG_PATH,
|
|
19
|
+
}),
|
|
20
|
+
});
|
|
21
|
+
if (!shouldMigrateConfig) {
|
|
22
|
+
(0, usageTracking_1.trackCommandMetadataUsage)('config-migrate', {
|
|
23
|
+
command: 'hs config migrate',
|
|
24
|
+
type: 'migration',
|
|
25
|
+
step: 'Reject migration via prompt',
|
|
26
|
+
}, accountId);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const deprecatedConfig = (0, migrate_1.getDeprecatedConfig)(configPath);
|
|
30
|
+
(0, migrate_1.migrateConfig)(deprecatedConfig);
|
|
31
|
+
(0, usageTracking_1.trackCommandMetadataUsage)('config-migrate', {
|
|
32
|
+
command: 'hs config migrate',
|
|
33
|
+
type: 'migration',
|
|
34
|
+
step: 'Confirm migration via prompt',
|
|
35
|
+
successful: true,
|
|
36
|
+
}, accountId);
|
|
37
|
+
logger_1.logger.success((0, lang_1.i18n)('lib.configMigrate.migrationSuccess', {
|
|
38
|
+
globalConfigPath: config_1.GLOBAL_CONFIG_PATH,
|
|
39
|
+
}));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
async function mergeConfigProperties(globalConfig, deprecatedConfig, force) {
|
|
43
|
+
const { initialConfig, conflicts, } = (0, migrate_1.mergeConfigProperties)(globalConfig, deprecatedConfig, force);
|
|
44
|
+
if (conflicts.length > 0) {
|
|
45
|
+
for (const conflict of conflicts) {
|
|
46
|
+
const { property, newValue, oldValue } = conflict;
|
|
47
|
+
const { shouldOverwrite } = await (0, promptUtils_1.promptUser)({
|
|
48
|
+
name: 'shouldOverwrite',
|
|
49
|
+
type: 'confirm',
|
|
50
|
+
message: (0, lang_1.i18n)('lib.configMigrate.mergeConfigConflictPrompt', {
|
|
51
|
+
property,
|
|
52
|
+
oldValue: `${oldValue}`,
|
|
53
|
+
newValue: `${newValue}`,
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
if (shouldOverwrite) {
|
|
57
|
+
// @ts-expect-error Cannot reconcile CLIConfig_NEW and CLIConfig_DEPRECATED
|
|
58
|
+
initialConfig[property] = oldValue;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return initialConfig;
|
|
63
|
+
}
|
|
64
|
+
async function handleMerge(accountId, configPath, force) {
|
|
65
|
+
const { shouldMergeConfigs } = await (0, promptUtils_1.promptUser)({
|
|
66
|
+
name: 'shouldMergeConfigs',
|
|
67
|
+
type: 'confirm',
|
|
68
|
+
message: (0, lang_1.i18n)('lib.configMigrate.mergeConfigsPrompt', {
|
|
69
|
+
deprecatedConfigPath: (0, migrate_1.getConfigPath)(configPath, false) ||
|
|
70
|
+
config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
71
|
+
globalConfigPath: config_1.GLOBAL_CONFIG_PATH,
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
if (!shouldMergeConfigs) {
|
|
75
|
+
(0, usageTracking_1.trackCommandMetadataUsage)('config-migrate', {
|
|
76
|
+
command: 'hs config migrate',
|
|
77
|
+
type: 'merge',
|
|
78
|
+
step: 'Reject merge via prompt',
|
|
79
|
+
}, accountId);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const deprecatedConfig = (0, migrate_1.getDeprecatedConfig)(configPath);
|
|
83
|
+
const globalConfig = (0, migrate_1.getGlobalConfig)();
|
|
84
|
+
if (!deprecatedConfig || !globalConfig) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const mergedConfig = await mergeConfigProperties(globalConfig, deprecatedConfig, force);
|
|
88
|
+
const { skippedAccountIds } = (0, migrate_1.mergeExistingConfigs)(mergedConfig, deprecatedConfig);
|
|
89
|
+
if (skippedAccountIds.length > 0) {
|
|
90
|
+
logger_1.logger.log((0, lang_1.i18n)('lib.configMigrate.skippedExistingAccounts', {
|
|
91
|
+
skippedAccountIds: skippedAccountIds.join(', '),
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
logger_1.logger.success((0, lang_1.i18n)('lib.configMigrate.mergeSuccess', {
|
|
95
|
+
globalConfigPath: config_1.GLOBAL_CONFIG_PATH,
|
|
96
|
+
}));
|
|
97
|
+
(0, usageTracking_1.trackCommandMetadataUsage)('config-migrate', {
|
|
98
|
+
command: 'hs config migrate',
|
|
99
|
+
type: 'merge',
|
|
100
|
+
step: 'Confirm merge via prompt',
|
|
101
|
+
successful: true,
|
|
102
|
+
}, accountId);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
@@ -11,16 +11,15 @@ interface Section {
|
|
|
11
11
|
export declare class Diagnosis {
|
|
12
12
|
private readonly prefixes;
|
|
13
13
|
private readonly diagnosis;
|
|
14
|
-
private readonly indentation;
|
|
15
14
|
private errorCount;
|
|
16
15
|
private warningCount;
|
|
17
16
|
constructor({ diagnosticInfo, accountId }: DiagnosisOptions);
|
|
18
|
-
private indent;
|
|
19
17
|
getErrorCount(): number;
|
|
20
18
|
getWarningCount(): number;
|
|
21
19
|
addCliSection(section: Section): void;
|
|
22
20
|
addProjectSection(section: Section): void;
|
|
23
21
|
addCLIConfigSection(section: Section): void;
|
|
22
|
+
addDefaultAccountOverrideFileSection(section: Section): void;
|
|
24
23
|
toString(): string;
|
|
25
24
|
private generateSections;
|
|
26
25
|
}
|
package/lib/doctor/Diagnosis.js
CHANGED
|
@@ -5,12 +5,12 @@ const spinniesUtils_1 = require("../ui/spinniesUtils");
|
|
|
5
5
|
const chalk_1 = require("chalk");
|
|
6
6
|
const interpolation_1 = require("../interpolation");
|
|
7
7
|
const ui_1 = require("../ui");
|
|
8
|
+
const index_1 = require("../ui/index");
|
|
8
9
|
const { i18n } = require('../lang');
|
|
9
10
|
const i18nKey = `lib.doctor.diagnosis`;
|
|
10
11
|
class Diagnosis {
|
|
11
12
|
prefixes;
|
|
12
13
|
diagnosis;
|
|
13
|
-
indentation = ' ';
|
|
14
14
|
errorCount = 0;
|
|
15
15
|
warningCount = 0;
|
|
16
16
|
constructor({ diagnosticInfo, accountId }) {
|
|
@@ -29,6 +29,10 @@ class Diagnosis {
|
|
|
29
29
|
header: i18n(`${i18nKey}.cliConfig.header`),
|
|
30
30
|
sections: [],
|
|
31
31
|
},
|
|
32
|
+
defaultAccountOverrideFile: {
|
|
33
|
+
header: i18n(`${i18nKey}.defaultAccountOverrideFile.header`),
|
|
34
|
+
sections: [],
|
|
35
|
+
},
|
|
32
36
|
project: {
|
|
33
37
|
header: i18n(`${i18nKey}.projectConfig.header`),
|
|
34
38
|
subheaders: [
|
|
@@ -53,9 +57,6 @@ class Diagnosis {
|
|
|
53
57
|
];
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
|
-
indent(level) {
|
|
57
|
-
return this.indentation.repeat(level);
|
|
58
|
-
}
|
|
59
60
|
getErrorCount() {
|
|
60
61
|
return this.errorCount;
|
|
61
62
|
}
|
|
@@ -71,6 +72,9 @@ class Diagnosis {
|
|
|
71
72
|
addCLIConfigSection(section) {
|
|
72
73
|
this.diagnosis.cliConfig.sections.push(section);
|
|
73
74
|
}
|
|
75
|
+
addDefaultAccountOverrideFileSection(section) {
|
|
76
|
+
this.diagnosis.defaultAccountOverrideFile.sections.push(section);
|
|
77
|
+
}
|
|
74
78
|
toString() {
|
|
75
79
|
const output = [];
|
|
76
80
|
for (const value of Object.values(this.diagnosis)) {
|
|
@@ -108,9 +112,9 @@ class Diagnosis {
|
|
|
108
112
|
else if (section.type === 'warning') {
|
|
109
113
|
this.warningCount++;
|
|
110
114
|
}
|
|
111
|
-
output.push(`${
|
|
115
|
+
output.push(`${(0, index_1.indent)(1)}${this.prefixes[section.type]} ${section.message}`);
|
|
112
116
|
if (section.secondaryMessaging) {
|
|
113
|
-
output.push(`${
|
|
117
|
+
output.push(`${(0, index_1.indent)(2)}- ${section.secondaryMessaging}`);
|
|
114
118
|
}
|
|
115
119
|
});
|
|
116
120
|
return output.join('\n');
|
|
@@ -64,6 +64,7 @@ class DiagnosticInfoBuilder {
|
|
|
64
64
|
arch,
|
|
65
65
|
path: mainModule?.path,
|
|
66
66
|
config: (0, config_2.getConfigPath)(),
|
|
67
|
+
defaultAccountOverrideFile: (0, config_1.getDefaultAccountOverrideFilePath)(),
|
|
67
68
|
configSettings: this.configSettings,
|
|
68
69
|
versions: {
|
|
69
70
|
[hubspotCli]: package_json_1.default.version,
|
package/lib/doctor/Doctor.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare class Doctor {
|
|
|
10
10
|
private performCliChecks;
|
|
11
11
|
private performProjectChecks;
|
|
12
12
|
private performCliConfigChecks;
|
|
13
|
+
private performDefaultAccountOverrideFileChecks;
|
|
13
14
|
private performCliConfigSettingsChecks;
|
|
14
15
|
private checkIfAccessTokenValid;
|
|
15
16
|
private checkIfNodeIsInstalled;
|
package/lib/doctor/Doctor.js
CHANGED
|
@@ -51,6 +51,7 @@ class Doctor {
|
|
|
51
51
|
...this.performCliConfigChecks(),
|
|
52
52
|
...(this.projectConfig?.projectConfig ? this.performProjectChecks() : []),
|
|
53
53
|
]);
|
|
54
|
+
this.performDefaultAccountOverrideFileChecks();
|
|
54
55
|
this.performCliConfigSettingsChecks();
|
|
55
56
|
SpinniesManager_1.default.succeed('runningDiagnostics', {
|
|
56
57
|
text: i18n(`${i18nKey}.diagnosticsComplete`),
|
|
@@ -88,6 +89,23 @@ class Doctor {
|
|
|
88
89
|
}
|
|
89
90
|
return [this.checkIfAccessTokenValid()];
|
|
90
91
|
}
|
|
92
|
+
performDefaultAccountOverrideFileChecks() {
|
|
93
|
+
const localI18nKey = `${i18nKey}.defaultAccountOverrideFileChecks`;
|
|
94
|
+
if (this.diagnosticInfo?.defaultAccountOverrideFile) {
|
|
95
|
+
this.diagnosis?.addDefaultAccountOverrideFileSection({
|
|
96
|
+
type: 'warning',
|
|
97
|
+
message: i18n(`${localI18nKey}.overrideActive`, {
|
|
98
|
+
defaultAccountOverrideFile: this.diagnosticInfo.defaultAccountOverrideFile,
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
this.diagnosis?.addDefaultAccountOverrideFileSection({
|
|
102
|
+
type: 'warning',
|
|
103
|
+
message: i18n(`${localI18nKey}.overrideAccountId`, {
|
|
104
|
+
overrideAccountId: (0, config_1.getCWDAccountOverride)(),
|
|
105
|
+
}),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
91
109
|
performCliConfigSettingsChecks() {
|
|
92
110
|
if (this.diagnosticInfo?.configSettings.httpUseLocalhost) {
|
|
93
111
|
this.diagnosis?.addCLIConfigSection({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
37
|
+
const cliConfig = __importStar(require("@hubspot/local-dev-lib/config"));
|
|
38
|
+
const validation = __importStar(require("../../validation"));
|
|
39
|
+
const exitCodes_1 = require("../../enums/exitCodes");
|
|
40
|
+
const configMiddleware_1 = require("../configMiddleware");
|
|
41
|
+
jest.mock('@hubspot/local-dev-lib/logger', () => ({
|
|
42
|
+
logger: {
|
|
43
|
+
error: jest.fn(),
|
|
44
|
+
log: jest.fn(),
|
|
45
|
+
},
|
|
46
|
+
}));
|
|
47
|
+
jest.mock('@hubspot/local-dev-lib/config');
|
|
48
|
+
jest.mock('../../validation');
|
|
49
|
+
const validateAccountSpy = jest.spyOn(validation, 'validateAccount');
|
|
50
|
+
const loadConfigSpy = jest.spyOn(cliConfig, 'loadConfig');
|
|
51
|
+
const getAccountIdSpy = jest.spyOn(cliConfig, 'getAccountId');
|
|
52
|
+
const configFileExistsSpy = jest.spyOn(cliConfig, 'configFileExists');
|
|
53
|
+
const getConfigPathSpy = jest.spyOn(cliConfig, 'getConfigPath');
|
|
54
|
+
const validateConfigSpy = jest.spyOn(cliConfig, 'validateConfig');
|
|
55
|
+
const processExitSpy = jest.spyOn(process, 'exit');
|
|
56
|
+
describe('lib/middleware/configMiddleware', () => {
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
processExitSpy.mockImplementation(code => {
|
|
59
|
+
throw new Error(`Process.exit called with code ${code}`);
|
|
60
|
+
});
|
|
61
|
+
getConfigPathSpy.mockReturnValue('/path/to/config');
|
|
62
|
+
});
|
|
63
|
+
describe('handleDeprecatedEnvVariables()', () => {
|
|
64
|
+
it('should handle deprecated HUBSPOT_PORTAL_ID environment variable', () => {
|
|
65
|
+
const originalEnv = process.env;
|
|
66
|
+
process.env = {
|
|
67
|
+
...originalEnv,
|
|
68
|
+
HUBSPOT_PORTAL_ID: '123',
|
|
69
|
+
HUBSPOT_ACCOUNT_ID: undefined,
|
|
70
|
+
};
|
|
71
|
+
const argv = {
|
|
72
|
+
_: ['some-command'],
|
|
73
|
+
useEnv: true,
|
|
74
|
+
$0: 'hs',
|
|
75
|
+
};
|
|
76
|
+
(0, configMiddleware_1.handleDeprecatedEnvVariables)(argv);
|
|
77
|
+
expect(logger_1.logger.log).toHaveBeenCalledWith(expect.stringContaining('The HUBSPOT_PORTAL_ID environment variable is deprecated. Please use HUBSPOT_ACCOUNT_ID instead.'));
|
|
78
|
+
expect(process.env.HUBSPOT_ACCOUNT_ID).toBe('123');
|
|
79
|
+
process.env = originalEnv;
|
|
80
|
+
});
|
|
81
|
+
it('should not handle HUBSPOT_PORTAL_ID if HUBSPOT_ACCOUNT_ID is set', () => {
|
|
82
|
+
const originalEnv = process.env;
|
|
83
|
+
process.env = {
|
|
84
|
+
...originalEnv,
|
|
85
|
+
HUBSPOT_PORTAL_ID: '123',
|
|
86
|
+
HUBSPOT_ACCOUNT_ID: '456',
|
|
87
|
+
};
|
|
88
|
+
const argv = {
|
|
89
|
+
_: ['some-command'],
|
|
90
|
+
useEnv: true,
|
|
91
|
+
$0: 'hs',
|
|
92
|
+
};
|
|
93
|
+
(0, configMiddleware_1.handleDeprecatedEnvVariables)(argv);
|
|
94
|
+
expect(logger_1.logger.log).not.toHaveBeenCalled();
|
|
95
|
+
expect(process.env.HUBSPOT_ACCOUNT_ID).toBe('456');
|
|
96
|
+
process.env = originalEnv;
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('injectAccountIdMiddleware()', () => {
|
|
100
|
+
it('should use HUBSPOT_ACCOUNT_ID from environment when useEnv is true', async () => {
|
|
101
|
+
const originalEnv = process.env;
|
|
102
|
+
process.env = {
|
|
103
|
+
...originalEnv,
|
|
104
|
+
HUBSPOT_ACCOUNT_ID: '123',
|
|
105
|
+
};
|
|
106
|
+
const argv = {
|
|
107
|
+
_: ['some-command'],
|
|
108
|
+
useEnv: true,
|
|
109
|
+
$0: 'hs',
|
|
110
|
+
};
|
|
111
|
+
await (0, configMiddleware_1.injectAccountIdMiddleware)(argv);
|
|
112
|
+
expect(argv.providedAccountId).toBeUndefined();
|
|
113
|
+
expect(argv.derivedAccountId).toBe(123);
|
|
114
|
+
expect(getAccountIdSpy).not.toHaveBeenCalled();
|
|
115
|
+
process.env = originalEnv;
|
|
116
|
+
});
|
|
117
|
+
it('should use getAccountId when useEnv is false', async () => {
|
|
118
|
+
getAccountIdSpy.mockReturnValue(456);
|
|
119
|
+
const argv = {
|
|
120
|
+
_: ['some-command'],
|
|
121
|
+
account: 'test-account',
|
|
122
|
+
useEnv: false,
|
|
123
|
+
$0: 'hs',
|
|
124
|
+
};
|
|
125
|
+
await (0, configMiddleware_1.injectAccountIdMiddleware)(argv);
|
|
126
|
+
expect(argv.providedAccountId).toBe('test-account');
|
|
127
|
+
expect(argv.derivedAccountId).toBe(456);
|
|
128
|
+
expect(getAccountIdSpy).toHaveBeenCalledWith('test-account');
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
describe('loadConfigMiddleware()', () => {
|
|
132
|
+
it('should exit with error when config file exists and --config flag is used', async () => {
|
|
133
|
+
configFileExistsSpy.mockReturnValue(true);
|
|
134
|
+
const argv = {
|
|
135
|
+
_: ['some-command'],
|
|
136
|
+
config: 'custom-config.json',
|
|
137
|
+
$0: 'hs',
|
|
138
|
+
};
|
|
139
|
+
await expect((0, configMiddleware_1.loadConfigMiddleware)(argv)).rejects.toThrow();
|
|
140
|
+
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
141
|
+
expect(logger_1.logger.error).toHaveBeenCalledWith('A configuration file already exists at /path/to/config. To specify a new configuration file, delete the existing one and try again.');
|
|
142
|
+
});
|
|
143
|
+
it('should load config and validate for non-init commands', async () => {
|
|
144
|
+
configFileExistsSpy.mockReturnValue(false);
|
|
145
|
+
loadConfigSpy.mockReturnValue({});
|
|
146
|
+
validateConfigSpy.mockReturnValue(true);
|
|
147
|
+
const argv = {
|
|
148
|
+
_: ['some-command'],
|
|
149
|
+
$0: 'hs',
|
|
150
|
+
};
|
|
151
|
+
await (0, configMiddleware_1.loadConfigMiddleware)(argv);
|
|
152
|
+
expect(loadConfigSpy).toHaveBeenCalled();
|
|
153
|
+
expect(validateConfigSpy).toHaveBeenCalled();
|
|
154
|
+
});
|
|
155
|
+
it('should skip validation for init command', async () => {
|
|
156
|
+
configFileExistsSpy.mockReturnValue(false);
|
|
157
|
+
const argv = {
|
|
158
|
+
_: ['init'],
|
|
159
|
+
$0: 'hs',
|
|
160
|
+
};
|
|
161
|
+
await (0, configMiddleware_1.loadConfigMiddleware)(argv);
|
|
162
|
+
expect(loadConfigSpy).not.toHaveBeenCalled();
|
|
163
|
+
expect(validateConfigSpy).not.toHaveBeenCalled();
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
describe('validateAccountOptions()', () => {
|
|
167
|
+
it('should validate account for non-skipped commands', async () => {
|
|
168
|
+
validateAccountSpy.mockResolvedValue(true);
|
|
169
|
+
const argv = {
|
|
170
|
+
_: ['some-command'],
|
|
171
|
+
$0: 'hs',
|
|
172
|
+
};
|
|
173
|
+
await (0, configMiddleware_1.validateAccountOptions)(argv);
|
|
174
|
+
expect(validateAccountSpy).toHaveBeenCalledWith(argv);
|
|
175
|
+
});
|
|
176
|
+
it('should skip validation for init command', async () => {
|
|
177
|
+
const argv = {
|
|
178
|
+
_: ['init'],
|
|
179
|
+
$0: 'hs',
|
|
180
|
+
};
|
|
181
|
+
await (0, configMiddleware_1.validateAccountOptions)(argv);
|
|
182
|
+
expect(validateAccountSpy).not.toHaveBeenCalled();
|
|
183
|
+
});
|
|
184
|
+
it('should exit with error when account validation fails', async () => {
|
|
185
|
+
validateAccountSpy.mockResolvedValue(false);
|
|
186
|
+
const argv = {
|
|
187
|
+
_: ['some-command'],
|
|
188
|
+
$0: 'hs',
|
|
189
|
+
};
|
|
190
|
+
await expect((0, configMiddleware_1.validateAccountOptions)(argv)).rejects.toThrow();
|
|
191
|
+
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const config = __importStar(require("@hubspot/local-dev-lib/config"));
|
|
37
|
+
const gitUI = __importStar(require("../../ui/git"));
|
|
38
|
+
const gitMiddleware_1 = require("../gitMiddleware");
|
|
39
|
+
jest.mock('@hubspot/local-dev-lib/config');
|
|
40
|
+
jest.mock('../../ui/git');
|
|
41
|
+
const getConfigPathSpy = jest.spyOn(config, 'getConfigPath');
|
|
42
|
+
const checkAndWarnGitInclusionSpy = jest.spyOn(gitUI, 'checkAndWarnGitInclusion');
|
|
43
|
+
describe('lib/middleware/gitMiddleware', () => {
|
|
44
|
+
describe('checkAndWarnGitInclusionMiddleware()', () => {
|
|
45
|
+
it('should call checkAndWarnGitInclusion when command is provided and config path exists', () => {
|
|
46
|
+
const mockConfigPath = '/path/to/config';
|
|
47
|
+
getConfigPathSpy.mockReturnValue(mockConfigPath);
|
|
48
|
+
const argv = {
|
|
49
|
+
_: ['some-command'],
|
|
50
|
+
$0: 'hs',
|
|
51
|
+
};
|
|
52
|
+
(0, gitMiddleware_1.checkAndWarnGitInclusionMiddleware)(argv);
|
|
53
|
+
expect(getConfigPathSpy).toHaveBeenCalledTimes(1);
|
|
54
|
+
expect(checkAndWarnGitInclusionSpy).toHaveBeenCalledWith(mockConfigPath);
|
|
55
|
+
});
|
|
56
|
+
it('should not call checkAndWarnGitInclusion when no command is provided', () => {
|
|
57
|
+
const argv = {
|
|
58
|
+
_: [],
|
|
59
|
+
$0: 'hs',
|
|
60
|
+
};
|
|
61
|
+
(0, gitMiddleware_1.checkAndWarnGitInclusionMiddleware)(argv);
|
|
62
|
+
expect(getConfigPathSpy).not.toHaveBeenCalled();
|
|
63
|
+
expect(checkAndWarnGitInclusionSpy).not.toHaveBeenCalled();
|
|
64
|
+
});
|
|
65
|
+
it('should not call checkAndWarnGitInclusion when config path is null', () => {
|
|
66
|
+
getConfigPathSpy.mockReturnValue(null);
|
|
67
|
+
const argv = {
|
|
68
|
+
_: ['some-command'],
|
|
69
|
+
$0: 'hs',
|
|
70
|
+
};
|
|
71
|
+
(0, gitMiddleware_1.checkAndWarnGitInclusionMiddleware)(argv);
|
|
72
|
+
expect(getConfigPathSpy).toHaveBeenCalledTimes(1);
|
|
73
|
+
expect(checkAndWarnGitInclusionSpy).not.toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { notifyAboutUpdates } = require('../notificationsMiddleware');
|
|
4
|
+
describe('lib/middleware/notificationsMiddleware', () => {
|
|
5
|
+
describe('notifyAboutUpdates()', () => {
|
|
6
|
+
it('should safely execute without throwing an error', () => {
|
|
7
|
+
expect(() => notifyAboutUpdates()).not.toThrow();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const http_1 = require("@hubspot/local-dev-lib/http");
|
|
7
|
+
const requestMiddleware_1 = require("../requestMiddleware");
|
|
8
|
+
const package_json_1 = __importDefault(require("../../../package.json"));
|
|
9
|
+
jest.mock('@hubspot/local-dev-lib/http', () => ({
|
|
10
|
+
addUserAgentHeader: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
describe('lib/middleware/requestMiddleware', () => {
|
|
13
|
+
describe('setRequestHeaders()', () => {
|
|
14
|
+
it('should call addUserAgentHeader with correct parameters', () => {
|
|
15
|
+
(0, requestMiddleware_1.setRequestHeaders)();
|
|
16
|
+
expect(http_1.addUserAgentHeader).toHaveBeenCalledTimes(1);
|
|
17
|
+
expect(http_1.addUserAgentHeader).toHaveBeenCalledWith('HubSpot CLI', package_json_1.default.version);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../utils");
|
|
4
|
+
const targetCommandMap = {
|
|
5
|
+
init: { target: true },
|
|
6
|
+
account: {
|
|
7
|
+
target: true,
|
|
8
|
+
subCommands: {
|
|
9
|
+
use: { target: true },
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
project: {
|
|
13
|
+
subCommands: {
|
|
14
|
+
deploy: { target: true },
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
describe('lib/middleware/utils', () => {
|
|
19
|
+
describe('isTargetedCommand()', () => {
|
|
20
|
+
it('should return true for a direct target command', () => {
|
|
21
|
+
const result = (0, utils_1.isTargetedCommand)(['init'], targetCommandMap);
|
|
22
|
+
expect(result).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
it('should return true for a command with a subcommand', () => {
|
|
25
|
+
const result = (0, utils_1.isTargetedCommand)(['account'], targetCommandMap);
|
|
26
|
+
expect(result).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('should return true for a nested target command', () => {
|
|
29
|
+
const result = (0, utils_1.isTargetedCommand)(['project', 'deploy'], targetCommandMap);
|
|
30
|
+
expect(result).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
it('should return false for a non-existent command', () => {
|
|
33
|
+
const result = (0, utils_1.isTargetedCommand)(['nonexistent'], targetCommandMap);
|
|
34
|
+
expect(result).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
it('should return false for a non-targeted command', () => {
|
|
37
|
+
const result = (0, utils_1.isTargetedCommand)(['auth'], targetCommandMap);
|
|
38
|
+
expect(result).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
it('should return false for a command with a targeted subcommand', () => {
|
|
41
|
+
const result = (0, utils_1.isTargetedCommand)(['project'], targetCommandMap);
|
|
42
|
+
expect(result).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
it('should return false for a non-existent subcommand', () => {
|
|
45
|
+
const result = (0, utils_1.isTargetedCommand)(['auth', 'nonexistent'], targetCommandMap);
|
|
46
|
+
expect(result).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
it('should return false for an empty command array', () => {
|
|
49
|
+
const result = (0, utils_1.isTargetedCommand)([], targetCommandMap);
|
|
50
|
+
expect(result).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|