@hubspot/local-dev-lib 0.2.4 → 0.2.6-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 (189) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +17 -0
  3. package/api/appsDev.d.ts +6 -0
  4. package/api/appsDev.js +29 -0
  5. package/api/customObjects.d.ts +8 -7
  6. package/api/customObjects.js +13 -16
  7. package/api/designManager.d.ts +4 -13
  8. package/api/designManager.js +6 -9
  9. package/api/developerTestAccounts.d.ts +7 -0
  10. package/api/developerTestAccounts.js +48 -0
  11. package/api/fileManager.d.ts +5 -4
  12. package/api/fileManager.js +11 -11
  13. package/api/fileMapper.d.ts +8 -7
  14. package/api/fileMapper.js +16 -16
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/functions.d.ts +7 -7
  18. package/api/functions.js +13 -16
  19. package/api/github.d.ts +8 -9
  20. package/api/github.js +31 -13
  21. package/api/hubdb.d.ts +11 -10
  22. package/api/hubdb.js +28 -22
  23. package/api/lighthouseScore.d.ts +4 -4
  24. package/api/lighthouseScore.js +9 -12
  25. package/api/localDevAuth.d.ts +8 -16
  26. package/api/localDevAuth.js +34 -13
  27. package/api/marketplaceValidation.d.ts +4 -4
  28. package/api/marketplaceValidation.js +8 -11
  29. package/api/projects.d.ts +73 -22
  30. package/api/projects.js +199 -43
  31. package/api/sandboxHubs.d.ts +6 -4
  32. package/api/sandboxHubs.js +10 -11
  33. package/api/sandboxSync.d.ts +4 -4
  34. package/api/sandboxSync.js +4 -13
  35. package/api/secrets.d.ts +6 -8
  36. package/api/secrets.js +9 -12
  37. package/api/validateHubl.d.ts +2 -1
  38. package/api/validateHubl.js +3 -6
  39. package/config/CLIConfiguration.d.ts +15 -11
  40. package/config/CLIConfiguration.js +175 -90
  41. package/config/configFile.js +12 -18
  42. package/config/configUtils.d.ts +2 -21
  43. package/config/configUtils.js +5 -4
  44. package/config/config_DEPRECATED.d.ts +6 -8
  45. package/config/config_DEPRECATED.js +79 -25
  46. package/config/environment.js +5 -4
  47. package/config/getAccountIdentifier.d.ts +2 -0
  48. package/config/getAccountIdentifier.js +15 -0
  49. package/config/index.d.ts +13 -8
  50. package/config/index.js +97 -57
  51. package/constants/config.d.ts +18 -1
  52. package/constants/config.js +20 -3
  53. package/constants/environments.d.ts +1 -0
  54. package/constants/environments.js +1 -0
  55. package/constants/extensions.d.ts +2 -0
  56. package/constants/extensions.js +3 -1
  57. package/constants/files.d.ts +2 -2
  58. package/constants/files.js +3 -3
  59. package/constants/platformVersion.d.ts +6 -0
  60. package/constants/platformVersion.js +9 -0
  61. package/errors/errors_DEPRECATED.d.ts +1 -5
  62. package/errors/errors_DEPRECATED.js +2 -2
  63. package/errors/index.d.ts +18 -0
  64. package/errors/index.js +63 -0
  65. package/http/addQueryParams.d.ts +2 -0
  66. package/http/addQueryParams.js +14 -0
  67. package/http/getAxiosConfig.d.ts +6 -3
  68. package/http/getAxiosConfig.js +49 -6
  69. package/http/index.d.ts +11 -12
  70. package/http/index.js +35 -41
  71. package/http/unauthed.d.ts +14 -0
  72. package/http/unauthed.js +38 -0
  73. package/lang/en.json +378 -386
  74. package/lib/archive.d.ts +3 -8
  75. package/lib/archive.js +34 -30
  76. package/lib/cms/functions.d.ts +7 -12
  77. package/lib/cms/functions.js +49 -51
  78. package/lib/cms/handleFieldsJS.js +16 -14
  79. package/lib/cms/modules.d.ts +4 -15
  80. package/lib/cms/modules.js +81 -78
  81. package/lib/cms/processFieldsJs.js +10 -33
  82. package/lib/cms/templates.d.ts +43 -3
  83. package/lib/cms/templates.js +53 -11
  84. package/lib/cms/uploadFolder.d.ts +3 -14
  85. package/lib/cms/uploadFolder.js +58 -42
  86. package/lib/cms/validate.js +1 -1
  87. package/lib/cms/watch.d.ts +2 -18
  88. package/lib/cms/watch.js +63 -68
  89. package/lib/customObjects.js +4 -15
  90. package/lib/fileManager.d.ts +2 -6
  91. package/lib/fileManager.js +54 -65
  92. package/lib/fileMapper.d.ts +4 -15
  93. package/lib/fileMapper.js +67 -88
  94. package/lib/fs.d.ts +1 -1
  95. package/lib/fs.js +10 -6
  96. package/lib/github.d.ts +13 -14
  97. package/lib/github.js +70 -35
  98. package/lib/gitignore.d.ts +2 -0
  99. package/lib/gitignore.js +21 -4
  100. package/lib/hubdb.d.ts +3 -2
  101. package/lib/hubdb.js +11 -9
  102. package/{utils → lib}/notify.js +2 -2
  103. package/lib/oauth.d.ts +2 -5
  104. package/lib/oauth.js +14 -25
  105. package/lib/path.d.ts +3 -0
  106. package/lib/path.js +46 -1
  107. package/lib/personalAccessKey.d.ts +8 -11
  108. package/lib/personalAccessKey.js +75 -38
  109. package/lib/portManager.d.ts +3 -5
  110. package/lib/portManager.js +18 -6
  111. package/lib/trackUsage.js +18 -11
  112. package/lib/urls.js +5 -1
  113. package/models/FileSystemError.d.ts +6 -0
  114. package/models/FileSystemError.js +47 -0
  115. package/models/HubSpotHttpError.d.ts +24 -0
  116. package/models/HubSpotHttpError.js +197 -0
  117. package/models/OAuth2Manager.d.ts +2 -27
  118. package/models/OAuth2Manager.js +20 -34
  119. package/package.json +34 -36
  120. package/types/Accounts.d.ts +103 -3
  121. package/types/Apps.d.ts +77 -0
  122. package/types/Archive.d.ts +9 -0
  123. package/types/Archive.js +2 -0
  124. package/types/Build.d.ts +4 -2
  125. package/types/ComponentStructure.d.ts +30 -10
  126. package/types/Config.d.ts +19 -2
  127. package/types/Deploy.d.ts +3 -2
  128. package/types/DesignManager.d.ts +10 -0
  129. package/types/DesignManager.js +2 -0
  130. package/types/Error.d.ts +9 -5
  131. package/types/FieldsJS.d.ts +1 -0
  132. package/types/FieldsJS.js +2 -0
  133. package/types/FileManager.d.ts +1 -1
  134. package/types/Files.d.ts +43 -4
  135. package/types/Functions.d.ts +52 -0
  136. package/types/Github.d.ts +13 -0
  137. package/types/Http.d.ts +13 -12
  138. package/types/Hubdb.d.ts +9 -0
  139. package/types/MarketplaceValidation.d.ts +7 -3
  140. package/types/Migration.d.ts +28 -0
  141. package/types/Migration.js +10 -0
  142. package/types/Modules.d.ts +11 -0
  143. package/types/PortManager.d.ts +7 -0
  144. package/types/Project.d.ts +30 -0
  145. package/types/ProjectLog.d.ts +9 -0
  146. package/types/ProjectLog.js +2 -0
  147. package/types/Sandbox.d.ts +37 -47
  148. package/types/Schemas.d.ts +56 -0
  149. package/types/Secrets.d.ts +3 -0
  150. package/types/Secrets.js +2 -0
  151. package/types/developerTestAccounts.d.ts +13 -0
  152. package/types/developerTestAccounts.js +2 -0
  153. package/utils/PortManagerServer.d.ts +6 -7
  154. package/utils/PortManagerServer.js +22 -16
  155. package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
  156. package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
  157. package/utils/cms/fieldsJS.d.ts +1 -2
  158. package/utils/cms/modules.js +2 -2
  159. package/utils/detectPort.js +3 -3
  160. package/utils/git.d.ts +1 -7
  161. package/utils/git.js +2 -18
  162. package/errors/apiErrors.d.ts +0 -16
  163. package/errors/apiErrors.js +0 -176
  164. package/errors/fileSystemErrors.d.ts +0 -6
  165. package/errors/fileSystemErrors.js +0 -35
  166. package/errors/standardErrors.d.ts +0 -21
  167. package/errors/standardErrors.js +0 -52
  168. package/lang/lang/en.json +0 -401
  169. package/lib/logging/git.d.ts +0 -2
  170. package/lib/logging/git.js +0 -54
  171. package/lib/logging/logs.d.ts +0 -22
  172. package/lib/logging/logs.js +0 -86
  173. package/lib/logging/table.d.ts +0 -3
  174. package/lib/logging/table.js +0 -47
  175. package/lib/sandboxes.d.ts +0 -14
  176. package/lib/sandboxes.js +0 -71
  177. package/models/HubSpotAuthError.d.ts +0 -12
  178. package/models/HubSpotAuthError.js +0 -20
  179. package/types/LogCallbacks.d.ts +0 -7
  180. package/utils/logger.d.ts +0 -5
  181. package/utils/logger.js +0 -23
  182. package/utils/objectUtils.d.ts +0 -8
  183. package/utils/objectUtils.js +0 -33
  184. /package/{utils → lib}/escapeRegExp.d.ts +0 -0
  185. /package/{utils → lib}/escapeRegExp.js +0 -0
  186. /package/lib/{logging/logger.d.ts → logger.d.ts} +0 -0
  187. /package/lib/{logging/logger.js → logger.js} +0 -0
  188. /package/{utils → lib}/notify.d.ts +0 -0
  189. /package/types/{LogCallbacks.js → Apps.js} +0 -0
