@hubspot/local-dev-lib 0.2.1-experimental.1 → 0.2.2-experimental.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/api/github.d.ts +0 -1
  2. package/api/projects.d.ts +0 -1
  3. package/config/CLIConfiguration.d.ts +65 -0
  4. package/config/CLIConfiguration.js +509 -0
  5. package/config/configFile.d.ts +21 -0
  6. package/config/configFile.js +100 -0
  7. package/config/configUtils.d.ts +5 -0
  8. package/config/configUtils.js +87 -0
  9. package/config/config_DEPRECATED.d.ts +76 -0
  10. package/config/config_DEPRECATED.js +693 -0
  11. package/config/environment.d.ts +2 -0
  12. package/config/environment.js +60 -0
  13. package/config/getAccountIdentifier.d.ts +2 -0
  14. package/config/getAccountIdentifier.js +15 -0
  15. package/config/index.d.ts +41 -25
  16. package/config/index.js +236 -248
  17. package/config/migrate.d.ts +20 -0
  18. package/config/migrate.js +150 -0
  19. package/constants/config.d.ts +7 -24
  20. package/constants/config.js +13 -25
  21. package/constants/environments.d.ts +11 -0
  22. package/constants/environments.js +12 -1
  23. package/http/getAxiosConfig.js +1 -7
  24. package/http/index.js +19 -23
  25. package/lang/en.json +81 -67
  26. package/lib/archive.d.ts +0 -1
  27. package/lib/cms/themes.js +1 -3
  28. package/lib/environment.d.ts +1 -1
  29. package/lib/github.d.ts +0 -1
  30. package/lib/oauth.d.ts +2 -2
  31. package/lib/oauth.js +16 -8
  32. package/lib/personalAccessKey.d.ts +2 -2
  33. package/lib/personalAccessKey.js +30 -39
  34. package/lib/trackUsage.js +3 -6
  35. package/models/OAuth2Manager.d.ts +4 -3
  36. package/models/OAuth2Manager.js +29 -20
  37. package/package.json +4 -3
  38. package/types/Accounts.d.ts +109 -20
  39. package/types/Config.d.ts +24 -11
  40. package/types/Http.d.ts +0 -1
  41. package/utils/accounts.d.ts +4 -0
  42. package/utils/accounts.js +28 -0
  43. package/config/defaultAccountOverride.d.ts +0 -2
  44. package/config/defaultAccountOverride.js +0 -57
  45. package/config/utils.d.ts +0 -70
  46. package/config/utils.js +0 -328
