@hubspot/cli 7.0.1 → 7.0.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +7 -2
- package/commands/account/info.d.ts +7 -0
- package/commands/account/info.js +28 -25
- package/commands/account/remove.js +4 -4
- package/commands/account/use.js +3 -3
- package/commands/auth.js +3 -3
- package/commands/function/deploy.js +1 -1
- package/commands/init.js +1 -1
- package/commands/logs.js +1 -7
- package/commands/project/cloneApp.js +1 -1
- package/commands/project/create.js +6 -0
- package/commands/project/dev.js +4 -3
- package/commands/project/installDeps.js +2 -4
- package/commands/project/migrateApp.js +1 -1
- package/commands/project/upload.js +4 -4
- package/commands/project/watch.js +4 -4
- package/commands/sandbox/create.js +7 -18
- package/commands/sandbox/delete.js +6 -10
- package/commands/theme/preview.js +3 -2
- package/lang/en.lyaml +11 -4
- package/lib/DevServerManager.d.ts +40 -1
- package/lib/DevServerManager.js +39 -30
- package/lib/LocalDevManager.d.ts +58 -1
- package/lib/LocalDevManager.js +162 -121
- package/lib/buildAccount.d.ts +12 -0
- package/lib/buildAccount.js +110 -95
- package/lib/commonOpts.d.ts +4 -8
- package/lib/commonOpts.js +2 -14
- package/lib/constants.d.ts +1 -7
- package/lib/constants.js +2 -8
- package/lib/dependencyManagement.d.ts +9 -4
- package/lib/dependencyManagement.js +45 -49
- package/lib/developerTestAccounts.d.ts +1 -0
- package/lib/developerTestAccounts.js +1 -0
- package/lib/errorHandlers/index.js +5 -2
- package/lib/localDev.d.ts +17 -1
- package/lib/localDev.js +203 -203
- package/lib/polling.d.ts +13 -5
- package/lib/polling.js +21 -7
- package/lib/projects/buildAndDeploy.d.ts +1 -7
- package/lib/projects/buildAndDeploy.js +3 -3
- package/lib/projects/index.js +9 -4
- package/lib/projects/structure.d.ts +5 -71
- package/lib/projects/structure.js +27 -10
- package/lib/projects/upload.d.ts +4 -3
- package/lib/projects/upload.js +3 -5
- package/lib/prompts/createProjectPrompt.js +8 -1
- package/lib/prompts/installPublicAppPrompt.d.ts +1 -1
- package/lib/prompts/personalAccessKeyPrompt.d.ts +1 -1
- package/lib/prompts/projectDevTargetAccountPrompt.d.ts +2 -2
- package/lib/sandboxSync.d.ts +4 -1
- package/lib/sandboxSync.js +67 -68
- package/lib/sandboxes.d.ts +20 -1
- package/lib/sandboxes.js +77 -175
- package/lib/serverlessLogs.d.ts +4 -1
- package/lib/serverlessLogs.js +64 -60
- package/lib/ui/serverlessFunctionLogs.d.ts +8 -0
- package/lib/ui/serverlessFunctionLogs.js +1 -3
- package/lib/validation.d.ts +2 -0
- package/lib/validation.js +5 -8
- package/package.json +8 -7
- package/types/Projects.d.ts +74 -0
- package/types/Projects.js +7 -0
- package/types/Sandboxes.d.ts +3 -0
- package/types/Sandboxes.js +2 -0
- package/types/Yargs.d.ts +14 -0
- package/types/Yargs.js +2 -0
package/lib/sandboxes.js
CHANGED
|
@@ -1,43 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
3
|
+
exports.SANDBOX_API_TYPE_MAP = exports.SANDBOX_TYPE_MAP = exports.SYNC_TYPES = void 0;
|
|
4
|
+
exports.getSandboxTypeAsString = getSandboxTypeAsString;
|
|
5
|
+
exports.getAvailableSyncTypes = getAvailableSyncTypes;
|
|
6
|
+
exports.validateSandboxUsageLimits = validateSandboxUsageLimits;
|
|
7
|
+
exports.handleSandboxCreateError = handleSandboxCreateError;
|
|
8
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
9
|
+
const sandboxHubs_1 = require("@hubspot/local-dev-lib/api/sandboxHubs");
|
|
10
|
+
const sandboxSync_1 = require("@hubspot/local-dev-lib/api/sandboxSync");
|
|
11
|
+
const config_1 = require("@hubspot/local-dev-lib/config");
|
|
12
|
+
const urls_1 = require("@hubspot/local-dev-lib/urls");
|
|
13
|
+
const config_2 = require("@hubspot/local-dev-lib/constants/config");
|
|
14
|
+
const getAccountIdentifier_1 = require("@hubspot/local-dev-lib/config/getAccountIdentifier");
|
|
15
|
+
const index_1 = require("@hubspot/local-dev-lib/errors/index");
|
|
16
|
+
const lang_1 = require("./lang");
|
|
17
|
+
const ui_1 = require("./ui");
|
|
18
|
+
const index_2 = require("./errorHandlers/index");
|
|
19
|
+
const i18nKey = 'lib.sandbox';
|
|
20
|
+
exports.SYNC_TYPES = {
|
|
19
21
|
OBJECT_RECORDS: 'object-records',
|
|
20
22
|
};
|
|
21
|
-
|
|
22
|
-
dev: HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX,
|
|
23
|
-
developer: HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX,
|
|
24
|
-
development: HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX,
|
|
25
|
-
standard: HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX,
|
|
23
|
+
exports.SANDBOX_TYPE_MAP = {
|
|
24
|
+
dev: config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX,
|
|
25
|
+
developer: config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX,
|
|
26
|
+
development: config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX,
|
|
27
|
+
standard: config_2.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX,
|
|
26
28
|
};
|
|
27
|
-
|
|
28
|
-
[HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX]: 1,
|
|
29
|
-
[HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX]: 2,
|
|
29
|
+
exports.SANDBOX_API_TYPE_MAP = {
|
|
30
|
+
[config_2.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX]: 1,
|
|
31
|
+
[config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX]: 2,
|
|
30
32
|
};
|
|
31
|
-
|
|
32
|
-
if (accountType === HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
|
|
33
|
+
function getSandboxTypeAsString(accountType) {
|
|
34
|
+
if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
|
|
33
35
|
return 'development'; // Only place we're using this specific name
|
|
34
36
|
}
|
|
35
37
|
return 'standard';
|
|
36
|
-
}
|
|
38
|
+
}
|
|
37
39
|
function getHasSandboxesByType(parentAccountConfig, type) {
|
|
38
|
-
const id = getAccountIdentifier(parentAccountConfig);
|
|
39
|
-
const parentPortalId = getAccountId(id);
|
|
40
|
-
const accountsList = getConfigAccounts();
|
|
40
|
+
const id = (0, getAccountIdentifier_1.getAccountIdentifier)(parentAccountConfig);
|
|
41
|
+
const parentPortalId = (0, config_1.getAccountId)(id);
|
|
42
|
+
const accountsList = (0, config_1.getConfigAccounts)() || [];
|
|
41
43
|
for (const portal of accountsList) {
|
|
42
44
|
if ((portal.parentAccountId !== null ||
|
|
43
45
|
portal.parentAccountId !== undefined) &&
|
|
@@ -49,79 +51,45 @@ function getHasSandboxesByType(parentAccountConfig, type) {
|
|
|
49
51
|
}
|
|
50
52
|
return false;
|
|
51
53
|
}
|
|
52
|
-
function getSandboxLimit(error) {
|
|
53
|
-
// Error context should contain a limit property with a list of one number. That number is the current limit
|
|
54
|
-
const limit = error.context && error.context.limit && error.context.limit[0];
|
|
55
|
-
return limit ? parseInt(limit, 10) : 1; // Default to 1
|
|
56
|
-
}
|
|
57
54
|
// Fetches available sync types for a given sandbox portal
|
|
58
55
|
async function getAvailableSyncTypes(parentAccountConfig, config) {
|
|
59
|
-
const parentId = getAccountIdentifier(parentAccountConfig);
|
|
60
|
-
const parentPortalId = getAccountId(parentId);
|
|
61
|
-
const id = getAccountIdentifier(config);
|
|
62
|
-
const portalId = getAccountId(id);
|
|
63
|
-
|
|
56
|
+
const parentId = (0, getAccountIdentifier_1.getAccountIdentifier)(parentAccountConfig);
|
|
57
|
+
const parentPortalId = (0, config_1.getAccountId)(parentId);
|
|
58
|
+
const id = (0, getAccountIdentifier_1.getAccountIdentifier)(config);
|
|
59
|
+
const portalId = (0, config_1.getAccountId)(id);
|
|
60
|
+
if (!parentPortalId || !portalId) {
|
|
61
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.sync.failure.syncTypeFetch`));
|
|
62
|
+
}
|
|
63
|
+
const { data: { results: syncTypes }, } = await (0, sandboxSync_1.fetchTypes)(parentPortalId, portalId);
|
|
64
64
|
if (!syncTypes) {
|
|
65
|
-
throw new Error(
|
|
65
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.sync.failure.syncTypeFetch`));
|
|
66
66
|
}
|
|
67
67
|
return syncTypes.map(t => ({ type: t.name }));
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*/
|
|
75
|
-
const getSyncTypesWithContactRecordsPrompt = async (accountConfig, syncTasks, skipPrompt = false) => {
|
|
76
|
-
// TODO: remove this entire helper once hs sandbox sync is fully deprecated
|
|
77
|
-
const isDevSandbox = isDevelopmentSandbox(accountConfig);
|
|
78
|
-
if (isDevSandbox) {
|
|
79
|
-
// Disable dev sandbox from syncing contacts
|
|
80
|
-
return syncTasks.filter(t => t.type !== syncTypes.OBJECT_RECORDS);
|
|
69
|
+
async function validateSandboxUsageLimits(accountConfig, sandboxType, env) {
|
|
70
|
+
const id = (0, getAccountIdentifier_1.getAccountIdentifier)(accountConfig);
|
|
71
|
+
const accountId = (0, config_1.getAccountId)(id);
|
|
72
|
+
if (!accountId) {
|
|
73
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.create.failure.usageLimitFetch`));
|
|
81
74
|
}
|
|
82
|
-
|
|
83
|
-
syncTasks.some(t => t.type === syncTypes.OBJECT_RECORDS) &&
|
|
84
|
-
!skipPrompt) {
|
|
85
|
-
const { contactRecordsSyncPrompt } = await promptUser([
|
|
86
|
-
{
|
|
87
|
-
name: 'contactRecordsSyncPrompt',
|
|
88
|
-
type: 'confirm',
|
|
89
|
-
message: i18n('lib.sandbox.sync.confirm.syncContactRecords.standard'),
|
|
90
|
-
},
|
|
91
|
-
]);
|
|
92
|
-
if (!contactRecordsSyncPrompt) {
|
|
93
|
-
return syncTasks.filter(t => t.type !== syncTypes.OBJECT_RECORDS);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return syncTasks;
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* @param {Object} accountConfig - Account config of sandbox portal
|
|
100
|
-
* @param {String} sandboxType - Sandbox type for limit validation
|
|
101
|
-
* @param {String} env - Environment
|
|
102
|
-
* @returns {null}
|
|
103
|
-
*/
|
|
104
|
-
const validateSandboxUsageLimits = async (accountConfig, sandboxType, env) => {
|
|
105
|
-
const id = getAccountIdentifier(accountConfig);
|
|
106
|
-
const accountId = getAccountId(id);
|
|
107
|
-
const { data: { usage }, } = await getSandboxUsageLimits(accountId);
|
|
75
|
+
const { data: { usage }, } = await (0, sandboxHubs_1.getSandboxUsageLimits)(accountId);
|
|
108
76
|
if (!usage) {
|
|
109
|
-
throw new Error(
|
|
77
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.create.failure.usageLimitFetch`));
|
|
110
78
|
}
|
|
111
|
-
if (sandboxType === HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
|
|
79
|
+
if (sandboxType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
|
|
112
80
|
if (usage['DEVELOPER'].available === 0) {
|
|
113
81
|
const devSandboxLimit = usage['DEVELOPER'].limit;
|
|
114
82
|
const plural = devSandboxLimit !== 1;
|
|
115
|
-
const hasDevelopmentSandboxes = getHasSandboxesByType(accountConfig, HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX);
|
|
83
|
+
const hasDevelopmentSandboxes = getHasSandboxesByType(accountConfig, config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX);
|
|
116
84
|
if (hasDevelopmentSandboxes) {
|
|
117
|
-
throw new Error(i18n(
|
|
85
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.create.failure.alreadyInConfig.developer.${plural ? 'other' : 'one'}`, {
|
|
118
86
|
accountName: accountConfig.name || accountId,
|
|
119
87
|
limit: devSandboxLimit,
|
|
120
88
|
}));
|
|
121
89
|
}
|
|
122
90
|
else {
|
|
123
|
-
const baseUrl = getHubSpotWebsiteOrigin(env);
|
|
124
|
-
throw new Error(i18n(
|
|
91
|
+
const baseUrl = (0, urls_1.getHubSpotWebsiteOrigin)(env);
|
|
92
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.create.failure.limit.developer.${plural ? 'other' : 'one'}`, {
|
|
125
93
|
accountName: accountConfig.name || accountId,
|
|
126
94
|
limit: devSandboxLimit,
|
|
127
95
|
link: `${baseUrl}/sandboxes-developer/${accountId}/development`,
|
|
@@ -129,20 +97,20 @@ const validateSandboxUsageLimits = async (accountConfig, sandboxType, env) => {
|
|
|
129
97
|
}
|
|
130
98
|
}
|
|
131
99
|
}
|
|
132
|
-
if (sandboxType === HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX) {
|
|
100
|
+
if (sandboxType === config_2.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX) {
|
|
133
101
|
if (usage['STANDARD'].available === 0) {
|
|
134
102
|
const standardSandboxLimit = usage['STANDARD'].limit;
|
|
135
103
|
const plural = standardSandboxLimit !== 1;
|
|
136
|
-
const hasStandardSandboxes = getHasSandboxesByType(accountConfig, HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX);
|
|
104
|
+
const hasStandardSandboxes = getHasSandboxesByType(accountConfig, config_2.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX);
|
|
137
105
|
if (hasStandardSandboxes) {
|
|
138
|
-
throw new Error(i18n(
|
|
106
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.create.failure.alreadyInConfig.standard.${plural ? 'other' : 'one'}`, {
|
|
139
107
|
accountName: accountConfig.name || accountId,
|
|
140
108
|
limit: standardSandboxLimit,
|
|
141
109
|
}));
|
|
142
110
|
}
|
|
143
111
|
else {
|
|
144
|
-
const baseUrl = getHubSpotWebsiteOrigin(env);
|
|
145
|
-
throw new Error(i18n(
|
|
112
|
+
const baseUrl = (0, urls_1.getHubSpotWebsiteOrigin)(env);
|
|
113
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.create.failure.limit.standard.${plural ? 'other' : 'one'}`, {
|
|
146
114
|
accountName: accountConfig.name || accountId,
|
|
147
115
|
limit: standardSandboxLimit,
|
|
148
116
|
link: `${baseUrl}/sandboxes-developer/${accountId}/standard`,
|
|
@@ -150,112 +118,46 @@ const validateSandboxUsageLimits = async (accountConfig, sandboxType, env) => {
|
|
|
150
118
|
}
|
|
151
119
|
}
|
|
152
120
|
}
|
|
153
|
-
}
|
|
154
|
-
function handleSandboxCreateError(
|
|
155
|
-
if (isMissingScopeError(err)) {
|
|
156
|
-
logger.error(i18n(
|
|
157
|
-
accountName: uiAccountDescription(accountId),
|
|
121
|
+
}
|
|
122
|
+
function handleSandboxCreateError(err, env, name, accountId) {
|
|
123
|
+
if ((0, index_1.isMissingScopeError)(err)) {
|
|
124
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.create.failure.scopes.message`, {
|
|
125
|
+
accountName: (0, ui_1.uiAccountDescription)(accountId),
|
|
158
126
|
}));
|
|
159
|
-
const websiteOrigin = getHubSpotWebsiteOrigin(env);
|
|
127
|
+
const websiteOrigin = (0, urls_1.getHubSpotWebsiteOrigin)(env);
|
|
160
128
|
const url = `${websiteOrigin}/personal-access-key/${accountId}`;
|
|
161
|
-
logger.info(i18n(
|
|
162
|
-
accountName: uiAccountDescription(accountId),
|
|
129
|
+
logger_1.logger.info((0, lang_1.i18n)(`${i18nKey}.create.failure.scopes.instructions`, {
|
|
130
|
+
accountName: (0, ui_1.uiAccountDescription)(accountId),
|
|
163
131
|
url,
|
|
164
132
|
}));
|
|
165
133
|
}
|
|
166
|
-
else if (isSpecifiedError(err, {
|
|
134
|
+
else if ((0, index_1.isSpecifiedError)(err, {
|
|
167
135
|
statusCode: 403,
|
|
168
136
|
category: 'BANNED',
|
|
169
137
|
subCategory: 'SandboxErrors.USER_ACCESS_NOT_ALLOWED',
|
|
170
138
|
})) {
|
|
171
|
-
logger.log('');
|
|
172
|
-
logger.error(i18n(
|
|
139
|
+
logger_1.logger.log('');
|
|
140
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.create.failure.invalidUser`, {
|
|
173
141
|
accountName: name,
|
|
174
|
-
parentAccountName: uiAccountDescription(accountId),
|
|
142
|
+
parentAccountName: (0, ui_1.uiAccountDescription)(accountId),
|
|
175
143
|
}));
|
|
176
|
-
logger.log('');
|
|
144
|
+
logger_1.logger.log('');
|
|
177
145
|
}
|
|
178
|
-
else if (isSpecifiedError(err, {
|
|
146
|
+
else if ((0, index_1.isSpecifiedError)(err, {
|
|
179
147
|
statusCode: 403,
|
|
180
148
|
category: 'BANNED',
|
|
181
149
|
subCategory: 'SandboxErrors.DEVELOPMENT_SANDBOX_ACCESS_NOT_ALLOWED',
|
|
182
150
|
})) {
|
|
183
|
-
logger.log('');
|
|
184
|
-
logger.error(i18n(
|
|
151
|
+
logger_1.logger.log('');
|
|
152
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.create.failure.403Gating`, {
|
|
185
153
|
accountName: name,
|
|
186
|
-
parentAccountName: uiAccountDescription(accountId),
|
|
154
|
+
parentAccountName: (0, ui_1.uiAccountDescription)(accountId),
|
|
187
155
|
accountId,
|
|
188
156
|
}));
|
|
189
|
-
logger.log('');
|
|
190
|
-
}
|
|
191
|
-
else if (isSpecifiedError(err, {
|
|
192
|
-
statusCode: 400,
|
|
193
|
-
category: 'VALIDATION_ERROR',
|
|
194
|
-
subCategory: 'SandboxErrors.NUM_DEVELOPMENT_SANDBOXES_LIMIT_EXCEEDED_ERROR',
|
|
195
|
-
}) &&
|
|
196
|
-
err.error &&
|
|
197
|
-
err.error.message) {
|
|
198
|
-
logger.log('');
|
|
199
|
-
const devSandboxLimit = getSandboxLimit(err.error);
|
|
200
|
-
const plural = devSandboxLimit !== 1;
|
|
201
|
-
const hasDevelopmentSandboxes = getHasSandboxesByType(accountConfig, HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX);
|
|
202
|
-
if (hasDevelopmentSandboxes) {
|
|
203
|
-
logger.error(i18n(`lib.sandboxes.create.failure.alreadyInConfig.developer.${plural ? 'other' : 'one'}`, {
|
|
204
|
-
accountName: uiAccountDescription(accountId),
|
|
205
|
-
limit: devSandboxLimit,
|
|
206
|
-
}));
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
const baseUrl = getHubSpotWebsiteOrigin(getValidEnv(getEnv(accountId)));
|
|
210
|
-
logger.error(i18n(`lib.sandboxes.create.failure.limit.developer.${plural ? 'other' : 'one'}`, {
|
|
211
|
-
accountName: uiAccountDescription(accountId),
|
|
212
|
-
limit: devSandboxLimit,
|
|
213
|
-
link: `${baseUrl}/sandboxes-developer/${accountId}/development`,
|
|
214
|
-
}));
|
|
215
|
-
}
|
|
216
|
-
logger.log('');
|
|
217
|
-
}
|
|
218
|
-
else if (isSpecifiedError(err, {
|
|
219
|
-
statusCode: 400,
|
|
220
|
-
category: 'VALIDATION_ERROR',
|
|
221
|
-
subCategory: 'SandboxErrors.NUM_STANDARD_SANDBOXES_LIMIT_EXCEEDED_ERROR',
|
|
222
|
-
}) &&
|
|
223
|
-
err.error &&
|
|
224
|
-
err.error.message) {
|
|
225
|
-
logger.log('');
|
|
226
|
-
const standardSandboxLimit = getSandboxLimit(err.error);
|
|
227
|
-
const plural = standardSandboxLimit !== 1;
|
|
228
|
-
const hasStandardSandboxes = getHasSandboxesByType(accountConfig, HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX);
|
|
229
|
-
if (hasStandardSandboxes) {
|
|
230
|
-
logger.error(i18n(`lib.sandboxes.create.failure.alreadyInConfig.standard.${plural ? 'other' : 'one'}`, {
|
|
231
|
-
accountName: uiAccountDescription(accountId),
|
|
232
|
-
limit: standardSandboxLimit,
|
|
233
|
-
}));
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
const baseUrl = getHubSpotWebsiteOrigin(getValidEnv(getEnv(accountId)));
|
|
237
|
-
logger.error(i18n(`lib.sandboxes.create.failure.limit.standard.${plural ? 'other' : 'one'}`, {
|
|
238
|
-
accountName: uiAccountDescription(accountId),
|
|
239
|
-
limit: standardSandboxLimit,
|
|
240
|
-
link: `${baseUrl}/sandboxes-developer/${accountId}/standard`,
|
|
241
|
-
}));
|
|
242
|
-
}
|
|
243
|
-
logger.log('');
|
|
157
|
+
logger_1.logger.log('');
|
|
244
158
|
}
|
|
245
159
|
else {
|
|
246
|
-
logError(err);
|
|
160
|
+
(0, index_2.logError)(err);
|
|
247
161
|
}
|
|
248
162
|
throw err;
|
|
249
163
|
}
|
|
250
|
-
module.exports = {
|
|
251
|
-
sandboxTypeMap,
|
|
252
|
-
sandboxApiTypeMap,
|
|
253
|
-
syncTypes,
|
|
254
|
-
getSandboxTypeAsString,
|
|
255
|
-
getHasSandboxesByType,
|
|
256
|
-
getSandboxLimit,
|
|
257
|
-
validateSandboxUsageLimits,
|
|
258
|
-
getAvailableSyncTypes,
|
|
259
|
-
getSyncTypesWithContactRecordsPrompt,
|
|
260
|
-
handleSandboxCreateError,
|
|
261
|
-
};
|
package/lib/serverlessLogs.d.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { HubSpotPromise } from '@hubspot/local-dev-lib/types/Http';
|
|
2
|
+
import { FunctionLog, GetFunctionLogsResponse } from '@hubspot/local-dev-lib/types/Functions';
|
|
3
|
+
export declare function tailLogs(accountId: number, name: string, fetchLatest: () => HubSpotPromise<FunctionLog>, tailCall: (after?: string) => HubSpotPromise<GetFunctionLogsResponse>, compact?: boolean): Promise<void>;
|
|
4
|
+
export declare function outputBuildLog(buildLogUrl: string): Promise<string>;
|
package/lib/serverlessLogs.js
CHANGED
|
@@ -1,89 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
6
|
+
exports.tailLogs = tailLogs;
|
|
7
|
+
exports.outputBuildLog = outputBuildLog;
|
|
8
|
+
const https_1 = __importDefault(require("https"));
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
11
|
+
const index_1 = require("@hubspot/local-dev-lib/errors/index");
|
|
12
|
+
const auth_1 = require("@hubspot/local-dev-lib/constants/auth");
|
|
13
|
+
const config_1 = require("@hubspot/local-dev-lib/config");
|
|
14
|
+
const localDevAuth_1 = require("@hubspot/local-dev-lib/api/localDevAuth");
|
|
15
|
+
const serverlessFunctionLogs_1 = require("./ui/serverlessFunctionLogs");
|
|
16
|
+
const index_2 = require("./errorHandlers/index");
|
|
17
|
+
const SpinniesManager_1 = __importDefault(require("./ui/SpinniesManager"));
|
|
18
|
+
const process_1 = require("./process");
|
|
19
|
+
const exitCodes_1 = require("./enums/exitCodes");
|
|
20
|
+
const lang_1 = require("./lang");
|
|
17
21
|
const TAIL_DELAY = 5000;
|
|
18
|
-
|
|
22
|
+
function base64EncodeString(valueToEncode) {
|
|
19
23
|
if (typeof valueToEncode !== 'string') {
|
|
20
24
|
return valueToEncode;
|
|
21
25
|
}
|
|
22
26
|
const stringBuffer = Buffer.from(valueToEncode);
|
|
23
27
|
return encodeURIComponent(stringBuffer.toString('base64'));
|
|
24
|
-
}
|
|
25
|
-
|
|
28
|
+
}
|
|
29
|
+
function handleUserInput() {
|
|
26
30
|
const onTerminate = async () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
31
|
+
SpinniesManager_1.default.remove('tailLogs');
|
|
32
|
+
SpinniesManager_1.default.remove('stopMessage');
|
|
33
|
+
process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
30
34
|
};
|
|
31
|
-
handleExit(onTerminate);
|
|
32
|
-
handleKeypress(key => {
|
|
35
|
+
(0, process_1.handleExit)(onTerminate);
|
|
36
|
+
(0, process_1.handleKeypress)(key => {
|
|
33
37
|
if ((key.ctrl && key.name == 'c') || key.name === 'q') {
|
|
34
38
|
onTerminate();
|
|
35
39
|
}
|
|
36
40
|
});
|
|
37
|
-
}
|
|
41
|
+
}
|
|
38
42
|
async function verifyAccessKeyAndUserAccess(accountId, scopeGroup) {
|
|
39
|
-
const accountConfig = getAccountConfig(accountId);
|
|
43
|
+
const accountConfig = (0, config_1.getAccountConfig)(accountId);
|
|
44
|
+
if (!accountConfig) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
40
47
|
// TODO[JOE]: Update this i18n key
|
|
41
48
|
const i18nKey = 'lib.serverless';
|
|
42
49
|
const { authType } = accountConfig;
|
|
43
|
-
if (authType !== PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
50
|
+
if (authType !== auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
44
51
|
return;
|
|
45
52
|
}
|
|
46
53
|
let scopesData;
|
|
47
54
|
try {
|
|
48
|
-
|
|
55
|
+
const resp = await (0, localDevAuth_1.fetchScopeData)(accountId, scopeGroup);
|
|
56
|
+
scopesData = resp.data;
|
|
49
57
|
}
|
|
50
58
|
catch (e) {
|
|
51
|
-
logger.debug(i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.fetchScopeDataError`, {
|
|
59
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.verifyAccessKeyAndUserAccess.fetchScopeDataError`, {
|
|
52
60
|
scopeGroup,
|
|
53
|
-
error: e,
|
|
54
61
|
}));
|
|
62
|
+
logger_1.logger.debug(e);
|
|
55
63
|
return;
|
|
56
64
|
}
|
|
57
65
|
const { portalScopesInGroup, userScopesInGroup } = scopesData;
|
|
58
66
|
if (!portalScopesInGroup.length) {
|
|
59
|
-
logger.error(i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.portalMissingScope`));
|
|
67
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.verifyAccessKeyAndUserAccess.portalMissingScope`));
|
|
60
68
|
return;
|
|
61
69
|
}
|
|
62
70
|
if (!portalScopesInGroup.every(s => userScopesInGroup.includes(s))) {
|
|
63
|
-
logger.error(i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.userMissingScope`));
|
|
71
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.verifyAccessKeyAndUserAccess.userMissingScope`));
|
|
64
72
|
}
|
|
65
73
|
else {
|
|
66
|
-
logger.error(i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.genericMissingScope`));
|
|
74
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.verifyAccessKeyAndUserAccess.genericMissingScope`));
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
|
-
|
|
70
|
-
let initialAfter;
|
|
77
|
+
async function tailLogs(accountId, name, fetchLatest, tailCall, compact = false) {
|
|
78
|
+
let initialAfter = '';
|
|
71
79
|
try {
|
|
72
80
|
const { data: latestLog } = await fetchLatest();
|
|
73
81
|
initialAfter = latestLog && base64EncodeString(latestLog.id);
|
|
74
82
|
}
|
|
75
83
|
catch (e) {
|
|
76
84
|
// A 404 means no latest log exists(never executed)
|
|
77
|
-
if (isHubSpotHttpError(e) && e.status !== 404) {
|
|
78
|
-
if (isMissingScopeError(e)) {
|
|
79
|
-
await verifyAccessKeyAndUserAccess(accountId, SCOPE_GROUPS.CMS_FUNCTIONS);
|
|
85
|
+
if ((0, index_1.isHubSpotHttpError)(e) && e.status !== 404) {
|
|
86
|
+
if ((0, index_1.isMissingScopeError)(e)) {
|
|
87
|
+
await verifyAccessKeyAndUserAccess(accountId, auth_1.SCOPE_GROUPS.CMS_FUNCTIONS);
|
|
80
88
|
}
|
|
81
89
|
else {
|
|
82
|
-
await logError(e, new ApiErrorContext({ accountId }));
|
|
90
|
+
await (0, index_2.logError)(e, new index_2.ApiErrorContext({ accountId }));
|
|
83
91
|
}
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
|
-
|
|
94
|
+
async function tail(after) {
|
|
87
95
|
let latestLog;
|
|
88
96
|
let nextAfter;
|
|
89
97
|
try {
|
|
@@ -92,41 +100,41 @@ const tailLogs = async ({ accountId, compact, fetchLatest, tailCall, name, }) =>
|
|
|
92
100
|
nextAfter = latestLog.paging.next.after;
|
|
93
101
|
}
|
|
94
102
|
catch (e) {
|
|
95
|
-
if (isHubSpotHttpError(e) && e.status !== 404) {
|
|
96
|
-
logError(e, new ApiErrorContext({
|
|
103
|
+
if ((0, index_1.isHubSpotHttpError)(e) && e.status !== 404) {
|
|
104
|
+
(0, index_2.logError)(e, new index_2.ApiErrorContext({
|
|
97
105
|
accountId,
|
|
98
106
|
}));
|
|
99
107
|
}
|
|
100
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
108
|
+
process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
101
109
|
}
|
|
102
110
|
if (latestLog && latestLog.results.length) {
|
|
103
|
-
outputLogs(latestLog, {
|
|
111
|
+
(0, serverlessFunctionLogs_1.outputLogs)(latestLog, {
|
|
104
112
|
compact,
|
|
105
113
|
});
|
|
106
114
|
}
|
|
107
115
|
setTimeout(async () => {
|
|
108
116
|
await tail(nextAfter);
|
|
109
117
|
}, TAIL_DELAY);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
118
|
+
}
|
|
119
|
+
SpinniesManager_1.default.init();
|
|
120
|
+
SpinniesManager_1.default.add('tailLogs', {
|
|
113
121
|
text: `Following logs for ${name}`,
|
|
114
122
|
});
|
|
115
|
-
|
|
116
|
-
text: `> Press ${
|
|
123
|
+
SpinniesManager_1.default.add('stopMessage', {
|
|
124
|
+
text: `> Press ${chalk_1.default.bold('q')} to stop following`,
|
|
117
125
|
status: 'non-spinnable',
|
|
118
126
|
});
|
|
119
127
|
handleUserInput();
|
|
120
128
|
await tail(initialAfter);
|
|
121
|
-
}
|
|
122
|
-
|
|
129
|
+
}
|
|
130
|
+
async function outputBuildLog(buildLogUrl) {
|
|
123
131
|
if (!buildLogUrl) {
|
|
124
|
-
logger.debug('Unable to display build output. No build log URL was provided.');
|
|
125
|
-
return;
|
|
132
|
+
logger_1.logger.debug('Unable to display build output. No build log URL was provided.');
|
|
133
|
+
return '';
|
|
126
134
|
}
|
|
127
135
|
return new Promise(resolve => {
|
|
128
136
|
try {
|
|
129
|
-
|
|
137
|
+
https_1.default
|
|
130
138
|
.get(buildLogUrl, response => {
|
|
131
139
|
if (response.statusCode === 404) {
|
|
132
140
|
resolve('');
|
|
@@ -136,21 +144,17 @@ const outputBuildLog = async (buildLogUrl) => {
|
|
|
136
144
|
data += chunk;
|
|
137
145
|
});
|
|
138
146
|
response.on('end', () => {
|
|
139
|
-
logger.log(data);
|
|
147
|
+
logger_1.logger.log(data);
|
|
140
148
|
resolve(data);
|
|
141
149
|
});
|
|
142
150
|
})
|
|
143
151
|
.on('error', () => {
|
|
144
|
-
logger.error('The build log could not be retrieved.');
|
|
152
|
+
logger_1.logger.error('The build log could not be retrieved.');
|
|
145
153
|
});
|
|
146
154
|
}
|
|
147
155
|
catch (e) {
|
|
148
|
-
logger.error('The build log could not be retrieved.');
|
|
156
|
+
logger_1.logger.error('The build log could not be retrieved.');
|
|
149
157
|
resolve('');
|
|
150
158
|
}
|
|
151
159
|
});
|
|
152
|
-
}
|
|
153
|
-
module.exports = {
|
|
154
|
-
outputBuildLog,
|
|
155
|
-
tailLogs,
|
|
156
|
-
};
|
|
160
|
+
}
|
|
@@ -1 +1,9 @@
|
|
|
1
|
+
import { FunctionLog, GetFunctionLogsResponse } from '@hubspot/local-dev-lib/types/Functions';
|
|
2
|
+
type Options = {
|
|
3
|
+
compact?: boolean;
|
|
4
|
+
insertions?: {
|
|
5
|
+
header?: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare function outputLogs(logsResp: GetFunctionLogsResponse | FunctionLog, options: Options): void;
|
|
1
9
|
export {};
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.outputLogs = outputLogs;
|
|
6
7
|
const moment_1 = __importDefault(require("moment"));
|
|
7
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
9
|
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
@@ -90,6 +91,3 @@ function processLogs(logsResp, options) {
|
|
|
90
91
|
function outputLogs(logsResp, options) {
|
|
91
92
|
logger_1.logger.log(processLogs(logsResp, options));
|
|
92
93
|
}
|
|
93
|
-
module.exports = {
|
|
94
|
-
outputLogs,
|
|
95
|
-
};
|
package/lib/validation.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { CmsPublishMode } from '@hubspot/local-dev-lib/types/Files';
|
|
|
3
3
|
export declare function validateAccount(options: Arguments<{
|
|
4
4
|
account?: string;
|
|
5
5
|
accountId?: string;
|
|
6
|
+
derivedAccountId?: number;
|
|
7
|
+
providedAccountId?: string;
|
|
6
8
|
}>): Promise<boolean>;
|
|
7
9
|
export declare function validateCmsPublishMode(options: Arguments<{
|
|
8
10
|
cmsPublishMode?: CmsPublishMode;
|
package/lib/validation.js
CHANGED
|
@@ -50,21 +50,18 @@ const path_1 = require("@hubspot/local-dev-lib/path");
|
|
|
50
50
|
const commonOpts_1 = require("./commonOpts");
|
|
51
51
|
const index_1 = require("./errorHandlers/index");
|
|
52
52
|
async function validateAccount(options) {
|
|
53
|
-
const
|
|
54
|
-
const
|
|
53
|
+
const { derivedAccountId, providedAccountId } = options;
|
|
54
|
+
const accountId = (0, config_1.getAccountId)(derivedAccountId);
|
|
55
55
|
if (!accountId) {
|
|
56
|
-
if (
|
|
57
|
-
logger_1.logger.error(`The account "${
|
|
58
|
-
}
|
|
59
|
-
else if (accountIdOption) {
|
|
60
|
-
logger_1.logger.error(`The account "${accountIdOption}" could not be found in the config`);
|
|
56
|
+
if (providedAccountId) {
|
|
57
|
+
logger_1.logger.error(`The account "${providedAccountId}" could not be found in the config`);
|
|
61
58
|
}
|
|
62
59
|
else {
|
|
63
60
|
logger_1.logger.error('An account needs to be supplied either via "--account" or through setting a "defaultPortal"');
|
|
64
61
|
}
|
|
65
62
|
return false;
|
|
66
63
|
}
|
|
67
|
-
if (
|
|
64
|
+
if (providedAccountId && (0, config_1.loadConfigFromEnvironment)()) {
|
|
68
65
|
throw new Error('Cannot specify an account when environment variables are supplied. Please unset the environment variables or do not use the "--account" flag.');
|
|
69
66
|
}
|
|
70
67
|
const accountConfig = (0, config_1.getAccountConfig)(accountId);
|