@hubspot/cli 4.1.7-beta.0 → 4.1.7-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/accounts/list.js +1 -1
- package/commands/module/marketplace-validate.js +27 -37
- package/commands/sandbox/create.js +24 -86
- package/commands/sandbox/delete.js +11 -8
- package/commands/sandbox/sync.js +300 -0
- package/commands/sandbox.js +2 -0
- package/commands/theme/marketplace-validate.js +15 -125
- package/lib/marketplace-validate.js +137 -0
- package/lib/prompts/accountsPrompt.js +1 -3
- package/lib/prompts/sandboxesPrompt.js +1 -3
- package/lib/sandboxes.js +217 -0
- package/package.json +5 -4
- package/lib/validators/__tests__/ModuleDependencyValidator.js +0 -79
- package/lib/validators/__tests__/ModuleValidator.js +0 -51
- package/lib/validators/__tests__/RelativeValidator.js +0 -28
- package/lib/validators/__tests__/validatorTestUtils.js +0 -8
- package/lib/validators/applyValidators.js +0 -17
- package/lib/validators/constants.js +0 -11
- package/lib/validators/index.js +0 -8
- package/lib/validators/logValidatorResults.js +0 -59
- package/lib/validators/marketplaceValidators/RelativeValidator.js +0 -46
- package/lib/validators/marketplaceValidators/module/ModuleDependencyValidator.js +0 -101
- package/lib/validators/marketplaceValidators/module/ModuleValidator.js +0 -102
|
@@ -12,7 +12,7 @@ const {
|
|
|
12
12
|
} = require('../../lib/commonOpts');
|
|
13
13
|
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
14
14
|
const { loadAndValidateOptions } = require('../../lib/validation');
|
|
15
|
-
const { getSandboxType } = require('../../lib/
|
|
15
|
+
const { getSandboxType } = require('../../lib/sandboxes');
|
|
16
16
|
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
17
17
|
|
|
18
18
|
const i18nKey = 'cli.commands.accounts.subcommands.list';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const Spinnies = require('spinnies');
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
addConfigOptions,
|
|
@@ -9,17 +9,15 @@ const {
|
|
|
9
9
|
const { loadAndValidateOptions } = require('../../lib/validation');
|
|
10
10
|
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
11
11
|
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const { VALIDATION_RESULT } = require('../../lib/validators/constants');
|
|
12
|
+
kickOffValidation,
|
|
13
|
+
pollForValidationFinish,
|
|
14
|
+
fetchValidationResults,
|
|
15
|
+
processValidationErrors,
|
|
16
|
+
displayValidationResults,
|
|
17
|
+
} = require('../../lib/marketplace-validate');
|
|
19
18
|
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
20
19
|
|
|
21
20
|
const i18nKey = 'cli.commands.module.subcommands.marketplaceValidate';
|
|
22
|
-
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
23
21
|
|
|
24
22
|
exports.command = 'marketplace-validate <src>';
|
|
25
23
|
exports.describe = i18n(`${i18nKey}.describe`);
|
|
@@ -31,31 +29,29 @@ exports.handler = async options => {
|
|
|
31
29
|
|
|
32
30
|
const accountId = getAccountId(options);
|
|
33
31
|
|
|
34
|
-
if (!options.json) {
|
|
35
|
-
logger.log(
|
|
36
|
-
i18n(`${i18nKey}.logs.validatingModule`, {
|
|
37
|
-
path: src,
|
|
38
|
-
})
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
32
|
trackCommandUsage('validate', null, accountId);
|
|
42
33
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
).then(groupedResults => {
|
|
49
|
-
logValidatorResults(groupedResults, { logAsJson: options.json });
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
groupedResults
|
|
53
|
-
.flat()
|
|
54
|
-
.some(result => result.result === VALIDATION_RESULT.FATAL)
|
|
55
|
-
) {
|
|
56
|
-
process.exit(EXIT_CODES.WARNING);
|
|
57
|
-
}
|
|
34
|
+
const spinnies = new Spinnies();
|
|
35
|
+
spinnies.add('marketplaceValidation', {
|
|
36
|
+
text: i18n(`${i18nKey}.logs.validatingModule`, {
|
|
37
|
+
path: src,
|
|
38
|
+
}),
|
|
58
39
|
});
|
|
40
|
+
|
|
41
|
+
const assetType = 'MODULE';
|
|
42
|
+
const validationId = await kickOffValidation(accountId, assetType, src);
|
|
43
|
+
await pollForValidationFinish(accountId, validationId);
|
|
44
|
+
|
|
45
|
+
spinnies.remove('marketplaceValidation');
|
|
46
|
+
|
|
47
|
+
const validationResults = await fetchValidationResults(
|
|
48
|
+
accountId,
|
|
49
|
+
validationId
|
|
50
|
+
);
|
|
51
|
+
processValidationErrors(validationResults);
|
|
52
|
+
displayValidationResults(i18nKey, validationResults);
|
|
53
|
+
|
|
54
|
+
process.exit();
|
|
59
55
|
};
|
|
60
56
|
|
|
61
57
|
exports.builder = yargs => {
|
|
@@ -63,12 +59,6 @@ exports.builder = yargs => {
|
|
|
63
59
|
addAccountOptions(yargs, true);
|
|
64
60
|
addUseEnvironmentOptions(yargs, true);
|
|
65
61
|
|
|
66
|
-
yargs.options({
|
|
67
|
-
json: {
|
|
68
|
-
describe: i18n(`${i18nKey}.options.json.describe`),
|
|
69
|
-
type: 'boolean',
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
62
|
yargs.positional('src', {
|
|
73
63
|
describe: i18n(`${i18nKey}.positionals.src.describe`),
|
|
74
64
|
type: 'string',
|
|
@@ -10,105 +10,27 @@ const { logger } = require('@hubspot/cli-lib/logger');
|
|
|
10
10
|
const Spinnies = require('spinnies');
|
|
11
11
|
const { createSandbox } = require('@hubspot/cli-lib/sandboxes');
|
|
12
12
|
const { loadAndValidateOptions } = require('../../lib/validation');
|
|
13
|
+
const { createSandboxPrompt } = require('../../lib/prompts/sandboxesPrompt');
|
|
13
14
|
const {
|
|
14
|
-
createSandboxPrompt,
|
|
15
15
|
getSandboxType,
|
|
16
|
-
|
|
16
|
+
sandboxCreatePersonalAccessKeyFlow,
|
|
17
|
+
} = require('../../lib/sandboxes');
|
|
17
18
|
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
18
19
|
const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');
|
|
19
20
|
const {
|
|
20
21
|
debugErrorAndContext,
|
|
21
22
|
} = require('@hubspot/cli-lib/errorHandlers/standardErrors');
|
|
22
|
-
const {
|
|
23
|
-
ENVIRONMENTS,
|
|
24
|
-
PERSONAL_ACCESS_KEY_AUTH_METHOD,
|
|
25
|
-
DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
26
|
-
} = require('@hubspot/cli-lib/lib/constants');
|
|
27
|
-
const {
|
|
28
|
-
personalAccessKeyPrompt,
|
|
29
|
-
} = require('../../lib/prompts/personalAccessKeyPrompt');
|
|
30
|
-
const {
|
|
31
|
-
updateConfigWithPersonalAccessKey,
|
|
32
|
-
} = require('@hubspot/cli-lib/personalAccessKey');
|
|
23
|
+
const { ENVIRONMENTS } = require('@hubspot/cli-lib/lib/constants');
|
|
33
24
|
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
34
|
-
const {
|
|
35
|
-
getConfig,
|
|
36
|
-
writeConfig,
|
|
37
|
-
updateAccountConfig,
|
|
38
|
-
getAccountConfig,
|
|
39
|
-
} = require('@hubspot/cli-lib');
|
|
40
|
-
const {
|
|
41
|
-
enterAccountNamePrompt,
|
|
42
|
-
} = require('../../lib/prompts/enterAccountNamePrompt');
|
|
43
|
-
const {
|
|
44
|
-
setAsDefaultAccountPrompt,
|
|
45
|
-
} = require('../../lib/prompts/setAsDefaultAccountPrompt');
|
|
25
|
+
const { getAccountConfig } = require('@hubspot/cli-lib');
|
|
46
26
|
const { getHubSpotWebsiteOrigin } = require('@hubspot/cli-lib/lib/urls');
|
|
47
27
|
const {
|
|
48
28
|
isMissingScopeError,
|
|
29
|
+
isSpecifiedError,
|
|
49
30
|
} = require('@hubspot/cli-lib/errorHandlers/apiErrors');
|
|
50
|
-
const { uiFeatureHighlight } = require('../../lib/ui');
|
|
51
31
|
|
|
52
32
|
const i18nKey = 'cli.commands.sandbox.subcommands.create';
|
|
53
33
|
|
|
54
|
-
const personalAccessKeyFlow = async (env, account, name) => {
|
|
55
|
-
const configData = await personalAccessKeyPrompt({ env, account });
|
|
56
|
-
const updatedConfig = await updateConfigWithPersonalAccessKey(configData);
|
|
57
|
-
|
|
58
|
-
if (!updatedConfig) {
|
|
59
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let validName = updatedConfig.name;
|
|
63
|
-
|
|
64
|
-
if (!updatedConfig.name) {
|
|
65
|
-
const nameForConfig = name
|
|
66
|
-
.toLowerCase()
|
|
67
|
-
.split(' ')
|
|
68
|
-
.join('-');
|
|
69
|
-
const { name: promptName } = await enterAccountNamePrompt(nameForConfig);
|
|
70
|
-
validName = promptName;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
updateAccountConfig({
|
|
74
|
-
...updatedConfig,
|
|
75
|
-
environment: updatedConfig.env,
|
|
76
|
-
tokenInfo: updatedConfig.auth.tokenInfo,
|
|
77
|
-
name: validName,
|
|
78
|
-
});
|
|
79
|
-
writeConfig();
|
|
80
|
-
|
|
81
|
-
const setAsDefault = await setAsDefaultAccountPrompt(validName);
|
|
82
|
-
|
|
83
|
-
logger.log('');
|
|
84
|
-
if (setAsDefault) {
|
|
85
|
-
logger.success(
|
|
86
|
-
i18n(`cli.lib.prompts.setAsDefaultAccountPrompt.setAsDefaultAccount`, {
|
|
87
|
-
accountName: validName,
|
|
88
|
-
})
|
|
89
|
-
);
|
|
90
|
-
} else {
|
|
91
|
-
const config = getConfig();
|
|
92
|
-
logger.info(
|
|
93
|
-
i18n(`cli.lib.prompts.setAsDefaultAccountPrompt.keepingCurrentDefault`, {
|
|
94
|
-
accountName: config.defaultPortal,
|
|
95
|
-
})
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
logger.success(
|
|
99
|
-
i18n(`${i18nKey}.success.configFileUpdated`, {
|
|
100
|
-
configFilename: DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
101
|
-
authMethod: PERSONAL_ACCESS_KEY_AUTH_METHOD.name,
|
|
102
|
-
account: validName,
|
|
103
|
-
})
|
|
104
|
-
);
|
|
105
|
-
uiFeatureHighlight([
|
|
106
|
-
'accountsUseCommand',
|
|
107
|
-
'accountOption',
|
|
108
|
-
'accountsListCommand',
|
|
109
|
-
]);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
34
|
exports.command = 'create [--name]';
|
|
113
35
|
exports.describe = i18n(`${i18nKey}.describe`);
|
|
114
36
|
|
|
@@ -194,13 +116,29 @@ exports.handler = async options => {
|
|
|
194
116
|
url,
|
|
195
117
|
})
|
|
196
118
|
);
|
|
197
|
-
} else
|
|
119
|
+
} else if (
|
|
120
|
+
isSpecifiedError(
|
|
121
|
+
err,
|
|
122
|
+
400,
|
|
123
|
+
'VALIDATION_ERROR',
|
|
124
|
+
'SandboxErrors.NUM_DEVELOPMENT_SANDBOXES_LIMIT_EXCEEDED_ERROR'
|
|
125
|
+
) &&
|
|
126
|
+
err.error &&
|
|
127
|
+
err.error.message
|
|
128
|
+
) {
|
|
129
|
+
logger.log('');
|
|
198
130
|
logger.error(err.error.message);
|
|
131
|
+
} else {
|
|
132
|
+
logErrorInstance(err);
|
|
199
133
|
}
|
|
200
134
|
process.exit(EXIT_CODES.ERROR);
|
|
201
135
|
}
|
|
202
136
|
try {
|
|
203
|
-
await
|
|
137
|
+
await sandboxCreatePersonalAccessKeyFlow(
|
|
138
|
+
env,
|
|
139
|
+
result.sandboxHubId,
|
|
140
|
+
result.name
|
|
141
|
+
);
|
|
204
142
|
process.exit(EXIT_CODES.SUCCESS);
|
|
205
143
|
} catch (err) {
|
|
206
144
|
logErrorInstance(err);
|
|
@@ -11,7 +11,7 @@ const { loadAndValidateOptions } = require('../../lib/validation');
|
|
|
11
11
|
const {
|
|
12
12
|
debugErrorAndContext,
|
|
13
13
|
} = require('@hubspot/cli-lib/errorHandlers/standardErrors');
|
|
14
|
-
|
|
14
|
+
const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');
|
|
15
15
|
const { deleteSandbox } = require('@hubspot/cli-lib/sandboxes');
|
|
16
16
|
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
17
17
|
const { getConfig, getEnv } = require('@hubspot/cli-lib');
|
|
@@ -26,12 +26,12 @@ const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
|
26
26
|
const { promptUser } = require('../../lib/prompts/promptUtils');
|
|
27
27
|
const { getHubSpotWebsiteOrigin } = require('@hubspot/cli-lib/lib/urls');
|
|
28
28
|
const { ENVIRONMENTS } = require('@hubspot/cli-lib/lib/constants');
|
|
29
|
+
const {
|
|
30
|
+
isSpecifiedError,
|
|
31
|
+
} = require('@hubspot/cli-lib/errorHandlers/apiErrors');
|
|
29
32
|
|
|
30
33
|
const i18nKey = 'cli.commands.sandbox.subcommands.delete';
|
|
31
34
|
|
|
32
|
-
const SANDBOX_NOT_FOUND = 'SandboxErrors.SANDBOX_NOT_FOUND';
|
|
33
|
-
const OBJECT_NOT_FOUND = 'OBJECT_NOT_FOUND';
|
|
34
|
-
|
|
35
35
|
exports.command = 'delete [--account]';
|
|
36
36
|
exports.describe = i18n(`${i18nKey}.describe`);
|
|
37
37
|
|
|
@@ -147,9 +147,12 @@ exports.handler = async options => {
|
|
|
147
147
|
);
|
|
148
148
|
|
|
149
149
|
if (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
isSpecifiedError(
|
|
151
|
+
err,
|
|
152
|
+
404,
|
|
153
|
+
'OBJECT_NOT_FOUND',
|
|
154
|
+
'SandboxErrors.SANDBOX_NOT_FOUND'
|
|
155
|
+
)
|
|
153
156
|
) {
|
|
154
157
|
logger.log('');
|
|
155
158
|
logger.warn(
|
|
@@ -167,7 +170,7 @@ exports.handler = async options => {
|
|
|
167
170
|
}
|
|
168
171
|
process.exit(EXIT_CODES.SUCCESS);
|
|
169
172
|
} else {
|
|
170
|
-
|
|
173
|
+
logErrorInstance(err);
|
|
171
174
|
}
|
|
172
175
|
process.exit(EXIT_CODES.ERROR);
|
|
173
176
|
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
const {
|
|
2
|
+
addAccountOptions,
|
|
3
|
+
addConfigOptions,
|
|
4
|
+
getAccountId,
|
|
5
|
+
addUseEnvironmentOptions,
|
|
6
|
+
addTestingOptions,
|
|
7
|
+
} = require('../../lib/commonOpts');
|
|
8
|
+
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
9
|
+
const { logger } = require('@hubspot/cli-lib/logger');
|
|
10
|
+
const Spinnies = require('spinnies');
|
|
11
|
+
const { initiateSync } = require('@hubspot/cli-lib/sandboxes');
|
|
12
|
+
const { loadAndValidateOptions } = require('../../lib/validation');
|
|
13
|
+
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
14
|
+
const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');
|
|
15
|
+
const { ENVIRONMENTS } = require('@hubspot/cli-lib/lib/constants');
|
|
16
|
+
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
17
|
+
const { getAccountConfig, getEnv } = require('@hubspot/cli-lib');
|
|
18
|
+
const { getHubSpotWebsiteOrigin } = require('@hubspot/cli-lib/lib/urls');
|
|
19
|
+
const { promptUser } = require('../../lib/prompts/promptUtils');
|
|
20
|
+
const { uiLine } = require('../../lib/ui');
|
|
21
|
+
const {
|
|
22
|
+
getAccountName,
|
|
23
|
+
getAvailableSyncTypes,
|
|
24
|
+
pollSyncTaskStatus,
|
|
25
|
+
} = require('../../lib/sandboxes');
|
|
26
|
+
const {
|
|
27
|
+
isMissingScopeError,
|
|
28
|
+
isSpecifiedError,
|
|
29
|
+
} = require('@hubspot/cli-lib/errorHandlers/apiErrors');
|
|
30
|
+
|
|
31
|
+
const i18nKey = 'cli.commands.sandbox.subcommands.sync';
|
|
32
|
+
|
|
33
|
+
exports.command = 'sync';
|
|
34
|
+
exports.describe = i18n(`${i18nKey}.describe`);
|
|
35
|
+
|
|
36
|
+
exports.handler = async options => {
|
|
37
|
+
await loadAndValidateOptions(options);
|
|
38
|
+
|
|
39
|
+
const { force } = options; // For scripting purposes
|
|
40
|
+
const accountId = getAccountId(options);
|
|
41
|
+
const accountConfig = getAccountConfig(accountId);
|
|
42
|
+
const spinnies = new Spinnies({
|
|
43
|
+
succeedColor: 'white',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
trackCommandUsage('sandbox-sync', null, accountId);
|
|
47
|
+
|
|
48
|
+
if (
|
|
49
|
+
// Check if default account is a sandbox, otherwise exit
|
|
50
|
+
// sandboxAccountType is null for non-sandbox portals, and one of 'DEVELOPER' or 'STANDARD' for sandbox portals. Undefined is to handle older config entries.
|
|
51
|
+
accountConfig.sandboxAccountType === undefined ||
|
|
52
|
+
accountConfig.sandboxAccountType === null
|
|
53
|
+
) {
|
|
54
|
+
trackCommandUsage('sandbox-sync', { successful: false }, accountId);
|
|
55
|
+
|
|
56
|
+
logger.error(i18n(`${i18nKey}.failure.notSandbox`));
|
|
57
|
+
|
|
58
|
+
process.exit(EXIT_CODES.ERROR);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Verify parent account exists in the config
|
|
62
|
+
let parentAccountId = accountConfig.parentAccountId || undefined;
|
|
63
|
+
if (!parentAccountId || !getAccountId({ account: parentAccountId })) {
|
|
64
|
+
logger.log('');
|
|
65
|
+
logger.error(
|
|
66
|
+
i18n(`${i18nKey}.failure.missingParentPortal`, {
|
|
67
|
+
sandboxName: getAccountName(accountConfig),
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
process.exit(EXIT_CODES.ERROR);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const parentAccountConfig = getAccountConfig(parentAccountId);
|
|
74
|
+
const isDevelopmentSandbox = accountConfig.sandboxAccountType === 'DEVELOPER';
|
|
75
|
+
const isStandardSandbox = accountConfig.sandboxAccountType === 'STANDARD';
|
|
76
|
+
|
|
77
|
+
if (isDevelopmentSandbox) {
|
|
78
|
+
logger.log(i18n(`${i18nKey}.info.developmentSandbox`));
|
|
79
|
+
logger.log(
|
|
80
|
+
i18n(`${i18nKey}.info.sync`, {
|
|
81
|
+
parentAccountName: getAccountName(parentAccountConfig),
|
|
82
|
+
sandboxName: getAccountName(accountConfig),
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
uiLine();
|
|
86
|
+
logger.warn(i18n(`${i18nKey}.warning.developmentSandbox`));
|
|
87
|
+
uiLine();
|
|
88
|
+
logger.log('');
|
|
89
|
+
|
|
90
|
+
if (!force) {
|
|
91
|
+
// Skip confirmation if force flag is present.
|
|
92
|
+
const { confirmSandboxSyncPrompt: confirmed } = await promptUser([
|
|
93
|
+
{
|
|
94
|
+
name: 'confirmSandboxSyncPrompt',
|
|
95
|
+
type: 'confirm',
|
|
96
|
+
message: i18n(`${i18nKey}.confirm.developmentSandbox`, {
|
|
97
|
+
parentAccountName: getAccountName(parentAccountConfig),
|
|
98
|
+
sandboxName: getAccountName(accountConfig),
|
|
99
|
+
}),
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
102
|
+
if (!confirmed) {
|
|
103
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} else if (isStandardSandbox) {
|
|
107
|
+
const standardSyncUrl = `${getHubSpotWebsiteOrigin(
|
|
108
|
+
getEnv(accountId) === 'qa' ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD
|
|
109
|
+
)}/sandboxes-developer/${parentAccountId}/sync?step=select_sync_path&id=${parentAccountId}_${accountId}`;
|
|
110
|
+
|
|
111
|
+
logger.log(
|
|
112
|
+
i18n(`${i18nKey}.info.standardSandbox`, {
|
|
113
|
+
url: standardSyncUrl,
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
logger.log(
|
|
117
|
+
i18n(`${i18nKey}.info.sync`, {
|
|
118
|
+
parentAccountName: getAccountName(parentAccountConfig),
|
|
119
|
+
sandboxName: getAccountName(accountConfig),
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
uiLine();
|
|
123
|
+
logger.warn(i18n(`${i18nKey}.warning.standardSandbox`));
|
|
124
|
+
uiLine();
|
|
125
|
+
logger.log('');
|
|
126
|
+
|
|
127
|
+
if (!force) {
|
|
128
|
+
// Skip confirmation if force flag is present.
|
|
129
|
+
const { confirmSandboxSyncPrompt: confirmed } = await promptUser([
|
|
130
|
+
{
|
|
131
|
+
name: 'confirmSandboxSyncPrompt',
|
|
132
|
+
type: 'confirm',
|
|
133
|
+
message: i18n(`${i18nKey}.confirm.standardSandbox`, {
|
|
134
|
+
parentAccountName: getAccountName(parentAccountConfig),
|
|
135
|
+
sandboxName: getAccountName(accountConfig),
|
|
136
|
+
}),
|
|
137
|
+
},
|
|
138
|
+
]);
|
|
139
|
+
if (!confirmed) {
|
|
140
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
logger.error('Sync must be run in a sandbox account.');
|
|
145
|
+
process.exit(EXIT_CODES.ERROR);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let initiateSyncResponse;
|
|
149
|
+
|
|
150
|
+
const baseUrl = getHubSpotWebsiteOrigin(
|
|
151
|
+
getEnv(accountId) === 'qa' ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD
|
|
152
|
+
);
|
|
153
|
+
const syncStatusUrl = `${baseUrl}/sandboxes-developer/${parentAccountId}/${
|
|
154
|
+
isDevelopmentSandbox ? 'development' : 'standard'
|
|
155
|
+
}`;
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
logger.log('');
|
|
159
|
+
spinnies.add('sandboxSync', {
|
|
160
|
+
text: i18n(`${i18nKey}.loading.startSync`),
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Fetches sync types based on default account. Parent account required for fetch
|
|
164
|
+
const tasks = await getAvailableSyncTypes(
|
|
165
|
+
parentAccountConfig,
|
|
166
|
+
accountConfig
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
initiateSyncResponse = await initiateSync(
|
|
170
|
+
parentAccountId,
|
|
171
|
+
accountId,
|
|
172
|
+
tasks,
|
|
173
|
+
accountId
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
logger.log(i18n(`${i18nKey}.info.earlyExit`));
|
|
177
|
+
logger.log('');
|
|
178
|
+
spinnies.succeed('sandboxSync', {
|
|
179
|
+
text: i18n(`${i18nKey}.loading.succeed`),
|
|
180
|
+
});
|
|
181
|
+
} catch (err) {
|
|
182
|
+
trackCommandUsage('sandbox-sync', { successful: false }, accountId);
|
|
183
|
+
|
|
184
|
+
spinnies.fail('sandboxSync', {
|
|
185
|
+
text: i18n(`${i18nKey}.loading.fail`),
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
logger.log('');
|
|
189
|
+
if (isMissingScopeError(err)) {
|
|
190
|
+
logger.error(
|
|
191
|
+
i18n(`${i18nKey}.failure.missingScopes`, {
|
|
192
|
+
accountName: getAccountName(parentAccountConfig),
|
|
193
|
+
})
|
|
194
|
+
);
|
|
195
|
+
} else if (
|
|
196
|
+
isSpecifiedError(
|
|
197
|
+
err,
|
|
198
|
+
429,
|
|
199
|
+
'RATE_LIMITS',
|
|
200
|
+
'sandboxes-sync-api.SYNC_IN_PROGRESS'
|
|
201
|
+
)
|
|
202
|
+
) {
|
|
203
|
+
logger.error(
|
|
204
|
+
i18n(`${i18nKey}.failure.syncInProgress`, {
|
|
205
|
+
url: `${baseUrl}/sandboxes-developer/${parentAccountId}/syncactivitylog`,
|
|
206
|
+
})
|
|
207
|
+
);
|
|
208
|
+
} else if (
|
|
209
|
+
isSpecifiedError(
|
|
210
|
+
err,
|
|
211
|
+
403,
|
|
212
|
+
'BANNED',
|
|
213
|
+
'sandboxes-sync-api.SYNC_NOT_ALLOWED_INVALID_USERID'
|
|
214
|
+
)
|
|
215
|
+
) {
|
|
216
|
+
// This will only trigger if a user is not a super admin of the target account.
|
|
217
|
+
logger.error(
|
|
218
|
+
i18n(`${i18nKey}.failure.notSuperAdmin`, {
|
|
219
|
+
account: getAccountName(accountConfig),
|
|
220
|
+
})
|
|
221
|
+
);
|
|
222
|
+
} else if (
|
|
223
|
+
isSpecifiedError(
|
|
224
|
+
err,
|
|
225
|
+
404,
|
|
226
|
+
'OBJECT_NOT_FOUND',
|
|
227
|
+
'SandboxErrors.SANDBOX_NOT_FOUND'
|
|
228
|
+
)
|
|
229
|
+
) {
|
|
230
|
+
logger.error(
|
|
231
|
+
i18n(`${i18nKey}.failure.objectNotFound`, {
|
|
232
|
+
account: getAccountName(accountConfig),
|
|
233
|
+
})
|
|
234
|
+
);
|
|
235
|
+
} else {
|
|
236
|
+
logErrorInstance(err);
|
|
237
|
+
}
|
|
238
|
+
logger.log('');
|
|
239
|
+
|
|
240
|
+
process.exit(EXIT_CODES.ERROR);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
try {
|
|
244
|
+
logger.log('');
|
|
245
|
+
logger.log('Sync progress:');
|
|
246
|
+
// Poll sync task status to show progress bars
|
|
247
|
+
await pollSyncTaskStatus(
|
|
248
|
+
parentAccountId,
|
|
249
|
+
initiateSyncResponse.id,
|
|
250
|
+
syncStatusUrl
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
logger.log('');
|
|
254
|
+
spinnies.add('syncComplete', {
|
|
255
|
+
text: i18n(`${i18nKey}.polling.syncing`),
|
|
256
|
+
});
|
|
257
|
+
spinnies.succeed('syncComplete', {
|
|
258
|
+
text: i18n(`${i18nKey}.polling.succeed`),
|
|
259
|
+
});
|
|
260
|
+
logger.log('');
|
|
261
|
+
logger.log(
|
|
262
|
+
i18n(`${i18nKey}.info.syncStatus`, {
|
|
263
|
+
url: syncStatusUrl,
|
|
264
|
+
})
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
268
|
+
} catch (err) {
|
|
269
|
+
// If polling fails at this point, we do not track a failed sync since it is running in the background.
|
|
270
|
+
logErrorInstance(err);
|
|
271
|
+
|
|
272
|
+
spinnies.add('syncComplete', {
|
|
273
|
+
text: i18n(`${i18nKey}.polling.syncing`),
|
|
274
|
+
});
|
|
275
|
+
spinnies.fail('syncComplete', {
|
|
276
|
+
text: i18n(`${i18nKey}.polling.fail`, {
|
|
277
|
+
url: syncStatusUrl,
|
|
278
|
+
}),
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
process.exit(EXIT_CODES.ERROR);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
exports.builder = yargs => {
|
|
286
|
+
yargs.option('f', {
|
|
287
|
+
type: 'boolean',
|
|
288
|
+
alias: 'force',
|
|
289
|
+
describe: i18n(`${i18nKey}.examples.force`),
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
yargs.example([['$0 sandbox sync', i18n(`${i18nKey}.examples.default`)]]);
|
|
293
|
+
|
|
294
|
+
addConfigOptions(yargs, true);
|
|
295
|
+
addAccountOptions(yargs, true);
|
|
296
|
+
addUseEnvironmentOptions(yargs, true);
|
|
297
|
+
addTestingOptions(yargs, true);
|
|
298
|
+
|
|
299
|
+
return yargs;
|
|
300
|
+
};
|
package/commands/sandbox.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { addConfigOptions, addAccountOptions } = require('../lib/commonOpts');
|
|
2
2
|
const create = require('./sandbox/create');
|
|
3
3
|
const del = require('./sandbox/delete');
|
|
4
|
+
const sync = require('./sandbox/sync');
|
|
4
5
|
|
|
5
6
|
// const i18nKey = 'cli.commands.sandbox';
|
|
6
7
|
|
|
@@ -14,6 +15,7 @@ exports.builder = yargs => {
|
|
|
14
15
|
yargs
|
|
15
16
|
.command(create)
|
|
16
17
|
.command(del)
|
|
18
|
+
.command(sync)
|
|
17
19
|
.demandCommand(1, '');
|
|
18
20
|
|
|
19
21
|
return yargs;
|