@@ -1,7 +1,13 @@
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
- const logger_1 = require("../utils/logger");
4
- const standardErrors_1 = require("../errors/standardErrors");
6
+ exports.CLIConfiguration = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const findup_sync_1 = __importDefault(require("findup-sync"));
9
+ const path_1 = require("../lib/path");
10
+ const logger_1 = require("../lib/logger");
5
11
  const environment_1 = require("./environment");
6
12
  const environment_2 = require("../lib/environment");
7
13
  const configFile_1 = require("./configFile");
@@ -10,17 +16,9 @@ const environments_1 = require("../constants/environments");
10
16
  const auth_1 = require("../constants/auth");
11
17
  const config_1 = require("../constants/config");
12
18
  const files_1 = require("../constants/files");
19
+ const lang_1 = require("../utils/lang");
13
20
  const i18nKey = 'config.cliConfiguration';
14
- const validateLogCallbackKeys = [
15
- 'noConfig',
16
- 'noConfigAccounts',
17
- 'emptyAccountConfig',
18
- 'noAccountId',
19
- 'duplicateAccountIds',
20
- 'duplicateAccountNames',
21
- 'nameContainsSpaces',
22
- ];
23
- class CLIConfiguration {
21
+ class _CLIConfiguration {
24
22
  options;
25
23
  useEnvConfig;
26
24
  config;
@@ -47,22 +45,22 @@ class CLIConfiguration {
47
45
  if (this.options.useEnv) {
48
46
  const configFromEnv = (0, environment_1.loadConfigFromEnvironment)();
49
47
  if (configFromEnv) {
50
- (0, logger_1.debug)(`${i18nKey}.load.configFromEnv`, {
48
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.configFromEnv`, {
51
49
  accountId: configFromEnv.accounts[0].accountId,
52
- });
50
+ }));
53
51
  this.useEnvConfig = true;
54
- this.config = configFromEnv;
52
+ this.config = this.handleLegacyCmsPublishMode(configFromEnv);
55
53
  }
56
54
  }
57
55
  else {
58
56
  const configFromFile = (0, configFile_1.loadConfigFromFile)();
59
- (0, logger_1.debug)(`${i18nKey}.load.configFromFile`);
57
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.configFromFile`));
60
58
  if (!configFromFile) {
61
- (0, logger_1.debug)(`${i18nKey}.load.empty`);
59
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.empty`));
62
60
  this.config = { accounts: [] };
63
61
  }
64
62
  this.useEnvConfig = false;
65
- this.config = configFromFile;
63
+ this.config = this.handleLegacyCmsPublishMode(configFromFile);
66
64
  }
67
65
  return this.config;
68
66
  }
@@ -97,48 +95,54 @@ class CLIConfiguration {
97
95
  }
98
96
  return this.config;
99
97
  }
100
- validate(logCallbacks) {
101
- const validateLogger = (0, logger_1.makeTypedLogger)(logCallbacks);
98
+ validate() {
102
99
  if (!this.config) {
103
- validateLogger('noConfig');
100
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noConfig`));
104
101
  return false;
105
102
  }
106
103
  if (!Array.isArray(this.config.accounts)) {
107
- validateLogger('noConfigAccounts');
104
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noConfigAccounts`));
108
105
  return false;
109
106
  }
110
107
  const accountIdsMap = {};
111
108
  const accountNamesMap = {};
112
109
  return this.config.accounts.every(accountConfig => {
113
110
  if (!accountConfig) {
114
- validateLogger('emptyAccountConfig');
111
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.emptyAccountConfig`));
115
112
  return false;
116
113
  }
117
114
  if (!accountConfig.accountId) {
118
- validateLogger('noAccountId');
115
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noAccountId`));
119
116
  return false;
120
117
  }
121
118
  if (accountIdsMap[accountConfig.accountId]) {
122
- validateLogger('duplicateAccountIds', `${i18nKey}.validate.duplicateAccountIds`, {
119
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.duplicateAccountIds`, {
123
120
  accountId: accountConfig.accountId,
124
- });
121
+ }));
125
122
  return false;
