@hubspot/cli 6.1.1 → 6.2.1
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 +2 -2
- package/commands/accounts/clean.js +5 -7
- package/commands/auth.js +5 -5
- package/commands/cms/convertFields.js +2 -2
- package/commands/cms/lighthouseScore.js +47 -36
- package/commands/create/api-sample.js +2 -4
- package/commands/create/function.js +2 -2
- package/commands/create/module.js +2 -2
- package/commands/create/template.js +2 -2
- package/commands/create.js +3 -5
- package/commands/customObject/create.js +2 -2
- package/commands/customObject/schema/create.js +4 -4
- package/commands/customObject/schema/delete.js +2 -3
- package/commands/customObject/schema/fetch-all.js +2 -5
- package/commands/customObject/schema/fetch.js +2 -4
- package/commands/customObject/schema/list.js +2 -4
- package/commands/customObject/schema/update.js +4 -4
- package/commands/fetch.js +2 -2
- package/commands/filemanager/fetch.js +2 -2
- package/commands/filemanager/upload.js +3 -7
- package/commands/functions/deploy.js +26 -23
- package/commands/functions/list.js +3 -6
- package/commands/hubdb/clear.js +5 -3
- package/commands/hubdb/create.js +2 -2
- package/commands/hubdb/delete.js +2 -2
- package/commands/hubdb/fetch.js +2 -2
- package/commands/init.js +4 -7
- package/commands/lint.js +2 -2
- package/commands/list.js +4 -6
- package/commands/logs.js +6 -3
- package/commands/mv.js +3 -6
- package/commands/project/__tests__/deploy.test.js +37 -26
- package/commands/project/__tests__/logs.test.js +4 -5
- package/commands/project/add.js +2 -2
- package/commands/project/cloneApp.js +11 -9
- package/commands/project/create.js +2 -6
- package/commands/project/deploy.js +9 -12
- package/commands/project/dev.js +6 -5
- package/commands/project/download.js +7 -9
- package/commands/project/listBuilds.js +8 -12
- package/commands/project/logs.js +2 -2
- package/commands/project/migrateApp.js +20 -15
- package/commands/project/upload.js +4 -10
- package/commands/project/watch.js +8 -13
- package/commands/remove.js +2 -5
- package/commands/sandbox/create.js +4 -6
- package/commands/sandbox/delete.js +6 -12
- package/commands/secrets/addSecret.js +2 -5
- package/commands/secrets/deleteSecret.js +2 -5
- package/commands/secrets/listSecrets.js +5 -6
- package/commands/secrets/updateSecret.js +2 -5
- package/commands/theme/preview.js +2 -5
- package/commands/upload.js +3 -7
- package/commands/watch.js +3 -7
- package/lang/en.lyaml +14 -18
- package/lib/LocalDevManager.js +8 -6
- package/lib/__tests__/downloadProjectPrompt.test.js +1 -1
- package/lib/__tests__/projectLogsManager.test.js +19 -17
- package/lib/__tests__/serverlessLogs.test.js +13 -9
- package/lib/buildAccount.js +10 -10
- package/lib/developerTestAccounts.js +27 -27
- package/lib/errorHandlers/index.js +101 -0
- package/lib/errorHandlers/{overrideErrors.js → suppressError.js} +7 -7
- package/lib/hasFeature.js +15 -0
- package/lib/localDev.js +32 -19
- package/lib/marketplace-validate.js +3 -3
- package/lib/oauth.js +1 -1
- package/lib/polling.js +1 -1
- package/lib/projectLogsManager.js +3 -4
- package/lib/projectStructure.js +2 -2
- package/lib/projects.js +42 -29
- package/lib/projectsWatch.js +7 -12
- package/lib/prompts/createProjectPrompt.js +14 -5
- package/lib/prompts/downloadProjectPrompt.js +3 -6
- package/lib/prompts/projectDevTargetAccountPrompt.js +8 -6
- package/lib/prompts/selectPublicAppPrompt.js +5 -3
- package/lib/sandboxSync.js +7 -7
- package/lib/sandboxes.js +11 -7
- package/lib/schema.js +2 -2
- package/lib/serverlessLogs.js +67 -15
- package/lib/upload.js +2 -2
- package/lib/validation.js +2 -2
- package/package.json +8 -9
- package/lib/errorHandlers/apiErrors.js +0 -145
- package/lib/errorHandlers/fileSystemErrors.js +0 -20
- package/lib/errorHandlers/standardErrors.js +0 -103
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const SpinniesManager = require('../../lib/ui/SpinniesManager');
|
|
2
2
|
const {
|
|
3
3
|
addAccountOptions,
|
|
4
4
|
addConfigOptions,
|
|
@@ -6,11 +6,8 @@ const {
|
|
|
6
6
|
addUseEnvironmentOptions,
|
|
7
7
|
} = require('../../lib/commonOpts');
|
|
8
8
|
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
ApiErrorContext,
|
|
12
|
-
} = require('../../lib/errorHandlers/apiErrors');
|
|
13
|
-
|
|
9
|
+
const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index');
|
|
10
|
+
const { uiAccountDescription } = require('../../lib/ui');
|
|
14
11
|
const { poll } = require('../../lib/polling');
|
|
15
12
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
16
13
|
const {
|
|
@@ -20,6 +17,7 @@ const {
|
|
|
20
17
|
const { loadAndValidateOptions } = require('../../lib/validation');
|
|
21
18
|
const { outputBuildLog } = require('../../lib/serverlessLogs');
|
|
22
19
|
const { i18n } = require('../../lib/lang');
|
|
20
|
+
const { isHubSpotHttpError } = require('@hubspot/local-dev-lib/errors/index');
|
|
23
21
|
|
|
24
22
|
const i18nKey = 'commands.functions.subcommands.deploy';
|
|
25
23
|
|
|
@@ -32,7 +30,6 @@ exports.handler = async options => {
|
|
|
32
30
|
const { path: functionPath } = options;
|
|
33
31
|
const accountId = getAccountId(options);
|
|
34
32
|
const splitFunctionPath = functionPath.split('.');
|
|
35
|
-
let spinner;
|
|
36
33
|
|
|
37
34
|
trackCommandUsage('functions-deploy', null, accountId);
|
|
38
35
|
|
|
@@ -54,17 +51,22 @@ exports.handler = async options => {
|
|
|
54
51
|
})
|
|
55
52
|
);
|
|
56
53
|
|
|
54
|
+
SpinniesManager.init();
|
|
55
|
+
|
|
56
|
+
SpinniesManager.add('loading', {
|
|
57
|
+
text: i18n(`${i18nKey}.loading`, {
|
|
58
|
+
account: uiAccountDescription(accountId),
|
|
59
|
+
functionPath,
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
|
|
57
63
|
try {
|
|
58
|
-
|
|
59
|
-
i18n(`${i18nKey}.loading`, {
|
|
60
|
-
accountId,
|
|
61
|
-
functionPath,
|
|
62
|
-
})
|
|
63
|
-
).start();
|
|
64
|
-
const buildId = await buildPackage(accountId, functionPath);
|
|
64
|
+
const { data: buildId } = await buildPackage(accountId, functionPath);
|
|
65
65
|
const successResp = await poll(getBuildStatus, accountId, buildId);
|
|
66
66
|
const buildTimeSeconds = (successResp.buildTime / 1000).toFixed(2);
|
|
67
|
-
|
|
67
|
+
|
|
68
|
+
SpinniesManager.succeed('loading');
|
|
69
|
+
|
|
68
70
|
await outputBuildLog(successResp.cdnUrl);
|
|
69
71
|
logger.success(
|
|
70
72
|
i18n(`${i18nKey}.success.deployed`, {
|
|
@@ -74,15 +76,19 @@ exports.handler = async options => {
|
|
|
74
76
|
})
|
|
75
77
|
);
|
|
76
78
|
} catch (e) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
SpinniesManager.fail('loading', {
|
|
80
|
+
text: i18n(`${i18nKey}.loadingFailed`, {
|
|
81
|
+
account: uiAccountDescription(accountId),
|
|
82
|
+
functionPath,
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (isHubSpotHttpError(e) && e.status === 404) {
|
|
79
87
|
logger.error(
|
|
80
88
|
i18n(`${i18nKey}.errors.noPackageJson`, {
|
|
81
89
|
functionPath,
|
|
82
90
|
})
|
|
83
91
|
);
|
|
84
|
-
} else if (e.response && e.response.status === 400) {
|
|
85
|
-
logger.error(e.error.message);
|
|
86
92
|
} else if (e.status === 'ERROR') {
|
|
87
93
|
await outputBuildLog(e.cdnUrl);
|
|
88
94
|
logger.error(
|
|
@@ -91,10 +97,7 @@ exports.handler = async options => {
|
|
|
91
97
|
})
|
|
92
98
|
);
|
|
93
99
|
} else {
|
|
94
|
-
|
|
95
|
-
e,
|
|
96
|
-
new ApiErrorContext({ accountId, request: functionPath })
|
|
97
|
-
);
|
|
100
|
+
logError(e, new ApiErrorContext({ accountId, request: functionPath }));
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
const { getRoutes } = require('@hubspot/local-dev-lib/api/functions');
|
|
2
2
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
3
|
-
const {
|
|
4
|
-
logApiErrorInstance,
|
|
5
|
-
ApiErrorContext,
|
|
6
|
-
} = require('../../lib/errorHandlers/apiErrors');
|
|
3
|
+
const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index');
|
|
7
4
|
const { getFunctionArrays } = require('../../lib/getFunctionArrays');
|
|
8
5
|
const { getTableContents, getTableHeader } = require('../../lib/ui/table');
|
|
9
6
|
const {
|
|
@@ -31,8 +28,8 @@ exports.handler = async options => {
|
|
|
31
28
|
|
|
32
29
|
logger.debug(i18n(`${i18nKey}.debug.gettingFunctions`));
|
|
33
30
|
|
|
34
|
-
const routesResp = await getRoutes(accountId).catch(async e => {
|
|
35
|
-
|
|
31
|
+
const { data: routesResp } = await getRoutes(accountId).catch(async e => {
|
|
32
|
+
logError(e, new ApiErrorContext({ accountId }));
|
|
36
33
|
process.exit(EXIT_CODES.SUCCESS);
|
|
37
34
|
});
|
|
38
35
|
|
package/commands/hubdb/clear.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
2
|
-
const {
|
|
2
|
+
const { logError } = require('../../lib/errorHandlers/index');
|
|
3
3
|
const { clearHubDbTableRows } = require('@hubspot/local-dev-lib/hubdb');
|
|
4
4
|
const { publishTable } = require('@hubspot/local-dev-lib/api/hubdb');
|
|
5
5
|
|
|
@@ -37,7 +37,9 @@ exports.handler = async options => {
|
|
|
37
37
|
tableId,
|
|
38
38
|
})
|
|
39
39
|
);
|
|
40
|
-
const {
|
|
40
|
+
const {
|
|
41
|
+
data: { rowCount },
|
|
42
|
+
} = await publishTable(accountId, tableId);
|
|
41
43
|
logger.log(
|
|
42
44
|
i18n(`${i18nKey}.logs.rowCount`, {
|
|
43
45
|
rowCount,
|
|
@@ -52,7 +54,7 @@ exports.handler = async options => {
|
|
|
52
54
|
);
|
|
53
55
|
}
|
|
54
56
|
} catch (e) {
|
|
55
|
-
|
|
57
|
+
logError(e);
|
|
56
58
|
}
|
|
57
59
|
};
|
|
58
60
|
|
package/commands/hubdb/create.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
|
|
3
3
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
4
|
-
const {
|
|
4
|
+
const { logError } = require('../../lib/errorHandlers/index');
|
|
5
5
|
const { getCwd } = require('@hubspot/local-dev-lib/path');
|
|
6
6
|
const { createHubDbTable } = require('@hubspot/local-dev-lib/hubdb');
|
|
7
7
|
|
|
@@ -56,7 +56,7 @@ exports.handler = async options => {
|
|
|
56
56
|
src,
|
|
57
57
|
})
|
|
58
58
|
);
|
|
59
|
-
|
|
59
|
+
logError(e);
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
|
package/commands/hubdb/delete.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
2
|
-
const {
|
|
2
|
+
const { logError } = require('../../lib/errorHandlers/index');
|
|
3
3
|
const { deleteTable } = require('@hubspot/local-dev-lib/api/hubdb');
|
|
4
4
|
const { loadAndValidateOptions } = require('../../lib/validation');
|
|
5
5
|
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
@@ -40,7 +40,7 @@ exports.handler = async options => {
|
|
|
40
40
|
tableId,
|
|
41
41
|
})
|
|
42
42
|
);
|
|
43
|
-
|
|
43
|
+
logError(e);
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
|
package/commands/hubdb/fetch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
2
|
-
const {
|
|
2
|
+
const { logError } = require('../../lib/errorHandlers/index');
|
|
3
3
|
const { downloadHubDbTable } = require('@hubspot/local-dev-lib/hubdb');
|
|
4
4
|
|
|
5
5
|
const { loadAndValidateOptions } = require('../../lib/validation');
|
|
@@ -37,7 +37,7 @@ exports.handler = async options => {
|
|
|
37
37
|
})
|
|
38
38
|
);
|
|
39
39
|
} catch (e) {
|
|
40
|
-
|
|
40
|
+
logError(e);
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
|
package/commands/init.js
CHANGED
|
@@ -11,10 +11,7 @@ const { handleExit } = require('../lib/process');
|
|
|
11
11
|
const {
|
|
12
12
|
checkAndAddConfigToGitignore,
|
|
13
13
|
} = require('@hubspot/local-dev-lib/gitignore');
|
|
14
|
-
const {
|
|
15
|
-
logErrorInstance,
|
|
16
|
-
debugErrorAndContext,
|
|
17
|
-
} = require('../lib/errorHandlers/standardErrors');
|
|
14
|
+
const { debugError, logError } = require('../lib/errorHandlers/index');
|
|
18
15
|
const {
|
|
19
16
|
OAUTH_AUTH_METHOD,
|
|
20
17
|
PERSONAL_ACCESS_KEY_AUTH_METHOD,
|
|
@@ -71,7 +68,7 @@ const personalAccessKeyConfigCreationFlow = async (env, account) => {
|
|
|
71
68
|
true
|
|
72
69
|
);
|
|
73
70
|
} catch (e) {
|
|
74
|
-
|
|
71
|
+
logError(e);
|
|
75
72
|
}
|
|
76
73
|
return updatedConfig;
|
|
77
74
|
};
|
|
@@ -140,7 +137,7 @@ exports.handler = async options => {
|
|
|
140
137
|
try {
|
|
141
138
|
checkAndAddConfigToGitignore(configPath);
|
|
142
139
|
} catch (e) {
|
|
143
|
-
|
|
140
|
+
debugError(e);
|
|
144
141
|
}
|
|
145
142
|
|
|
146
143
|
logger.log('');
|
|
@@ -165,7 +162,7 @@ exports.handler = async options => {
|
|
|
165
162
|
);
|
|
166
163
|
process.exit(EXIT_CODES.SUCCESS);
|
|
167
164
|
} catch (err) {
|
|
168
|
-
|
|
165
|
+
logError(err);
|
|
169
166
|
await trackAuthAction('init', authType, TRACKING_STATUS.ERROR);
|
|
170
167
|
process.exit(EXIT_CODES.ERROR);
|
|
171
168
|
}
|
package/commands/lint.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { lint } = require('@hubspot/local-dev-lib/cms/validate');
|
|
2
2
|
const { printHublValidationResult } = require('../lib/hublValidate');
|
|
3
3
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
4
|
-
const {
|
|
4
|
+
const { logError } = require('../lib/errorHandlers/index');
|
|
5
5
|
|
|
6
6
|
const {
|
|
7
7
|
addConfigOptions,
|
|
@@ -41,7 +41,7 @@ exports.handler = async options => {
|
|
|
41
41
|
});
|
|
42
42
|
} catch (err) {
|
|
43
43
|
logger.groupEnd(groupName);
|
|
44
|
-
|
|
44
|
+
logError(err, { accountId });
|
|
45
45
|
process.exit(EXIT_CODES.ERROR);
|
|
46
46
|
}
|
|
47
47
|
logger.groupEnd(groupName);
|
package/commands/list.js
CHANGED
|
@@ -9,10 +9,7 @@ const { trackCommandUsage } = require('../lib/usageTracking');
|
|
|
9
9
|
const { isPathFolder } = require('../lib/filesystem');
|
|
10
10
|
|
|
11
11
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
12
|
-
const {
|
|
13
|
-
logApiErrorInstance,
|
|
14
|
-
ApiErrorContext,
|
|
15
|
-
} = require('../lib/errorHandlers/apiErrors');
|
|
12
|
+
const { logError } = require('../lib/errorHandlers/index');
|
|
16
13
|
const {
|
|
17
14
|
getDirectoryContentsByPath,
|
|
18
15
|
} = require('@hubspot/local-dev-lib/api/fileMapper');
|
|
@@ -43,9 +40,10 @@ exports.handler = async options => {
|
|
|
43
40
|
);
|
|
44
41
|
|
|
45
42
|
try {
|
|
46
|
-
|
|
43
|
+
const { data } = await getDirectoryContentsByPath(accountId, directoryPath);
|
|
44
|
+
contentsResp = data;
|
|
47
45
|
} catch (e) {
|
|
48
|
-
|
|
46
|
+
logError(e);
|
|
49
47
|
process.exit(EXIT_CODES.SUCCESS);
|
|
50
48
|
}
|
|
51
49
|
|
package/commands/logs.js
CHANGED
|
@@ -15,11 +15,12 @@ const { tailLogs } = require('../lib/serverlessLogs');
|
|
|
15
15
|
const { loadAndValidateOptions } = require('../lib/validation');
|
|
16
16
|
const { i18n } = require('../lib/lang');
|
|
17
17
|
const { EXIT_CODES } = require('../lib/enums/exitCodes');
|
|
18
|
+
const { isHubSpotHttpError } = require('@hubspot/local-dev-lib/errors/index');
|
|
18
19
|
|
|
19
20
|
const i18nKey = 'commands.logs';
|
|
20
21
|
|
|
21
22
|
const handleLogsError = (e, accountId, functionPath) => {
|
|
22
|
-
if (e.
|
|
23
|
+
if (isHubSpotHttpError(e) && (e.status === 404 || e.status == 400)) {
|
|
23
24
|
logger.error(
|
|
24
25
|
i18n(`${i18nKey}.errors.noLogsFound`, {
|
|
25
26
|
accountId,
|
|
@@ -61,14 +62,16 @@ const endpointLog = async (accountId, options) => {
|
|
|
61
62
|
});
|
|
62
63
|
} else if (latest) {
|
|
63
64
|
try {
|
|
64
|
-
|
|
65
|
+
const { data } = await getLatestFunctionLog(accountId, functionPath);
|
|
66
|
+
logsResp = data;
|
|
65
67
|
} catch (e) {
|
|
66
68
|
handleLogsError(e, accountId, functionPath);
|
|
67
69
|
process.exit(EXIT_CODES.ERROR);
|
|
68
70
|
}
|
|
69
71
|
} else {
|
|
70
72
|
try {
|
|
71
|
-
|
|
73
|
+
const { data } = await getFunctionLogs(accountId, functionPath, options);
|
|
74
|
+
logsResp = data;
|
|
72
75
|
} catch (e) {
|
|
73
76
|
handleLogsError(e, accountId, functionPath);
|
|
74
77
|
process.exit(EXIT_CODES.ERROR);
|
package/commands/mv.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
2
2
|
const { moveFile } = require('@hubspot/local-dev-lib/api/fileMapper');
|
|
3
|
-
const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/
|
|
4
|
-
const {
|
|
5
|
-
logApiErrorInstance,
|
|
6
|
-
ApiErrorContext,
|
|
7
|
-
} = require('../lib/errorHandlers/apiErrors');
|
|
3
|
+
const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/index');
|
|
4
|
+
const { logError, ApiErrorContext } = require('../lib/errorHandlers/index');
|
|
8
5
|
const {
|
|
9
6
|
addConfigOptions,
|
|
10
7
|
addAccountOptions,
|
|
@@ -64,7 +61,7 @@ exports.handler = async options => {
|
|
|
64
61
|
})
|
|
65
62
|
);
|
|
66
63
|
} else {
|
|
67
|
-
|
|
64
|
+
logError(
|
|
68
65
|
error,
|
|
69
66
|
new ApiErrorContext({
|
|
70
67
|
accountId,
|
|
@@ -57,6 +57,9 @@ const { EXIT_CODES } = require('../../../lib/enums/exitCodes');
|
|
|
57
57
|
const { AxiosError, HttpStatusCode } = require('axios');
|
|
58
58
|
|
|
59
59
|
const chalk = require('chalk');
|
|
60
|
+
const {
|
|
61
|
+
HubSpotHttpError,
|
|
62
|
+
} = require('@hubspot/local-dev-lib/models/HubSpotHttpError');
|
|
60
63
|
|
|
61
64
|
describe('commands/project/deploy', () => {
|
|
62
65
|
const projectFlag = 'project';
|
|
@@ -163,8 +166,8 @@ describe('commands/project/deploy', () => {
|
|
|
163
166
|
});
|
|
164
167
|
getAccountId.mockReturnValue(accountId);
|
|
165
168
|
getAccountConfig.mockReturnValue({ accountType });
|
|
166
|
-
fetchProject.mockResolvedValue(projectDetails);
|
|
167
|
-
deployProject.mockResolvedValue(deployDetails);
|
|
169
|
+
fetchProject.mockResolvedValue({ data: projectDetails });
|
|
170
|
+
deployProject.mockResolvedValue({ data: deployDetails });
|
|
168
171
|
deployBuildIdPrompt.mockResolvedValue({
|
|
169
172
|
buildId: projectDetails.latestBuild.buildId,
|
|
170
173
|
});
|
|
@@ -251,7 +254,7 @@ describe('commands/project/deploy', () => {
|
|
|
251
254
|
});
|
|
252
255
|
|
|
253
256
|
it('should log an error and exit when latest build is not defined', async () => {
|
|
254
|
-
fetchProject.mockResolvedValue({});
|
|
257
|
+
fetchProject.mockResolvedValue({ data: {} });
|
|
255
258
|
await handler(options);
|
|
256
259
|
expect(logger.error).toHaveBeenCalledTimes(1);
|
|
257
260
|
expect(logger.error).toHaveBeenCalledWith(
|
|
@@ -332,7 +335,9 @@ describe('commands/project/deploy', () => {
|
|
|
332
335
|
it('should log an error and exit when the deploy fails', async () => {
|
|
333
336
|
const errorMessage = `Just wasn't feeling it`;
|
|
334
337
|
deployProject.mockResolvedValue({
|
|
335
|
-
|
|
338
|
+
data: {
|
|
339
|
+
error: { message: errorMessage },
|
|
340
|
+
},
|
|
336
341
|
});
|
|
337
342
|
|
|
338
343
|
await handler(options);
|
|
@@ -361,13 +366,15 @@ describe('commands/project/deploy', () => {
|
|
|
361
366
|
uiCommandReference.mockReturnValue(commandReference);
|
|
362
367
|
uiAccountDescription.mockReturnValue(accountDescription);
|
|
363
368
|
fetchProject.mockImplementation(() => {
|
|
364
|
-
throw new
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
369
|
+
throw new HubSpotHttpError('OH NO', {
|
|
370
|
+
cause: new AxiosError(
|
|
371
|
+
'OH NO',
|
|
372
|
+
'',
|
|
373
|
+
{},
|
|
374
|
+
{},
|
|
375
|
+
{ status: HttpStatusCode.NotFound }
|
|
376
|
+
),
|
|
377
|
+
});
|
|
371
378
|
});
|
|
372
379
|
await handler(options);
|
|
373
380
|
|
|
@@ -388,18 +395,20 @@ describe('commands/project/deploy', () => {
|
|
|
388
395
|
uiAccountDescription.mockReturnValue(accountDescription);
|
|
389
396
|
const errorMessage = 'Something bad happened';
|
|
390
397
|
fetchProject.mockImplementation(() => {
|
|
391
|
-
throw new
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
+
throw new HubSpotHttpError(errorMessage, {
|
|
399
|
+
cause: new AxiosError(
|
|
400
|
+
errorMessage,
|
|
401
|
+
'',
|
|
402
|
+
{},
|
|
403
|
+
{},
|
|
404
|
+
{ status: HttpStatusCode.BadRequest }
|
|
405
|
+
),
|
|
406
|
+
});
|
|
398
407
|
});
|
|
399
408
|
await handler(options);
|
|
400
409
|
|
|
401
410
|
expect(logger.error).toHaveBeenCalledTimes(1);
|
|
402
|
-
expect(logger.error).toHaveBeenCalledWith(
|
|
411
|
+
expect(logger.error).toHaveBeenCalledWith('The request was bad.');
|
|
403
412
|
expect(processExitSpy).toHaveBeenCalledTimes(1);
|
|
404
413
|
expect(processExitSpy).toHaveBeenCalledWith(EXIT_CODES.ERROR);
|
|
405
414
|
});
|
|
@@ -411,13 +420,15 @@ describe('commands/project/deploy', () => {
|
|
|
411
420
|
uiAccountDescription.mockReturnValue(accountDescription);
|
|
412
421
|
const errorMessage = 'Something bad happened';
|
|
413
422
|
fetchProject.mockImplementation(() => {
|
|
414
|
-
throw new
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
423
|
+
throw new HubSpotHttpError('OH NO', {
|
|
424
|
+
cause: new AxiosError(
|
|
425
|
+
errorMessage,
|
|
426
|
+
'',
|
|
427
|
+
{},
|
|
428
|
+
{},
|
|
429
|
+
{ status: HttpStatusCode.MethodNotAllowed }
|
|
430
|
+
),
|
|
431
|
+
});
|
|
421
432
|
});
|
|
422
433
|
await handler(options);
|
|
423
434
|
|
|
@@ -4,10 +4,9 @@ jest.mock('../../../lib/validation');
|
|
|
4
4
|
jest.mock('../../../lib/projectLogsManager');
|
|
5
5
|
jest.mock('../../../lib/prompts/projectsLogsPrompt');
|
|
6
6
|
jest.mock('@hubspot/local-dev-lib/logger');
|
|
7
|
-
jest.mock('../../../lib/errorHandlers/apiErrors');
|
|
8
7
|
jest.mock('../../../lib/ui/table');
|
|
9
8
|
jest.mock('../../../lib/ui');
|
|
10
|
-
jest.mock('../../../lib/errorHandlers
|
|
9
|
+
jest.mock('../../../lib/errorHandlers');
|
|
11
10
|
|
|
12
11
|
// Deps where we don't want mocks
|
|
13
12
|
const libUi = jest.requireActual('../../../lib/ui');
|
|
@@ -27,7 +26,6 @@ const {
|
|
|
27
26
|
const { getTableContents, getTableHeader } = require('../../../lib/ui/table');
|
|
28
27
|
|
|
29
28
|
const { trackCommandUsage } = require('../../../lib/usageTracking');
|
|
30
|
-
const { logApiErrorInstance } = require('../../../lib/errorHandlers/apiErrors');
|
|
31
29
|
|
|
32
30
|
const {
|
|
33
31
|
handler,
|
|
@@ -36,6 +34,7 @@ const {
|
|
|
36
34
|
builder,
|
|
37
35
|
} = require('../logs');
|
|
38
36
|
const { EXIT_CODES } = require('../../../lib/enums/exitCodes');
|
|
37
|
+
const { logError } = require('../../../lib/errorHandlers');
|
|
39
38
|
|
|
40
39
|
describe('commands/project/logs', () => {
|
|
41
40
|
let processExitSpy;
|
|
@@ -292,8 +291,8 @@ describe('commands/project/logs', () => {
|
|
|
292
291
|
|
|
293
292
|
await handler({});
|
|
294
293
|
|
|
295
|
-
expect(
|
|
296
|
-
expect(
|
|
294
|
+
expect(logError).toHaveBeenCalledTimes(1);
|
|
295
|
+
expect(logError).toHaveBeenCalledWith(error, {
|
|
297
296
|
accountId: accountId,
|
|
298
297
|
projectName: ProjectLogsManager.projectName,
|
|
299
298
|
});
|
package/commands/project/add.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
2
2
|
const { getAccountId } = require('@hubspot/local-dev-lib/config');
|
|
3
|
-
const {
|
|
3
|
+
const { logError } = require('../../lib/errorHandlers/index');
|
|
4
4
|
const { fetchReleaseData } = require('@hubspot/local-dev-lib/github');
|
|
5
5
|
|
|
6
6
|
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
@@ -58,7 +58,7 @@ exports.handler = async options => {
|
|
|
58
58
|
})
|
|
59
59
|
);
|
|
60
60
|
} catch (error) {
|
|
61
|
-
|
|
61
|
+
logError(error);
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
|
|
@@ -26,10 +26,7 @@ const {
|
|
|
26
26
|
uiAccountDescription,
|
|
27
27
|
} = require('../../lib/ui');
|
|
28
28
|
const SpinniesManager = require('../../lib/ui/SpinniesManager');
|
|
29
|
-
const {
|
|
30
|
-
logApiErrorInstance,
|
|
31
|
-
ApiErrorContext,
|
|
32
|
-
} = require('../../lib/errorHandlers/apiErrors');
|
|
29
|
+
const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index');
|
|
33
30
|
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
34
31
|
const { isAppDeveloperAccount } = require('../../lib/accountTypes');
|
|
35
32
|
const { writeProjectConfig } = require('../../lib/projects');
|
|
@@ -90,7 +87,7 @@ exports.handler = async options => {
|
|
|
90
87
|
name = projectResponse.name;
|
|
91
88
|
location = projectResponse.location;
|
|
92
89
|
} catch (error) {
|
|
93
|
-
|
|
90
|
+
logError(error, new ApiErrorContext({ accountId }));
|
|
94
91
|
process.exit(EXIT_CODES.ERROR);
|
|
95
92
|
}
|
|
96
93
|
try {
|
|
@@ -100,7 +97,9 @@ exports.handler = async options => {
|
|
|
100
97
|
text: i18n(`${i18nKey}.cloneStatus.inProgress`),
|
|
101
98
|
});
|
|
102
99
|
|
|
103
|
-
const {
|
|
100
|
+
const {
|
|
101
|
+
data: { exportId },
|
|
102
|
+
} = await cloneApp(accountId, appId);
|
|
104
103
|
const { status } = await poll(checkCloneStatus, accountId, exportId);
|
|
105
104
|
if (status === 'SUCCESS') {
|
|
106
105
|
// Ensure correct project folder structure exists
|
|
@@ -109,7 +108,10 @@ exports.handler = async options => {
|
|
|
109
108
|
fs.mkdirSync(absoluteDestPath, { recursive: true });
|
|
110
109
|
|
|
111
110
|
// Extract zipped app files and place them in correct directory
|
|
112
|
-
const zippedApp = await downloadClonedProject(
|
|
111
|
+
const { data: zippedApp } = await downloadClonedProject(
|
|
112
|
+
accountId,
|
|
113
|
+
exportId
|
|
114
|
+
);
|
|
113
115
|
await extractZipArchive(
|
|
114
116
|
zippedApp,
|
|
115
117
|
sanitizeFileName(name),
|
|
@@ -169,10 +171,10 @@ exports.handler = async options => {
|
|
|
169
171
|
// Migrations endpoints return a response object with an errors property. The errors property contains an array of errors.
|
|
170
172
|
if (error.errors && Array.isArray(error.errors)) {
|
|
171
173
|
error.errors.forEach(e =>
|
|
172
|
-
|
|
174
|
+
logError(e, new ApiErrorContext({ accountId }))
|
|
173
175
|
);
|
|
174
176
|
} else {
|
|
175
|
-
|
|
177
|
+
logError(error, new ApiErrorContext({ accountId }));
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
};
|
|
@@ -47,16 +47,12 @@ exports.handler = async options => {
|
|
|
47
47
|
options
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
-
trackCommandUsage(
|
|
51
|
-
'project-create',
|
|
52
|
-
{ type: options.template || template },
|
|
53
|
-
accountId
|
|
54
|
-
);
|
|
50
|
+
trackCommandUsage('project-create', { type: template.name }, accountId);
|
|
55
51
|
|
|
56
52
|
await createProjectConfig(
|
|
57
53
|
path.resolve(getCwd(), options.location || location),
|
|
58
54
|
options.name || name,
|
|
59
|
-
template
|
|
55
|
+
template,
|
|
60
56
|
options.templateSource,
|
|
61
57
|
githubRef
|
|
62
58
|
);
|
|
@@ -6,10 +6,7 @@ const {
|
|
|
6
6
|
addUseEnvironmentOptions,
|
|
7
7
|
} = require('../../lib/commonOpts');
|
|
8
8
|
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
9
|
-
const {
|
|
10
|
-
logApiErrorInstance,
|
|
11
|
-
ApiErrorContext,
|
|
12
|
-
} = require('../../lib/errorHandlers/apiErrors');
|
|
9
|
+
const { logError, ApiErrorContext } = require('../../lib/errorHandlers/index');
|
|
13
10
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
14
11
|
const {
|
|
15
12
|
deployProject,
|
|
@@ -32,6 +29,7 @@ const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
|
|
|
32
29
|
const i18nKey = 'commands.project.subcommands.deploy';
|
|
33
30
|
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
34
31
|
const { uiCommandReference, uiAccountDescription } = require('../../lib/ui');
|
|
32
|
+
const { isHubSpotHttpError } = require('@hubspot/local-dev-lib/errors/index');
|
|
35
33
|
|
|
36
34
|
exports.command = 'deploy';
|
|
37
35
|
exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false);
|
|
@@ -94,10 +92,9 @@ exports.handler = async options => {
|
|
|
94
92
|
let buildIdToDeploy = buildIdOption;
|
|
95
93
|
|
|
96
94
|
try {
|
|
97
|
-
const {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
);
|
|
95
|
+
const {
|
|
96
|
+
data: { latestBuild, deployedBuildId },
|
|
97
|
+
} = await fetchProject(accountId, projectName);
|
|
101
98
|
|
|
102
99
|
if (!latestBuild || !latestBuild.buildId) {
|
|
103
100
|
logger.error(i18n(`${i18nKey}.errors.noBuilds`));
|
|
@@ -137,7 +134,7 @@ exports.handler = async options => {
|
|
|
137
134
|
return process.exit(EXIT_CODES.ERROR);
|
|
138
135
|
}
|
|
139
136
|
|
|
140
|
-
const deployResp = await deployProject(
|
|
137
|
+
const { data: deployResp } = await deployProject(
|
|
141
138
|
accountId,
|
|
142
139
|
projectName,
|
|
143
140
|
buildIdToDeploy
|
|
@@ -159,7 +156,7 @@ exports.handler = async options => {
|
|
|
159
156
|
buildIdToDeploy
|
|
160
157
|
);
|
|
161
158
|
} catch (e) {
|
|
162
|
-
if (e
|
|
159
|
+
if (isHubSpotHttpError(e) && e.status === 404) {
|
|
163
160
|
logger.error(
|
|
164
161
|
i18n(`${i18nKey}.errors.projectNotFound`, {
|
|
165
162
|
projectName: chalk.bold(projectName),
|
|
@@ -167,10 +164,10 @@ exports.handler = async options => {
|
|
|
167
164
|
command: uiCommandReference('hs project upload'),
|
|
168
165
|
})
|
|
169
166
|
);
|
|
170
|
-
} else if (e
|
|
167
|
+
} else if (isHubSpotHttpError(e) && e.status === 400) {
|
|
171
168
|
logger.error(e.message);
|
|
172
169
|
} else {
|
|
173
|
-
|
|
170
|
+
logError(
|
|
174
171
|
e,
|
|
175
172
|
new ApiErrorContext({ accountId, request: 'project deploy' })
|
|
176
173
|
);
|