@hubspot/cli 5.2.1-beta.6 → 5.2.1-beta.8
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/clean.js +4 -4
- package/commands/accounts/info.js +2 -2
- package/commands/accounts/list.js +2 -2
- package/commands/accounts/rename.js +2 -2
- package/commands/accounts.js +2 -2
- package/commands/auth.js +2 -2
- package/commands/cms/lighthouseScore.js +3 -3
- package/commands/cms.js +2 -2
- package/commands/config.js +2 -2
- package/commands/customObject/schema/create.js +1 -1
- package/commands/customObject/schema/update.js +1 -1
- package/commands/customObject.js +2 -2
- package/commands/fetch.js +5 -5
- package/commands/filemanager/fetch.js +3 -3
- package/commands/filemanager/upload.js +3 -3
- package/commands/filemanager.js +3 -3
- package/commands/functions/deploy.js +6 -22
- package/commands/functions/list.js +3 -3
- package/commands/functions/server.js +3 -3
- package/commands/functions.js +2 -2
- package/commands/hubdb/clear.js +3 -3
- package/commands/hubdb/create.js +3 -3
- package/commands/hubdb/delete.js +3 -3
- package/commands/hubdb/fetch.js +3 -3
- package/commands/hubdb.js +2 -2
- package/commands/init.js +2 -2
- package/commands/lint.js +2 -2
- package/commands/list.js +3 -3
- package/commands/logs.js +3 -3
- package/commands/module/marketplace-validate.js +3 -3
- package/commands/module.js +2 -2
- package/commands/mv.js +3 -3
- package/commands/open.js +3 -3
- package/commands/project/create.js +3 -3
- package/commands/project/deploy.js +3 -3
- package/commands/project/dev.js +12 -4
- package/commands/project/download.js +2 -2
- package/commands/project/listBuilds.js +3 -3
- package/commands/project/logs.js +3 -3
- package/commands/project/migrateApp.js +210 -0
- package/commands/project/open.js +4 -4
- package/commands/project/upload.js +11 -6
- package/commands/project/watch.js +3 -3
- package/commands/project.js +4 -2
- package/commands/remove.js +3 -3
- package/commands/sandbox/create.js +7 -7
- package/commands/sandbox/delete.js +4 -4
- package/commands/sandbox/sync.js +4 -4
- package/commands/sandbox.js +2 -2
- package/commands/secrets/addSecret.js +3 -3
- package/commands/secrets/deleteSecret.js +3 -3
- package/commands/secrets/listSecrets.js +3 -3
- package/commands/secrets/updateSecret.js +3 -3
- package/commands/secrets.js +2 -2
- package/commands/theme/marketplace-validate.js +3 -3
- package/commands/theme/preview.js +4 -3
- package/commands/upload.js +4 -4
- package/commands/watch.js +61 -18
- package/jest.config.js +1 -0
- package/lang/en.lyaml +75 -29
- package/lib/LocalDevManager.js +8 -0
- package/lib/__tests__/{commonOpts.js → commonOpts.test.js} +3 -0
- package/lib/__tests__/downloadProjectPrompt.test.js +31 -0
- package/lib/__tests__/projects.test.js +13 -17
- package/lib/__tests__/{serverlessLogs.js → serverlessLogs.test.js} +1 -0
- package/lib/{developerTestAccountCreate.js → buildAccount.js} +91 -80
- package/lib/constants.js +9 -0
- package/lib/developerTestAccounts.js +52 -4
- package/lib/localDev.js +11 -10
- package/lib/polling.js +25 -0
- package/lib/projects.js +49 -4
- package/lib/prompts/createProjectPrompt.js +19 -7
- package/lib/prompts/downloadProjectPrompt.js +4 -5
- package/lib/prompts/selectPublicAppPrompt.js +74 -0
- package/lib/sandboxes.js +160 -1
- package/package.json +6 -6
- package/lib/sandboxCreate.js +0 -318
- /package/lib/__tests__/{validation.js → validation.test.js} +0 -0
package/lib/sandboxCreate.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
const SpinniesManager = require('./ui/SpinniesManager');
|
|
2
|
-
const {
|
|
3
|
-
getSandboxLimit,
|
|
4
|
-
getHasSandboxesByType,
|
|
5
|
-
sandboxApiTypeMap,
|
|
6
|
-
} = require('./sandboxes');
|
|
7
|
-
const { i18n } = require('./lang');
|
|
8
|
-
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
9
|
-
const {
|
|
10
|
-
debugErrorAndContext,
|
|
11
|
-
logErrorInstance,
|
|
12
|
-
} = require('./errorHandlers/standardErrors');
|
|
13
|
-
const {
|
|
14
|
-
isMissingScopeError,
|
|
15
|
-
isSpecifiedError,
|
|
16
|
-
} = require('@hubspot/local-dev-lib/errors/apiErrors');
|
|
17
|
-
const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
|
|
18
|
-
const { getEnv, getAccountId } = require('@hubspot/local-dev-lib/config');
|
|
19
|
-
const { createSandbox } = require('@hubspot/local-dev-lib/sandboxes');
|
|
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
|
-
personalAccessKeyPrompt,
|
|
28
|
-
} = require('./prompts/personalAccessKeyPrompt');
|
|
29
|
-
const { enterAccountNamePrompt } = require('./prompts/enterAccountNamePrompt');
|
|
30
|
-
const {
|
|
31
|
-
accountNameExistsInConfig,
|
|
32
|
-
writeConfig,
|
|
33
|
-
updateAccountConfig,
|
|
34
|
-
} = require('@hubspot/local-dev-lib/config');
|
|
35
|
-
const {
|
|
36
|
-
HUBSPOT_ACCOUNT_TYPES,
|
|
37
|
-
} = require('@hubspot/local-dev-lib/constants/config');
|
|
38
|
-
|
|
39
|
-
const i18nKey = 'lib.sandbox.create';
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @param {String} env - Environment (QA/Prod)
|
|
43
|
-
* @param {Object} result - Sandbox instance returned from API
|
|
44
|
-
* @param {Boolean} force - Force flag to skip prompt
|
|
45
|
-
* @returns {String} validName saved into config
|
|
46
|
-
*/
|
|
47
|
-
const saveSandboxToConfig = async (env, result, force = false) => {
|
|
48
|
-
let personalAccessKey = result.personalAccessKey;
|
|
49
|
-
if (!personalAccessKey) {
|
|
50
|
-
const configData = await personalAccessKeyPrompt({
|
|
51
|
-
env,
|
|
52
|
-
account: result.sandbox.sandboxHubId,
|
|
53
|
-
});
|
|
54
|
-
personalAccessKey = configData.personalAccessKey;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let updatedConfig;
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const token = await getAccessToken(personalAccessKey, env);
|
|
61
|
-
updatedConfig = await updateConfigWithAccessToken(
|
|
62
|
-
token,
|
|
63
|
-
personalAccessKey,
|
|
64
|
-
env
|
|
65
|
-
);
|
|
66
|
-
} catch (e) {
|
|
67
|
-
logErrorInstance(e);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!updatedConfig) {
|
|
71
|
-
throw new Error('Failed to update config with personal access key.');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let validName = updatedConfig.name;
|
|
75
|
-
if (!updatedConfig.name) {
|
|
76
|
-
const nameForConfig = result.sandbox.name
|
|
77
|
-
.toLowerCase()
|
|
78
|
-
.split(' ')
|
|
79
|
-
.join('-');
|
|
80
|
-
validName = nameForConfig;
|
|
81
|
-
const invalidAccountName = accountNameExistsInConfig(nameForConfig);
|
|
82
|
-
if (invalidAccountName) {
|
|
83
|
-
if (!force) {
|
|
84
|
-
logger.log('');
|
|
85
|
-
logger.warn(
|
|
86
|
-
i18n(`lib.prompts.enterAccountNamePrompt.errors.accountNameExists`, {
|
|
87
|
-
name: nameForConfig,
|
|
88
|
-
})
|
|
89
|
-
);
|
|
90
|
-
const { name: promptName } = await enterAccountNamePrompt(
|
|
91
|
-
nameForConfig + `_${result.sandbox.sandboxHubId}`
|
|
92
|
-
);
|
|
93
|
-
validName = promptName;
|
|
94
|
-
} else {
|
|
95
|
-
// Basic invalid name handling when force flag is passed
|
|
96
|
-
validName = nameForConfig + `_${result.sandbox.sandboxHubId}`;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
updateAccountConfig({
|
|
101
|
-
...updatedConfig,
|
|
102
|
-
environment: updatedConfig.env,
|
|
103
|
-
tokenInfo: updatedConfig.auth.tokenInfo,
|
|
104
|
-
name: validName,
|
|
105
|
-
});
|
|
106
|
-
writeConfig();
|
|
107
|
-
|
|
108
|
-
logger.log('');
|
|
109
|
-
return validName;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @param {String} name - Name of sandbox
|
|
114
|
-
* @param {String} type - Sandbox type to be created (STANDARD_SANDBOX/DEVELOPMENT_SANDBOX)
|
|
115
|
-
* @param {Object} accountConfig - Account config of parent portal
|
|
116
|
-
* @param {String} env - Environment (QA/Prod)
|
|
117
|
-
* @returns {Object} Object containing sandboxConfigName string and sandbox instance from API
|
|
118
|
-
*/
|
|
119
|
-
const buildSandbox = async ({
|
|
120
|
-
name,
|
|
121
|
-
type,
|
|
122
|
-
accountConfig,
|
|
123
|
-
env,
|
|
124
|
-
force = false,
|
|
125
|
-
}) => {
|
|
126
|
-
SpinniesManager.init({
|
|
127
|
-
succeedColor: 'white',
|
|
128
|
-
});
|
|
129
|
-
const accountId = getAccountId(accountConfig.portalId);
|
|
130
|
-
|
|
131
|
-
let result;
|
|
132
|
-
const loadingLangKey =
|
|
133
|
-
type === HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX
|
|
134
|
-
? 'developer'
|
|
135
|
-
: 'standard';
|
|
136
|
-
const spinniesI18nKey = `${i18nKey}.loading.${loadingLangKey}`;
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
logger.log('');
|
|
140
|
-
SpinniesManager.add('sandboxCreate', {
|
|
141
|
-
text: i18n(`${spinniesI18nKey}.add`, {
|
|
142
|
-
sandboxName: name,
|
|
143
|
-
}),
|
|
144
|
-
});
|
|
145
|
-
const sandboxApiType = sandboxApiTypeMap[type]; // API expects sandbox type as 1 or 2
|
|
146
|
-
result = await createSandbox(accountId, name, sandboxApiType);
|
|
147
|
-
|
|
148
|
-
SpinniesManager.succeed('sandboxCreate', {
|
|
149
|
-
text: i18n(`${spinniesI18nKey}.succeed`, {
|
|
150
|
-
name: result.sandbox.name,
|
|
151
|
-
sandboxHubId: result.sandbox.sandboxHubId,
|
|
152
|
-
}),
|
|
153
|
-
});
|
|
154
|
-
} catch (err) {
|
|
155
|
-
debugErrorAndContext(err);
|
|
156
|
-
|
|
157
|
-
SpinniesManager.fail('sandboxCreate', {
|
|
158
|
-
text: i18n(`${spinniesI18nKey}.fail`, {
|
|
159
|
-
sandboxName: name,
|
|
160
|
-
}),
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
if (isMissingScopeError(err)) {
|
|
164
|
-
logger.error(
|
|
165
|
-
i18n(`${i18nKey}.failure.scopes.message`, {
|
|
166
|
-
accountName: uiAccountDescription(accountId),
|
|
167
|
-
})
|
|
168
|
-
);
|
|
169
|
-
const websiteOrigin = getHubSpotWebsiteOrigin(env);
|
|
170
|
-
const url = `${websiteOrigin}/personal-access-key/${accountId}`;
|
|
171
|
-
logger.info(
|
|
172
|
-
i18n(`${i18nKey}.failure.scopes.instructions`, {
|
|
173
|
-
accountName: uiAccountDescription(accountId),
|
|
174
|
-
url,
|
|
175
|
-
})
|
|
176
|
-
);
|
|
177
|
-
} else if (
|
|
178
|
-
isSpecifiedError(err, {
|
|
179
|
-
statusCode: 403,
|
|
180
|
-
category: 'BANNED',
|
|
181
|
-
subCategory: 'SandboxErrors.USER_ACCESS_NOT_ALLOWED',
|
|
182
|
-
})
|
|
183
|
-
) {
|
|
184
|
-
logger.log('');
|
|
185
|
-
logger.error(
|
|
186
|
-
i18n(`${i18nKey}.failure.invalidUser`, {
|
|
187
|
-
accountName: name,
|
|
188
|
-
parentAccountName: uiAccountDescription(accountId),
|
|
189
|
-
})
|
|
190
|
-
);
|
|
191
|
-
logger.log('');
|
|
192
|
-
} else if (
|
|
193
|
-
isSpecifiedError(err, {
|
|
194
|
-
statusCode: 403,
|
|
195
|
-
category: 'BANNED',
|
|
196
|
-
subCategory: 'SandboxErrors.DEVELOPMENT_SANDBOX_ACCESS_NOT_ALLOWED',
|
|
197
|
-
})
|
|
198
|
-
) {
|
|
199
|
-
logger.log('');
|
|
200
|
-
logger.error(
|
|
201
|
-
i18n(`${i18nKey}.failure.403Gating`, {
|
|
202
|
-
accountName: name,
|
|
203
|
-
parentAccountName: uiAccountDescription(accountId),
|
|
204
|
-
accountId,
|
|
205
|
-
})
|
|
206
|
-
);
|
|
207
|
-
logger.log('');
|
|
208
|
-
} else if (
|
|
209
|
-
isSpecifiedError(err, {
|
|
210
|
-
statusCode: 400,
|
|
211
|
-
category: 'VALIDATION_ERROR',
|
|
212
|
-
subCategory:
|
|
213
|
-
'SandboxErrors.NUM_DEVELOPMENT_SANDBOXES_LIMIT_EXCEEDED_ERROR',
|
|
214
|
-
}) &&
|
|
215
|
-
err.error &&
|
|
216
|
-
err.error.message
|
|
217
|
-
) {
|
|
218
|
-
logger.log('');
|
|
219
|
-
const devSandboxLimit = getSandboxLimit(err.error);
|
|
220
|
-
const plural = devSandboxLimit !== 1;
|
|
221
|
-
const hasDevelopmentSandboxes = getHasSandboxesByType(
|
|
222
|
-
accountConfig,
|
|
223
|
-
HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX
|
|
224
|
-
);
|
|
225
|
-
if (hasDevelopmentSandboxes) {
|
|
226
|
-
logger.error(
|
|
227
|
-
i18n(
|
|
228
|
-
`${i18nKey}.failure.alreadyInConfig.developer.${
|
|
229
|
-
plural ? 'other' : 'one'
|
|
230
|
-
}`,
|
|
231
|
-
{
|
|
232
|
-
accountName: uiAccountDescription(accountId),
|
|
233
|
-
limit: devSandboxLimit,
|
|
234
|
-
}
|
|
235
|
-
)
|
|
236
|
-
);
|
|
237
|
-
} else {
|
|
238
|
-
const baseUrl = getHubSpotWebsiteOrigin(getValidEnv(getEnv(accountId)));
|
|
239
|
-
logger.error(
|
|
240
|
-
i18n(
|
|
241
|
-
`${i18nKey}.failure.limit.developer.${plural ? 'other' : 'one'}`,
|
|
242
|
-
{
|
|
243
|
-
accountName: uiAccountDescription(accountId),
|
|
244
|
-
limit: devSandboxLimit,
|
|
245
|
-
link: `${baseUrl}/sandboxes-developer/${accountId}/development`,
|
|
246
|
-
}
|
|
247
|
-
)
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
logger.log('');
|
|
251
|
-
} else if (
|
|
252
|
-
isSpecifiedError(err, {
|
|
253
|
-
statusCode: 400,
|
|
254
|
-
category: 'VALIDATION_ERROR',
|
|
255
|
-
subCategory:
|
|
256
|
-
'SandboxErrors.NUM_STANDARD_SANDBOXES_LIMIT_EXCEEDED_ERROR',
|
|
257
|
-
}) &&
|
|
258
|
-
err.error &&
|
|
259
|
-
err.error.message
|
|
260
|
-
) {
|
|
261
|
-
logger.log('');
|
|
262
|
-
const standardSandboxLimit = getSandboxLimit(err.error);
|
|
263
|
-
const plural = standardSandboxLimit !== 1;
|
|
264
|
-
const hasStandardSandboxes = getHasSandboxesByType(
|
|
265
|
-
accountConfig,
|
|
266
|
-
HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX
|
|
267
|
-
);
|
|
268
|
-
if (hasStandardSandboxes) {
|
|
269
|
-
logger.error(
|
|
270
|
-
i18n(
|
|
271
|
-
`${i18nKey}.failure.alreadyInConfig.standard.${
|
|
272
|
-
plural ? 'other' : 'one'
|
|
273
|
-
}`,
|
|
274
|
-
{
|
|
275
|
-
accountName: uiAccountDescription(accountId),
|
|
276
|
-
limit: standardSandboxLimit,
|
|
277
|
-
}
|
|
278
|
-
)
|
|
279
|
-
);
|
|
280
|
-
} else {
|
|
281
|
-
const baseUrl = getHubSpotWebsiteOrigin(getValidEnv(getEnv(accountId)));
|
|
282
|
-
logger.error(
|
|
283
|
-
i18n(
|
|
284
|
-
`${i18nKey}.failure.limit.standard.${plural ? 'other' : 'one'}`,
|
|
285
|
-
{
|
|
286
|
-
accountName: uiAccountDescription(accountId),
|
|
287
|
-
limit: standardSandboxLimit,
|
|
288
|
-
link: `${baseUrl}/sandboxes-developer/${accountId}/standard`,
|
|
289
|
-
}
|
|
290
|
-
)
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
logger.log('');
|
|
294
|
-
} else {
|
|
295
|
-
logErrorInstance(err);
|
|
296
|
-
}
|
|
297
|
-
throw err;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
let sandboxConfigName;
|
|
301
|
-
|
|
302
|
-
try {
|
|
303
|
-
// Response contains PAK, save to config here
|
|
304
|
-
sandboxConfigName = await saveSandboxToConfig(env, result, force);
|
|
305
|
-
} catch (err) {
|
|
306
|
-
logErrorInstance(err);
|
|
307
|
-
throw err;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return {
|
|
311
|
-
sandboxConfigName,
|
|
312
|
-
result,
|
|
313
|
-
};
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
module.exports = {
|
|
317
|
-
buildSandbox,
|
|
318
|
-
};
|
|
File without changes
|