@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
package/config/migrate.js
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const config_1 = require("../constants/config");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
function getConfigAtPath(path) {
|
|
13
|
-
const configFileSource = (0, utils_1.readConfigFile)(path);
|
|
14
|
-
return (0, utils_1.parseConfig)(configFileSource, path);
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { createEmptyConfigFile, getGlobalConfigFilePath } from './index.js';
|
|
3
|
+
import { ENV, DEFAULT_ACCOUNT, ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME, CONFIG_FLAGS, } from '../constants/config.js';
|
|
4
|
+
import { parseConfig, readConfigFile, writeConfigFile } from './utils.js';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
export function getConfigAtPath(path) {
|
|
7
|
+
const configFileSource = readConfigFile(path);
|
|
8
|
+
return parseConfig(configFileSource, path);
|
|
15
9
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(0, index_1.createEmptyConfigFile)(true);
|
|
10
|
+
export function migrateConfigAtPath(path) {
|
|
11
|
+
createEmptyConfigFile(true);
|
|
19
12
|
const configToMigrate = getConfigAtPath(path);
|
|
20
|
-
|
|
13
|
+
writeConfigFile(configToMigrate, getGlobalConfigFilePath());
|
|
21
14
|
}
|
|
22
|
-
|
|
23
|
-
function mergeConfigProperties(toConfig, fromConfig, force) {
|
|
15
|
+
export function mergeConfigProperties(toConfig, fromConfig, force) {
|
|
24
16
|
const conflicts = [];
|
|
25
17
|
if (force) {
|
|
26
18
|
toConfig.defaultCmsPublishMode = fromConfig.defaultCmsPublishMode;
|
|
@@ -54,14 +46,14 @@ function mergeConfigProperties(toConfig, fromConfig, force) {
|
|
|
54
46
|
: toConfig.allowAutoUpdates;
|
|
55
47
|
toConfig.defaultAccount ||= fromConfig.defaultAccount;
|
|
56
48
|
const propertiesToCheck = [
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
CONFIG_FLAGS.DEFAULT_CMS_PUBLISH_MODE,
|
|
50
|
+
CONFIG_FLAGS.HTTP_TIMEOUT,
|
|
51
|
+
CONFIG_FLAGS.HTTP_USE_LOCALHOST,
|
|
52
|
+
CONFIG_FLAGS.ALLOW_USAGE_TRACKING,
|
|
53
|
+
CONFIG_FLAGS.AUTO_OPEN_BROWSER,
|
|
54
|
+
CONFIG_FLAGS.ALLOW_AUTO_UPDATES,
|
|
55
|
+
ENV,
|
|
56
|
+
DEFAULT_ACCOUNT,
|
|
65
57
|
];
|
|
66
58
|
propertiesToCheck.forEach(prop => {
|
|
67
59
|
if (toConfig[prop] !== undefined &&
|
|
@@ -81,7 +73,6 @@ function mergeConfigProperties(toConfig, fromConfig, force) {
|
|
|
81
73
|
}
|
|
82
74
|
return { configWithMergedProperties: toConfig, conflicts };
|
|
83
75
|
}
|
|
84
|
-
exports.mergeConfigProperties = mergeConfigProperties;
|
|
85
76
|
function buildConfigWithMergedAccounts(toConfig, fromConfig) {
|
|
86
77
|
const existingAccountIds = toConfig.accounts.map(({ accountId }) => accountId);
|
|
87
78
|
const skippedAccountIds = [];
|
|
@@ -98,15 +89,13 @@ function buildConfigWithMergedAccounts(toConfig, fromConfig) {
|
|
|
98
89
|
skippedAccountIds,
|
|
99
90
|
};
|
|
100
91
|
}
|
|
101
|
-
function mergeConfigAccounts(toConfig, fromConfig) {
|
|
92
|
+
export function mergeConfigAccounts(toConfig, fromConfig) {
|
|
102
93
|
const { configWithMergedAccounts, skippedAccountIds } = buildConfigWithMergedAccounts(toConfig, fromConfig);
|
|
103
|
-
|
|
94
|
+
writeConfigFile(configWithMergedAccounts, getGlobalConfigFilePath());
|
|
104
95
|
return { configWithMergedAccounts, skippedAccountIds };
|
|
105
96
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
fs_1.default.renameSync(configPath, archivedConfigPath);
|
|
97
|
+
export function archiveConfigAtPath(configPath) {
|
|
98
|
+
const dir = path.dirname(configPath);
|
|
99
|
+
const archivedConfigPath = path.join(dir, ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME);
|
|
100
|
+
fs.renameSync(configPath, archivedConfigPath);
|
|
111
101
|
}
|
|
112
|
-
exports.archiveConfigAtPath = archiveConfigAtPath;
|
package/config/state.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HubSpotState } from '../types/Config';
|
|
1
|
+
import { HubSpotState } from '../types/Config.js';
|
|
2
2
|
export declare function getStateValue<K extends keyof HubSpotState>(key: K): HubSpotState[K];
|
|
3
3
|
export declare function setStateValue<K extends keyof HubSpotState>(key: K, value: HubSpotState[K]): void;
|
package/config/state.js
CHANGED
|
@@ -1,48 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.setStateValue = exports.getStateValue = void 0;
|
|
27
|
-
const fs = __importStar(require("fs"));
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const lang_1 = require("../utils/lang");
|
|
30
|
-
const config_1 = require("../constants/config");
|
|
31
|
-
const logger_1 = require("../lib/logger");
|
|
32
|
-
const config_2 = require("../constants/config");
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { i18n } from '../utils/lang.js';
|
|
4
|
+
import { STATE_FILE_PATH } from '../constants/config.js';
|
|
5
|
+
import { logger } from '../lib/logger.js';
|
|
6
|
+
import { STATE_FLAGS } from '../constants/config.js';
|
|
33
7
|
const i18nKey = 'config.state';
|
|
34
8
|
const DEFAULT_STATE = {
|
|
35
|
-
[
|
|
9
|
+
[STATE_FLAGS.MCP_TOTAL_TOOL_CALLS]: 0,
|
|
36
10
|
};
|
|
37
11
|
function ensureCLIDirectory() {
|
|
38
12
|
try {
|
|
39
|
-
const dir = path.dirname(
|
|
13
|
+
const dir = path.dirname(STATE_FILE_PATH);
|
|
40
14
|
if (!fs.existsSync(dir)) {
|
|
41
15
|
fs.mkdirSync(dir, { recursive: true });
|
|
42
16
|
}
|
|
43
17
|
}
|
|
44
18
|
catch (error) {
|
|
45
|
-
throw new Error(
|
|
19
|
+
throw new Error(i18n(`${i18nKey}.ensureCLIDirectory.errors.cannotCreateDirectory`, {
|
|
46
20
|
error: error instanceof Error ? error.message : String(error),
|
|
47
21
|
}));
|
|
48
22
|
}
|
|
@@ -65,41 +39,39 @@ function sanitizeAndMerge(parsed) {
|
|
|
65
39
|
}
|
|
66
40
|
function getCurrentState() {
|
|
67
41
|
try {
|
|
68
|
-
if (!fs.existsSync(
|
|
42
|
+
if (!fs.existsSync(STATE_FILE_PATH)) {
|
|
69
43
|
return structuredClone(DEFAULT_STATE);
|
|
70
44
|
}
|
|
71
|
-
const data = fs.readFileSync(
|
|
45
|
+
const data = fs.readFileSync(STATE_FILE_PATH, 'utf-8');
|
|
72
46
|
if (!data?.trim()) {
|
|
73
|
-
|
|
47
|
+
logger.debug(i18n(`${i18nKey}.getCurrentState.debug.emptyStateFile`));
|
|
74
48
|
return structuredClone(DEFAULT_STATE);
|
|
75
49
|
}
|
|
76
50
|
const parsed = JSON.parse(data);
|
|
77
51
|
return sanitizeAndMerge(parsed);
|
|
78
52
|
}
|
|
79
53
|
catch (error) {
|
|
80
|
-
|
|
54
|
+
logger.debug(i18n(`${i18nKey}.getCurrentState.errors.errorReading`, {
|
|
81
55
|
error: error instanceof Error ? error.message : String(error),
|
|
82
56
|
}));
|
|
83
57
|
return structuredClone(DEFAULT_STATE);
|
|
84
58
|
}
|
|
85
59
|
}
|
|
86
|
-
function getStateValue(key) {
|
|
60
|
+
export function getStateValue(key) {
|
|
87
61
|
ensureCLIDirectory();
|
|
88
62
|
const state = getCurrentState();
|
|
89
63
|
return state[key];
|
|
90
64
|
}
|
|
91
|
-
|
|
92
|
-
function setStateValue(key, value) {
|
|
65
|
+
export function setStateValue(key, value) {
|
|
93
66
|
ensureCLIDirectory();
|
|
94
67
|
const currentState = getCurrentState();
|
|
95
68
|
const newState = { ...currentState, [key]: value };
|
|
96
69
|
try {
|
|
97
|
-
fs.writeFileSync(
|
|
70
|
+
fs.writeFileSync(STATE_FILE_PATH, JSON.stringify(newState, null, 2), 'utf-8');
|
|
98
71
|
}
|
|
99
72
|
catch (error) {
|
|
100
|
-
throw new Error(
|
|
73
|
+
throw new Error(i18n(`${i18nKey}.setStateValue.errors.failedToWrite`, {
|
|
101
74
|
error: error instanceof Error ? error.message : String(error),
|
|
102
75
|
}));
|
|
103
76
|
}
|
|
104
77
|
}
|
|
105
|
-
exports.setStateValue = setStateValue;
|
package/config/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ACCOUNT_IDENTIFIERS } from '../constants/config';
|
|
2
|
-
import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType, HubSpotConfigValidationResult } from '../types/Config';
|
|
3
|
-
import { HubSpotConfigAccount } from '../types/Accounts';
|
|
4
|
-
import { ValueOf } from '../types/Utils';
|
|
1
|
+
import { ACCOUNT_IDENTIFIERS } from '../constants/config.js';
|
|
2
|
+
import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType, HubSpotConfigValidationResult } from '../types/Config.js';
|
|
3
|
+
import { HubSpotConfigAccount } from '../types/Accounts.js';
|
|
4
|
+
import { ValueOf } from '../types/Utils.js';
|
|
5
5
|
export declare function getLocalConfigDefaultFilePath(): string;
|
|
6
6
|
export declare function getConfigPathEnvironmentVariables(): {
|
|
7
7
|
useEnvironmentConfig: boolean;
|
package/config/utils.js
CHANGED
|
@@ -1,57 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const path_1 = require("../lib/path");
|
|
14
|
-
const files_1 = require("../constants/files");
|
|
15
|
-
const lang_1 = require("../utils/lang");
|
|
16
|
-
const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
|
|
17
|
-
function getLocalConfigDefaultFilePath() {
|
|
18
|
-
return `${(0, path_1.getCwd)()}/${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}`;
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import yaml from 'js-yaml';
|
|
3
|
+
import { HUBSPOT_ACCOUNT_TYPES, DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME, ENVIRONMENT_VARIABLES, ACCOUNT_IDENTIFIERS, HUBSPOT_CONFIG_ERROR_TYPES, HUBSPOT_CONFIG_OPERATIONS, GLOBAL_CONFIG_PATH, } from '../constants/config.js';
|
|
4
|
+
import { PERSONAL_ACCESS_KEY_AUTH_METHOD, API_KEY_AUTH_METHOD, OAUTH_AUTH_METHOD, OAUTH_SCOPES, } from '../constants/auth.js';
|
|
5
|
+
import { FileSystemError } from '../models/FileSystemError.js';
|
|
6
|
+
import { getValidEnv } from '../lib/environment.js';
|
|
7
|
+
import { getCwd } from '../lib/path.js';
|
|
8
|
+
import { CMS_PUBLISH_MODE } from '../constants/files.js';
|
|
9
|
+
import { i18n } from '../utils/lang.js';
|
|
10
|
+
import { HubSpotConfigError } from '../models/HubSpotConfigError.js';
|
|
11
|
+
export function getLocalConfigDefaultFilePath() {
|
|
12
|
+
return `${getCwd()}/${DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}`;
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const useEnvironmentConfig = process.env[config_1.ENVIRONMENT_VARIABLES.USE_ENVIRONMENT_HUBSPOT_CONFIG] ===
|
|
14
|
+
export function getConfigPathEnvironmentVariables() {
|
|
15
|
+
const configFilePathFromEnvironment = process.env[ENVIRONMENT_VARIABLES.HUBSPOT_CONFIG_PATH];
|
|
16
|
+
const useEnvironmentConfig = process.env[ENVIRONMENT_VARIABLES.USE_ENVIRONMENT_HUBSPOT_CONFIG] ===
|
|
24
17
|
'true';
|
|
25
18
|
if (configFilePathFromEnvironment && useEnvironmentConfig) {
|
|
26
|
-
throw new
|
|
19
|
+
throw new HubSpotConfigError(i18n('config.utils.getConfigPathEnvironmentVariables.invalidEnvironmentVariables'), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
27
20
|
}
|
|
28
21
|
return {
|
|
29
22
|
configFilePathFromEnvironment,
|
|
30
23
|
useEnvironmentConfig,
|
|
31
24
|
};
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
function doesConfigFileExistAtPath(path) {
|
|
26
|
+
export function doesConfigFileExistAtPath(path) {
|
|
35
27
|
try {
|
|
36
|
-
return
|
|
28
|
+
return fs.existsSync(path);
|
|
37
29
|
}
|
|
38
30
|
catch (error) {
|
|
39
31
|
const { message, type } = handleConfigFileSystemError(error, path);
|
|
40
|
-
throw new
|
|
32
|
+
throw new HubSpotConfigError(message, type, HUBSPOT_CONFIG_OPERATIONS.READ, { cause: error });
|
|
41
33
|
}
|
|
42
34
|
}
|
|
43
|
-
|
|
44
|
-
function readConfigFile(configPath) {
|
|
35
|
+
export function readConfigFile(configPath) {
|
|
45
36
|
try {
|
|
46
|
-
return
|
|
37
|
+
return fs.readFileSync(configPath).toString();
|
|
47
38
|
}
|
|
48
39
|
catch (err) {
|
|
49
40
|
const { message, type } = handleConfigFileSystemError(err, configPath);
|
|
50
|
-
throw new
|
|
41
|
+
throw new HubSpotConfigError(message, type, HUBSPOT_CONFIG_OPERATIONS.READ, { cause: err });
|
|
51
42
|
}
|
|
52
43
|
}
|
|
53
|
-
|
|
54
|
-
function removeUndefinedFieldsFromConfigAccount(account) {
|
|
44
|
+
export function removeUndefinedFieldsFromConfigAccount(account) {
|
|
55
45
|
Object.keys(account).forEach(k => {
|
|
56
46
|
const key = k;
|
|
57
47
|
if (account[key] === undefined) {
|
|
@@ -59,7 +49,7 @@ function removeUndefinedFieldsFromConfigAccount(account) {
|
|
|
59
49
|
}
|
|
60
50
|
});
|
|
61
51
|
if ('auth' in account && account.auth) {
|
|
62
|
-
if (account.authType ===
|
|
52
|
+
if (account.authType === OAUTH_AUTH_METHOD.value) {
|
|
63
53
|
Object.keys(account.auth).forEach(k => {
|
|
64
54
|
const key = k;
|
|
65
55
|
if (account.auth?.[key] === undefined) {
|
|
@@ -79,9 +69,8 @@ function removeUndefinedFieldsFromConfigAccount(account) {
|
|
|
79
69
|
}
|
|
80
70
|
return account;
|
|
81
71
|
}
|
|
82
|
-
exports.removeUndefinedFieldsFromConfigAccount = removeUndefinedFieldsFromConfigAccount;
|
|
83
72
|
// Ensure written config files have fields in a consistent order
|
|
84
|
-
function formatConfigForWrite(config) {
|
|
73
|
+
export function formatConfigForWrite(config) {
|
|
85
74
|
const { defaultAccount, defaultCmsPublishMode, httpTimeout, allowUsageTracking, accounts, ...rest } = config;
|
|
86
75
|
const orderedConfig = {
|
|
87
76
|
...(defaultAccount && { defaultAccount }),
|
|
@@ -104,37 +93,35 @@ function formatConfigForWrite(config) {
|
|
|
104
93
|
};
|
|
105
94
|
return orderedConfig;
|
|
106
95
|
}
|
|
107
|
-
|
|
108
|
-
function writeConfigFile(config, configPath) {
|
|
96
|
+
export function writeConfigFile(config, configPath) {
|
|
109
97
|
const formattedConfig = formatConfigForWrite(config);
|
|
110
|
-
const configToWrite = configPath ==
|
|
98
|
+
const configToWrite = configPath == GLOBAL_CONFIG_PATH
|
|
111
99
|
? formattedConfig
|
|
112
100
|
: convertToDeprecatedConfig(formattedConfig);
|
|
113
|
-
const source =
|
|
101
|
+
const source = yaml.dump(configToWrite);
|
|
114
102
|
try {
|
|
115
|
-
|
|
116
|
-
|
|
103
|
+
fs.ensureFileSync(configPath);
|
|
104
|
+
fs.writeFileSync(configPath, source);
|
|
117
105
|
}
|
|
118
106
|
catch (err) {
|
|
119
|
-
throw new
|
|
107
|
+
throw new FileSystemError({ cause: err }, {
|
|
120
108
|
filepath: configPath,
|
|
121
109
|
operation: 'write',
|
|
122
110
|
});
|
|
123
111
|
}
|
|
124
112
|
}
|
|
125
|
-
exports.writeConfigFile = writeConfigFile;
|
|
126
113
|
function getAccountType(sandboxAccountType) {
|
|
127
114
|
if (sandboxAccountType) {
|
|
128
115
|
if (sandboxAccountType.toUpperCase() === 'DEVELOPER') {
|
|
129
|
-
return
|
|
116
|
+
return HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX;
|
|
130
117
|
}
|
|
131
118
|
if (sandboxAccountType.toUpperCase() === 'STANDARD') {
|
|
132
|
-
return
|
|
119
|
+
return HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX;
|
|
133
120
|
}
|
|
134
121
|
}
|
|
135
|
-
return
|
|
122
|
+
return HUBSPOT_ACCOUNT_TYPES.STANDARD;
|
|
136
123
|
}
|
|
137
|
-
function normalizeParsedConfig(parsedConfig) {
|
|
124
|
+
export function normalizeParsedConfig(parsedConfig) {
|
|
138
125
|
if (!parsedConfig.portals && !parsedConfig.accounts) {
|
|
139
126
|
parsedConfig.accounts = [];
|
|
140
127
|
}
|
|
@@ -165,11 +152,10 @@ function normalizeParsedConfig(parsedConfig) {
|
|
|
165
152
|
}
|
|
166
153
|
return parsedConfig;
|
|
167
154
|
}
|
|
168
|
-
|
|
169
|
-
function convertToDeprecatedConfig(config) {
|
|
155
|
+
export function convertToDeprecatedConfig(config) {
|
|
170
156
|
const deprecatedConfig = structuredClone(config);
|
|
171
157
|
if (config.defaultAccount) {
|
|
172
|
-
const defaultAccount = getConfigAccountByIdentifier(config.accounts,
|
|
158
|
+
const defaultAccount = getConfigAccountByIdentifier(config.accounts, ACCOUNT_IDENTIFIERS.ACCOUNT_ID, config.defaultAccount);
|
|
173
159
|
if (defaultAccount) {
|
|
174
160
|
deprecatedConfig.defaultPortal = defaultAccount.name;
|
|
175
161
|
delete deprecatedConfig.defaultAccount;
|
|
@@ -189,33 +175,31 @@ function convertToDeprecatedConfig(config) {
|
|
|
189
175
|
delete deprecatedConfig.accounts;
|
|
190
176
|
return deprecatedConfig;
|
|
191
177
|
}
|
|
192
|
-
|
|
193
|
-
function parseConfig(configSource, configPath) {
|
|
178
|
+
export function parseConfig(configSource, configPath) {
|
|
194
179
|
let parsedYaml;
|
|
195
180
|
try {
|
|
196
|
-
parsedYaml =
|
|
181
|
+
parsedYaml = yaml.load(configSource);
|
|
197
182
|
}
|
|
198
183
|
catch (err) {
|
|
199
|
-
throw new
|
|
184
|
+
throw new HubSpotConfigError(i18n('config.utils.parseConfig.error', { configPath: configPath }), HUBSPOT_CONFIG_ERROR_TYPES.YAML_PARSING, HUBSPOT_CONFIG_OPERATIONS.READ, { cause: err });
|
|
200
185
|
}
|
|
201
186
|
return normalizeParsedConfig(parsedYaml);
|
|
202
187
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
const
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
const
|
|
216
|
-
const defaultCmsPublishModeVar = process.env[config_1.ENVIRONMENT_VARIABLES.DEFAULT_CMS_PUBLISH_MODE];
|
|
188
|
+
export function buildConfigFromEnvironment() {
|
|
189
|
+
const apiKey = process.env[ENVIRONMENT_VARIABLES.HUBSPOT_API_KEY];
|
|
190
|
+
const clientId = process.env[ENVIRONMENT_VARIABLES.HUBSPOT_CLIENT_ID];
|
|
191
|
+
const clientSecret = process.env[ENVIRONMENT_VARIABLES.HUBSPOT_CLIENT_SECRET];
|
|
192
|
+
const personalAccessKey = process.env[ENVIRONMENT_VARIABLES.HUBSPOT_PERSONAL_ACCESS_KEY];
|
|
193
|
+
const accountIdVar = process.env[ENVIRONMENT_VARIABLES.HUBSPOT_ACCOUNT_ID] ||
|
|
194
|
+
process.env[ENVIRONMENT_VARIABLES.HUBSPOT_PORTAL_ID];
|
|
195
|
+
const refreshToken = process.env[ENVIRONMENT_VARIABLES.HUBSPOT_REFRESH_TOKEN];
|
|
196
|
+
const hubspotEnvironment = process.env[ENVIRONMENT_VARIABLES.HUBSPOT_ENVIRONMENT];
|
|
197
|
+
const httpTimeoutVar = process.env[ENVIRONMENT_VARIABLES.HTTP_TIMEOUT];
|
|
198
|
+
const httpUseLocalhostVar = process.env[ENVIRONMENT_VARIABLES.HTTP_USE_LOCALHOST];
|
|
199
|
+
const allowUsageTrackingVar = process.env[ENVIRONMENT_VARIABLES.ALLOW_USAGE_TRACKING];
|
|
200
|
+
const defaultCmsPublishModeVar = process.env[ENVIRONMENT_VARIABLES.DEFAULT_CMS_PUBLISH_MODE];
|
|
217
201
|
if (!accountIdVar) {
|
|
218
|
-
throw new
|
|
202
|
+
throw new HubSpotConfigError(i18n('config.utils.buildConfigFromEnvironment.missingAccountId'), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
219
203
|
}
|
|
220
204
|
const accountId = parseInt(accountIdVar);
|
|
221
205
|
const httpTimeout = httpTimeoutVar ? parseInt(httpTimeoutVar) : undefined;
|
|
@@ -225,15 +209,15 @@ function buildConfigFromEnvironment() {
|
|
|
225
209
|
const allowUsageTracking = allowUsageTrackingVar
|
|
226
210
|
? allowUsageTrackingVar === 'true'
|
|
227
211
|
: undefined;
|
|
228
|
-
const defaultCmsPublishMode = defaultCmsPublishModeVar ===
|
|
229
|
-
defaultCmsPublishModeVar ===
|
|
212
|
+
const defaultCmsPublishMode = defaultCmsPublishModeVar === CMS_PUBLISH_MODE.draft ||
|
|
213
|
+
defaultCmsPublishModeVar === CMS_PUBLISH_MODE.publish
|
|
230
214
|
? defaultCmsPublishModeVar
|
|
231
215
|
: undefined;
|
|
232
|
-
const env =
|
|
216
|
+
const env = getValidEnv(hubspotEnvironment);
|
|
233
217
|
let account;
|
|
234
218
|
if (personalAccessKey) {
|
|
235
219
|
account = {
|
|
236
|
-
authType:
|
|
220
|
+
authType: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
237
221
|
accountId,
|
|
238
222
|
personalAccessKey,
|
|
239
223
|
env,
|
|
@@ -245,12 +229,12 @@ function buildConfigFromEnvironment() {
|
|
|
245
229
|
}
|
|
246
230
|
else if (clientId && clientSecret && refreshToken) {
|
|
247
231
|
account = {
|
|
248
|
-
authType:
|
|
232
|
+
authType: OAUTH_AUTH_METHOD.value,
|
|
249
233
|
accountId,
|
|
250
234
|
auth: {
|
|
251
235
|
clientId,
|
|
252
236
|
clientSecret,
|
|
253
|
-
scopes:
|
|
237
|
+
scopes: OAUTH_SCOPES.map((scope) => scope.value),
|
|
254
238
|
tokenInfo: {
|
|
255
239
|
refreshToken,
|
|
256
240
|
},
|
|
@@ -261,7 +245,7 @@ function buildConfigFromEnvironment() {
|
|
|
261
245
|
}
|
|
262
246
|
else if (apiKey) {
|
|
263
247
|
account = {
|
|
264
|
-
authType:
|
|
248
|
+
authType: API_KEY_AUTH_METHOD.value,
|
|
265
249
|
accountId,
|
|
266
250
|
apiKey,
|
|
267
251
|
env,
|
|
@@ -269,7 +253,7 @@ function buildConfigFromEnvironment() {
|
|
|
269
253
|
};
|
|
270
254
|
}
|
|
271
255
|
else {
|
|
272
|
-
throw new
|
|
256
|
+
throw new HubSpotConfigError(i18n('config.utils.buildConfigFromEnvironment.invalidAuthType'), HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES, HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
273
257
|
}
|
|
274
258
|
return {
|
|
275
259
|
accounts: [account],
|
|
@@ -280,8 +264,7 @@ function buildConfigFromEnvironment() {
|
|
|
280
264
|
defaultCmsPublishMode,
|
|
281
265
|
};
|
|
282
266
|
}
|
|
283
|
-
|
|
284
|
-
function getAccountIdentifierAndType(accountIdentifier) {
|
|
267
|
+
export function getAccountIdentifierAndType(accountIdentifier) {
|
|
285
268
|
const identifierAsNumber = typeof accountIdentifier === 'number'
|
|
286
269
|
? accountIdentifier
|
|
287
270
|
: parseInt(accountIdentifier);
|
|
@@ -289,85 +272,79 @@ function getAccountIdentifierAndType(accountIdentifier) {
|
|
|
289
272
|
return {
|
|
290
273
|
identifier: isId ? identifierAsNumber : accountIdentifier,
|
|
291
274
|
identifierType: isId
|
|
292
|
-
?
|
|
293
|
-
:
|
|
275
|
+
? ACCOUNT_IDENTIFIERS.ACCOUNT_ID
|
|
276
|
+
: ACCOUNT_IDENTIFIERS.NAME,
|
|
294
277
|
};
|
|
295
278
|
}
|
|
296
|
-
|
|
297
|
-
function getConfigAccountByIdentifier(accounts, identifierFieldName, identifier) {
|
|
279
|
+
export function getConfigAccountByIdentifier(accounts, identifierFieldName, identifier) {
|
|
298
280
|
return accounts.find(account => account[identifierFieldName] === identifier);
|
|
299
281
|
}
|
|
300
|
-
|
|
301
|
-
function getConfigAccountByInferredIdentifier(accounts, accountIdentifier) {
|
|
282
|
+
export function getConfigAccountByInferredIdentifier(accounts, accountIdentifier) {
|
|
302
283
|
const { identifier, identifierType } = getAccountIdentifierAndType(accountIdentifier);
|
|
303
284
|
const account = getConfigAccountByIdentifier(accounts, identifierType, identifier);
|
|
304
285
|
if (account) {
|
|
305
286
|
return account;
|
|
306
287
|
}
|
|
307
288
|
// Fallback to handle accounts with numbers as names
|
|
308
|
-
return getConfigAccountByIdentifier(accounts,
|
|
289
|
+
return getConfigAccountByIdentifier(accounts, ACCOUNT_IDENTIFIERS.NAME, String(accountIdentifier));
|
|
309
290
|
}
|
|
310
|
-
|
|
311
|
-
function getConfigAccountIndexById(accounts, id) {
|
|
291
|
+
export function getConfigAccountIndexById(accounts, id) {
|
|
312
292
|
return accounts.findIndex(account => account.accountId === id);
|
|
313
293
|
}
|
|
314
|
-
|
|
315
|
-
function validateConfigAccount(account) {
|
|
294
|
+
export function validateConfigAccount(account) {
|
|
316
295
|
const validationErrors = [];
|
|
317
296
|
if (!account || typeof account !== 'object') {
|
|
318
|
-
validationErrors.push(
|
|
297
|
+
validationErrors.push(i18n('config.utils.validateConfigAccount.missingAccount'));
|
|
319
298
|
return { isValid: false, errors: validationErrors };
|
|
320
299
|
}
|
|
321
300
|
if (!account.accountId) {
|
|
322
|
-
validationErrors.push(
|
|
301
|
+
validationErrors.push(i18n('config.utils.validateConfigAccount.missingAccountId'));
|
|
323
302
|
return { isValid: false, errors: validationErrors };
|
|
324
303
|
}
|
|
325
304
|
if (!account.authType) {
|
|
326
|
-
validationErrors.push(
|
|
305
|
+
validationErrors.push(i18n('config.utils.validateConfigAccount.missingAuthType', {
|
|
327
306
|
accountId: account.accountId,
|
|
328
307
|
}));
|
|
329
308
|
return { isValid: false, errors: validationErrors };
|
|
330
309
|
}
|
|
331
|
-
if (account.authType ===
|
|
310
|
+
if (account.authType === PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
332
311
|
const isValidPersonalAccessKeyAccount = 'personalAccessKey' in account && Boolean(account.personalAccessKey);
|
|
333
312
|
if (!isValidPersonalAccessKeyAccount) {
|
|
334
|
-
validationErrors.push(
|
|
313
|
+
validationErrors.push(i18n('config.utils.validateConfigAccount.missingPersonalAccessKey', {
|
|
335
314
|
accountId: account.accountId,
|
|
336
315
|
}));
|
|
337
316
|
}
|
|
338
317
|
}
|
|
339
|
-
if (account.authType ===
|
|
318
|
+
if (account.authType === OAUTH_AUTH_METHOD.value) {
|
|
340
319
|
const isValidOAuthAccount = 'auth' in account && Boolean(account.auth);
|
|
341
320
|
if (!isValidOAuthAccount) {
|
|
342
|
-
validationErrors.push(
|
|
321
|
+
validationErrors.push(i18n('config.utils.validateConfigAccount.missingAuth', {
|
|
343
322
|
accountId: account.accountId,
|
|
344
323
|
}));
|
|
345
324
|
}
|
|
346
325
|
}
|
|
347
|
-
if (account.authType ===
|
|
326
|
+
if (account.authType === API_KEY_AUTH_METHOD.value) {
|
|
348
327
|
const isValidAPIKeyAccount = 'apiKey' in account && Boolean(account.apiKey);
|
|
349
328
|
if (!isValidAPIKeyAccount) {
|
|
350
|
-
validationErrors.push(
|
|
329
|
+
validationErrors.push(i18n('config.utils.validateConfigAccount.missingApiKey', {
|
|
351
330
|
accountId: account.accountId,
|
|
352
331
|
}));
|
|
353
332
|
}
|
|
354
333
|
}
|
|
355
334
|
return { isValid: validationErrors.length === 0, errors: validationErrors };
|
|
356
335
|
}
|
|
357
|
-
|
|
358
|
-
function handleConfigFileSystemError(error, path) {
|
|
336
|
+
export function handleConfigFileSystemError(error, path) {
|
|
359
337
|
let message;
|
|
360
|
-
let type =
|
|
338
|
+
let type = HUBSPOT_CONFIG_ERROR_TYPES.UNKNOWN;
|
|
361
339
|
if (error instanceof Error && 'code' in error) {
|
|
362
340
|
if (error.code === 'ENOENT') {
|
|
363
|
-
message =
|
|
364
|
-
type =
|
|
341
|
+
message = i18n('config.utils.handleConfigFileSystemError.configNotFoundError', { path });
|
|
342
|
+
type = HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND;
|
|
365
343
|
}
|
|
366
344
|
else if (error.code === 'EACCES') {
|
|
367
|
-
message =
|
|
368
|
-
type =
|
|
345
|
+
message = i18n('config.utils.handleConfigFileSystemError.insufficientPermissionsError', { path });
|
|
346
|
+
type = HUBSPOT_CONFIG_ERROR_TYPES.INSUFFICIENT_PERMISSIONS;
|
|
369
347
|
}
|
|
370
348
|
}
|
|
371
349
|
return { message, type };
|
|
372
350
|
}
|
|
373
|
-
exports.handleConfigFileSystemError = handleConfigFileSystemError;
|
package/constants/api.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SANDBOX_TIMEOUT = exports.HTTP_METHOD_PREPOSITIONS = exports.HTTP_METHOD_VERBS = void 0;
|
|
4
|
-
exports.HTTP_METHOD_VERBS = {
|
|
1
|
+
export const HTTP_METHOD_VERBS = {
|
|
5
2
|
delete: 'delete',
|
|
6
3
|
get: 'request',
|
|
7
4
|
patch: 'update',
|
|
8
5
|
post: 'post',
|
|
9
6
|
put: 'update',
|
|
10
7
|
};
|
|
11
|
-
|
|
8
|
+
export const HTTP_METHOD_PREPOSITIONS = {
|
|
12
9
|
delete: 'of',
|
|
13
10
|
get: 'for',
|
|
14
11
|
patch: 'to',
|
|
15
12
|
post: 'to',
|
|
16
13
|
put: 'to',
|
|
17
14
|
};
|
|
18
|
-
|
|
15
|
+
export const SANDBOX_TIMEOUT = 60000;
|