@hubspot/local-dev-lib 4.0.4 → 5.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 -52
- 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 -37
- 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 -42
- 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 +141 -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.js +37 -43
- 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.js +14 -42
- 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 -46
- package/http/unauthed.d.ts +1 -1
- package/http/unauthed.js +15 -18
- package/lang/en.json +1 -1
- 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 +23 -29
- 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 +20 -16
- 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,114 +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 isDeepEqual_1 = require("../lib/isDeepEqual");
|
|
18
|
-
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';
|
|
19
14
|
const EMPTY_CONFIG = { accounts: [] };
|
|
20
|
-
function getGlobalConfigFilePath() {
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
exports.getLocalConfigFilePathIfExists = getLocalConfigFilePathIfExists;
|
|
31
|
-
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() {
|
|
32
25
|
return Boolean(getLocalConfigFilePathIfExists());
|
|
33
26
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return (0, utils_1.doesConfigFileExistAtPath)(getGlobalConfigFilePath());
|
|
27
|
+
export function globalConfigFileExists() {
|
|
28
|
+
return doesConfigFileExistAtPath(getGlobalConfigFilePath());
|
|
37
29
|
}
|
|
38
|
-
|
|
39
|
-
function configFileExists() {
|
|
30
|
+
export function configFileExists() {
|
|
40
31
|
try {
|
|
41
|
-
return
|
|
32
|
+
return doesConfigFileExistAtPath(getConfigFilePath());
|
|
42
33
|
}
|
|
43
34
|
catch (error) {
|
|
44
35
|
return false;
|
|
45
36
|
}
|
|
46
37
|
}
|
|
47
|
-
exports.configFileExists = configFileExists;
|
|
48
38
|
function getConfigDefaultFilePath() {
|
|
49
39
|
const globalConfigFilePath = getGlobalConfigFilePath();
|
|
50
|
-
if (
|
|
40
|
+
if (doesConfigFileExistAtPath(globalConfigFilePath)) {
|
|
51
41
|
return globalConfigFilePath;
|
|
52
42
|
}
|
|
53
43
|
const localConfigFilePath = getLocalConfigFilePathIfExists();
|
|
54
44
|
if (!localConfigFilePath) {
|
|
55
|
-
throw new
|
|
45
|
+
throw new HubSpotConfigError(i18n('config.getDefaultConfigFilePath.error'), HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
56
46
|
}
|
|
57
47
|
return localConfigFilePath;
|
|
58
48
|
}
|
|
59
|
-
function getConfigFilePath() {
|
|
60
|
-
const { configFilePathFromEnvironment } =
|
|
49
|
+
export function getConfigFilePath() {
|
|
50
|
+
const { configFilePathFromEnvironment } = getConfigPathEnvironmentVariables();
|
|
61
51
|
return configFilePathFromEnvironment || getConfigDefaultFilePath();
|
|
62
52
|
}
|
|
63
|
-
|
|
64
|
-
function getConfig() {
|
|
53
|
+
export function getConfig() {
|
|
65
54
|
let pathToRead;
|
|
66
55
|
try {
|
|
67
|
-
const { useEnvironmentConfig } =
|
|
56
|
+
const { useEnvironmentConfig } = getConfigPathEnvironmentVariables();
|
|
68
57
|
if (useEnvironmentConfig) {
|
|
69
|
-
return
|
|
58
|
+
return buildConfigFromEnvironment();
|
|
70
59
|
}
|
|
71
60
|
pathToRead = getConfigFilePath();
|
|
72
|
-
|
|
73
|
-
const configFileSource =
|
|
74
|
-
return
|
|
61
|
+
logger.debug(i18n('config.getConfig.reading', { path: pathToRead }));
|
|
62
|
+
const configFileSource = readConfigFile(pathToRead);
|
|
63
|
+
return parseConfig(configFileSource, pathToRead);
|
|
75
64
|
}
|
|
76
65
|
catch (err) {
|
|
77
|
-
throw new
|
|
78
|
-
?
|
|
79
|
-
:
|
|
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 });
|
|
80
69
|
}
|
|
81
70
|
}
|
|
82
|
-
|
|
83
|
-
function validateConfig() {
|
|
71
|
+
export function validateConfig() {
|
|
84
72
|
const config = getConfig();
|
|
85
73
|
if (config.accounts.length === 0) {
|
|
86
74
|
return {
|
|
87
75
|
isValid: false,
|
|
88
|
-
errors: [
|
|
76
|
+
errors: [i18n('config.validateConfig.missingAccounts')],
|
|
89
77
|
};
|
|
90
78
|
}
|
|
91
79
|
const accountIdsMap = {};
|
|
92
80
|
const accountNamesMap = {};
|
|
93
81
|
const validationErrors = [];
|
|
94
82
|
config.accounts.forEach(account => {
|
|
95
|
-
const accountValidationResult =
|
|
83
|
+
const accountValidationResult = validateConfigAccount(account);
|
|
96
84
|
if (!accountValidationResult.isValid) {
|
|
97
85
|
validationErrors.push(...accountValidationResult.errors);
|
|
98
86
|
}
|
|
99
87
|
if (accountIdsMap[account.accountId]) {
|
|
100
|
-
validationErrors.push(
|
|
88
|
+
validationErrors.push(i18n('config.validateConfig.duplicateAccountIds', {
|
|
101
89
|
accountId: account.accountId,
|
|
102
90
|
}));
|
|
103
91
|
}
|
|
104
92
|
if (account.name) {
|
|
105
93
|
if (accountNamesMap[account.name.toLowerCase()]) {
|
|
106
|
-
validationErrors.push(
|
|
94
|
+
validationErrors.push(i18n('config.validateConfig.duplicateAccountNames', {
|
|
107
95
|
accountName: account.name,
|
|
108
96
|
}));
|
|
109
97
|
}
|
|
110
98
|
if (/\s+/.test(account.name)) {
|
|
111
|
-
validationErrors.push(
|
|
99
|
+
validationErrors.push(i18n('config.validateConfig.invalidAccountName', {
|
|
112
100
|
accountName: account.name,
|
|
113
101
|
}));
|
|
114
102
|
}
|
|
@@ -118,273 +106,249 @@ function validateConfig() {
|
|
|
118
106
|
});
|
|
119
107
|
return { isValid: validationErrors.length === 0, errors: validationErrors };
|
|
120
108
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const { configFilePathFromEnvironment } = (0, utils_1.getConfigPathEnvironmentVariables)();
|
|
109
|
+
export function createEmptyConfigFile(useGlobalConfig = false) {
|
|
110
|
+
const { configFilePathFromEnvironment } = getConfigPathEnvironmentVariables();
|
|
124
111
|
const defaultPath = useGlobalConfig
|
|
125
112
|
? getGlobalConfigFilePath()
|
|
126
|
-
:
|
|
113
|
+
: getLocalConfigDefaultFilePath();
|
|
127
114
|
const pathToWrite = configFilePathFromEnvironment || defaultPath;
|
|
128
|
-
|
|
115
|
+
writeConfigFile(EMPTY_CONFIG, pathToWrite);
|
|
129
116
|
}
|
|
130
|
-
|
|
131
|
-
function deleteConfigFileIfEmpty() {
|
|
117
|
+
export function deleteConfigFileIfEmpty() {
|
|
132
118
|
const pathToDelete = getConfigFilePath();
|
|
133
119
|
try {
|
|
134
120
|
const config = getConfig();
|
|
135
|
-
if (
|
|
136
|
-
|
|
121
|
+
if (isDeepEqual(config, EMPTY_CONFIG)) {
|
|
122
|
+
fs.unlinkSync(pathToDelete);
|
|
137
123
|
}
|
|
138
124
|
}
|
|
139
125
|
catch (error) {
|
|
140
|
-
const { message, type } =
|
|
141
|
-
throw new
|
|
126
|
+
const { message, type } = handleConfigFileSystemError(error, pathToDelete);
|
|
127
|
+
throw new HubSpotConfigError(message, type, HUBSPOT_CONFIG_OPERATIONS.DELETE, {
|
|
142
128
|
cause: error,
|
|
143
129
|
});
|
|
144
130
|
}
|
|
145
131
|
}
|
|
146
|
-
|
|
147
|
-
function getConfigAccountById(accountId) {
|
|
132
|
+
export function getConfigAccountById(accountId) {
|
|
148
133
|
const { accounts } = getConfig();
|
|
149
|
-
const account =
|
|
134
|
+
const account = getConfigAccountByIdentifier(accounts, ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountId);
|
|
150
135
|
if (!account) {
|
|
151
|
-
throw new
|
|
136
|
+
throw new HubSpotConfigError(i18n('config.getConfigAccountById.error', { accountId }), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
152
137
|
}
|
|
153
138
|
return account;
|
|
154
139
|
}
|
|
155
|
-
|
|
156
|
-
function getConfigAccountByName(accountName) {
|
|
140
|
+
export function getConfigAccountByName(accountName) {
|
|
157
141
|
const { accounts } = getConfig();
|
|
158
|
-
const account =
|
|
142
|
+
const account = getConfigAccountByIdentifier(accounts, ACCOUNT_IDENTIFIERS.NAME, accountName);
|
|
159
143
|
if (!account) {
|
|
160
|
-
throw new
|
|
144
|
+
throw new HubSpotConfigError(i18n('config.getConfigAccountByName.error', { accountName }), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
161
145
|
}
|
|
162
146
|
return account;
|
|
163
147
|
}
|
|
164
|
-
|
|
165
|
-
function getConfigAccountIfExists(identifier) {
|
|
148
|
+
export function getConfigAccountIfExists(identifier) {
|
|
166
149
|
const config = getConfig();
|
|
167
|
-
return
|
|
150
|
+
return getConfigAccountByInferredIdentifier(config.accounts, identifier);
|
|
168
151
|
}
|
|
169
|
-
|
|
170
|
-
function getConfigDefaultAccount() {
|
|
152
|
+
export function getConfigDefaultAccount() {
|
|
171
153
|
const { accounts, defaultAccount } = getConfig();
|
|
172
154
|
let defaultAccountToUse = defaultAccount;
|
|
173
155
|
const currentConfigPath = getConfigFilePath();
|
|
174
156
|
const globalConfigPath = getGlobalConfigFilePath();
|
|
175
157
|
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
176
|
-
const defaultAccountOverrideAccountId =
|
|
158
|
+
const defaultAccountOverrideAccountId = getDefaultAccountOverrideAccountId(accounts);
|
|
177
159
|
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
178
160
|
}
|
|
179
161
|
if (!defaultAccountToUse) {
|
|
180
|
-
throw new
|
|
162
|
+
throw new HubSpotConfigError(i18n('config.getConfigDefaultAccount.fieldMissingError'), HUBSPOT_CONFIG_ERROR_TYPES.NO_DEFAULT_ACCOUNT, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
181
163
|
}
|
|
182
|
-
const account =
|
|
164
|
+
const account = getConfigAccountByInferredIdentifier(accounts, defaultAccountToUse);
|
|
183
165
|
if (!account) {
|
|
184
|
-
throw new
|
|
166
|
+
throw new HubSpotConfigError(i18n('config.getConfigDefaultAccount.accountMissingError', {
|
|
185
167
|
defaultAccountToUse,
|
|
186
|
-
}),
|
|
168
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
187
169
|
}
|
|
188
170
|
return account;
|
|
189
171
|
}
|
|
190
|
-
|
|
191
|
-
function getConfigDefaultAccountIfExists() {
|
|
172
|
+
export function getConfigDefaultAccountIfExists() {
|
|
192
173
|
const { accounts, defaultAccount } = getConfig();
|
|
193
174
|
let defaultAccountToUse = defaultAccount;
|
|
194
175
|
// Only check for default account override if we're using the global config
|
|
195
176
|
const currentConfigPath = getConfigFilePath();
|
|
196
177
|
const globalConfigPath = getGlobalConfigFilePath();
|
|
197
178
|
if (currentConfigPath === globalConfigPath && globalConfigFileExists()) {
|
|
198
|
-
const defaultAccountOverrideAccountId =
|
|
179
|
+
const defaultAccountOverrideAccountId = getDefaultAccountOverrideAccountId(accounts);
|
|
199
180
|
defaultAccountToUse = defaultAccountOverrideAccountId || defaultAccount;
|
|
200
181
|
}
|
|
201
182
|
if (!defaultAccountToUse) {
|
|
202
183
|
return;
|
|
203
184
|
}
|
|
204
|
-
const account =
|
|
185
|
+
const account = getConfigAccountByInferredIdentifier(accounts, defaultAccountToUse);
|
|
205
186
|
return account;
|
|
206
187
|
}
|
|
207
|
-
|
|
208
|
-
function getAllConfigAccounts() {
|
|
188
|
+
export function getAllConfigAccounts() {
|
|
209
189
|
const { accounts } = getConfig();
|
|
210
190
|
return accounts;
|
|
211
191
|
}
|
|
212
|
-
|
|
213
|
-
function getConfigAccountEnvironment(identifier) {
|
|
192
|
+
export function getConfigAccountEnvironment(identifier) {
|
|
214
193
|
const config = getConfig();
|
|
215
|
-
const account =
|
|
194
|
+
const account = getConfigAccountByInferredIdentifier(config.accounts, identifier);
|
|
216
195
|
if (!account) {
|
|
217
|
-
throw new
|
|
196
|
+
throw new HubSpotConfigError(i18n('config.getConfigAccountEnvironment.accountNotFound', {
|
|
218
197
|
identifier,
|
|
219
|
-
}),
|
|
198
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
220
199
|
}
|
|
221
|
-
return
|
|
200
|
+
return getValidEnv(account.env);
|
|
222
201
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.addConfigAccount.invalidAccount'), config_1.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);
|
|
227
205
|
}
|
|
228
206
|
const config = getConfig();
|
|
229
|
-
const accountInConfig =
|
|
207
|
+
const accountInConfig = getConfigAccountByIdentifier(config.accounts, ACCOUNT_IDENTIFIERS.ACCOUNT_ID, accountToAdd.accountId);
|
|
230
208
|
if (accountInConfig) {
|
|
231
|
-
throw new
|
|
209
|
+
throw new HubSpotConfigError(i18n('config.addConfigAccount.duplicateAccount', {
|
|
232
210
|
accountId: accountToAdd.accountId,
|
|
233
|
-
}),
|
|
211
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
234
212
|
}
|
|
235
213
|
config.accounts.push(accountToAdd);
|
|
236
|
-
|
|
214
|
+
writeConfigFile(config, getConfigFilePath());
|
|
237
215
|
}
|
|
238
|
-
|
|
239
|
-
function updateConfigAccount(updatedAccount) {
|
|
216
|
+
export function updateConfigAccount(updatedAccount) {
|
|
240
217
|
// Skip updating the config file if we're using environment variables
|
|
241
|
-
if (process.env[
|
|
218
|
+
if (process.env[ENVIRONMENT_VARIABLES.USE_ENVIRONMENT_HUBSPOT_CONFIG]) {
|
|
242
219
|
return;
|
|
243
220
|
}
|
|
244
|
-
if (!
|
|
245
|
-
throw new
|
|
221
|
+
if (!validateConfigAccount(updatedAccount)) {
|
|
222
|
+
throw new HubSpotConfigError(i18n('config.updateConfigAccount.invalidAccount', {
|
|
246
223
|
name: updatedAccount.name,
|
|
247
|
-
}),
|
|
224
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
248
225
|
}
|
|
249
226
|
const config = getConfig();
|
|
250
|
-
const accountIndex =
|
|
227
|
+
const accountIndex = getConfigAccountIndexById(config.accounts, updatedAccount.accountId);
|
|
251
228
|
if (accountIndex < 0) {
|
|
252
|
-
throw new
|
|
229
|
+
throw new HubSpotConfigError(i18n('config.updateConfigAccount.accountNotFound', {
|
|
253
230
|
accountId: updatedAccount.accountId,
|
|
254
|
-
}),
|
|
231
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
255
232
|
}
|
|
256
233
|
config.accounts[accountIndex] = updatedAccount;
|
|
257
|
-
|
|
234
|
+
writeConfigFile(config, getConfigFilePath());
|
|
258
235
|
}
|
|
259
|
-
|
|
260
|
-
function setConfigAccountAsDefault(identifier) {
|
|
236
|
+
export function setConfigAccountAsDefault(identifier) {
|
|
261
237
|
const config = getConfig();
|
|
262
|
-
const account =
|
|
238
|
+
const account = getConfigAccountByInferredIdentifier(config.accounts, identifier);
|
|
263
239
|
if (!account) {
|
|
264
|
-
throw new
|
|
240
|
+
throw new HubSpotConfigError(i18n('config.setConfigAccountAsDefault.accountNotFound', {
|
|
265
241
|
identifier,
|
|
266
|
-
}),
|
|
242
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
267
243
|
}
|
|
268
244
|
config.defaultAccount = account.accountId;
|
|
269
|
-
|
|
245
|
+
writeConfigFile(config, getConfigFilePath());
|
|
270
246
|
}
|
|
271
|
-
|
|
272
|
-
function renameConfigAccount(currentName, newName) {
|
|
247
|
+
export function renameConfigAccount(currentName, newName) {
|
|
273
248
|
const config = getConfig();
|
|
274
|
-
const account =
|
|
249
|
+
const account = getConfigAccountByIdentifier(config.accounts, ACCOUNT_IDENTIFIERS.NAME, currentName);
|
|
275
250
|
if (!account) {
|
|
276
|
-
throw new
|
|
251
|
+
throw new HubSpotConfigError(i18n('config.renameConfigAccount.accountNotFound', {
|
|
277
252
|
currentName,
|
|
278
|
-
}),
|
|
253
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
279
254
|
}
|
|
280
|
-
const duplicateAccount =
|
|
255
|
+
const duplicateAccount = getConfigAccountByIdentifier(config.accounts, ACCOUNT_IDENTIFIERS.NAME, newName);
|
|
281
256
|
if (duplicateAccount) {
|
|
282
|
-
throw new
|
|
257
|
+
throw new HubSpotConfigError(i18n('config.renameConfigAccount.duplicateAccount', {
|
|
283
258
|
currentName,
|
|
284
259
|
newName,
|
|
285
|
-
}),
|
|
260
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ACCOUNT, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
286
261
|
}
|
|
287
262
|
account.name = newName;
|
|
288
|
-
|
|
263
|
+
writeConfigFile(config, getConfigFilePath());
|
|
289
264
|
}
|
|
290
|
-
|
|
291
|
-
function removeAccountFromConfig(accountId) {
|
|
265
|
+
export function removeAccountFromConfig(accountId) {
|
|
292
266
|
const config = getConfig();
|
|
293
|
-
const index =
|
|
267
|
+
const index = getConfigAccountIndexById(config.accounts, accountId);
|
|
294
268
|
if (index < 0) {
|
|
295
|
-
throw new
|
|
269
|
+
throw new HubSpotConfigError(i18n('config.removeAccountFromConfig.accountNotFound', {
|
|
296
270
|
accountId,
|
|
297
|
-
}),
|
|
271
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
298
272
|
}
|
|
299
273
|
config.accounts.splice(index, 1);
|
|
300
274
|
if (config.defaultAccount === accountId) {
|
|
301
275
|
delete config.defaultAccount;
|
|
302
276
|
}
|
|
303
|
-
|
|
277
|
+
writeConfigFile(config, getConfigFilePath());
|
|
304
278
|
}
|
|
305
|
-
|
|
306
|
-
function updateHttpTimeout(timeout) {
|
|
279
|
+
export function updateHttpTimeout(timeout) {
|
|
307
280
|
const parsedTimeout = typeof timeout === 'string' ? parseInt(timeout) : timeout;
|
|
308
|
-
if (isNaN(parsedTimeout) || parsedTimeout <
|
|
309
|
-
throw new
|
|
310
|
-
minTimeout:
|
|
281
|
+
if (isNaN(parsedTimeout) || parsedTimeout < MIN_HTTP_TIMEOUT) {
|
|
282
|
+
throw new HubSpotConfigError(i18n('config.updateHttpTimeout.invalidTimeout', {
|
|
283
|
+
minTimeout: MIN_HTTP_TIMEOUT,
|
|
311
284
|
timeout: parsedTimeout,
|
|
312
|
-
}),
|
|
285
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
313
286
|
}
|
|
314
287
|
const config = getConfig();
|
|
315
288
|
config.httpTimeout = parsedTimeout;
|
|
316
|
-
|
|
289
|
+
writeConfigFile(config, getConfigFilePath());
|
|
317
290
|
}
|
|
318
|
-
|
|
319
|
-
function updateAllowUsageTracking(isAllowed) {
|
|
291
|
+
export function updateAllowUsageTracking(isAllowed) {
|
|
320
292
|
if (typeof isAllowed !== 'boolean') {
|
|
321
|
-
throw new
|
|
293
|
+
throw new HubSpotConfigError(i18n('config.updateAllowUsageTracking.invalidInput', {
|
|
322
294
|
isAllowed: `${isAllowed}`,
|
|
323
|
-
}),
|
|
295
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
324
296
|
}
|
|
325
297
|
const config = getConfig();
|
|
326
298
|
config.allowUsageTracking = isAllowed;
|
|
327
|
-
|
|
299
|
+
writeConfigFile(config, getConfigFilePath());
|
|
328
300
|
}
|
|
329
|
-
|
|
330
|
-
function updateAllowAutoUpdates(isEnabled) {
|
|
301
|
+
export function updateAllowAutoUpdates(isEnabled) {
|
|
331
302
|
if (typeof isEnabled !== 'boolean') {
|
|
332
|
-
throw new
|
|
303
|
+
throw new HubSpotConfigError(i18n('config.updateAllowAutoUpdates.invalidInput', {
|
|
333
304
|
isEnabled: `${isEnabled}`,
|
|
334
|
-
}),
|
|
305
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
335
306
|
}
|
|
336
307
|
const config = getConfig();
|
|
337
308
|
config.allowAutoUpdates = isEnabled;
|
|
338
|
-
|
|
309
|
+
writeConfigFile(config, getConfigFilePath());
|
|
339
310
|
}
|
|
340
|
-
|
|
341
|
-
function updateAutoOpenBrowser(isEnabled) {
|
|
311
|
+
export function updateAutoOpenBrowser(isEnabled) {
|
|
342
312
|
if (typeof isEnabled !== 'boolean') {
|
|
343
|
-
throw new
|
|
313
|
+
throw new HubSpotConfigError(i18n('config.updateAutoOpenBrowser.invalidInput', {
|
|
344
314
|
isEnabled: `${isEnabled}`,
|
|
345
|
-
}),
|
|
315
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
346
316
|
}
|
|
347
317
|
const config = getConfig();
|
|
348
318
|
config.autoOpenBrowser = isEnabled;
|
|
349
|
-
|
|
319
|
+
writeConfigFile(config, getConfigFilePath());
|
|
350
320
|
}
|
|
351
|
-
|
|
352
|
-
function updateDefaultCmsPublishMode(cmsPublishMode) {
|
|
321
|
+
export function updateDefaultCmsPublishMode(cmsPublishMode) {
|
|
353
322
|
if (!cmsPublishMode ||
|
|
354
|
-
!Object.values(
|
|
355
|
-
throw new
|
|
323
|
+
!Object.values(CMS_PUBLISH_MODE).includes(cmsPublishMode)) {
|
|
324
|
+
throw new HubSpotConfigError(i18n('config.updateDefaultCmsPublishMode.invalidCmsPublishMode', {
|
|
356
325
|
cmsPublishMode,
|
|
357
|
-
}),
|
|
326
|
+
}), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_FIELD, HUBSPOT_CONFIG_OPERATIONS.WRITE);
|
|
358
327
|
}
|
|
359
328
|
const config = getConfig();
|
|
360
329
|
config.defaultCmsPublishMode = cmsPublishMode;
|
|
361
|
-
|
|
330
|
+
writeConfigFile(config, getConfigFilePath());
|
|
362
331
|
}
|
|
363
|
-
|
|
364
|
-
function isConfigFlagEnabled(flag, defaultValue) {
|
|
332
|
+
export function isConfigFlagEnabled(flag, defaultValue) {
|
|
365
333
|
const config = getConfig();
|
|
366
334
|
if (typeof config[flag] === 'undefined') {
|
|
367
335
|
return defaultValue || false;
|
|
368
336
|
}
|
|
369
337
|
return Boolean(config[flag]);
|
|
370
338
|
}
|
|
371
|
-
|
|
372
|
-
function hasLocalStateFlag(flag) {
|
|
339
|
+
export function hasLocalStateFlag(flag) {
|
|
373
340
|
const config = getConfig();
|
|
374
341
|
return config.flags?.includes(flag) || false;
|
|
375
342
|
}
|
|
376
|
-
|
|
377
|
-
function addLocalStateFlag(flag) {
|
|
343
|
+
export function addLocalStateFlag(flag) {
|
|
378
344
|
const config = getConfig();
|
|
379
345
|
if (!hasLocalStateFlag(flag)) {
|
|
380
346
|
config.flags = [...(config.flags || []), flag];
|
|
381
347
|
}
|
|
382
|
-
|
|
348
|
+
writeConfigFile(config, getConfigFilePath());
|
|
383
349
|
}
|
|
384
|
-
|
|
385
|
-
function removeLocalStateFlag(flag) {
|
|
350
|
+
export function removeLocalStateFlag(flag) {
|
|
386
351
|
const config = getConfig();
|
|
387
352
|
config.flags = config.flags?.filter(f => f !== flag) || [];
|
|
388
|
-
|
|
353
|
+
writeConfigFile(config, getConfigFilePath());
|
|
389
354
|
}
|
|
390
|
-
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 = {
|