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