@hubspot/local-dev-lib 3.21.2 → 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.
Files changed (45) hide show
  1. package/config/defaultAccountOverride.d.ts +2 -0
  2. package/config/defaultAccountOverride.js +57 -0
  3. package/config/index.d.ts +30 -44
  4. package/config/index.js +332 -267
  5. package/config/migrate.d.ts +12 -16
  6. package/config/migrate.js +86 -160
  7. package/config/utils.d.ts +30 -0
  8. package/config/utils.js +373 -0
  9. package/constants/config.d.ts +40 -0
  10. package/constants/config.js +41 -1
  11. package/constants/environments.d.ts +0 -11
  12. package/constants/environments.js +1 -12
  13. package/errors/index.d.ts +2 -0
  14. package/errors/index.js +6 -1
  15. package/http/getAxiosConfig.js +7 -1
  16. package/http/index.js +23 -19
  17. package/lang/en.json +89 -61
  18. package/lib/cms/themes.js +3 -1
  19. package/lib/environment.d.ts +1 -1
  20. package/lib/oauth.d.ts +2 -2
  21. package/lib/oauth.js +8 -16
  22. package/lib/personalAccessKey.d.ts +2 -2
  23. package/lib/personalAccessKey.js +43 -30
  24. package/lib/trackUsage.js +6 -3
  25. package/models/HubSpotConfigError.d.ts +6 -0
  26. package/models/HubSpotConfigError.js +34 -0
  27. package/models/OAuth2Manager.d.ts +3 -4
  28. package/models/OAuth2Manager.js +20 -29
  29. package/package.json +5 -5
  30. package/types/Accounts.d.ts +20 -109
  31. package/types/Config.d.ts +17 -26
  32. package/config/CLIConfiguration.d.ts +0 -72
  33. package/config/CLIConfiguration.js +0 -551
  34. package/config/configFile.d.ts +0 -21
  35. package/config/configFile.js +0 -100
  36. package/config/configUtils.d.ts +0 -5
  37. package/config/configUtils.js +0 -87
  38. package/config/config_DEPRECATED.d.ts +0 -87
  39. package/config/config_DEPRECATED.js +0 -738
  40. package/config/environment.d.ts +0 -2
  41. package/config/environment.js +0 -60
  42. package/config/getAccountIdentifier.d.ts +0 -2
  43. package/config/getAccountIdentifier.js +0 -15
  44. package/utils/accounts.d.ts +0 -4
  45. package/utils/accounts.js +0 -28
@@ -1,22 +1,18 @@
1
- import { CLIConfig_DEPRECATED, CLIConfig_NEW, Environment } from '../types/Config';
2
- import { CmsPublishMode } from '../types/Files';
3
- export declare function getDeprecatedConfig(configPath?: string): CLIConfig_DEPRECATED | null;
4
- export declare function getGlobalConfig(): CLIConfig_NEW | null;
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 CLIConfig_NEW;
11
- oldValue: ConflictValue;
12
- newValue: ConflictValue;
6
+ property: keyof HubSpotConfig;
7
+ oldValue: ValueOf<HubSpotConfig>;
8
+ newValue: ValueOf<Required<HubSpotConfig>>;
13
9
  };
14
- export declare function mergeConfigProperties(globalConfig: CLIConfig_NEW, deprecatedConfig: CLIConfig_DEPRECATED, force?: boolean): {
15
- initialConfig: CLIConfig_NEW;
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 mergeExistingConfigs(globalConfig: CLIConfig_NEW, deprecatedConfig: CLIConfig_DEPRECATED): {
19
- finalConfig: CLIConfig_NEW;
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.mergeExistingConfigs = exports.mergeConfigProperties = exports.migrateConfig = exports.getConfigPath = exports.configFileExists = exports.getGlobalConfig = exports.getDeprecatedConfig = void 0;
30
- const config_DEPRECATED = __importStar(require("./config_DEPRECATED"));
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 lang_1 = require("../utils/lang");
36
- const fs_1 = __importDefault(require("fs"));
10
+ const utils_1 = require("./utils");
37
11
  const path_1 = __importDefault(require("path"));
38
- const i18nKey = 'config.migrate';
39
- function getDeprecatedConfig(configPath) {
40
- return config_DEPRECATED.loadConfig(configPath);
12
+ function getConfigAtPath(path) {
13
+ const configFileSource = (0, utils_1.readConfigFile)(path);
14
+ return (0, utils_1.parseConfig)(configFileSource, path);
41
15
  }
42
- exports.getDeprecatedConfig = getDeprecatedConfig;
43
- function getGlobalConfig() {
44
- if (CLIConfiguration_1.CLIConfiguration.isActive()) {
45
- return CLIConfiguration_1.CLIConfiguration.config;
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.migrateConfig = migrateConfig;
101
- function mergeConfigProperties(globalConfig, deprecatedConfig, force) {
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
- propertiesToCheck.forEach(prop => {
113
- if (prop in deprecatedConfig) {
114
- if (force ||
115
- !(prop in globalConfig) ||
116
- globalConfig[prop] === deprecatedConfig[prop]) {
117
- // @ts-expect-error Cannot reconcile CLIConfig_NEW and CLIConfig_DEPRECATED types
118
- globalConfig[prop] = deprecatedConfig[prop];
119
- }
120
- else {
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: deprecatedConfig[prop],
124
- newValue: globalConfig[prop],
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
- if (config_1.DEFAULT_ACCOUNT in globalConfig &&
136
- config_1.DEFAULT_PORTAL in deprecatedConfig &&
137
- globalConfig.defaultAccount !== deprecatedConfig.defaultPortal) {
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
- else if (config_1.DEFAULT_PORTAL in deprecatedConfig) {
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 mergeAccounts(globalConfig, deprecatedConfig) {
156
- let existingAccountIds = [];
85
+ function buildConfigWithMergedAccounts(toConfig, fromConfig) {
86
+ const existingAccountIds = toConfig.accounts.map(({ accountId }) => accountId);
157
87
  const skippedAccountIds = [];
158
- if (globalConfig.accounts && deprecatedConfig.portals) {
159
- existingAccountIds = globalConfig.accounts.map(account => account.accountId);
160
- const newAccounts = deprecatedConfig.portals
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
- finalConfig: globalConfig,
97
+ configWithMergedAccounts: toConfig,
178
98
  skippedAccountIds,
179
99
  };
180
100
  }
181
- function mergeExistingConfigs(globalConfig, deprecatedConfig) {
182
- const { finalConfig, skippedAccountIds } = mergeAccounts(globalConfig, deprecatedConfig);
183
- writeGlobalConfigFile(finalConfig);
184
- return { finalConfig, skippedAccountIds };
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.mergeExistingConfigs = mergeExistingConfigs;
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
+ };