126
123
  }
127
124
  if (accountConfig.name) {
128
- if (accountNamesMap[accountConfig.name]) {
129
- validateLogger('duplicateAccountNames', `${i18nKey}.validate.duplicateAccountNames`, {
125
+ if (accountNamesMap[accountConfig.name.toLowerCase()]) {
126
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.duplicateAccountNames`, {
130
127
  accountName: accountConfig.name,
131
- });
128
+ }));
132
129
  return false;
133
130
  }
134
131
  if (/\s+/.test(accountConfig.name)) {
135
- validateLogger('nameContainsSpaces', `${i18nKey}.validate.nameContainsSpaces`, {
132
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.nameContainsSpaces`, {
136
133
  accountName: accountConfig.name,
137
- });
134
+ }));
138
135
  return false;
139
136
  }
140
137
  accountNamesMap[accountConfig.name] = true;
141
138
  }
139
+ if (!accountConfig.accountType) {
140
+ this.addOrUpdateAccount({
141
+ ...accountConfig,
142
+ accountId: accountConfig.accountId,
143
+ accountType: this.getAccountType(undefined, accountConfig.sandboxAccountType),
144
+ });
145
+ }
142
146
  accountIdsMap[accountConfig.accountId] = true;
143
147
  return true;
144
148
  });
