@hubspot/local-dev-lib 0.1.1 → 0.1.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 (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 +17 -17
  15. package/api/fileTransport.d.ts +4 -0
  16. package/api/fileTransport.js +39 -0
  17. package/api/functions.d.ts +7 -4
  18. package/api/functions.js +22 -11
  19. package/api/github.d.ts +7 -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 +7 -15
  26. package/api/localDevAuth.js +28 -13
  27. package/api/marketplaceValidation.d.ts +4 -4
  28. package/api/marketplaceValidation.js +8 -11
  29. package/api/projects.d.ts +31 -24
  30. package/api/projects.js +154 -44
  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 +179 -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 +12 -7
  50. package/config/index.js +95 -55
  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/errors/errors_DEPRECATED.d.ts +1 -5
  60. package/errors/errors_DEPRECATED.js +2 -2
  61. package/errors/index.d.ts +18 -0
  62. package/errors/index.js +63 -0
  63. package/http/addQueryParams.d.ts +2 -0
  64. package/http/addQueryParams.js +14 -0
  65. package/http/getAxiosConfig.d.ts +6 -3
  66. package/http/getAxiosConfig.js +51 -7
  67. package/http/index.d.ts +11 -12
  68. package/http/index.js +35 -41
  69. package/http/unauthed.d.ts +14 -0
  70. package/http/unauthed.js +38 -0
  71. package/lang/en.json +378 -383
  72. package/lib/archive.d.ts +2 -8
  73. package/lib/archive.js +34 -30
  74. package/lib/cms/functions.d.ts +7 -12
  75. package/lib/cms/functions.js +47 -50
  76. package/lib/cms/handleFieldsJS.js +16 -14
  77. package/lib/cms/modules.d.ts +5 -15
  78. package/lib/cms/modules.js +100 -39
  79. package/lib/cms/processFieldsJs.js +10 -33
  80. package/lib/cms/templates.d.ts +43 -3
  81. package/lib/cms/templates.js +51 -11
  82. package/lib/cms/uploadFolder.d.ts +3 -14
  83. package/lib/cms/uploadFolder.js +58 -42
  84. package/lib/cms/validate.js +1 -1
  85. package/lib/cms/watch.d.ts +2 -18
  86. package/lib/cms/watch.js +63 -68
  87. package/lib/customObjects.js +4 -15
  88. package/lib/fileManager.d.ts +2 -6
  89. package/lib/fileManager.js +54 -65
  90. package/lib/fileMapper.d.ts +4 -15
  91. package/lib/fileMapper.js +67 -88
  92. package/lib/fs.d.ts +1 -1
  93. package/lib/fs.js +10 -6
  94. package/lib/github.d.ts +5 -14
  95. package/lib/github.js +57 -28
  96. package/lib/gitignore.d.ts +2 -0
  97. package/lib/gitignore.js +21 -4
  98. package/lib/hubdb.d.ts +3 -2
  99. package/lib/hubdb.js +11 -9
  100. package/lib/{logging/logger.d.ts → logger.d.ts} +20 -8
  101. package/{utils → lib}/notify.js +2 -2
  102. package/lib/oauth.d.ts +2 -5
  103. package/lib/oauth.js +14 -25
  104. package/lib/path.d.ts +3 -0
  105. package/lib/path.js +46 -1
  106. package/lib/personalAccessKey.d.ts +7 -10
  107. package/lib/personalAccessKey.js +74 -47
  108. package/lib/portManager.d.ts +3 -5
  109. package/lib/portManager.js +18 -6
  110. package/lib/text.d.ts +1 -0
  111. package/lib/text.js +9 -1
  112. package/lib/trackUsage.js +18 -11
  113. package/lib/urls.js +5 -1
  114. package/models/FileSystemError.d.ts +6 -0
  115. package/models/FileSystemError.js +47 -0
  116. package/models/HubSpotHttpError.d.ts +24 -0
  117. package/models/HubSpotHttpError.js +197 -0
  118. package/models/OAuth2Manager.d.ts +5 -27
  119. package/models/OAuth2Manager.js +41 -64
  120. package/package.json +19 -18
  121. package/types/Accounts.d.ts +90 -3
  122. package/types/Apps.d.ts +77 -0
  123. package/types/Archive.d.ts +9 -0
  124. package/types/Archive.js +2 -0
  125. package/types/Build.d.ts +4 -2
  126. package/types/ComponentStructure.d.ts +30 -10
  127. package/types/Config.d.ts +19 -2
  128. package/types/Deploy.d.ts +3 -2
  129. package/types/DesignManager.d.ts +10 -0
  130. package/types/DesignManager.js +2 -0
  131. package/types/Error.d.ts +9 -5
  132. package/types/FieldsJS.d.ts +1 -0
  133. package/types/FieldsJS.js +2 -0
  134. package/types/FileManager.d.ts +1 -1
  135. package/types/Files.d.ts +43 -4
  136. package/types/Functions.d.ts +52 -0
  137. package/types/Github.d.ts +12 -0
  138. package/types/Http.d.ts +12 -11
  139. package/types/Hubdb.d.ts +9 -0
  140. package/types/MarketplaceValidation.d.ts +7 -3
  141. package/types/Migration.d.ts +28 -0
  142. package/types/Migration.js +10 -0
  143. package/types/Modules.d.ts +11 -0
  144. package/types/PortManager.d.ts +7 -0
  145. package/types/Project.d.ts +30 -0
  146. package/types/ProjectLog.d.ts +9 -0
  147. package/types/ProjectLog.js +2 -0
  148. package/types/Sandbox.d.ts +37 -47
  149. package/types/Schemas.d.ts +12 -0
  150. package/types/Secrets.d.ts +3 -0
  151. package/types/Secrets.js +2 -0
  152. package/types/developerTestAccounts.d.ts +13 -0
  153. package/types/developerTestAccounts.js +2 -0
  154. package/utils/PortManagerServer.d.ts +6 -7
  155. package/utils/PortManagerServer.js +22 -16
  156. package/utils/{getAccountIdentifier.d.ts → accounts.d.ts} +0 -6
  157. package/utils/{getAccountIdentifier.js → accounts.js} +1 -13
  158. package/utils/cms/fieldsJS.d.ts +1 -2
  159. package/utils/cms/modules.js +2 -2
  160. package/utils/detectPort.js +3 -3
  161. package/utils/git.d.ts +1 -7
  162. package/utils/git.js +2 -18
  163. package/errors/apiErrors.d.ts +0 -19
  164. package/errors/apiErrors.js +0 -179
  165. package/errors/fileSystemErrors.d.ts +0 -5
  166. package/errors/fileSystemErrors.js +0 -31
  167. package/errors/standardErrors.d.ts +0 -27
  168. package/errors/standardErrors.js +0 -59
  169. package/lang/lang/en.json +0 -398
  170. package/lib/logging/git.d.ts +0 -2
  171. package/lib/logging/git.js +0 -54
  172. package/lib/logging/logs.d.ts +0 -22
  173. package/lib/logging/logs.js +0 -86
  174. package/lib/logging/table.d.ts +0 -3
  175. package/lib/logging/table.js +0 -47
  176. package/lib/sandboxes.d.ts +0 -14
  177. package/lib/sandboxes.js +0 -71
  178. package/models/HubSpotAuthError.d.ts +0 -12
  179. package/models/HubSpotAuthError.js +0 -20
  180. package/types/LogCallbacks.d.ts +0 -7
  181. package/utils/logger.d.ts +0 -5
  182. package/utils/logger.js +0 -23
  183. package/utils/objectUtils.d.ts +0 -8
  184. package/utils/objectUtils.js +0 -33
  185. /package/{utils → lib}/escapeRegExp.d.ts +0 -0
  186. /package/{utils → lib}/escapeRegExp.js +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,76 @@ 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
+ });
194
+ }
195
+ getCWDAccountOverride() {
196
+ const defaultOverrideFile = this.getDefaultAccountOverrideFilePath();
197
+ if (!defaultOverrideFile) {
198
+ return null;
199
+ }
200
+ try {
201
+ const source = fs_1.default.readFileSync(defaultOverrideFile, 'utf8');
202
+ const accountId = Number(source);
203
+ if (isNaN(accountId)) {
204
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.getCWDAccountOverride.errorHeader`, {
205
+ hsAccountFile: defaultOverrideFile,
206
+ }), {
207
+ cause: config_1.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID,
208
+ });
209
+ }
210
+ const account = this.config?.accounts?.find(account => account.accountId === accountId);
211
+ if (!account) {
212
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.getCWDAccountOverride.errorHeader`, {
213
+ hsAccountFile: defaultOverrideFile,
214
+ }), {
215
+ cause: config_1.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND,
216
+ });
217
+ }
218
+ return account.name || account.accountId;
219
+ }
220
+ catch (e) {
221
+ if (e instanceof Error) {
222
+ logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.getCWDAccountOverride.readFileError`, {
223
+ error: e.message,
224
+ }));
225
+ }
226
+ else {
227
+ logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.getCWDAccountOverride.readFileError`, {
228
+ error: String(e),
229
+ }));
230
+ }
231
+ return null;
232
+ }
198
233
  }
