@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
package/api/github.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import { GithubReleaseData, GithubRepoFile, RepoPath } from '../types/Github';
4
3
  import { HubSpotPromise } from '../types/Http';
5
4
  declare global {
package/api/projects.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import { HubSpotPromise, QueryParams } from '../types/Http';
4
3
  import { Project, FetchProjectResponse, UploadProjectResponse, ProjectSettings, FetchPlatformVersionResponse, WarnLogsResponse, UploadIRResponse } from '../types/Project';
5
4
  import { Build, FetchProjectBuildsResponse } from '../types/Build';
@@ -0,0 +1,65 @@
1
+ import { CLIConfig_NEW, Environment } from '../types/Config';
2
+ import { CLIAccount_NEW, FlatAccountFields_NEW, AccountType } from '../types/Accounts';
3
+ import { CLIOptions } from '../types/CLIOptions';
4
+ import { CmsPublishMode } from '../types/Files';
5
+ declare class _CLIConfiguration {
6
+ options: CLIOptions;
7
+ useEnvConfig: boolean;
8
+ config: CLIConfig_NEW | null;
9
+ active: boolean;
10
+ constructor();
11
+ setActive(isActive: boolean): void;
12
+ isActive(): boolean;
13
+ init(options?: CLIOptions): CLIConfig_NEW | null;
14
+ load(): CLIConfig_NEW | null;
15
+ configIsEmpty(): boolean;
16
+ delete(): void;
17
+ write(updatedConfig?: CLIConfig_NEW): CLIConfig_NEW | null;
18
+ validate(): boolean;
19
+ getAccount(nameOrId: string | number | undefined): CLIAccount_NEW | null;
20
+ isConfigFlagEnabled(flag: keyof CLIConfig_NEW, defaultValue?: boolean): boolean;
21
+ getAccountId(nameOrId?: string | number): number | null;
22
+ getDefaultAccount(): string | number | null;
23
+ getDefaultAccountOverrideFilePath(): string | null;
24
+ getCWDAccountOverride(): string | number | null;
25
+ getAccountIndex(accountId: number): number;
26
+ getConfigForAccount(accountId?: number): CLIAccount_NEW | null;
27
+ getConfigAccounts(): Array<CLIAccount_NEW> | null;
28
+ isAccountInConfig(nameOrId: string | number): boolean;
29
+ getAndLoadConfigIfNeeded(options?: CLIOptions): CLIConfig_NEW;
30
+ getEnv(nameOrId?: string | number): Environment;
31
+ getAccountType(accountType?: AccountType | null, sandboxAccountType?: string | null): AccountType;
32
+ /**
33
+ * @throws {Error}
34
+ */
35
+ addOrUpdateAccount(updatedAccountFields: Partial<FlatAccountFields_NEW>, writeUpdate?: boolean): FlatAccountFields_NEW | null;
36
+ /**
37
+ * @throws {Error}
38
+ */
39
+ updateDefaultAccount(defaultAccount: string | number): CLIConfig_NEW | null;
40
+ /**
41
+ * @throws {Error}
42
+ */
43
+ renameAccount(currentName: string, newName: string): void;
44
+ /**
45
+ * @throws {Error}
46
+ * TODO: this does not account for the special handling of sandbox account deletes
47
+ */
48
+ removeAccountFromConfig(nameOrId: string | number): boolean;
49
+ /**
50
+ * @throws {Error}
51
+ */
52
+ updateDefaultCmsPublishMode(defaultCmsPublishMode: CmsPublishMode): CLIConfig_NEW | null;
53
+ /**
54
+ * @throws {Error}
55
+ */
56
+ updateHttpTimeout(timeout: string): CLIConfig_NEW | null;
57
+ /**
58
+ * @throws {Error}
59
+ */
60
+ updateAllowUsageTracking(isEnabled: boolean): CLIConfig_NEW | null;
61
+ isTrackingAllowed(): boolean;
62
+ handleLegacyCmsPublishMode(config: CLIConfig_NEW | null): CLIConfig_NEW | null;
63
+ }
64
+ export declare const CLIConfiguration: _CLIConfiguration;
65
+ export {};
@@ -0,0 +1,509 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
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");
11
+ const environment_1 = require("./environment");
12
+ const environment_2 = require("../lib/environment");
13
+ const configFile_1 = require("./configFile");
14
+ const text_1 = require("../lib/text");
15
+ const environments_1 = require("../constants/environments");
16
+ const auth_1 = require("../constants/auth");
17
+ const config_1 = require("../constants/config");
18
+ const files_1 = require("../constants/files");
19
+ const lang_1 = require("../utils/lang");
20
+ const i18nKey = 'config.cliConfiguration';
21
+ class _CLIConfiguration {
22
+ options;
23
+ useEnvConfig;
24
+ config;
25
+ active;
26
+ constructor() {
27
+ this.options = {};
28
+ this.useEnvConfig = false;
29
+ this.config = null;
30
+ this.active = false;
31
+ }
32
+ setActive(isActive) {
33
+ this.active = isActive;
34
+ }
35
+ isActive() {
36
+ return this.active;
37
+ }
38
+ init(options = {}) {
39
+ this.options = options;
40
+ this.load();
41
+ this.setActive(true);
42
+ return this.config;
43
+ }
44
+ load() {
45
+ if (this.options.useEnv) {
46
+ const configFromEnv = (0, environment_1.loadConfigFromEnvironment)();
47
+ if (configFromEnv) {
48
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.configFromEnv`, {
49
+ accountId: configFromEnv.accounts[0].accountId,
50
+ }));
51
+ this.useEnvConfig = true;
52
+ this.config = this.handleLegacyCmsPublishMode(configFromEnv);
53
+ }
54
+ }
55
+ else {
56
+ const configFromFile = (0, configFile_1.loadConfigFromFile)();
57
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.configFromFile`));
58
+ if (!configFromFile) {
59
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.empty`));
60
+ this.config = { accounts: [] };
61
+ }
62
+ this.useEnvConfig = false;
63
+ this.config = this.handleLegacyCmsPublishMode(configFromFile);
64
+ }
65
+ return this.config;
66
+ }
67
+ configIsEmpty() {
68
+ if (!(0, configFile_1.configFileExists)() || (0, configFile_1.configFileIsBlank)()) {
69
+ return true;
70
+ }
71
+ else {
72
+ this.load();
73
+ if (!!this.config &&
74
+ Object.keys(this.config).length === 1 &&
75
+ !!this.config.accounts) {
76
+ return true;
77
+ }
78
+ }
79
+ return false;
80
+ }
81
+ delete() {
82
+ if (!this.useEnvConfig && this.configIsEmpty()) {
83
+ (0, configFile_1.deleteConfigFile)();
84
+ this.config = null;
85
+ }
86
+ }
87
+ write(updatedConfig) {
88
+ if (!this.useEnvConfig) {
89
+ if (updatedConfig) {
90
+ this.config = updatedConfig;
91
+ }
92
+ if (this.config) {
93
+ (0, configFile_1.writeConfigToFile)(this.config);
94
+ }
95
+ }
96
+ return this.config;
97
+ }
98
+ validate() {
99
+ if (!this.config) {
100
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noConfig`));
101
+ return false;
102
+ }
103
+ if (!Array.isArray(this.config.accounts)) {
104
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noConfigAccounts`));
105
+ return false;
106
+ }
107
+ const accountIdsMap = {};
108
+ const accountNamesMap = {};
109
+ return this.config.accounts.every(accountConfig => {
110
+ if (!accountConfig) {
111
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.emptyAccountConfig`));
112
+ return false;
113
+ }
114
+ if (!accountConfig.accountId) {
115
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noAccountId`));
116
+ return false;
117
+ }
118
+ if (accountIdsMap[accountConfig.accountId]) {
119
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.duplicateAccountIds`, {
120
+ accountId: accountConfig.accountId,
121
+ }));
122
+ return false;
123
+ }
124
+ if (accountConfig.name) {
125
+ if (accountNamesMap[accountConfig.name.toLowerCase()]) {
126
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.duplicateAccountNames`, {
127
+ accountName: accountConfig.name,
128
+ }));
129
+ return false;
130
+ }
131
+ if (/\s+/.test(accountConfig.name)) {
132
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.nameContainsSpaces`, {
133
+ accountName: accountConfig.name,
134
+ }));
135
+ return false;
136
+ }
137
+ accountNamesMap[accountConfig.name] = true;
138
+ }
139
+ if (!accountConfig.accountType) {
140
+ this.addOrUpdateAccount({
141
+ ...accountConfig,
142
+ accountId: accountConfig.accountId,
143
+ accountType: this.getAccountType(undefined, accountConfig.sandboxAccountType),
144
+ });
145
+ }
146
+ accountIdsMap[accountConfig.accountId] = true;
147
+ return true;
148
+ });
149
+ }
150
+ getAccount(nameOrId) {
151
+ let name = null;
152
+ let accountId = null;
153
+ if (!this.config) {
154
+ return null;
155
+ }
156
+ const nameOrIdToCheck = nameOrId ? nameOrId : this.getDefaultAccount();
157
+ if (!nameOrIdToCheck) {
158
+ return null;
159
+ }
160
+ if (typeof nameOrIdToCheck === 'number') {
161
+ accountId = nameOrIdToCheck;
162
+ }
163
+ else if (/^\d+$/.test(nameOrIdToCheck)) {
164
+ accountId = parseInt(nameOrIdToCheck, 10);
165
+ }
166
+ else {
167
+ name = nameOrIdToCheck;
168
+ }
169
+ if (name) {
170
+ return this.config.accounts.find(a => a.name === name) || null;
171
+ }
172
+ else if (accountId) {
173
+ return this.config.accounts.find(a => accountId === a.accountId) || null;
174
+ }
175
+ return null;
176
+ }
177
+ isConfigFlagEnabled(flag, defaultValue = false) {
178
+ if (this.config && typeof this.config[flag] !== 'undefined') {
179
+ return Boolean(this.config[flag]);
180
+ }
181
+ return defaultValue;
182
+ }
183
+ getAccountId(nameOrId) {
184
+ const account = this.getAccount(nameOrId);
185
+ return account ? account.accountId : null;
186
+ }
187
+ getDefaultAccount() {
188
+ return this.getCWDAccountOverride() || this.config?.defaultAccount || null;
189
+ }
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
+ 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) {
231
+ return this.config
232
+ ? this.config.accounts.findIndex(account => account.accountId === accountId)
233
+ : -1;
234
+ }
235
+ getConfigForAccount(accountId) {
236
+ if (this.config) {
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;
245
+ }
246
+ return null;
247
+ }
248
+ isAccountInConfig(nameOrId) {
249
+ if (typeof nameOrId === 'string') {
250
+ return (!!this.config &&
251
+ this.config.accounts &&
252
+ !!this.getAccountId(nameOrId.toLowerCase()));
253
+ }
254
+ return (!!this.config && this.config.accounts && !!this.getAccountId(nameOrId));
255
+ }
256
+ getAndLoadConfigIfNeeded(options) {
257
+ if (!this.config) {
258
+ this.init(options);
259
+ }
260
+ return this.config;
261
+ }
262
+ getEnv(nameOrId) {
263
+ const accountConfig = this.getAccount(nameOrId);
264
+ if (accountConfig && accountConfig.accountId && accountConfig.env) {
265
+ return accountConfig.env;
266
+ }
267
+ if (this.config && this.config.env) {
268
+ return this.config.env;
269
+ }
270
+ return environments_1.ENVIRONMENTS.PROD;
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
+ }
287
+ /*
288
+ * Config Update Utils
289
+ */
290
+ /**
291
+ * @throws {Error}
292
+ */
293
+ addOrUpdateAccount(updatedAccountFields, writeUpdate = true) {
294
+ const { accountId, accountType, apiKey, authType, clientId, clientSecret, defaultCmsPublishMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
295
+ if (!accountId) {
296
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAccount.errors.accountIdRequired`));
297
+ }
298
+ if (!this.config) {
299
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.noConfigToUpdate`));
300
+ return null;
301
+ }
302
+ // Check whether the account is already listed in the config.yml file.
303
+ const currentAccountConfig = this.getAccount(accountId);
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.
307
+ if (clientId || clientSecret || scopes || tokenInfo) {
308
+ auth = {
309
+ ...(currentAccountConfig ? currentAccountConfig.auth : {}),
310
+ clientId,
311
+ clientSecret,
312
+ scopes,
313
+ tokenInfo,
314
+ };
315
+ }
316
+ const nextAccountConfig = {
317
+ ...(currentAccountConfig ? currentAccountConfig : {}),
318
+ };
319
+ // Allow everything except for 'undefined' values to override the existing values
320
+ function safelyApplyUpdates(fieldName,
321
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
322
+ newValue) {
323
+ if (typeof newValue !== 'undefined') {
324
+ nextAccountConfig[fieldName] = newValue;
325
+ }
326
+ }
327
+ const updatedEnv = (0, environment_2.getValidEnv)(env || (currentAccountConfig && currentAccountConfig.env));
328
+ const updatedDefaultCmsPublishMode = defaultCmsPublishMode &&
329
+ defaultCmsPublishMode.toLowerCase();
330
+ const updatedAccountType = accountType || (currentAccountConfig && currentAccountConfig.accountType);
331
+ safelyApplyUpdates('name', name);
332
+ safelyApplyUpdates('env', updatedEnv);
333
+ safelyApplyUpdates('accountId', accountId);
334
+ safelyApplyUpdates('authType', authType);
335
+ safelyApplyUpdates('auth', auth);
336
+ if (nextAccountConfig.authType === auth_1.API_KEY_AUTH_METHOD.value) {
337
+ safelyApplyUpdates('apiKey', apiKey);
338
+ }
339
+ if (typeof updatedDefaultCmsPublishMode !== 'undefined') {
340
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
341
+ safelyApplyUpdates('defaultCmsPublishMode', files_1.CMS_PUBLISH_MODE[updatedDefaultCmsPublishMode]);
342
+ }
343
+ safelyApplyUpdates('personalAccessKey', personalAccessKey);
344
+ // Deprecating sandboxAccountType in favor of the more generic accountType
345
+ safelyApplyUpdates('sandboxAccountType', sandboxAccountType);
346
+ safelyApplyUpdates('accountType', this.getAccountType(updatedAccountType, sandboxAccountType));
347
+ safelyApplyUpdates('parentAccountId', parentAccountId);
348
+ const completedAccountConfig = nextAccountConfig;
349
+ if (!Object.hasOwn(this.config, 'accounts')) {
350
+ this.config.accounts = [];
351
+ }
352
+ if (currentAccountConfig) {
353
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.updating`, {
354
+ accountId,
355
+ }));
356
+ const index = this.getAccountIndex(accountId);
357
+ if (index < 0) {
358
+ this.config.accounts.push(completedAccountConfig);
359
+ }
360
+ else {
361
+ this.config.accounts[index] = completedAccountConfig;
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);
369
+ }
370
+ if (writeUpdate) {
371
+ this.write();
372
+ }
373
+ return completedAccountConfig;
374
+ }
375
+ /**
376
+ * @throws {Error}
377
+ */
378
+ updateDefaultAccount(defaultAccount) {
379
+ if (!this.config) {
380
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
381
+ }
382
+ if (!defaultAccount ||
383
+ (typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')) {
384
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`));
385
+ }
386
+ this.config.defaultAccount = defaultAccount;
387
+ return this.write();
388
+ }
389
+ /**
390
+ * @throws {Error}
391
+ */
392
+ renameAccount(currentName, newName) {
393
+ if (!this.config) {
394
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
395
+ }
396
+ const accountId = this.getAccountId(currentName);
397
+ let accountConfigToRename = null;
398
+ if (accountId) {
399
+ accountConfigToRename = this.getAccount(accountId);
400
+ }
401
+ if (!accountConfigToRename) {
402
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.renameAccount.errors.invalidName`, {
403
+ currentName,
404
+ }));
405
+ }
406
+ if (accountId) {
407
+ this.addOrUpdateAccount({
408
+ accountId,
409
+ name: newName,
410
+ env: this.getEnv(),
411
+ accountType: accountConfigToRename.accountType,
412
+ });
413
+ }
414
+ if (accountConfigToRename.name === this.getDefaultAccount()) {
415
+ this.updateDefaultAccount(newName);
416
+ }
417
+ }
418
+ /**
419
+ * @throws {Error}
420
+ * TODO: this does not account for the special handling of sandbox account deletes
421
+ */
422
+ removeAccountFromConfig(nameOrId) {
423
+ if (!this.config) {
424
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
425
+ }
426
+ const accountId = this.getAccountId(nameOrId);
427
+ if (!accountId) {
428
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, {
429
+ nameOrId,
430
+ }));
431
+ }
432
+ let removedAccountIsDefault = false;
433
+ const accountConfig = this.getAccount(accountId);
434
+ if (accountConfig) {
435
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId }));
436
+ const index = this.getAccountIndex(accountId);
437
+ this.config.accounts.splice(index, 1);
438
+ if (this.getDefaultAccount() === accountConfig.name) {
439
+ removedAccountIsDefault = true;
440
+ }
441
+ this.write();
442
+ }
443
+ return removedAccountIsDefault;
444
+ }
445
+ /**
446
+ * @throws {Error}
447
+ */
448
+ updateDefaultCmsPublishMode(defaultCmsPublishMode) {
449
+ if (!this.config) {
450
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
451
+ }
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
+ }));
459
+ }
460
+ this.config.defaultCmsPublishMode = defaultCmsPublishMode;
461
+ return this.write();
462
+ }
463
+ /**
464
+ * @throws {Error}
465
+ */
466
+ updateHttpTimeout(timeout) {
467
+ if (!this.config) {
468
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
469
+ }
470
+ const parsedTimeout = parseInt(timeout);
471
+ if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
472
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
473
+ timeout,
474
+ minTimeout: config_1.MIN_HTTP_TIMEOUT,
475
+ }));
476
+ }
477
+ this.config.httpTimeout = parsedTimeout;
478
+ return this.write();
479
+ }
480
+ /**
481
+ * @throws {Error}
482
+ */
483
+ updateAllowUsageTracking(isEnabled) {
484
+ if (!this.config) {
485
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
486
+ }
487
+ if (typeof isEnabled !== 'boolean') {
488
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
489
+ isEnabled: `${isEnabled}`,
490
+ }));
491
+ }
492
+ this.config.allowUsageTracking = isEnabled;
493
+ return this.write();
494
+ }
495
+ isTrackingAllowed() {
496
+ if (!this.config) {
497
+ return true;
498
+ }
499
+ return this.config.allowUsageTracking !== false;
500
+ }
501
+ handleLegacyCmsPublishMode(config) {
502
+ if (config?.defaultMode) {
503
+ config.defaultCmsPublishMode = config.defaultMode;
504
+ delete config.defaultMode;
505
+ }
506
+ return config;
507
+ }
508
+ }
509
+ exports.CLIConfiguration = new _CLIConfiguration();
@@ -0,0 +1,21 @@
1
+ import { CLIConfig_NEW } from '../types/Config';
2
+ export declare function getConfigFilePath(): string;
3
+ export declare function configFileExists(): boolean;
4
+ export declare function configFileIsBlank(): boolean;
5
+ export declare function deleteConfigFile(): void;
6
+ /**
7
+ * @throws {Error}
8
+ */
9
+ export declare function readConfigFile(configPath: string): string;
10
+ /**
11
+ * @throws {Error}
12
+ */
13
+ export declare function parseConfig(configSource: string): CLIConfig_NEW;
14
+ /**
15
+ * @throws {Error}
16
+ */
17
+ export declare function loadConfigFromFile(): CLIConfig_NEW | null;
18
+ /**
19
+ * @throws {Error}
20
+ */
21
+ export declare function writeConfigToFile(config: CLIConfig_NEW): void;