@@ -181,34 +185,72 @@ class CLIConfiguration {
181
185
  return account ? account.accountId : null;
182
186
  }
183
187
  getDefaultAccount() {
184
- return this.config && this.config.defaultAccount
185
- ? this.config.defaultAccount
186
- : null;
188
+ return this.getCWDAccountOverride() || this.config?.defaultAccount || null;
187
189
  }
188
- // TODO a util that returns the account to use, respecting the values set in
189
- // "defaultAccountOverrides"
190
- // Example "defaultAccountOverrides":
191
- // - /src/brodgers/customer-project-1: customer-account1
192
- // - /src/brodgers/customer-project-2: customer-account2
193
- // "/src/brodgers/customer-project-1" is the path to the project dir
194
- // "customer-account1" is the name of the account to use as the default for the specified dir
195
- // These defaults take precedence over the standard default account specified in the config
196
- getResolvedDefaultAccountForCWD(nameOrId) {
197
- return this.getAccount(nameOrId);
190
+ getDefaultAccountOverrideFilePath() {
191
+ return (0, findup_sync_1.default)([config_1.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME], {
192
+ cwd: (0, path_1.getCwd)(),
193
+ });
198
194
  }
199
- getConfigAccountIndex(accountId) {
195
+ getCWDAccountOverride() {
196
+ const defaultOverrideFile = this.getDefaultAccountOverrideFilePath();
197
+ if (!defaultOverrideFile) {
198
+ return null;
199
+ }
200
+ let source;
201
+ try {
202
+ source = fs_1.default.readFileSync(defaultOverrideFile, 'utf8');
203
+ }
204
+ catch (e) {
205
+ if (e instanceof Error) {
206
+ logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.getCWDAccountOverride.readFileError`, {
207
+ error: e.message,
208
+ }));
209
+ }
210
+ return null;
211
+ }
212
+ const accountId = Number(source);
213
+ if (isNaN(accountId)) {
214
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.getCWDAccountOverride.errorHeader`, {
215
+ hsAccountFile: defaultOverrideFile,
216
+ }), {
217
+ cause: config_1.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID,
218
+ });
219
+ }
220
+ const account = this.config?.accounts?.find(account => account.accountId === accountId);
221
+ if (!account) {
222
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.getCWDAccountOverride.errorHeader`, {
223
+ hsAccountFile: defaultOverrideFile,
224
+ }), {
225
+ cause: config_1.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND,
226
+ });
227
+ }
228
+ return account.name || account.accountId;
229
+ }
230
+ getAccountIndex(accountId) {
200
231
  return this.config
201
232
  ? this.config.accounts.findIndex(account => account.accountId === accountId)
202
233
  : -1;
203
234
  }
204
235
  getConfigForAccount(accountId) {
205
236
  if (this.config) {
206
- this.config.accounts.find(account => account.accountId === accountId) ||
207
- null;
237
+ return (this.config.accounts.find(account => account.accountId === accountId) ||
238
+ null);
239
+ }
240
+ return null;
241
+ }
242
+ getConfigAccounts() {
243
+ if (this.config) {
244
+ return this.config.accounts || null;
208
245
  }
209
246
  return null;
210
247
  }
211
248
  isAccountInConfig(nameOrId) {
249
+ if (typeof nameOrId === 'string') {
250
+ return (!!this.config &&
251
+ this.config.accounts &&
252
+ !!this.getAccountId(nameOrId.toLowerCase()));
253
+ }
212
254
  return (!!this.config && this.config.accounts && !!this.getAccountId(nameOrId));
213
255
  }
214
256
  getAndLoadConfigIfNeeded(options) {
@@ -227,23 +269,41 @@ class CLIConfiguration {
227
269
  }
228
270
  return environments_1.ENVIRONMENTS.PROD;
229
271
  }
272
+ // Deprecating sandboxAccountType in favor of accountType
273
+ getAccountType(accountType, sandboxAccountType) {
274
+ if (accountType) {
275
+ return accountType;
276
+ }
277
+ if (typeof sandboxAccountType === 'string') {
278
+ if (sandboxAccountType.toUpperCase() === 'DEVELOPER') {
279
+ return config_1.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX;
280
+ }
281
+ if (sandboxAccountType.toUpperCase() === 'STANDARD') {
282
+ return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX;
283
+ }
284
+ }
285
+ return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD;
286
+ }
230
287
  /*
231
288
  * Config Update Utils
232
289
  */
233
290
  /**
234
291
  * @throws {Error}
235
292
  */
236
- updateAccount(updatedAccountFields, writeUpdate = true) {
237
- const { accountId, apiKey, authType, clientId, clientSecret, defaultMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
293
+ addOrUpdateAccount(updatedAccountFields, writeUpdate = true) {
294
+ const { accountId, accountType, apiKey, authType, clientId, clientSecret, defaultCmsPublishMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
238
295
  if (!accountId) {
239
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAccount.errors.accountIdRequired`);
296
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAccount.errors.accountIdRequired`));
240
297
  }
241
298
  if (!this.config) {
242
- (0, logger_1.debug)(`${i18nKey}.updateAccount.noConfigToUpdate`);
299
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.noConfigToUpdate`));
243
300
  return null;