@@ -0,0 +1,150 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.mergeExistingConfigs = exports.mergeConfigProperties = exports.migrateConfig = exports.getConfigPath = exports.getConfig = void 0;
27
+ const config_DEPRECATED = __importStar(require("./config_DEPRECATED"));
28
+ const CLIConfiguration_1 = require("./CLIConfiguration");
29
+ const index_1 = require("./index");
30
+ const configFile_1 = require("./configFile");
31
+ const config_1 = require("../constants/config");
32
+ const lang_1 = require("../utils/lang");
33
+ const i18nKey = 'config.migrate';
34
+ function getConfig(useHiddenConfig, configPath) {
35
+ if (useHiddenConfig) {
36
+ return CLIConfiguration_1.CLIConfiguration.config;
37
+ }
38
+ return config_DEPRECATED.loadConfig(configPath);
39
+ }
40
+ exports.getConfig = getConfig;
41
+ function getConfigPath(configPath, useHiddenConfig = false) {
42
+ if (useHiddenConfig) {
43
+ return (0, configFile_1.getConfigFilePath)();
44
+ }
45
+ return config_DEPRECATED.getConfigPath(configPath);
46
+ }
47
+ exports.getConfigPath = getConfigPath;
48
+ function writeGlobalConfigFile(updatedConfig, isMigrating = false) {
49
+ const updatedConfigJson = JSON.stringify(updatedConfig);
50
+ if (isMigrating) {
51
+ (0, index_1.createEmptyConfigFile)({}, true);
52
+ }
53
+ (0, index_1.loadConfig)('');
54
+ try {
55
+ (0, index_1.writeConfig)({ source: updatedConfigJson });
56
+ config_DEPRECATED.deleteConfigFile();
57
+ }
58
+ catch (error) {
59
+ (0, index_1.deleteEmptyConfigFile)();
60
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.writeConfig`, { configPath: config_1.GLOBAL_CONFIG_PATH }), { cause: error });
61
+ }
62
+ }
63
+ function migrateConfig(deprecatedConfig) {
64
+ if (!deprecatedConfig) {
65
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noDeprecatedConfig`));
66
+ }
67
+ const { defaultPortal, portals, ...rest } = deprecatedConfig;
68
+ const updatedConfig = {
69
+ ...rest,
70
+ defaultAccount: defaultPortal,
71
+ accounts: portals
72
+ .filter(({ portalId }) => portalId !== undefined)
73
+ .map(({ portalId, ...rest }) => ({
74
+ ...rest,
75
+ accountId: portalId,
76
+ })),
77
+ };
78
+ writeGlobalConfigFile(updatedConfig, true);
79
+ }
80
+ exports.migrateConfig = migrateConfig;
81
+ function mergeConfigProperties(globalConfig, deprecatedConfig, force) {
82
+ const propertiesToCheck = [
83
+ config_1.DEFAULT_CMS_PUBLISH_MODE,
84
+ config_1.HTTP_TIMEOUT,
85
+ config_1.ENV,
86
+ config_1.HTTP_USE_LOCALHOST,
87
+ ];
88
+ const conflicts = [];
89
+ propertiesToCheck.forEach(prop => {
90
+ if (prop in globalConfig && prop in deprecatedConfig) {
91
+ if (force || globalConfig[prop] === deprecatedConfig[prop]) {
92
+ // @ts-expect-error Cannot reconcile CLIConfig_NEW and CLIConfig_DEPRECATED types
93
+ globalConfig[prop] = deprecatedConfig[prop];
94
+ }
95
+ else {
96
+ conflicts.push({
97
+ property: prop,
98
+ oldValue: deprecatedConfig[prop],
99
+ newValue: globalConfig[prop],
100
+ });
101
+ }
102
+ }
103
+ });
104
+ if (config_1.DEFAULT_ACCOUNT in globalConfig &&
105
+ config_1.DEFAULT_PORTAL in deprecatedConfig &&
106
+ globalConfig.defaultAccount !== deprecatedConfig.defaultPortal) {
107
+ conflicts.push({
108
+ property: config_1.DEFAULT_ACCOUNT,
109
+ oldValue: deprecatedConfig.defaultPortal,
110
+ newValue: globalConfig.defaultAccount,
111
+ });
112
+ }
113
+ else if (config_1.DEFAULT_PORTAL in deprecatedConfig) {
114
+ globalConfig.defaultAccount = deprecatedConfig.defaultPortal;
115
+ }
116
+ return { initialConfig: globalConfig, conflicts };
117
+ }
118
+ exports.mergeConfigProperties = mergeConfigProperties;
119
+ function mergeAccounts(globalConfig, deprecatedConfig) {
120
+ let existingAccountIds = [];
121
+ const skippedAccountIds = [];
122
+ if (globalConfig.accounts && deprecatedConfig.portals) {
123
+ existingAccountIds = globalConfig.accounts.map(account => account.accountId);
124
+ const newAccounts = deprecatedConfig.portals
125
+ .filter(portal => {
126
+ const isExisting = existingAccountIds.includes(portal.portalId);
127
+ if (isExisting) {
128
+ skippedAccountIds.push(portal.portalId);
129
+ }
130
+ return !isExisting;
131
+ })
132
+ .map(({ portalId, ...rest }) => ({
133
+ ...rest,
134
+ accountId: portalId,
135
+ }));
136
+ if (newAccounts.length > 0) {
137
+ globalConfig.accounts.push(...newAccounts);
138
+ }
139
+ }
140
+ return {
141
+ finalConfig: globalConfig,
142
+ skippedAccountIds,
143
+ };
144
+ }
145
+ function mergeExistingConfigs(globalConfig, deprecatedConfig) {
146
+ const { finalConfig, skippedAccountIds } = mergeAccounts(globalConfig, deprecatedConfig);
147
+ writeGlobalConfigFile(finalConfig);
148
+ return { finalConfig, skippedAccountIds };
149
+ }
150
+ exports.mergeExistingConfigs = mergeExistingConfigs;
@@ -1,9 +1,16 @@
1
1
  export declare const DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = "hubspot.config.yml";
2
2
  export declare const HUBSPOT_CONFIGURATION_FOLDER = ".hscli";
3
3
  export declare const HUBSPOT_CONFIGURATION_FILE = "config.yml";
4
+ export declare const GLOBAL_CONFIG_PATH: string;
4
5
  export declare const DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME = ".hsaccount";
5
6
  export declare const DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID = "DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID";
6
7
  export declare const DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND = "DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND";
8
+ export declare const DEFAULT_CMS_PUBLISH_MODE = "defaultCmsPublishMode";
9
+ export declare const HTTP_TIMEOUT = "httpTimeout";
10
+ export declare const ENV = "env";
11
+ export declare const HTTP_USE_LOCALHOST = "httpUseLocalhost";
12
+ export declare const DEFAULT_ACCOUNT = "defaultAccount";
13
+ export declare const DEFAULT_PORTAL = "defaultPortal";
7
14
  export declare const MIN_HTTP_TIMEOUT = 3000;
