@hubspot/local-dev-lib 0.5.0-experimental.9 → 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 +5 -3
- package/config/index.js +48 -29
- package/config/migrate.d.ts +1 -0
- package/config/migrate.js +13 -5
- package/config/utils.d.ts +5 -54
- package/config/utils.js +59 -38
- package/lang/en.json +13 -13
- package/lib/personalAccessKey.js +3 -3
- package/package.json +4 -4
- package/types/Config.d.ts +4 -0
package/config/index.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
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;
|
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,12 +15,26 @@ 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 (0, utils_1.doesConfigFileExistAtPath)(
|
|
37
|
+
return (0, utils_1.doesConfigFileExistAtPath)(getGlobalConfigFilePath());
|
|
23
38
|
}
|
|
24
39
|
exports.globalConfigFileExists = globalConfigFileExists;
|
|
25
40
|
function configFileExists() {
|
|
@@ -32,11 +47,11 @@ function configFileExists() {
|
|
|
32
47
|
}
|
|
33
48
|
exports.configFileExists = configFileExists;
|
|
34
49
|
function getConfigDefaultFilePath() {
|
|
35
|
-
const globalConfigFilePath =
|
|
50
|
+
const globalConfigFilePath = getGlobalConfigFilePath();
|
|
36
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,57 +81,61 @@ 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 {
|
|
119
|
-
|
|
135
|
+
const config = getConfig();
|
|
136
|
+
if ((0, isDeepEqual_1.isDeepEqual)(config, EMPTY_CONFIG)) {
|
|
137
|
+
fs_extra_1.default.unlinkSync(pathToDelete);
|
|
138
|
+
}
|
|
120
139
|
}
|
|
121
140
|
catch (error) {
|
|
122
141
|
const { message, type } = (0, utils_1.handleConfigFileSystemError)(error, pathToDelete);
|
|
@@ -125,7 +144,7 @@ function deleteConfigFile() {
|
|
|
125
144
|
});
|
|
126
145
|
}
|
|
127
146
|
}
|
|
128
|
-
exports.
|
|
147
|
+
exports.deleteConfigFileIfEmpty = deleteConfigFileIfEmpty;
|
|
129
148
|
function getConfigAccountById(accountId) {
|
|
130
149
|
const { accounts } = getConfig();
|
|
131
150
|
const account = (0, utils_1.getConfigAccountByIdentifier)(accounts, config_1.ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountId);
|
|
@@ -153,7 +172,7 @@ function getConfigDefaultAccount() {
|
|
|
153
172
|
const { accounts, defaultAccount } = getConfig();
|
|
154
173
|
let defaultAccountToUse = defaultAccount;
|
|
155
174
|
const currentConfigPath = getConfigFilePath();
|
|
156
|
-
const globalConfigPath =
|
|
175
|
+
const globalConfigPath = getGlobalConfigFilePath();
|
|
157
176
|
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
158
177
|
const defaultAccountOverrideAccountId = (0, defaultAccountOverride_1.getDefaultAccountOverrideAccountId)();
|
|
159
178
|
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
@@ -175,7 +194,7 @@ function getConfigDefaultAccountIfExists() {
|
|
|
175
194
|
let defaultAccountToUse = defaultAccount;
|
|
176
195
|
// Only check for default account override if we're using the global config
|
|
177
196
|
const currentConfigPath = getConfigFilePath();
|
|
178
|
-
const globalConfigPath =
|
|
197
|
+
const globalConfigPath = getGlobalConfigFilePath();
|
|
179
198
|
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
180
199
|
const defaultAccountOverrideAccountId = (0, defaultAccountOverride_1.getDefaultAccountOverrideAccountId)();
|
|
181
200
|
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
@@ -204,7 +223,7 @@ function getConfigAccountEnvironment(identifier) {
|
|
|
204
223
|
}
|
|
205
224
|
exports.getConfigAccountEnvironment = getConfigAccountEnvironment;
|
|
206
225
|
function addConfigAccount(accountToAdd) {
|
|
207
|
-
if (!(0, utils_1.
|
|
226
|
+
if (!(0, utils_1.validateConfigAccount)(accountToAdd)) {
|
|
208
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);
|
|
209
228
|
}
|
|
210
229
|
const config = getConfig();
|
|
@@ -219,7 +238,7 @@ function addConfigAccount(accountToAdd) {
|
|
|
219
238
|
}
|
|
220
239
|
exports.addConfigAccount = addConfigAccount;
|
|
221
240
|
function updateConfigAccount(updatedAccount) {
|
|
222
|
-
if (!(0, utils_1.
|
|
241
|
+
if (!(0, utils_1.validateConfigAccount)(updatedAccount)) {
|
|
223
242
|
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.updateConfigAccount.invalidAccount', {
|
|
224
243
|
name: updatedAccount.name,
|
|
225
244
|
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
@@ -240,7 +259,7 @@ function setConfigAccountAsDefault(identifier) {
|
|
|
240
259
|
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
|
|
241
260
|
if (!account) {
|
|
242
261
|
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.setConfigAccountAsDefault.accountNotFound', {
|
|
243
|
-
|
|
262
|
+
identifier,
|
|
244
263
|
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
245
264
|
}
|
|
246
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,9 +1,7 @@
|
|
|
1
1
|
import { ACCOUNT_IDENTIFIERS } from '../constants/config';
|
|
2
|
-
import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType } 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;
|
|
@@ -12,57 +10,10 @@ export declare function getConfigPathEnvironmentVariables(): {
|
|
|
12
10
|
export declare function doesConfigFileExistAtPath(path: string): boolean;
|
|
13
11
|
export declare function readConfigFile(configPath: string): string;
|
|
14
12
|
export declare function removeUndefinedFieldsFromConfigAccount<T extends HubSpotConfigAccount | Partial<HubSpotConfigAccount> = HubSpotConfigAccount>(account: T): T;
|
|
15
|
-
export declare function formatConfigForWrite(config: HubSpotConfig):
|
|
16
|
-
accounts: ({
|
|
17
|
-
personalAccessKey: string;
|
|
18
|
-
auth: {
|
|
19
|
-
tokenInfo: TokenInfo;
|
|
20
|
-
};
|
|
21
|
-
accountType?: AccountType | undefined;
|
|
22
|
-
defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
|
|
23
|
-
parentAccountId?: number | undefined;
|
|
24
|
-
name: string;
|
|
25
|
-
accountId: number;
|
|
26
|
-
env: import("../types/Config").Environment;
|
|
27
|
-
authType: "apikey" | "oauth2" | "personalaccesskey";
|
|
28
|
-
} | {
|
|
29
|
-
auth: {
|
|
30
|
-
clientId: string;
|
|
31
|
-
clientSecret: string;
|
|
32
|
-
scopes: string[];
|
|
33
|
-
tokenInfo: TokenInfo;
|
|
34
|
-
};
|
|
35
|
-
accountType?: AccountType | undefined;
|
|
36
|
-
defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
|
|
37
|
-
parentAccountId?: number | undefined;
|
|
38
|
-
name: string;
|
|
39
|
-
accountId: number;
|
|
40
|
-
env: import("../types/Config").Environment;
|
|
41
|
-
authType: "apikey" | "oauth2" | "personalaccesskey";
|
|
42
|
-
} | {
|
|
43
|
-
apiKey: string;
|
|
44
|
-
accountType?: AccountType | undefined;
|
|
45
|
-
defaultCmsPublishMode?: import("../types/Files").CmsPublishMode | undefined;
|
|
46
|
-
parentAccountId?: number | undefined;
|
|
47
|
-
name: string;
|
|
48
|
-
accountId: number;
|
|
49
|
-
env: import("../types/Config").Environment;
|
|
50
|
-
authType: "apikey" | "oauth2" | "personalaccesskey";
|
|
51
|
-
})[];
|
|
52
|
-
allowAutoUpdates?: boolean | undefined;
|
|
53
|
-
defaultMode?: import("../types/Files").CmsPublishMode | undefined;
|
|
54
|
-
env?: import("../types/Config").Environment | undefined;
|
|
55
|
-
httpUseLocalhost?: boolean | undefined;
|
|
56
|
-
autoOpenBrowser?: boolean | undefined;
|
|
57
|
-
useCustomObjectHubfile?: boolean | undefined;
|
|
58
|
-
flags?: string[] | undefined;
|
|
59
|
-
defaultCmsPublishMode: import("../types/Files").CmsPublishMode | undefined;
|
|
60
|
-
httpTimeout: number | undefined;
|
|
61
|
-
allowUsageTracking: boolean | undefined;
|
|
62
|
-
defaultAccount?: number | undefined;
|
|
63
|
-
};
|
|
13
|
+
export declare function formatConfigForWrite(config: HubSpotConfig): HubSpotConfig;
|
|
64
14
|
export declare function writeConfigFile(config: HubSpotConfig, configPath: string): void;
|
|
65
15
|
export declare function normalizeParsedConfig(parsedConfig: HubSpotConfig & DeprecatedHubSpotConfigFields): HubSpotConfig;
|
|
16
|
+
export declare function convertToDeprecatedConfig(config: HubSpotConfig): Partial<HubSpotConfig> & Partial<DeprecatedHubSpotConfigFields>;
|
|
66
17
|
export declare function parseConfig(configSource: string, configPath: string): HubSpotConfig;
|
|
67
18
|
export declare function buildConfigFromEnvironment(): HubSpotConfig;
|
|
68
19
|
export declare function getAccountIdentifierAndType(accountIdentifier: string | number): {
|
|
@@ -72,7 +23,7 @@ export declare function getAccountIdentifierAndType(accountIdentifier: string |
|
|
|
72
23
|
export declare function getConfigAccountByIdentifier(accounts: Array<HubSpotConfigAccount>, identifierFieldName: ValueOf<typeof ACCOUNT_IDENTIFIERS>, identifier: string | number): HubSpotConfigAccount | undefined;
|
|
73
24
|
export declare function getConfigAccountByInferredIdentifier(accounts: Array<HubSpotConfigAccount>, accountIdentifier: string | number): HubSpotConfigAccount | undefined;
|
|
74
25
|
export declare function getConfigAccountIndexById(accounts: Array<HubSpotConfigAccount>, id: number): number;
|
|
75
|
-
export declare function
|
|
26
|
+
export declare function validateConfigAccount(account: Partial<HubSpotConfigAccount>): HubSpotConfigValidationResult;
|
|
76
27
|
export declare function handleConfigFileSystemError(error: unknown, path: string): {
|
|
77
28
|
message?: string;
|
|
78
29
|
type: HubSpotConfigErrorType;
|
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.handleConfigFileSystemError = 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
|
}
|
|
@@ -104,20 +91,26 @@ function formatConfigForWrite(config) {
|
|
|
104
91
|
...rest,
|
|
105
92
|
accounts: accounts.map(account => {
|
|
106
93
|
const { name, accountId, env, authType, ...rest } = account;
|
|
107
|
-
|
|
94
|
+
const orderedAccount = {
|
|
108
95
|
name,
|
|
109
96
|
accountId,
|
|
110
97
|
env,
|
|
111
98
|
authType,
|
|
112
99
|
...rest,
|
|
100
|
+
// using ...rest messes with the typing
|
|
113
101
|
};
|
|
102
|
+
return removeUndefinedFieldsFromConfigAccount(orderedAccount);
|
|
114
103
|
}),
|
|
115
104
|
};
|
|
116
|
-
return
|
|
105
|
+
return orderedConfig;
|
|
117
106
|
}
|
|
118
107
|
exports.formatConfigForWrite = formatConfigForWrite;
|
|
119
108
|
function writeConfigFile(config, configPath) {
|
|
120
|
-
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);
|
|
121
114
|
try {
|
|
122
115
|
fs_extra_1.default.ensureFileSync(configPath);
|
|
123
116
|
fs_extra_1.default.writeFileSync(configPath, source);
|
|
@@ -173,6 +166,30 @@ function normalizeParsedConfig(parsedConfig) {
|
|
|
173
166
|
return parsedConfig;
|
|
174
167
|
}
|
|
175
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;
|
|
176
193
|
function parseConfig(configSource, configPath) {
|
|
177
194
|
let parsedYaml;
|
|
178
195
|
try {
|
|
@@ -283,57 +300,61 @@ function getConfigAccountByIdentifier(accounts, identifierFieldName, identifier)
|
|
|
283
300
|
exports.getConfigAccountByIdentifier = getConfigAccountByIdentifier;
|
|
284
301
|
function getConfigAccountByInferredIdentifier(accounts, accountIdentifier) {
|
|
285
302
|
const { identifier, identifierType } = getAccountIdentifierAndType(accountIdentifier);
|
|
286
|
-
|
|
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));
|
|
287
309
|
}
|
|
288
310
|
exports.getConfigAccountByInferredIdentifier = getConfigAccountByInferredIdentifier;
|
|
289
311
|
function getConfigAccountIndexById(accounts, id) {
|
|
290
312
|
return accounts.findIndex(account => account.accountId === id);
|
|
291
313
|
}
|
|
292
314
|
exports.getConfigAccountIndexById = getConfigAccountIndexById;
|
|
293
|
-
function
|
|
315
|
+
function validateConfigAccount(account) {
|
|
316
|
+
const validationErrors = [];
|
|
294
317
|
if (!account || typeof account !== 'object') {
|
|
295
|
-
|
|
296
|
-
return false;
|
|
318
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAccount'));
|
|
319
|
+
return { isValid: false, errors: validationErrors };
|
|
297
320
|
}
|
|
298
321
|
if (!account.accountId) {
|
|
299
|
-
|
|
300
|
-
return false;
|
|
322
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAccountId'));
|
|
323
|
+
return { isValid: false, errors: validationErrors };
|
|
301
324
|
}
|
|
302
325
|
if (!account.authType) {
|
|
303
|
-
|
|
326
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAuthType', {
|
|
304
327
|
accountId: account.accountId,
|
|
305
328
|
}));
|
|
306
|
-
return false;
|
|
329
|
+
return { isValid: false, errors: validationErrors };
|
|
307
330
|
}
|
|
308
|
-
let valid = false;
|
|
309
331
|
if (account.authType === auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
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', {
|
|
314
335
|
accountId: account.accountId,
|
|
315
336
|
}));
|
|
316
337
|
}
|
|
317
338
|
}
|
|
318
339
|
if (account.authType === auth_1.OAUTH_AUTH_METHOD.value) {
|
|
319
|
-
|
|
320
|
-
if (!
|
|
321
|
-
|
|
340
|
+
const isValidOAuthAccount = 'auth' in account && Boolean(account.auth);
|
|
341
|
+
if (!isValidOAuthAccount) {
|
|
342
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingAuth', {
|
|
322
343
|
accountId: account.accountId,
|
|
323
344
|
}));
|
|
324
345
|
}
|
|
325
346
|
}
|
|
326
347
|
if (account.authType === auth_1.API_KEY_AUTH_METHOD.value) {
|
|
327
|
-
|
|
328
|
-
if (!
|
|
329
|
-
|
|
348
|
+
const isValidAPIKeyAccount = 'apiKey' in account && Boolean(account.apiKey);
|
|
349
|
+
if (!isValidAPIKeyAccount) {
|
|
350
|
+
validationErrors.push((0, lang_1.i18n)('config.utils.validateConfigAccount.missingApiKey', {
|
|
330
351
|
accountId: account.accountId,
|
|
331
352
|
}));
|
|
332
353
|
}
|
|
333
354
|
}
|
|
334
|
-
return
|
|
355
|
+
return { isValid: validationErrors.length === 0, errors: validationErrors };
|
|
335
356
|
}
|
|
336
|
-
exports.
|
|
357
|
+
exports.validateConfigAccount = validateConfigAccount;
|
|
337
358
|
function handleConfigFileSystemError(error, path) {
|
|
338
359
|
let message;
|
|
339
360
|
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"
|
|
@@ -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",
|
|
@@ -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
|
@@ -121,7 +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 =
|
|
124
|
+
const account = (0, config_1.getConfigAccountIfExists)(portalId);
|
|
125
125
|
const accountEnv = env || account?.env || environments_1.ENVIRONMENTS.PROD;
|
|
126
126
|
let parentAccountId;
|
|
127
127
|
try {
|
|
@@ -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
|
@@ -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
|
+
};
|