244
301
  }
302
+ // Check whether the account is already listed in the config.yml file.
245
303
  const currentAccountConfig = this.getAccount(accountId);
246
- let auth = {};
304
+ // For accounts that are already in the config.yml file, sets the auth property.
305
+ let auth = (currentAccountConfig && currentAccountConfig.auth) || {};
306
+ // For accounts not already in the config.yml file, sets the auth property.
247
307
  if (clientId || clientSecret || scopes || tokenInfo) {
248
308
  auth = {
249
309
  ...(currentAccountConfig ? currentAccountConfig.auth : {}),
@@ -265,7 +325,9 @@ class CLIConfiguration {
265
325
  }
266
326
  }
267
327
  const updatedEnv = (0, environment_2.getValidEnv)(env || (currentAccountConfig && currentAccountConfig.env));
268
- const updatedDefaultMode = defaultMode && defaultMode.toLowerCase();
328
+ const updatedDefaultCmsPublishMode = defaultCmsPublishMode &&
329
+ defaultCmsPublishMode.toLowerCase();
330
+ const updatedAccountType = accountType || (currentAccountConfig && currentAccountConfig.accountType);
269
331
  safelyApplyUpdates('name', name);
270
332
  safelyApplyUpdates('env', updatedEnv);
271
333
  safelyApplyUpdates('accountId', accountId);
@@ -274,29 +336,36 @@ class CLIConfiguration {
274
336
  if (nextAccountConfig.authType === auth_1.API_KEY_AUTH_METHOD.value) {
275
337
  safelyApplyUpdates('apiKey', apiKey);
276
338
  }
277
- if (typeof updatedDefaultMode !== 'undefined') {
339
+ if (typeof updatedDefaultCmsPublishMode !== 'undefined') {
278
340
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
279
- safelyApplyUpdates('defaultMode', files_1.MODE[updatedDefaultMode]);
341
+ safelyApplyUpdates('defaultCmsPublishMode', files_1.CMS_PUBLISH_MODE[updatedDefaultCmsPublishMode]);
280
342
  }
281
343
  safelyApplyUpdates('personalAccessKey', personalAccessKey);
344
+ // Deprecating sandboxAccountType in favor of the more generic accountType
282
345
  safelyApplyUpdates('sandboxAccountType', sandboxAccountType);
346
+ safelyApplyUpdates('accountType', this.getAccountType(updatedAccountType, sandboxAccountType));
283
347
  safelyApplyUpdates('parentAccountId', parentAccountId);
284
348
  const completedAccountConfig = nextAccountConfig;
349
+ if (!Object.hasOwn(this.config, 'accounts')) {
350
+ this.config.accounts = [];
351
+ }
285
352
  if (currentAccountConfig) {
286
- (0, logger_1.debug)(`${i18nKey}.updateAccount.updating`, {
287
- accountId,
288
- });
289
- const index = this.getConfigAccountIndex(accountId);
290
- this.config.accounts[index] = completedAccountConfig;
291
- (0, logger_1.debug)(`${i18nKey}.updateAccount.addingConfigEntry`, {
353
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.updating`, {
292
354
  accountId,
293
- });
294
- if (this.config.accounts) {
355
+ }));
356
+ const index = this.getAccountIndex(accountId);
357
+ if (index < 0) {
295
358
  this.config.accounts.push(completedAccountConfig);
296
359
  }
297
360
  else {
298
- this.config.accounts = [completedAccountConfig];
361
+ this.config.accounts[index] = completedAccountConfig;
299
362
  }
363
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.addingConfigEntry`, {
364
+ accountId,
365
+ }));
366
+ }
367
+ else {
368
+ this.config.accounts.push(completedAccountConfig);
300
369
  }
301
370
  if (writeUpdate) {
302
371
  this.write();
@@ -308,11 +377,11 @@ class CLIConfiguration {
308
377
  */
309
378
  updateDefaultAccount(defaultAccount) {
310
379
  if (!this.config) {
311
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
380
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
312
381
  }
313
382
  if (!defaultAccount ||
314
383
  (typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')) {
315
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`);
384
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`));
316
385
  }
317
386
  this.config.defaultAccount = defaultAccount;
318
387
  return this.write();
@@ -322,7 +391,7 @@ class CLIConfiguration {
322
391
  */
323
392
  renameAccount(currentName, newName) {
324
393
  if (!this.config) {
325
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
394
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
326
395
  }
327
396
  const accountId = this.getAccountId(currentName);
328
397
  let accountConfigToRename = null;
@@ -330,12 +399,17 @@ class CLIConfiguration {
330
399
  accountConfigToRename = this.getAccount(accountId);
331
400
  }
332
401
  if (!accountConfigToRename) {
333
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.renameAccount.errors.invalidName`, {
402
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.renameAccount.errors.invalidName`, {
334
403
  currentName,
335
- });
404
+ }));
336
405
  }
337
406
  if (accountId) {
338
- this.updateAccount({ accountId, name: newName, env: this.getEnv() });
407
+ this.addOrUpdateAccount({
408
+ accountId,
409
+ name: newName,
410
+ env: this.getEnv(),
411
+ accountType: accountConfigToRename.accountType,
412
+ });
339
413
  }
340
414
  if (accountConfigToRename.name === this.getDefaultAccount()) {
341
415
  this.updateDefaultAccount(newName);
@@ -343,20 +417,23 @@ class CLIConfiguration {
343
417
  }
344
418
  /**
345
419
  * @throws {Error}
420
+ * TODO: this does not account for the special handling of sandbox account deletes
346
421
  */
347
422
  removeAccountFromConfig(nameOrId) {
348
423
  if (!this.config) {
349
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
424
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
350
425
  }
351
426
  const accountId = this.getAccountId(nameOrId);
352
427
  if (!accountId) {
353
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, { nameOrId });
428
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, {
429
+ nameOrId,
430
+ }));
354
431
  }
355
432
  let removedAccountIsDefault = false;
356
433
  const accountConfig = this.getAccount(accountId);
357
434
  if (accountConfig) {
358
- (0, logger_1.debug)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId });
359
- const index = this.getConfigAccountIndex(accountId);
435
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId }));
436
+ const index = this.getAccountIndex(accountId);
360
437
  this.config.accounts.splice(index, 1);