199
- getConfigAccountIndex(accountId) {
234
+ getAccountIndex(accountId) {
200
235
  return this.config
201
236
  ? this.config.accounts.findIndex(account => account.accountId === accountId)
202
237
  : -1;
203
238
  }
204
239
  getConfigForAccount(accountId) {
205
240
  if (this.config) {
206
- this.config.accounts.find(account => account.accountId === accountId) ||
207
- null;
241
+ return (this.config.accounts.find(account => account.accountId === accountId) ||
242
+ null);
243
+ }
244
+ return null;
245
+ }
246
+ getConfigAccounts() {
247
+ if (this.config) {
248
+ return this.config.accounts || null;
208
249
  }
209
250
  return null;
210
251
  }
211
252
  isAccountInConfig(nameOrId) {
253
+ if (typeof nameOrId === 'string') {
254
+ return (!!this.config &&
255
+ this.config.accounts &&
256
+ !!this.getAccountId(nameOrId.toLowerCase()));
257
+ }
212
258
  return (!!this.config && this.config.accounts && !!this.getAccountId(nameOrId));
213
259
  }
214
260
  getAndLoadConfigIfNeeded(options) {
@@ -227,23 +273,41 @@ class CLIConfiguration {
227
273
  }
228
274
  return environments_1.ENVIRONMENTS.PROD;
229
275
  }
276
+ // Deprecating sandboxAccountType in favor of accountType
277
+ getAccountType(accountType, sandboxAccountType) {
278
+ if (accountType) {
279
+ return accountType;
280
+ }
281
+ if (typeof sandboxAccountType === 'string') {
282
+ if (sandboxAccountType.toUpperCase() === 'DEVELOPER') {
283
+ return config_1.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX;
284
+ }
285
+ if (sandboxAccountType.toUpperCase() === 'STANDARD') {
286
+ return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX;
287
+ }
288
+ }
289
+ return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD;
290
+ }
230
291
  /*
231
292
  * Config Update Utils
232
293
  */
233
294
  /**
234
295
  * @throws {Error}
235
296
  */
236
- updateAccount(updatedAccountFields, writeUpdate = true) {
237
- const { accountId, apiKey, authType, clientId, clientSecret, defaultMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
297
+ addOrUpdateAccount(updatedAccountFields, writeUpdate = true) {
298
+ const { accountId, accountType, apiKey, authType, clientId, clientSecret, defaultCmsPublishMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
238
299
  if (!accountId) {
239
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAccount.errors.accountIdRequired`);
300
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAccount.errors.accountIdRequired`));
240
301
  }
241
302
  if (!this.config) {
242
- (0, logger_1.debug)(`${i18nKey}.updateAccount.noConfigToUpdate`);
303
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.noConfigToUpdate`));
243
304
  return null;
244
305
  }
306
+ // Check whether the account is already listed in the config.yml file.
245
307
  const currentAccountConfig = this.getAccount(accountId);
246
- let auth = {};
308
+ // For accounts that are already in the config.yml file, sets the auth property.
309
+ let auth = (currentAccountConfig && currentAccountConfig.auth) || {};
310
+ // For accounts not already in the config.yml file, sets the auth property.
247
311
  if (clientId || clientSecret || scopes || tokenInfo) {
248
312
  auth = {
249
313
  ...(currentAccountConfig ? currentAccountConfig.auth : {}),
@@ -265,7 +329,9 @@ class CLIConfiguration {
265
329
  }
266
330
  }
267
331
  const updatedEnv = (0, environment_2.getValidEnv)(env || (currentAccountConfig && currentAccountConfig.env));
268
- const updatedDefaultMode = defaultMode && defaultMode.toLowerCase();
332
+ const updatedDefaultCmsPublishMode = defaultCmsPublishMode &&
333
+ defaultCmsPublishMode.toLowerCase();
334
+ const updatedAccountType = accountType || (currentAccountConfig && currentAccountConfig.accountType);
269
335
  safelyApplyUpdates('name', name);
270
336
  safelyApplyUpdates('env', updatedEnv);
271
337
  safelyApplyUpdates('accountId', accountId);
@@ -274,29 +340,36 @@ class CLIConfiguration {
274
340
  if (nextAccountConfig.authType === auth_1.API_KEY_AUTH_METHOD.value) {
275
341
  safelyApplyUpdates('apiKey', apiKey);
276
342
  }
277
- if (typeof updatedDefaultMode !== 'undefined') {
343
+ if (typeof updatedDefaultCmsPublishMode !== 'undefined') {
278
344
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
279
- safelyApplyUpdates('defaultMode', files_1.MODE[updatedDefaultMode]);
345
+ safelyApplyUpdates('defaultCmsPublishMode', files_1.CMS_PUBLISH_MODE[updatedDefaultCmsPublishMode]);
280
346
  }
281
347
  safelyApplyUpdates('personalAccessKey', personalAccessKey);
348
+ // Deprecating sandboxAccountType in favor of the more generic accountType
282
349
  safelyApplyUpdates('sandboxAccountType', sandboxAccountType);
350
+ safelyApplyUpdates('accountType', this.getAccountType(updatedAccountType, sandboxAccountType));
283
351
  safelyApplyUpdates('parentAccountId', parentAccountId);
284
352
  const completedAccountConfig = nextAccountConfig;
353
+ if (!Object.hasOwn(this.config, 'accounts')) {
354
+ this.config.accounts = [];
355
+ }
285
356
  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`, {
357
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.updating`, {
292
358
  accountId,
293
- });
294
- if (this.config.accounts) {
359
+ }));
360
+ const index = this.getAccountIndex(accountId);
361
+ if (index < 0) {
295
362
  this.config.accounts.push(completedAccountConfig);
296
363
  }
297
364
  else {
298
- this.config.accounts = [completedAccountConfig];
365
+ this.config.accounts[index] = completedAccountConfig;
299
366
  }
367
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.addingConfigEntry`, {
368
+ accountId,
369
+ }));
370
+ }
371
+ else {
372
+ this.config.accounts.push(completedAccountConfig);
300
373
  }
301
374
  if (writeUpdate) {
302
375
  this.write();
@@ -308,11 +381,11 @@ class CLIConfiguration {
308
381
  */
309
382
  updateDefaultAccount(defaultAccount) {
310
383
  if (!this.config) {
311
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
384
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
312
385
  }
313
386
  if (!defaultAccount ||
314
387
  (typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')) {
315
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`);
388
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`));
316
389
  }
317
390
  this.config.defaultAccount = defaultAccount;
318
391
  return this.write();
@@ -322,7 +395,7 @@ class CLIConfiguration {
322
395
  */
323
396
  renameAccount(currentName, newName) {
324
397
  if (!this.config) {
325
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
398
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
326
399
  }
327
400
  const accountId = this.getAccountId(currentName);
328
401
  let accountConfigToRename = null;
@@ -330,12 +403,17 @@ class CLIConfiguration {
330
403
  accountConfigToRename = this.getAccount(accountId);
331
404
  }
332
405
  if (!accountConfigToRename) {
333
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.renameAccount.errors.invalidName`, {
406
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.renameAccount.errors.invalidName`, {
334
407
  currentName,
335
- });
408
+ }));
336
409
  }
337
410
  if (accountId) {
338
- this.updateAccount({ accountId, name: newName, env: this.getEnv() });
411
+ this.addOrUpdateAccount({
412
+ accountId,
413
+ name: newName,
414
+ env: this.getEnv(),
415
+ accountType: accountConfigToRename.accountType,
416
+ });
339
417
  }
340
418
  if (accountConfigToRename.name === this.getDefaultAccount()) {
341
419
  this.updateDefaultAccount(newName);
@@ -343,20 +421,23 @@ class CLIConfiguration {
343
421
  }
344
422
  /**
345
423
  * @throws {Error}
424
+ * TODO: this does not account for the special handling of sandbox account deletes
346
425
  */
347
426
  removeAccountFromConfig(nameOrId) {
348
427
  if (!this.config) {
349
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
428
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
350
429
  }
351
430
  const accountId = this.getAccountId(nameOrId);
352
431
  if (!accountId) {
353
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, { nameOrId });
432
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, {
433
+ nameOrId,
434
+ }));
354
435
  }
355
436
  let removedAccountIsDefault = false;
356
437
  const accountConfig = this.getAccount(accountId);
357
438
  if (accountConfig) {
358
- (0, logger_1.debug)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId });
359
- const index = this.getConfigAccountIndex(accountId);
439
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId }));
440
+ const index = this.getAccountIndex(accountId);
360
441
  this.config.accounts.splice(index, 1);