8
15
  export declare const HUBSPOT_ACCOUNT_TYPES: {
9
16
  readonly DEVELOPMENT_SANDBOX: "DEVELOPMENT_SANDBOX";
@@ -19,27 +26,3 @@ export declare const HUBSPOT_ACCOUNT_TYPE_STRINGS: {
19
26
  readonly APP_DEVELOPER: string;
20
27
  readonly STANDARD: string;
21
28
  };
22
- export declare const CONFIG_FLAGS: {
23
- readonly USE_CUSTOM_OBJECT_HUBFILE: "useCustomObjectHubfile";
24
- readonly HTTP_USE_LOCALHOST: "httpUseLocalhost";
25
- };
26
- export declare const ENVIRONMENT_VARIABLES: {
27
- readonly HUBSPOT_API_KEY: "HUBSPOT_API_KEY";
28
- readonly HUBSPOT_CLIENT_ID: "HUBSPOT_CLIENT_ID";
29
- readonly HUBSPOT_CLIENT_SECRET: "HUBSPOT_CLIENT_SECRET";
30
- readonly HUBSPOT_PERSONAL_ACCESS_KEY: "HUBSPOT_PERSONAL_ACCESS_KEY";
31
- readonly HUBSPOT_ACCOUNT_ID: "HUBSPOT_ACCOUNT_ID";
32
- readonly HUBSPOT_PORTAL_ID: "HUBSPOT_PORTAL_ID";
33
- readonly HUBSPOT_REFRESH_TOKEN: "HUBSPOT_REFRESH_TOKEN";
34
- readonly HUBSPOT_ENVIRONMENT: "HUBSPOT_ENVIRONMENT";
35
- readonly HTTP_TIMEOUT: "HTTP_TIMEOUT";
36
- readonly HTTP_USE_LOCALHOST: "HTTP_USE_LOCALHOST";
37
- readonly ALLOW_USAGE_TRACKING: "ALLOW_USAGE_TRACKING";
38
- readonly DEFAULT_CMS_PUBLISH_MODE: "DEFUALT_CMS_PUBLISH_MODE";
39
- readonly USE_ENVIRONMENT_HUBSPOT_CONFIG: "USE_ENVIRONMENT_HUBSPOT_CONFIG";
40
- readonly HUBSPOT_CONFIG_PATH: "HUBSPOT_CONFIG_PATH";
41
- };
42
- export declare const ACCOUNT_IDENTIFIERS: {
43
- readonly ACCOUNT_ID: "accountId";
44
- readonly NAME: "name";
45
- };
@@ -1,13 +1,25 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ACCOUNT_IDENTIFIERS = exports.ENVIRONMENT_VARIABLES = exports.CONFIG_FLAGS = exports.HUBSPOT_ACCOUNT_TYPE_STRINGS = exports.HUBSPOT_ACCOUNT_TYPES = exports.MIN_HTTP_TIMEOUT = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID = exports.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME = exports.HUBSPOT_CONFIGURATION_FILE = exports.HUBSPOT_CONFIGURATION_FOLDER = exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = void 0;
6
+ exports.HUBSPOT_ACCOUNT_TYPE_STRINGS = exports.HUBSPOT_ACCOUNT_TYPES = exports.MIN_HTTP_TIMEOUT = exports.DEFAULT_PORTAL = exports.DEFAULT_ACCOUNT = exports.HTTP_USE_LOCALHOST = exports.ENV = exports.HTTP_TIMEOUT = exports.DEFAULT_CMS_PUBLISH_MODE = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID = exports.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME = exports.GLOBAL_CONFIG_PATH = exports.HUBSPOT_CONFIGURATION_FILE = exports.HUBSPOT_CONFIGURATION_FOLDER = exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = void 0;
4
7
  const lang_1 = require("../utils/lang");
8
+ const path_1 = __importDefault(require("path"));
9
+ const os_1 = __importDefault(require("os"));
5
10
  exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = 'hubspot.config.yml';
6
11
  exports.HUBSPOT_CONFIGURATION_FOLDER = '.hscli';
7
12
  exports.HUBSPOT_CONFIGURATION_FILE = 'config.yml';
13
+ exports.GLOBAL_CONFIG_PATH = path_1.default.join(os_1.default.homedir(), exports.HUBSPOT_CONFIGURATION_FOLDER, exports.HUBSPOT_CONFIGURATION_FILE);
8
14
  exports.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME = '.hsaccount';
9
15
  exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID = 'DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID';
10
16
  exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND = 'DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND';
17
+ exports.DEFAULT_CMS_PUBLISH_MODE = 'defaultCmsPublishMode';
18
+ exports.HTTP_TIMEOUT = 'httpTimeout';
19
+ exports.ENV = 'env';
20
+ exports.HTTP_USE_LOCALHOST = 'httpUseLocalhost';
21
+ exports.DEFAULT_ACCOUNT = 'defaultAccount';
22
+ exports.DEFAULT_PORTAL = 'defaultPortal';
11
23
  exports.MIN_HTTP_TIMEOUT = 3000;
12
24
  exports.HUBSPOT_ACCOUNT_TYPES = {
13
25
  DEVELOPMENT_SANDBOX: 'DEVELOPMENT_SANDBOX',
@@ -23,27 +35,3 @@ exports.HUBSPOT_ACCOUNT_TYPE_STRINGS = {
23
35
  APP_DEVELOPER: (0, lang_1.i18n)('lib.accountTypes.appDeveloper'),
24
36
  STANDARD: (0, lang_1.i18n)('lib.accountTypes.standard'),
25
37
  };
26
- exports.CONFIG_FLAGS = {
27
- USE_CUSTOM_OBJECT_HUBFILE: 'useCustomObjectHubfile',
28
- HTTP_USE_LOCALHOST: 'httpUseLocalhost',
29
- };
30
- exports.ENVIRONMENT_VARIABLES = {
31
- HUBSPOT_API_KEY: 'HUBSPOT_API_KEY',
32
- HUBSPOT_CLIENT_ID: 'HUBSPOT_CLIENT_ID',
33
- HUBSPOT_CLIENT_SECRET: 'HUBSPOT_CLIENT_SECRET',
34
- HUBSPOT_PERSONAL_ACCESS_KEY: 'HUBSPOT_PERSONAL_ACCESS_KEY',
35
- HUBSPOT_ACCOUNT_ID: 'HUBSPOT_ACCOUNT_ID',
36
- HUBSPOT_PORTAL_ID: 'HUBSPOT_PORTAL_ID',
37
- HUBSPOT_REFRESH_TOKEN: 'HUBSPOT_REFRESH_TOKEN',
38
- HUBSPOT_ENVIRONMENT: 'HUBSPOT_ENVIRONMENT',
39
- HTTP_TIMEOUT: 'HTTP_TIMEOUT',
40
- HTTP_USE_LOCALHOST: 'HTTP_USE_LOCALHOST',
41
- ALLOW_USAGE_TRACKING: 'ALLOW_USAGE_TRACKING',
42
- DEFAULT_CMS_PUBLISH_MODE: 'DEFUALT_CMS_PUBLISH_MODE',
43
- USE_ENVIRONMENT_HUBSPOT_CONFIG: 'USE_ENVIRONMENT_HUBSPOT_CONFIG',
44
- HUBSPOT_CONFIG_PATH: 'HUBSPOT_CONFIG_PATH',
45
- };
46
- exports.ACCOUNT_IDENTIFIERS = {
47
- ACCOUNT_ID: 'accountId',
48
- NAME: 'name',
49
- };
@@ -2,3 +2,14 @@ export declare const ENVIRONMENTS: {
2
2
  readonly PROD: "prod";
3
3
  readonly QA: "qa";
4
4
  };
5
+ export declare const ENVIRONMENT_VARIABLES: {
6
+ readonly HUBSPOT_API_KEY: "HUBSPOT_API_KEY";
7
+ readonly HUBSPOT_CLIENT_ID: "HUBSPOT_CLIENT_ID";
8
+ readonly HUBSPOT_CLIENT_SECRET: "HUBSPOT_CLIENT_SECRET";
9
+ readonly HUBSPOT_PERSONAL_ACCESS_KEY: "HUBSPOT_PERSONAL_ACCESS_KEY";
10
+ readonly HUBSPOT_ACCOUNT_ID: "HUBSPOT_ACCOUNT_ID";
11
+ readonly HUBSPOT_PORTAL_ID: "HUBSPOT_PORTAL_ID";
12
+ readonly HUBSPOT_REFRESH_TOKEN: "HUBSPOT_REFRESH_TOKEN";
13
+ readonly HUBSPOT_ENVIRONMENT: "HUBSPOT_ENVIRONMENT";
14
+ readonly HTTP_TIMEOUT: "HTTP_TIMEOUT";
15
+ };
@@ -1,7 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENVIRONMENTS = void 0;
3
+ exports.ENVIRONMENT_VARIABLES = exports.ENVIRONMENTS = void 0;
4
4
  exports.ENVIRONMENTS = {
5
5
  PROD: 'prod',
6
6
  QA: 'qa',
7
7
  };
8
+ exports.ENVIRONMENT_VARIABLES = {
9
+ HUBSPOT_API_KEY: 'HUBSPOT_API_KEY',
10
+ HUBSPOT_CLIENT_ID: 'HUBSPOT_CLIENT_ID',
11
+ HUBSPOT_CLIENT_SECRET: 'HUBSPOT_CLIENT_SECRET',
12
+ HUBSPOT_PERSONAL_ACCESS_KEY: 'HUBSPOT_PERSONAL_ACCESS_KEY',
13
+ HUBSPOT_ACCOUNT_ID: 'HUBSPOT_ACCOUNT_ID',
14
+ HUBSPOT_PORTAL_ID: 'HUBSPOT_PORTAL_ID',
15
+ HUBSPOT_REFRESH_TOKEN: 'HUBSPOT_REFRESH_TOKEN',
16
+ HUBSPOT_ENVIRONMENT: 'HUBSPOT_ENVIRONMENT',
17
+ HTTP_TIMEOUT: 'HTTP_TIMEOUT',
18
+ };
@@ -41,13 +41,7 @@ const DEFAULT_TRANSITIONAL = {
41
41
  };
42
42
  function getAxiosConfig(options) {
43
43
  const { env, localHostOverride, headers, ...rest } = options;
44
- let config;
45
- try {
46
- config = (0, config_1.getConfig)();
47
- }
48
- catch (e) {
49
- config = null;
50
- }
44
+ const config = (0, config_1.getAndLoadConfigIfNeeded)();
51
45
  let httpTimeout = 15000;
52
46
  let httpUseLocalhost = false;
53
47
  if (config && config.httpTimeout) {
package/http/index.js CHANGED
@@ -16,7 +16,6 @@ const oauth_1 = require("../lib/oauth");
16
16
  const logger_1 = require("../lib/logger");
17
17
  const lang_1 = require("../utils/lang");
18
18
  const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
19
- const auth_1 = require("../constants/auth");
20
19
  const i18nKey = 'http.index';
21
20
  axios_1.default.interceptors.response.use(undefined, error => {
22
21
  // Wrap all axios errors in our own Error class. Attach the error
@@ -27,11 +26,11 @@ function addUserAgentHeader(key, value) {
27
26
  getAxiosConfig_1.USER_AGENTS[key] = value;
28
27
  }
29
28
  exports.addUserAgentHeader = addUserAgentHeader;
30
- async function withOauth(account, axiosConfig) {
29
+ async function withOauth(accountId, accountConfig, axiosConfig) {
31
30
  const { headers } = axiosConfig;
32
- const oauth = (0, oauth_1.getOauthManager)(account);
31
+ const oauth = (0, oauth_1.getOauthManager)(accountId, accountConfig);
33
32
  if (!oauth) {
34
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withOauth`, { accountId: account.accountId }));
33
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withOauth`, { accountId }));
35
34
  }
36
35
  const accessToken = await oauth.accessToken();
37
36
  return {
@@ -64,29 +63,26 @@ function withPortalId(portalId, axiosConfig) {
64
63
  };
65
64
  }
66
65
  async function withAuth(accountId, options) {
67
- const account = (0, config_1.getConfigAccountById)(accountId);
68
- const { env, authType } = account;
66
+ const accountConfig = (0, config_1.getAccountConfig)(accountId);
67
+ if (!accountConfig) {
68
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.withAuth`, { accountId }));
69
+ }
70
+ const { env, authType, apiKey } = accountConfig;
69
71
  const axiosConfig = withPortalId(accountId, (0, getAxiosConfig_1.getAxiosConfig)({ env, ...options }));
70
- if (authType === auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
72
+ if (authType === 'personalaccesskey') {
71
73
  return withPersonalAccessKey(accountId, axiosConfig);
72
74
  }
73
- if (authType === auth_1.OAUTH_AUTH_METHOD.value) {
74
- return withOauth(account, axiosConfig);
75
- }
76
- if (authType === auth_1.API_KEY_AUTH_METHOD.value) {
77
- const { params } = axiosConfig;
78
- return {
79
- ...axiosConfig,
80
- params: {
81
- ...params,
82
- hapikey: account.apiKey,
83
- },
84
- };
75
+ if (authType === 'oauth2') {
76
+ return withOauth(accountId, accountConfig, axiosConfig);
85
77
  }
86
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidAuthType`, {
87
- accountId,
88
- authType,
89
- }));
78
+ const { params } = axiosConfig;
79
+ return {
80
+ ...axiosConfig,
81
+ params: {
82
+ ...params,
83
+ hapikey: apiKey,
84
+ },
85
+ };
90
86
  }
91
87
  async function getRequest(accountId, options) {
92
88
  const { params, ...rest } = options;
package/lang/en.json CHANGED
@@ -74,8 +74,7 @@
74
74
  "personalAccessKey": {
75
75
  "errors": {
76
76
  "accountNotFound": "Account with id {{ accountId }} does not exist.",
77
- "invalidPersonalAccessKey": "Error while retrieving new access token: {{ errorMessage }}",
78
- "invalidAuthType": "Error fetching access token: account {{ accountId }} uses an auth type other than personalaccesskey"
77
+ "invalidPersonalAccessKey": "Error while retrieving new access token: {{ errorMessage }}"
79
78
  }
80
79
  },
81
80
  "cms": {
@@ -233,74 +232,90 @@
233
232
  }
234
233
  },
235
234
  "config": {
236
- "getDefaultConfigFilePath": {
237
- "error": "Error getting config file path: no config file found"
238
- },
239
- "getConfig": "Reading config from {{ path }}",
240
- "isConfigValid": {
241
- "missingAccounts": "Invalid config: no accounts found",
242
- "duplicateAccountIds": "Invalid config: multiple accounts with accountId: {{ accountId }}",
243
- "duplicateAccountNames": "Invalid config: multiple accounts with name: {{ accountName }}",
244
- "invalidAccountName": "Invalid config: account name {{ accountName }} contains spaces"
245
- },
246
- "getConfigAccountById": {
247
- "error": "Error getting config account: no account with id {{ accountId }} exists in config"
248
- },
249
- "getConfigAccountByName": {
250
- "error": "Error getting config account: no account with name {{ accountName }} exists in config"
251
- },
252
- "getConfigDefaultAccount": {
253
- "fieldMissingError": "Error getting config default account: no default account field found in config",
254
- "accountMissingError": "Error getting config default account: default account is set to {{ defaultAccount }} but no account with that id exists in config"
255
- },
256
- "addConfigAccount": {
257
- "invalidAccount": "Error adding config account: account is invalid",
258
- "duplicateAccount": "Error adding config account: account with id {{ accountId }} already exists in config"
259
- },
260
- "updateConfigAccount": {
261
- "invalidAccount": "Error updating config account: account is invalid",
262
- "accountNotFound": "Error updating config account: account with id {{ accountId }} not found in config"
263
- },
264
- "setConfigAccountAsDefault": {
265
- "accountNotFound": "Error setting config default account: account with id {{ accountId }} not found in config"
266
- },
267
- "renameConfigAccount": {
268
- "accountNotFound": "Error renaming config account: account with name {{ currentName }} not found in config",
269
- "duplicateAccount": "Error renaming config account: account with name {{ newName}} already exists in config"
270
- },
271
- "removeAccountFromConfig": {
272
- "accountNotFound": "Error removing config account: account with id {{ accountId }} not found in config"
273
- },
274
- "updateHttpTimeout": {
275
- "invalidTimeout": "Error updating config http timeout: timeout must be greater than {{ minTimeout }}"
276
- },
277
- "updateDefaultCmsPublishMode": {
278
- "invalidCmsPublishMode": "Error updating config default CMS publish mode: CMS publish can only be set to 'draft' or 'publish'"
279
- },
280
- "utils": {
281
- "isConfigAccountValid": {
282
- "missingAccount": "Invalid config: at least one account in config is missing data",
283
- "missingAuthType": "Invalid config: account {{ accountId }} has no authType",
284
- "missingAccountId": "Invalid config: at least one account in config is missing accountId",
285
- "missingApiKey": "Invalid config: account {{ accountId }} has authType of apikey but is missing the apiKey field",
286
- "missingAuth": "Invalid config: account {{ accountId }} has authtype of oauth2 but is missing auth data",
287
- "missingPersonalAccessKey": "Invalid config: account {{ accountId }} has authType of personalAccessKey but is missing the personalAccessKey field"
235
+ "cliConfiguration": {
236
+ "errors": {
237
+ "noConfigLoaded": "No config loaded."
288
238
  },
289
- "getConfigPathEnvironmentVariables": {
290
- "invalidEnvironmentVariables": "Error loading config: USE_ENVIRONMENT_HUBSPOT_CONFIG and HUBSPOT_CONFIG_PATH cannot both be set simultaneously"
239
+ "load": {
240
+ "configFromEnv": "Loaded config from environment variables for {{ accountId }}",
241
+ "configFromFile": "Loaded config from configuration file.",
242
+ "empty": "The config file was empty. Initializing an empty config."
291
243
  },
292
- "parseConfig": {
293
- "error": "An error occurred parsing the config file."
244
+ "validate": {
245
+ "noConfig": "Valiation failed: No config was found.",
246
+ "noConfigAccounts": "Valiation failed: config.accounts[] is not defined.",
247
+ "emptyAccountConfig": "Valiation failed: config.accounts[] has an empty entry.",
248
+ "noAccountId": "Valiation failed: config.accounts[] has an entry missing accountId.",
249
+ "duplicateAccountIds": "Valiation failed: config.accounts[] has multiple entries with {{ accountId }}.",
250
+ "duplicateAccountNames": "Valiation failed: config.accounts[] has multiple entries with {{ accountName }}.",
251
+ "nameContainsSpaces": "Valiation failed: config.name {{ accountName }} cannot contain spaces."
294
252
  },
295
- "buildConfigFromEnvironment": {
296
- "missingAccountId": "Error loading config from environment: HUBSPOT_ACCOUNT_ID not set",
297
- "invalidAuthType": "Error loading config from environment: auth is invalid. Use HUBSPOT_CLIENT_ID, HUBSPOT_CLIENT_SECRET, and HUBSPOT_REFRESH_TOKEN to authenticate with Oauth2, PERSONAL_ACCESS_KEY to authenticate with Personal Access Key, or API_KEY to authenticate with API Key."
298
- }
299
- },
300
- "defaultAccountOverride": {
301
- "getDefaultAccountOverrideAccountId": {
253
+ "updateAccount": {
254
+ "noConfigToUpdate": "No config to update.",
255
+ "updating": "Updating account config for {{ accountId }}",
256
+ "addingConfigEntry": "Adding account config entry for {{ accountId }}",
257
+ "errors": {
258
+ "accountIdRequired": "An accountId is required to update the config"
259
+ }
260
+ },
261
+ "updateDefaultAccount": {
262
+ "errors": {
263
+ "invalidInput": "A 'defaultAccount' with value of number or string is required to update the config."
264
+ }
265
+ },
266
+ "getCWDAccountOverride": {
302
267
  "errorHeader": "Error in {{ hsAccountFile }}",
303
268
  "readFileError": "Error reading account override file."
269
+ },
270
+ "renameAccount": {
271
+ "errors": {
272
+ "invalidName": "Cannot find account with identifier {{ currentName }}"
273
+ }
274
+ },
275
+ "removeAccountFromConfig": {
276
+ "deleting": "Deleting config for {{ accountId }}",
277
+ "errors": {
278
+ "invalidId": "Unable to find account for {{ nameOrId }}."
279
+ }
280
+ },
281
+ "updateDefaultCmsPublishMode": {
282
+ "errors": {
283
+ "invalidCmsPublishMode": "The CMS publish mode {{ defaultCmsPublishMode }} is invalid. Valid values are {{ validCmsPublishModes }}."
284
+ }
285
+ },
286
+ "updateHttpTimeout": {
287
+ "errors": {
288
+ "invalidTimeout": "The value {{ timeout }} is invalid. The value must be a number greater than {{ minTimeout }}."
289
+ }
290
+ },
291
+ "updateAllowUsageTracking": {
292
+ "errors": {
293
+ "invalidInput": "Unable to update allowUsageTracking. The value {{ isEnabled }} is invalid. The value must be a boolean."
294
+ }
295
+ }
296
+ },
297
+ "configFile": {
298
+ "errorReading": "Config file could not be read: {{ configPath }}",
299
+ "writeSuccess": "Successfully wrote updated config data to {{ configPath }}",
300
+ "errorLoading": "A configuration file could not be found at {{ configPath }}.",
301
+ "errors": {
302
+ "parsing": "Config file could not be parsed"
303
+ }
304
+ },
305
+ "configUtils": {
306
+ "unknownType": "Unknown auth type {{ type }}"
307
+ },
308
+ "environment": {
309
+ "loadConfig": {
310
+ "missingAccountId": "Unable to load config from environment variables: Missing accountId",
311
+ "missingEnv": "Unable to load config from environment variables: Missing env",
312
+ "unknownAuthType": "Unable to load config from environment variables: Unknown auth type"
313
+ }
314
+ },
315
+ "migrate": {
316
+ "errors": {
317
+ "writeConfig": "Unable to write global configuration file at {{ configPath }}.",
318
+ "noDeprecatedConfig": "No deprecated configuration file found. Skipping migration to global config."
304
319
  }
305
320
  }
306
321
  },
@@ -352,8 +367,7 @@
352
367
  },
353
368
  "errors": {
354
369
  "withOauth": "Oauth manager for account {{ accountId }} not found.",
355
- "withAuth": "Account with id {{ accountId }} not found.",
356
- "invalidAuthType": "Error authenticating HTTP request: account {{ accountId }} has an invalid auth type {{ authType }}"
370
+ "withAuth": "Account with id {{ accountId }} not found."
357
371
  }
358
372
  }
359
373
  },
package/lib/archive.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import { CopySourceToDestOptions } from '../types/Archive';
4
3
  export declare function extractZipArchive(zip: Buffer, name: string, dest: string, { sourceDir, includesRootDir, hideLogs }?: CopySourceToDestOptions): Promise<boolean>;
package/lib/cms/themes.js CHANGED
@@ -28,9 +28,7 @@ function getThemePreviewUrl(filePath, accountId) {
28
28
  const themeName = getThemeNameFromPath(filePath);
29
29
  if (!themeName)
30
30
  return;
31
- const baseUrl = (0, urls_1.getHubSpotWebsiteOrigin)((0, config_1.getConfigAccountEnvironment)(accountId) === 'qa'
32
- ? environments_1.ENVIRONMENTS.QA
33
- : environments_1.ENVIRONMENTS.PROD);
31
+ const baseUrl = (0, urls_1.getHubSpotWebsiteOrigin)((0, config_1.getEnv)(accountId) === 'qa' ? environments_1.ENVIRONMENTS.QA : environments_1.ENVIRONMENTS.PROD);
34
32
  return `${baseUrl}/theme-previewer/${accountId}/edit/${encodeURIComponent(themeName)}`;
35
33
  }
36
34
  exports.getThemePreviewUrl = getThemePreviewUrl;
@@ -1,2 +1,2 @@
1
1
  import { Environment } from '../types/Config';
2
- export declare function getValidEnv(env?: string | null, maskedProductionValue?: Environment): Environment;
2
+ export declare function getValidEnv(env?: Environment | null, maskedProductionValue?: Environment): Environment;
package/lib/github.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import { GithubReleaseData, GithubRepoFile, RepoPath, CloneGithubRepoOptions } from '../types/Github';
4
3
  /**
5
4
  * @deprecated Use `fetchRepoFile` instead - this util is a thin wrapper around it
package/lib/oauth.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { OAuth2Manager } from '../models/OAuth2Manager';
2
- import { OAuthConfigAccount } from '../types/Accounts';
3
- export declare function getOauthManager(account: OAuthConfigAccount): OAuth2Manager | undefined;
2
+ import { FlatAccountFields } from '../types/Accounts';
3
+ export declare function getOauthManager(accountId: number, accountConfig: FlatAccountFields): OAuth2Manager | undefined;
4
4
  export declare function addOauthToAccountConfig(oauth: OAuth2Manager): void;
package/lib/oauth.js CHANGED
@@ -2,25 +2,33 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addOauthToAccountConfig = exports.getOauthManager = void 0;
4
4
  const OAuth2Manager_1 = require("../models/OAuth2Manager");
5
+ const auth_1 = require("../constants/auth");
5
6
  const logger_1 = require("./logger");
7
+ const getAccountIdentifier_1 = require("../config/getAccountIdentifier");
6
8
  const config_1 = require("../config");
7
9
  const lang_1 = require("../utils/lang");
8
10
  const i18nKey = 'lib.oauth';
9
11
  const oauthManagers = new Map();
10
- function writeOauthTokenInfo(account) {
11
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.writeTokenInfo`, { portalId: account.accountId }));
12
- (0, config_1.updateConfigAccount)(account);
12
+ function writeOauthTokenInfo(accountConfig) {
13
+ const accountId = (0, getAccountIdentifier_1.getAccountIdentifier)(accountConfig);
14
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.writeTokenInfo`, { portalId: accountId || '' }));
15
+ (0, config_1.updateAccountConfig)(accountConfig);
16
+ (0, config_1.writeConfig)();
13
17
  }
14
- function getOauthManager(account) {
15
- if (!oauthManagers.has(account.accountId)) {
16
- oauthManagers.set(account.accountId, new OAuth2Manager_1.OAuth2Manager(account, () => writeOauthTokenInfo(account)));
18
+ function getOauthManager(accountId, accountConfig) {
19
+ if (!oauthManagers.has(accountId)) {
20
+ oauthManagers.set(accountId, OAuth2Manager_1.OAuth2Manager.fromConfig(accountConfig, () => writeOauthTokenInfo(accountConfig)));
17
21
  }
18
- return oauthManagers.get(account.accountId);
22
+ return oauthManagers.get(accountId);
19
23
  }
20
24
  exports.getOauthManager = getOauthManager;
21
25
  function addOauthToAccountConfig(oauth) {
22
26
  logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.addOauthToAccountConfig.init`));
23
- (0, config_1.updateConfigAccount)(oauth.account);
27
+ (0, config_1.updateAccountConfig)({
28
+ ...oauth.account,
29
+ authType: auth_1.AUTH_METHODS.oauth.value,
30
+ });
31
+ (0, config_1.writeConfig)();
24
32
  logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.addOauthToAccountConfig.success`));
25
33
  }
26
34
  exports.addOauthToAccountConfig = addOauthToAccountConfig;
@@ -1,4 +1,4 @@
1
- import { PersonalAccessKeyConfigAccount, ScopeGroupAuthorization } from '../types/Accounts';
1
+ import { CLIAccount, ScopeGroupAuthorization } from '../types/Accounts';
2
2
  import { Environment } from '../types/Config';
3
3
  import { AccessToken } from '../types/Accounts';
4
4
  export declare function getAccessToken(personalAccessKey: string, env?: Environment, accountId?: number): Promise<AccessToken>;
@@ -8,4 +8,4 @@ export declare function enabledFeaturesForPersonalAccessKey(accountId: number):
8
8
  } | undefined>;
9
9
  export declare function scopesOnAccessToken(accountId: number): Promise<Array<string>>;
10
10
  export declare function authorizedScopesForPortalAndUser(accountId: number): Promise<Array<ScopeGroupAuthorization>>;
11
- export declare function updateConfigWithAccessToken(token: AccessToken, personalAccessKey: string, env?: Environment, name?: string, makeDefault?: boolean): Promise<PersonalAccessKeyConfigAccount>;
11
+ export declare function updateConfigWithAccessToken(token: AccessToken, personalAccessKey: string, env?: Environment, name?: string, makeDefault?: boolean): Promise<CLIAccount | null>;