361
438
  if (this.getDefaultAccount() === accountConfig.name) {
362
439
  removedAccountIsDefault = true;
@@ -368,18 +445,19 @@ class CLIConfiguration {
368
445
  /**
369
446
  * @throws {Error}
370
447
  */
371
- updateDefaultMode(defaultMode) {
448
+ updateDefaultCmsPublishMode(defaultCmsPublishMode) {
372
449
  if (!this.config) {
373
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
450
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
374
451
  }
375
- const ALL_MODES = Object.values(files_1.MODE);
376
- if (!defaultMode || !ALL_MODES.find(m => m === defaultMode)) {
377
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultMode.errors.invalidMode`, {
378
- defaultMode,
379
- validModes: (0, text_1.commaSeparatedValues)(ALL_MODES),
380
- });
452
+ const ALL_CMS_PUBLISH_MODES = Object.values(files_1.CMS_PUBLISH_MODE);
453
+ if (!defaultCmsPublishMode ||
454
+ !ALL_CMS_PUBLISH_MODES.find(m => m === defaultCmsPublishMode)) {
455
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultCmsPublishMode.errors.invalidCmsPublishMode`, {
456
+ defaultCmsPublishMode,
457
+ validCmsPublishModes: (0, text_1.commaSeparatedValues)(ALL_CMS_PUBLISH_MODES),
458
+ }));
381
459
  }
382
- this.config.defaultMode = defaultMode;
460
+ this.config.defaultCmsPublishMode = defaultCmsPublishMode;
383
461
  return this.write();
384
462
  }
385
463
  /**
@@ -387,14 +465,14 @@ class CLIConfiguration {
387
465
  */
388
466
  updateHttpTimeout(timeout) {
389
467
  if (!this.config) {
390
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
468
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
391
469
  }
392
470
  const parsedTimeout = parseInt(timeout);
393
471
  if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
394
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
472
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
395
473
  timeout,
396
474
  minTimeout: config_1.MIN_HTTP_TIMEOUT,
397
- });
475
+ }));
398
476
  }
399
477
  this.config.httpTimeout = parsedTimeout;
400
478
  return this.write();
@@ -404,12 +482,12 @@ class CLIConfiguration {
404
482
  */
405
483
  updateAllowUsageTracking(isEnabled) {
406
484
  if (!this.config) {
407
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
485
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
408
486
  }
409
487
  if (typeof isEnabled !== 'boolean') {
410
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
488
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
411
489
  isEnabled: `${isEnabled}`,
412
- });
490
+ }));
413
491
  }
414
492
  this.config.allowUsageTracking = isEnabled;
415
493
  return this.write();
@@ -420,5 +498,12 @@ class CLIConfiguration {
420
498
  }
421
499
  return this.config.allowUsageTracking !== false;
422
500
  }
