@hubspot/local-dev-lib 3.21.2-beta.0 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/defaultAccountOverride.d.ts +2 -0
- package/config/defaultAccountOverride.js +57 -0
- package/config/index.d.ts +30 -44
- package/config/index.js +332 -267
- package/config/migrate.d.ts +12 -16
- package/config/migrate.js +86 -160
- package/config/utils.d.ts +30 -0
- package/config/utils.js +373 -0
- package/constants/config.d.ts +40 -0
- package/constants/config.js +41 -1
- package/constants/environments.d.ts +0 -11
- package/constants/environments.js +1 -12
- package/errors/index.d.ts +2 -0
- package/errors/index.js +6 -1
- package/http/getAxiosConfig.js +7 -1
- package/http/index.js +23 -19
- package/lang/en.json +89 -61
- package/lib/cms/themes.js +3 -1
- package/lib/environment.d.ts +1 -1
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +8 -16
- package/lib/personalAccessKey.d.ts +2 -2
- package/lib/personalAccessKey.js +43 -30
- package/lib/trackUsage.js +6 -3
- package/models/HubSpotConfigError.d.ts +6 -0
- package/models/HubSpotConfigError.js +34 -0
- package/models/OAuth2Manager.d.ts +3 -4
- package/models/OAuth2Manager.js +20 -29
- package/package.json +5 -5
- package/types/Accounts.d.ts +20 -109
- package/types/Config.d.ts +17 -26
- package/config/CLIConfiguration.d.ts +0 -72
- package/config/CLIConfiguration.js +0 -551
- package/config/configFile.d.ts +0 -21
- package/config/configFile.js +0 -100
- package/config/configUtils.d.ts +0 -5
- package/config/configUtils.js +0 -87
- package/config/config_DEPRECATED.d.ts +0 -87
- package/config/config_DEPRECATED.js +0 -738
- package/config/environment.d.ts +0 -2
- package/config/environment.js +0 -60
- package/config/getAccountIdentifier.d.ts +0 -2
- package/config/getAccountIdentifier.js +0 -15
- package/utils/accounts.d.ts +0 -4
- package/utils/accounts.js +0 -28
package/config/migrate.d.ts
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function configFileExists(useHiddenConfig?: boolean, configPath?: string): boolean;
|
|
6
|
-
export declare function getConfigPath(configPath?: string, useHiddenConfig?: boolean): string | null;
|
|
7
|
-
export declare function migrateConfig(deprecatedConfig: CLIConfig_DEPRECATED | null): void;
|
|
8
|
-
type ConflictValue = boolean | string | number | CmsPublishMode | Environment;
|
|
1
|
+
import { HubSpotConfig } from '../types/Config';
|
|
2
|
+
import { ValueOf } from '../types/Utils';
|
|
3
|
+
export declare function getConfigAtPath(path: string): HubSpotConfig;
|
|
4
|
+
export declare function migrateConfigAtPath(path: string): void;
|
|
9
5
|
export type ConflictProperty = {
|
|
10
|
-
property: keyof
|
|
11
|
-
oldValue:
|
|
12
|
-
newValue:
|
|
6
|
+
property: keyof HubSpotConfig;
|
|
7
|
+
oldValue: ValueOf<HubSpotConfig>;
|
|
8
|
+
newValue: ValueOf<Required<HubSpotConfig>>;
|
|
13
9
|
};
|
|
14
|
-
export declare function mergeConfigProperties(
|
|
15
|
-
|
|
10
|
+
export declare function mergeConfigProperties(toConfig: HubSpotConfig, fromConfig: HubSpotConfig, force?: boolean): {
|
|
11
|
+
configWithMergedProperties: HubSpotConfig;
|
|
16
12
|
conflicts: Array<ConflictProperty>;
|
|
17
13
|
};
|
|
18
|
-
export declare function
|
|
19
|
-
|
|
14
|
+
export declare function mergeConfigAccounts(toConfig: HubSpotConfig, fromConfig: HubSpotConfig): {
|
|
15
|
+
configWithMergedAccounts: HubSpotConfig;
|
|
20
16
|
skippedAccountIds: Array<string | number>;
|
|
21
17
|
};
|
|
22
|
-
export
|
|
18
|
+
export declare function archiveConfigAtPath(configPath: string): void;
|
package/config/migrate.js
CHANGED
|
@@ -1,186 +1,112 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
const
|
|
31
|
-
const CLIConfiguration_1 = require("./CLIConfiguration");
|
|
6
|
+
exports.archiveConfigAtPath = exports.mergeConfigAccounts = exports.mergeConfigProperties = exports.migrateConfigAtPath = exports.getConfigAtPath = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
32
8
|
const index_1 = require("./index");
|
|
33
|
-
const configFile_1 = require("./configFile");
|
|
34
9
|
const config_1 = require("../constants/config");
|
|
35
|
-
const
|
|
36
|
-
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const utils_1 = require("./utils");
|
|
37
11
|
const path_1 = __importDefault(require("path"));
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return
|
|
12
|
+
function getConfigAtPath(path) {
|
|
13
|
+
const configFileSource = (0, utils_1.readConfigFile)(path);
|
|
14
|
+
return (0, utils_1.parseConfig)(configFileSource, path);
|
|
41
15
|
}
|
|
42
|
-
exports.
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
exports.getGlobalConfig = getGlobalConfig;
|
|
50
|
-
function configFileExists(useHiddenConfig = false, configPath) {
|
|
51
|
-
return useHiddenConfig
|
|
52
|
-
? (0, configFile_1.configFileExists)()
|
|
53
|
-
: Boolean(config_DEPRECATED.getConfigPath(configPath));
|
|
54
|
-
}
|
|
55
|
-
exports.configFileExists = configFileExists;
|
|
56
|
-
function getConfigPath(configPath, useHiddenConfig = false) {
|
|
57
|
-
if (useHiddenConfig) {
|
|
58
|
-
return (0, configFile_1.getConfigFilePath)();
|
|
59
|
-
}
|
|
60
|
-
return config_DEPRECATED.getConfigPath(configPath);
|
|
61
|
-
}
|
|
62
|
-
exports.getConfigPath = getConfigPath;
|
|
63
|
-
function writeGlobalConfigFile(updatedConfig, isMigrating = false) {
|
|
64
|
-
const updatedConfigJson = JSON.stringify(updatedConfig);
|
|
65
|
-
if (isMigrating) {
|
|
66
|
-
(0, index_1.createEmptyConfigFile)({}, true);
|
|
67
|
-
}
|
|
68
|
-
(0, index_1.loadConfig)('');
|
|
69
|
-
try {
|
|
70
|
-
(0, index_1.writeConfig)({ source: updatedConfigJson });
|
|
71
|
-
const oldConfigPath = config_DEPRECATED.getConfigPath();
|
|
72
|
-
if (oldConfigPath) {
|
|
73
|
-
const dir = path_1.default.dirname(oldConfigPath);
|
|
74
|
-
const newConfigPath = path_1.default.join(dir, config_1.ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME);
|
|
75
|
-
fs_1.default.renameSync(oldConfigPath, newConfigPath);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
(0, index_1.deleteEmptyConfigFile)();
|
|
80
|
-
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.writeConfig`, { configPath: config_1.GLOBAL_CONFIG_PATH }), { cause: error });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function migrateConfig(deprecatedConfig) {
|
|
84
|
-
if (!deprecatedConfig) {
|
|
85
|
-
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noDeprecatedConfig`));
|
|
86
|
-
}
|
|
87
|
-
const { defaultPortal, portals, ...rest } = deprecatedConfig;
|
|
88
|
-
const updatedConfig = {
|
|
89
|
-
...rest,
|
|
90
|
-
defaultAccount: defaultPortal,
|
|
91
|
-
accounts: portals
|
|
92
|
-
.filter(({ portalId }) => portalId !== undefined)
|
|
93
|
-
.map(({ portalId, ...rest }) => ({
|
|
94
|
-
...rest,
|
|
95
|
-
accountId: portalId,
|
|
96
|
-
})),
|
|
97
|
-
};
|
|
98
|
-
writeGlobalConfigFile(updatedConfig, true);
|
|
16
|
+
exports.getConfigAtPath = getConfigAtPath;
|
|
17
|
+
function migrateConfigAtPath(path) {
|
|
18
|
+
(0, index_1.createEmptyConfigFile)(true);
|
|
19
|
+
const configToMigrate = getConfigAtPath(path);
|
|
20
|
+
(0, utils_1.writeConfigFile)(configToMigrate, (0, index_1.getGlobalConfigFilePath)());
|
|
99
21
|
}
|
|
100
|
-
exports.
|
|
101
|
-
function mergeConfigProperties(
|
|
102
|
-
const propertiesToCheck = [
|
|
103
|
-
config_1.DEFAULT_CMS_PUBLISH_MODE,
|
|
104
|
-
config_1.HTTP_TIMEOUT,
|
|
105
|
-
config_1.ENV,
|
|
106
|
-
config_1.HTTP_USE_LOCALHOST,
|
|
107
|
-
config_1.ALLOW_USAGE_TRACKING,
|
|
108
|
-
config_1.AUTO_OPEN_BROWSER,
|
|
109
|
-
config_1.ALLOW_AUTO_UPDATES,
|
|
110
|
-
];
|
|
22
|
+
exports.migrateConfigAtPath = migrateConfigAtPath;
|
|
23
|
+
function mergeConfigProperties(toConfig, fromConfig, force) {
|
|
111
24
|
const conflicts = [];
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
25
|
+
if (force) {
|
|
26
|
+
toConfig.defaultCmsPublishMode = fromConfig.defaultCmsPublishMode;
|
|
27
|
+
toConfig.httpTimeout = fromConfig.httpTimeout;
|
|
28
|
+
toConfig.env = fromConfig.env;
|
|
29
|
+
toConfig.httpUseLocalhost = fromConfig.httpUseLocalhost;
|
|
30
|
+
toConfig.allowUsageTracking = fromConfig.allowUsageTracking;
|
|
31
|
+
toConfig.autoOpenBrowser = fromConfig.autoOpenBrowser;
|
|
32
|
+
toConfig.allowAutoUpdates = fromConfig.allowAutoUpdates;
|
|
33
|
+
toConfig.defaultAccount = fromConfig.defaultAccount;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
toConfig.defaultCmsPublishMode ||= fromConfig.defaultCmsPublishMode;
|
|
37
|
+
toConfig.httpTimeout ||= fromConfig.httpTimeout;
|
|
38
|
+
toConfig.env ||= fromConfig.env;
|
|
39
|
+
toConfig.httpUseLocalhost =
|
|
40
|
+
toConfig.httpUseLocalhost === undefined
|
|
41
|
+
? fromConfig.httpUseLocalhost
|
|
42
|
+
: toConfig.httpUseLocalhost;
|
|
43
|
+
toConfig.allowUsageTracking =
|
|
44
|
+
toConfig.allowUsageTracking === undefined
|
|
45
|
+
? fromConfig.allowUsageTracking
|
|
46
|
+
: toConfig.allowUsageTracking;
|
|
47
|
+
toConfig.autoOpenBrowser =
|
|
48
|
+
toConfig.autoOpenBrowser === undefined
|
|
49
|
+
? fromConfig.autoOpenBrowser
|
|
50
|
+
: toConfig.autoOpenBrowser;
|
|
51
|
+
toConfig.allowAutoUpdates =
|
|
52
|
+
toConfig.allowAutoUpdates === undefined
|
|
53
|
+
? fromConfig.allowAutoUpdates
|
|
54
|
+
: toConfig.allowAutoUpdates;
|
|
55
|
+
toConfig.defaultAccount ||= fromConfig.defaultAccount;
|
|
56
|
+
const propertiesToCheck = [
|
|
57
|
+
config_1.DEFAULT_CMS_PUBLISH_MODE,
|
|
58
|
+
config_1.HTTP_TIMEOUT,
|
|
59
|
+
config_1.ENV,
|
|
60
|
+
config_1.HTTP_USE_LOCALHOST,
|
|
61
|
+
config_1.ALLOW_USAGE_TRACKING,
|
|
62
|
+
config_1.AUTO_OPEN_BROWSER,
|
|
63
|
+
config_1.ALLOW_AUTO_UPDATES,
|
|
64
|
+
config_1.DEFAULT_ACCOUNT,
|
|
65
|
+
];
|
|
66
|
+
propertiesToCheck.forEach(prop => {
|
|
67
|
+
if (toConfig[prop] !== undefined &&
|
|
68
|
+
fromConfig[prop] !== undefined &&
|
|
69
|
+
toConfig[prop] !== fromConfig[prop]) {
|
|
121
70
|
conflicts.push({
|
|
122
71
|
property: prop,
|
|
123
|
-
oldValue:
|
|
124
|
-
newValue:
|
|
72
|
+
oldValue: fromConfig[prop],
|
|
73
|
+
newValue: toConfig[prop],
|
|
125
74
|
});
|
|
126
75
|
}
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
if (globalConfig.flags || deprecatedConfig.flags) {
|
|
130
|
-
globalConfig.flags = Array.from(new Set([
|
|
131
|
-
...(globalConfig.flags || []),
|
|
132
|
-
...(deprecatedConfig.flags || []),
|
|
133
|
-
]));
|
|
76
|
+
});
|
|
134
77
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (force) {
|
|
139
|
-
globalConfig.defaultAccount = deprecatedConfig.defaultPortal;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
conflicts.push({
|
|
143
|
-
property: config_1.DEFAULT_ACCOUNT,
|
|
144
|
-
oldValue: deprecatedConfig.defaultPortal,
|
|
145
|
-
newValue: globalConfig.defaultAccount,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
78
|
+
// Merge flags
|
|
79
|
+
if (toConfig.flags || fromConfig.flags) {
|
|
80
|
+
toConfig.flags = Array.from(new Set([...(toConfig.flags || []), ...(fromConfig.flags || [])]));
|
|
148
81
|
}
|
|
149
|
-
|
|
150
|
-
globalConfig.defaultAccount = deprecatedConfig.defaultPortal;
|
|
151
|
-
}
|
|
152
|
-
return { initialConfig: globalConfig, conflicts };
|
|
82
|
+
return { configWithMergedProperties: toConfig, conflicts };
|
|
153
83
|
}
|
|
154
84
|
exports.mergeConfigProperties = mergeConfigProperties;
|
|
155
|
-
function
|
|
156
|
-
|
|
85
|
+
function buildConfigWithMergedAccounts(toConfig, fromConfig) {
|
|
86
|
+
const existingAccountIds = toConfig.accounts.map(({ accountId }) => accountId);
|
|
157
87
|
const skippedAccountIds = [];
|
|
158
|
-
|
|
159
|
-
existingAccountIds
|
|
160
|
-
|
|
161
|
-
.filter(portal => {
|
|
162
|
-
const isExisting = existingAccountIds.includes(portal.portalId);
|
|
163
|
-
if (isExisting) {
|
|
164
|
-
skippedAccountIds.push(portal.portalId);
|
|
165
|
-
}
|
|
166
|
-
return !isExisting;
|
|
167
|
-
})
|
|
168
|
-
.map(({ portalId, ...rest }) => ({
|
|
169
|
-
...rest,
|
|
170
|
-
accountId: portalId,
|
|
171
|
-
}));
|
|
172
|
-
if (newAccounts.length > 0) {
|
|
173
|
-
globalConfig.accounts.push(...newAccounts);
|
|
88
|
+
fromConfig.accounts.forEach(account => {
|
|
89
|
+
if (existingAccountIds.includes(account.accountId)) {
|
|
90
|
+
skippedAccountIds.push(account.accountId);
|
|
174
91
|
}
|
|
175
|
-
|
|
92
|
+
else {
|
|
93
|
+
toConfig.accounts.push(account);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
176
96
|
return {
|
|
177
|
-
|
|
97
|
+
configWithMergedAccounts: toConfig,
|
|
178
98
|
skippedAccountIds,
|
|
179
99
|
};
|
|
180
100
|
}
|
|
181
|
-
function
|
|
182
|
-
const {
|
|
183
|
-
|
|
184
|
-
return {
|
|
101
|
+
function mergeConfigAccounts(toConfig, fromConfig) {
|
|
102
|
+
const { configWithMergedAccounts, skippedAccountIds } = buildConfigWithMergedAccounts(toConfig, fromConfig);
|
|
103
|
+
(0, utils_1.writeConfigFile)(configWithMergedAccounts, (0, index_1.getGlobalConfigFilePath)());
|
|
104
|
+
return { configWithMergedAccounts, skippedAccountIds };
|
|
105
|
+
}
|
|
106
|
+
exports.mergeConfigAccounts = mergeConfigAccounts;
|
|
107
|
+
function archiveConfigAtPath(configPath) {
|
|
108
|
+
const dir = path_1.default.dirname(configPath);
|
|
109
|
+
const archivedConfigPath = path_1.default.join(dir, config_1.ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME);
|
|
110
|
+
fs_1.default.renameSync(configPath, archivedConfigPath);
|
|
185
111
|
}
|
|
186
|
-
exports.
|
|
112
|
+
exports.archiveConfigAtPath = archiveConfigAtPath;
|
|
@@ -0,0 +1,30 @@
|
|
|
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';
|
|
5
|
+
export declare function getLocalConfigDefaultFilePath(): string;
|
|
6
|
+
export declare function getConfigPathEnvironmentVariables(): {
|
|
7
|
+
useEnvironmentConfig: boolean;
|
|
8
|
+
configFilePathFromEnvironment: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare function doesConfigFileExistAtPath(path: string): boolean;
|
|
11
|
+
export declare function readConfigFile(configPath: string): string;
|
|
12
|
+
export declare function removeUndefinedFieldsFromConfigAccount<T extends HubSpotConfigAccount | Partial<HubSpotConfigAccount> = HubSpotConfigAccount>(account: T): T;
|
|
13
|
+
export declare function formatConfigForWrite(config: HubSpotConfig): HubSpotConfig;
|
|
14
|
+
export declare function writeConfigFile(config: HubSpotConfig, configPath: string): void;
|
|
15
|
+
export declare function normalizeParsedConfig(parsedConfig: HubSpotConfig & DeprecatedHubSpotConfigFields): HubSpotConfig;
|
|
16
|
+
export declare function convertToDeprecatedConfig(config: HubSpotConfig): Partial<HubSpotConfig> & Partial<DeprecatedHubSpotConfigFields>;
|
|
17
|
+
export declare function parseConfig(configSource: string, configPath: string): HubSpotConfig;
|
|
18
|
+
export declare function buildConfigFromEnvironment(): HubSpotConfig;
|
|
19
|
+
export declare function getAccountIdentifierAndType(accountIdentifier: string | number): {
|
|
20
|
+
identifier: string | number;
|
|
21
|
+
identifierType: ValueOf<typeof ACCOUNT_IDENTIFIERS>;
|
|
22
|
+
};
|
|
23
|
+
export declare function getConfigAccountByIdentifier(accounts: Array<HubSpotConfigAccount>, identifierFieldName: ValueOf<typeof ACCOUNT_IDENTIFIERS>, identifier: string | number): HubSpotConfigAccount | undefined;
|
|
24
|
+
export declare function getConfigAccountByInferredIdentifier(accounts: Array<HubSpotConfigAccount>, accountIdentifier: string | number): HubSpotConfigAccount | undefined;
|
|
25
|
+
export declare function getConfigAccountIndexById(accounts: Array<HubSpotConfigAccount>, id: number): number;
|
|
26
|
+
export declare function validateConfigAccount(account: Partial<HubSpotConfigAccount>): HubSpotConfigValidationResult;
|
|
27
|
+
export declare function handleConfigFileSystemError(error: unknown, path: string): {
|
|
28
|
+
message?: string;
|
|
29
|
+
type: HubSpotConfigErrorType;
|
|
30
|
+
};
|