@hubspot/local-dev-lib 0.5.0-experimental.8 → 0.6.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/index.d.ts +6 -4
- package/config/index.js +65 -39
- package/config/migrate.d.ts +1 -0
- package/config/migrate.js +13 -5
- package/config/utils.d.ts +10 -54
- package/config/utils.js +91 -45
- package/constants/config.d.ts +3 -0
- package/constants/config.js +3 -0
- package/lang/en.json +21 -14
- package/lib/personalAccessKey.js +3 -5
- package/models/HubSpotConfigError.d.ts +1 -1
- package/models/HubSpotConfigError.js +7 -2
- package/package.json +4 -4
- package/types/Config.d.ts +4 -0
package/config/index.d.ts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { HubSpotConfigAccount } from '../types/Accounts';
|
|
2
|
-
import { HubSpotConfig, ConfigFlag } from '../types/Config';
|
|
2
|
+
import { HubSpotConfig, ConfigFlag, HubSpotConfigValidationResult } from '../types/Config';
|
|
3
3
|
import { CmsPublishMode } from '../types/Files';
|
|
4
4
|
import { Environment } from '../types/Config';
|
|
5
|
+
export declare function getGlobalConfigFilePath(): string;
|
|
6
|
+
export declare function getLocalConfigFilePathIfExists(): string | null;
|
|
5
7
|
export declare function localConfigFileExists(): boolean;
|
|
6
8
|
export declare function globalConfigFileExists(): boolean;
|
|
7
9
|
export declare function configFileExists(): boolean;
|
|
8
10
|
export declare function getConfigFilePath(): string;
|
|
9
11
|
export declare function getConfig(): HubSpotConfig;
|
|
10
|
-
export declare function
|
|
12
|
+
export declare function validateConfig(): HubSpotConfigValidationResult;
|
|
11
13
|
export declare function createEmptyConfigFile(useGlobalConfig?: boolean): void;
|
|
12
|
-
export declare function
|
|
14
|
+
export declare function deleteConfigFileIfEmpty(): void;
|
|
13
15
|
export declare function getConfigAccountById(accountId: number): HubSpotConfigAccount;
|
|
14
16
|
export declare function getConfigAccountByName(accountName: string): HubSpotConfigAccount;
|
|
15
17
|
export declare function getConfigAccountIfExists(identifier: number | string): HubSpotConfigAccount | undefined;
|
|
16
18
|
export declare function getConfigDefaultAccount(): HubSpotConfigAccount;
|
|
17
19
|
export declare function getConfigDefaultAccountIfExists(): HubSpotConfigAccount | undefined;
|
|
18
20
|
export declare function getAllConfigAccounts(): HubSpotConfigAccount[];
|
|
19
|
-
export declare function getConfigAccountEnvironment(identifier
|
|
21
|
+
export declare function getConfigAccountEnvironment(identifier: number | string): Environment;
|
|
20
22
|
export declare function addConfigAccount(accountToAdd: HubSpotConfigAccount): void;
|
|
21
23
|
export declare function updateConfigAccount(updatedAccount: HubSpotConfigAccount): void;
|
|
22
24
|
export declare function setConfigAccountAsDefault(identifier: number | string): void;
|
package/config/index.js
CHANGED
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.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.
|
|
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
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
8
9
|
const config_1 = require("../constants/config");
|
|
9
10
|
const logger_1 = require("../lib/logger");
|
|
10
11
|
const utils_1 = require("./utils");
|
|
@@ -14,17 +15,31 @@ const defaultAccountOverride_1 = require("./defaultAccountOverride");
|
|
|
14
15
|
const environment_1 = require("../lib/environment");
|
|
15
16
|
const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
|
|
16
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;
|
|
17
32
|
function localConfigFileExists() {
|
|
18
|
-
return Boolean((
|
|
33
|
+
return Boolean(getLocalConfigFilePathIfExists());
|
|
19
34
|
}
|
|
20
35
|
exports.localConfigFileExists = localConfigFileExists;
|
|
21
36
|
function globalConfigFileExists() {
|
|
22
|
-
return
|
|
37
|
+
return (0, utils_1.doesConfigFileExistAtPath)(getGlobalConfigFilePath());
|
|
23
38
|
}
|
|
24
39
|
exports.globalConfigFileExists = globalConfigFileExists;
|
|
25
40
|
function configFileExists() {
|
|
26
41
|
try {
|
|
27
|
-
return
|
|
42
|
+
return (0, utils_1.doesConfigFileExistAtPath)(getConfigFilePath());
|
|
28
43
|
}
|
|
29
44
|
catch (error) {
|
|
30
45
|
return false;
|
|
@@ -32,11 +47,11 @@ function configFileExists() {
|
|
|
32
47
|
}
|
|
33
48
|
exports.configFileExists = configFileExists;
|
|
34
49
|
function getConfigDefaultFilePath() {
|
|
35
|
-
const globalConfigFilePath =
|
|
36
|
-
if (
|
|
50
|
+
const globalConfigFilePath = getGlobalConfigFilePath();
|
|
51
|
+
if ((0, utils_1.doesConfigFileExistAtPath)(globalConfigFilePath)) {
|
|
37
52
|
return globalConfigFilePath;
|
|
38
53
|
}
|
|
39
|
-
const localConfigFilePath = (
|
|
54
|
+
const localConfigFilePath = getLocalConfigFilePathIfExists();
|
|
40
55
|
if (!localConfigFilePath) {
|
|
41
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);
|
|
42
57
|
}
|
|
@@ -66,58 +81,70 @@ function getConfig() {
|
|
|
66
81
|
}
|
|
67
82
|
}
|
|
68
83
|
exports.getConfig = getConfig;
|
|
69
|
-
function
|
|
84
|
+
function validateConfig() {
|
|
70
85
|
const config = getConfig();
|
|
71
86
|
if (config.accounts.length === 0) {
|
|
72
|
-
|
|
73
|
-
|
|
87
|
+
return {
|
|
88
|
+
isValid: false,
|
|
89
|
+
errors: [(0, lang_1.i18n)('config.validateConfig.missingAccounts')],
|
|
90
|
+
};
|
|
74
91
|
}
|
|
75
92
|
const accountIdsMap = {};
|
|
76
93
|
const accountNamesMap = {};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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);
|
|
80
99
|
}
|
|
81
100
|
if (accountIdsMap[account.accountId]) {
|
|
82
|
-
|
|
101
|
+
validationErrors.push((0, lang_1.i18n)('config.validateConfig.duplicateAccountIds', {
|
|
83
102
|
accountId: account.accountId,
|
|
84
103
|
}));
|
|
85
|
-
return false;
|
|
86
104
|
}
|
|
87
105
|
if (account.name) {
|
|
88
106
|
if (accountNamesMap[account.name.toLowerCase()]) {
|
|
89
|
-
|
|
107
|
+
validationErrors.push((0, lang_1.i18n)('config.validateConfig.duplicateAccountNames', {
|
|
90
108
|
accountName: account.name,
|
|
91
109
|
}));
|
|
92
|
-
return false;
|
|
93
110
|
}
|
|
94
111
|
if (/\s+/.test(account.name)) {
|
|
95
|
-
|
|
112
|
+
validationErrors.push((0, lang_1.i18n)('config.validateConfig.invalidAccountName', {
|
|
96
113
|
accountName: account.name,
|
|
97
114
|
}));
|
|
98
|
-
return false;
|
|
99
115
|
}
|
|
100
116
|
accountNamesMap[account.name] = true;
|
|
101
117
|
}
|
|
102
118
|
accountIdsMap[account.accountId] = true;
|
|
103
|
-
return true;
|
|
104
119
|
});
|
|
120
|
+
return { isValid: validationErrors.length === 0, errors: validationErrors };
|
|
105
121
|
}
|
|
106
|
-
exports.
|
|
122
|
+
exports.validateConfig = validateConfig;
|
|
107
123
|
function createEmptyConfigFile(useGlobalConfig = false) {
|
|
108
124
|
const { configFilePathFromEnvironment } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
109
125
|
const defaultPath = useGlobalConfig
|
|
110
|
-
?
|
|
126
|
+
? getGlobalConfigFilePath()
|
|
111
127
|
: (0, utils_1.getLocalConfigDefaultFilePath)();
|
|
112
128
|
const pathToWrite = configFilePathFromEnvironment || defaultPath;
|
|
113
|
-
(0, utils_1.writeConfigFile)(
|
|
129
|
+
(0, utils_1.writeConfigFile)(EMPTY_CONFIG, pathToWrite);
|
|
114
130
|
}
|
|
115
131
|
exports.createEmptyConfigFile = createEmptyConfigFile;
|
|
116
|
-
function
|
|
132
|
+
function deleteConfigFileIfEmpty() {
|
|
117
133
|
const pathToDelete = getConfigFilePath();
|
|
118
|
-
|
|
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,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
119
146
|
}
|
|
120
|
-
exports.
|
|
147
|
+
exports.deleteConfigFileIfEmpty = deleteConfigFileIfEmpty;
|
|
121
148
|
function getConfigAccountById(accountId) {
|
|
122
149
|
const { accounts } = getConfig();
|
|
123
150
|
const account = (0, utils_1.getConfigAccountByIdentifier)(accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountId);
|
|
@@ -145,7 +172,7 @@ function getConfigDefaultAccount() {
|
|
|
145
172
|
const { accounts, defaultAccount } = getConfig();
|
|
146
173
|
let defaultAccountToUse = defaultAccount;
|
|
147
174
|
const currentConfigPath = getConfigFilePath();
|
|
148
|
-
const globalConfigPath =
|
|
175
|
+
const globalConfigPath = getGlobalConfigFilePath();
|
|
149
176
|
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
150
177
|
const defaultAccountOverrideAccountId = (0, defaultAccountOverride_1.getDefaultAccountOverrideAccountId)();
|
|
151
178
|
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
@@ -167,7 +194,7 @@ function getConfigDefaultAccountIfExists() {
|
|
|
167
194
|
let defaultAccountToUse = defaultAccount;
|
|
168
195
|
// Only check for default account override if we're using the global config
|
|
169
196
|
const currentConfigPath = getConfigFilePath();
|
|
170
|
-
const globalConfigPath =
|
|
197
|
+
const globalConfigPath = getGlobalConfigFilePath();
|
|
171
198
|
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
172
199
|
const defaultAccountOverrideAccountId = (0, defaultAccountOverride_1.getDefaultAccountOverrideAccountId)();
|
|
173
200
|
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
@@ -185,19 +212,18 @@ function getAllConfigAccounts() {
|
|
|
185
212
|
}
|
|
186
213
|
exports.getAllConfigAccounts = getAllConfigAccounts;
|
|
187
214
|
function getConfigAccountEnvironment(identifier) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
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);
|
|
194
221
|
}
|
|
195
|
-
|
|
196
|
-
return (0, environment_1.getValidEnv)(defaultAccount.env);
|
|
222
|
+
return (0, environment_1.getValidEnv)(account.env);
|
|
197
223
|
}
|
|
198
224
|
exports.getConfigAccountEnvironment = getConfigAccountEnvironment;
|
|
199
225
|
function addConfigAccount(accountToAdd) {
|
|
200
|
-
if (!(0, utils_1.
|
|
226
|
+
if (!(0, utils_1.validateConfigAccount)(accountToAdd)) {
|
|
201
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);
|
|
202
228
|
}
|
|
203
229
|
const config = getConfig();
|
|
@@ -212,7 +238,7 @@ function addConfigAccount(accountToAdd) {
|
|
|
212
238
|
}
|
|
213
239
|
exports.addConfigAccount = addConfigAccount;
|
|
214
240
|
function updateConfigAccount(updatedAccount) {
|
|
215
|
-
if (!(0, utils_1.
|
|
241
|
+
if (!(0, utils_1.validateConfigAccount)(updatedAccount)) {
|
|
216
242
|
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateConfigAccount.invalidAccount', {
|
|
217
243
|
name: updatedAccount.name,
|
|
218
244
|
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
@@ -233,7 +259,7 @@ function setConfigAccountAsDefault(identifier) {
|
|
|
233
259
|
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
|
|
234
260
|
if (!account) {
|
|
235
261
|
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.setConfigAccountAsDefault.accountNotFound', {
|
|
236
|
-
|
|
262
|
+
identifier,
|
|
237
263
|
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
238
264
|
}
|
|
239
265
|
config.defaultAccount = account.accountId;
|
package/config/migrate.d.ts
CHANGED
package/config/migrate.js
CHANGED
|
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.mergeConfigAccounts = exports.mergeConfigProperties = exports.migrateConfigAtPath = exports.getConfigAtPath = void 0;
|
|
6
|
+
exports.archiveConfigAtPath = exports.mergeConfigAccounts = exports.mergeConfigProperties = exports.migrateConfigAtPath = exports.getConfigAtPath = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const index_1 = require("./index");
|
|
9
9
|
const config_1 = require("../constants/config");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
11
12
|
function getConfigAtPath(path) {
|
|
12
13
|
const configFileSource = (0, utils_1.readConfigFile)(path);
|
|
13
14
|
return (0, utils_1.parseConfig)(configFileSource, path);
|
|
@@ -16,8 +17,7 @@ exports.getConfigAtPath = getConfigAtPath;
|
|
|
16
17
|
function migrateConfigAtPath(path) {
|
|
17
18
|
(0, index_1.createEmptyConfigFile)(true);
|
|
18
19
|
const configToMigrate = getConfigAtPath(path);
|
|
19
|
-
(0, utils_1.writeConfigFile)(configToMigrate, (0,
|
|
20
|
-
fs_1.default.unlinkSync(path);
|
|
20
|
+
(0, utils_1.writeConfigFile)(configToMigrate, (0, index_1.getGlobalConfigFilePath)());
|
|
21
21
|
}
|
|
22
22
|
exports.migrateConfigAtPath = migrateConfigAtPath;
|
|
23
23
|
function mergeConfigProperties(toConfig, fromConfig, force) {
|
|
@@ -64,7 +64,9 @@ function mergeConfigProperties(toConfig, fromConfig, force) {
|
|
|
64
64
|
config_1.DEFAULT_ACCOUNT,
|
|
65
65
|
];
|
|
66
66
|
propertiesToCheck.forEach(prop => {
|
|
67
|
-
if (toConfig[prop] !== undefined &&
|
|
67
|
+
if (toConfig[prop] !== undefined &&
|
|
68
|
+
fromConfig[prop] !== undefined &&
|
|
69
|
+
toConfig[prop] !== fromConfig[prop]) {
|
|
68
70
|
conflicts.push({
|
|
69
71
|
property: prop,
|
|
70
72
|
oldValue: fromConfig[prop],
|
|
@@ -98,7 +100,13 @@ function buildConfigWithMergedAccounts(toConfig, fromConfig) {
|
|
|
98
100
|
}
|
|
99
101
|
function mergeConfigAccounts(toConfig, fromConfig) {
|
|
100
102
|
const { configWithMergedAccounts, skippedAccountIds } = buildConfigWithMergedAccounts(toConfig, fromConfig);
|
|
101
|
-
(0, utils_1.writeConfigFile)(configWithMergedAccounts, (0,
|
|
103
|
+
(0, utils_1.writeConfigFile)(configWithMergedAccounts, (0, index_1.getGlobalConfigFilePath)());
|
|
102
104
|
return { configWithMergedAccounts, skippedAccountIds };
|
|
103
105
|
}
|
|
104
106
|
exports.mergeConfigAccounts = mergeConfigAccounts;
|
|
107
|
+
function archiveConfigAtPath(configPath) {
|
|
108
|
+
const dir = path_1.default.dirname(configPath);
|
|
109
|
+
const archivedConfigPath = path_1.default.join(dir, config_1.ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME);
|
|
110
|
+
fs_1.default.renameSync(configPath, archivedConfigPath);
|
|
111
|
+
}
|
|
112
|
+
exports.archiveConfigAtPath = archiveConfigAtPath;
|
package/config/utils.d.ts
CHANGED
|
@@ -1,67 +1,19 @@
|
|
|
1
1
|
import { ACCOUNT_IDENTIFIERS } from '../constants/config';
|
|
2
|
-
import { HubSpotConfig, DeprecatedHubSpotConfigFields } from '../types/Config';
|
|
3
|
-
import { HubSpotConfigAccount
|
|
2
|
+
import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType, HubSpotConfigValidationResult } from '../types/Config';
|
|
3
|
+
import { HubSpotConfigAccount } from '../types/Accounts';
|
|
4
4
|
import { ValueOf } from '../types/Utils';
|
|
5
|
-
export declare function getGlobalConfigFilePath(): string;
|
|
6
|
-
export declare function getLocalConfigFilePath(): string | null;
|
|
7
5
|
export declare function getLocalConfigDefaultFilePath(): string;
|
|
8
6
|
export declare function getConfigPathEnvironmentVariables(): {
|
|
9
7
|
useEnvironmentConfig: boolean;
|
|
10
8
|
configFilePathFromEnvironment: string | undefined;
|
|
11
9
|
};
|
|
10
|
+
export declare function doesConfigFileExistAtPath(path: string): boolean;
|
|
12
11
|
export declare function readConfigFile(configPath: string): string;
|
|
13
12
|
export declare function removeUndefinedFieldsFromConfigAccount<T extends HubSpotConfigAccount | Partial<HubSpotConfigAccount> = HubSpotConfigAccount>(account: T): T;
|
|
14
|
-
export declare function formatConfigForWrite(config: HubSpotConfig):
|
|
15
|
-
accounts: ({
|
|
16
|
-
personalAccessKey: string;
|
|
17
|
-
auth: {
|
|
18
|
-
tokenInfo: TokenInfo;
|
|
19
|
-
};
|
|
20
|
-
accountType?: AccountType | undefined;
|
|
21
|
-
defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
|
|
22
|
-
parentAccountId?: number | undefined;
|
|
23
|
-
name: string;
|
|
24
|
-
accountId: number;
|
|
25
|
-
env: import("../types/Config").Environment;
|
|
26
|
-
authType: "apikey" | "oauth2" | "personalaccesskey";
|
|
27
|
-
} | {
|
|
28
|
-
auth: {
|
|
29
|
-
clientId: string;
|
|
30
|
-
clientSecret: string;
|
|
31
|
-
scopes: string[];
|
|
32
|
-
tokenInfo: TokenInfo;
|
|
33
|
-
};
|
|
34
|
-
accountType?: AccountType | undefined;
|
|
35
|
-
defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
|
|
36
|
-
parentAccountId?: number | undefined;
|
|
37
|
-
name: string;
|
|
38
|
-
accountId: number;
|
|
39
|
-
env: import("../types/Config").Environment;
|
|
40
|
-
authType: "apikey" | "oauth2" | "personalaccesskey";
|
|
41
|
-
} | {
|
|
42
|
-
apiKey: string;
|
|
43
|
-
accountType?: AccountType | undefined;
|
|
44
|
-
defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
|
|
45
|
-
parentAccountId?: number | undefined;
|
|
46
|
-
name: string;
|
|
47
|
-
accountId: number;
|
|
48
|
-
env: import("../types/Config").Environment;
|
|
49
|
-
authType: "apikey" | "oauth2" | "personalaccesskey";
|
|
50
|
-
})[];
|
|
51
|
-
allowAutoUpdates?: boolean | undefined;
|
|
52
|
-
defaultMode?: import("../types/Files").CmsPublishMode | undefined;
|
|
53
|
-
env?: import("../types/Config").Environment | undefined;
|
|
54
|
-
httpUseLocalhost?: boolean | undefined;
|
|
55
|
-
autoOpenBrowser?: boolean | undefined;
|
|
56
|
-
useCustomObjectHubfile?: boolean | undefined;
|
|
57
|
-
flags?: string[] | undefined;
|
|
58
|
-
defaultCmsPublishMode: import("../types/Files").CmsPublishMode | undefined;
|
|
59
|
-
httpTimeout: number | undefined;
|
|
60
|
-
allowUsageTracking: boolean | undefined;
|
|
61
|
-
defaultAccount?: number | undefined;
|
|
62
|
-
};
|
|
13
|
+
export declare function formatConfigForWrite(config: HubSpotConfig): HubSpotConfig;
|
|
63
14
|
export declare function writeConfigFile(config: HubSpotConfig, configPath: string): void;
|
|
64
15
|
export declare function normalizeParsedConfig(parsedConfig: HubSpotConfig & DeprecatedHubSpotConfigFields): HubSpotConfig;
|
|
16
|
+
export declare function convertToDeprecatedConfig(config: HubSpotConfig): Partial<HubSpotConfig> & Partial<DeprecatedHubSpotConfigFields>;
|
|
65
17
|
export declare function parseConfig(configSource: string, configPath: string): HubSpotConfig;
|
|
66
18
|
export declare function buildConfigFromEnvironment(): HubSpotConfig;
|
|
67
19
|
export declare function getAccountIdentifierAndType(accountIdentifier: string | number): {
|
|
@@ -71,4 +23,8 @@ export declare function getAccountIdentifierAndType(accountIdentifier: string |
|
|
|
71
23
|
export declare function getConfigAccountByIdentifier(accounts: Array<HubSpotConfigAccount>, identifierFieldName: ValueOf<typeof ACCOUNT_IDENTIFIERS>, identifier: string | number): HubSpotConfigAccount | undefined;
|
|
72
24
|
export declare function getConfigAccountByInferredIdentifier(accounts: Array<HubSpotConfigAccount>, accountIdentifier: string | number): HubSpotConfigAccount | undefined;
|
|
73
25
|
export declare function getConfigAccountIndexById(accounts: Array<HubSpotConfigAccount>, id: number): number;
|
|
74
|
-
export declare function
|
|
26
|
+
export declare function validateConfigAccount(account: Partial<HubSpotConfigAccount>): HubSpotConfigValidationResult;
|
|
27
|
+
export declare function handleConfigFileSystemError(error: unknown, path: string): {
|
|
28
|
+
message?: string;
|
|
29
|
+
type: HubSpotConfigErrorType;
|
|
30
|
+
};
|
package/config/utils.js
CHANGED
|
@@ -3,30 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.handleConfigFileSystemError = exports.validateConfigAccount = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = exports.convertToDeprecatedConfig = exports.normalizeParsedConfig = exports.writeConfigFile = exports.formatConfigForWrite = exports.removeUndefinedFieldsFromConfigAccount = exports.readConfigFile = exports.doesConfigFileExistAtPath = exports.getConfigPathEnvironmentVariables = exports.getLocalConfigDefaultFilePath = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
|
-
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
10
9
|
const config_1 = require("../constants/config");
|
|
11
10
|
const auth_1 = require("../constants/auth");
|
|
12
11
|
const FileSystemError_1 = require("../models/FileSystemError");
|
|
13
|
-
const logger_1 = require("../lib/logger");
|
|
14
12
|
const environment_1 = require("../lib/environment");
|
|
15
13
|
const path_1 = require("../lib/path");
|
|
16
14
|
const files_1 = require("../constants/files");
|
|
17
15
|
const lang_1 = require("../utils/lang");
|
|
18
16
|
const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
|
|
19
|
-
function getGlobalConfigFilePath() {
|
|
20
|
-
return config_1.GLOBAL_CONFIG_PATH;
|
|
21
|
-
}
|
|
22
|
-
exports.getGlobalConfigFilePath = getGlobalConfigFilePath;
|
|
23
|
-
function getLocalConfigFilePath() {
|
|
24
|
-
return (0, findup_sync_1.default)([
|
|
25
|
-
config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
26
|
-
config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME.replace('.yml', '.yaml'),
|
|
27
|
-
], { cwd: (0, path_1.getCwd)() });
|
|
28
|
-
}
|
|
29
|
-
exports.getLocalConfigFilePath = getLocalConfigFilePath;
|
|
30
17
|
function getLocalConfigDefaultFilePath() {
|
|
31
18
|
return `${(0, path_1.getCwd)()}/${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}`;
|
|
32
19
|
}
|
|
@@ -44,18 +31,24 @@ function getConfigPathEnvironmentVariables() {
|
|
|
44
31
|
};
|
|
45
32
|
}
|
|
46
33
|
exports.getConfigPathEnvironmentVariables = getConfigPathEnvironmentVariables;
|
|
34
|
+
function doesConfigFileExistAtPath(path) {
|
|
35
|
+
try {
|
|
36
|
+
return fs_extra_1.default.existsSync(path);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
const { message, type } = handleConfigFileSystemError(error, path);
|
|
40
|
+
throw new HubSpotConfigError_1.HubSpotConfigError(message, type, config_1.HUBSPOT_CONFIG_OPERATIONS.READ, { cause: error });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.doesConfigFileExistAtPath = doesConfigFileExistAtPath;
|
|
47
44
|
function readConfigFile(configPath) {
|
|
48
|
-
let source = '';
|
|
49
45
|
try {
|
|
50
|
-
|
|
46
|
+
return fs_extra_1.default.readFileSync(configPath).toString();
|
|
51
47
|
}
|
|
52
48
|
catch (err) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
operation: 'read',
|
|
56
|
-
});
|
|
49
|
+
const { message, type } = handleConfigFileSystemError(err, configPath);
|
|
50
|
+
throw new HubSpotConfigError_1.HubSpotConfigError(message, type, config_1.HUBSPOT_CONFIG_OPERATIONS.READ, { cause: err });
|
|
57
51
|
}
|
|
58
|
-
return source;
|
|
59
52
|
}
|
|
60
53
|
exports.readConfigFile = readConfigFile;
|
|
61
54
|
function removeUndefinedFieldsFromConfigAccount(account) {
|
|
@@ -98,20 +91,26 @@ function formatConfigForWrite(config) {
|
|
|
98
91
|
...rest,
|
|
99
92
|
accounts: accounts.map(account => {
|
|
100
93
|
const { name, accountId, env, authType, ...rest } = account;
|
|
101
|
-
|
|
94
|
+
const orderedAccount = {
|
|
102
95
|
name,
|
|
103
96
|
accountId,
|
|
104
97
|
env,
|
|
105
98
|
authType,
|
|
106
99
|
...rest,
|
|
100
|
+
// using ...rest messes with the typing
|
|
107
101
|
};
|
|
102
|
+
return removeUndefinedFieldsFromConfigAccount(orderedAccount);
|
|
108
103
|
}),
|
|
109
104
|
};
|
|
110
|
-
return
|
|
105
|
+
return orderedConfig;
|
|
111
106
|
}
|
|
112
107
|
exports.formatConfigForWrite = formatConfigForWrite;
|
|
113
108
|
function writeConfigFile(config, configPath) {
|
|
114
|
-
const
|
|
109
|
+
const formattedConfig = formatConfigForWrite(config);
|
|
110
|
+
const configToWrite = configPath == config_1.GLOBAL_CONFIG_PATH
|
|
111
|
+
? formattedConfig
|
|
112
|
+
: convertToDeprecatedConfig(formattedConfig);
|
|
113
|
+
const source = js_yaml_1.default.dump(configToWrite);
|
|
115
114
|
try {
|
|
116
115
|
fs_extra_1.default.ensureFileSync(configPath);
|
|
117
116
|
fs_extra_1.default.writeFileSync(configPath, source);
|
|
@@ -136,6 +135,9 @@ function getAccountType(sandboxAccountType) {
|
|
|
136
135
|
return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD;
|
|
137
136
|
}
|
|
138
137
|
function normalizeParsedConfig(parsedConfig) {
|
|
138
|
+
if (!parsedConfig.portals && !parsedConfig.accounts) {
|
|
139
|
+
parsedConfig.accounts = [];
|
|
140
|
+
}
|
|
139
141
|
if (parsedConfig.portals) {
|
|
140
142
|
parsedConfig.accounts = parsedConfig.portals.map(account => {
|
|
141
143
|
if (account.portalId) {
|
|
@@ -164,6 +166,30 @@ function normalizeParsedConfig(parsedConfig) {
|
|
|
164
166
|
return parsedConfig;
|
|
165
167
|
}
|
|
166
168
|
exports.normalizeParsedConfig = normalizeParsedConfig;
|
|
169
|
+
function convertToDeprecatedConfig(config) {
|
|
170
|
+
const deprecatedConfig = structuredClone(config);
|
|
171
|
+
if (config.defaultAccount) {
|
|
172
|
+
const defaultAccount = getConfigAccountByIdentifier(config.accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, config.defaultAccount);
|
|
173
|
+
if (defaultAccount) {
|
|
174
|
+
deprecatedConfig.defaultPortal = defaultAccount.name;
|
|
175
|
+
delete deprecatedConfig.defaultAccount;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const portals = config.accounts.map(account => {
|
|
179
|
+
if (account.accountId) {
|
|
180
|
+
const deprecatedAccount = structuredClone(account);
|
|
181
|
+
deprecatedAccount.portalId = account.accountId;
|
|
182
|
+
// @ts-expect-error deleting accountId is intential since using deprecated config format
|
|
183
|
+
delete deprecatedAccount.accountId;
|
|
184
|
+
return deprecatedAccount;
|
|
185
|
+
}
|
|
186
|
+
return account;
|
|
187
|
+
});
|
|
188
|
+
deprecatedConfig.portals = portals;
|
|
189
|
+
delete deprecatedConfig.accounts;
|
|
190
|
+
return deprecatedConfig;
|
|
191
|
+
}
|
|
192
|
+
exports.convertToDeprecatedConfig = convertToDeprecatedConfig;
|
|
167
193
|
function parseConfig(configSource, configPath) {
|
|
168
194
|
let parsedYaml;
|
|
169
195
|
try {
|
|
@@ -274,54 +300,74 @@ function getConfigAccountByIdentifier(accounts, identifierFieldName, identifier)
|
|
|
274
300
|
exports.getConfigAccountByIdentifier = getConfigAccountByIdentifier;
|
|
275
301
|
function getConfigAccountByInferredIdentifier(accounts, accountIdentifier) {
|
|
276
302
|
const { identifier, identifierType } = getAccountIdentifierAndType(accountIdentifier);
|
|
277
|
-
|
|
303
|
+
const account = getConfigAccountByIdentifier(accounts, identifierType, identifier);
|
|
304
|
+
if (account) {
|
|
305
|
+
return account;
|
|
306
|
+
}
|
|
307
|
+
// Fallback to handle accounts with numbers as names
|
|
308
|
+
return getConfigAccountByIdentifier(accounts, config_1.ACCOUNT_IDENTIFIERS.NAME, String(accountIdentifier));
|
|
278
309
|
}
|
|
279
310
|
exports.getConfigAccountByInferredIdentifier = getConfigAccountByInferredIdentifier;
|
|
280
311
|
function getConfigAccountIndexById(accounts, id) {
|
|
281
312
|
return accounts.findIndex(account => account.accountId === id);
|
|
282
313
|
}
|
|
283
314
|
exports.getConfigAccountIndexById = getConfigAccountIndexById;
|
|
284
|
-
function
|
|
315
|
+
function validateConfigAccount(account) {
|
|
316
|
+
const validationErrors = [];
|
|
285
317
|
if (!account || typeof account !== 'object') {
|
|
286
|
-
|
|
287
|
-
return false;
|
|
318
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAccount'));
|
|
319
|
+
return { isValid: false, errors: validationErrors };
|
|
288
320
|
}
|
|
289
321
|
if (!account.accountId) {
|
|
290
|
-
|
|
291
|
-
return false;
|
|
322
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAccountId'));
|
|
323
|
+
return { isValid: false, errors: validationErrors };
|
|
292
324
|
}
|
|
293
325
|
if (!account.authType) {
|
|
294
|
-
|
|
326
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAuthType', {
|
|
295
327
|
accountId: account.accountId,
|
|
296
328
|
}));
|
|
297
|
-
return false;
|
|
329
|
+
return { isValid: false, errors: validationErrors };
|
|
298
330
|
}
|
|
299
|
-
let valid = false;
|
|
300
331
|
if (account.authType === auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingPersonalAccessKey', {
|
|
332
|
+
const isValidPersonalAccessKeyAccount = 'personalAccessKey' in account && Boolean(account.personalAccessKey);
|
|
333
|
+
if (!isValidPersonalAccessKeyAccount) {
|
|
334
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingPersonalAccessKey', {
|
|
305
335
|
accountId: account.accountId,
|
|
306
336
|
}));
|
|
307
337
|
}
|
|
308
338
|
}
|
|
309
339
|
if (account.authType === auth_1.OAUTH_AUTH_METHOD.value) {
|
|
310
|
-
|
|
311
|
-
if (!
|
|
312
|
-
|
|
340
|
+
const isValidOAuthAccount = 'auth' in account && Boolean(account.auth);
|
|
341
|
+
if (!isValidOAuthAccount) {
|
|
342
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAuth', {
|
|
313
343
|
accountId: account.accountId,
|
|
314
344
|
}));
|
|
315
345
|
}
|
|
316
346
|
}
|
|
317
347
|
if (account.authType === auth_1.API_KEY_AUTH_METHOD.value) {
|
|
318
|
-
|
|
319
|
-
if (!
|
|
320
|
-
|
|
348
|
+
const isValidAPIKeyAccount = 'apiKey' in account && Boolean(account.apiKey);
|
|
349
|
+
if (!isValidAPIKeyAccount) {
|
|
350
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingApiKey', {
|
|
321
351
|
accountId: account.accountId,
|
|
322
352
|
}));
|
|
323
353
|
}
|
|
324
354
|
}
|
|
325
|
-
return
|
|
355
|
+
return { isValid: validationErrors.length === 0, errors: validationErrors };
|
|
356
|
+
}
|
|
357
|
+
exports.validateConfigAccount = validateConfigAccount;
|
|
358
|
+
function handleConfigFileSystemError(error, path) {
|
|
359
|
+
let message;
|
|
360
|
+
let type = config_1.HUBSPOT_CONFIG_ERROR_TYPES.UNKNOWN;
|
|
361
|
+
if (error instanceof Error && 'code' in error) {
|
|
362
|
+
if (error.code === 'ENOENT') {
|
|
363
|
+
message = (0, lang_1.i18n)('config.utils.handleConfigFileSystemError.configNotFoundError', { path });
|
|
364
|
+
type = config_1.HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND;
|
|
365
|
+
}
|
|
366
|
+
else if (error.code === 'EACCES') {
|
|
367
|
+
message = (0, lang_1.i18n)('config.utils.handleConfigFileSystemError.insufficientPermissionsError', { path });
|
|
368
|
+
type = config_1.HUBSPOT_CONFIG_ERROR_TYPES.INSUFFICIENT_PERMISSIONS;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return { message, type };
|
|
326
372
|
}
|
|
327
|
-
exports.
|
|
373
|
+
exports.handleConfigFileSystemError = handleConfigFileSystemError;
|
package/constants/config.d.ts
CHANGED
|
@@ -59,14 +59,17 @@ export declare const ACCOUNT_IDENTIFIERS: {
|
|
|
59
59
|
};
|
|
60
60
|
export declare const HUBSPOT_CONFIG_ERROR_TYPES: {
|
|
61
61
|
readonly CONFIG_NOT_FOUND: "CONFIG_NOT_FOUND";
|
|
62
|
+
readonly INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS";
|
|
62
63
|
readonly ACCOUNT_NOT_FOUND: "ACCOUNT_NOT_FOUND";
|
|
63
64
|
readonly NO_DEFAULT_ACCOUNT: "NO_DEFAULT_ACCOUNT";
|
|
64
65
|
readonly INVALID_ENVIRONMENT_VARIABLES: "ENVIRONMENT_VARIABLES";
|
|
65
66
|
readonly YAML_PARSING: "YAML_PARSING";
|
|
66
67
|
readonly INVALID_ACCOUNT: "INVALID_ACCOUNT";
|
|
67
68
|
readonly INVALID_FIELD: "INVALID_FIELD";
|
|
69
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
68
70
|
};
|
|
69
71
|
export declare const HUBSPOT_CONFIG_OPERATIONS: {
|
|
70
72
|
readonly READ: "READ";
|
|
71
73
|
readonly WRITE: "WRITE";
|
|
74
|
+
readonly DELETE: "DELETE";
|
|
72
75
|
};
|
package/constants/config.js
CHANGED
|
@@ -68,14 +68,17 @@ exports.ACCOUNT_IDENTIFIERS = {
|
|
|
68
68
|
};
|
|
69
69
|
exports.HUBSPOT_CONFIG_ERROR_TYPES = {
|
|
70
70
|
CONFIG_NOT_FOUND: 'CONFIG_NOT_FOUND',
|
|
71
|
+
INSUFFICIENT_PERMISSIONS: 'INSUFFICIENT_PERMISSIONS',
|
|
71
72
|
ACCOUNT_NOT_FOUND: 'ACCOUNT_NOT_FOUND',
|
|
72
73
|
NO_DEFAULT_ACCOUNT: 'NO_DEFAULT_ACCOUNT',
|
|
73
74
|
INVALID_ENVIRONMENT_VARIABLES: 'ENVIRONMENT_VARIABLES',
|
|
74
75
|
YAML_PARSING: 'YAML_PARSING',
|
|
75
76
|
INVALID_ACCOUNT: 'INVALID_ACCOUNT',
|
|
76
77
|
INVALID_FIELD: 'INVALID_FIELD',
|
|
78
|
+
UNKNOWN: 'UNKNOWN',
|
|
77
79
|
};
|
|
78
80
|
exports.HUBSPOT_CONFIG_OPERATIONS = {
|
|
79
81
|
READ: 'READ',
|
|
80
82
|
WRITE: 'WRITE',
|
|
83
|
+
DELETE: 'DELETE',
|
|
81
84
|
};
|
package/lang/en.json
CHANGED
|
@@ -251,11 +251,11 @@
|
|
|
251
251
|
"error": "No config file found.",
|
|
252
252
|
"errorWithPath": "No config file found at {{ path }}."
|
|
253
253
|
},
|
|
254
|
-
"
|
|
255
|
-
"missingAccounts": "
|
|
256
|
-
"duplicateAccountIds": "
|
|
257
|
-
"duplicateAccountNames": "
|
|
258
|
-
"invalidAccountName": "
|
|
254
|
+
"validateConfig": {
|
|
255
|
+
"missingAccounts": "No accounts found",
|
|
256
|
+
"duplicateAccountIds": "Multiple accounts with accountId: {{ accountId }}",
|
|
257
|
+
"duplicateAccountNames": "Multiple accounts with name: {{ accountName }}",
|
|
258
|
+
"invalidAccountName": "Account name {{ accountName }} contains spaces"
|
|
259
259
|
},
|
|
260
260
|
"getConfigAccountById": {
|
|
261
261
|
"error": "No account with id {{ accountId }} exists in config"
|
|
@@ -276,7 +276,7 @@
|
|
|
276
276
|
"accountNotFound": "Attempting to update account with id {{ id }}, but that account was not found in config"
|
|
277
277
|
},
|
|
278
278
|
"setConfigAccountAsDefault": {
|
|
279
|
-
"accountNotFound": "Attempted to set account with
|
|
279
|
+
"accountNotFound": "Attempted to set account with identifier {{ identifier }} as default, but that account was not found in config"
|
|
280
280
|
},
|
|
281
281
|
"renameConfigAccount": {
|
|
282
282
|
"accountNotFound": "Attempted to rename account with name {{ currentName }}, but that account was not found in config",
|
|
@@ -291,14 +291,21 @@
|
|
|
291
291
|
"updateDefaultCmsPublishMode": {
|
|
292
292
|
"invalidCmsPublishMode": "Error updating config default CMS publish mode: CMS publish can only be set to 'draft' or 'publish'"
|
|
293
293
|
},
|
|
294
|
+
"getConfigAccountEnvironment": {
|
|
295
|
+
"accountNotFound": "Attempted to get environment for account with identifier {{ identifier }}, but that account was not found in config"
|
|
296
|
+
},
|
|
294
297
|
"utils": {
|
|
295
|
-
"
|
|
296
|
-
"
|
|
297
|
-
"
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
"
|
|
301
|
-
"
|
|
298
|
+
"handleConfigFileSystemError": {
|
|
299
|
+
"configNotFoundError": "No config file found at {{ path }}.",
|
|
300
|
+
"insufficientPermissionsError": "Insufficient permissions to access config file at {{ path }}"
|
|
301
|
+
},
|
|
302
|
+
"validateConfigAccount": {
|
|
303
|
+
"missingAccount": "At least one account in config is missing data",
|
|
304
|
+
"missingAuthType": "Account {{ accountId }} has no authType",
|
|
305
|
+
"missingAccountId": "At least one account in config is missing accountId",
|
|
306
|
+
"missingApiKey": "Account {{ accountId }} has authType of apikey but is missing the apiKey field",
|
|
307
|
+
"missingAuth": "Account {{ accountId }} has authtype of oauth2 but is missing auth data",
|
|
308
|
+
"missingPersonalAccessKey": "Account {{ accountId }} has authType of personalAccessKey but is missing the personalAccessKey field"
|
|
302
309
|
},
|
|
303
310
|
"getConfigPathEnvironmentVariables": {
|
|
304
311
|
"invalidEnvironmentVariables": "USE_ENVIRONMENT_HUBSPOT_CONFIG and HUBSPOT_CONFIG_PATH cannot both be set simultaneously"
|
|
@@ -382,7 +389,7 @@
|
|
|
382
389
|
}
|
|
383
390
|
},
|
|
384
391
|
"HubSpotConfigError": {
|
|
385
|
-
"baseMessage": "An error occurred while {{ operation }} your HubSpot config {{ configType }}
|
|
392
|
+
"baseMessage": "An error occurred while {{ operation }} your HubSpot config {{ configType }}{{ message }}"
|
|
386
393
|
}
|
|
387
394
|
},
|
|
388
395
|
"utils": {
|
package/lib/personalAccessKey.js
CHANGED
|
@@ -121,9 +121,7 @@ async function authorizedScopesForPortalAndUser(accountId) {
|
|
|
121
121
|
exports.authorizedScopesForPortalAndUser = authorizedScopesForPortalAndUser;
|
|
122
122
|
async function updateConfigWithAccessToken(token, personalAccessKey, env, name, makeDefault = false) {
|
|
123
123
|
const { portalId, accessToken, expiresAt, accountType } = token;
|
|
124
|
-
const account =
|
|
125
|
-
? (0, config_1.getConfigAccountIfExists)(name)
|
|
126
|
-
: (0, config_1.getConfigDefaultAccountIfExists)();
|
|
124
|
+
const account = (0, config_1.getConfigAccountIfExists)(portalId);
|
|
127
125
|
const accountEnv = env || account?.env || environments_1.ENVIRONMENTS.PROD;
|
|
128
126
|
let parentAccountId;
|
|
129
127
|
try {
|
|
@@ -161,12 +159,12 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
|
|
|
161
159
|
accountId: portalId,
|
|
162
160
|
accountType,
|
|
163
161
|
personalAccessKey,
|
|
164
|
-
name: name || account?.name
|
|
162
|
+
name: name || account?.name,
|
|
165
163
|
authType: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
166
164
|
auth: { tokenInfo: { accessToken, expiresAt } },
|
|
167
165
|
parentAccountId,
|
|
168
166
|
env: accountEnv,
|
|
169
|
-
};
|
|
167
|
+
}; // Account may temporarily not have a name before prompted to add one in the CLI
|
|
170
168
|
// Add new account if it doesn't exist, otherwise update existing account
|
|
171
169
|
if (account) {
|
|
172
170
|
(0, config_1.updateConfigAccount)(updatedAccount);
|
|
@@ -2,5 +2,5 @@ import { HubSpotConfigErrorType, HubSpotConfigOperation } from '../types/Config'
|
|
|
2
2
|
export declare class HubSpotConfigError extends Error {
|
|
3
3
|
type: HubSpotConfigErrorType;
|
|
4
4
|
operation: HubSpotConfigOperation;
|
|
5
|
-
constructor(message: string, type: HubSpotConfigErrorType, operation: HubSpotConfigOperation, options?: ErrorOptions);
|
|
5
|
+
constructor(message: string | undefined, type: HubSpotConfigErrorType, operation: HubSpotConfigOperation, options?: ErrorOptions);
|
|
6
6
|
}
|
|
@@ -4,6 +4,11 @@ exports.HubSpotConfigError = void 0;
|
|
|
4
4
|
const config_1 = require("../constants/config");
|
|
5
5
|
const lang_1 = require("../utils/lang");
|
|
6
6
|
const NAME = 'HubSpotConfigError';
|
|
7
|
+
const OPERATION_TEXT = {
|
|
8
|
+
[config_1.HUBSPOT_CONFIG_OPERATIONS.READ]: 'reading',
|
|
9
|
+
[config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE]: 'writing to',
|
|
10
|
+
[config_1.HUBSPOT_CONFIG_OPERATIONS.DELETE]: 'deleting',
|
|
11
|
+
};
|
|
7
12
|
function isEnvironmentError(type) {
|
|
8
13
|
return type === config_1.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES;
|
|
9
14
|
}
|
|
@@ -14,10 +19,10 @@ class HubSpotConfigError extends Error {
|
|
|
14
19
|
const configType = isEnvironmentError(type)
|
|
15
20
|
? 'environment variables'
|
|
16
21
|
: 'file';
|
|
17
|
-
const operationText = operation
|
|
22
|
+
const operationText = OPERATION_TEXT[operation];
|
|
18
23
|
const withBaseMessage = (0, lang_1.i18n)('models.HubSpotConfigError.baseMessage', {
|
|
19
24
|
configType,
|
|
20
|
-
message,
|
|
25
|
+
message: message ? `: ${message}` : '',
|
|
21
26
|
operation: operationText,
|
|
22
27
|
});
|
|
23
28
|
super(withBaseMessage, options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/local-dev-lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-experimental.0",
|
|
4
4
|
"description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "
|
|
14
|
+
"build": "tsx ./scripts/build.ts",
|
|
15
15
|
"lint": "eslint --max-warnings=0 . && prettier . --check",
|
|
16
16
|
"local-dev": "yarn build && cd dist && yarn link && cd .. && tsc --watch --rootDir . --outdir dist",
|
|
17
17
|
"prettier:write": "prettier . --write",
|
|
18
|
-
"release": "
|
|
18
|
+
"release": "tsx ./scripts/release.ts release",
|
|
19
19
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ./node_modules/.bin/jest"
|
|
20
20
|
},
|
|
21
21
|
"license": "Apache-2.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"jest": "^29.5.0",
|
|
40
40
|
"open": "^8.4.2",
|
|
41
41
|
"ts-jest": "^29.0.5",
|
|
42
|
-
"
|
|
42
|
+
"tsx": "^4.20.6",
|
|
43
43
|
"typescript": "^4.9.5",
|
|
44
44
|
"yargs": "^17.7.2"
|
|
45
45
|
},
|
package/types/Config.d.ts
CHANGED
|
@@ -34,3 +34,7 @@ export type HubSpotState = {
|
|
|
34
34
|
};
|
|
35
35
|
export type HubSpotConfigErrorType = ValueOf<typeof HUBSPOT_CONFIG_ERROR_TYPES>;
|
|
36
36
|
export type HubSpotConfigOperation = ValueOf<typeof HUBSPOT_CONFIG_OPERATIONS>;
|
|
37
|
+
export type HubSpotConfigValidationResult = {
|
|
38
|
+
isValid: boolean;
|
|
39
|
+
errors: Array<string>;
|
|
40
|
+
};
|