501
+ handleLegacyCmsPublishMode(config) {
502
+ if (config?.defaultMode) {
503
+ config.defaultCmsPublishMode = config.defaultMode;
504
+ delete config.defaultMode;
505
+ }
506
+ return config;
507
+ }
423
508
  }
424
- exports.default = new CLIConfiguration();
509
+ exports.CLIConfiguration = new _CLIConfiguration();
@@ -8,11 +8,11 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const os_1 = __importDefault(require("os"));
10
10
  const js_yaml_1 = __importDefault(require("js-yaml"));
11
- const logger_1 = require("../utils/logger");
12
- const fileSystemErrors_1 = require("../errors/fileSystemErrors");
13
- const standardErrors_1 = require("../errors/standardErrors");
11
+ const logger_1 = require("../lib/logger");
14
12
  const config_1 = require("../constants/config");
15
13
  const configUtils_1 = require("./configUtils");
14
+ const lang_1 = require("../utils/lang");
15
+ const FileSystemError_1 = require("../models/FileSystemError");
16
16
  const i18nKey = 'config.configFile';
17
17
  function getConfigFilePath() {
18
18
  return path_1.default.join(os_1.default.homedir(), config_1.HUBSPOT_CONFIGURATION_FOLDER, config_1.HUBSPOT_CONFIGURATION_FILE);
@@ -42,10 +42,10 @@ function readConfigFile(configPath) {
42
42
  source = fs_extra_1.default.readFileSync(configPath).toString();
43
43
  }
44
44
  catch (err) {
45
- (0, logger_1.debug)(`${i18nKey}.errorReading`, { configPath });
46
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
45
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorReading`, { configPath }));
46
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
47
47
  filepath: configPath,
48
- read: true,
48
+ operation: 'read',
49
49
  });
50
50
  }
51
51
  return source;
@@ -60,7 +60,7 @@ function parseConfig(configSource) {
60
60
  parsed = js_yaml_1.default.load(configSource);
61
61
  }
62
62
  catch (err) {
63
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.parsing`, {}, err);
63
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.parsing`), { cause: err });
64
64
  }
65
65
  return parsed;
66
66
  }
@@ -77,7 +77,7 @@ function loadConfigFromFile() {
77
77
  }
78
78
  return parseConfig(source);
79
79
  }
80
- (0, logger_1.debug)(`${i18nKey}.errorLoading`, { configPath });
80
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorLoading`, { configPath }));
81
81
  return null;
82
82
  }
83
83
  exports.loadConfigFromFile = loadConfigFromFile;
@@ -85,23 +85,17 @@ exports.loadConfigFromFile = loadConfigFromFile;
85
85
  * @throws {Error}
86
86
  */
87
87
  function writeConfigToFile(config) {
88
- let source;
89
- try {
90
- source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
91
- }
92
- catch (err) {
93
- (0, standardErrors_1.throwError)(err);
94
- }
88
+ const source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
95
89
  const configPath = getConfigFilePath();
96
90
  try {
97
91
  fs_extra_1.default.ensureFileSync(configPath);
98
92
  fs_extra_1.default.writeFileSync(configPath, source);
99
- (0, logger_1.debug)(`${i18nKey}.writeSuccess`, { configPath });
93
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.writeSuccess`, { configPath }));
100
94
  }
101
95
  catch (err) {
102
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
96
+ throw new FileSystemError_1.FileSystemError({ cause: err }, {
103
97
  filepath: configPath,
104
- write: true,
98
+ operation: 'write',
105
99
  });
106
100
  }
107
101
  }
@@ -1,24 +1,5 @@
1
- import { CLIConfig_NEW, Environment } from '../types/Config';
2
- import { AuthType, CLIAccount_NEW } from '../types/Accounts';
1
+ import { CLIConfig_NEW } from '../types/Config';
2
+ import { AuthType, CLIAccount_NEW, PersonalAccessKeyOptions, OAuthOptions, APIKeyOptions } from '../types/Accounts';
3
3
  export declare function getOrderedAccount(unorderedAccount: CLIAccount_NEW): CLIAccount_NEW;
4
4
  export declare function getOrderedConfig(unorderedConfig: CLIConfig_NEW): CLIConfig_NEW;
5
- type PersonalAccessKeyOptions = {
6
- accountId: number;
7
- personalAccessKey: string;
8
- env: Environment;
9
- };
10
- type OAuthOptions = {
11
- accountId: number;
12
- clientId: string;
13
- clientSecret: string;
14
- refreshToken: string;
15
- scopes: Array<string>;
16
- env: Environment;
17
- };
18
- type APIKeyOptions = {
19
- accountId: number;
20
- apiKey: string;
21
- env: Environment;
22
- };
23
5
  export declare function generateConfig(type: AuthType, options: PersonalAccessKeyOptions | OAuthOptions | APIKeyOptions): CLIConfig_NEW | null;
24
- export {};
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateConfig = exports.getOrderedConfig = exports.getOrderedAccount = void 0;
4
- const logger_1 = require("../utils/logger");
4
+ const logger_1 = require("../lib/logger");
5
5
  const auth_1 = require("../constants/auth");
6
+ const lang_1 = require("../utils/lang");
6
7
  const i18nKey = 'config.configUtils';
7
8
  function getOrderedAccount(unorderedAccount) {
8
9
  const { name, accountId, env, authType, ...rest } = unorderedAccount;
@@ -16,10 +17,10 @@ function getOrderedAccount(unorderedAccount) {
16
17
  }
17
18
  exports.getOrderedAccount = getOrderedAccount;
18
19
  function getOrderedConfig(unorderedConfig) {
19
- const { defaultAccount, defaultMode, httpTimeout, allowUsageTracking, accounts, ...rest } = unorderedConfig;
20
+ const { defaultAccount, defaultCmsPublishMode, httpTimeout, allowUsageTracking, accounts, ...rest } = unorderedConfig;
20
21
  return {
21
22
  ...(defaultAccount && { defaultAccount }),
22
- defaultMode,
23
+ defaultCmsPublishMode,
23
24
  httpTimeout,
24
25
  allowUsageTracking,
25
26
  ...rest,
@@ -75,7 +76,7 @@ function generateConfig(type, options) {
75
76
  configAccount = generateOauthAccountConfig(options);
76
77
  break;
77
78
  default:
78
- (0, logger_1.debug)(`${i18nKey}.unknownType`, { type });
79
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.unknownType`, { type }));
79
80
  return null;
