@hubspot/cli 5.1.3 → 5.1.4-beta.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/commands/accounts/list.js +43 -31
- package/commands/customObject/create.js +10 -6
- package/commands/customObject/schema/create.js +10 -9
- package/commands/customObject/schema/delete.js +6 -6
- package/commands/customObject/schema/fetch.js +1 -1
- package/commands/customObject/schema/update.js +10 -9
- package/commands/functions/deploy.js +1 -1
- package/commands/functions/list.js +1 -1
- package/commands/hubdb/clear.js +4 -4
- package/commands/hubdb/create.js +5 -5
- package/commands/hubdb/delete.js +3 -3
- package/commands/hubdb/fetch.js +3 -3
- package/commands/mv.js +3 -2
- package/commands/project/deploy.js +4 -1
- package/commands/project/dev.js +33 -14
- package/commands/project/download.js +1 -1
- package/commands/project/listBuilds.js +1 -1
- package/commands/project/logs.js +7 -7
- package/commands/project/upload.js +5 -2
- package/commands/project/watch.js +7 -2
- package/commands/sandbox/create.js +6 -7
- package/commands/sandbox/delete.js +8 -11
- package/commands/sandbox/sync.js +18 -17
- package/commands/secrets/addSecret.js +5 -6
- package/commands/secrets/deleteSecret.js +5 -6
- package/commands/secrets/listSecrets.js +5 -6
- package/commands/secrets/updateSecret.js +5 -6
- package/lang/en.lyaml +3 -2
- package/lib/DevServerManager.js +12 -6
- package/lib/LocalDevManager.js +1 -1
- package/lib/constants.js +11 -0
- package/lib/developerTestAccounts.js +14 -0
- package/lib/lang.js +3 -1
- package/lib/marketplace-validate.js +1 -1
- package/lib/projects.js +6 -5
- package/lib/projectsWatch.js +61 -19
- package/lib/prompts/accountsPrompt.js +5 -7
- package/lib/prompts/downloadProjectPrompt.js +1 -1
- package/lib/prompts/projectDevTargetAccountPrompt.js +15 -11
- package/lib/prompts/projectsLogsPrompt.js +1 -1
- package/lib/prompts/sandboxesPrompt.js +12 -13
- package/lib/{sandbox-create.js → sandboxCreate.js} +100 -13
- package/lib/{sandbox-sync.js → sandboxSync.js} +7 -7
- package/lib/sandboxes.js +53 -136
- package/lib/schema.js +4 -2
- package/lib/ui.js +16 -5
- package/lib/validation.js +8 -6
- package/package.json +4 -4
package/lib/projectsWatch.js
CHANGED
|
@@ -16,7 +16,8 @@ const {
|
|
|
16
16
|
uploadFileToBuild,
|
|
17
17
|
deleteFileFromBuild,
|
|
18
18
|
queueBuild,
|
|
19
|
-
} = require('@hubspot/
|
|
19
|
+
} = require('@hubspot/local-dev-lib/api/projects');
|
|
20
|
+
const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/apiErrors');
|
|
20
21
|
const { ERROR_TYPES } = require('@hubspot/cli-lib/lib/constants');
|
|
21
22
|
|
|
22
23
|
const i18nKey = 'cli.commands.project.subcommands.watch';
|
|
@@ -29,25 +30,40 @@ let currentBuildId = null;
|
|
|
29
30
|
let handleBuildStatus, handleUserInput;
|
|
30
31
|
let timer;
|
|
31
32
|
|
|
32
|
-
const processStandByQueue = async (accountId, projectName) => {
|
|
33
|
+
const processStandByQueue = async (accountId, projectName, platformVersion) => {
|
|
33
34
|
queue.addAll(
|
|
34
35
|
standbyeQueue.map(({ filePath, remotePath, action }) => {
|
|
35
36
|
return async () => {
|
|
36
|
-
queueFileOrFolder(
|
|
37
|
+
queueFileOrFolder(
|
|
38
|
+
accountId,
|
|
39
|
+
projectName,
|
|
40
|
+
platformVersion,
|
|
41
|
+
filePath,
|
|
42
|
+
remotePath,
|
|
43
|
+
action
|
|
44
|
+
);
|
|
37
45
|
};
|
|
38
46
|
})
|
|
39
47
|
);
|
|
40
48
|
standbyeQueue.length = 0;
|
|
41
|
-
debounceQueueBuild(accountId, projectName);
|
|
49
|
+
debounceQueueBuild(accountId, projectName, platformVersion);
|
|
42
50
|
};
|
|
43
51
|
|
|
44
|
-
const createNewStagingBuild = async (
|
|
45
|
-
|
|
52
|
+
const createNewStagingBuild = async (
|
|
53
|
+
accountId,
|
|
54
|
+
projectName,
|
|
55
|
+
platformVersion
|
|
56
|
+
) => {
|
|
57
|
+
currentBuildId = await createNewBuild(
|
|
58
|
+
accountId,
|
|
59
|
+
projectName,
|
|
60
|
+
platformVersion
|
|
61
|
+
);
|
|
46
62
|
|
|
47
63
|
handleUserInput(accountId, projectName, currentBuildId);
|
|
48
64
|
};
|
|
49
65
|
|
|
50
|
-
const debounceQueueBuild = (accountId, projectName) => {
|
|
66
|
+
const debounceQueueBuild = (accountId, projectName, platformVersion) => {
|
|
51
67
|
if (timer) {
|
|
52
68
|
clearTimeout(timer);
|
|
53
69
|
}
|
|
@@ -58,12 +74,13 @@ const debounceQueueBuild = (accountId, projectName) => {
|
|
|
58
74
|
await queue.onIdle();
|
|
59
75
|
|
|
60
76
|
try {
|
|
61
|
-
await queueBuild(accountId, projectName);
|
|
77
|
+
await queueBuild(accountId, projectName, platformVersion);
|
|
62
78
|
logger.debug(i18n(`${i18nKey}.debug.buildStarted`, { projectName }));
|
|
63
79
|
} catch (err) {
|
|
64
80
|
if (
|
|
65
|
-
err
|
|
66
|
-
|
|
81
|
+
isSpecifiedError(err, {
|
|
82
|
+
subCategory: ERROR_TYPES.MISSING_PROJECT_PROVISION,
|
|
83
|
+
})
|
|
67
84
|
) {
|
|
68
85
|
logger.log(i18n(`${i18nKey}.logs.watchCancelledFromUi`));
|
|
69
86
|
process.exit(0);
|
|
@@ -79,10 +96,10 @@ const debounceQueueBuild = (accountId, projectName) => {
|
|
|
79
96
|
|
|
80
97
|
await handleBuildStatus(accountId, projectName, currentBuildId);
|
|
81
98
|
|
|
82
|
-
await createNewStagingBuild(accountId, projectName);
|
|
99
|
+
await createNewStagingBuild(accountId, projectName, platformVersion);
|
|
83
100
|
|
|
84
101
|
if (standbyeQueue.length > 0) {
|
|
85
|
-
await processStandByQueue(accountId, projectName);
|
|
102
|
+
await processStandByQueue(accountId, projectName, platformVersion);
|
|
86
103
|
}
|
|
87
104
|
|
|
88
105
|
queue.start();
|
|
@@ -94,6 +111,7 @@ const debounceQueueBuild = (accountId, projectName) => {
|
|
|
94
111
|
const queueFileOrFolder = async (
|
|
95
112
|
accountId,
|
|
96
113
|
projectName,
|
|
114
|
+
platformVersion,
|
|
97
115
|
filePath,
|
|
98
116
|
remotePath,
|
|
99
117
|
action
|
|
@@ -107,7 +125,7 @@ const queueFileOrFolder = async (
|
|
|
107
125
|
return;
|
|
108
126
|
}
|
|
109
127
|
if (!queue.isPaused) {
|
|
110
|
-
debounceQueueBuild(accountId, projectName);
|
|
128
|
+
debounceQueueBuild(accountId, projectName, platformVersion);
|
|
111
129
|
}
|
|
112
130
|
|
|
113
131
|
logger.debug(i18n(`${i18nKey}.debug.uploading`, { filePath, remotePath }));
|
|
@@ -130,14 +148,18 @@ const queueFileOrFolder = async (
|
|
|
130
148
|
});
|
|
131
149
|
};
|
|
132
150
|
|
|
133
|
-
const createNewBuild = async (accountId, projectName) => {
|
|
151
|
+
const createNewBuild = async (accountId, projectName, platformVersion) => {
|
|
134
152
|
try {
|
|
135
153
|
logger.debug(i18n(`${i18nKey}.debug.attemptNewBuild`));
|
|
136
|
-
const { buildId } = await provisionBuild(
|
|
154
|
+
const { buildId } = await provisionBuild(
|
|
155
|
+
accountId,
|
|
156
|
+
projectName,
|
|
157
|
+
platformVersion
|
|
158
|
+
);
|
|
137
159
|
return buildId;
|
|
138
160
|
} catch (err) {
|
|
139
161
|
logApiErrorInstance(err, new ApiErrorContext({ accountId, projectName }));
|
|
140
|
-
if (err
|
|
162
|
+
if (isSpecifiedError(err, { subCategory: ERROR_TYPES.PROJECT_LOCKED })) {
|
|
141
163
|
await cancelStagedBuild(accountId, projectName);
|
|
142
164
|
logger.log(i18n(`${i18nKey}.logs.previousStagingBuildCancelled`));
|
|
143
165
|
}
|
|
@@ -148,6 +170,7 @@ const createNewBuild = async (accountId, projectName) => {
|
|
|
148
170
|
const handleWatchEvent = async (
|
|
149
171
|
accountId,
|
|
150
172
|
projectName,
|
|
173
|
+
platformVersion,
|
|
151
174
|
projectSourceDir,
|
|
152
175
|
filePath,
|
|
153
176
|
action = 'upload'
|
|
@@ -165,6 +188,7 @@ const handleWatchEvent = async (
|
|
|
165
188
|
await queueFileOrFolder(
|
|
166
189
|
accountId,
|
|
167
190
|
projectName,
|
|
191
|
+
platformVersion,
|
|
168
192
|
filePath,
|
|
169
193
|
remotePath,
|
|
170
194
|
action
|
|
@@ -184,7 +208,11 @@ const createWatcher = async (
|
|
|
184
208
|
handleBuildStatus = handleBuildStatusFn;
|
|
185
209
|
handleUserInput = handleUserInputFn;
|
|
186
210
|
|
|
187
|
-
await createNewStagingBuild(
|
|
211
|
+
await createNewStagingBuild(
|
|
212
|
+
accountId,
|
|
213
|
+
projectConfig.name,
|
|
214
|
+
projectConfig.platformVersion
|
|
215
|
+
);
|
|
188
216
|
|
|
189
217
|
const watcher = chokidar.watch(projectSourceDir, {
|
|
190
218
|
ignoreInitial: true,
|
|
@@ -195,15 +223,28 @@ const createWatcher = async (
|
|
|
195
223
|
logger.log(`\n> Press ${chalk.bold('q')} to quit watching\n`);
|
|
196
224
|
});
|
|
197
225
|
watcher.on('add', async path => {
|
|
198
|
-
handleWatchEvent(
|
|
226
|
+
handleWatchEvent(
|
|
227
|
+
accountId,
|
|
228
|
+
projectConfig.name,
|
|
229
|
+
projectConfig.platformVersion,
|
|
230
|
+
projectSourceDir,
|
|
231
|
+
path
|
|
232
|
+
);
|
|
199
233
|
});
|
|
200
234
|
watcher.on('change', async path => {
|
|
201
|
-
handleWatchEvent(
|
|
235
|
+
handleWatchEvent(
|
|
236
|
+
accountId,
|
|
237
|
+
projectConfig.name,
|
|
238
|
+
projectConfig.platformVersion,
|
|
239
|
+
projectSourceDir,
|
|
240
|
+
path
|
|
241
|
+
);
|
|
202
242
|
});
|
|
203
243
|
watcher.on('unlink', async path => {
|
|
204
244
|
handleWatchEvent(
|
|
205
245
|
accountId,
|
|
206
246
|
projectConfig.name,
|
|
247
|
+
projectConfig.platformVersion,
|
|
207
248
|
projectSourceDir,
|
|
208
249
|
path,
|
|
209
250
|
'deleteFile'
|
|
@@ -213,6 +254,7 @@ const createWatcher = async (
|
|
|
213
254
|
handleWatchEvent(
|
|
214
255
|
accountId,
|
|
215
256
|
projectConfig.name,
|
|
257
|
+
projectConfig.platformVersion,
|
|
216
258
|
projectSourceDir,
|
|
217
259
|
path,
|
|
218
260
|
'deleteFolder'
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
const { updateDefaultAccount } = require('@hubspot/local-dev-lib/config');
|
|
2
2
|
const { promptUser } = require('./promptUtils');
|
|
3
3
|
const { i18n } = require('../lang');
|
|
4
|
-
const {
|
|
4
|
+
const { uiAccountDescription } = require('../ui');
|
|
5
5
|
|
|
6
6
|
const mapAccountChoices = portals =>
|
|
7
|
-
portals.map(p => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
});
|
|
7
|
+
portals.map(p => ({
|
|
8
|
+
name: uiAccountDescription(p.portalId, false),
|
|
9
|
+
value: p.name || p.portalId,
|
|
10
|
+
}));
|
|
13
11
|
|
|
14
12
|
const i18nKey = 'cli.commands.accounts.subcommands.use';
|
|
15
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { promptUser } = require('./promptUtils');
|
|
2
2
|
const { getAccountId } = require('@hubspot/local-dev-lib/config');
|
|
3
|
-
const { fetchProjects } = require('@hubspot/
|
|
3
|
+
const { fetchProjects } = require('@hubspot/local-dev-lib/api/projects');
|
|
4
4
|
const {
|
|
5
5
|
logApiErrorInstance,
|
|
6
6
|
ApiErrorContext,
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
const { promptUser } = require('./promptUtils');
|
|
2
2
|
const { i18n } = require('../lang');
|
|
3
3
|
const { uiAccountDescription, uiCommandReference } = require('../ui');
|
|
4
|
-
const { isSandbox
|
|
4
|
+
const { isSandbox } = require('../sandboxes');
|
|
5
5
|
const { getAccountId } = require('@hubspot/local-dev-lib/config');
|
|
6
6
|
const { getSandboxUsageLimits } = require('@hubspot/local-dev-lib/sandboxes');
|
|
7
7
|
const { logger } = require('@hubspot/cli-lib/logger');
|
|
8
|
+
const { DEVELOPER_SANDBOX, STANDARD_SANDBOX } = require('../constants');
|
|
8
9
|
|
|
9
10
|
const i18nKey = 'cli.lib.prompts.projectDevTargetAccountPrompt';
|
|
10
11
|
|
|
11
12
|
const mapSandboxAccount = accountConfig => ({
|
|
12
|
-
name:
|
|
13
|
+
name: uiAccountDescription(accountConfig.portalId, false),
|
|
13
14
|
value: {
|
|
14
15
|
targetAccountId: getAccountId(accountConfig.name),
|
|
15
16
|
createNewSandbox: false,
|
|
@@ -33,15 +34,18 @@ const selectTargetAccountPrompt = async (accounts, defaultAccountConfig) => {
|
|
|
33
34
|
);
|
|
34
35
|
let disabledMessage = false;
|
|
35
36
|
|
|
36
|
-
if (
|
|
37
|
-
|
|
37
|
+
if (
|
|
38
|
+
sandboxUsage[DEVELOPER_SANDBOX] &&
|
|
39
|
+
sandboxUsage[DEVELOPER_SANDBOX].available === 0
|
|
40
|
+
) {
|
|
41
|
+
if (sandboxAccounts.length < sandboxUsage[DEVELOPER_SANDBOX].limit) {
|
|
38
42
|
disabledMessage = i18n(`${i18nKey}.sandboxLimitWithSuggestion`, {
|
|
39
43
|
authCommand: uiCommandReference('hs auth'),
|
|
40
|
-
limit: sandboxUsage[
|
|
44
|
+
limit: sandboxUsage[DEVELOPER_SANDBOX].limit,
|
|
41
45
|
});
|
|
42
46
|
} else {
|
|
43
47
|
disabledMessage = i18n(`${i18nKey}.sandboxLimit`, {
|
|
44
|
-
limit: sandboxUsage[
|
|
48
|
+
limit: sandboxUsage[DEVELOPER_SANDBOX].limit,
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
51
|
}
|
|
@@ -49,10 +53,10 @@ const selectTargetAccountPrompt = async (accounts, defaultAccountConfig) => {
|
|
|
49
53
|
// Order choices by Developer Sandbox -> Standard Sandbox
|
|
50
54
|
const choices = [
|
|
51
55
|
...sandboxAccounts
|
|
52
|
-
.filter(a => a.sandboxAccountType ===
|
|
56
|
+
.filter(a => a.sandboxAccountType === DEVELOPER_SANDBOX)
|
|
53
57
|
.map(mapSandboxAccount),
|
|
54
58
|
...sandboxAccounts
|
|
55
|
-
.filter(a => a.sandboxAccountType ===
|
|
59
|
+
.filter(a => a.sandboxAccountType === STANDARD_SANDBOX)
|
|
56
60
|
.map(mapSandboxAccount),
|
|
57
61
|
{
|
|
58
62
|
name: i18n(`${i18nKey}.createNewSandboxOption`),
|
|
@@ -85,12 +89,12 @@ const selectTargetAccountPrompt = async (accounts, defaultAccountConfig) => {
|
|
|
85
89
|
return targetAccountInfo;
|
|
86
90
|
};
|
|
87
91
|
|
|
88
|
-
const
|
|
92
|
+
const confirmDefaultAccountPrompt = async (accountName, accountType) => {
|
|
89
93
|
const { useDefaultAccount } = await promptUser([
|
|
90
94
|
{
|
|
91
95
|
name: 'useDefaultAccount',
|
|
92
96
|
type: 'confirm',
|
|
93
|
-
message: i18n(`${i18nKey}.
|
|
97
|
+
message: i18n(`${i18nKey}.confirmDefaultAccount`, {
|
|
94
98
|
accountName,
|
|
95
99
|
accountType,
|
|
96
100
|
}),
|
|
@@ -101,5 +105,5 @@ const confirmDefaultSandboxAccountPrompt = async (accountName, accountType) => {
|
|
|
101
105
|
|
|
102
106
|
module.exports = {
|
|
103
107
|
selectTargetAccountPrompt,
|
|
104
|
-
|
|
108
|
+
confirmDefaultAccountPrompt,
|
|
105
109
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { i18n } = require('../lang');
|
|
2
|
-
const { fetchProject } = require('@hubspot/
|
|
2
|
+
const { fetchProject } = require('@hubspot/local-dev-lib/api/projects');
|
|
3
3
|
const { promptUser } = require('./promptUtils');
|
|
4
4
|
const { getAccountId } = require('../commonOpts');
|
|
5
5
|
const { getProjectConfig, ensureProjectExists } = require('../projects');
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
const { promptUser } = require('./promptUtils');
|
|
2
2
|
const { i18n } = require('../lang');
|
|
3
|
+
const { accountNameExistsInConfig } = require('@hubspot/local-dev-lib/config');
|
|
4
|
+
const { uiAccountDescription } = require('../ui');
|
|
3
5
|
const {
|
|
4
|
-
getSandboxTypeAsString,
|
|
5
|
-
STANDARD_SANDBOX,
|
|
6
6
|
DEVELOPER_SANDBOX,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
STANDARD_SANDBOX,
|
|
8
|
+
STANDARD_SANDBOX_TYPE,
|
|
9
|
+
DEVELOPER_SANDBOX_TYPE,
|
|
10
|
+
} = require('../constants');
|
|
9
11
|
|
|
10
12
|
const i18nKey = 'cli.lib.prompts.sandboxesPrompt';
|
|
11
13
|
|
|
@@ -13,11 +15,8 @@ const mapSandboxAccountChoices = portals =>
|
|
|
13
15
|
portals
|
|
14
16
|
.filter(p => p.sandboxAccountType && p.sandboxAccountType !== null)
|
|
15
17
|
.map(p => {
|
|
16
|
-
const sandboxName = `[${getSandboxTypeAsString(
|
|
17
|
-
p.sandboxAccountType
|
|
18
|
-
)} sandbox] `;
|
|
19
18
|
return {
|
|
20
|
-
name:
|
|
19
|
+
name: uiAccountDescription(p.portalId, false),
|
|
21
20
|
value: p.name || p.portalId,
|
|
22
21
|
};
|
|
23
22
|
});
|
|
@@ -34,8 +33,8 @@ const mapNonSandboxAccountChoices = portals =>
|
|
|
34
33
|
};
|
|
35
34
|
});
|
|
36
35
|
|
|
37
|
-
const sandboxNamePrompt = (type =
|
|
38
|
-
const isDeveloperSandbox = type ===
|
|
36
|
+
const sandboxNamePrompt = (type = STANDARD_SANDBOX_TYPE) => {
|
|
37
|
+
const isDeveloperSandbox = type === DEVELOPER_SANDBOX_TYPE;
|
|
39
38
|
const namePromptMessage = isDeveloperSandbox
|
|
40
39
|
? `${i18nKey}.name.developmentSandboxMessage`
|
|
41
40
|
: `${i18nKey}.name.message`;
|
|
@@ -61,11 +60,11 @@ const sandboxNamePrompt = (type = STANDARD_SANDBOX) => {
|
|
|
61
60
|
const sandboxTypeChoices = [
|
|
62
61
|
{
|
|
63
62
|
name: i18n(`${i18nKey}.type.developer`),
|
|
64
|
-
value:
|
|
63
|
+
value: DEVELOPER_SANDBOX,
|
|
65
64
|
},
|
|
66
65
|
{
|
|
67
66
|
name: i18n(`${i18nKey}.type.standard`),
|
|
68
|
-
value:
|
|
67
|
+
value: STANDARD_SANDBOX,
|
|
69
68
|
},
|
|
70
69
|
];
|
|
71
70
|
|
|
@@ -77,7 +76,7 @@ const sandboxTypePrompt = () => {
|
|
|
77
76
|
type: 'list',
|
|
78
77
|
look: false,
|
|
79
78
|
choices: sandboxTypeChoices,
|
|
80
|
-
default:
|
|
79
|
+
default: DEVELOPER_SANDBOX,
|
|
81
80
|
},
|
|
82
81
|
]);
|
|
83
82
|
};
|
|
@@ -2,10 +2,7 @@ const SpinniesManager = require('./SpinniesManager');
|
|
|
2
2
|
const {
|
|
3
3
|
getSandboxLimit,
|
|
4
4
|
getHasSandboxesByType,
|
|
5
|
-
saveSandboxToConfig,
|
|
6
5
|
sandboxApiTypeMap,
|
|
7
|
-
STANDARD_SANDBOX,
|
|
8
|
-
DEVELOPER_SANDBOX,
|
|
9
6
|
} = require('./sandboxes');
|
|
10
7
|
const { i18n } = require('./lang');
|
|
11
8
|
const { logger } = require('@hubspot/cli-lib/logger');
|
|
@@ -21,9 +18,99 @@ const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
|
|
|
21
18
|
const { getEnv, getAccountId } = require('@hubspot/local-dev-lib/config');
|
|
22
19
|
const { createSandbox } = require('@hubspot/local-dev-lib/sandboxes');
|
|
23
20
|
const { getValidEnv } = require('@hubspot/local-dev-lib/environment');
|
|
21
|
+
const {
|
|
22
|
+
getAccessToken,
|
|
23
|
+
updateConfigWithAccessToken,
|
|
24
|
+
} = require('@hubspot/local-dev-lib/personalAccessKey');
|
|
25
|
+
const { uiAccountDescription } = require('./ui');
|
|
26
|
+
const {
|
|
27
|
+
DEVELOPER_SANDBOX_TYPE,
|
|
28
|
+
STANDARD_SANDBOX_TYPE,
|
|
29
|
+
} = require('./constants');
|
|
30
|
+
const {
|
|
31
|
+
personalAccessKeyPrompt,
|
|
32
|
+
} = require('./prompts/personalAccessKeyPrompt');
|
|
33
|
+
const { enterAccountNamePrompt } = require('./prompts/enterAccountNamePrompt');
|
|
34
|
+
const {
|
|
35
|
+
accountNameExistsInConfig,
|
|
36
|
+
writeConfig,
|
|
37
|
+
updateAccountConfig,
|
|
38
|
+
} = require('@hubspot/local-dev-lib/config');
|
|
24
39
|
|
|
25
40
|
const i18nKey = 'cli.lib.sandbox.create';
|
|
26
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @param {String} env - Environment (QA/Prod)
|
|
44
|
+
* @param {Object} result - Sandbox instance returned from API
|
|
45
|
+
* @param {Boolean} force - Force flag to skip prompt
|
|
46
|
+
* @returns {String} validName saved into config
|
|
47
|
+
*/
|
|
48
|
+
const saveSandboxToConfig = async (env, result, force = false) => {
|
|
49
|
+
let personalAccessKey = result.personalAccessKey;
|
|
50
|
+
if (!personalAccessKey) {
|
|
51
|
+
const configData = await personalAccessKeyPrompt({
|
|
52
|
+
env,
|
|
53
|
+
account: result.sandbox.sandboxHubId,
|
|
54
|
+
});
|
|
55
|
+
personalAccessKey = configData.personalAccessKey;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let updatedConfig;
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const token = await getAccessToken(personalAccessKey, env);
|
|
62
|
+
updatedConfig = await updateConfigWithAccessToken(
|
|
63
|
+
token,
|
|
64
|
+
personalAccessKey,
|
|
65
|
+
env
|
|
66
|
+
);
|
|
67
|
+
} catch (e) {
|
|
68
|
+
logErrorInstance(e);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!updatedConfig) {
|
|
72
|
+
throw new Error('Failed to update config with personal access key.');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let validName = updatedConfig.name;
|
|
76
|
+
if (!updatedConfig.name) {
|
|
77
|
+
const nameForConfig = result.sandbox.name
|
|
78
|
+
.toLowerCase()
|
|
79
|
+
.split(' ')
|
|
80
|
+
.join('-');
|
|
81
|
+
validName = nameForConfig;
|
|
82
|
+
const invalidAccountName = accountNameExistsInConfig(nameForConfig);
|
|
83
|
+
if (invalidAccountName) {
|
|
84
|
+
if (!force) {
|
|
85
|
+
logger.log('');
|
|
86
|
+
logger.warn(
|
|
87
|
+
i18n(
|
|
88
|
+
`cli.lib.prompts.enterAccountNamePrompt.errors.accountNameExists`,
|
|
89
|
+
{ name: nameForConfig }
|
|
90
|
+
)
|
|
91
|
+
);
|
|
92
|
+
const { name: promptName } = await enterAccountNamePrompt(
|
|
93
|
+
nameForConfig + `_${result.sandbox.sandboxHubId}`
|
|
94
|
+
);
|
|
95
|
+
validName = promptName;
|
|
96
|
+
} else {
|
|
97
|
+
// Basic invalid name handling when force flag is passed
|
|
98
|
+
validName = nameForConfig + `_${result.sandbox.sandboxHubId}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
updateAccountConfig({
|
|
103
|
+
...updatedConfig,
|
|
104
|
+
environment: updatedConfig.env,
|
|
105
|
+
tokenInfo: updatedConfig.auth.tokenInfo,
|
|
106
|
+
name: validName,
|
|
107
|
+
});
|
|
108
|
+
writeConfig();
|
|
109
|
+
|
|
110
|
+
logger.log('');
|
|
111
|
+
return validName;
|
|
112
|
+
};
|
|
113
|
+
|
|
27
114
|
/**
|
|
28
115
|
* @param {String} name - Name of sandbox
|
|
29
116
|
* @param {String} type - Sandbox type to be created (standard/developer)
|
|
@@ -75,14 +162,14 @@ const buildSandbox = async ({
|
|
|
75
162
|
if (isMissingScopeError(err)) {
|
|
76
163
|
logger.error(
|
|
77
164
|
i18n(`${i18nKey}.failure.scopes.message`, {
|
|
78
|
-
accountName:
|
|
165
|
+
accountName: uiAccountDescription(accountId),
|
|
79
166
|
})
|
|
80
167
|
);
|
|
81
168
|
const websiteOrigin = getHubSpotWebsiteOrigin(env);
|
|
82
169
|
const url = `${websiteOrigin}/personal-access-key/${accountId}`;
|
|
83
170
|
logger.info(
|
|
84
171
|
i18n(`${i18nKey}.failure.scopes.instructions`, {
|
|
85
|
-
accountName:
|
|
172
|
+
accountName: uiAccountDescription(accountId),
|
|
86
173
|
url,
|
|
87
174
|
})
|
|
88
175
|
);
|
|
@@ -97,7 +184,7 @@ const buildSandbox = async ({
|
|
|
97
184
|
logger.error(
|
|
98
185
|
i18n(`${i18nKey}.failure.invalidUser`, {
|
|
99
186
|
accountName: name,
|
|
100
|
-
parentAccountName:
|
|
187
|
+
parentAccountName: uiAccountDescription(accountId),
|
|
101
188
|
})
|
|
102
189
|
);
|
|
103
190
|
logger.log('');
|
|
@@ -112,7 +199,7 @@ const buildSandbox = async ({
|
|
|
112
199
|
logger.error(
|
|
113
200
|
i18n(`${i18nKey}.failure.403Gating`, {
|
|
114
201
|
accountName: name,
|
|
115
|
-
parentAccountName:
|
|
202
|
+
parentAccountName: uiAccountDescription(accountId),
|
|
116
203
|
accountId,
|
|
117
204
|
})
|
|
118
205
|
);
|
|
@@ -132,7 +219,7 @@ const buildSandbox = async ({
|
|
|
132
219
|
const plural = devSandboxLimit !== 1;
|
|
133
220
|
const hasDevelopmentSandboxes = getHasSandboxesByType(
|
|
134
221
|
accountConfig,
|
|
135
|
-
|
|
222
|
+
DEVELOPER_SANDBOX_TYPE
|
|
136
223
|
);
|
|
137
224
|
if (hasDevelopmentSandboxes) {
|
|
138
225
|
logger.error(
|
|
@@ -141,7 +228,7 @@ const buildSandbox = async ({
|
|
|
141
228
|
plural ? 'other' : 'one'
|
|
142
229
|
}`,
|
|
143
230
|
{
|
|
144
|
-
accountName:
|
|
231
|
+
accountName: uiAccountDescription(accountId),
|
|
145
232
|
limit: devSandboxLimit,
|
|
146
233
|
}
|
|
147
234
|
)
|
|
@@ -152,7 +239,7 @@ const buildSandbox = async ({
|
|
|
152
239
|
i18n(
|
|
153
240
|
`${i18nKey}.failure.limit.developer.${plural ? 'other' : 'one'}`,
|
|
154
241
|
{
|
|
155
|
-
accountName:
|
|
242
|
+
accountName: uiAccountDescription(accountId),
|
|
156
243
|
limit: devSandboxLimit,
|
|
157
244
|
link: `${baseUrl}/sandboxes-developer/${accountId}/development`,
|
|
158
245
|
}
|
|
@@ -175,7 +262,7 @@ const buildSandbox = async ({
|
|
|
175
262
|
const plural = standardSandboxLimit !== 1;
|
|
176
263
|
const hasStandardSandboxes = getHasSandboxesByType(
|
|
177
264
|
accountConfig,
|
|
178
|
-
|
|
265
|
+
STANDARD_SANDBOX_TYPE
|
|
179
266
|
);
|
|
180
267
|
if (hasStandardSandboxes) {
|
|
181
268
|
logger.error(
|
|
@@ -184,7 +271,7 @@ const buildSandbox = async ({
|
|
|
184
271
|
plural ? 'other' : 'one'
|
|
185
272
|
}`,
|
|
186
273
|
{
|
|
187
|
-
accountName:
|
|
274
|
+
accountName: uiAccountDescription(accountId),
|
|
188
275
|
limit: standardSandboxLimit,
|
|
189
276
|
}
|
|
190
277
|
)
|
|
@@ -195,7 +282,7 @@ const buildSandbox = async ({
|
|
|
195
282
|
i18n(
|
|
196
283
|
`${i18nKey}.failure.limit.standard.${plural ? 'other' : 'one'}`,
|
|
197
284
|
{
|
|
198
|
-
accountName:
|
|
285
|
+
accountName: uiAccountDescription(accountId),
|
|
199
286
|
limit: standardSandboxLimit,
|
|
200
287
|
link: `${baseUrl}/sandboxes-developer/${accountId}/standard`,
|
|
201
288
|
}
|
|
@@ -5,8 +5,6 @@ const { i18n } = require('./lang');
|
|
|
5
5
|
const {
|
|
6
6
|
getAvailableSyncTypes,
|
|
7
7
|
pollSyncTaskStatus,
|
|
8
|
-
getAccountName,
|
|
9
|
-
DEVELOPER_SANDBOX,
|
|
10
8
|
sandboxTypeMap,
|
|
11
9
|
syncTypes,
|
|
12
10
|
} = require('./sandboxes');
|
|
@@ -22,6 +20,7 @@ const {
|
|
|
22
20
|
const { getSandboxTypeAsString } = require('./sandboxes');
|
|
23
21
|
const { getAccountId } = require('@hubspot/local-dev-lib/config');
|
|
24
22
|
const { uiAccountDescription } = require('./ui');
|
|
23
|
+
const { DEVELOPER_SANDBOX_TYPE } = require('./constants');
|
|
25
24
|
|
|
26
25
|
const i18nKey = 'cli.lib.sandbox.sync';
|
|
27
26
|
|
|
@@ -89,7 +88,8 @@ const syncSandbox = async ({
|
|
|
89
88
|
});
|
|
90
89
|
if (
|
|
91
90
|
skipPolling &&
|
|
92
|
-
sandboxTypeMap[accountConfig.sandboxAccountType] ===
|
|
91
|
+
sandboxTypeMap[accountConfig.sandboxAccountType] ===
|
|
92
|
+
DEVELOPER_SANDBOX_TYPE
|
|
93
93
|
) {
|
|
94
94
|
if (syncTasks.some(t => t.type === syncTypes.OBJECT_RECORDS)) {
|
|
95
95
|
logger.log(i18n(`${i18nKey}.loading.skipPollingWithContacts`));
|
|
@@ -109,7 +109,7 @@ const syncSandbox = async ({
|
|
|
109
109
|
if (isMissingScopeError(err)) {
|
|
110
110
|
logger.error(
|
|
111
111
|
i18n(`${i18nKey}.failure.missingScopes`, {
|
|
112
|
-
accountName:
|
|
112
|
+
accountName: uiAccountDescription(parentAccountId),
|
|
113
113
|
})
|
|
114
114
|
);
|
|
115
115
|
} else if (
|
|
@@ -122,7 +122,7 @@ const syncSandbox = async ({
|
|
|
122
122
|
logger.error(
|
|
123
123
|
i18n(`${i18nKey}.failure.invalidUser`, {
|
|
124
124
|
accountName: uiAccountDescription(accountId),
|
|
125
|
-
parentAccountName:
|
|
125
|
+
parentAccountName: uiAccountDescription(parentAccountId),
|
|
126
126
|
})
|
|
127
127
|
);
|
|
128
128
|
} else if (
|
|
@@ -147,7 +147,7 @@ const syncSandbox = async ({
|
|
|
147
147
|
// This will only trigger if a user is not a super admin of the target account.
|
|
148
148
|
logger.error(
|
|
149
149
|
i18n(`${i18nKey}.failure.notSuperAdmin`, {
|
|
150
|
-
account:
|
|
150
|
+
account: uiAccountDescription(accountId),
|
|
151
151
|
})
|
|
152
152
|
);
|
|
153
153
|
} else if (
|
|
@@ -159,7 +159,7 @@ const syncSandbox = async ({
|
|
|
159
159
|
) {
|
|
160
160
|
logger.error(
|
|
161
161
|
i18n(`${i18nKey}.failure.objectNotFound`, {
|
|
162
|
-
account:
|
|
162
|
+
account: uiAccountDescription(accountId),
|
|
163
163
|
})
|
|
164
164
|
);
|
|
165
165
|
} else {
|