@hubspot/local-dev-lib 0.5.0-experimental.11 → 0.5.0-experimental.13
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 +2 -2
- package/config/index.js +18 -17
- package/config/migrate.js +3 -1
- package/config/utils.d.ts +2 -2
- package/config/utils.js +20 -22
- package/lang/en.json +12 -12
- package/lib/personalAccessKey.js +2 -2
- package/package.json +1 -1
- package/types/Config.d.ts +4 -0
package/config/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
5
|
export declare function getGlobalConfigFilePath(): string;
|
|
@@ -9,7 +9,7 @@ export declare function globalConfigFileExists(): boolean;
|
|
|
9
9
|
export declare function configFileExists(): boolean;
|
|
10
10
|
export declare function getConfigFilePath(): string;
|
|
11
11
|
export declare function getConfig(): HubSpotConfig;
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function validateConfig(): HubSpotConfigValidationResult;
|
|
13
13
|
export declare function createEmptyConfigFile(useGlobalConfig?: boolean): void;
|
|
14
14
|
export declare function deleteConfigFileIfEmpty(): void;
|
|
15
15
|
export declare function getConfigAccountById(accountId: number): HubSpotConfigAccount;
|
package/config/index.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.deleteConfigFileIfEmpty = exports.createEmptyConfigFile = 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
8
|
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
9
9
|
const config_1 = require("../constants/config");
|
|
@@ -81,44 +81,45 @@ function getConfig() {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
exports.getConfig = getConfig;
|
|
84
|
-
function
|
|
84
|
+
function validateConfig() {
|
|
85
85
|
const config = getConfig();
|
|
86
86
|
if (config.accounts.length === 0) {
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
return {
|
|
88
|
+
isValid: false,
|
|
89
|
+
errors: [(0, lang_1.i18n)('config.validateConfig.missingAccounts')],
|
|
90
|
+
};
|
|
89
91
|
}
|
|
90
92
|
const accountIdsMap = {};
|
|
91
93
|
const accountNamesMap = {};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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);
|
|
95
99
|
}
|
|
96
100
|
if (accountIdsMap[account.accountId]) {
|
|
97
|
-
|
|
101
|
+
validationErrors.push((0, lang_1.i18n)('config.validateConfig.duplicateAccountIds', {
|
|
98
102
|
accountId: account.accountId,
|
|
99
103
|
}));
|
|
100
|
-
return false;
|
|
101
104
|
}
|
|
102
105
|
if (account.name) {
|
|
103
106
|
if (accountNamesMap[account.name.toLowerCase()]) {
|
|
104
|
-
logger_1.logger.debug((0, lang_1.i18n)('config.
|
|
107
|
+
logger_1.logger.debug((0, lang_1.i18n)('config.validateConfig.duplicateAccountNames', {
|
|
105
108
|
accountName: account.name,
|
|
106
109
|
}));
|
|
107
|
-
return false;
|
|
108
110
|
}
|
|
109
111
|
if (/\s+/.test(account.name)) {
|
|
110
|
-
logger_1.logger.debug((0, lang_1.i18n)('config.
|
|
112
|
+
logger_1.logger.debug((0, lang_1.i18n)('config.validateConfig.invalidAccountName', {
|
|
111
113
|
accountName: account.name,
|
|
112
114
|
}));
|
|
113
|
-
return false;
|
|
114
115
|
}
|
|
115
116
|
accountNamesMap[account.name] = true;
|
|
116
117
|
}
|
|
117
118
|
accountIdsMap[account.accountId] = true;
|
|
118
|
-
return true;
|
|
119
119
|
});
|
|
120
|
+
return { isValid: validationErrors.length === 0, errors: validationErrors };
|
|
120
121
|
}
|
|
121
|
-
exports.
|
|
122
|
+
exports.validateConfig = validateConfig;
|
|
122
123
|
function createEmptyConfigFile(useGlobalConfig = false) {
|
|
123
124
|
const { configFilePathFromEnvironment } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
124
125
|
const defaultPath = useGlobalConfig
|
|
@@ -222,7 +223,7 @@ function getConfigAccountEnvironment(identifier) {
|
|
|
222
223
|
}
|
|
223
224
|
exports.getConfigAccountEnvironment = getConfigAccountEnvironment;
|
|
224
225
|
function addConfigAccount(accountToAdd) {
|
|
225
|
-
if (!(0, utils_1.
|
|
226
|
+
if (!(0, utils_1.validateConfigAccount)(accountToAdd)) {
|
|
226
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);
|
|
227
228
|
}
|
|
228
229
|
const config = getConfig();
|
|
@@ -237,7 +238,7 @@ function addConfigAccount(accountToAdd) {
|
|
|
237
238
|
}
|
|
238
239
|
exports.addConfigAccount = addConfigAccount;
|
|
239
240
|
function updateConfigAccount(updatedAccount) {
|
|
240
|
-
if (!(0, utils_1.
|
|
241
|
+
if (!(0, utils_1.validateConfigAccount)(updatedAccount)) {
|
|
241
242
|
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateConfigAccount.invalidAccount', {
|
|
242
243
|
name: updatedAccount.name,
|
|
243
244
|
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
package/config/migrate.js
CHANGED
|
@@ -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],
|
package/config/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ACCOUNT_IDENTIFIERS } from '../constants/config';
|
|
2
|
-
import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType } from '../types/Config';
|
|
2
|
+
import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType, HubSpotConfigValidationResult } from '../types/Config';
|
|
3
3
|
import { HubSpotConfigAccount, AccountType, TokenInfo } from '../types/Accounts';
|
|
4
4
|
import { ValueOf } from '../types/Utils';
|
|
5
5
|
export declare function getLocalConfigDefaultFilePath(): string;
|
|
@@ -70,7 +70,7 @@ export declare function getAccountIdentifierAndType(accountIdentifier: string |
|
|
|
70
70
|
export declare function getConfigAccountByIdentifier(accounts: Array<HubSpotConfigAccount>, identifierFieldName: ValueOf<typeof ACCOUNT_IDENTIFIERS>, identifier: string | number): HubSpotConfigAccount | undefined;
|
|
71
71
|
export declare function getConfigAccountByInferredIdentifier(accounts: Array<HubSpotConfigAccount>, accountIdentifier: string | number): HubSpotConfigAccount | undefined;
|
|
72
72
|
export declare function getConfigAccountIndexById(accounts: Array<HubSpotConfigAccount>, id: number): number;
|
|
73
|
-
export declare function
|
|
73
|
+
export declare function validateConfigAccount(account: Partial<HubSpotConfigAccount>): HubSpotConfigValidationResult;
|
|
74
74
|
export declare function handleConfigFileSystemError(error: unknown, path: string): {
|
|
75
75
|
message?: string;
|
|
76
76
|
type: HubSpotConfigErrorType;
|
package/config/utils.js
CHANGED
|
@@ -3,13 +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.handleConfigFileSystemError = exports.
|
|
6
|
+
exports.handleConfigFileSystemError = exports.validateConfigAccount = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = 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
9
|
const config_1 = require("../constants/config");
|
|
10
10
|
const auth_1 = require("../constants/auth");
|
|
11
11
|
const FileSystemError_1 = require("../models/FileSystemError");
|
|
12
|
-
const logger_1 = require("../lib/logger");
|
|
13
12
|
const environment_1 = require("../lib/environment");
|
|
14
13
|
const path_1 = require("../lib/path");
|
|
15
14
|
const files_1 = require("../constants/files");
|
|
@@ -278,50 +277,49 @@ function getConfigAccountIndexById(accounts, id) {
|
|
|
278
277
|
return accounts.findIndex(account => account.accountId === id);
|
|
279
278
|
}
|
|
280
279
|
exports.getConfigAccountIndexById = getConfigAccountIndexById;
|
|
281
|
-
function
|
|
280
|
+
function validateConfigAccount(account) {
|
|
281
|
+
const validationErrors = [];
|
|
282
282
|
if (!account || typeof account !== 'object') {
|
|
283
|
-
|
|
284
|
-
return false;
|
|
283
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAccount'));
|
|
284
|
+
return { isValid: false, errors: validationErrors };
|
|
285
285
|
}
|
|
286
286
|
if (!account.accountId) {
|
|
287
|
-
|
|
288
|
-
return false;
|
|
287
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAccountId'));
|
|
288
|
+
return { isValid: false, errors: validationErrors };
|
|
289
289
|
}
|
|
290
290
|
if (!account.authType) {
|
|
291
|
-
|
|
291
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAuthType', {
|
|
292
292
|
accountId: account.accountId,
|
|
293
293
|
}));
|
|
294
|
-
return false;
|
|
294
|
+
return { isValid: false, errors: validationErrors };
|
|
295
295
|
}
|
|
296
|
-
let valid = false;
|
|
297
296
|
if (account.authType === auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
logger_1.logger.debug((0, lang_1.i18n)('config.utils.isConfigAccountValid.missingPersonalAccessKey', {
|
|
297
|
+
const isValidPersonalAccessKeyAccount = 'personalAccessKey' in account && Boolean(account.personalAccessKey);
|
|
298
|
+
if (!isValidPersonalAccessKeyAccount) {
|
|
299
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingPersonalAccessKey', {
|
|
302
300
|
accountId: account.accountId,
|
|
303
301
|
}));
|
|
304
302
|
}
|
|
305
303
|
}
|
|
306
304
|
if (account.authType === auth_1.OAUTH_AUTH_METHOD.value) {
|
|
307
|
-
|
|
308
|
-
if (!
|
|
309
|
-
|
|
305
|
+
const isValidOAuthAccount = 'auth' in account && Boolean(account.auth);
|
|
306
|
+
if (!isValidOAuthAccount) {
|
|
307
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAuth', {
|
|
310
308
|
accountId: account.accountId,
|
|
311
309
|
}));
|
|
312
310
|
}
|
|
313
311
|
}
|
|
314
312
|
if (account.authType === auth_1.API_KEY_AUTH_METHOD.value) {
|
|
315
|
-
|
|
316
|
-
if (!
|
|
317
|
-
|
|
313
|
+
const isValidAPIKeyAccount = 'apiKey' in account && Boolean(account.apiKey);
|
|
314
|
+
if (!isValidAPIKeyAccount) {
|
|
315
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingApiKey', {
|
|
318
316
|
accountId: account.accountId,
|
|
319
317
|
}));
|
|
320
318
|
}
|
|
321
319
|
}
|
|
322
|
-
return
|
|
320
|
+
return { isValid: validationErrors.length === 0, errors: validationErrors };
|
|
323
321
|
}
|
|
324
|
-
exports.
|
|
322
|
+
exports.validateConfigAccount = validateConfigAccount;
|
|
325
323
|
function handleConfigFileSystemError(error, path) {
|
|
326
324
|
let message;
|
|
327
325
|
let type = config_1.HUBSPOT_CONFIG_ERROR_TYPES.UNKNOWN;
|
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"
|
|
@@ -299,13 +299,13 @@
|
|
|
299
299
|
"configNotFoundError": "No config file found at {{ path }}.",
|
|
300
300
|
"insufficientPermissionsError": "Insufficient permissions to access config file at {{ path }}"
|
|
301
301
|
},
|
|
302
|
-
"
|
|
303
|
-
"missingAccount": "
|
|
304
|
-
"missingAuthType": "
|
|
305
|
-
"missingAccountId": "
|
|
306
|
-
"missingApiKey": "
|
|
307
|
-
"missingAuth": "
|
|
308
|
-
"missingPersonalAccessKey": "
|
|
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"
|
|
309
309
|
},
|
|
310
310
|
"getConfigPathEnvironmentVariables": {
|
|
311
311
|
"invalidEnvironmentVariables": "USE_ENVIRONMENT_HUBSPOT_CONFIG and HUBSPOT_CONFIG_PATH cannot both be set simultaneously"
|
package/lib/personalAccessKey.js
CHANGED
|
@@ -159,12 +159,12 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
|
|
|
159
159
|
accountId: portalId,
|
|
160
160
|
accountType,
|
|
161
161
|
personalAccessKey,
|
|
162
|
-
name: name || account?.name
|
|
162
|
+
name: name || account?.name,
|
|
163
163
|
authType: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
164
164
|
auth: { tokenInfo: { accessToken, expiresAt } },
|
|
165
165
|
parentAccountId,
|
|
166
166
|
env: accountEnv,
|
|
167
|
-
};
|
|
167
|
+
}; // Account may temporarily not have a name before prompted to add one in the CLI
|
|
168
168
|
// Add new account if it doesn't exist, otherwise update existing account
|
|
169
169
|
if (account) {
|
|
170
170
|
(0, config_1.updateConfigAccount)(updatedAccount);
|
package/package.json
CHANGED
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
|
+
};
|