80
81
  }
81
82
  if (configAccount) {
@@ -1,6 +1,6 @@
1
1
  import { CLIConfig_DEPRECATED, Environment } from '../types/Config';
2
- import { CLIAccount_DEPRECATED, FlatAccountFields_DEPRECATED } from '../types/Accounts';
3
- import { Mode } from '../types/Files';
2
+ import { AccountType, CLIAccount_DEPRECATED, FlatAccountFields_DEPRECATED, UpdateAccountConfigOptions } from '../types/Accounts';
3
+ import { CmsPublishMode } from '../types/Files';
4
4
  import { CLIOptions, WriteConfigOptions } from '../types/CLIOptions';
5
5
  export declare const getConfig: () => CLIConfig_DEPRECATED | null;
6
6
  export declare function setConfig(updatedConfig?: CLIConfig_DEPRECATED): CLIConfig_DEPRECATED | null;
@@ -14,9 +14,10 @@ export declare function accountNameExistsInConfig(name: string): boolean;
14
14
  export declare function getOrderedAccount(unorderedAccount: CLIAccount_DEPRECATED): CLIAccount_DEPRECATED;
15
15
  export declare function getOrderedConfig(unorderedConfig: CLIConfig_DEPRECATED): {
16
16
  portals: CLIAccount_DEPRECATED[];
17
+ defaultMode?: CmsPublishMode | undefined;
17
18
  env?: Environment | undefined;
18
19
  httpUseLocalhost?: boolean | undefined;
19
- defaultMode: string | undefined;
20
+ defaultCmsPublishMode: CmsPublishMode | undefined;
20
21
  httpTimeout: number | undefined;
21
22
  allowUsageTracking: boolean | undefined;
22
23
  defaultPortal?: string | number | undefined;
@@ -27,15 +28,13 @@ export declare function isTrackingAllowed(): boolean;
27
28
  export declare function getAndLoadConfigIfNeeded(options?: {}): Partial<CLIConfig_DEPRECATED>;
28
29
  export declare function findConfig(directory: string): string | null;
29
30
  export declare function getEnv(nameOrId?: string | number): Environment;
31
+ export declare function getAccountType(accountType?: AccountType, sandboxAccountType?: string | null): AccountType;
30
32
  export declare function getAccountConfig(accountId: number | undefined): CLIAccount_DEPRECATED | undefined;
31
33
  export declare function getAccountId(nameOrId?: string | number): number | undefined;
32
34
  /**
33
35
  * @throws {Error}
34
36
  */
35
37
  export declare function removeSandboxAccountFromConfig(nameOrId: string | number): boolean;
36
- type UpdateAccountConfigOptions = Partial<FlatAccountFields_DEPRECATED> & {
37
- environment?: Environment;
38
- };
39
38
  /**
40
39
  * @throws {Error}
41
40
  */
@@ -47,7 +46,7 @@ export declare function updateDefaultAccount(defaultAccount: string | number): v
47
46
  /**
48
47
  * @throws {Error}
49
48
  */
50
- export declare function updateDefaultMode(defaultMode: Mode): void;
49
+ export declare function updateDefaultCmsPublishMode(defaultCmsPublishMode: CmsPublishMode): void;
51
50
  /**
52
51
  * @throws {Error}
53
52
  */
@@ -75,4 +74,3 @@ export declare function loadConfigFromEnvironment({ useEnv, }?: {
75
74
  portals: Array<CLIAccount_DEPRECATED>;
76
75
  } | undefined;
77
76
  export declare function isConfigFlagEnabled(flag: keyof CLIConfig_DEPRECATED): boolean;
78
- export {};