@hubspot/cli 7.10.0 → 7.10.1-experimental.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/bin/cli.js +5 -4
- package/commands/__tests__/getStarted.test.js +10 -0
- package/commands/__tests__/project.test.js +3 -0
- package/commands/account/__tests__/rename.test.js +10 -3
- package/commands/account/auth.js +10 -14
- package/commands/account/clean.js +11 -19
- package/commands/account/createOverride.js +15 -11
- package/commands/account/info.js +8 -5
- package/commands/account/list.js +15 -19
- package/commands/account/remove.js +23 -22
- package/commands/account/removeOverride.js +6 -6
- package/commands/account/rename.js +2 -2
- package/commands/account/use.js +19 -8
- package/commands/app/__tests__/migrate.test.js +8 -4
- package/commands/app/migrate.js +2 -2
- package/commands/auth.js +18 -14
- package/commands/config/migrate.js +5 -5
- package/commands/customObject/createSchema.js +2 -3
- package/commands/customObject/updateSchema.js +2 -3
- package/commands/getStarted.js +2 -3
- package/commands/hubdb/__tests__/list.test.js +1 -0
- package/commands/hubdb/list.js +2 -2
- package/commands/init.js +36 -32
- package/commands/project/__tests__/deploy.test.js +10 -5
- package/commands/project/__tests__/devUnifiedFlow.test.js +6 -4
- package/commands/project/__tests__/lint.test.js +709 -0
- package/commands/project/__tests__/logs.test.js +4 -0
- package/commands/project/__tests__/validate.test.js +286 -28
- package/commands/project/cloneApp.js +2 -2
- package/commands/project/deploy.js +16 -8
- package/commands/project/dev/deprecatedFlow.js +4 -5
- package/commands/project/dev/index.js +19 -7
- package/commands/project/dev/unifiedFlow.js +4 -5
- package/commands/project/lint.d.ts +6 -0
- package/commands/project/lint.js +178 -0
- package/commands/project/logs.js +2 -3
- package/commands/project/migrate.js +4 -13
- package/commands/project/profile/add.js +6 -7
- package/commands/project/profile/delete.js +2 -2
- package/commands/project/upload.js +10 -4
- package/commands/project/validate.js +73 -13
- package/commands/project.js +2 -0
- package/commands/sandbox/__tests__/create.test.js +14 -5
- package/commands/sandbox/create.js +4 -5
- package/commands/sandbox/delete.js +23 -20
- package/commands/testAccount/create.js +2 -2
- package/commands/testAccount/delete.js +9 -8
- package/lang/en.d.ts +48 -11
- package/lang/en.js +58 -15
- package/lib/__tests__/buildAccount.test.js +22 -30
- package/lib/__tests__/commonOpts.test.js +9 -13
- package/lib/__tests__/developerTestAccounts.test.js +29 -17
- package/lib/__tests__/importData.test.js +20 -10
- package/lib/__tests__/oauth.test.js +19 -8
- package/lib/__tests__/projectProfiles.test.js +273 -32
- package/lib/__tests__/sandboxSync.test.js +33 -11
- package/lib/__tests__/sandboxes.test.js +30 -19
- package/lib/__tests__/usageTracking.test.js +10 -10
- package/lib/__tests__/validation.test.js +32 -32
- package/lib/accountTypes.d.ts +9 -9
- package/lib/accountTypes.js +2 -4
- package/lib/app/__tests__/migrate.test.js +15 -0
- package/lib/app/__tests__/migrate_legacy.test.js +9 -0
- package/lib/app/migrate_legacy.d.ts +2 -2
- package/lib/buildAccount.d.ts +4 -4
- package/lib/buildAccount.js +7 -14
- package/lib/commonOpts.js +3 -3
- package/lib/configMigrate.d.ts +2 -2
- package/lib/configMigrate.js +42 -18
- package/lib/configOptions.js +3 -2
- package/lib/developerTestAccounts.d.ts +3 -3
- package/lib/developerTestAccounts.js +4 -7
- package/lib/doctor/DiagnosticInfoBuilder.d.ts +1 -1
- package/lib/doctor/DiagnosticInfoBuilder.js +9 -6
- package/lib/doctor/Doctor.js +4 -3
- package/lib/doctor/__tests__/Diagnosis.test.js +4 -3
- package/lib/doctor/__tests__/DiagnosticInfoBuilder.test.js +17 -9
- package/lib/doctor/__tests__/Doctor.test.js +14 -0
- package/lib/importData.js +8 -7
- package/lib/links.js +5 -5
- package/lib/middleware/{__test__ → __tests__}/commandTargetingUtils.test.js +3 -3
- package/lib/middleware/{__test__ → __tests__}/configMiddleware.test.js +23 -22
- package/lib/middleware/{__test__ → __tests__}/gitMiddleware.test.js +9 -7
- package/lib/middleware/autoUpdateMiddleware.js +34 -23
- package/lib/middleware/commandTargetingUtils.js +3 -2
- package/lib/middleware/configMiddleware.d.ts +6 -1
- package/lib/middleware/configMiddleware.js +36 -15
- package/lib/middleware/fireAlarmMiddleware.js +4 -15
- package/lib/middleware/gitMiddleware.js +8 -4
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +8 -10
- package/lib/projectProfiles.d.ts +4 -3
- package/lib/projectProfiles.js +78 -32
- package/lib/projects/__tests__/AppDevModeInterface.test.js +17 -6
- package/lib/projects/__tests__/DevServerManager.test.js +1 -0
- package/lib/projects/__tests__/LocalDevProcess.test.js +1 -0
- package/lib/projects/__tests__/deploy.test.js +1 -0
- package/lib/projects/__tests__/uieLinting.test.js +640 -0
- package/lib/projects/create/__tests__/v2.test.js +11 -0
- package/lib/projects/localDev/AppDevModeInterface.js +2 -2
- package/lib/projects/localDev/DevServerManager_DEPRECATED.js +2 -2
- package/lib/projects/localDev/LocalDevLogger.js +4 -4
- package/lib/projects/localDev/LocalDevManager_DEPRECATED.js +3 -3
- package/lib/projects/localDev/helpers/account.d.ts +10 -10
- package/lib/projects/localDev/helpers/account.js +6 -11
- package/lib/projects/uieLinting.d.ts +33 -0
- package/lib/projects/uieLinting.js +222 -0
- package/lib/projects/urls.js +5 -6
- package/lib/prompts/__tests__/downloadProjectPrompt.test.js +7 -5
- package/lib/prompts/accountNamePrompt.js +3 -3
- package/lib/prompts/accountsPrompt.d.ts +1 -1
- package/lib/prompts/accountsPrompt.js +6 -7
- package/lib/prompts/confirmImportDataPrompt.js +2 -2
- package/lib/prompts/downloadProjectPrompt.d.ts +1 -0
- package/lib/prompts/downloadProjectPrompt.js +5 -2
- package/lib/prompts/importDataTestAccountSelectPrompt.js +4 -5
- package/lib/prompts/personalAccessKeyPrompt.js +2 -2
- package/lib/prompts/projectDevTargetAccountPrompt.d.ts +3 -3
- package/lib/prompts/projectDevTargetAccountPrompt.js +5 -7
- package/lib/prompts/sandboxesPrompt.js +7 -8
- package/lib/prompts/setAsDefaultAccountPrompt.js +7 -6
- package/lib/sandboxSync.d.ts +2 -2
- package/lib/sandboxSync.js +3 -9
- package/lib/sandboxes.d.ts +4 -4
- package/lib/sandboxes.js +6 -11
- package/lib/serverlessLogs.js +2 -2
- package/lib/theme/__tests__/migrate.test.js +15 -0
- package/lib/ui/index.js +6 -3
- package/lib/usageTracking.js +15 -8
- package/lib/validation.js +13 -11
- package/mcp-server/tools/cms/HsCreateFunctionTool.js +4 -2
- package/mcp-server/tools/cms/HsCreateModuleTool.js +4 -2
- package/mcp-server/tools/cms/HsCreateTemplateTool.js +4 -2
- package/mcp-server/tools/cms/HsFunctionLogsTool.js +4 -2
- package/mcp-server/tools/cms/HsListFunctionsTool.js +3 -1
- package/mcp-server/tools/cms/HsListTool.js +3 -1
- package/mcp-server/tools/cms/__tests__/HsCreateFunctionTool.test.js +1 -0
- package/mcp-server/tools/index.js +4 -0
- package/mcp-server/tools/project/AddFeatureToProjectTool.js +4 -2
- package/mcp-server/tools/project/CreateProjectTool.js +4 -2
- package/mcp-server/tools/project/CreateTestAccountTool.js +17 -7
- package/mcp-server/tools/project/DeployProjectTool.js +3 -1
- package/mcp-server/tools/project/DocFetchTool.js +6 -4
- package/mcp-server/tools/project/DocsSearchTool.d.ts +1 -1
- package/mcp-server/tools/project/DocsSearchTool.js +10 -8
- package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.d.ts +1 -1
- package/mcp-server/tools/project/GetApiUsagePatternsByAppIdTool.js +9 -7
- package/mcp-server/tools/project/GetApplicationInfoTool.js +8 -6
- package/mcp-server/tools/project/GetBuildLogsTool.d.ts +26 -0
- package/mcp-server/tools/project/GetBuildLogsTool.js +125 -0
- package/mcp-server/tools/project/GetBuildStatusTool.d.ts +26 -0
- package/mcp-server/tools/project/GetBuildStatusTool.js +166 -0
- package/mcp-server/tools/project/GetConfigValuesTool.d.ts +1 -1
- package/mcp-server/tools/project/GetConfigValuesTool.js +9 -7
- package/mcp-server/tools/project/GuidedWalkthroughTool.d.ts +1 -1
- package/mcp-server/tools/project/GuidedWalkthroughTool.js +5 -3
- package/mcp-server/tools/project/UploadProjectTools.js +3 -1
- package/mcp-server/tools/project/ValidateProjectTool.js +4 -2
- package/mcp-server/tools/project/__tests__/CreateTestAccountTool.test.js +12 -2
- package/mcp-server/tools/project/__tests__/DocFetchTool.test.js +5 -1
- package/mcp-server/tools/project/__tests__/DocsSearchTool.test.js +23 -11
- package/mcp-server/tools/project/__tests__/GetApiUsagePatternsByAppIdTool.test.js +7 -5
- package/mcp-server/tools/project/__tests__/GetApplicationInfoTool.test.js +7 -5
- package/mcp-server/tools/project/__tests__/GetBuildLogsTool.test.d.ts +1 -0
- package/mcp-server/tools/project/__tests__/GetBuildLogsTool.test.js +305 -0
- package/mcp-server/tools/project/__tests__/GetBuildStatusTool.test.d.ts +1 -0
- package/mcp-server/tools/project/__tests__/GetBuildStatusTool.test.js +240 -0
- package/mcp-server/tools/project/__tests__/GetConfigValuesTool.test.js +8 -6
- package/mcp-server/utils/__tests__/content.test.js +21 -20
- package/mcp-server/utils/__tests__/feedbackTracking.test.js +34 -28
- package/mcp-server/utils/config.d.ts +1 -0
- package/mcp-server/utils/config.js +10 -0
- package/mcp-server/utils/content.d.ts +1 -1
- package/mcp-server/utils/content.js +2 -2
- package/mcp-server/utils/feedbackTracking.d.ts +1 -1
- package/mcp-server/utils/feedbackTracking.js +3 -3
- package/mcp-server/utils/toolUsageTracking.js +4 -3
- package/package.json +9 -9
- package/ui/components/BoxWithTitle.d.ts +2 -1
- package/ui/components/BoxWithTitle.js +2 -2
- package/ui/components/StatusMessageBoxes.d.ts +5 -4
- package/ui/components/StatusMessageBoxes.js +8 -8
- package/lib/middleware/__test__/notificationsMiddleware.test.js +0 -8
- package/lib/middleware/notificationsMiddleware.d.ts +0 -1
- package/lib/middleware/notificationsMiddleware.js +0 -28
- package/lib/ui/boxen.d.ts +0 -5
- package/lib/ui/boxen.js +0 -26
- package/mcp-server/utils/__tests__/cliConfig.test.js +0 -110
- package/mcp-server/utils/cliConfig.d.ts +0 -1
- package/mcp-server/utils/cliConfig.js +0 -12
- /package/{lib/middleware/__test__/commandTargetingUtils.test.d.ts → commands/project/__tests__/lint.test.d.ts} +0 -0
- /package/lib/middleware/{__test__/configMiddleware.test.d.ts → __tests__/commandTargetingUtils.test.d.ts} +0 -0
- /package/lib/middleware/{__test__/gitMiddleware.test.d.ts → __tests__/configMiddleware.test.d.ts} +0 -0
- /package/lib/middleware/{__test__/notificationsMiddleware.test.d.ts → __tests__/gitMiddleware.test.d.ts} +0 -0
- /package/lib/middleware/{__test__ → __tests__}/requestMiddleware.test.d.ts +0 -0
- /package/lib/middleware/{__test__ → __tests__}/requestMiddleware.test.js +0 -0
- /package/lib/middleware/{__test__ → __tests__}/yargsChecksMiddleware.test.d.ts +0 -0
- /package/lib/middleware/{__test__ → __tests__}/yargsChecksMiddleware.test.js +0 -0
- /package/{mcp-server/utils/__tests__/cliConfig.test.d.ts → lib/projects/__tests__/uieLinting.test.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { trackUsage } from '@hubspot/local-dev-lib/trackUsage';
|
|
2
|
-
import {
|
|
2
|
+
import { getConfig, getConfigAccountById } from '@hubspot/local-dev-lib/config';
|
|
3
3
|
import { API_KEY_AUTH_METHOD } from '@hubspot/local-dev-lib/constants/auth';
|
|
4
4
|
import { uiLogger } from '../ui/logger.js';
|
|
5
5
|
import { trackCommandUsage, trackHelpUsage, trackConvertFieldsUsage, trackAuthAction, trackCommandMetadataUsage, } from '../usageTracking.js';
|
|
@@ -9,14 +9,14 @@ vi.mock('@hubspot/local-dev-lib/trackUsage');
|
|
|
9
9
|
vi.mock('@hubspot/local-dev-lib/config');
|
|
10
10
|
vi.mock('../ui/logger.js');
|
|
11
11
|
const mockedTrackUsage = trackUsage;
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const mockedGetConfig = getConfig;
|
|
13
|
+
const mockedGetConfigAccountById = getConfigAccountById;
|
|
14
14
|
const mockedUiLogger = uiLogger;
|
|
15
15
|
describe('lib/usageTracking', () => {
|
|
16
16
|
const mockPlatform = 'darwin';
|
|
17
17
|
const mockNodeVersion = 'v16.14.0';
|
|
18
18
|
beforeEach(() => {
|
|
19
|
-
|
|
19
|
+
mockedGetConfig.mockReturnValue({ allowUsageTracking: true });
|
|
20
20
|
Object.defineProperty(process, 'platform', { value: mockPlatform });
|
|
21
21
|
Object.defineProperty(process, 'version', { value: mockNodeVersion });
|
|
22
22
|
});
|
|
@@ -24,7 +24,7 @@ describe('lib/usageTracking', () => {
|
|
|
24
24
|
const mockCommand = 'test-command';
|
|
25
25
|
const mockAccountId = 123;
|
|
26
26
|
it('should not track when tracking is disabled', async () => {
|
|
27
|
-
|
|
27
|
+
mockedGetConfig.mockReturnValue({ allowUsageTracking: false });
|
|
28
28
|
await trackCommandUsage(mockCommand);
|
|
29
29
|
expect(mockedTrackUsage).not.toHaveBeenCalled();
|
|
30
30
|
});
|
|
@@ -41,7 +41,7 @@ describe('lib/usageTracking', () => {
|
|
|
41
41
|
}), mockAccountId);
|
|
42
42
|
});
|
|
43
43
|
it('should track command usage with custom auth type', async () => {
|
|
44
|
-
|
|
44
|
+
mockedGetConfigAccountById.mockReturnValue({ authType: 'oauth2' });
|
|
45
45
|
await trackCommandUsage(mockCommand, {}, mockAccountId);
|
|
46
46
|
expect(mockedTrackUsage).toHaveBeenCalledWith('cli-interaction', 'INTERACTION', expect.objectContaining({
|
|
47
47
|
authType: 'oauth2',
|
|
@@ -59,7 +59,7 @@ describe('lib/usageTracking', () => {
|
|
|
59
59
|
describe('trackHelpUsage()', () => {
|
|
60
60
|
const mockCommand = 'help-command';
|
|
61
61
|
it('should not track when tracking is disabled', async () => {
|
|
62
|
-
|
|
62
|
+
mockedGetConfig.mockReturnValue({ allowUsageTracking: false });
|
|
63
63
|
await trackHelpUsage(mockCommand);
|
|
64
64
|
expect(mockedTrackUsage).not.toHaveBeenCalled();
|
|
65
65
|
});
|
|
@@ -82,7 +82,7 @@ describe('lib/usageTracking', () => {
|
|
|
82
82
|
describe('trackConvertFieldsUsage()', () => {
|
|
83
83
|
const mockCommand = 'convert-fields-command';
|
|
84
84
|
it('should not track when tracking is disabled', async () => {
|
|
85
|
-
|
|
85
|
+
mockedGetConfig.mockReturnValue({ allowUsageTracking: false });
|
|
86
86
|
await trackConvertFieldsUsage(mockCommand);
|
|
87
87
|
expect(mockedTrackUsage).not.toHaveBeenCalled();
|
|
88
88
|
});
|
|
@@ -104,7 +104,7 @@ describe('lib/usageTracking', () => {
|
|
|
104
104
|
const mockStep = 'init';
|
|
105
105
|
const mockAccountId = 123;
|
|
106
106
|
it('should not track when tracking is disabled', async () => {
|
|
107
|
-
|
|
107
|
+
mockedGetConfig.mockReturnValue({ allowUsageTracking: false });
|
|
108
108
|
await trackAuthAction(mockCommand, mockAuthType, mockStep, mockAccountId);
|
|
109
109
|
expect(mockedTrackUsage).not.toHaveBeenCalled();
|
|
110
110
|
});
|
|
@@ -127,7 +127,7 @@ describe('lib/usageTracking', () => {
|
|
|
127
127
|
const mockMeta = { assetType: 'test-asset' };
|
|
128
128
|
const mockAccountId = 123;
|
|
129
129
|
it('should not track when tracking is disabled', async () => {
|
|
130
|
-
|
|
130
|
+
mockedGetConfig.mockReturnValue({ allowUsageTracking: false });
|
|
131
131
|
await trackCommandMetadataUsage(mockCommand, mockMeta, mockAccountId);
|
|
132
132
|
expect(mockedTrackUsage).not.toHaveBeenCalled();
|
|
133
133
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConfigAccountById, getConfigAccountIfExists, } from '@hubspot/local-dev-lib/config';
|
|
2
2
|
import { getOauthManager } from '@hubspot/local-dev-lib/oauth';
|
|
3
3
|
import { accessTokenForPersonalAccessKey } from '@hubspot/local-dev-lib/personalAccessKey';
|
|
4
4
|
import { validateAccount } from '../validation.js';
|
|
@@ -14,47 +14,47 @@ const yargsOption = (option) => ({
|
|
|
14
14
|
...option,
|
|
15
15
|
});
|
|
16
16
|
describe('lib/validation', () => {
|
|
17
|
-
const
|
|
18
|
-
const
|
|
17
|
+
const getConfigAccountIfExistsMock = getConfigAccountIfExists;
|
|
18
|
+
const getConfigAccountByIdMock = getConfigAccountById;
|
|
19
19
|
const getOauthManagerMock = getOauthManager;
|
|
20
20
|
const accessTokenForPersonalAccessKeyMock = accessTokenForPersonalAccessKey;
|
|
21
21
|
describe('validateAccount', () => {
|
|
22
22
|
it('returns false if an account is missing', async () => {
|
|
23
|
-
|
|
24
|
-
expect(await validateAccount(yargsOption({
|
|
23
|
+
getConfigAccountIfExistsMock.mockReturnValueOnce(null);
|
|
24
|
+
expect(await validateAccount(yargsOption({ derivedAccountId: '123' }))).toBe(false);
|
|
25
25
|
});
|
|
26
26
|
it('returns false if an account config is missing', async () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
expect(await validateAccount(yargsOption({
|
|
27
|
+
getConfigAccountIfExistsMock.mockReturnValueOnce('123');
|
|
28
|
+
getConfigAccountByIdMock.mockReturnValueOnce(undefined);
|
|
29
|
+
expect(await validateAccount(yargsOption({ derivedAccountId: '123' }))).toBe(false);
|
|
30
30
|
});
|
|
31
31
|
it('returns false for oauth2 authType if auth is missing', async () => {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
getConfigAccountIfExistsMock.mockReturnValueOnce('123');
|
|
33
|
+
getConfigAccountByIdMock.mockReturnValueOnce({
|
|
34
34
|
accountId: '123',
|
|
35
35
|
authType: 'oauth2',
|
|
36
36
|
});
|
|
37
|
-
expect(await validateAccount(yargsOption({
|
|
37
|
+
expect(await validateAccount(yargsOption({ derivedAccountId: '123' }))).toBe(false);
|
|
38
38
|
});
|
|
39
39
|
it('returns false if OAuth is missing configuration', async () => {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
getConfigAccountIfExistsMock.mockReturnValueOnce('123');
|
|
41
|
+
getConfigAccountByIdMock.mockReturnValueOnce({
|
|
42
42
|
accountId: '123',
|
|
43
43
|
authType: 'oauth2',
|
|
44
44
|
auth: {
|
|
45
45
|
clientId: 'foo',
|
|
46
46
|
},
|
|
47
47
|
});
|
|
48
|
-
expect(await validateAccount(yargsOption({
|
|
48
|
+
expect(await validateAccount(yargsOption({ derivedAccountId: '123' }))).toBe(false);
|
|
49
49
|
});
|
|
50
50
|
it('returns false if an access token was not retrieved', async () => {
|
|
51
|
-
|
|
51
|
+
getConfigAccountIfExistsMock.mockReturnValueOnce('123');
|
|
52
52
|
getOauthManagerMock.mockReturnValueOnce({
|
|
53
53
|
accessToken() {
|
|
54
54
|
return null;
|
|
55
55
|
},
|
|
56
56
|
});
|
|
57
|
-
|
|
57
|
+
getConfigAccountByIdMock.mockReturnValueOnce({
|
|
58
58
|
accountId: '123',
|
|
59
59
|
authType: 'oauth2',
|
|
60
60
|
auth: {
|
|
@@ -65,16 +65,16 @@ describe('lib/validation', () => {
|
|
|
65
65
|
},
|
|
66
66
|
},
|
|
67
67
|
});
|
|
68
|
-
expect(await validateAccount(yargsOption({
|
|
68
|
+
expect(await validateAccount(yargsOption({ derivedAccountId: '123' }))).toBe(false);
|
|
69
69
|
});
|
|
70
70
|
it('returns false if an getting an access token throws', async () => {
|
|
71
|
-
|
|
71
|
+
getConfigAccountIfExistsMock.mockReturnValueOnce('123');
|
|
72
72
|
getOauthManagerMock.mockReturnValueOnce({
|
|
73
73
|
accessToken() {
|
|
74
74
|
throw new Error('It failed');
|
|
75
75
|
},
|
|
76
76
|
});
|
|
77
|
-
|
|
77
|
+
getConfigAccountByIdMock.mockReturnValueOnce({
|
|
78
78
|
accountId: '123',
|
|
79
79
|
authType: 'oauth2',
|
|
80
80
|
auth: {
|
|
@@ -85,16 +85,16 @@ describe('lib/validation', () => {
|
|
|
85
85
|
},
|
|
86
86
|
},
|
|
87
87
|
});
|
|
88
|
-
expect(await validateAccount(yargsOption({
|
|
88
|
+
expect(await validateAccount(yargsOption({ derivedAccountId: '123' }))).toBe(false);
|
|
89
89
|
});
|
|
90
90
|
it('returns true if OAuth is configured and an access token is received', async () => {
|
|
91
|
-
|
|
91
|
+
getConfigAccountIfExistsMock.mockReturnValueOnce('123');
|
|
92
92
|
getOauthManagerMock.mockReturnValueOnce({
|
|
93
93
|
accessToken() {
|
|
94
94
|
return 'yep';
|
|
95
95
|
},
|
|
96
96
|
});
|
|
97
|
-
|
|
97
|
+
getConfigAccountByIdMock.mockReturnValueOnce({
|
|
98
98
|
accountId: '123',
|
|
99
99
|
authType: 'oauth2',
|
|
100
100
|
auth: {
|
|
@@ -105,40 +105,40 @@ describe('lib/validation', () => {
|
|
|
105
105
|
},
|
|
106
106
|
},
|
|
107
107
|
});
|
|
108
|
-
expect(await validateAccount(yargsOption({
|
|
108
|
+
expect(await validateAccount(yargsOption({ derivedAccountId: '123' }))).toBe(true);
|
|
109
109
|
});
|
|
110
110
|
it('returns false if "personalaccesskey" configured and getting an access token throws', async () => {
|
|
111
|
-
|
|
111
|
+
getConfigAccountIfExistsMock.mockReturnValueOnce('123');
|
|
112
112
|
accessTokenForPersonalAccessKeyMock.mockImplementationOnce(() => {
|
|
113
113
|
throw new Error('It failed');
|
|
114
114
|
});
|
|
115
|
-
|
|
115
|
+
getConfigAccountByIdMock.mockReturnValueOnce({
|
|
116
116
|
accountId: '123',
|
|
117
117
|
authType: 'personalaccesskey',
|
|
118
118
|
personalAccessKey: 'foo',
|
|
119
119
|
});
|
|
120
|
-
expect(await validateAccount(yargsOption({
|
|
120
|
+
expect(await validateAccount(yargsOption({ derivedAccountId: '123' }))).toBe(false);
|
|
121
121
|
});
|
|
122
122
|
it('returns true if "personalaccesskey" configured and an access token is received', async () => {
|
|
123
|
-
|
|
123
|
+
getConfigAccountIfExistsMock.mockReturnValueOnce('123');
|
|
124
124
|
accessTokenForPersonalAccessKeyMock.mockImplementationOnce(() => {
|
|
125
125
|
return 'secret-stuff';
|
|
126
126
|
});
|
|
127
|
-
|
|
127
|
+
getConfigAccountByIdMock.mockReturnValueOnce({
|
|
128
128
|
accountId: '123',
|
|
129
129
|
authType: 'personalaccesskey',
|
|
130
130
|
personalAccessKey: 'foo',
|
|
131
131
|
});
|
|
132
|
-
expect(await validateAccount(yargsOption({
|
|
132
|
+
expect(await validateAccount(yargsOption({ derivedAccountId: '123' }))).toBe(true);
|
|
133
133
|
});
|
|
134
134
|
it('returns true if apiKey is configured and present', async () => {
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
getConfigAccountIfExistsMock.mockReturnValueOnce('123');
|
|
136
|
+
getConfigAccountByIdMock.mockReturnValueOnce({
|
|
137
137
|
accountId: '123',
|
|
138
138
|
authType: 'apikey',
|
|
139
139
|
apiKey: 'my-secret-key',
|
|
140
140
|
});
|
|
141
|
-
expect(await validateAccount(yargsOption({
|
|
141
|
+
expect(await validateAccount(yargsOption({ derivedAccountId: '123' }))).toBe(true);
|
|
142
142
|
});
|
|
143
143
|
});
|
|
144
144
|
});
|
package/lib/accountTypes.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function isStandardAccount(accountConfig:
|
|
3
|
-
export declare function isSandbox(accountConfig:
|
|
4
|
-
export declare function isStandardSandbox(accountConfig:
|
|
5
|
-
export declare function isDevelopmentSandbox(accountConfig:
|
|
6
|
-
export declare function isDeveloperTestAccount(accountConfig:
|
|
7
|
-
export declare function isAppDeveloperAccount(accountConfig:
|
|
8
|
-
export declare function isTestAccountOrSandbox(accountConfig:
|
|
9
|
-
export declare function isUnifiedAccount(account:
|
|
1
|
+
import { HubSpotConfigAccount } from '@hubspot/local-dev-lib/types/Accounts';
|
|
2
|
+
export declare function isStandardAccount(accountConfig: HubSpotConfigAccount): boolean;
|
|
3
|
+
export declare function isSandbox(accountConfig: HubSpotConfigAccount): boolean;
|
|
4
|
+
export declare function isStandardSandbox(accountConfig: HubSpotConfigAccount): boolean;
|
|
5
|
+
export declare function isDevelopmentSandbox(accountConfig: HubSpotConfigAccount): boolean;
|
|
6
|
+
export declare function isDeveloperTestAccount(accountConfig: HubSpotConfigAccount): boolean;
|
|
7
|
+
export declare function isAppDeveloperAccount(accountConfig: HubSpotConfigAccount): boolean;
|
|
8
|
+
export declare function isTestAccountOrSandbox(accountConfig: HubSpotConfigAccount): boolean;
|
|
9
|
+
export declare function isUnifiedAccount(account: HubSpotConfigAccount): Promise<boolean>;
|
package/lib/accountTypes.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { HUBSPOT_ACCOUNT_TYPES } from '@hubspot/local-dev-lib/constants/config';
|
|
2
2
|
import { hasUnfiedAppsAccess } from './hasFeature.js';
|
|
3
|
-
import { getAccountIdentifier } from '@hubspot/local-dev-lib/config/getAccountIdentifier';
|
|
4
3
|
function isAccountType(accountConfig, accountType) {
|
|
5
4
|
return Boolean(accountConfig.accountType && accountType.includes(accountConfig.accountType));
|
|
6
5
|
}
|
|
@@ -35,9 +34,8 @@ export function isTestAccountOrSandbox(accountConfig) {
|
|
|
35
34
|
]);
|
|
36
35
|
}
|
|
37
36
|
export async function isUnifiedAccount(account) {
|
|
38
|
-
|
|
39
|
-
if (!accountId) {
|
|
37
|
+
if (!account.accountId) {
|
|
40
38
|
return false;
|
|
41
39
|
}
|
|
42
|
-
return hasUnfiedAppsAccess(accountId);
|
|
40
|
+
return hasUnfiedAppsAccess(account.accountId);
|
|
43
41
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { uiLogger } from '../../ui/logger.js';
|
|
2
2
|
import { getCwd, sanitizeFileName } from '@hubspot/local-dev-lib/path';
|
|
3
3
|
import { extractZipArchive } from '@hubspot/local-dev-lib/archive';
|
|
4
|
+
import { getConfigAccountById } from '@hubspot/local-dev-lib/config';
|
|
4
5
|
import { validateUid } from '@hubspot/project-parsing-lib';
|
|
5
6
|
import { UNMIGRATABLE_REASONS } from '@hubspot/local-dev-lib/constants/projects';
|
|
6
7
|
import { MIGRATION_STATUS } from '@hubspot/local-dev-lib/types/Migration';
|
|
@@ -26,6 +27,7 @@ vi.mock('../../ui/SpinniesManager');
|
|
|
26
27
|
vi.mock('../../polling');
|
|
27
28
|
vi.mock('../../../api/migrate');
|
|
28
29
|
vi.mock('../../hasFeature');
|
|
30
|
+
vi.mock('@hubspot/local-dev-lib/config');
|
|
29
31
|
vi.mock('../../projects/urls');
|
|
30
32
|
vi.mock('fs');
|
|
31
33
|
const mockedUiLogger = uiLogger;
|
|
@@ -34,6 +36,7 @@ const mockedSanitizeFileName = sanitizeFileName;
|
|
|
34
36
|
const mockedExtractZipArchive = extractZipArchive;
|
|
35
37
|
const mockedValidateUid = validateUid;
|
|
36
38
|
const mockedDownloadProject = downloadProject;
|
|
39
|
+
const mockedGetConfigAccountById = getConfigAccountById;
|
|
37
40
|
const mockedConfirmPrompt = confirmPrompt;
|
|
38
41
|
const mockedInputPrompt = inputPrompt;
|
|
39
42
|
const mockedListPrompt = listPrompt;
|
|
@@ -83,6 +86,18 @@ describe('lib/app/migrate', () => {
|
|
|
83
86
|
mockedValidateUid.mockReturnValue(undefined);
|
|
84
87
|
mockedHasUnfiedAppsAccess.mockResolvedValue(true);
|
|
85
88
|
mockedFs.renameSync.mockImplementation(() => { });
|
|
89
|
+
// Mock account config for the test account ID
|
|
90
|
+
mockedGetConfigAccountById.mockReturnValue({
|
|
91
|
+
accountId: ACCOUNT_ID,
|
|
92
|
+
name: 'Test Account',
|
|
93
|
+
authType: 'personalaccesskey',
|
|
94
|
+
auth: {
|
|
95
|
+
tokenInfo: {
|
|
96
|
+
accessToken: 'test-token',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
env: 'prod',
|
|
100
|
+
});
|
|
86
101
|
});
|
|
87
102
|
describe('getUnmigratableReason', () => {
|
|
88
103
|
const testCases = [
|
|
@@ -9,6 +9,7 @@ import { projectNameAndDestPrompt as _projectNameAndDestPrompt } from '../../pro
|
|
|
9
9
|
import { ensureProjectExists as _ensureProjectExists } from '../../projects/ensureProjectExists.js';
|
|
10
10
|
import { poll as _poll } from '../../polling.js';
|
|
11
11
|
import { migrateApp2023_2 } from '../migrate_legacy.js';
|
|
12
|
+
import { getConfigAccountById } from '@hubspot/local-dev-lib/config';
|
|
12
13
|
// Mock all external dependencies
|
|
13
14
|
vi.mock('@hubspot/local-dev-lib/api/appsDev');
|
|
14
15
|
vi.mock('../../ui/logger.js');
|
|
@@ -26,6 +27,7 @@ vi.mock('../../usageTracking');
|
|
|
26
27
|
vi.mock('../../ui/SpinniesManager');
|
|
27
28
|
vi.mock('../../process');
|
|
28
29
|
vi.mock('../../polling');
|
|
30
|
+
vi.mock('@hubspot/local-dev-lib/config');
|
|
29
31
|
const isAppDeveloperAccount = _isAppDeveloperAccount;
|
|
30
32
|
const isUnifiedAccount = _isUnifiedAccount;
|
|
31
33
|
const selectPublicAppForMigrationPrompt = _selectPublicAppForMigrationPrompt;
|
|
@@ -57,6 +59,13 @@ describe('migrateApp2023_2', () => {
|
|
|
57
59
|
beforeEach(() => {
|
|
58
60
|
// @ts-expect-error function mismatch
|
|
59
61
|
vi.spyOn(process, 'exit').mockImplementation(() => { });
|
|
62
|
+
getConfigAccountById.mockReturnValue({
|
|
63
|
+
accountId: mockDerivedAccountId,
|
|
64
|
+
name: 'Test Account',
|
|
65
|
+
authType: 'personalaccesskey',
|
|
66
|
+
personalAccessKey: 'test-key',
|
|
67
|
+
env: 'prod',
|
|
68
|
+
});
|
|
60
69
|
selectPublicAppForMigrationPrompt.mockResolvedValue({
|
|
61
70
|
appId,
|
|
62
71
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HubSpotConfigAccount } from '@hubspot/local-dev-lib/types/Accounts';
|
|
2
2
|
import { ArgumentsCamelCase } from 'yargs';
|
|
3
3
|
import { MigrateAppArgs } from './migrate.js';
|
|
4
|
-
export declare function migrateApp2023_2(derivedAccountId: number, options: ArgumentsCamelCase<MigrateAppArgs>, accountConfig:
|
|
4
|
+
export declare function migrateApp2023_2(derivedAccountId: number, options: ArgumentsCamelCase<MigrateAppArgs>, accountConfig: HubSpotConfigAccount): Promise<void>;
|
package/lib/buildAccount.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeveloperTestAccountConfig } from '@hubspot/local-dev-lib/types/developerTestAccounts';
|
|
2
2
|
import { Environment } from '@hubspot/local-dev-lib/types/Config';
|
|
3
|
-
import {
|
|
3
|
+
import { HubSpotConfigAccount } from '@hubspot/local-dev-lib/types/Accounts';
|
|
4
4
|
import { SandboxResponse, V2Sandbox } from '@hubspot/local-dev-lib/types/Sandbox';
|
|
5
5
|
import { SandboxAccountType } from '../types/Sandboxes.js';
|
|
6
6
|
export declare function saveAccountToConfig(accountId: number | undefined, accountName: string, env: Environment, personalAccessKey?: string, force?: boolean): Promise<string>;
|
|
@@ -9,12 +9,12 @@ export declare function createDeveloperTestAccountV2(parentAccountId: number, te
|
|
|
9
9
|
accountId?: number;
|
|
10
10
|
personalAccessKey?: string;
|
|
11
11
|
}>;
|
|
12
|
-
export declare function buildDeveloperTestAccount(testAccountName: string, parentAccountConfig:
|
|
12
|
+
export declare function buildDeveloperTestAccount(testAccountName: string, parentAccountConfig: HubSpotConfigAccount, env: Environment, portalLimit: number, useV2?: boolean): Promise<number>;
|
|
13
13
|
type SandboxAccount = SandboxResponse & {
|
|
14
14
|
name: string;
|
|
15
15
|
};
|
|
16
|
-
export declare function buildSandbox(sandboxName: string, parentAccountConfig:
|
|
17
|
-
export declare function buildV2Sandbox(sandboxName: string, parentAccountConfig:
|
|
16
|
+
export declare function buildSandbox(sandboxName: string, parentAccountConfig: HubSpotConfigAccount, sandboxType: SandboxAccountType, env: Environment, force?: boolean): Promise<SandboxAccount>;
|
|
17
|
+
export declare function buildV2Sandbox(sandboxName: string, parentAccountConfig: HubSpotConfigAccount, sandboxType: SandboxAccountType, syncObjectRecords: boolean, env: Environment, force?: boolean): Promise<{
|
|
18
18
|
sandbox: V2Sandbox;
|
|
19
19
|
}>;
|
|
20
20
|
export {};
|
package/lib/buildAccount.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getAccessToken, updateConfigWithAccessToken, } from '@hubspot/local-dev-lib/personalAccessKey';
|
|
2
|
-
import {
|
|
3
|
-
import { getAccountIdentifier } from '@hubspot/local-dev-lib/config/getAccountIdentifier';
|
|
2
|
+
import { getConfigAccountIfExists, updateConfigAccount, } from '@hubspot/local-dev-lib/config';
|
|
4
3
|
import { uiLogger } from './ui/logger.js';
|
|
5
4
|
import { createDeveloperTestAccount, fetchDeveloperTestAccountGateSyncStatus, generateDeveloperTestAccountPersonalAccessKey, } from '@hubspot/local-dev-lib/api/developerTestAccounts';
|
|
6
5
|
import { HUBSPOT_ACCOUNT_TYPES } from '@hubspot/local-dev-lib/constants/config';
|
|
@@ -28,8 +27,8 @@ export async function saveAccountToConfig(accountId, accountName, env, personalA
|
|
|
28
27
|
if (!updatedConfig?.name) {
|
|
29
28
|
const nameForConfig = accountName.toLowerCase().split(' ').join('-');
|
|
30
29
|
validName = nameForConfig;
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
30
|
+
const existingAccount = getConfigAccountIfExists(nameForConfig);
|
|
31
|
+
if (existingAccount) {
|
|
33
32
|
if (!force) {
|
|
34
33
|
uiLogger.log('');
|
|
35
34
|
uiLogger.warn(lib.prompts.accountNamePrompt.errors.accountNameExists(nameForConfig));
|
|
@@ -42,13 +41,10 @@ export async function saveAccountToConfig(accountId, accountName, env, personalA
|
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
|
|
44
|
+
updateConfigAccount({
|
|
46
45
|
...updatedConfig,
|
|
47
|
-
env: updatedConfig?.env,
|
|
48
|
-
tokenInfo: updatedConfig?.auth?.tokenInfo,
|
|
49
46
|
name: validName,
|
|
50
47
|
});
|
|
51
|
-
writeConfig();
|
|
52
48
|
uiLogger.log('');
|
|
53
49
|
return validName;
|
|
54
50
|
}
|
|
@@ -83,8 +79,7 @@ export async function createDeveloperTestAccountV2(parentAccountId, testAccountC
|
|
|
83
79
|
return result;
|
|
84
80
|
}
|
|
85
81
|
export async function buildDeveloperTestAccount(testAccountName, parentAccountConfig, env, portalLimit, useV2 = false) {
|
|
86
|
-
const
|
|
87
|
-
const parentAccountId = getAccountId(id);
|
|
82
|
+
const parentAccountId = parentAccountConfig.accountId;
|
|
88
83
|
let testAccountConfig = {
|
|
89
84
|
accountName: testAccountName,
|
|
90
85
|
};
|
|
@@ -141,8 +136,7 @@ export async function buildSandbox(sandboxName, parentAccountConfig, sandboxType
|
|
|
141
136
|
const sandboxTypeKey = sandboxType === HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX
|
|
142
137
|
? 'standard'
|
|
143
138
|
: 'developer';
|
|
144
|
-
const
|
|
145
|
-
const parentAccountId = getAccountId(id);
|
|
139
|
+
const parentAccountId = parentAccountConfig.accountId;
|
|
146
140
|
if (!parentAccountId) {
|
|
147
141
|
throw new Error(lib.sandbox.create[sandboxTypeKey].loading.fail(''));
|
|
148
142
|
}
|
|
@@ -182,8 +176,7 @@ export async function buildV2Sandbox(sandboxName, parentAccountConfig, sandboxTy
|
|
|
182
176
|
const sandboxTypeKey = sandboxType === HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX
|
|
183
177
|
? 'standard'
|
|
184
178
|
: 'developer';
|
|
185
|
-
const
|
|
186
|
-
const parentAccountId = getAccountId(id);
|
|
179
|
+
const parentAccountId = parentAccountConfig.accountId;
|
|
187
180
|
if (!parentAccountId) {
|
|
188
181
|
throw new Error(lib.sandbox.create[sandboxTypeKey].loading.fail(''));
|
|
189
182
|
}
|
package/lib/commonOpts.js
CHANGED
|
@@ -3,7 +3,7 @@ import yargsParser from 'yargs-parser';
|
|
|
3
3
|
import { LOG_LEVEL, setLogLevel } from '@hubspot/local-dev-lib/logger';
|
|
4
4
|
import { uiLogger } from './ui/logger.js';
|
|
5
5
|
import { DEFAULT_CMS_PUBLISH_MODE, CMS_PUBLISH_MODE, } from '@hubspot/local-dev-lib/constants/files';
|
|
6
|
-
import {
|
|
6
|
+
import { getConfigAccountById, getConfig } from '@hubspot/local-dev-lib/config';
|
|
7
7
|
import { debugError } from './errorHandlers/index.js';
|
|
8
8
|
import { EXIT_CODES } from './enums/exitCodes.js';
|
|
9
9
|
import { uiCommandReference } from './ui/index.js';
|
|
@@ -168,14 +168,14 @@ export function getCmsPublishMode(options) {
|
|
|
168
168
|
}
|
|
169
169
|
// 2. config[account].defaultCmsPublishMode
|
|
170
170
|
if (options.derivedAccountId) {
|
|
171
|
-
const accountConfig =
|
|
171
|
+
const accountConfig = getConfigAccountById(options.derivedAccountId);
|
|
172
172
|
if (accountConfig && accountConfig.defaultCmsPublishMode) {
|
|
173
173
|
return accountConfig.defaultCmsPublishMode;
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
// 3. config.defaultCmsPublishMode
|
|
177
177
|
// 4. DEFAULT_CMS_PUBLISH_MODE
|
|
178
|
-
const config =
|
|
178
|
+
const config = getConfig();
|
|
179
179
|
return ((config && config.defaultCmsPublishMode) ||
|
|
180
180
|
DEFAULT_CMS_PUBLISH_MODE);
|
|
181
181
|
}
|
package/lib/configMigrate.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function handleMigration(
|
|
2
|
-
export declare function handleMerge(
|
|
1
|
+
export declare function handleMigration(hideWarning?: boolean): Promise<boolean>;
|
|
2
|
+
export declare function handleMerge(force?: boolean, hideWarning?: boolean): Promise<boolean>;
|
package/lib/configMigrate.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConfigAtPath, migrateConfigAtPath, mergeConfigProperties, mergeConfigAccounts, archiveConfigAtPath, } from '@hubspot/local-dev-lib/config/migrate';
|
|
2
2
|
import { ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME } from '@hubspot/local-dev-lib/constants/config';
|
|
3
3
|
import { promptUser } from './prompts/promptUtils.js';
|
|
4
4
|
import { lib } from '../lang/en.js';
|
|
5
5
|
import { uiLogger } from './ui/logger.js';
|
|
6
|
+
import { getConfig, getLocalConfigFilePathIfExists, } from '@hubspot/local-dev-lib/config';
|
|
7
|
+
import { debugError } from './errorHandlers/index.js';
|
|
6
8
|
async function promptRenameOrOmitAccount(accountName, accountId) {
|
|
7
9
|
const { shouldRename } = await promptUser({
|
|
8
10
|
name: 'shouldRename',
|
|
@@ -24,7 +26,7 @@ async function promptNewAccountName(account, globalConfig, renamedAccounts) {
|
|
|
24
26
|
if (value === account.name) {
|
|
25
27
|
return lib.configMigrate.handleAccountNameConflicts.errors.sameName;
|
|
26
28
|
}
|
|
27
|
-
const existingAccount = globalConfig.accounts
|
|
29
|
+
const existingAccount = globalConfig.accounts.some((acc) => acc.name === value);
|
|
28
30
|
const renamedAccount = renamedAccounts.some(acc => acc.name === value);
|
|
29
31
|
if (existingAccount || renamedAccount) {
|
|
30
32
|
return lib.configMigrate.handleAccountNameConflicts.errors.nameAlreadyInConfig(value);
|
|
@@ -34,9 +36,10 @@ async function promptNewAccountName(account, globalConfig, renamedAccounts) {
|
|
|
34
36
|
});
|
|
35
37
|
return newAccountName;
|
|
36
38
|
}
|
|
37
|
-
export async function handleMigration(
|
|
39
|
+
export async function handleMigration(hideWarning) {
|
|
40
|
+
const deprecatedConfigPath = process.env.HUBSPOT_CONFIG_PATH || getLocalConfigFilePathIfExists();
|
|
38
41
|
if (!hideWarning) {
|
|
39
|
-
uiLogger.warn(lib.configMigrate.deprecatedConfigWarning(deprecatedConfigPath ||
|
|
42
|
+
uiLogger.warn(lib.configMigrate.deprecatedConfigWarning(deprecatedConfigPath || ''));
|
|
40
43
|
uiLogger.log('');
|
|
41
44
|
}
|
|
42
45
|
uiLogger.log(lib.configMigrate.handleMigration.description(ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME));
|
|
@@ -49,13 +52,20 @@ export async function handleMigration(deprecatedConfigPath, hideWarning) {
|
|
|
49
52
|
if (!shouldMigrateConfig) {
|
|
50
53
|
return false;
|
|
51
54
|
}
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
migrateConfigAtPath(deprecatedConfigPath || '');
|
|
56
|
+
try {
|
|
57
|
+
archiveConfigAtPath(deprecatedConfigPath);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
debugError(error);
|
|
61
|
+
uiLogger.error(lib.configMigrate.errors.archive(deprecatedConfigPath));
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
54
64
|
uiLogger.success(lib.configMigrate.handleMigration.success);
|
|
55
65
|
return true;
|
|
56
66
|
}
|
|
57
67
|
async function handleMergeConfigProperties(globalConfig, deprecatedConfig, force) {
|
|
58
|
-
const {
|
|
68
|
+
const { configWithMergedProperties, conflicts, } = mergeConfigProperties(globalConfig, deprecatedConfig, force);
|
|
59
69
|
if (conflicts.length > 0) {
|
|
60
70
|
const properties = conflicts.map(c => c.property);
|
|
61
71
|
const propertyList = properties.length <= 2
|
|
@@ -68,15 +78,15 @@ async function handleMergeConfigProperties(globalConfig, deprecatedConfig, force
|
|
|
68
78
|
const { shouldOverwrite } = await promptUser({
|
|
69
79
|
name: 'shouldOverwrite',
|
|
70
80
|
type: 'confirm',
|
|
71
|
-
message: lib.configMigrate.handleMergeConfigProperties.mergeConfigConflictPrompt(property, newValue.toString(), oldValue
|
|
81
|
+
message: lib.configMigrate.handleMergeConfigProperties.mergeConfigConflictPrompt(property, newValue.toString(), oldValue?.toString() || ''),
|
|
72
82
|
});
|
|
73
83
|
if (shouldOverwrite) {
|
|
74
84
|
// @ts-expect-error Cannot reconcile CLIConfig_NEW and CLIConfig_DEPRECATED
|
|
75
|
-
|
|
85
|
+
configWithMergedProperties[property] = oldValue;
|
|
76
86
|
}
|
|
77
87
|
}
|
|
78
88
|
}
|
|
79
|
-
return
|
|
89
|
+
return configWithMergedProperties;
|
|
80
90
|
}
|
|
81
91
|
async function handleAccountNameConflicts(globalConfig, deprecatedConfig, force) {
|
|
82
92
|
if (!deprecatedConfig.portals?.length || !globalConfig.accounts?.length) {
|
|
@@ -84,7 +94,7 @@ async function handleAccountNameConflicts(globalConfig, deprecatedConfig, force)
|
|
|
84
94
|
}
|
|
85
95
|
const accountsWithConflictsToRemove = new Set();
|
|
86
96
|
const renamedAccounts = [];
|
|
87
|
-
const accountsNotYetInGlobal = deprecatedConfig.portals.filter(portal => portal.portalId &&
|
|
97
|
+
const accountsNotYetInGlobal = (deprecatedConfig.portals || []).filter(portal => portal.portalId &&
|
|
88
98
|
!globalConfig.accounts?.some(acc => acc.accountId === portal.portalId));
|
|
89
99
|
const accountsWithConflicts = accountsNotYetInGlobal.filter(localAccount => globalConfig.accounts?.some(globalAccount => globalAccount.name === localAccount.name));
|
|
90
100
|
if (accountsWithConflicts.length > 0) {
|
|
@@ -120,12 +130,13 @@ async function handleAccountNameConflicts(globalConfig, deprecatedConfig, force)
|
|
|
120
130
|
}
|
|
121
131
|
deprecatedConfig.portals.push(...renamedAccounts);
|
|
122
132
|
}
|
|
123
|
-
const cleanedPortals = deprecatedConfig.portals.filter(portal => !accountsWithConflictsToRemove.has(portal));
|
|
133
|
+
const cleanedPortals = (deprecatedConfig.portals || []).filter(portal => !accountsWithConflictsToRemove.has(portal));
|
|
124
134
|
return { ...deprecatedConfig, portals: cleanedPortals };
|
|
125
135
|
}
|
|
126
|
-
export async function handleMerge(
|
|
136
|
+
export async function handleMerge(force, hideWarning) {
|
|
137
|
+
const deprecatedConfigPath = process.env.HUBSPOT_CONFIG_PATH || getLocalConfigFilePathIfExists();
|
|
127
138
|
if (!hideWarning) {
|
|
128
|
-
uiLogger.warn(lib.configMigrate.deprecatedConfigWarning(deprecatedConfigPath ||
|
|
139
|
+
uiLogger.warn(lib.configMigrate.deprecatedConfigWarning(deprecatedConfigPath || ''));
|
|
129
140
|
uiLogger.log('');
|
|
130
141
|
}
|
|
131
142
|
uiLogger.log(lib.configMigrate.handleMerge.description(ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME));
|
|
@@ -140,19 +151,32 @@ export async function handleMerge(deprecatedConfigPath, force, hideWarning) {
|
|
|
140
151
|
return true; // exit with "true" so the user is shown a success message instead of an error
|
|
141
152
|
}
|
|
142
153
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
154
|
+
let deprecatedConfig;
|
|
155
|
+
let globalConfig;
|
|
156
|
+
try {
|
|
157
|
+
deprecatedConfig = getConfigAtPath(deprecatedConfigPath || '');
|
|
158
|
+
globalConfig = getConfig();
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
debugError(error);
|
|
146
162
|
return true;
|
|
147
163
|
}
|
|
148
164
|
const mergedConfig = await handleMergeConfigProperties(globalConfig, deprecatedConfig, force);
|
|
149
165
|
const cleanedDeprecatedConfig = await handleAccountNameConflicts(mergedConfig, deprecatedConfig, force);
|
|
150
|
-
const { skippedAccountIds } =
|
|
166
|
+
const { skippedAccountIds } = mergeConfigAccounts(mergedConfig, cleanedDeprecatedConfig);
|
|
151
167
|
if (skippedAccountIds.length > 0) {
|
|
152
168
|
uiLogger.log('');
|
|
153
169
|
uiLogger.log(lib.configMigrate.handleMerge.skippedExistingAccounts(skippedAccountIds));
|
|
154
170
|
uiLogger.log('');
|
|
155
171
|
}
|
|
172
|
+
try {
|
|
173
|
+
archiveConfigAtPath(deprecatedConfigPath);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
debugError(error);
|
|
177
|
+
uiLogger.error(lib.configMigrate.errors.archive(deprecatedConfigPath));
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
156
180
|
uiLogger.success(lib.configMigrate.handleMerge.success);
|
|
157
181
|
return true;
|
|
158
182
|
}
|
package/lib/configOptions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { updateAllowUsageTracking, updateAllowAutoUpdates, updateDefaultCmsPublishMode, updateHttpTimeout,
|
|
1
|
+
import { updateAllowUsageTracking, updateAllowAutoUpdates, updateDefaultCmsPublishMode, updateHttpTimeout, updateAutoOpenBrowser, getConfig, } from '@hubspot/local-dev-lib/config';
|
|
2
2
|
import { CMS_PUBLISH_MODE } from '@hubspot/local-dev-lib/constants/files';
|
|
3
3
|
import { commaSeparatedValues } from '@hubspot/local-dev-lib/text';
|
|
4
4
|
import { trackCommandUsage } from './usageTracking.js';
|
|
@@ -110,5 +110,6 @@ export async function setAutoOpenBrowser({ accountId, autoOpenBrowser, }) {
|
|
|
110
110
|
: lib.configOptions.setAutoOpenBrowser.disabled);
|
|
111
111
|
}
|
|
112
112
|
export function isAutoOpenBrowserEnabled() {
|
|
113
|
-
|
|
113
|
+
const config = getConfig();
|
|
114
|
+
return config?.autoOpenBrowser !== false; // Default to true
|
|
114
115
|
}
|