@hubspot/cli 5.4.0 → 5.4.1-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.
Files changed (35) hide show
  1. package/commands/__tests__/projects.test.js +105 -0
  2. package/commands/accounts/clean.js +1 -1
  3. package/commands/project/__tests__/deploy.test.js +1 -1
  4. package/commands/project/__tests__/installDeps.test.js +168 -0
  5. package/commands/project/__tests__/logs.test.js +305 -0
  6. package/commands/project/cloneApp.js +3 -16
  7. package/commands/project/deploy.js +4 -1
  8. package/commands/project/dev.js +15 -6
  9. package/commands/project/download.js +4 -1
  10. package/commands/project/installDeps.js +78 -0
  11. package/commands/project/logs.js +80 -242
  12. package/commands/project/migrateApp.js +3 -6
  13. package/commands/project/upload.js +5 -3
  14. package/commands/project/watch.js +3 -9
  15. package/commands/project.js +2 -0
  16. package/commands/sandbox/create.js +1 -0
  17. package/commands/sandbox.js +0 -2
  18. package/lang/en.lyaml +25 -70
  19. package/lib/LocalDevManager.js +1 -22
  20. package/lib/__tests__/dependencyManagement.test.js +245 -0
  21. package/lib/__tests__/projectLogsManager.test.js +210 -0
  22. package/lib/dependencyManagement.js +157 -0
  23. package/lib/errorHandlers/apiErrors.js +1 -3
  24. package/lib/errorHandlers/overrideErrors.js +57 -36
  25. package/lib/localDev.js +1 -7
  26. package/lib/projectLogsManager.js +144 -0
  27. package/lib/projects.js +3 -6
  28. package/lib/projectsWatch.js +2 -5
  29. package/lib/prompts/__tests__/projectsLogsPrompt.test.js +46 -0
  30. package/lib/prompts/createProjectPrompt.js +4 -0
  31. package/lib/prompts/projectDevTargetAccountPrompt.js +16 -25
  32. package/lib/prompts/projectsLogsPrompt.js +17 -108
  33. package/lib/sandboxSync.js +13 -15
  34. package/package.json +6 -6
  35. package/commands/sandbox/sync.js +0 -225
