@hubspot/local-dev-lib 0.4.2-experimental.0 → 0.5.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/config/defaultAccountOverride.d.ts +2 -0
- package/config/defaultAccountOverride.js +57 -0
- package/config/index.d.ts +26 -43
- package/config/index.js +275 -276
- package/config/migrate.d.ts +11 -16
- package/config/migrate.js +79 -159
- package/config/state.d.ts +3 -0
- package/config/state.js +88 -0
- package/config/utils.d.ts +74 -0
- package/config/utils.js +326 -0
- package/constants/config.d.ts +28 -0
- package/constants/config.js +29 -1
- package/constants/environments.d.ts +0 -11
- package/constants/environments.js +1 -12
- package/http/getAxiosConfig.js +7 -1
- package/http/index.js +23 -19
- package/lang/en.json +87 -62
- package/lib/cms/themes.js +3 -1
- package/lib/environment.d.ts +1 -1
- package/lib/gitignore.js +1 -1
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +8 -16
- package/lib/personalAccessKey.d.ts +2 -2
- package/lib/personalAccessKey.js +39 -30
- package/lib/portManager.d.ts +1 -0
- package/lib/portManager.js +6 -1
- package/lib/trackUsage.js +6 -3
- package/models/OAuth2Manager.d.ts +3 -4
- package/models/OAuth2Manager.js +20 -29
- package/package.json +4 -3
- package/types/Accounts.d.ts +20 -109
- package/types/Build.d.ts +1 -0
- package/types/Config.d.ts +14 -26
- package/config/CLIConfiguration.d.ts +0 -72
- package/config/CLIConfiguration.js +0 -548
- package/config/configFile.d.ts +0 -21
- package/config/configFile.js +0 -100
- package/config/configUtils.d.ts +0 -5
- package/config/configUtils.js +0 -87
- package/config/config_DEPRECATED.d.ts +0 -87
- package/config/config_DEPRECATED.js +0 -738
- package/config/environment.d.ts +0 -2
- package/config/environment.js +0 -60
- package/config/getAccountIdentifier.d.ts +0 -2
- package/config/getAccountIdentifier.js +0 -15
- package/utils/accounts.d.ts +0 -4
- package/utils/accounts.js +0 -28
package/config/index.js
CHANGED
|
@@ -1,322 +1,321 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
exports.loadConfigFromEnvironment = loadConfigFromEnvironment;
|
|
61
|
-
function createEmptyConfigFile(options = {}, useHiddenConfig = false) {
|
|
62
|
-
if (useHiddenConfig) {
|
|
63
|
-
CLIConfiguration_1.CLIConfiguration.write({ accounts: [] });
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
return config_DEPRECATED.createEmptyConfigFile(options);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.createEmptyConfigFile = createEmptyConfigFile;
|
|
70
|
-
function deleteEmptyConfigFile() {
|
|
71
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
72
|
-
return CLIConfiguration_1.CLIConfiguration.delete();
|
|
73
|
-
}
|
|
74
|
-
return config_DEPRECATED.deleteEmptyConfigFile();
|
|
75
|
-
}
|
|
76
|
-
exports.deleteEmptyConfigFile = deleteEmptyConfigFile;
|
|
6
|
+
exports.removeLocalStateFlag = exports.addLocalStateFlag = exports.hasLocalStateFlag = exports.isConfigFlagEnabled = exports.updateDefaultCmsPublishMode = exports.updateAutoOpenBrowser = exports.updateAllowAutoUpdates = exports.updateAllowUsageTracking = exports.updateHttpTimeout = exports.removeAccountFromConfig = exports.renameConfigAccount = exports.setConfigAccountAsDefault = exports.updateConfigAccount = exports.addConfigAccount = exports.getConfigAccountEnvironment = exports.getAllConfigAccounts = exports.getConfigDefaultAccountIfExists = exports.getConfigDefaultAccount = exports.getConfigAccountIfExists = exports.getConfigAccountByName = exports.getConfigAccountById = exports.deleteConfigFile = exports.createEmptyConfigFile = exports.isConfigValid = exports.getConfig = exports.getConfigFilePath = exports.globalConfigFileExists = exports.localConfigFileExists = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const config_1 = require("../constants/config");
|
|
9
|
+
const logger_1 = require("../lib/logger");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const files_1 = require("../constants/files");
|
|
12
|
+
const lang_1 = require("../utils/lang");
|
|
13
|
+
const defaultAccountOverride_1 = require("./defaultAccountOverride");
|
|
14
|
+
const environment_1 = require("../lib/environment");
|
|
15
|
+
function localConfigFileExists() {
|
|
16
|
+
return Boolean((0, utils_1.getLocalConfigFilePath)());
|
|
17
|
+
}
|
|
18
|
+
exports.localConfigFileExists = localConfigFileExists;
|
|
19
|
+
function globalConfigFileExists() {
|
|
20
|
+
return fs_extra_1.default.existsSync((0, utils_1.getGlobalConfigFilePath)());
|
|
21
|
+
}
|
|
22
|
+
exports.globalConfigFileExists = globalConfigFileExists;
|
|
23
|
+
function getConfigDefaultFilePath() {
|
|
24
|
+
const globalConfigFilePath = (0, utils_1.getGlobalConfigFilePath)();
|
|
25
|
+
if (fs_extra_1.default.existsSync(globalConfigFilePath)) {
|
|
26
|
+
return globalConfigFilePath;
|
|
27
|
+
}
|
|
28
|
+
const localConfigFilePath = (0, utils_1.getLocalConfigFilePath)();
|
|
29
|
+
if (!localConfigFilePath) {
|
|
30
|
+
throw new Error((0, lang_1.i18n)('config.getDefaultConfigFilePath.error'));
|
|
31
|
+
}
|
|
32
|
+
return localConfigFilePath;
|
|
33
|
+
}
|
|
34
|
+
function getConfigFilePath() {
|
|
35
|
+
const { configFilePathFromEnvironment } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
36
|
+
return configFilePathFromEnvironment || getConfigDefaultFilePath();
|
|
37
|
+
}
|
|
38
|
+
exports.getConfigFilePath = getConfigFilePath;
|
|
77
39
|
function getConfig() {
|
|
78
|
-
|
|
79
|
-
|
|
40
|
+
const { useEnvironmentConfig } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
41
|
+
if (useEnvironmentConfig) {
|
|
42
|
+
return (0, utils_1.buildConfigFromEnvironment)();
|
|
80
43
|
}
|
|
81
|
-
|
|
44
|
+
const pathToRead = getConfigFilePath();
|
|
45
|
+
logger_1.logger.debug((0, lang_1.i18n)('config.getConfig', { path: pathToRead }));
|
|
46
|
+
const configFileSource = (0, utils_1.readConfigFile)(pathToRead);
|
|
47
|
+
return (0, utils_1.parseConfig)(configFileSource);
|
|
82
48
|
}
|
|
83
49
|
exports.getConfig = getConfig;
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
50
|
+
function isConfigValid() {
|
|
51
|
+
const config = getConfig();
|
|
52
|
+
if (config.accounts.length === 0) {
|
|
53
|
+
logger_1.logger.debug((0, lang_1.i18n)('config.isConfigValid.missingAccounts'));
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const accountIdsMap = {};
|
|
57
|
+
const accountNamesMap = {};
|
|
58
|
+
return config.accounts.every(account => {
|
|
59
|
+
if (!(0, utils_1.isConfigAccountValid)(account)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (accountIdsMap[account.accountId]) {
|
|
63
|
+
logger_1.logger.debug((0, lang_1.i18n)('config.isConfigValid.duplicateAccountIds', {
|
|
64
|
+
accountId: account.accountId,
|
|
65
|
+
}));
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
if (account.name) {
|
|
69
|
+
if (accountNamesMap[account.name.toLowerCase()]) {
|
|
70
|
+
logger_1.logger.debug((0, lang_1.i18n)('config.isConfigValid.duplicateAccountNames', {
|
|
71
|
+
accountName: account.name,
|
|
72
|
+
}));
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (/\s+/.test(account.name)) {
|
|
76
|
+
logger_1.logger.debug((0, lang_1.i18n)('config.isConfigValid.invalidAccountName', {
|
|
77
|
+
accountName: account.name,
|
|
78
|
+
}));
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
accountNamesMap[account.name] = true;
|
|
82
|
+
}
|
|
83
|
+
accountIdsMap[account.accountId] = true;
|
|
84
|
+
return true;
|
|
85
|
+
});
|
|
114
86
|
}
|
|
115
|
-
exports.
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
87
|
+
exports.isConfigValid = isConfigValid;
|
|
88
|
+
function createEmptyConfigFile(useGlobalConfig = false) {
|
|
89
|
+
const { configFilePathFromEnvironment } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
90
|
+
const defaultPath = useGlobalConfig
|
|
91
|
+
? (0, utils_1.getGlobalConfigFilePath)()
|
|
92
|
+
: (0, utils_1.getLocalConfigDefaultFilePath)();
|
|
93
|
+
const pathToWrite = configFilePathFromEnvironment || defaultPath;
|
|
94
|
+
(0, utils_1.writeConfigFile)({ accounts: [] }, pathToWrite);
|
|
121
95
|
}
|
|
122
|
-
exports.
|
|
123
|
-
function
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
return CLIConfiguration_1.CLIConfiguration.addOrUpdateAccount({
|
|
127
|
-
...configOptions,
|
|
128
|
-
accountId: accountIdentifier,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return config_DEPRECATED.updateAccountConfig({
|
|
132
|
-
...configOptions,
|
|
133
|
-
portalId: accountIdentifier,
|
|
134
|
-
});
|
|
96
|
+
exports.createEmptyConfigFile = createEmptyConfigFile;
|
|
97
|
+
function deleteConfigFile() {
|
|
98
|
+
const pathToDelete = getConfigFilePath();
|
|
99
|
+
fs_extra_1.default.unlinkSync(pathToDelete);
|
|
135
100
|
}
|
|
136
|
-
exports.
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
config_DEPRECATED.updateDefaultAccount(nameOrId);
|
|
101
|
+
exports.deleteConfigFile = deleteConfigFile;
|
|
102
|
+
function getConfigAccountById(accountId) {
|
|
103
|
+
const { accounts } = getConfig();
|
|
104
|
+
const account = (0, utils_1.getConfigAccountByIdentifier)(accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountId);
|
|
105
|
+
if (!account) {
|
|
106
|
+
throw new Error((0, lang_1.i18n)('config.getConfigAccountById.error', { accountId }));
|
|
143
107
|
}
|
|
108
|
+
return account;
|
|
144
109
|
}
|
|
145
|
-
exports.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return config_DEPRECATED.renameAccount(currentName, newName);
|
|
110
|
+
exports.getConfigAccountById = getConfigAccountById;
|
|
111
|
+
function getConfigAccountByName(accountName) {
|
|
112
|
+
const { accounts } = getConfig();
|
|
113
|
+
const account = (0, utils_1.getConfigAccountByIdentifier)(accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, accountName);
|
|
114
|
+
if (!account) {
|
|
115
|
+
throw new Error((0, lang_1.i18n)('config.getConfigAccountByName.error', { accountName }));
|
|
152
116
|
}
|
|
117
|
+
return account;
|
|
153
118
|
}
|
|
154
|
-
exports.
|
|
155
|
-
function
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
return config_DEPRECATED.getAccountId(nameOrId) || null;
|
|
119
|
+
exports.getConfigAccountByName = getConfigAccountByName;
|
|
120
|
+
function getConfigAccountIfExists(identifier) {
|
|
121
|
+
const config = getConfig();
|
|
122
|
+
return (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
|
|
160
123
|
}
|
|
161
|
-
exports.
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
|
|
124
|
+
exports.getConfigAccountIfExists = getConfigAccountIfExists;
|
|
125
|
+
function getConfigDefaultAccount() {
|
|
126
|
+
const { accounts, defaultAccount } = getConfig();
|
|
127
|
+
let defaultAccountToUse = defaultAccount;
|
|
128
|
+
if (globalConfigFileExists()) {
|
|
129
|
+
const defaultAccountOverrideAccountId = (0, defaultAccountOverride_1.getDefaultAccountOverrideAccountId)();
|
|
130
|
+
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
165
131
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
exports.removeSandboxAccountFromConfig = removeSandboxAccountFromConfig;
|
|
169
|
-
async function deleteAccount(accountName) {
|
|
170
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
171
|
-
return CLIConfiguration_1.CLIConfiguration.removeAccountFromConfig(accountName);
|
|
132
|
+
if (!defaultAccountToUse) {
|
|
133
|
+
throw new Error((0, lang_1.i18n)('config.getConfigDefaultAccount.fieldMissingError'));
|
|
172
134
|
}
|
|
173
|
-
|
|
174
|
-
|
|
135
|
+
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(accounts, defaultAccountToUse);
|
|
136
|
+
if (!account) {
|
|
137
|
+
throw new Error((0, lang_1.i18n)('config.getConfigDefaultAccount.accountMissingError', {
|
|
138
|
+
defaultAccountToUse,
|
|
139
|
+
}));
|
|
175
140
|
}
|
|
141
|
+
return account;
|
|
176
142
|
}
|
|
177
|
-
exports.
|
|
143
|
+
exports.getConfigDefaultAccount = getConfigDefaultAccount;
|
|
144
|
+
function getConfigDefaultAccountIfExists() {
|
|
145
|
+
const { accounts, defaultAccount } = getConfig();
|
|
146
|
+
let defaultAccountToUse = defaultAccount;
|
|
147
|
+
if (globalConfigFileExists()) {
|
|
148
|
+
const defaultAccountOverrideAccountId = (0, defaultAccountOverride_1.getDefaultAccountOverrideAccountId)();
|
|
149
|
+
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
150
|
+
}
|
|
151
|
+
if (!defaultAccountToUse) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(accounts, defaultAccountToUse);
|
|
155
|
+
return account;
|
|
156
|
+
}
|
|
157
|
+
exports.getConfigDefaultAccountIfExists = getConfigDefaultAccountIfExists;
|
|
158
|
+
function getAllConfigAccounts() {
|
|
159
|
+
const { accounts } = getConfig();
|
|
160
|
+
return accounts;
|
|
161
|
+
}
|
|
162
|
+
exports.getAllConfigAccounts = getAllConfigAccounts;
|
|
163
|
+
function getConfigAccountEnvironment(identifier) {
|
|
164
|
+
if (identifier) {
|
|
165
|
+
const config = getConfig();
|
|
166
|
+
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
|
|
167
|
+
if (account) {
|
|
168
|
+
return (0, environment_1.getValidEnv)(account.env);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const defaultAccount = getConfigDefaultAccount();
|
|
172
|
+
return (0, environment_1.getValidEnv)(defaultAccount.env);
|
|
173
|
+
}
|
|
174
|
+
exports.getConfigAccountEnvironment = getConfigAccountEnvironment;
|
|
175
|
+
function addConfigAccount(accountToAdd) {
|
|
176
|
+
if (!(0, utils_1.isConfigAccountValid)(accountToAdd)) {
|
|
177
|
+
throw new Error((0, lang_1.i18n)('config.addConfigAccount.invalidAccount'));
|
|
178
|
+
}
|
|
179
|
+
const config = getConfig();
|
|
180
|
+
const accountInConfig = (0, utils_1.getConfigAccountByIdentifier)(config.accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountToAdd.accountId);
|
|
181
|
+
if (accountInConfig) {
|
|
182
|
+
throw new Error((0, lang_1.i18n)('config.addConfigAccount.duplicateAccount', {
|
|
183
|
+
accountId: accountToAdd.accountId,
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
config.accounts.push(accountToAdd);
|
|
187
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
188
|
+
}
|
|
189
|
+
exports.addConfigAccount = addConfigAccount;
|
|
190
|
+
function updateConfigAccount(updatedAccount) {
|
|
191
|
+
if (!(0, utils_1.isConfigAccountValid)(updatedAccount)) {
|
|
192
|
+
throw new Error((0, lang_1.i18n)('config.updateConfigAccount.invalidAccount'));
|
|
193
|
+
}
|
|
194
|
+
const config = getConfig();
|
|
195
|
+
const accountIndex = (0, utils_1.getConfigAccountIndexById)(config.accounts, updatedAccount.accountId);
|
|
196
|
+
if (accountIndex < 0) {
|
|
197
|
+
throw new Error((0, lang_1.i18n)('config.updateConfigAccount.accountNotFound', {
|
|
198
|
+
accountId: updatedAccount.accountId,
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
config.accounts[accountIndex] = updatedAccount;
|
|
202
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
203
|
+
}
|
|
204
|
+
exports.updateConfigAccount = updateConfigAccount;
|
|
205
|
+
function setConfigAccountAsDefault(identifier) {
|
|
206
|
+
const config = getConfig();
|
|
207
|
+
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
|
|
208
|
+
if (!account) {
|
|
209
|
+
throw new Error((0, lang_1.i18n)('config.setConfigAccountAsDefault.accountNotFound', {
|
|
210
|
+
accountId: identifier,
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
config.defaultAccount = account.accountId;
|
|
214
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
215
|
+
}
|
|
216
|
+
exports.setConfigAccountAsDefault = setConfigAccountAsDefault;
|
|
217
|
+
function renameConfigAccount(currentName, newName) {
|
|
218
|
+
const config = getConfig();
|
|
219
|
+
const account = (0, utils_1.getConfigAccountByIdentifier)(config.accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, currentName);
|
|
220
|
+
if (!account) {
|
|
221
|
+
throw new Error((0, lang_1.i18n)('config.renameConfigAccount.accountNotFound', {
|
|
222
|
+
currentName,
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
const duplicateAccount = (0, utils_1.getConfigAccountByIdentifier)(config.accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, newName);
|
|
226
|
+
if (duplicateAccount) {
|
|
227
|
+
throw new Error((0, lang_1.i18n)('config.renameConfigAccount.duplicateAccount', {
|
|
228
|
+
newName,
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
account.name = newName;
|
|
232
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
233
|
+
}
|
|
234
|
+
exports.renameConfigAccount = renameConfigAccount;
|
|
235
|
+
function removeAccountFromConfig(accountId) {
|
|
236
|
+
const config = getConfig();
|
|
237
|
+
const index = (0, utils_1.getConfigAccountIndexById)(config.accounts, accountId);
|
|
238
|
+
if (index < 0) {
|
|
239
|
+
throw new Error((0, lang_1.i18n)('config.removeAccountFromConfig.accountNotFound', {
|
|
240
|
+
accountId,
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
config.accounts.splice(index, 1);
|
|
244
|
+
if (config.defaultAccount === accountId) {
|
|
245
|
+
delete config.defaultAccount;
|
|
246
|
+
}
|
|
247
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
248
|
+
}
|
|
249
|
+
exports.removeAccountFromConfig = removeAccountFromConfig;
|
|
178
250
|
function updateHttpTimeout(timeout) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
251
|
+
const parsedTimeout = typeof timeout === 'string' ? parseInt(timeout) : timeout;
|
|
252
|
+
if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
|
|
253
|
+
throw new Error((0, lang_1.i18n)('config.updateHttpTimeout.invalidTimeout', {
|
|
254
|
+
minTimeout: config_1.MIN_HTTP_TIMEOUT,
|
|
255
|
+
}));
|
|
184
256
|
}
|
|
257
|
+
const config = getConfig();
|
|
258
|
+
config.httpTimeout = parsedTimeout;
|
|
259
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
185
260
|
}
|
|
186
261
|
exports.updateHttpTimeout = updateHttpTimeout;
|
|
262
|
+
function updateAllowUsageTracking(isAllowed) {
|
|
263
|
+
const config = getConfig();
|
|
264
|
+
config.allowUsageTracking = isAllowed;
|
|
265
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
266
|
+
}
|
|
267
|
+
exports.updateAllowUsageTracking = updateAllowUsageTracking;
|
|
187
268
|
function updateAllowAutoUpdates(enabled) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
else {
|
|
192
|
-
config_DEPRECATED.updateAllowAutoUpdates(enabled);
|
|
193
|
-
}
|
|
269
|
+
const config = getConfig();
|
|
270
|
+
config.allowAutoUpdates = enabled;
|
|
271
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
194
272
|
}
|
|
195
273
|
exports.updateAllowAutoUpdates = updateAllowAutoUpdates;
|
|
196
|
-
function updateAllowUsageTracking(isEnabled) {
|
|
197
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
198
|
-
CLIConfiguration_1.CLIConfiguration.updateAllowUsageTracking(isEnabled);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
config_DEPRECATED.updateAllowUsageTracking(isEnabled);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
exports.updateAllowUsageTracking = updateAllowUsageTracking;
|
|
205
274
|
function updateAutoOpenBrowser(isEnabled) {
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
config_DEPRECATED.updateAutoOpenBrowser(isEnabled);
|
|
275
|
+
if (typeof isEnabled !== 'boolean') {
|
|
276
|
+
throw new Error((0, lang_1.i18n)('config.updateAutoOpenBrowser.invalidInput', {
|
|
277
|
+
isEnabled: `${isEnabled}`,
|
|
278
|
+
}));
|
|
211
279
|
}
|
|
280
|
+
const config = getConfig();
|
|
281
|
+
config.autoOpenBrowser = isEnabled;
|
|
282
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
212
283
|
}
|
|
213
284
|
exports.updateAutoOpenBrowser = updateAutoOpenBrowser;
|
|
214
|
-
function deleteConfigFile() {
|
|
215
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
216
|
-
(0, configFile_1.deleteConfigFile)();
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
config_DEPRECATED.deleteConfigFile();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
exports.deleteConfigFile = deleteConfigFile;
|
|
223
|
-
function isConfigFlagEnabled(flag, defaultValue = false) {
|
|
224
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
225
|
-
return CLIConfiguration_1.CLIConfiguration.isConfigFlagEnabled(flag, defaultValue);
|
|
226
|
-
}
|
|
227
|
-
return config_DEPRECATED.isConfigFlagEnabled(flag, defaultValue);
|
|
228
|
-
}
|
|
229
|
-
exports.isConfigFlagEnabled = isConfigFlagEnabled;
|
|
230
|
-
function isTrackingAllowed() {
|
|
231
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
232
|
-
return CLIConfiguration_1.CLIConfiguration.isTrackingAllowed();
|
|
233
|
-
}
|
|
234
|
-
return config_DEPRECATED.isTrackingAllowed();
|
|
235
|
-
}
|
|
236
|
-
exports.isTrackingAllowed = isTrackingAllowed;
|
|
237
|
-
function getEnv(nameOrId) {
|
|
238
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
239
|
-
return CLIConfiguration_1.CLIConfiguration.getEnv(nameOrId);
|
|
240
|
-
}
|
|
241
|
-
return config_DEPRECATED.getEnv(nameOrId);
|
|
242
|
-
}
|
|
243
|
-
exports.getEnv = getEnv;
|
|
244
|
-
function getAccountType(accountType, sandboxAccountType) {
|
|
245
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
246
|
-
return CLIConfiguration_1.CLIConfiguration.getAccountType(accountType, sandboxAccountType);
|
|
247
|
-
}
|
|
248
|
-
return config_DEPRECATED.getAccountType(accountType, sandboxAccountType);
|
|
249
|
-
}
|
|
250
|
-
exports.getAccountType = getAccountType;
|
|
251
|
-
function getConfigDefaultAccount() {
|
|
252
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
253
|
-
return CLIConfiguration_1.CLIConfiguration.getDefaultAccount();
|
|
254
|
-
}
|
|
255
|
-
return config_DEPRECATED.getConfigDefaultAccount();
|
|
256
|
-
}
|
|
257
|
-
exports.getConfigDefaultAccount = getConfigDefaultAccount;
|
|
258
|
-
function getDisplayDefaultAccount() {
|
|
259
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
260
|
-
return CLIConfiguration_1.CLIConfiguration.config?.defaultAccount;
|
|
261
|
-
}
|
|
262
|
-
return config_DEPRECATED.getConfigDefaultAccount();
|
|
263
|
-
}
|
|
264
|
-
exports.getDisplayDefaultAccount = getDisplayDefaultAccount;
|
|
265
|
-
function getConfigAccounts() {
|
|
266
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
267
|
-
return CLIConfiguration_1.CLIConfiguration.getConfigAccounts();
|
|
268
|
-
}
|
|
269
|
-
return config_DEPRECATED.getConfigAccounts();
|
|
270
|
-
}
|
|
271
|
-
exports.getConfigAccounts = getConfigAccounts;
|
|
272
285
|
function updateDefaultCmsPublishMode(cmsPublishMode) {
|
|
273
|
-
if (
|
|
274
|
-
|
|
286
|
+
if (!cmsPublishMode ||
|
|
287
|
+
!Object.values(files_1.CMS_PUBLISH_MODE).includes(cmsPublishMode)) {
|
|
288
|
+
throw new Error((0, lang_1.i18n)('config.updateDefaultCmsPublishMode.invalidCmsPublishMode'));
|
|
275
289
|
}
|
|
276
|
-
|
|
290
|
+
const config = getConfig();
|
|
291
|
+
config.defaultCmsPublishMode = cmsPublishMode;
|
|
292
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
277
293
|
}
|
|
278
294
|
exports.updateDefaultCmsPublishMode = updateDefaultCmsPublishMode;
|
|
279
|
-
function
|
|
280
|
-
|
|
281
|
-
|
|
295
|
+
function isConfigFlagEnabled(flag, defaultValue) {
|
|
296
|
+
const config = getConfig();
|
|
297
|
+
if (typeof config[flag] === 'undefined') {
|
|
298
|
+
return defaultValue || false;
|
|
282
299
|
}
|
|
300
|
+
return Boolean(config[flag]);
|
|
283
301
|
}
|
|
284
|
-
exports.
|
|
285
|
-
function getDefaultAccountOverrideFilePath() {
|
|
286
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
287
|
-
return CLIConfiguration_1.CLIConfiguration.getDefaultAccountOverrideFilePath();
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
exports.getDefaultAccountOverrideFilePath = getDefaultAccountOverrideFilePath;
|
|
302
|
+
exports.isConfigFlagEnabled = isConfigFlagEnabled;
|
|
291
303
|
function hasLocalStateFlag(flag) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
return config_DEPRECATED.hasLocalStateFlag(flag);
|
|
304
|
+
const config = getConfig();
|
|
305
|
+
return config.flags?.includes(flag) || false;
|
|
296
306
|
}
|
|
297
307
|
exports.hasLocalStateFlag = hasLocalStateFlag;
|
|
298
308
|
function addLocalStateFlag(flag) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
else {
|
|
303
|
-
config_DEPRECATED.addLocalStateFlag(flag);
|
|
309
|
+
const config = getConfig();
|
|
310
|
+
if (!hasLocalStateFlag(flag)) {
|
|
311
|
+
config.flags = [...(config.flags || []), flag];
|
|
304
312
|
}
|
|
313
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
305
314
|
}
|
|
306
315
|
exports.addLocalStateFlag = addLocalStateFlag;
|
|
307
316
|
function removeLocalStateFlag(flag) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
else {
|
|
312
|
-
config_DEPRECATED.removeLocalStateFlag(flag);
|
|
313
|
-
}
|
|
317
|
+
const config = getConfig();
|
|
318
|
+
config.flags = config.flags?.filter(f => f !== flag) || [];
|
|
319
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
314
320
|
}
|
|
315
321
|
exports.removeLocalStateFlag = removeLocalStateFlag;
|
|
316
|
-
// These functions are not supported with the new config setup
|
|
317
|
-
exports.getConfigAccountId = config_DEPRECATED.getConfigAccountId;
|
|
318
|
-
exports.getOrderedAccount = config_DEPRECATED.getOrderedAccount;
|
|
319
|
-
exports.getOrderedConfig = config_DEPRECATED.getOrderedConfig;
|
|
320
|
-
exports.setConfig = config_DEPRECATED.setConfig;
|
|
321
|
-
exports.setConfigPath = config_DEPRECATED.setConfigPath;
|
|
322
|
-
exports.findConfig = config_DEPRECATED.findConfig;
|
package/config/migrate.d.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function configFileExists(useHiddenConfig?: boolean, configPath?: string): boolean;
|
|
6
|
-
export declare function getConfigPath(configPath?: string, useHiddenConfig?: boolean): string | null;
|
|
7
|
-
export declare function migrateConfig(deprecatedConfig: CLIConfig_DEPRECATED | null): void;
|
|
8
|
-
type ConflictValue = boolean | string | number | CmsPublishMode | Environment;
|
|
1
|
+
import { HubSpotConfig } from '../types/Config';
|
|
2
|
+
import { ValueOf } from '../types/Utils';
|
|
3
|
+
export declare function getConfigAtPath(path: string): HubSpotConfig;
|
|
4
|
+
export declare function migrateConfigAtPath(path: string): void;
|
|
9
5
|
export type ConflictProperty = {
|
|
10
|
-
property: keyof
|
|
11
|
-
oldValue:
|
|
12
|
-
newValue:
|
|
6
|
+
property: keyof HubSpotConfig;
|
|
7
|
+
oldValue: ValueOf<HubSpotConfig>;
|
|
8
|
+
newValue: ValueOf<Required<HubSpotConfig>>;
|
|
13
9
|
};
|
|
14
|
-
export declare function mergeConfigProperties(
|
|
15
|
-
|
|
10
|
+
export declare function mergeConfigProperties(toConfig: HubSpotConfig, fromConfig: HubSpotConfig, force?: boolean): {
|
|
11
|
+
configWithMergedProperties: HubSpotConfig;
|
|
16
12
|
conflicts: Array<ConflictProperty>;
|
|
17
13
|
};
|
|
18
|
-
export declare function
|
|
19
|
-
|
|
14
|
+
export declare function mergeConfigAccounts(toConfig: HubSpotConfig, fromConfig: HubSpotConfig): {
|
|
15
|
+
configWithMergedAccounts: HubSpotConfig;
|
|
20
16
|
skippedAccountIds: Array<string | number>;
|
|
21
17
|
};
|
|
22
|
-
export {};
|