@hubspot/local-dev-lib 0.0.10 → 0.1.0-experimental.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/LICENSE +12 -0
- package/README.md +17 -0
- package/api/appsDev.d.ts +6 -0
- package/api/appsDev.js +29 -0
- package/api/customObjects.d.ts +8 -7
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +5 -13
- package/api/designManager.js +6 -9
- package/api/developerTestAccounts.d.ts +7 -0
- package/api/developerTestAccounts.js +48 -0
- package/api/fileManager.d.ts +6 -5
- package/api/fileManager.js +13 -12
- package/api/fileMapper.d.ts +8 -8
- package/api/fileMapper.js +19 -18
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/functions.d.ts +7 -3
- package/api/functions.js +22 -11
- package/api/github.d.ts +11 -0
- package/api/github.js +71 -0
- package/api/hubdb.d.ts +11 -9
- package/api/hubdb.js +28 -22
- package/api/lighthouseScore.d.ts +4 -3
- package/api/lighthouseScore.js +9 -12
- package/api/localDevAuth.d.ts +7 -15
- package/api/localDevAuth.js +28 -13
- package/api/marketplaceValidation.d.ts +4 -3
- package/api/marketplaceValidation.js +8 -11
- package/api/projects.d.ts +34 -21
- package/api/projects.js +135 -45
- package/api/sandboxHubs.d.ts +5 -4
- package/api/sandboxHubs.js +10 -11
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +5 -14
- package/api/secrets.d.ts +6 -8
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +13 -10
- package/config/CLIConfiguration.js +129 -77
- package/config/configFile.js +12 -18
- package/config/configUtils.d.ts +2 -21
- package/config/configUtils.js +5 -4
- package/config/config_DEPRECATED.d.ts +6 -8
- package/config/config_DEPRECATED.js +73 -24
- package/config/environment.js +5 -4
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +10 -7
- package/config/index.js +83 -55
- package/constants/api.d.ts +10 -12
- package/constants/api.js +10 -12
- package/constants/config.d.ts +15 -1
- package/constants/config.js +17 -3
- package/constants/environments.d.ts +1 -0
- package/constants/environments.js +1 -0
- package/constants/extensions.d.ts +2 -0
- package/constants/extensions.js +3 -1
- package/constants/files.d.ts +2 -2
- package/constants/files.js +3 -3
- package/errors/errors_DEPRECATED.d.ts +1 -5
- package/errors/errors_DEPRECATED.js +3 -16
- package/errors/index.d.ts +18 -0
- package/errors/index.js +63 -0
- package/http/addQueryParams.d.ts +2 -0
- package/http/addQueryParams.js +14 -0
- package/http/getAxiosConfig.d.ts +6 -3
- package/http/getAxiosConfig.js +51 -7
- package/http/index.d.ts +10 -11
- package/http/index.js +35 -41
- package/http/unauthed.d.ts +15 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +374 -368
- package/lib/archive.d.ts +2 -6
- package/lib/archive.js +34 -29
- package/lib/cms/functions.d.ts +7 -12
- package/lib/cms/functions.js +47 -50
- package/lib/cms/handleFieldsJS.js +16 -14
- package/lib/cms/modules.d.ts +5 -15
- package/lib/cms/modules.js +100 -39
- package/lib/cms/processFieldsJs.js +10 -33
- package/lib/cms/templates.d.ts +43 -3
- package/lib/cms/templates.js +51 -11
- package/lib/cms/uploadFolder.d.ts +3 -14
- package/lib/cms/uploadFolder.js +58 -42
- package/lib/{validate.d.ts → cms/validate.d.ts} +1 -1
- package/lib/{validate.js → cms/validate.js} +5 -5
- package/lib/cms/watch.d.ts +2 -18
- package/lib/cms/watch.js +63 -68
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.d.ts +2 -0
- package/lib/fileManager.js +184 -0
- package/lib/fileMapper.d.ts +4 -15
- package/lib/fileMapper.js +68 -89
- package/lib/fs.js +2 -2
- package/lib/github.d.ts +6 -18
- package/lib/github.js +97 -76
- package/lib/gitignore.d.ts +2 -0
- package/lib/gitignore.js +21 -4
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/lib/{logging/logger.d.ts → logger.d.ts} +20 -8
- package/{utils → lib}/notify.js +2 -2
- package/lib/oauth.d.ts +2 -5
- package/lib/oauth.js +14 -25
- package/lib/path.d.ts +3 -0
- package/lib/path.js +46 -1
- package/lib/personalAccessKey.d.ts +7 -10
- package/lib/personalAccessKey.js +75 -48
- package/lib/portManager.d.ts +3 -5
- package/lib/portManager.js +18 -6
- package/lib/text.d.ts +1 -0
- package/lib/text.js +9 -1
- package/lib/trackUsage.js +18 -11
- package/lib/urls.js +5 -1
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +24 -0
- package/models/HubSpotHttpError.js +197 -0
- package/models/OAuth2Manager.d.ts +5 -27
- package/models/OAuth2Manager.js +41 -64
- package/package.json +19 -18
- package/types/Accounts.d.ts +86 -3
- package/types/Apps.d.ts +77 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/ComponentStructure.d.ts +30 -10
- package/types/Config.d.ts +19 -2
- package/types/DesignManager.d.ts +10 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +12 -34
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +12 -7
- package/types/Files.d.ts +43 -4
- package/types/Functions.d.ts +26 -0
- package/types/Github.d.ts +12 -0
- package/types/Http.d.ts +11 -12
- package/types/Hubdb.d.ts +9 -0
- package/types/Lang.d.ts +3 -0
- package/types/Migration.d.ts +28 -0
- package/types/Migration.js +10 -0
- package/types/Modules.d.ts +11 -0
- package/types/PortManager.d.ts +7 -0
- package/types/Project.d.ts +4 -0
- package/types/ProjectLog.d.ts +9 -0
- package/types/ProjectLog.js +2 -0
- package/types/Sandbox.d.ts +37 -47
- package/types/Schemas.d.ts +12 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/developerTestAccounts.d.ts +12 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +6 -7
- package/utils/PortManagerServer.js +24 -18
- package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
- package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
- package/utils/cms/fieldsJS.d.ts +1 -2
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/utils/git.d.ts +1 -7
- package/utils/git.js +2 -18
- package/utils/lang.d.ts +1 -5
- package/constants/github.d.ts +0 -4
- package/constants/github.js +0 -7
- package/errors/apiErrors.d.ts +0 -23
- package/errors/apiErrors.js +0 -197
- package/errors/fileSystemErrors.d.ts +0 -5
- package/errors/fileSystemErrors.js +0 -31
- package/errors/standardErrors.d.ts +0 -26
- package/errors/standardErrors.js +0 -64
- package/lang/lang/en.json +0 -383
- package/lib/logging/git.d.ts +0 -2
- package/lib/logging/git.js +0 -54
- package/lib/logging/logs.d.ts +0 -22
- package/lib/logging/logs.js +0 -86
- package/lib/logging/table.d.ts +0 -3
- package/lib/logging/table.js +0 -47
- package/lib/sandboxes.d.ts +0 -14
- package/lib/sandboxes.js +0 -71
- package/models/HubSpotAuthError.d.ts +0 -9
- package/models/HubSpotAuthError.js +0 -20
- package/types/LogCallbacks.d.ts +0 -6
- package/utils/logger.d.ts +0 -11
- package/utils/logger.js +0 -23
- package/utils/objectUtils.d.ts +0 -8
- package/utils/objectUtils.js +0 -33
- /package/{utils → lib}/escapeRegExp.d.ts +0 -0
- /package/{utils → lib}/escapeRegExp.js +0 -0
- /package/lib/{logging/logger.js → logger.js} +0 -0
- /package/{utils → lib}/notify.d.ts +0 -0
- /package/types/{LogCallbacks.js → Apps.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
3
|
+
exports.CLIConfiguration = void 0;
|
|
4
|
+
const logger_1 = require("../lib/logger");
|
|
5
5
|
const environment_1 = require("./environment");
|
|
6
6
|
const environment_2 = require("../lib/environment");
|
|
7
7
|
const configFile_1 = require("./configFile");
|
|
@@ -10,17 +10,9 @@ const environments_1 = require("../constants/environments");
|
|
|
10
10
|
const auth_1 = require("../constants/auth");
|
|
11
11
|
const config_1 = require("../constants/config");
|
|
12
12
|
const files_1 = require("../constants/files");
|
|
13
|
+
const lang_1 = require("../utils/lang");
|
|
13
14
|
const i18nKey = 'config.cliConfiguration';
|
|
14
|
-
|
|
15
|
-
'noConfig',
|
|
16
|
-
'noConfigAccounts',
|
|
17
|
-
'emptyAccountConfig',
|
|
18
|
-
'noAccountId',
|
|
19
|
-
'duplicateAccountIds',
|
|
20
|
-
'duplicateAccountNames',
|
|
21
|
-
'nameContainsSpaces',
|
|
22
|
-
];
|
|
23
|
-
class CLIConfiguration {
|
|
15
|
+
class _CLIConfiguration {
|
|
24
16
|
options;
|
|
25
17
|
useEnvConfig;
|
|
26
18
|
config;
|
|
@@ -47,22 +39,22 @@ class CLIConfiguration {
|
|
|
47
39
|
if (this.options.useEnv) {
|
|
48
40
|
const configFromEnv = (0, environment_1.loadConfigFromEnvironment)();
|
|
49
41
|
if (configFromEnv) {
|
|
50
|
-
(0,
|
|
42
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.configFromEnv`, {
|
|
51
43
|
accountId: configFromEnv.accounts[0].accountId,
|
|
52
|
-
});
|
|
44
|
+
}));
|
|
53
45
|
this.useEnvConfig = true;
|
|
54
|
-
this.config = configFromEnv;
|
|
46
|
+
this.config = this.handleLegacyCmsPublishMode(configFromEnv);
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
49
|
else {
|
|
58
50
|
const configFromFile = (0, configFile_1.loadConfigFromFile)();
|
|
59
|
-
(0,
|
|
51
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.configFromFile`));
|
|
60
52
|
if (!configFromFile) {
|
|
61
|
-
(0,
|
|
53
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.empty`));
|
|
62
54
|
this.config = { accounts: [] };
|
|
63
55
|
}
|
|
64
56
|
this.useEnvConfig = false;
|
|
65
|
-
this.config = configFromFile;
|
|
57
|
+
this.config = this.handleLegacyCmsPublishMode(configFromFile);
|
|
66
58
|
}
|
|
67
59
|
return this.config;
|
|
68
60
|
}
|
|
@@ -97,48 +89,54 @@ class CLIConfiguration {
|
|
|
97
89
|
}
|
|
98
90
|
return this.config;
|
|
99
91
|
}
|
|
100
|
-
validate(
|
|
101
|
-
const validateLogger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
92
|
+
validate() {
|
|
102
93
|
if (!this.config) {
|
|
103
|
-
|
|
94
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noConfig`));
|
|
104
95
|
return false;
|
|
105
96
|
}
|
|
106
97
|
if (!Array.isArray(this.config.accounts)) {
|
|
107
|
-
|
|
98
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noConfigAccounts`));
|
|
108
99
|
return false;
|
|
109
100
|
}
|
|
110
101
|
const accountIdsMap = {};
|
|
111
102
|
const accountNamesMap = {};
|
|
112
103
|
return this.config.accounts.every(accountConfig => {
|
|
113
104
|
if (!accountConfig) {
|
|
114
|
-
|
|
105
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.emptyAccountConfig`));
|
|
115
106
|
return false;
|
|
116
107
|
}
|
|
117
108
|
if (!accountConfig.accountId) {
|
|
118
|
-
|
|
109
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noAccountId`));
|
|
119
110
|
return false;
|
|
120
111
|
}
|
|
121
112
|
if (accountIdsMap[accountConfig.accountId]) {
|
|
122
|
-
|
|
113
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.duplicateAccountIds`, {
|
|
123
114
|
accountId: accountConfig.accountId,
|
|
124
|
-
});
|
|
115
|
+
}));
|
|
125
116
|
return false;
|
|
126
117
|
}
|
|
127
118
|
if (accountConfig.name) {
|
|
128
|
-
if (accountNamesMap[accountConfig.name]) {
|
|
129
|
-
|
|
119
|
+
if (accountNamesMap[accountConfig.name.toLowerCase()]) {
|
|
120
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.duplicateAccountNames`, {
|
|
130
121
|
accountName: accountConfig.name,
|
|
131
|
-
});
|
|
122
|
+
}));
|
|
132
123
|
return false;
|
|
133
124
|
}
|
|
134
125
|
if (/\s+/.test(accountConfig.name)) {
|
|
135
|
-
|
|
126
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.nameContainsSpaces`, {
|
|
136
127
|
accountName: accountConfig.name,
|
|
137
|
-
});
|
|
128
|
+
}));
|
|
138
129
|
return false;
|
|
139
130
|
}
|
|
140
131
|
accountNamesMap[accountConfig.name] = true;
|
|
141
132
|
}
|
|
133
|
+
if (!accountConfig.accountType) {
|
|
134
|
+
this.addOrUpdateAccount({
|
|
135
|
+
...accountConfig,
|
|
136
|
+
accountId: accountConfig.accountId,
|
|
137
|
+
accountType: this.getAccountType(undefined, accountConfig.sandboxAccountType),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
142
140
|
accountIdsMap[accountConfig.accountId] = true;
|
|
143
141
|
return true;
|
|
144
142
|
});
|
|
@@ -196,19 +194,30 @@ class CLIConfiguration {
|
|
|
196
194
|
getResolvedDefaultAccountForCWD(nameOrId) {
|
|
197
195
|
return this.getAccount(nameOrId);
|
|
198
196
|
}
|
|
199
|
-
|
|
197
|
+
getAccountIndex(accountId) {
|
|
200
198
|
return this.config
|
|
201
199
|
? this.config.accounts.findIndex(account => account.accountId === accountId)
|
|
202
200
|
: -1;
|
|
203
201
|
}
|
|
204
202
|
getConfigForAccount(accountId) {
|
|
205
203
|
if (this.config) {
|
|
206
|
-
this.config.accounts.find(account => account.accountId === accountId) ||
|
|
207
|
-
null;
|
|
204
|
+
return (this.config.accounts.find(account => account.accountId === accountId) ||
|
|
205
|
+
null);
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
getConfigAccounts() {
|
|
210
|
+
if (this.config) {
|
|
211
|
+
return this.config.accounts || null;
|
|
208
212
|
}
|
|
209
213
|
return null;
|
|
210
214
|
}
|
|
211
215
|
isAccountInConfig(nameOrId) {
|
|
216
|
+
if (typeof nameOrId === 'string') {
|
|
217
|
+
return (!!this.config &&
|
|
218
|
+
this.config.accounts &&
|
|
219
|
+
!!this.getAccountId(nameOrId.toLowerCase()));
|
|
220
|
+
}
|
|
212
221
|
return (!!this.config && this.config.accounts && !!this.getAccountId(nameOrId));
|
|
213
222
|
}
|
|
214
223
|
getAndLoadConfigIfNeeded(options) {
|
|
@@ -227,23 +236,41 @@ class CLIConfiguration {
|
|
|
227
236
|
}
|
|
228
237
|
return environments_1.ENVIRONMENTS.PROD;
|
|
229
238
|
}
|
|
239
|
+
// Deprecating sandboxAccountType in favor of accountType
|
|
240
|
+
getAccountType(accountType, sandboxAccountType) {
|
|
241
|
+
if (accountType) {
|
|
242
|
+
return accountType;
|
|
243
|
+
}
|
|
244
|
+
if (typeof sandboxAccountType === 'string') {
|
|
245
|
+
if (sandboxAccountType.toUpperCase() === 'DEVELOPER') {
|
|
246
|
+
return config_1.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX;
|
|
247
|
+
}
|
|
248
|
+
if (sandboxAccountType.toUpperCase() === 'STANDARD') {
|
|
249
|
+
return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD;
|
|
253
|
+
}
|
|
230
254
|
/*
|
|
231
255
|
* Config Update Utils
|
|
232
256
|
*/
|
|
233
257
|
/**
|
|
234
258
|
* @throws {Error}
|
|
235
259
|
*/
|
|
236
|
-
|
|
237
|
-
const { accountId, apiKey, authType, clientId, clientSecret,
|
|
260
|
+
addOrUpdateAccount(updatedAccountFields, writeUpdate = true) {
|
|
261
|
+
const { accountId, accountType, apiKey, authType, clientId, clientSecret, defaultCmsPublishMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
|
|
238
262
|
if (!accountId) {
|
|
239
|
-
(0,
|
|
263
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAccount.errors.accountIdRequired`));
|
|
240
264
|
}
|
|
241
265
|
if (!this.config) {
|
|
242
|
-
(0,
|
|
266
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.noConfigToUpdate`));
|
|
243
267
|
return null;
|
|
244
268
|
}
|
|
269
|
+
// Check whether the account is already listed in the config.yml file.
|
|
245
270
|
const currentAccountConfig = this.getAccount(accountId);
|
|
246
|
-
|
|
271
|
+
// For accounts that are already in the config.yml file, sets the auth property.
|
|
272
|
+
let auth = (currentAccountConfig && currentAccountConfig.auth) || {};
|
|
273
|
+
// For accounts not already in the config.yml file, sets the auth property.
|
|
247
274
|
if (clientId || clientSecret || scopes || tokenInfo) {
|
|
248
275
|
auth = {
|
|
249
276
|
...(currentAccountConfig ? currentAccountConfig.auth : {}),
|
|
@@ -265,7 +292,9 @@ class CLIConfiguration {
|
|
|
265
292
|
}
|
|
266
293
|
}
|
|
267
294
|
const updatedEnv = (0, environment_2.getValidEnv)(env || (currentAccountConfig && currentAccountConfig.env));
|
|
268
|
-
const
|
|
295
|
+
const updatedDefaultCmsPublishMode = defaultCmsPublishMode &&
|
|
296
|
+
defaultCmsPublishMode.toLowerCase();
|
|
297
|
+
const updatedAccountType = accountType || (currentAccountConfig && currentAccountConfig.accountType);
|
|
269
298
|
safelyApplyUpdates('name', name);
|
|
270
299
|
safelyApplyUpdates('env', updatedEnv);
|
|
271
300
|
safelyApplyUpdates('accountId', accountId);
|
|
@@ -274,29 +303,36 @@ class CLIConfiguration {
|
|
|
274
303
|
if (nextAccountConfig.authType === auth_1.API_KEY_AUTH_METHOD.value) {
|
|
275
304
|
safelyApplyUpdates('apiKey', apiKey);
|
|
276
305
|
}
|
|
277
|
-
if (typeof
|
|
306
|
+
if (typeof updatedDefaultCmsPublishMode !== 'undefined') {
|
|
278
307
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
279
|
-
safelyApplyUpdates('
|
|
308
|
+
safelyApplyUpdates('defaultCmsPublishMode', files_1.CMS_PUBLISH_MODE[updatedDefaultCmsPublishMode]);
|
|
280
309
|
}
|
|
281
310
|
safelyApplyUpdates('personalAccessKey', personalAccessKey);
|
|
311
|
+
// Deprecating sandboxAccountType in favor of the more generic accountType
|
|
282
312
|
safelyApplyUpdates('sandboxAccountType', sandboxAccountType);
|
|
313
|
+
safelyApplyUpdates('accountType', this.getAccountType(updatedAccountType, sandboxAccountType));
|
|
283
314
|
safelyApplyUpdates('parentAccountId', parentAccountId);
|
|
284
315
|
const completedAccountConfig = nextAccountConfig;
|
|
316
|
+
if (!Object.hasOwn(this.config, 'accounts')) {
|
|
317
|
+
this.config.accounts = [];
|
|
318
|
+
}
|
|
285
319
|
if (currentAccountConfig) {
|
|
286
|
-
(0,
|
|
320
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.updating`, {
|
|
287
321
|
accountId,
|
|
288
|
-
});
|
|
289
|
-
const index = this.
|
|
290
|
-
|
|
291
|
-
(0, logger_1.debug)(`${i18nKey}.updateAccount.addingConfigEntry`, {
|
|
292
|
-
accountId,
|
|
293
|
-
});
|
|
294
|
-
if (this.config.accounts) {
|
|
322
|
+
}));
|
|
323
|
+
const index = this.getAccountIndex(accountId);
|
|
324
|
+
if (index < 0) {
|
|
295
325
|
this.config.accounts.push(completedAccountConfig);
|
|
296
326
|
}
|
|
297
327
|
else {
|
|
298
|
-
this.config.accounts =
|
|
328
|
+
this.config.accounts[index] = completedAccountConfig;
|
|
299
329
|
}
|
|
330
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.addingConfigEntry`, {
|
|
331
|
+
accountId,
|
|
332
|
+
}));
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
this.config.accounts.push(completedAccountConfig);
|
|
300
336
|
}
|
|
301
337
|
if (writeUpdate) {
|
|
302
338
|
this.write();
|
|
@@ -308,11 +344,11 @@ class CLIConfiguration {
|
|
|
308
344
|
*/
|
|
309
345
|
updateDefaultAccount(defaultAccount) {
|
|
310
346
|
if (!this.config) {
|
|
311
|
-
(0,
|
|
347
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
312
348
|
}
|
|
313
349
|
if (!defaultAccount ||
|
|
314
350
|
(typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')) {
|
|
315
|
-
(0,
|
|
351
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`));
|
|
316
352
|
}
|
|
317
353
|
this.config.defaultAccount = defaultAccount;
|
|
318
354
|
return this.write();
|
|
@@ -322,7 +358,7 @@ class CLIConfiguration {
|
|
|
322
358
|
*/
|
|
323
359
|
renameAccount(currentName, newName) {
|
|
324
360
|
if (!this.config) {
|
|
325
|
-
(0,
|
|
361
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
326
362
|
}
|
|
327
363
|
const accountId = this.getAccountId(currentName);
|
|
328
364
|
let accountConfigToRename = null;
|
|
@@ -330,12 +366,17 @@ class CLIConfiguration {
|
|
|
330
366
|
accountConfigToRename = this.getAccount(accountId);
|
|
331
367
|
}
|
|
332
368
|
if (!accountConfigToRename) {
|
|
333
|
-
(0,
|
|
369
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.renameAccount.errors.invalidName`, {
|
|
334
370
|
currentName,
|
|
335
|
-
});
|
|
371
|
+
}));
|
|
336
372
|
}
|
|
337
373
|
if (accountId) {
|
|
338
|
-
this.
|
|
374
|
+
this.addOrUpdateAccount({
|
|
375
|
+
accountId,
|
|
376
|
+
name: newName,
|
|
377
|
+
env: this.getEnv(),
|
|
378
|
+
accountType: accountConfigToRename.accountType,
|
|
379
|
+
});
|
|
339
380
|
}
|
|
340
381
|
if (accountConfigToRename.name === this.getDefaultAccount()) {
|
|
341
382
|
this.updateDefaultAccount(newName);
|
|
@@ -343,20 +384,23 @@ class CLIConfiguration {
|
|
|
343
384
|
}
|
|
344
385
|
/**
|
|
345
386
|
* @throws {Error}
|
|
387
|
+
* TODO: this does not account for the special handling of sandbox account deletes
|
|
346
388
|
*/
|
|
347
389
|
removeAccountFromConfig(nameOrId) {
|
|
348
390
|
if (!this.config) {
|
|
349
|
-
(0,
|
|
391
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
350
392
|
}
|
|
351
393
|
const accountId = this.getAccountId(nameOrId);
|
|
352
394
|
if (!accountId) {
|
|
353
|
-
(0,
|
|
395
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, {
|
|
396
|
+
nameOrId,
|
|
397
|
+
}));
|
|
354
398
|
}
|
|
355
399
|
let removedAccountIsDefault = false;
|
|
356
400
|
const accountConfig = this.getAccount(accountId);
|
|
357
401
|
if (accountConfig) {
|
|
358
|
-
(0,
|
|
359
|
-
const index = this.
|
|
402
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId }));
|
|
403
|
+
const index = this.getAccountIndex(accountId);
|
|
360
404
|
this.config.accounts.splice(index, 1);
|
|
361
405
|
if (this.getDefaultAccount() === accountConfig.name) {
|
|
362
406
|
removedAccountIsDefault = true;
|
|
@@ -368,18 +412,19 @@ class CLIConfiguration {
|
|
|
368
412
|
/**
|
|
369
413
|
* @throws {Error}
|
|
370
414
|
*/
|
|
371
|
-
|
|
415
|
+
updateDefaultCmsPublishMode(defaultCmsPublishMode) {
|
|
372
416
|
if (!this.config) {
|
|
373
|
-
(0,
|
|
417
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
374
418
|
}
|
|
375
|
-
const
|
|
376
|
-
if (!
|
|
377
|
-
(
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
419
|
+
const ALL_CMS_PUBLISH_MODES = Object.values(files_1.CMS_PUBLISH_MODE);
|
|
420
|
+
if (!defaultCmsPublishMode ||
|
|
421
|
+
!ALL_CMS_PUBLISH_MODES.find(m => m === defaultCmsPublishMode)) {
|
|
422
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultCmsPublishMode.errors.invalidCmsPublishMode`, {
|
|
423
|
+
defaultCmsPublishMode,
|
|
424
|
+
validCmsPublishModes: (0, text_1.commaSeparatedValues)(ALL_CMS_PUBLISH_MODES),
|
|
425
|
+
}));
|
|
381
426
|
}
|
|
382
|
-
this.config.
|
|
427
|
+
this.config.defaultCmsPublishMode = defaultCmsPublishMode;
|
|
383
428
|
return this.write();
|
|
384
429
|
}
|
|
385
430
|
/**
|
|
@@ -387,14 +432,14 @@ class CLIConfiguration {
|
|
|
387
432
|
*/
|
|
388
433
|
updateHttpTimeout(timeout) {
|
|
389
434
|
if (!this.config) {
|
|
390
|
-
(0,
|
|
435
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
391
436
|
}
|
|
392
437
|
const parsedTimeout = parseInt(timeout);
|
|
393
438
|
if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
|
|
394
|
-
(0,
|
|
439
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
|
|
395
440
|
timeout,
|
|
396
441
|
minTimeout: config_1.MIN_HTTP_TIMEOUT,
|
|
397
|
-
});
|
|
442
|
+
}));
|
|
398
443
|
}
|
|
399
444
|
this.config.httpTimeout = parsedTimeout;
|
|
400
445
|
return this.write();
|
|
@@ -404,12 +449,12 @@ class CLIConfiguration {
|
|
|
404
449
|
*/
|
|
405
450
|
updateAllowUsageTracking(isEnabled) {
|
|
406
451
|
if (!this.config) {
|
|
407
|
-
(0,
|
|
452
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
408
453
|
}
|
|
409
454
|
if (typeof isEnabled !== 'boolean') {
|
|
410
|
-
(0,
|
|
455
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
|
|
411
456
|
isEnabled: `${isEnabled}`,
|
|
412
|
-
});
|
|
457
|
+
}));
|
|
413
458
|
}
|
|
414
459
|
this.config.allowUsageTracking = isEnabled;
|
|
415
460
|
return this.write();
|
|
@@ -420,5 +465,12 @@ class CLIConfiguration {
|
|
|
420
465
|
}
|
|
421
466
|
return this.config.allowUsageTracking !== false;
|
|
422
467
|
}
|
|
468
|
+
handleLegacyCmsPublishMode(config) {
|
|
469
|
+
if (config?.defaultMode) {
|
|
470
|
+
config.defaultCmsPublishMode = config.defaultMode;
|
|
471
|
+
delete config.defaultMode;
|
|
472
|
+
}
|
|
473
|
+
return config;
|
|
474
|
+
}
|
|
423
475
|
}
|
|
424
|
-
exports.
|
|
476
|
+
exports.CLIConfiguration = new _CLIConfiguration();
|
package/config/configFile.js
CHANGED
|
@@ -8,11 +8,11 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const os_1 = __importDefault(require("os"));
|
|
10
10
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
11
|
-
const logger_1 = require("../
|
|
12
|
-
const fileSystemErrors_1 = require("../errors/fileSystemErrors");
|
|
13
|
-
const standardErrors_1 = require("../errors/standardErrors");
|
|
11
|
+
const logger_1 = require("../lib/logger");
|
|
14
12
|
const config_1 = require("../constants/config");
|
|
15
13
|
const configUtils_1 = require("./configUtils");
|
|
14
|
+
const lang_1 = require("../utils/lang");
|
|
15
|
+
const FileSystemError_1 = require("../models/FileSystemError");
|
|
16
16
|
const i18nKey = 'config.configFile';
|
|
17
17
|
function getConfigFilePath() {
|
|
18
18
|
return path_1.default.join(os_1.default.homedir(), config_1.HUBSPOT_CONFIGURATION_FOLDER, config_1.HUBSPOT_CONFIGURATION_FILE);
|
|
@@ -42,10 +42,10 @@ function readConfigFile(configPath) {
|
|
|
42
42
|
source = fs_extra_1.default.readFileSync(configPath).toString();
|
|
43
43
|
}
|
|
44
44
|
catch (err) {
|
|
45
|
-
(0,
|
|
46
|
-
|
|
45
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorReading`, { configPath }));
|
|
46
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
47
47
|
filepath: configPath,
|
|
48
|
-
|
|
48
|
+
operation: 'read',
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
return source;
|
|
@@ -60,7 +60,7 @@ function parseConfig(configSource) {
|
|
|
60
60
|
parsed = js_yaml_1.default.load(configSource);
|
|
61
61
|
}
|
|
62
62
|
catch (err) {
|
|
63
|
-
(0,
|
|
63
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.parsing`), { cause: err });
|
|
64
64
|
}
|
|
65
65
|
return parsed;
|
|
66
66
|
}
|
|
@@ -77,7 +77,7 @@ function loadConfigFromFile() {
|
|
|
77
77
|
}
|
|
78
78
|
return parseConfig(source);
|
|
79
79
|
}
|
|
80
|
-
(0,
|
|
80
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorLoading`, { configPath }));
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
exports.loadConfigFromFile = loadConfigFromFile;
|
|
@@ -85,23 +85,17 @@ exports.loadConfigFromFile = loadConfigFromFile;
|
|
|
85
85
|
* @throws {Error}
|
|
86
86
|
*/
|
|
87
87
|
function writeConfigToFile(config) {
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
(0, standardErrors_1.throwError)(err);
|
|
94
|
-
}
|
|
88
|
+
const source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
|
|
95
89
|
const configPath = getConfigFilePath();
|
|
96
90
|
try {
|
|
97
91
|
fs_extra_1.default.ensureFileSync(configPath);
|
|
98
92
|
fs_extra_1.default.writeFileSync(configPath, source);
|
|
99
|
-
(0,
|
|
93
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.writeSuccess`, { configPath }));
|
|
100
94
|
}
|
|
101
95
|
catch (err) {
|
|
102
|
-
|
|
96
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
103
97
|
filepath: configPath,
|
|
104
|
-
|
|
98
|
+
operation: 'write',
|
|
105
99
|
});
|
|
106
100
|
}
|
|
107
101
|
}
|
package/config/configUtils.d.ts
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
import { CLIConfig_NEW
|
|
2
|
-
import { AuthType, CLIAccount_NEW } from '../types/Accounts';
|
|
1
|
+
import { CLIConfig_NEW } from '../types/Config';
|
|
2
|
+
import { AuthType, CLIAccount_NEW, PersonalAccessKeyOptions, OAuthOptions, APIKeyOptions } from '../types/Accounts';
|
|
3
3
|
export declare function getOrderedAccount(unorderedAccount: CLIAccount_NEW): CLIAccount_NEW;
|
|
4
4
|
export declare function getOrderedConfig(unorderedConfig: CLIConfig_NEW): CLIConfig_NEW;
|
|
5
|
-
type PersonalAccessKeyOptions = {
|
|
6
|
-
accountId: number;
|
|
7
|
-
personalAccessKey: string;
|
|
8
|
-
env: Environment;
|
|
9
|
-
};
|
|
10
|
-
type OAuthOptions = {
|
|
11
|
-
accountId: number;
|
|
12
|
-
clientId: string;
|
|
13
|
-
clientSecret: string;
|
|
14
|
-
refreshToken: string;
|
|
15
|
-
scopes: Array<string>;
|
|
16
|
-
env: Environment;
|
|
17
|
-
};
|
|
18
|
-
type APIKeyOptions = {
|
|
19
|
-
accountId: number;
|
|
20
|
-
apiKey: string;
|
|
21
|
-
env: Environment;
|
|
22
|
-
};
|
|
23
5
|
export declare function generateConfig(type: AuthType, options: PersonalAccessKeyOptions | OAuthOptions | APIKeyOptions): CLIConfig_NEW | null;
|
|
24
|
-
export {};
|
package/config/configUtils.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateConfig = exports.getOrderedConfig = exports.getOrderedAccount = void 0;
|
|
4
|
-
const logger_1 = require("../
|
|
4
|
+
const logger_1 = require("../lib/logger");
|
|
5
5
|
const auth_1 = require("../constants/auth");
|
|
6
|
+
const lang_1 = require("../utils/lang");
|
|
6
7
|
const i18nKey = 'config.configUtils';
|
|
7
8
|
function getOrderedAccount(unorderedAccount) {
|
|
8
9
|
const { name, accountId, env, authType, ...rest } = unorderedAccount;
|
|
@@ -16,10 +17,10 @@ function getOrderedAccount(unorderedAccount) {
|
|
|
16
17
|
}
|
|
17
18
|
exports.getOrderedAccount = getOrderedAccount;
|
|
18
19
|
function getOrderedConfig(unorderedConfig) {
|
|
19
|
-
const { defaultAccount,
|
|
20
|
+
const { defaultAccount, defaultCmsPublishMode, httpTimeout, allowUsageTracking, accounts, ...rest } = unorderedConfig;
|
|
20
21
|
return {
|
|
21
22
|
...(defaultAccount && { defaultAccount }),
|
|
22
|
-
|
|
23
|
+
defaultCmsPublishMode,
|
|
23
24
|
httpTimeout,
|
|
24
25
|
allowUsageTracking,
|
|
25
26
|
...rest,
|
|
@@ -75,7 +76,7 @@ function generateConfig(type, options) {
|
|
|
75
76
|
configAccount = generateOauthAccountConfig(options);
|
|
76
77
|
break;
|
|
77
78
|
default:
|
|
78
|
-
(0,
|
|
79
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.unknownType`, { type }));
|
|
79
80
|
return null;
|
|
80
81
|
}
|
|
81
82
|
if (configAccount) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CLIConfig_DEPRECATED, Environment } from '../types/Config';
|
|
2
|
-
import { CLIAccount_DEPRECATED, FlatAccountFields_DEPRECATED } from '../types/Accounts';
|
|
3
|
-
import {
|
|
2
|
+
import { AccountType, CLIAccount_DEPRECATED, FlatAccountFields_DEPRECATED, UpdateAccountConfigOptions } from '../types/Accounts';
|
|
3
|
+
import { CmsPublishMode } from '../types/Files';
|
|
4
4
|
import { CLIOptions, WriteConfigOptions } from '../types/CLIOptions';
|
|
5
5
|
export declare const getConfig: () => CLIConfig_DEPRECATED | null;
|
|
6
6
|
export declare function setConfig(updatedConfig?: CLIConfig_DEPRECATED): CLIConfig_DEPRECATED | null;
|
|
@@ -14,9 +14,10 @@ export declare function accountNameExistsInConfig(name: string): boolean;
|
|
|
14
14
|
export declare function getOrderedAccount(unorderedAccount: CLIAccount_DEPRECATED): CLIAccount_DEPRECATED;
|
|
15
15
|
export declare function getOrderedConfig(unorderedConfig: CLIConfig_DEPRECATED): {
|
|
16
16
|
portals: CLIAccount_DEPRECATED[];
|
|
17
|
+
defaultMode?: CmsPublishMode | undefined;
|
|
17
18
|
env?: Environment | undefined;
|
|
18
19
|
httpUseLocalhost?: boolean | undefined;
|
|
19
|
-
|
|
20
|
+
defaultCmsPublishMode: CmsPublishMode | undefined;
|
|
20
21
|
httpTimeout: number | undefined;
|
|
21
22
|
allowUsageTracking: boolean | undefined;
|
|
22
23
|
defaultPortal?: string | number | undefined;
|
|
@@ -27,15 +28,13 @@ export declare function isTrackingAllowed(): boolean;
|
|
|
27
28
|
export declare function getAndLoadConfigIfNeeded(options?: {}): Partial<CLIConfig_DEPRECATED>;
|
|
28
29
|
export declare function findConfig(directory: string): string | null;
|
|
29
30
|
export declare function getEnv(nameOrId?: string | number): Environment;
|
|
31
|
+
export declare function getAccountType(accountType?: AccountType, sandboxAccountType?: string | null): AccountType;
|
|
30
32
|
export declare function getAccountConfig(accountId: number | undefined): CLIAccount_DEPRECATED | undefined;
|
|
31
33
|
export declare function getAccountId(nameOrId?: string | number): number | undefined;
|
|
32
34
|
/**
|
|
33
35
|
* @throws {Error}
|
|
34
36
|
*/
|
|
35
37
|
export declare function removeSandboxAccountFromConfig(nameOrId: string | number): boolean;
|
|
36
|
-
type UpdateAccountConfigOptions = Partial<FlatAccountFields_DEPRECATED> & {
|
|
37
|
-
environment?: Environment;
|
|
38
|
-
};
|
|
39
38
|
/**
|
|
40
39
|
* @throws {Error}
|
|
41
40
|
*/
|
|
@@ -47,7 +46,7 @@ export declare function updateDefaultAccount(defaultAccount: string | number): v
|
|
|
47
46
|
/**
|
|
48
47
|
* @throws {Error}
|
|
49
48
|
*/
|
|
50
|
-
export declare function
|
|
49
|
+
export declare function updateDefaultCmsPublishMode(defaultCmsPublishMode: CmsPublishMode): void;
|
|
51
50
|
/**
|
|
52
51
|
* @throws {Error}
|
|
53
52
|
*/
|
|
@@ -75,4 +74,3 @@ export declare function loadConfigFromEnvironment({ useEnv, }?: {
|
|
|
75
74
|
portals: Array<CLIAccount_DEPRECATED>;
|
|
76
75
|
} | undefined;
|
|
77
76
|
export declare function isConfigFlagEnabled(flag: keyof CLIConfig_DEPRECATED): boolean;
|
|
78
|
-
export {};
|