@hubspot/local-dev-lib 0.6.1-experimental.0 → 0.6.3-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/api/appsDev.d.ts +2 -2
- package/api/appsDev.js +13 -22
- package/api/crm.d.ts +2 -2
- package/api/crm.js +9 -16
- package/api/customObjects.d.ts +2 -2
- package/api/customObjects.js +13 -22
- package/api/designManager.d.ts +2 -2
- package/api/designManager.js +5 -10
- package/api/devSecrets.d.ts +2 -2
- package/api/devSecrets.js +9 -16
- package/api/developerTestAccounts.d.ts +2 -4
- package/api/developerTestAccounts.js +23 -55
- package/api/fileManager.d.ts +2 -2
- package/api/fileManager.js +14 -24
- package/api/fileMapper.d.ts +2 -3
- package/api/fileMapper.js +34 -49
- package/api/fileTransport.d.ts +1 -1
- package/api/fileTransport.js +12 -21
- package/api/fireAlarm.d.ts +2 -3
- package/api/fireAlarm.js +5 -9
- package/api/functions.d.ts +2 -2
- package/api/functions.js +11 -19
- package/api/github.d.ts +2 -4
- package/api/github.js +16 -27
- package/api/hubdb.d.ts +2 -2
- package/api/hubdb.js +19 -31
- package/api/lighthouseScore.d.ts +2 -2
- package/api/lighthouseScore.js +7 -13
- package/api/localDevAuth.d.ts +3 -6
- package/api/localDevAuth.js +10 -40
- package/api/marketplaceValidation.d.ts +2 -2
- package/api/marketplaceValidation.js +7 -13
- package/api/projects.d.ts +6 -8
- package/api/projects.js +65 -100
- package/api/sandboxHubs.d.ts +2 -5
- package/api/sandboxHubs.js +15 -45
- package/api/sandboxSync.d.ts +2 -2
- package/api/sandboxSync.js +7 -12
- package/api/secrets.d.ts +2 -2
- package/api/secrets.js +9 -16
- package/api/validateHubl.d.ts +2 -2
- package/api/validateHubl.js +3 -7
- package/config/defaultAccountOverride.d.ts +2 -1
- package/config/defaultAccountOverride.js +16 -26
- package/config/index.d.ts +4 -4
- package/config/index.js +144 -177
- package/config/migrate.d.ts +2 -2
- package/config/migrate.js +26 -37
- package/config/state.d.ts +1 -1
- package/config/state.js +17 -45
- package/config/utils.d.ts +4 -4
- package/config/utils.js +85 -108
- package/constants/api.js +3 -6
- package/constants/auth.js +9 -12
- package/constants/config.d.ts +30 -1
- package/constants/config.js +65 -42
- package/constants/endpoints.d.ts +6 -0
- package/constants/endpoints.js +6 -0
- package/constants/environments.js +1 -4
- package/constants/extensions.js +6 -9
- package/constants/files.js +5 -8
- package/constants/ports.js +3 -6
- package/constants/projects.js +2 -5
- package/enums/build.d.ts +1 -0
- package/enums/build.js +6 -8
- package/enums/deploy.js +2 -5
- package/enums/project.js +1 -4
- package/errors/index.d.ts +4 -5
- package/errors/index.js +17 -39
- package/errors/isSystemError.d.ts +2 -0
- package/errors/isSystemError.js +9 -0
- package/http/addQueryParams.d.ts +1 -1
- package/http/addQueryParams.js +1 -5
- package/http/client.d.ts +1 -0
- package/http/client.js +54 -0
- package/http/getAxiosConfig.d.ts +1 -1
- package/http/getAxiosConfig.js +21 -31
- package/http/index.d.ts +2 -2
- package/http/index.js +39 -124
- package/http/unauthed.d.ts +1 -1
- package/http/unauthed.js +15 -21
- package/lang/en.json +3 -2
- package/lib/archive.d.ts +1 -3
- package/lib/archive.js +37 -67
- package/lib/cms/functions.d.ts +1 -1
- package/lib/cms/functions.js +45 -55
- package/lib/cms/handleFieldsJS.js +36 -44
- package/lib/cms/modules.d.ts +2 -2
- package/lib/cms/modules.js +49 -59
- package/lib/cms/processFieldsJs.js +17 -32
- package/lib/cms/templates.js +17 -26
- package/lib/cms/themes.js +10 -18
- package/lib/cms/uploadFolder.d.ts +4 -4
- package/lib/cms/uploadFolder.js +55 -64
- package/lib/cms/validate.d.ts +1 -1
- package/lib/cms/validate.js +11 -18
- package/lib/cms/watch.d.ts +2 -2
- package/lib/cms/watch.js +66 -73
- package/lib/crm.d.ts +1 -1
- package/lib/crm.js +15 -23
- package/lib/customObjects.d.ts +1 -1
- package/lib/customObjects.js +15 -25
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +5 -11
- package/lib/escapeRegExp.js +1 -5
- package/lib/fileManager.js +43 -51
- package/lib/fileMapper.d.ts +1 -1
- package/lib/fileMapper.js +68 -84
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +18 -27
- package/lib/github.d.ts +1 -3
- package/lib/github.js +39 -51
- package/lib/gitignore.d.ts +1 -1
- package/lib/gitignore.js +16 -24
- package/lib/hubdb.d.ts +1 -1
- package/lib/hubdb.js +29 -40
- package/lib/ignoreRules.js +25 -34
- package/lib/isDeepEqual.js +1 -5
- package/lib/logger.d.ts +8 -20
- package/lib/logger.js +47 -59
- package/lib/notify.js +9 -16
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +12 -17
- package/lib/path.d.ts +0 -1
- package/lib/path.js +30 -48
- package/lib/personalAccessKey.d.ts +2 -4
- package/lib/personalAccessKey.js +43 -60
- package/lib/portManager.d.ts +2 -2
- package/lib/portManager.js +26 -41
- package/lib/text.js +2 -7
- package/lib/trackUsage.d.ts +0 -2
- package/lib/trackUsage.js +27 -31
- package/lib/urls.js +4 -9
- package/models/FileSystemError.d.ts +1 -1
- package/models/FileSystemError.js +12 -16
- package/models/HubSpotConfigError.d.ts +1 -1
- package/models/HubSpotConfigError.js +8 -12
- package/models/HubSpotHttpError.d.ts +1 -1
- package/models/HubSpotHttpError.js +22 -26
- package/models/OAuth2Manager.d.ts +1 -1
- package/models/OAuth2Manager.js +17 -24
- package/package.json +21 -17
- package/types/Accounts.d.ts +6 -5
- package/types/Accounts.js +1 -2
- package/types/Activity.d.ts +3 -3
- package/types/Activity.js +1 -2
- package/types/Api.d.ts +1 -1
- package/types/Api.js +1 -2
- package/types/Apps.js +1 -2
- package/types/Archive.js +1 -2
- package/types/Build.d.ts +4 -5
- package/types/Build.js +1 -2
- package/types/CLIOptions.js +1 -2
- package/types/ComponentStructure.d.ts +2 -2
- package/types/ComponentStructure.js +1 -2
- package/types/Config.d.ts +4 -6
- package/types/Config.js +1 -2
- package/types/Crm.js +1 -2
- package/types/Deploy.d.ts +5 -11
- package/types/Deploy.js +1 -2
- package/types/DesignManager.js +1 -2
- package/types/DevSecrets.js +1 -2
- package/types/Error.js +1 -2
- package/types/FieldsJS.js +1 -2
- package/types/FileManager.js +1 -2
- package/types/Files.d.ts +4 -4
- package/types/Files.js +1 -2
- package/types/FireAlarm.js +1 -2
- package/types/Functions.js +1 -2
- package/types/Github.d.ts +1 -1
- package/types/Github.js +1 -2
- package/types/Http.d.ts +0 -4
- package/types/Http.js +1 -2
- package/types/Hubdb.js +1 -2
- package/types/HublValidation.js +1 -2
- package/types/Lang.d.ts +1 -1
- package/types/Lang.js +1 -2
- package/types/Lighthouse.js +1 -2
- package/types/MarketplaceValidation.js +1 -2
- package/types/Migration.d.ts +2 -2
- package/types/Migration.js +1 -4
- package/types/Modules.js +1 -2
- package/types/PortManager.js +1 -2
- package/types/Project.d.ts +3 -21
- package/types/Project.js +1 -2
- package/types/ProjectComponents.d.ts +24 -0
- package/types/ProjectComponents.js +1 -0
- package/types/ProjectLog.js +1 -2
- package/types/Sandbox.js +2 -5
- package/types/Schemas.js +1 -2
- package/types/Secrets.js +1 -2
- package/types/Utils.js +1 -2
- package/types/developerTestAccounts.js +1 -2
- package/utils/PortManagerServer.d.ts +1 -2
- package/utils/PortManagerServer.js +32 -38
- package/utils/cms/fieldsJS.d.ts +1 -1
- package/utils/cms/fieldsJS.js +1 -5
- package/utils/cms/modules.d.ts +1 -1
- package/utils/cms/modules.js +13 -22
- package/utils/detectPort.js +12 -19
- package/utils/git.js +17 -26
- package/utils/lang.d.ts +1 -1
- package/utils/lang.js +5 -14
- package/utils/personalAccessKey.d.ts +8 -0
- package/utils/personalAccessKey.js +51 -0
- package/errors/errors_DEPRECATED.d.ts +0 -3
- package/errors/errors_DEPRECATED.js +0 -60
|
@@ -1,57 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const path_1 = require("../lib/path");
|
|
10
|
-
const config_1 = require("../constants/config");
|
|
11
|
-
const lang_1 = require("../utils/lang");
|
|
12
|
-
const FileSystemError_1 = require("../models/FileSystemError");
|
|
13
|
-
const index_1 = require("./index");
|
|
1
|
+
import findup from 'findup-sync';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { getCwd } from '../lib/path.js';
|
|
4
|
+
import { DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID, DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND, DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME, } from '../constants/config.js';
|
|
5
|
+
import { i18n } from '../utils/lang.js';
|
|
6
|
+
import { FileSystemError } from '../models/FileSystemError.js';
|
|
14
7
|
const i18nKey = 'config.defaultAccountOverride';
|
|
15
|
-
function getDefaultAccountOverrideAccountId() {
|
|
8
|
+
export function getDefaultAccountOverrideAccountId(accounts) {
|
|
16
9
|
const defaultAccountOverrideFilePath = getDefaultAccountOverrideFilePath();
|
|
17
10
|
if (!defaultAccountOverrideFilePath) {
|
|
18
11
|
return null;
|
|
19
12
|
}
|
|
20
13
|
let source;
|
|
21
14
|
try {
|
|
22
|
-
source =
|
|
15
|
+
source = fs.readFileSync(defaultAccountOverrideFilePath, 'utf8');
|
|
23
16
|
}
|
|
24
17
|
catch (e) {
|
|
25
|
-
throw new
|
|
18
|
+
throw new FileSystemError({ cause: e }, {
|
|
26
19
|
filepath: defaultAccountOverrideFilePath,
|
|
27
20
|
operation: 'read',
|
|
28
21
|
});
|
|
29
22
|
}
|
|
30
23
|
const accountId = parseInt(source);
|
|
31
24
|
if (isNaN(accountId)) {
|
|
32
|
-
throw new Error(
|
|
25
|
+
throw new Error(i18n(`${i18nKey}.getDefaultAccountOverrideAccountId.errorHeader`, {
|
|
33
26
|
hsAccountFile: defaultAccountOverrideFilePath,
|
|
34
27
|
}), {
|
|
35
28
|
// TODO: This is improper use of cause, we should create a custom error class
|
|
36
|
-
cause:
|
|
29
|
+
cause: DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID,
|
|
37
30
|
});
|
|
38
31
|
}
|
|
39
|
-
const accounts = (0, index_1.getAllConfigAccounts)();
|
|
40
32
|
const account = accounts?.find(account => account.accountId === accountId);
|
|
41
33
|
if (!account) {
|
|
42
|
-
throw new Error(
|
|
34
|
+
throw new Error(i18n(`${i18nKey}.getDefaultAccountOverrideAccountId.errorHeader`, {
|
|
43
35
|
hsAccountFile: defaultAccountOverrideFilePath,
|
|
44
36
|
}), {
|
|
45
37
|
// TODO: This is improper use of cause, we should create a custom error class
|
|
46
|
-
cause:
|
|
38
|
+
cause: DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND,
|
|
47
39
|
});
|
|
48
40
|
}
|
|
49
41
|
return account.accountId;
|
|
50
42
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
cwd: (0, path_1.getCwd)(),
|
|
43
|
+
export function getDefaultAccountOverrideFilePath() {
|
|
44
|
+
return findup([DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME], {
|
|
45
|
+
cwd: getCwd(),
|
|
55
46
|
});
|
|
56
47
|
}
|
|
57
|
-
exports.getDefaultAccountOverrideFilePath = getDefaultAccountOverrideFilePath;
|
package/config/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { HubSpotConfigAccount } from '../types/Accounts';
|
|
2
|
-
import { HubSpotConfig, ConfigFlag, HubSpotConfigValidationResult } from '../types/Config';
|
|
3
|
-
import { CmsPublishMode } from '../types/Files';
|
|
4
|
-
import { Environment } from '../types/
|
|
1
|
+
import { HubSpotConfigAccount } from '../types/Accounts.js';
|
|
2
|
+
import { HubSpotConfig, ConfigFlag, HubSpotConfigValidationResult } from '../types/Config.js';
|
|
3
|
+
import { CmsPublishMode } from '../types/Files.js';
|
|
4
|
+
import { Environment } from '../types/Accounts.js';
|
|
5
5
|
export declare function getGlobalConfigFilePath(): string;
|
|
6
6
|
export declare function getLocalConfigFilePathIfExists(cwd?: string): string | null;
|
|
7
7
|
export declare function localConfigFileExists(): boolean;
|
package/config/index.js
CHANGED
|
@@ -1,115 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const defaultAccountOverride_1 = require("./defaultAccountOverride");
|
|
15
|
-
const environment_1 = require("../lib/environment");
|
|
16
|
-
const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
|
|
17
|
-
const config_2 = require("../constants/config");
|
|
18
|
-
const isDeepEqual_1 = require("../lib/isDeepEqual");
|
|
19
|
-
const path_1 = require("../lib/path");
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import findup from 'findup-sync';
|
|
3
|
+
import { ACCOUNT_IDENTIFIERS, DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME, GLOBAL_CONFIG_PATH, HUBSPOT_CONFIG_OPERATIONS, MIN_HTTP_TIMEOUT, ENVIRONMENT_VARIABLES, } from '../constants/config.js';
|
|
4
|
+
import { logger } from '../lib/logger.js';
|
|
5
|
+
import { readConfigFile, parseConfig, buildConfigFromEnvironment, writeConfigFile, getLocalConfigDefaultFilePath, getConfigAccountByIdentifier, validateConfigAccount, getConfigAccountIndexById, getConfigPathEnvironmentVariables, getConfigAccountByInferredIdentifier, handleConfigFileSystemError, doesConfigFileExistAtPath, } from './utils.js';
|
|
6
|
+
import { CMS_PUBLISH_MODE } from '../constants/files.js';
|
|
7
|
+
import { i18n } from '../utils/lang.js';
|
|
8
|
+
import { getDefaultAccountOverrideAccountId } from './defaultAccountOverride.js';
|
|
9
|
+
import { getValidEnv } from '../lib/environment.js';
|
|
10
|
+
import { HubSpotConfigError } from '../models/HubSpotConfigError.js';
|
|
11
|
+
import { HUBSPOT_CONFIG_ERROR_TYPES } from '../constants/config.js';
|
|
12
|
+
import { isDeepEqual } from '../lib/isDeepEqual.js';
|
|
13
|
+
import { getCwd } from '../lib/path.js';
|
|
20
14
|
const EMPTY_CONFIG = { accounts: [] };
|
|
21
|
-
function getGlobalConfigFilePath() {
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
exports.getLocalConfigFilePathIfExists = getLocalConfigFilePathIfExists;
|
|
32
|
-
function localConfigFileExists() {
|
|
15
|
+
export function getGlobalConfigFilePath() {
|
|
16
|
+
return GLOBAL_CONFIG_PATH;
|
|
17
|
+
}
|
|
18
|
+
export function getLocalConfigFilePathIfExists(cwd) {
|
|
19
|
+
return findup([
|
|
20
|
+
DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
21
|
+
DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME.replace('.yml', '.yaml'),
|
|
22
|
+
], { cwd: cwd || getCwd() });
|
|
23
|
+
}
|
|
24
|
+
export function localConfigFileExists() {
|
|
33
25
|
return Boolean(getLocalConfigFilePathIfExists());
|
|
34
26
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return (0, utils_1.doesConfigFileExistAtPath)(getGlobalConfigFilePath());
|
|
27
|
+
export function globalConfigFileExists() {
|
|
28
|
+
return doesConfigFileExistAtPath(getGlobalConfigFilePath());
|
|
38
29
|
}
|
|
39
|
-
|
|
40
|
-
function configFileExists() {
|
|
30
|
+
export function configFileExists() {
|
|
41
31
|
try {
|
|
42
|
-
return
|
|
32
|
+
return doesConfigFileExistAtPath(getConfigFilePath());
|
|
43
33
|
}
|
|
44
34
|
catch (error) {
|
|
45
35
|
return false;
|
|
46
36
|
}
|
|
47
37
|
}
|
|
48
|
-
exports.configFileExists = configFileExists;
|
|
49
38
|
function getConfigDefaultFilePath() {
|
|
50
39
|
const globalConfigFilePath = getGlobalConfigFilePath();
|
|
51
|
-
if (
|
|
40
|
+
if (doesConfigFileExistAtPath(globalConfigFilePath)) {
|
|
52
41
|
return globalConfigFilePath;
|
|
53
42
|
}
|
|
54
43
|
const localConfigFilePath = getLocalConfigFilePathIfExists();
|
|
55
44
|
if (!localConfigFilePath) {
|
|
56
|
-
throw new
|
|
45
|
+
throw new HubSpotConfigError(i18n('config.getDefaultConfigFilePath.error'), HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
57
46
|
}
|
|
58
47
|
return localConfigFilePath;
|
|
59
48
|
}
|
|
60
|
-
function getConfigFilePath() {
|
|
61
|
-
const { configFilePathFromEnvironment } =
|
|
49
|
+
export function getConfigFilePath() {
|
|
50
|
+
const { configFilePathFromEnvironment } = getConfigPathEnvironmentVariables();
|
|
62
51
|
return configFilePathFromEnvironment || getConfigDefaultFilePath();
|
|
63
52
|
}
|
|
64
|
-
|
|
65
|
-
function getConfig() {
|
|
53
|
+
export function getConfig() {
|
|
66
54
|
let pathToRead;
|
|
67
55
|
try {
|
|
68
|
-
const { useEnvironmentConfig } =
|
|
56
|
+
const { useEnvironmentConfig } = getConfigPathEnvironmentVariables();
|
|
69
57
|
if (useEnvironmentConfig) {
|
|
70
|
-
return
|
|
58
|
+
return buildConfigFromEnvironment();
|
|
71
59
|
}
|
|
72
60
|
pathToRead = getConfigFilePath();
|
|
73
|
-
|
|
74
|
-
const configFileSource =
|
|
75
|
-
return
|
|
61
|
+
logger.debug(i18n('config.getConfig.reading', { path: pathToRead }));
|
|
62
|
+
const configFileSource = readConfigFile(pathToRead);
|
|
63
|
+
return parseConfig(configFileSource, pathToRead);
|
|
76
64
|
}
|
|
77
65
|
catch (err) {
|
|
78
|
-
throw new
|
|
79
|
-
?
|
|
80
|
-
:
|
|
66
|
+
throw new HubSpotConfigError(pathToRead
|
|
67
|
+
? i18n('config.getConfig.errorWithPath', { path: pathToRead })
|
|
68
|
+
: i18n('config.getConfig.error'), HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ, { cause: err });
|
|
81
69
|
}
|
|
82
70
|
}
|
|
83
|
-
|
|
84
|
-
function validateConfig() {
|
|
71
|
+
export function validateConfig() {
|
|
85
72
|
const config = getConfig();
|
|
86
73
|
if (config.accounts.length === 0) {
|
|
87
74
|
return {
|
|
88
75
|
isValid: false,
|
|
89
|
-
errors: [
|
|
76
|
+
errors: [i18n('config.validateConfig.missingAccounts')],
|
|
90
77
|
};
|
|
91
78
|
}
|
|
92
79
|
const accountIdsMap = {};
|
|
93
80
|
const accountNamesMap = {};
|
|
94
81
|
const validationErrors = [];
|
|
95
82
|
config.accounts.forEach(account => {
|
|
96
|
-
const accountValidationResult =
|
|
83
|
+
const accountValidationResult = validateConfigAccount(account);
|
|
97
84
|
if (!accountValidationResult.isValid) {
|
|
98
85
|
validationErrors.push(...accountValidationResult.errors);
|
|
99
86
|
}
|
|
100
87
|
if (accountIdsMap[account.accountId]) {
|
|
101
|
-
validationErrors.push(
|
|
88
|
+
validationErrors.push(i18n('config.validateConfig.duplicateAccountIds', {
|
|
102
89
|
accountId: account.accountId,
|
|
103
90
|
}));
|
|
104
91
|
}
|
|
105
92
|
if (account.name) {
|
|
106
93
|
if (accountNamesMap[account.name.toLowerCase()]) {
|
|
107
|
-
validationErrors.push(
|
|
94
|
+
validationErrors.push(i18n('config.validateConfig.duplicateAccountNames', {
|
|
108
95
|
accountName: account.name,
|
|
109
96
|
}));
|
|
110
97
|
}
|
|
111
98
|
if (/\s+/.test(account.name)) {
|
|
112
|
-
validationErrors.push(
|
|
99
|
+
validationErrors.push(i18n('config.validateConfig.invalidAccountName', {
|
|
113
100
|
accountName: account.name,
|
|
114
101
|
}));
|
|
115
102
|
}
|
|
@@ -119,269 +106,249 @@ function validateConfig() {
|
|
|
119
106
|
});
|
|
120
107
|
return { isValid: validationErrors.length === 0, errors: validationErrors };
|
|
121
108
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const { configFilePathFromEnvironment } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
109
|
+
export function createEmptyConfigFile(useGlobalConfig = false) {
|
|
110
|
+
const { configFilePathFromEnvironment } = getConfigPathEnvironmentVariables();
|
|
125
111
|
const defaultPath = useGlobalConfig
|
|
126
112
|
? getGlobalConfigFilePath()
|
|
127
|
-
:
|
|
113
|
+
: getLocalConfigDefaultFilePath();
|
|
128
114
|
const pathToWrite = configFilePathFromEnvironment || defaultPath;
|
|
129
|
-
|
|
115
|
+
writeConfigFile(EMPTY_CONFIG, pathToWrite);
|
|
130
116
|
}
|
|
131
|
-
|
|
132
|
-
function deleteConfigFileIfEmpty() {
|
|
117
|
+
export function deleteConfigFileIfEmpty() {
|
|
133
118
|
const pathToDelete = getConfigFilePath();
|
|
134
119
|
try {
|
|
135
120
|
const config = getConfig();
|
|
136
|
-
if (
|
|
137
|
-
|
|
121
|
+
if (isDeepEqual(config, EMPTY_CONFIG)) {
|
|
122
|
+
fs.unlinkSync(pathToDelete);
|
|
138
123
|
}
|
|
139
124
|
}
|
|
140
125
|
catch (error) {
|
|
141
|
-
const { message, type } =
|
|
142
|
-
throw new
|
|
126
|
+
const { message, type } = handleConfigFileSystemError(error, pathToDelete);
|
|
127
|
+
throw new HubSpotConfigError(message, type, HUBSPOT_CONFIG_OPERATIONS.DELETE, {
|
|
143
128
|
cause: error,
|
|
144
129
|
});
|
|
145
130
|
}
|
|
146
131
|
}
|
|
147
|
-
|
|
148
|
-
function getConfigAccountById(accountId) {
|
|
132
|
+
export function getConfigAccountById(accountId) {
|
|
149
133
|
const { accounts } = getConfig();
|
|
150
|
-
const account =
|
|
134
|
+
const account = getConfigAccountByIdentifier(accounts, ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountId);
|
|
151
135
|
if (!account) {
|
|
152
|
-
throw new
|
|
136
|
+
throw new HubSpotConfigError(i18n('config.getConfigAccountById.error', { accountId }), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
153
137
|
}
|
|
154
138
|
return account;
|
|
155
139
|
}
|
|
156
|
-
|
|
157
|
-
function getConfigAccountByName(accountName) {
|
|
140
|
+
export function getConfigAccountByName(accountName) {
|
|
158
141
|
const { accounts } = getConfig();
|
|
159
|
-
const account =
|
|
142
|
+
const account = getConfigAccountByIdentifier(accounts, ACCOUNT_IDENTIFIERS.NAME, accountName);
|
|
160
143
|
if (!account) {
|
|
161
|
-
throw new
|
|
144
|
+
throw new HubSpotConfigError(i18n('config.getConfigAccountByName.error', { accountName }), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
162
145
|
}
|
|
163
146
|
return account;
|
|
164
147
|
}
|
|
165
|
-
|
|
166
|
-
function getConfigAccountIfExists(identifier) {
|
|
148
|
+
export function getConfigAccountIfExists(identifier) {
|
|
167
149
|
const config = getConfig();
|
|
168
|
-
return
|
|
150
|
+
return getConfigAccountByInferredIdentifier(config.accounts, identifier);
|
|
169
151
|
}
|
|
170
|
-
|
|
171
|
-
function getConfigDefaultAccount() {
|
|
152
|
+
export function getConfigDefaultAccount() {
|
|
172
153
|
const { accounts, defaultAccount } = getConfig();
|
|
173
154
|
let defaultAccountToUse = defaultAccount;
|
|
174
155
|
const currentConfigPath = getConfigFilePath();
|
|
175
156
|
const globalConfigPath = getGlobalConfigFilePath();
|
|
176
157
|
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
177
|
-
const defaultAccountOverrideAccountId =
|
|
158
|
+
const defaultAccountOverrideAccountId = getDefaultAccountOverrideAccountId(accounts);
|
|
178
159
|
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
179
160
|
}
|
|
180
161
|
if (!defaultAccountToUse) {
|
|
181
|
-
throw new
|
|
162
|
+
throw new HubSpotConfigError(i18n('config.getConfigDefaultAccount.fieldMissingError'), HUBSPOT_CONFIG_ERROR_TYPES.NO_DEFAULT_ACCOUNT, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
182
163
|
}
|
|
183
|
-
const account =
|
|
164
|
+
const account = getConfigAccountByInferredIdentifier(accounts, defaultAccountToUse);
|
|
184
165
|
if (!account) {
|
|
185
|
-
throw new
|
|
166
|
+
throw new HubSpotConfigError(i18n('config.getConfigDefaultAccount.accountMissingError', {
|
|
186
167
|
defaultAccountToUse,
|
|
187
|
-
}),
|
|
168
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
188
169
|
}
|
|
189
170
|
return account;
|
|
190
171
|
}
|
|
191
|
-
|
|
192
|
-
function getConfigDefaultAccountIfExists() {
|
|
172
|
+
export function getConfigDefaultAccountIfExists() {
|
|
193
173
|
const { accounts, defaultAccount } = getConfig();
|
|
194
174
|
let defaultAccountToUse = defaultAccount;
|
|
195
175
|
// Only check for default account override if we're using the global config
|
|
196
176
|
const currentConfigPath = getConfigFilePath();
|
|
197
177
|
const globalConfigPath = getGlobalConfigFilePath();
|
|
198
178
|
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
199
|
-
const defaultAccountOverrideAccountId =
|
|
179
|
+
const defaultAccountOverrideAccountId = getDefaultAccountOverrideAccountId(accounts);
|
|
200
180
|
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
201
181
|
}
|
|
202
182
|
if (!defaultAccountToUse) {
|
|
203
183
|
return;
|
|
204
184
|
}
|
|
205
|
-
const account =
|
|
185
|
+
const account = getConfigAccountByInferredIdentifier(accounts, defaultAccountToUse);
|
|
206
186
|
return account;
|
|
207
187
|
}
|
|
208
|
-
|
|
209
|
-
function getAllConfigAccounts() {
|
|
188
|
+
export function getAllConfigAccounts() {
|
|
210
189
|
const { accounts } = getConfig();
|
|
211
190
|
return accounts;
|
|
212
191
|
}
|
|
213
|
-
|
|
214
|
-
function getConfigAccountEnvironment(identifier) {
|
|
192
|
+
export function getConfigAccountEnvironment(identifier) {
|
|
215
193
|
const config = getConfig();
|
|
216
|
-
const account =
|
|
194
|
+
const account = getConfigAccountByInferredIdentifier(config.accounts, identifier);
|
|
217
195
|
if (!account) {
|
|
218
|
-
throw new
|
|
196
|
+
throw new HubSpotConfigError(i18n('config.getConfigAccountEnvironment.accountNotFound', {
|
|
219
197
|
identifier,
|
|
220
|
-
}),
|
|
198
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
221
199
|
}
|
|
222
|
-
return
|
|
200
|
+
return getValidEnv(account.env);
|
|
223
201
|
}
|
|
224
|
-
|
|
225
|
-
|
|
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);
|
|
202
|
+
export function addConfigAccount(accountToAdd) {
|
|
203
|
+
if (!validateConfigAccount(accountToAdd)) {
|
|
204
|
+
throw new HubSpotConfigError(i18n('config.addConfigAccount.invalidAccount'), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
228
205
|
}
|
|
229
206
|
const config = getConfig();
|
|
230
|
-
const accountInConfig =
|
|
207
|
+
const accountInConfig = getConfigAccountByIdentifier(config.accounts, ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountToAdd.accountId);
|
|
231
208
|
if (accountInConfig) {
|
|
232
|
-
throw new
|
|
209
|
+
throw new HubSpotConfigError(i18n('config.addConfigAccount.duplicateAccount', {
|
|
233
210
|
accountId: accountToAdd.accountId,
|
|
234
|
-
}),
|
|
211
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
235
212
|
}
|
|
236
213
|
config.accounts.push(accountToAdd);
|
|
237
|
-
|
|
214
|
+
writeConfigFile(config, getConfigFilePath());
|
|
238
215
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (
|
|
242
|
-
|
|
216
|
+
export function updateConfigAccount(updatedAccount) {
|
|
217
|
+
// Skip updating the config file if we're using environment variables
|
|
218
|
+
if (process.env[ENVIRONMENT_VARIABLES.USE_ENVIRONMENT_HUBSPOT_CONFIG]) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (!validateConfigAccount(updatedAccount)) {
|
|
222
|
+
throw new HubSpotConfigError(i18n('config.updateConfigAccount.invalidAccount', {
|
|
243
223
|
name: updatedAccount.name,
|
|
244
|
-
}),
|
|
224
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
245
225
|
}
|
|
246
226
|
const config = getConfig();
|
|
247
|
-
const accountIndex =
|
|
227
|
+
const accountIndex = getConfigAccountIndexById(config.accounts, updatedAccount.accountId);
|
|
248
228
|
if (accountIndex < 0) {
|
|
249
|
-
throw new
|
|
229
|
+
throw new HubSpotConfigError(i18n('config.updateConfigAccount.accountNotFound', {
|
|
250
230
|
accountId: updatedAccount.accountId,
|
|
251
|
-
}),
|
|
231
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
252
232
|
}
|
|
253
233
|
config.accounts[accountIndex] = updatedAccount;
|
|
254
|
-
|
|
234
|
+
writeConfigFile(config, getConfigFilePath());
|
|
255
235
|
}
|
|
256
|
-
|
|
257
|
-
function setConfigAccountAsDefault(identifier) {
|
|
236
|
+
export function setConfigAccountAsDefault(identifier) {
|
|
258
237
|
const config = getConfig();
|
|
259
|
-
const account =
|
|
238
|
+
const account = getConfigAccountByInferredIdentifier(config.accounts, identifier);
|
|
260
239
|
if (!account) {
|
|
261
|
-
throw new
|
|
240
|
+
throw new HubSpotConfigError(i18n('config.setConfigAccountAsDefault.accountNotFound', {
|
|
262
241
|
identifier,
|
|
263
|
-
}),
|
|
242
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
264
243
|
}
|
|
265
244
|
config.defaultAccount = account.accountId;
|
|
266
|
-
|
|
245
|
+
writeConfigFile(config, getConfigFilePath());
|
|
267
246
|
}
|
|
268
|
-
|
|
269
|
-
function renameConfigAccount(currentName, newName) {
|
|
247
|
+
export function renameConfigAccount(currentName, newName) {
|
|
270
248
|
const config = getConfig();
|
|
271
|
-
const account =
|
|
249
|
+
const account = getConfigAccountByIdentifier(config.accounts, ACCOUNT_IDENTIFIERS.NAME, currentName);
|
|
272
250
|
if (!account) {
|
|
273
|
-
throw new
|
|
251
|
+
throw new HubSpotConfigError(i18n('config.renameConfigAccount.accountNotFound', {
|
|
274
252
|
currentName,
|
|
275
|
-
}),
|
|
253
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
276
254
|
}
|
|
277
|
-
const duplicateAccount =
|
|
255
|
+
const duplicateAccount = getConfigAccountByIdentifier(config.accounts, ACCOUNT_IDENTIFIERS.NAME, newName);
|
|
278
256
|
if (duplicateAccount) {
|
|
279
|
-
throw new
|
|
257
|
+
throw new HubSpotConfigError(i18n('config.renameConfigAccount.duplicateAccount', {
|
|
280
258
|
currentName,
|
|
281
259
|
newName,
|
|
282
|
-
}),
|
|
260
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
283
261
|
}
|
|
284
262
|
account.name = newName;
|
|
285
|
-
|
|
263
|
+
writeConfigFile(config, getConfigFilePath());
|
|
286
264
|
}
|
|
287
|
-
|
|
288
|
-
function removeAccountFromConfig(accountId) {
|
|
265
|
+
export function removeAccountFromConfig(accountId) {
|
|
289
266
|
const config = getConfig();
|
|
290
|
-
const index =
|
|
267
|
+
const index = getConfigAccountIndexById(config.accounts, accountId);
|
|
291
268
|
if (index < 0) {
|
|
292
|
-
throw new
|
|
269
|
+
throw new HubSpotConfigError(i18n('config.removeAccountFromConfig.accountNotFound', {
|
|
293
270
|
accountId,
|
|
294
|
-
}),
|
|
271
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
295
272
|
}
|
|
296
273
|
config.accounts.splice(index, 1);
|
|
297
274
|
if (config.defaultAccount === accountId) {
|
|
298
275
|
delete config.defaultAccount;
|
|
299
276
|
}
|
|
300
|
-
|
|
277
|
+
writeConfigFile(config, getConfigFilePath());
|
|
301
278
|
}
|
|
302
|
-
|
|
303
|
-
function updateHttpTimeout(timeout) {
|
|
279
|
+
export function updateHttpTimeout(timeout) {
|
|
304
280
|
const parsedTimeout = typeof timeout === 'string' ? parseInt(timeout) : timeout;
|
|
305
|
-
if (isNaN(parsedTimeout) || parsedTimeout <
|
|
306
|
-
throw new
|
|
307
|
-
minTimeout:
|
|
281
|
+
if (isNaN(parsedTimeout) || parsedTimeout < MIN_HTTP_TIMEOUT) {
|
|
282
|
+
throw new HubSpotConfigError(i18n('config.updateHttpTimeout.invalidTimeout', {
|
|
283
|
+
minTimeout: MIN_HTTP_TIMEOUT,
|
|
308
284
|
timeout: parsedTimeout,
|
|
309
|
-
}),
|
|
285
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
310
286
|
}
|
|
311
287
|
const config = getConfig();
|
|
312
288
|
config.httpTimeout = parsedTimeout;
|
|
313
|
-
|
|
289
|
+
writeConfigFile(config, getConfigFilePath());
|
|
314
290
|
}
|
|
315
|
-
|
|
316
|
-
function updateAllowUsageTracking(isAllowed) {
|
|
291
|
+
export function updateAllowUsageTracking(isAllowed) {
|
|
317
292
|
if (typeof isAllowed !== 'boolean') {
|
|
318
|
-
throw new
|
|
293
|
+
throw new HubSpotConfigError(i18n('config.updateAllowUsageTracking.invalidInput', {
|
|
319
294
|
isAllowed: `${isAllowed}`,
|
|
320
|
-
}),
|
|
295
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
321
296
|
}
|
|
322
297
|
const config = getConfig();
|
|
323
298
|
config.allowUsageTracking = isAllowed;
|
|
324
|
-
|
|
299
|
+
writeConfigFile(config, getConfigFilePath());
|
|
325
300
|
}
|
|
326
|
-
|
|
327
|
-
function updateAllowAutoUpdates(isEnabled) {
|
|
301
|
+
export function updateAllowAutoUpdates(isEnabled) {
|
|
328
302
|
if (typeof isEnabled !== 'boolean') {
|
|
329
|
-
throw new
|
|
303
|
+
throw new HubSpotConfigError(i18n('config.updateAllowAutoUpdates.invalidInput', {
|
|
330
304
|
isEnabled: `${isEnabled}`,
|
|
331
|
-
}),
|
|
305
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
332
306
|
}
|
|
333
307
|
const config = getConfig();
|
|
334
308
|
config.allowAutoUpdates = isEnabled;
|
|
335
|
-
|
|
309
|
+
writeConfigFile(config, getConfigFilePath());
|
|
336
310
|
}
|
|
337
|
-
|
|
338
|
-
function updateAutoOpenBrowser(isEnabled) {
|
|
311
|
+
export function updateAutoOpenBrowser(isEnabled) {
|
|
339
312
|
if (typeof isEnabled !== 'boolean') {
|
|
340
|
-
throw new
|
|
313
|
+
throw new HubSpotConfigError(i18n('config.updateAutoOpenBrowser.invalidInput', {
|
|
341
314
|
isEnabled: `${isEnabled}`,
|
|
342
|
-
}),
|
|
315
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
343
316
|
}
|
|
344
317
|
const config = getConfig();
|
|
345
318
|
config.autoOpenBrowser = isEnabled;
|
|
346
|
-
|
|
319
|
+
writeConfigFile(config, getConfigFilePath());
|
|
347
320
|
}
|
|
348
|
-
|
|
349
|
-
function updateDefaultCmsPublishMode(cmsPublishMode) {
|
|
321
|
+
export function updateDefaultCmsPublishMode(cmsPublishMode) {
|
|
350
322
|
if (!cmsPublishMode ||
|
|
351
|
-
!Object.values(
|
|
352
|
-
throw new
|
|
323
|
+
!Object.values(CMS_PUBLISH_MODE).includes(cmsPublishMode)) {
|
|
324
|
+
throw new HubSpotConfigError(i18n('config.updateDefaultCmsPublishMode.invalidCmsPublishMode', {
|
|
353
325
|
cmsPublishMode,
|
|
354
|
-
}),
|
|
326
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
355
327
|
}
|
|
356
328
|
const config = getConfig();
|
|
357
329
|
config.defaultCmsPublishMode = cmsPublishMode;
|
|
358
|
-
|
|
330
|
+
writeConfigFile(config, getConfigFilePath());
|
|
359
331
|
}
|
|
360
|
-
|
|
361
|
-
function isConfigFlagEnabled(flag, defaultValue) {
|
|
332
|
+
export function isConfigFlagEnabled(flag, defaultValue) {
|
|
362
333
|
const config = getConfig();
|
|
363
334
|
if (typeof config[flag] === 'undefined') {
|
|
364
335
|
return defaultValue || false;
|
|
365
336
|
}
|
|
366
337
|
return Boolean(config[flag]);
|
|
367
338
|
}
|
|
368
|
-
|
|
369
|
-
function hasLocalStateFlag(flag) {
|
|
339
|
+
export function hasLocalStateFlag(flag) {
|
|
370
340
|
const config = getConfig();
|
|
371
341
|
return config.flags?.includes(flag) || false;
|
|
372
342
|
}
|
|
373
|
-
|
|
374
|
-
function addLocalStateFlag(flag) {
|
|
343
|
+
export function addLocalStateFlag(flag) {
|
|
375
344
|
const config = getConfig();
|
|
376
345
|
if (!hasLocalStateFlag(flag)) {
|
|
377
346
|
config.flags = [...(config.flags || []), flag];
|
|
378
347
|
}
|
|
379
|
-
|
|
348
|
+
writeConfigFile(config, getConfigFilePath());
|
|
380
349
|
}
|
|
381
|
-
|
|
382
|
-
function removeLocalStateFlag(flag) {
|
|
350
|
+
export function removeLocalStateFlag(flag) {
|
|
383
351
|
const config = getConfig();
|
|
384
352
|
config.flags = config.flags?.filter(f => f !== flag) || [];
|
|
385
|
-
|
|
353
|
+
writeConfigFile(config, getConfigFilePath());
|
|
386
354
|
}
|
|
387
|
-
exports.removeLocalStateFlag = removeLocalStateFlag;
|
package/config/migrate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HubSpotConfig } from '../types/Config';
|
|
2
|
-
import { ValueOf } from '../types/Utils';
|
|
1
|
+
import { HubSpotConfig } from '../types/Config.js';
|
|
2
|
+
import { ValueOf } from '../types/Utils.js';
|
|
3
3
|
export declare function getConfigAtPath(path: string): HubSpotConfig;
|
|
4
4
|
export declare function migrateConfigAtPath(path: string): void;
|
|
5
5
|
export type ConflictProperty = {
|