@@ -0,0 +1,105 @@
1
+ const { command, describe: projectDescribe, builder } = require('../project');
2
+
3
+ jest.mock('../project/deploy');
4
+ jest.mock('../project/create');
5
+ jest.mock('../project/upload');
6
+ jest.mock('../project/listBuilds');
7
+ jest.mock('../project/logs');
8
+ jest.mock('../project/watch');
9
+ jest.mock('../project/download');
10
+ jest.mock('../project/open');
11
+ jest.mock('../project/dev');
12
+ jest.mock('../project/add');
13
+ jest.mock('../project/migrateApp');
14
+ jest.mock('../project/cloneApp');
15
+ jest.mock('../project/installDeps');
16
+ jest.mock('../../lib/commonOpts');
17
+
18
+ const deploy = require('../project/deploy');
19
+ const create = require('../project/create');
20
+ const upload = require('../project/upload');
21
+ const listBuilds = require('../project/listBuilds');
22
+ const logs = require('../project/logs');
23
+ const watch = require('../project/watch');
24
+ const download = require('../project/download');
25
+ const open = require('../project/open');
26
+ const dev = require('../project/dev');
27
+ const add = require('../project/add');
28
+ const migrateApp = require('../project/migrateApp');
29
+ const cloneApp = require('../project/cloneApp');
30
+ const installDeps = require('../project/installDeps');
31
+ const { addConfigOptions, addAccountOptions } = require('../../lib/commonOpts');
32
+
33
+ describe('commands/projects', () => {
34
+ describe('command', () => {
35
+ it('should have the correct command structure', () => {
36
+ expect(command).toEqual('project');
37
+ });
38
+ });
39
+
40
+ describe('describe', () => {
41
+ it('should contain the beta tag', () => {
42
+ expect(projectDescribe).toContain('[BETA]');
43
+ });
44
+ it('should provide an accurate description of what the command is doing', () => {
45
+ expect(projectDescribe).toContain(
46
+ 'Commands for working with projects. For more information, visit our documentation: https://developers.hubspot.com/docs/platform/build-and-deploy-using-hubspot-projects'
47
+ );
48
+ });
49
+ });
50
+
51
+ describe('builder', () => {
52
+ let yargs;
53
+
54
+ const subcommands = [
55
+ ['create', create],
56
+ ['add', add],
57
+ ['watch', watch],
58
+ ['dev', dev],
59
+ ['upload', upload],
60
+ ['deploy', deploy],
61
+ ['logs', logs],
62
+ ['listBuilds', listBuilds],
63
+ ['download', download],
64
+ ['open', open],
65
+ ['migrateApp', migrateApp],
66
+ ['cloneApp', cloneApp],
67
+ ['installDeps', installDeps],
68
+ ];
69
+
70
+ beforeEach(() => {
71
+ yargs = {
72
+ command: jest.fn().mockImplementation(() => yargs),
73
+ demandCommand: jest.fn().mockImplementation(() => yargs),
74
+ };
75
+ });
76
+
77
+ it('should add the config options', () => {
78
+ builder(yargs);
79
+ expect(addConfigOptions).toHaveBeenCalledTimes(1);
80
+ expect(addConfigOptions).toHaveBeenCalledWith(yargs);
81
+ });
82
+
83
+ it('should add the account options', () => {
84
+ builder(yargs);
85
+ expect(addAccountOptions).toHaveBeenCalledTimes(1);
86
+ expect(addAccountOptions).toHaveBeenCalledWith(yargs);
87
+ });
88
+
89
+ it('should add the correct number of sub commands', () => {
90
+ builder(yargs);
91
+ expect(yargs.command).toHaveBeenCalledTimes(subcommands.length);
92
+ });
93
+
94
+ it.each(subcommands)('should attach the %s subcommand', (name, module) => {
95
+ builder(yargs);
96
+ expect(yargs.command).toHaveBeenCalledWith(module);
97
+ });
98
+
99
+ it('should demand the command takes one positional argument', () => {
100
+ builder(yargs);
101
+ expect(yargs.demandCommand).toHaveBeenCalledTimes(1);
102
+ expect(yargs.demandCommand).toHaveBeenCalledWith(1, '');
103
+ });
104
+ });
105
+ });
@@ -54,7 +54,7 @@ exports.handler = async options => {
54
54
 
55
55
  for (const account of filteredTestAccounts) {
56
56
  try {
57
- await accessTokenForPersonalAccessKey(account.portalId);
57
+ await accessTokenForPersonalAccessKey(account.portalId, true);
58
58
  } catch (error) {
59
59
  if (
60
60
  isSpecifiedHubSpotAuthError(error, {
@@ -423,7 +423,7 @@ describe('commands/project/deploy', () => {
423
423
 
424
424
  expect(logger.error).toHaveBeenCalledTimes(1);
425
425
  expect(logger.error).toHaveBeenCalledWith(
426
- `The request in account ${accountId} failed due to a client error.`
426
+ `The request for 'project deploy' in account ${accountId} failed due to a client error.`
427
427
  );
428
428
  expect(processExitSpy).toHaveBeenCalledTimes(1);
429
429
  expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
@@ -0,0 +1,168 @@
1
+ jest.mock('../../../lib/projects');
2
+ jest.mock('@hubspot/local-dev-lib/logger');
3
+ jest.mock('../../../lib/dependencyManagement');
4
+ jest.mock('../../../lib/prompts/promptUtils');
5
+ jest.mock('../../../lib/usageTracking');
6
+ jest.mock('../../../lib/commonOpts');
7
+
8
+ const { getProjectConfig } = require('../../../lib/projects');
9
+ const { EXIT_CODES } = require('../../../lib/enums/exitCodes');
10
+ const { logger } = require('@hubspot/local-dev-lib/logger');
11
+ const { trackCommandUsage } = require('../../../lib/usageTracking');
12
+ const { getAccountId } = require('../../../lib/commonOpts');
13
+ const {
14
+ installPackages,
15
+ getProjectPackageJsonLocations,
16
+ } = require('../../../lib/dependencyManagement');
17
+ const { promptUser } = require('../../../lib/prompts/promptUtils');
18
+ const {
19
+ command,
20
+ describe: installDepsDescribe,
21
+ builder,
22
+ handler,
23
+ } = require('../installDeps');
24
+ const path = require('path');
25
+
26
+ describe('commands/project/installDeps', () => {
27
+ describe('command', () => {
28
+ it('should have the correct command string', () => {
29
+ expect(command).toEqual('install-deps [packages..]');
30
+ });
31
+ });
32
+
33
+ describe('describe', () => {
34
+ it('should have the correct description', () => {
35
+ expect(installDepsDescribe).toEqual(null);
36
+ });
37
+ });
38
+
39
+ describe('builder', () => {
40
+ let yargs;
41
+ beforeEach(() => {
42
+ yargs = {
43
+ example: jest.fn().mockImplementation(() => yargs),
44
+ };
45
+ });
46
+
47
+ it('should add correct examples', () => {
48
+ builder(yargs);
49
+ expect(yargs.example).toHaveBeenCalledTimes(1);
50
+ expect(yargs.example).toHaveBeenCalledWith([
51
+ ['$0 project install-deps', 'Install the dependencies for the project'],
52
+ [
53
+ '$0 project install-deps dependency1 dependency2',
54
+ 'Install the dependencies to one or more project subcomponents',
55
+ ],
56
+ ]);
57
+ });
58
+ });
59
+
60
+ describe('handler', () => {
61
+ let processExitSpy;
62
+
63
+ beforeEach(() => {
64
+ processExitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {});
65
+ });
66
+
67
+ it('should track the command usage', async () => {
68
+ const accountId = 999999;
69
+ getAccountId.mockReturnValue(accountId);
70
+ await handler({});
71
+
72
+ expect(getAccountId).toHaveBeenCalledTimes(1);
73
+ expect(trackCommandUsage).toHaveBeenCalledTimes(1);
74
+ expect(trackCommandUsage).toHaveBeenCalledWith(
75
+ 'project-install-deps',
76
+ null,
77
+ accountId
78
+ );
79
+ });
80
+
81
+ it('should handle exceptions', async () => {
82
+ const error = new Error('Something went super wrong');
83
+
84
+ getProjectConfig.mockImplementationOnce(() => {
85
+ throw error;
86
+ });
87
+
88
+ await handler({});
89
+
90
+ expect(logger.debug).toHaveBeenCalledTimes(1);
91
+ expect(logger.debug).toHaveBeenCalledWith(error);
92
+
93
+ expect(logger.error).toHaveBeenCalledTimes(1);
94
+ expect(logger.error).toHaveBeenCalledWith(error.message);
95
+
96
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
97
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
98
+ });
99
+
100
+ it('should log an error and exit when the project config is not defined', async () => {
101
+ getProjectConfig.mockResolvedValueOnce(null);
102
+ await handler({});
103
+
104
+ expect(logger.error).toHaveBeenCalledTimes(1);
105
+ expect(logger.error).toHaveBeenCalledWith(
106
+ 'No project detected. Run this command from a project directory.'
107
+ );
108
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
109
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
110
+ });
111
+
112
+ it('should log an error and exit when the project config has no projectDir', async () => {
113
+ getProjectConfig.mockResolvedValueOnce({ projectDir: null });
114
+ await handler({});
115
+
116
+ expect(logger.error).toHaveBeenCalledTimes(1);
117
+ expect(logger.error).toHaveBeenCalledWith(
118
+ 'No project detected. Run this command from a project directory.'
119
+ );
120
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
121
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
122
+ });
123
+
124
+ it('should prompt for input when packages is defined', async () => {
125
+ const projectDir = 'src';
126
+ getProjectConfig.mockResolvedValue({ projectDir });
127
+ const packageJsonLocation = path.join(projectDir, 'directory1');
128
+ promptUser.mockResolvedValueOnce(packageJsonLocation);
129
+ getProjectPackageJsonLocations.mockResolvedValue([packageJsonLocation]);
130
+ await handler({ packages: ['@hubspot/local-dev-lib'] });
131
+ expect(getProjectPackageJsonLocations).toHaveBeenCalledTimes(1);
132
+ expect(promptUser).toHaveBeenCalledTimes(1);
133
+ expect(promptUser).toHaveBeenCalledWith([
134
+ {
135
+ name: 'selectedInstallLocations',
136
+ type: 'checkbox',
137
+ when: expect.any(Function),
138
+ choices: [
139
+ {
140
+ name: 'directory1',
141
+ value: packageJsonLocation,
142
+ },
143
+ ],
144
+ message: 'Choose the project components to install the dependencies:',
145
+ validate: expect.any(Function),
146
+ },
147
+ ]);
148
+ });
149
+
150
+ it('should call installPackages correctly', async () => {
151
+ const projectDir = 'src';
152
+ const packageJsonLocation = path.join(projectDir, 'directory1');
153
+ const installLocations = [packageJsonLocation];
154
+ const packages = ['@hubspot/local-dev-lib'];
155
+
156
+ getProjectConfig.mockResolvedValue({ projectDir });
157
+ promptUser.mockResolvedValueOnce(packageJsonLocation);
158
+ getProjectPackageJsonLocations.mockResolvedValue(installLocations);
159
+ await handler({ packages });
160
+
161
+ expect(installPackages).toHaveBeenCalledTimes(1);
162
+ expect(installPackages).toHaveBeenCalledWith({
163
+ packages,
164
+ installLocations,
165
+ });
166
+ });
167
+ });
168
+ });
@@ -0,0 +1,305 @@
1
+ jest.mock('../../../lib/commonOpts');
2
+ jest.mock('../../../lib/usageTracking');
3
+ jest.mock('../../../lib/validation');
4
+ jest.mock('../../../lib/projectLogsManager');
5
+ jest.mock('../../../lib/prompts/projectsLogsPrompt');
6
+ jest.mock('@hubspot/local-dev-lib/logger');
7
+ jest.mock('../../../lib/errorHandlers/apiErrors');
8
+ jest.mock('../../../lib/ui/table');
9
+ jest.mock('../../../lib/ui');
10
+ jest.mock('../../../lib/errorHandlers/apiErrors');
11
+
12
+ // Deps where we don't want mocks
13
+ const libUi = jest.requireActual('../../../lib/ui');
14
+
15
+ const { uiLine, uiLink, uiBetaTag } = require('../../../lib/ui');
16
+
17
+ uiBetaTag.mockImplementation(libUi.uiBetaTag);
18
+
19
+ const {
20
+ addUseEnvironmentOptions,
21
+ getAccountId,
22
+ } = require('../../../lib/commonOpts');
23
+ const ProjectLogsManager = require('../../../lib/projectLogsManager');
24
+ const {
25
+ projectLogsPrompt,
26
+ } = require('../../../lib/prompts/projectsLogsPrompt');
27
+ const { getTableContents, getTableHeader } = require('../../../lib/ui/table');
28
+
29
+ const { trackCommandUsage } = require('../../../lib/usageTracking');
30
+ const { logApiErrorInstance } = require('../../../lib/errorHandlers/apiErrors');
31
+
32
+ const {
33
+ handler,
34
+ describe: logsDescribe,
35
+ command,
36
+ builder,
37
+ } = require('../logs');
38
+ const { EXIT_CODES } = require('../../../lib/enums/exitCodes');
39
+
40
+ describe('commands/project/logs', () => {
41
+ let processExitSpy;
42
+ beforeEach(() => {
43
+ processExitSpy = jest.spyOn(process, 'exit').mockImplementation(() => {});
44
+ });
45
+
46
+ describe('command', () => {
47
+ it('should have the proper command string', async () => {
48
+ expect(command).toEqual('logs');
49
+ });
50
+ });
51
+
52
+ describe('describe', () => {
53
+ it('should contain the beta tag', () => {
54
+ expect(logsDescribe).toContain('[BETA]');
55
+ });
56
+ it('should provide an accurate description of what the command is doing', () => {
57
+ expect(logsDescribe).toMatch(
58
+ /Get execution logs for a serverless function within a project/
59
+ );
60
+ });
61
+ });
62
+
63
+ describe('builder', () => {
64
+ let yargsMock = {};
65
+ beforeEach(() => {
66
+ yargsMock = {
67
+ options: jest.fn().mockImplementation(() => yargsMock),
68
+ conflicts: jest.fn().mockImplementation(() => yargsMock),
69
+ example: jest.fn().mockImplementation(() => yargsMock),
70
+ };
71
+ });
72
+
73
+ it('should add all of the options', () => {
74
+ builder(yargsMock);
75
+ expect(yargsMock.options).toHaveBeenCalledTimes(1);
76
+ expect(yargsMock.options).toHaveBeenCalledWith({
77
+ function: {
78
+ alias: 'function',
79
+ requiresArg: true,
80
+ describe: 'App function name',
81
+ type: 'string',
82
+ },
83
+ latest: {
84
+ alias: 'l',
85
+ type: 'boolean',
86
+ describe: 'Retrieve most recent log only',
87
+ },
88
+ compact: {
89
+ type: 'boolean',
90
+ describe: 'Output compact logs',
91
+ },
92
+ tail: {
93
+ alias: ['t', 'follow'],
94
+ describe: 'Tail logs',
95
+ type: 'boolean',
96
+ },
97
+ limit: {
98
+ type: 'number',
99
+ describe: 'Limit the number of logs to output',
100
+ },
101
+ });
102
+ });
103
+
104
+ it('should add the environment options', () => {
105
+ builder(yargsMock);
106
+ expect(addUseEnvironmentOptions).toHaveBeenCalledTimes(1);
107
+ expect(addUseEnvironmentOptions).toHaveBeenCalledWith(yargsMock);
108
+ });
109
+
110
+ it('should set tail and limit as conflicting arguments', () => {
111
+ builder(yargsMock);
112
+ expect(yargsMock.conflicts).toHaveBeenCalledTimes(1);
113
+ expect(yargsMock.conflicts).toHaveBeenCalledWith('tail', 'limit');
114
+ });
115
+
116
+ it('should set examples', () => {
117
+ builder(yargsMock);
118
+ expect(yargsMock.example).toHaveBeenCalledTimes(1);
119
+ expect(yargsMock.example).toHaveBeenCalledWith([
120
+ [
121
+ '$0 project logs',
122
+ 'Open the project logs prompt to get logs for a serverless function',
123
+ ],
124
+ [
125
+ '$0 project logs --function=my-function',
126
+ 'Get logs for function named "my-function" within the app named "app" within the project named "my-project"',
127
+ ],
128
+ ]);
129
+ });
130
+ });
131
+
132
+ describe('handler', () => {
133
+ const accountId = 12345678;
134
+
135
+ beforeEach(() => {
136
+ getAccountId.mockReturnValue(accountId);
137
+ projectLogsPrompt.mockResolvedValue({ functionName: 'foo' });
138
+ });
139
+
140
+ it('should get the account id', async () => {
141
+ const options = {
142
+ foo: 'bar',
143
+ };
144
+ await handler(options);
145
+ expect(getAccountId).toHaveBeenCalledTimes(1);
146
+ expect(getAccountId).toHaveBeenCalledWith(options);
147
+ });
148
+
149
+ it('should track the command usage', async () => {
150
+ const options = {
151
+ foo: 'bar',
152
+ };
153
+ await handler(options);
154
+ expect(trackCommandUsage).toHaveBeenCalledTimes(1);
155
+ expect(trackCommandUsage).toHaveBeenCalledWith(
156
+ 'project-logs',
157
+ null,
158
+ accountId
159
+ );
160
+ });
161
+
162
+ it('should initialize the ProjectLogsManager', async () => {
163
+ const options = {
164
+ foo: 'bar',
165
+ };
166
+ await handler(options);
167
+ expect(ProjectLogsManager.init).toHaveBeenCalledTimes(1);
168
+ expect(ProjectLogsManager.init).toHaveBeenCalledWith(accountId);
169
+ });
170
+
171
+ it('should prompt the user for input', async () => {
172
+ const functionNames = ['function1', 'function2'];
173
+ ProjectLogsManager.getFunctionNames.mockReturnValue(functionNames);
174
+ const options = {
175
+ foo: 'bar',
176
+ };
177
+ await handler(options);
178
+ expect(projectLogsPrompt).toHaveBeenCalledTimes(1);
179
+ expect(projectLogsPrompt).toHaveBeenCalledWith({
180
+ functionChoices: functionNames,
181
+ promptOptions: options,
182
+ });
183
+ });
184
+
185
+ it('should set the function', async () => {
186
+ const selectedFunction = 'function1';
187
+ ProjectLogsManager.getFunctionNames.mockReturnValue([
188
+ selectedFunction,
189
+ 'function2',
190
+ ]);
191
+ projectLogsPrompt.mockReturnValue({
192
+ functionName: selectedFunction,
193
+ });
194
+
195
+ await handler({});
196
+ expect(ProjectLogsManager.setFunction).toHaveBeenCalledTimes(1);
197
+ expect(ProjectLogsManager.setFunction).toHaveBeenCalledWith(
198
+ selectedFunction
199
+ );
200
+ });
201
+
202
+ it('should log public functions correctly', async () => {
203
+ const functionNames = ['function1', 'function2'];
204
+ const selectedFunction = 'function1';
205
+ ProjectLogsManager.getFunctionNames.mockReturnValue(functionNames);
206
+ projectLogsPrompt.mockReturnValue({
207
+ functionName: selectedFunction,
208
+ });
209
+
210
+ const tableHeaders = ['Header 1', 'Header 2'];
211
+ getTableHeader.mockReturnValue(tableHeaders);
212
+
213
+ ProjectLogsManager.isPublicFunction = true;
214
+ ProjectLogsManager.accountId = accountId;
215
+ ProjectLogsManager.functionName = selectedFunction;
216
+ ProjectLogsManager.endpointName = 'my-endpoint';
217
+ ProjectLogsManager.appId = 123456;
218
+
219
+ await handler({});
220
+ expect(getTableHeader).toHaveBeenCalledTimes(1);
221
+ expect(getTableHeader).toHaveBeenCalledWith([
222
+ 'Account',
223
+ 'Function',
224
+ 'Endpoint',
225
+ ]);
226
+
227
+ expect(getTableContents).toHaveBeenCalledTimes(1);
228
+ expect(getTableContents).toHaveBeenCalledWith(
229
+ [
230
+ tableHeaders,
231
+ [
232
+ ProjectLogsManager.accountId,
233
+ ProjectLogsManager.functionName,
234
+ ProjectLogsManager.endpointName,
235
+ ],
236
+ ],
237
+ { border: { bodyLeft: ' ' } }
238
+ );
239
+ expect(uiLink).toHaveBeenCalledTimes(1);
240
+ expect(uiLink).toHaveBeenCalledWith(
241
+ 'View function logs in HubSpot',
242
+ `https://app.hubspot.com/private-apps/${accountId}/${ProjectLogsManager.appId}/logs/serverlessGatewayExecution?path=${ProjectLogsManager.endpointName}`
243
+ );
244
+ expect(uiLine).toHaveBeenCalledTimes(1);
245
+ });
246
+
247
+ it('should log private functions correctly', async () => {
248
+ const functionNames = ['function1', 'function2'];
249
+ const selectedFunction = 'function1';
250
+
251
+ ProjectLogsManager.getFunctionNames.mockReturnValue(functionNames);
252
+ projectLogsPrompt.mockReturnValue({
253
+ functionName: selectedFunction,
254
+ });
255
+
256
+ const tableHeaders = ['Header 1', 'Header 2'];
257
+ getTableHeader.mockReturnValue(tableHeaders);
258
+
259
+ ProjectLogsManager.isPublicFunction = false;
260
+ ProjectLogsManager.accountId = accountId;
261
+ ProjectLogsManager.functionName = selectedFunction;
262
+ ProjectLogsManager.appId = 456789;
263
+
264
+ await handler({});
265
+ expect(getTableHeader).toHaveBeenCalledTimes(1);
266
+ expect(getTableHeader).toHaveBeenCalledWith(['Account', 'Function']);
267
+
268
+ expect(getTableContents).toHaveBeenCalledTimes(1);
269
+ expect(getTableContents).toHaveBeenCalledWith(
270
+ [
271
+ tableHeaders,
272
+ [ProjectLogsManager.accountId, ProjectLogsManager.functionName],
273
+ ],
274
+ { border: { bodyLeft: ' ' } }
275
+ );
276
+
277
+ expect(uiLink).toHaveBeenCalledWith(
278
+ 'View function logs in HubSpot',
279
+ `https://app.hubspot.com/private-apps/${accountId}/${ProjectLogsManager.appId}/logs/crm?serverlessFunction=${selectedFunction}`
280
+ );
281
+
282
+ expect(uiLine).toHaveBeenCalledTimes(1);
283
+ });
284
+
285
+ it('should handle errors correctly', async () => {
286
+ const error = new Error('Something went wrong');
287
+ ProjectLogsManager.init.mockImplementation(() => {
288
+ throw error;
289
+ });
290
+
291
+ ProjectLogsManager.projectName = 'Super cool project';
292
+
293
+ await handler({});
294
+
295
+ expect(logApiErrorInstance).toHaveBeenCalledTimes(1);
296
+ expect(logApiErrorInstance).toHaveBeenCalledWith(error, {
297
+ accountId: accountId,
298
+ projectName: ProjectLogsManager.projectName,
299
+ });
300
+
301
+ expect(processExitSpy).toHaveBeenCalledTimes(1);
302
+ expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
303
+ });
304
+ });
305
+ });
@@ -42,9 +42,6 @@ const { getCwd, sanitizeFileName } = require('@hubspot/local-dev-lib/path');
42
42
  const { logger } = require('@hubspot/local-dev-lib/logger');
43
43
  const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
44
44
  const { extractZipArchive } = require('@hubspot/local-dev-lib/archive');
45
- const {
46
- fetchPublicAppMetadata,
47
- } = require('@hubspot/local-dev-lib/api/appsDev');
48
45
 
49
46
  const i18nKey = 'commands.project.subcommands.cloneApp';
50
47
 
@@ -76,8 +73,6 @@ exports.handler = async options => {
76
73
  let appId;
77
74
  let name;
78
75
  let location;
79
- let preventProjectMigrations;
80
- let listingInfo;
81
76
  try {
82
77
  appId = options.appId;
83
78
  if (!appId) {
@@ -89,11 +84,6 @@ exports.handler = async options => {
89
84
  });
90
85
  appId = appIdResponse.appId;
91
86
  }
92
- const selectedApp = await fetchPublicAppMetadata(appId, accountId);
93
- // preventProjectMigrations returns true if we have not added app to allowlist config.
94
- // listingInfo will only exist for marketplace apps
95
- preventProjectMigrations = selectedApp.preventProjectMigrations;
96
- listingInfo = selectedApp.listingInfo;
97
87
 
98
88
  const projectResponse = await createProjectPrompt('', options, true);
99
89
  name = projectResponse.name;
@@ -138,15 +128,12 @@ exports.handler = async options => {
138
128
  };
139
129
  const success = writeProjectConfig(configPath, configContent);
140
130
 
141
- const isListed = Boolean(listingInfo);
142
131
  trackCommandMetadataUsage(
143
132
  'clone-app',
144
133
  {
145
- projectName: name,
146
- appId,
147
- status,
148
- preventProjectMigrations,
149
- isListed,
134
+ type: name,
135
+ assetType: appId,
136
+ successful: success,
150
137
  },
151
138
  accountId
152
139
  );
@@ -170,7 +170,10 @@ exports.handler = async options => {
170
170
  } else if (e.response && e.response.status === 400) {
171
171
  logger.error(e.message);
172
172
  } else {
173
- logApiErrorInstance(e, new ApiErrorContext({ accountId, projectName }));
173
+ logApiErrorInstance(
174
+ e,
175
+ new ApiErrorContext({ accountId, request: 'project deploy' })
176
+ );
174
177
  }
175
178
  return process.exit(EXIT_CODES.ERROR);
176
179
  }