@hubspot/local-dev-lib 3.21.2 → 4.0.0-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/config/defaultAccountOverride.d.ts +2 -0
- package/config/defaultAccountOverride.js +57 -0
- package/config/index.d.ts +30 -44
- package/config/index.js +332 -267
- package/config/migrate.d.ts +12 -16
- package/config/migrate.js +86 -160
- package/config/utils.d.ts +30 -0
- package/config/utils.js +373 -0
- package/constants/config.d.ts +40 -0
- package/constants/config.js +41 -1
- package/constants/environments.d.ts +0 -11
- package/constants/environments.js +1 -12
- package/errors/index.d.ts +2 -0
- package/errors/index.js +6 -1
- package/http/getAxiosConfig.js +7 -1
- package/http/index.js +23 -19
- package/lang/en.json +89 -61
- package/lib/cms/themes.js +3 -1
- package/lib/environment.d.ts +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 +43 -30
- package/lib/trackUsage.js +6 -3
- package/models/HubSpotConfigError.d.ts +6 -0
- package/models/HubSpotConfigError.js +34 -0
- package/models/OAuth2Manager.d.ts +3 -4
- package/models/OAuth2Manager.js +20 -29
- package/package.json +5 -5
- package/types/Accounts.d.ts +20 -109
- package/types/Config.d.ts +17 -26
- package/config/CLIConfiguration.d.ts +0 -72
- package/config/CLIConfiguration.js +0 -551
- 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,387 @@
|
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.deleteConfigFileIfEmpty = exports.createEmptyConfigFile = exports.validateConfig = exports.getConfig = exports.getConfigFilePath = exports.configFileExists = exports.globalConfigFileExists = exports.localConfigFileExists = exports.getLocalConfigFilePathIfExists = exports.getGlobalConfigFilePath = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
9
|
+
const config_1 = require("../constants/config");
|
|
10
|
+
const logger_1 = require("../lib/logger");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const files_1 = require("../constants/files");
|
|
13
|
+
const lang_1 = require("../utils/lang");
|
|
14
|
+
const defaultAccountOverride_1 = require("./defaultAccountOverride");
|
|
15
|
+
const environment_1 = require("../lib/environment");
|
|
16
|
+
const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
|
|
17
|
+
const config_2 = require("../constants/config");
|
|
18
|
+
const isDeepEqual_1 = require("../lib/isDeepEqual");
|
|
19
|
+
const path_1 = require("../lib/path");
|
|
20
|
+
const EMPTY_CONFIG = { accounts: [] };
|
|
21
|
+
function getGlobalConfigFilePath() {
|
|
22
|
+
return config_1.GLOBAL_CONFIG_PATH;
|
|
23
|
+
}
|
|
24
|
+
exports.getGlobalConfigFilePath = getGlobalConfigFilePath;
|
|
25
|
+
function getLocalConfigFilePathIfExists() {
|
|
26
|
+
return (0, findup_sync_1.default)([
|
|
27
|
+
config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
28
|
+
config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME.replace('.yml', '.yaml'),
|
|
29
|
+
], { cwd: (0, path_1.getCwd)() });
|
|
30
|
+
}
|
|
31
|
+
exports.getLocalConfigFilePathIfExists = getLocalConfigFilePathIfExists;
|
|
32
|
+
function localConfigFileExists() {
|
|
33
|
+
return Boolean(getLocalConfigFilePathIfExists());
|
|
34
|
+
}
|
|
35
|
+
exports.localConfigFileExists = localConfigFileExists;
|
|
36
|
+
function globalConfigFileExists() {
|
|
37
|
+
return (0, utils_1.doesConfigFileExistAtPath)(getGlobalConfigFilePath());
|
|
38
|
+
}
|
|
39
|
+
exports.globalConfigFileExists = globalConfigFileExists;
|
|
40
|
+
function configFileExists() {
|
|
41
|
+
try {
|
|
42
|
+
return (0, utils_1.doesConfigFileExistAtPath)(getConfigFilePath());
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return false;
|
|
57
46
|
}
|
|
58
|
-
return Boolean(config_DEPRECATED.loadConfigFromEnvironment());
|
|
59
47
|
}
|
|
60
|
-
exports.
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
exports.configFileExists = configFileExists;
|
|
49
|
+
function getConfigDefaultFilePath() {
|
|
50
|
+
const globalConfigFilePath = getGlobalConfigFilePath();
|
|
51
|
+
if ((0, utils_1.doesConfigFileExistAtPath)(globalConfigFilePath)) {
|
|
52
|
+
return globalConfigFilePath;
|
|
64
53
|
}
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
const localConfigFilePath = getLocalConfigFilePathIfExists();
|
|
55
|
+
if (!localConfigFilePath) {
|
|
56
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getDefaultConfigFilePath.error'), config_2.HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
67
57
|
}
|
|
58
|
+
return localConfigFilePath;
|
|
68
59
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return CLIConfiguration_1.CLIConfiguration.delete();
|
|
73
|
-
}
|
|
74
|
-
return config_DEPRECATED.deleteEmptyConfigFile();
|
|
60
|
+
function getConfigFilePath() {
|
|
61
|
+
const { configFilePathFromEnvironment } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
62
|
+
return configFilePathFromEnvironment || getConfigDefaultFilePath();
|
|
75
63
|
}
|
|
76
|
-
exports.
|
|
64
|
+
exports.getConfigFilePath = getConfigFilePath;
|
|
77
65
|
function getConfig() {
|
|
78
|
-
|
|
79
|
-
|
|
66
|
+
let pathToRead;
|
|
67
|
+
try {
|
|
68
|
+
const { useEnvironmentConfig } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
69
|
+
if (useEnvironmentConfig) {
|
|
70
|
+
return (0, utils_1.buildConfigFromEnvironment)();
|
|
71
|
+
}
|
|
72
|
+
pathToRead = getConfigFilePath();
|
|
73
|
+
logger_1.logger.debug((0, lang_1.i18n)('config.getConfig.reading', { path: pathToRead }));
|
|
74
|
+
const configFileSource = (0, utils_1.readConfigFile)(pathToRead);
|
|
75
|
+
return (0, utils_1.parseConfig)(configFileSource, pathToRead);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
throw new HubSpotConfigError_1.HubSpotConfigError(pathToRead
|
|
79
|
+
? (0, lang_1.i18n)('config.getConfig.errorWithPath', { path: pathToRead })
|
|
80
|
+
: (0, lang_1.i18n)('config.getConfig.error'), config_2.HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ, { cause: err });
|
|
80
81
|
}
|
|
81
|
-
return config_DEPRECATED.getConfig();
|
|
82
82
|
}
|
|
83
83
|
exports.getConfig = getConfig;
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
84
|
+
function validateConfig() {
|
|
85
|
+
const config = getConfig();
|
|
86
|
+
if (config.accounts.length === 0) {
|
|
87
|
+
return {
|
|
88
|
+
isValid: false,
|
|
89
|
+
errors: [(0, lang_1.i18n)('config.validateConfig.missingAccounts')],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const accountIdsMap = {};
|
|
93
|
+
const accountNamesMap = {};
|
|
94
|
+
const validationErrors = [];
|
|
95
|
+
config.accounts.forEach(account => {
|
|
96
|
+
const accountValidationResult = (0, utils_1.validateConfigAccount)(account);
|
|
97
|
+
if (!accountValidationResult.isValid) {
|
|
98
|
+
validationErrors.push(...accountValidationResult.errors);
|
|
99
|
+
}
|
|
100
|
+
if (accountIdsMap[account.accountId]) {
|
|
101
|
+
validationErrors.push((0, lang_1.i18n)('config.validateConfig.duplicateAccountIds', {
|
|
102
|
+
accountId: account.accountId,
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
if (account.name) {
|
|
106
|
+
if (accountNamesMap[account.name.toLowerCase()]) {
|
|
107
|
+
validationErrors.push((0, lang_1.i18n)('config.validateConfig.duplicateAccountNames', {
|
|
108
|
+
accountName: account.name,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
if (/\s+/.test(account.name)) {
|
|
112
|
+
validationErrors.push((0, lang_1.i18n)('config.validateConfig.invalidAccountName', {
|
|
113
|
+
accountName: account.name,
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
accountNamesMap[account.name] = true;
|
|
117
|
+
}
|
|
118
|
+
accountIdsMap[account.accountId] = true;
|
|
119
|
+
});
|
|
120
|
+
return { isValid: validationErrors.length === 0, errors: validationErrors };
|
|
101
121
|
}
|
|
102
|
-
exports.
|
|
103
|
-
function
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
122
|
+
exports.validateConfig = validateConfig;
|
|
123
|
+
function createEmptyConfigFile(useGlobalConfig = false) {
|
|
124
|
+
const { configFilePathFromEnvironment } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
125
|
+
const defaultPath = useGlobalConfig
|
|
126
|
+
? getGlobalConfigFilePath()
|
|
127
|
+
: (0, utils_1.getLocalConfigDefaultFilePath)();
|
|
128
|
+
const pathToWrite = configFilePathFromEnvironment || defaultPath;
|
|
129
|
+
(0, utils_1.writeConfigFile)(EMPTY_CONFIG, pathToWrite);
|
|
107
130
|
}
|
|
108
|
-
exports.
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
exports.accountNameExistsInConfig = accountNameExistsInConfig;
|
|
123
|
-
function updateAccountConfig(configOptions) {
|
|
124
|
-
const accountIdentifier = (0, getAccountIdentifier_1.getAccountIdentifier)(configOptions);
|
|
125
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
126
|
-
return CLIConfiguration_1.CLIConfiguration.addOrUpdateAccount({
|
|
127
|
-
...configOptions,
|
|
128
|
-
accountId: accountIdentifier,
|
|
131
|
+
exports.createEmptyConfigFile = createEmptyConfigFile;
|
|
132
|
+
function deleteConfigFileIfEmpty() {
|
|
133
|
+
const pathToDelete = getConfigFilePath();
|
|
134
|
+
try {
|
|
135
|
+
const config = getConfig();
|
|
136
|
+
if ((0, isDeepEqual_1.isDeepEqual)(config, EMPTY_CONFIG)) {
|
|
137
|
+
fs_extra_1.default.unlinkSync(pathToDelete);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
const { message, type } = (0, utils_1.handleConfigFileSystemError)(error, pathToDelete);
|
|
142
|
+
throw new HubSpotConfigError_1.HubSpotConfigError(message, type, config_1.HUBSPOT_CONFIG_OPERATIONS.DELETE, {
|
|
143
|
+
cause: error,
|
|
129
144
|
});
|
|
130
145
|
}
|
|
131
|
-
return config_DEPRECATED.updateAccountConfig({
|
|
132
|
-
...configOptions,
|
|
133
|
-
portalId: accountIdentifier,
|
|
134
|
-
});
|
|
135
146
|
}
|
|
136
|
-
exports.
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
config_DEPRECATED.updateDefaultAccount(nameOrId);
|
|
147
|
+
exports.deleteConfigFileIfEmpty = deleteConfigFileIfEmpty;
|
|
148
|
+
function getConfigAccountById(accountId) {
|
|
149
|
+
const { accounts } = getConfig();
|
|
150
|
+
const account = (0, utils_1.getConfigAccountByIdentifier)(accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountId);
|
|
151
|
+
if (!account) {
|
|
152
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getConfigAccountById.error', { accountId }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
143
153
|
}
|
|
154
|
+
return account;
|
|
144
155
|
}
|
|
145
|
-
exports.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return config_DEPRECATED.renameAccount(currentName, newName);
|
|
156
|
+
exports.getConfigAccountById = getConfigAccountById;
|
|
157
|
+
function getConfigAccountByName(accountName) {
|
|
158
|
+
const { accounts } = getConfig();
|
|
159
|
+
const account = (0, utils_1.getConfigAccountByIdentifier)(accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, accountName);
|
|
160
|
+
if (!account) {
|
|
161
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getConfigAccountByName.error', { accountName }), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
152
162
|
}
|
|
163
|
+
return account;
|
|
153
164
|
}
|
|
154
|
-
exports.
|
|
155
|
-
function
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
return config_DEPRECATED.getAccountId(nameOrId) || null;
|
|
165
|
+
exports.getConfigAccountByName = getConfigAccountByName;
|
|
166
|
+
function getConfigAccountIfExists(identifier) {
|
|
167
|
+
const config = getConfig();
|
|
168
|
+
return (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
|
|
160
169
|
}
|
|
161
|
-
exports.
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
|
|
170
|
+
exports.getConfigAccountIfExists = getConfigAccountIfExists;
|
|
171
|
+
function getConfigDefaultAccount() {
|
|
172
|
+
const { accounts, defaultAccount } = getConfig();
|
|
173
|
+
let defaultAccountToUse = defaultAccount;
|
|
174
|
+
const currentConfigPath = getConfigFilePath();
|
|
175
|
+
const globalConfigPath = getGlobalConfigFilePath();
|
|
176
|
+
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
177
|
+
const defaultAccountOverrideAccountId = (0, defaultAccountOverride_1.getDefaultAccountOverrideAccountId)();
|
|
178
|
+
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
165
179
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
exports.removeSandboxAccountFromConfig = removeSandboxAccountFromConfig;
|
|
169
|
-
async function deleteAccount(accountName) {
|
|
170
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
171
|
-
return CLIConfiguration_1.CLIConfiguration.removeAccountFromConfig(accountName);
|
|
180
|
+
if (!defaultAccountToUse) {
|
|
181
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getConfigDefaultAccount.fieldMissingError'), config_2.HUBSPOT_CONFIG_ERROR_TYPES.NO_DEFAULT_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
172
182
|
}
|
|
173
|
-
|
|
174
|
-
|
|
183
|
+
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(accounts, defaultAccountToUse);
|
|
184
|
+
if (!account) {
|
|
185
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getConfigDefaultAccount.accountMissingError', {
|
|
186
|
+
defaultAccountToUse,
|
|
187
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
175
188
|
}
|
|
189
|
+
return account;
|
|
176
190
|
}
|
|
177
|
-
exports.
|
|
191
|
+
exports.getConfigDefaultAccount = getConfigDefaultAccount;
|
|
192
|
+
function getConfigDefaultAccountIfExists() {
|
|
193
|
+
const { accounts, defaultAccount } = getConfig();
|
|
194
|
+
let defaultAccountToUse = defaultAccount;
|
|
195
|
+
// Only check for default account override if we're using the global config
|
|
196
|
+
const currentConfigPath = getConfigFilePath();
|
|
197
|
+
const globalConfigPath = getGlobalConfigFilePath();
|
|
198
|
+
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
199
|
+
const defaultAccountOverrideAccountId = (0, defaultAccountOverride_1.getDefaultAccountOverrideAccountId)();
|
|
200
|
+
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
201
|
+
}
|
|
202
|
+
if (!defaultAccountToUse) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(accounts, defaultAccountToUse);
|
|
206
|
+
return account;
|
|
207
|
+
}
|
|
208
|
+
exports.getConfigDefaultAccountIfExists = getConfigDefaultAccountIfExists;
|
|
209
|
+
function getAllConfigAccounts() {
|
|
210
|
+
const { accounts } = getConfig();
|
|
211
|
+
return accounts;
|
|
212
|
+
}
|
|
213
|
+
exports.getAllConfigAccounts = getAllConfigAccounts;
|
|
214
|
+
function getConfigAccountEnvironment(identifier) {
|
|
215
|
+
const config = getConfig();
|
|
216
|
+
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
|
|
217
|
+
if (!account) {
|
|
218
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getConfigAccountEnvironment.accountNotFound', {
|
|
219
|
+
identifier,
|
|
220
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
221
|
+
}
|
|
222
|
+
return (0, environment_1.getValidEnv)(account.env);
|
|
223
|
+
}
|
|
224
|
+
exports.getConfigAccountEnvironment = getConfigAccountEnvironment;
|
|
225
|
+
function addConfigAccount(accountToAdd) {
|
|
226
|
+
if (!(0, utils_1.validateConfigAccount)(accountToAdd)) {
|
|
227
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.addConfigAccount.invalidAccount'), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
228
|
+
}
|
|
229
|
+
const config = getConfig();
|
|
230
|
+
const accountInConfig = (0, utils_1.getConfigAccountByIdentifier)(config.accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountToAdd.accountId);
|
|
231
|
+
if (accountInConfig) {
|
|
232
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.addConfigAccount.duplicateAccount', {
|
|
233
|
+
accountId: accountToAdd.accountId,
|
|
234
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
235
|
+
}
|
|
236
|
+
config.accounts.push(accountToAdd);
|
|
237
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
238
|
+
}
|
|
239
|
+
exports.addConfigAccount = addConfigAccount;
|
|
240
|
+
function updateConfigAccount(updatedAccount) {
|
|
241
|
+
if (!(0, utils_1.validateConfigAccount)(updatedAccount)) {
|
|
242
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateConfigAccount.invalidAccount', {
|
|
243
|
+
name: updatedAccount.name,
|
|
244
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
245
|
+
}
|
|
246
|
+
const config = getConfig();
|
|
247
|
+
const accountIndex = (0, utils_1.getConfigAccountIndexById)(config.accounts, updatedAccount.accountId);
|
|
248
|
+
if (accountIndex < 0) {
|
|
249
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateConfigAccount.accountNotFound', {
|
|
250
|
+
accountId: updatedAccount.accountId,
|
|
251
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
252
|
+
}
|
|
253
|
+
config.accounts[accountIndex] = updatedAccount;
|
|
254
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
255
|
+
}
|
|
256
|
+
exports.updateConfigAccount = updateConfigAccount;
|
|
257
|
+
function setConfigAccountAsDefault(identifier) {
|
|
258
|
+
const config = getConfig();
|
|
259
|
+
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
|
|
260
|
+
if (!account) {
|
|
261
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.setConfigAccountAsDefault.accountNotFound', {
|
|
262
|
+
identifier,
|
|
263
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
264
|
+
}
|
|
265
|
+
config.defaultAccount = account.accountId;
|
|
266
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
267
|
+
}
|
|
268
|
+
exports.setConfigAccountAsDefault = setConfigAccountAsDefault;
|
|
269
|
+
function renameConfigAccount(currentName, newName) {
|
|
270
|
+
const config = getConfig();
|
|
271
|
+
const account = (0, utils_1.getConfigAccountByIdentifier)(config.accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, currentName);
|
|
272
|
+
if (!account) {
|
|
273
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.renameConfigAccount.accountNotFound', {
|
|
274
|
+
currentName,
|
|
275
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
276
|
+
}
|
|
277
|
+
const duplicateAccount = (0, utils_1.getConfigAccountByIdentifier)(config.accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, newName);
|
|
278
|
+
if (duplicateAccount) {
|
|
279
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.renameConfigAccount.duplicateAccount', {
|
|
280
|
+
currentName,
|
|
281
|
+
newName,
|
|
282
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
283
|
+
}
|
|
284
|
+
account.name = newName;
|
|
285
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
286
|
+
}
|
|
287
|
+
exports.renameConfigAccount = renameConfigAccount;
|
|
288
|
+
function removeAccountFromConfig(accountId) {
|
|
289
|
+
const config = getConfig();
|
|
290
|
+
const index = (0, utils_1.getConfigAccountIndexById)(config.accounts, accountId);
|
|
291
|
+
if (index < 0) {
|
|
292
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.removeAccountFromConfig.accountNotFound', {
|
|
293
|
+
accountId,
|
|
294
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
295
|
+
}
|
|
296
|
+
config.accounts.splice(index, 1);
|
|
297
|
+
if (config.defaultAccount === accountId) {
|
|
298
|
+
delete config.defaultAccount;
|
|
299
|
+
}
|
|
300
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
301
|
+
}
|
|
302
|
+
exports.removeAccountFromConfig = removeAccountFromConfig;
|
|
178
303
|
function updateHttpTimeout(timeout) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
304
|
+
const parsedTimeout = typeof timeout === 'string' ? parseInt(timeout) : timeout;
|
|
305
|
+
if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
|
|
306
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateHttpTimeout.invalidTimeout', {
|
|
307
|
+
minTimeout: config_1.MIN_HTTP_TIMEOUT,
|
|
308
|
+
timeout: parsedTimeout,
|
|
309
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
184
310
|
}
|
|
311
|
+
const config = getConfig();
|
|
312
|
+
config.httpTimeout = parsedTimeout;
|
|
313
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
185
314
|
}
|
|
186
315
|
exports.updateHttpTimeout = updateHttpTimeout;
|
|
187
|
-
function
|
|
188
|
-
if (
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
config_DEPRECATED.updateAllowAutoUpdates(enabled);
|
|
316
|
+
function updateAllowUsageTracking(isAllowed) {
|
|
317
|
+
if (typeof isAllowed !== 'boolean') {
|
|
318
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateAllowUsageTracking.invalidInput', {
|
|
319
|
+
isAllowed: `${isAllowed}`,
|
|
320
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
193
321
|
}
|
|
322
|
+
const config = getConfig();
|
|
323
|
+
config.allowUsageTracking = isAllowed;
|
|
324
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
194
325
|
}
|
|
195
|
-
exports.
|
|
196
|
-
function
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
config_DEPRECATED.updateAllowUsageTracking(isEnabled);
|
|
326
|
+
exports.updateAllowUsageTracking = updateAllowUsageTracking;
|
|
327
|
+
function updateAllowAutoUpdates(isEnabled) {
|
|
328
|
+
if (typeof isEnabled !== 'boolean') {
|
|
329
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateAllowAutoUpdates.invalidInput', {
|
|
330
|
+
isEnabled: `${isEnabled}`,
|
|
331
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
202
332
|
}
|
|
333
|
+
const config = getConfig();
|
|
334
|
+
config.allowAutoUpdates = isEnabled;
|
|
335
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
203
336
|
}
|
|
204
|
-
exports.
|
|
337
|
+
exports.updateAllowAutoUpdates = updateAllowAutoUpdates;
|
|
205
338
|
function updateAutoOpenBrowser(isEnabled) {
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
config_DEPRECATED.updateAutoOpenBrowser(isEnabled);
|
|
339
|
+
if (typeof isEnabled !== 'boolean') {
|
|
340
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateAutoOpenBrowser.invalidInput', {
|
|
341
|
+
isEnabled: `${isEnabled}`,
|
|
342
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
211
343
|
}
|
|
344
|
+
const config = getConfig();
|
|
345
|
+
config.autoOpenBrowser = isEnabled;
|
|
346
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
212
347
|
}
|
|
213
348
|
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
349
|
function updateDefaultCmsPublishMode(cmsPublishMode) {
|
|
273
|
-
if (
|
|
274
|
-
|
|
350
|
+
if (!cmsPublishMode ||
|
|
351
|
+
!Object.values(files_1.CMS_PUBLISH_MODE).includes(cmsPublishMode)) {
|
|
352
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateDefaultCmsPublishMode.invalidCmsPublishMode', {
|
|
353
|
+
cmsPublishMode,
|
|
354
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
275
355
|
}
|
|
276
|
-
|
|
356
|
+
const config = getConfig();
|
|
357
|
+
config.defaultCmsPublishMode = cmsPublishMode;
|
|
358
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
277
359
|
}
|
|
278
360
|
exports.updateDefaultCmsPublishMode = updateDefaultCmsPublishMode;
|
|
279
|
-
function
|
|
280
|
-
|
|
281
|
-
|
|
361
|
+
function isConfigFlagEnabled(flag, defaultValue) {
|
|
362
|
+
const config = getConfig();
|
|
363
|
+
if (typeof config[flag] === 'undefined') {
|
|
364
|
+
return defaultValue || false;
|
|
282
365
|
}
|
|
366
|
+
return Boolean(config[flag]);
|
|
283
367
|
}
|
|
284
|
-
exports.
|
|
285
|
-
function getDefaultAccountOverrideFilePath() {
|
|
286
|
-
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
287
|
-
return CLIConfiguration_1.CLIConfiguration.getDefaultAccountOverrideFilePath();
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
exports.getDefaultAccountOverrideFilePath = getDefaultAccountOverrideFilePath;
|
|
368
|
+
exports.isConfigFlagEnabled = isConfigFlagEnabled;
|
|
291
369
|
function hasLocalStateFlag(flag) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
return config_DEPRECATED.hasLocalStateFlag(flag);
|
|
370
|
+
const config = getConfig();
|
|
371
|
+
return config.flags?.includes(flag) || false;
|
|
296
372
|
}
|
|
297
373
|
exports.hasLocalStateFlag = hasLocalStateFlag;
|
|
298
374
|
function addLocalStateFlag(flag) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
else {
|
|
303
|
-
config_DEPRECATED.addLocalStateFlag(flag);
|
|
375
|
+
const config = getConfig();
|
|
376
|
+
if (!hasLocalStateFlag(flag)) {
|
|
377
|
+
config.flags = [...(config.flags || []), flag];
|
|
304
378
|
}
|
|
379
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
305
380
|
}
|
|
306
381
|
exports.addLocalStateFlag = addLocalStateFlag;
|
|
307
382
|
function removeLocalStateFlag(flag) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
else {
|
|
312
|
-
config_DEPRECATED.removeLocalStateFlag(flag);
|
|
313
|
-
}
|
|
383
|
+
const config = getConfig();
|
|
384
|
+
config.flags = config.flags?.filter(f => f !== flag) || [];
|
|
385
|
+
(0, utils_1.writeConfigFile)(config, getConfigFilePath());
|
|
314
386
|
}
|
|
315
387
|
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;
|