361
442
  if (this.getDefaultAccount() === accountConfig.name) {
362
443
  removedAccountIsDefault = true;
@@ -368,18 +449,19 @@ class CLIConfiguration {
368
449
  /**
369
450
  * @throws {Error}
370
451
  */
371
- updateDefaultMode(defaultMode) {
452
+ updateDefaultCmsPublishMode(defaultCmsPublishMode) {
372
453
  if (!this.config) {
373
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
454
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
374
455
  }
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
- });
456
+ const ALL_CMS_PUBLISH_MODES = Object.values(files_1.CMS_PUBLISH_MODE);
457
+ if (!defaultCmsPublishMode ||
458
+ !ALL_CMS_PUBLISH_MODES.find(m => m === defaultCmsPublishMode)) {
459
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultCmsPublishMode.errors.invalidCmsPublishMode`, {
460
+ defaultCmsPublishMode,
461
+ validCmsPublishModes: (0, text_1.commaSeparatedValues)(ALL_CMS_PUBLISH_MODES),
462
+ }));
381
463
  }
382
- this.config.defaultMode = defaultMode;
464
+ this.config.defaultCmsPublishMode = defaultCmsPublishMode;
383
465
  return this.write();
384
466
  }
385
467
  /**
@@ -387,14 +469,14 @@ class CLIConfiguration {
387
469
  */
388
470
  updateHttpTimeout(timeout) {
389
471
  if (!this.config) {
390
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
472
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
391
473
  }
392
474
  const parsedTimeout = parseInt(timeout);
393
475
  if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
394
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
476
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
395
477
  timeout,
396
478
  minTimeout: config_1.MIN_HTTP_TIMEOUT,
397
- });
479
+ }));
398
480
  }
399
481
  this.config.httpTimeout = parsedTimeout;
400
482
  return this.write();
@@ -404,12 +486,12 @@ class CLIConfiguration {
404
486
  */
405
487
  updateAllowUsageTracking(isEnabled) {
406
488
  if (!this.config) {
407
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
489
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
408
490
  }
409
491
  if (typeof isEnabled !== 'boolean') {
410
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
492
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
411
493
  isEnabled: `${isEnabled}`,
412
- });
494
+ }));
413
495
  }
414
496
  this.config.allowUsageTracking = isEnabled;
415
497
  return this.write();
@@ -420,5 +502,12 @@ class CLIConfiguration {
420
502
  }
421
503
  return this.config.allowUsageTracking !== false;
422
504
  }
505
+ handleLegacyCmsPublishMode(config) {
506
+ if (config?.defaultMode) {
507
+ config.defaultCmsPublishMode = config.defaultMode;
508
+ delete config.defaultMode;
509
+ }
510
+ return config;
511
+ }
423
512
  }
424
- exports.default = new CLIConfiguration();
513
+ 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 {};