@hubspot/local-dev-lib 3.21.2-beta.0 → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/config/defaultAccountOverride.d.ts +2 -0
  2. package/config/defaultAccountOverride.js +57 -0
  3. package/config/index.d.ts +30 -44
  4. package/config/index.js +332 -267
  5. package/config/migrate.d.ts +12 -16
  6. package/config/migrate.js +86 -160
  7. package/config/utils.d.ts +30 -0
  8. package/config/utils.js +373 -0
  9. package/constants/config.d.ts +40 -0
  10. package/constants/config.js +41 -1
  11. package/constants/environments.d.ts +0 -11
  12. package/constants/environments.js +1 -12
  13. package/errors/index.d.ts +2 -0
  14. package/errors/index.js +6 -1
  15. package/http/getAxiosConfig.js +7 -1
  16. package/http/index.js +23 -19
  17. package/lang/en.json +89 -61
  18. package/lib/cms/themes.js +3 -1
  19. package/lib/environment.d.ts +1 -1
  20. package/lib/oauth.d.ts +2 -2
  21. package/lib/oauth.js +8 -16
  22. package/lib/personalAccessKey.d.ts +2 -2
  23. package/lib/personalAccessKey.js +43 -30
  24. package/lib/trackUsage.js +6 -3
  25. package/models/HubSpotConfigError.d.ts +6 -0
  26. package/models/HubSpotConfigError.js +34 -0
  27. package/models/OAuth2Manager.d.ts +3 -4
  28. package/models/OAuth2Manager.js +20 -29
  29. package/package.json +5 -5
  30. package/types/Accounts.d.ts +20 -109
  31. package/types/Config.d.ts +17 -26
  32. package/config/CLIConfiguration.d.ts +0 -72
  33. package/config/CLIConfiguration.js +0 -551
  34. package/config/configFile.d.ts +0 -21
  35. package/config/configFile.js +0 -100
  36. package/config/configUtils.d.ts +0 -5
  37. package/config/configUtils.js +0 -87
  38. package/config/config_DEPRECATED.d.ts +0 -87
  39. package/config/config_DEPRECATED.js +0 -738
  40. package/config/environment.d.ts +0 -2
  41. package/config/environment.js +0 -60
  42. package/config/getAccountIdentifier.d.ts +0 -2
  43. package/config/getAccountIdentifier.js +0 -15
  44. package/utils/accounts.d.ts +0 -4
  45. package/utils/accounts.js +0 -28
@@ -1,551 +0,0 @@
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 === 'string') {
161
- name = nameOrIdToCheck;
162
- if (/^\d+$/.test(nameOrIdToCheck)) {
163
- accountId = parseInt(nameOrIdToCheck, 10);
164
- }
165
- }
166
- else if (typeof nameOrIdToCheck === 'number') {
167
- accountId = nameOrIdToCheck;
168
- }
169
- let account = null;
170
- if (name) {
171
- account = this.config.accounts?.find(a => a.name === name) || null;
172
- }
173
- if (accountId && !account) {
174
- account =
175
- this.config.accounts?.find(a => accountId === a.accountId) || null;
176
- }
177
- return account;
178
- }
179
- isConfigFlagEnabled(flag, defaultValue = false) {
180
- if (this.config && typeof this.config[flag] !== 'undefined') {
181
- return Boolean(this.config[flag]);
182
- }
183
- return defaultValue;
184
- }
185
- getAccountId(nameOrId) {
186
- const account = this.getAccount(nameOrId);
187
- return account ? account.accountId : null;
188
- }
189
- getDefaultAccount() {
190
- return this.getCWDAccountOverride() || this.config?.defaultAccount || null;
191
- }
192
- getDefaultAccountOverrideFilePath() {
193
- return (0, findup_sync_1.default)([config_1.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME], {
194
- cwd: (0, path_1.getCwd)(),
195
- });
196
- }
197
- getCWDAccountOverride() {
198
- const defaultOverrideFile = this.getDefaultAccountOverrideFilePath();
199
- if (!defaultOverrideFile) {
200
- return null;
201
- }
202
- let source;
203
- try {
204
- source = fs_1.default.readFileSync(defaultOverrideFile, 'utf8');
205
- }
206
- catch (e) {
207
- if (e instanceof Error) {
208
- logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.getCWDAccountOverride.readFileError`, {
209
- error: e.message,
210
- }));
211
- }
212
- return null;
213
- }
214
- const accountId = Number(source);
215
- if (isNaN(accountId)) {
216
- throw new Error((0, lang_1.i18n)(`${i18nKey}.getCWDAccountOverride.errorHeader`, {
217
- hsAccountFile: defaultOverrideFile,
218
- }), {
219
- cause: config_1.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID,
220
- });
221
- }
222
- const account = this.config?.accounts?.find(account => account.accountId === accountId);
223
- if (!account) {
224
- throw new Error((0, lang_1.i18n)(`${i18nKey}.getCWDAccountOverride.errorHeader`, {
225
- hsAccountFile: defaultOverrideFile,
226
- }), {
227
- cause: config_1.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND,
228
- });
229
- }
230
- return account.name || account.accountId;
231
- }
232
- getAccountIndex(accountId) {
233
- return this.config && Array.isArray(this.config.accounts)
234
- ? this.config.accounts.findIndex(account => account.accountId === accountId)
235
- : -1;
236
- }
237
- getConfigAccounts() {
238
- if (this.config) {
239
- return this.config.accounts || null;
240
- }
241
- return null;
242
- }
243
- isAccountInConfig(nameOrId) {
244
- if (typeof nameOrId === 'string') {
245
- return (!!this.config &&
246
- !!this.config.accounts &&
247
- !!this.getAccountId(nameOrId.toLowerCase()));
248
- }
249
- return (!!this.config && !!this.config.accounts && !!this.getAccountId(nameOrId));
250
- }
251
- getAndLoadConfigIfNeeded(options) {
252
- if (!this.config) {
253
- this.init(options);
254
- }
255
- return this.config;
256
- }
257
- getEnv(nameOrId) {
258
- const accountConfig = this.getAccount(nameOrId);
259
- if (accountConfig && accountConfig.accountId && accountConfig.env) {
260
- return accountConfig.env;
261
- }
262
- if (this.config && this.config.env) {
263
- return this.config.env;
264
- }
265
- return environments_1.ENVIRONMENTS.PROD;
266
- }
267
- // Deprecating sandboxAccountType in favor of accountType
268
- getAccountType(accountType, sandboxAccountType) {
269
- if (accountType) {
270
- return accountType;
271
- }
272
- if (typeof sandboxAccountType === 'string') {
273
- if (sandboxAccountType.toUpperCase() === 'DEVELOPER') {
274
- return config_1.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX;
275
- }
276
- if (sandboxAccountType.toUpperCase() === 'STANDARD') {
277
- return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX;
278
- }
279
- }
280
- return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD;
281
- }
282
- /*
283
- * Config Update Utils
284
- */
285
- /**
286
- * @throws {Error}
287
- */
288
- addOrUpdateAccount(updatedAccountFields, writeUpdate = true) {
289
- const { accountId, accountType, apiKey, authType, clientId, clientSecret, defaultCmsPublishMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
290
- if (!accountId) {
291
- throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAccount.errors.accountIdRequired`));
292
- }
293
- if (!this.config) {
294
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.noConfigToUpdate`));
295
- return null;
296
- }
297
- // Check whether the account is already listed in the config.yml file.
298
- const currentAccountConfig = this.getAccount(accountId);
299
- // For accounts that are already in the config.yml file, sets the auth property.
300
- let auth = (currentAccountConfig && currentAccountConfig.auth) || {};
301
- // For accounts not already in the config.yml file, sets the auth property.
302
- if (clientId || clientSecret || scopes || tokenInfo) {
303
- auth = {
304
- ...(currentAccountConfig ? currentAccountConfig.auth : {}),
305
- clientId,
306
- clientSecret,
307
- scopes,
308
- tokenInfo,
309
- };
310
- }
311
- const nextAccountConfig = {
312
- ...(currentAccountConfig ? currentAccountConfig : {}),
313
- };
314
- // Allow everything except for 'undefined' values to override the existing values
315
- function safelyApplyUpdates(fieldName,
316
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
317
- newValue) {
318
- if (typeof newValue !== 'undefined') {
319
- nextAccountConfig[fieldName] = newValue;
320
- }
321
- }
322
- const updatedEnv = (0, environment_2.getValidEnv)(env || (currentAccountConfig && currentAccountConfig.env));
323
- const updatedDefaultCmsPublishMode = defaultCmsPublishMode &&
324
- defaultCmsPublishMode.toLowerCase();
325
- const updatedAccountType = accountType || (currentAccountConfig && currentAccountConfig.accountType);
326
- safelyApplyUpdates('name', name);
327
- safelyApplyUpdates('env', updatedEnv);
328
- safelyApplyUpdates('accountId', accountId);
329
- safelyApplyUpdates('authType', authType);
330
- safelyApplyUpdates('auth', auth);
331
- if (nextAccountConfig.authType === auth_1.API_KEY_AUTH_METHOD.value) {
332
- safelyApplyUpdates('apiKey', apiKey);
333
- }
334
- if (typeof updatedDefaultCmsPublishMode !== 'undefined') {
335
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
336
- safelyApplyUpdates('defaultCmsPublishMode', files_1.CMS_PUBLISH_MODE[updatedDefaultCmsPublishMode]);
337
- }
338
- safelyApplyUpdates('personalAccessKey', personalAccessKey);
339
- // Deprecating sandboxAccountType in favor of the more generic accountType
340
- safelyApplyUpdates('sandboxAccountType', sandboxAccountType);
341
- safelyApplyUpdates('accountType', this.getAccountType(updatedAccountType, sandboxAccountType));
342
- safelyApplyUpdates('parentAccountId', parentAccountId);
343
- const completedAccountConfig = nextAccountConfig;
344
- if (!Array.isArray(this.config.accounts)) {
345
- this.config.accounts = [];
346
- }
347
- if (currentAccountConfig) {
348
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.updating`, {
349
- accountId,
350
- }));
351
- const index = this.getAccountIndex(accountId);
352
- if (index < 0) {
353
- this.config.accounts.push(completedAccountConfig);
354
- }
355
- else {
356
- this.config.accounts[index] = completedAccountConfig;
357
- }
358
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.addingConfigEntry`, {
359
- accountId,
360
- }));
361
- }
362
- else {
363
- this.config.accounts.push(completedAccountConfig);
364
- }
365
- if (writeUpdate) {
366
- this.write();
367
- }
368
- return completedAccountConfig;
369
- }
370
- /**
371
- * @throws {Error}
372
- */
373
- updateDefaultAccount(defaultAccount) {
374
- if (!this.config) {
375
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
376
- }
377
- if (!defaultAccount ||
378
- (typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')) {
379
- throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`));
380
- }
381
- this.config.defaultAccount = defaultAccount;
382
- return this.write();
383
- }
384
- /**
385
- * @throws {Error}
386
- */
387
- renameAccount(currentName, newName) {
388
- if (!this.config) {
389
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
390
- }
391
- const accountId = this.getAccountId(currentName);
392
- let accountConfigToRename = null;
393
- if (accountId) {
394
- accountConfigToRename = this.getAccount(accountId);
395
- }
396
- if (!accountConfigToRename) {
397
- throw new Error((0, lang_1.i18n)(`${i18nKey}.renameAccount.errors.invalidName`, {
398
- currentName,
399
- }));
400
- }
401
- if (accountId) {
402
- this.addOrUpdateAccount({
403
- accountId,
404
- name: newName,
405
- env: this.getEnv(),
406
- accountType: accountConfigToRename.accountType,
407
- });
408
- }
409
- if (accountConfigToRename.name === this.getDefaultAccount()) {
410
- this.updateDefaultAccount(newName);
411
- }
412
- }
413
- /**
414
- * @throws {Error}
415
- * TODO: this does not account for the special handling of sandbox account deletes
416
- */
417
- removeAccountFromConfig(nameOrId) {
418
- if (!this.config) {
419
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
420
- }
421
- const accountId = this.getAccountId(nameOrId);
422
- if (!accountId) {
423
- throw new Error((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, {
424
- nameOrId,
425
- }));
426
- }
427
- let removedAccountIsDefault = false;
428
- const accountConfig = this.getAccount(accountId);
429
- if (accountConfig) {
430
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId }));
431
- const index = this.getAccountIndex(accountId);
432
- if (index === -1) {
433
- return removedAccountIsDefault;
434
- }
435
- this.config.accounts?.splice(index, 1);
436
- if (this.getDefaultAccount() === accountConfig.name) {
437
- removedAccountIsDefault = true;
438
- }
439
- this.write();
440
- }
441
- return removedAccountIsDefault;
442
- }
443
- /**
444
- * @throws {Error}
445
- */
446
- updateDefaultCmsPublishMode(defaultCmsPublishMode) {
447
- if (!this.config) {
448
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
449
- }
450
- const ALL_CMS_PUBLISH_MODES = Object.values(files_1.CMS_PUBLISH_MODE);
451
- if (!defaultCmsPublishMode ||
452
- !ALL_CMS_PUBLISH_MODES.find(m => m === defaultCmsPublishMode)) {
453
- throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultCmsPublishMode.errors.invalidCmsPublishMode`, {
454
- defaultCmsPublishMode,
455
- validCmsPublishModes: (0, text_1.commaSeparatedValues)(ALL_CMS_PUBLISH_MODES),
456
- }));
457
- }
458
- this.config.defaultCmsPublishMode = defaultCmsPublishMode;
459
- return this.write();
460
- }
461
- /**
462
- * @throws {Error}
463
- */
464
- updateHttpTimeout(timeout) {
465
- if (!this.config) {
466
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
467
- }
468
- const parsedTimeout = parseInt(timeout);
469
- if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
470
- throw new Error((0, lang_1.i18n)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
471
- timeout,
472
- minTimeout: config_1.MIN_HTTP_TIMEOUT,
473
- }));
474
- }
475
- this.config.httpTimeout = parsedTimeout;
476
- return this.write();
477
- }
478
- /**
479
- * @throws {Error}
480
- */
481
- updateAllowAutoUpdates(enabled) {
482
- if (!this.config) {
483
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
484
- }
485
- this.config.allowAutoUpdates = enabled;
486
- return this.write();
487
- }
488
- /**
489
- * @throws {Error}
490
- */
491
- updateAllowUsageTracking(isEnabled) {
492
- if (!this.config) {
493
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
494
- }
495
- if (typeof isEnabled !== 'boolean') {
496
- throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
497
- isEnabled: `${isEnabled}`,
498
- }));
499
- }
500
- this.config.allowUsageTracking = isEnabled;
501
- return this.write();
502
- }
503
- updateAutoOpenBrowser(isEnabled) {
504
- if (!this.config) {
505
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
506
- }
507
- if (typeof isEnabled !== 'boolean') {
508
- throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAutoOpenBrowser.errors.invalidInput`, {
509
- isEnabled: `${isEnabled}`,
510
- }));
511
- }
512
- this.config.autoOpenBrowser = isEnabled;
513
- return this.write();
514
- }
515
- isTrackingAllowed() {
516
- if (!this.config) {
517
- return true;
518
- }
519
- return this.config.allowUsageTracking !== false;
520
- }
521
- handleLegacyCmsPublishMode(config) {
522
- if (config?.defaultMode) {
523
- config.defaultCmsPublishMode = config.defaultMode;
524
- delete config.defaultMode;
525
- }
526
- return config;
527
- }
528
- hasLocalStateFlag(flag) {
529
- if (!this.config) {
530
- return false;
531
- }
532
- return this.config.flags?.includes(flag) || false;
533
- }
534
- addLocalStateFlag(flag) {
535
- if (!this.config) {
536
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
537
- }
538
- if (!this.hasLocalStateFlag(flag)) {
539
- this.config.flags = [...(this.config.flags || []), flag];
540
- }
541
- this.write();
542
- }
543
- removeLocalStateFlag(flag) {
544
- if (!this.config) {
545
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
546
- }
547
- this.config.flags = this.config.flags?.filter(f => f !== flag) || [];
548
- this.write();
549
- }
550
- }
551
- exports.CLIConfiguration = new _CLIConfiguration();
@@ -1,21 +0,0 @@
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;
@@ -1,100 +0,0 @@
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.writeConfigToFile = exports.loadConfigFromFile = exports.parseConfig = exports.readConfigFile = exports.deleteConfigFile = exports.configFileIsBlank = exports.configFileExists = exports.getConfigFilePath = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const js_yaml_1 = __importDefault(require("js-yaml"));
9
- const logger_1 = require("../lib/logger");
10
- const config_1 = require("../constants/config");
11
- const configUtils_1 = require("./configUtils");
12
- const lang_1 = require("../utils/lang");
13
- const FileSystemError_1 = require("../models/FileSystemError");
14
- const i18nKey = 'config.configFile';
15
- function getConfigFilePath() {
16
- return config_1.GLOBAL_CONFIG_PATH;
17
- }
18
- exports.getConfigFilePath = getConfigFilePath;
19
- function configFileExists() {
20
- const configPath = getConfigFilePath();
21
- return !!configPath && fs_extra_1.default.existsSync(configPath);
22
- }
23
- exports.configFileExists = configFileExists;
24
- function configFileIsBlank() {
25
- const configPath = getConfigFilePath();
26
- return !!configPath && fs_extra_1.default.readFileSync(configPath).length === 0;
27
- }
28
- exports.configFileIsBlank = configFileIsBlank;
29
- function deleteConfigFile() {
30
- const configPath = getConfigFilePath();
31
- fs_extra_1.default.unlinkSync(configPath);
32
- }
33
- exports.deleteConfigFile = deleteConfigFile;
34
- /**
35
- * @throws {Error}
36
- */
37
- function readConfigFile(configPath) {
38
- let source = '';
39
- try {
40
- source = fs_extra_1.default.readFileSync(configPath).toString();
41
- }
42
- catch (err) {
43
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorReading`, { configPath }));
44
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
45
- filepath: configPath,
46
- operation: 'read',
47
- });
48
- }
49
- return source;
50
- }
51
- exports.readConfigFile = readConfigFile;
52
- /**
53
- * @throws {Error}
54
- */
55
- function parseConfig(configSource) {
56
- let parsed;
57
- try {
58
- parsed = js_yaml_1.default.load(configSource);
59
- }
60
- catch (err) {
61
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.parsing`), { cause: err });
62
- }
63
- return parsed;
64
- }
65
- exports.parseConfig = parseConfig;
66
- /**
67
- * @throws {Error}
68
- */
69
- function loadConfigFromFile() {
70
- const configPath = getConfigFilePath();
71
- if (configPath) {
72
- const source = readConfigFile(configPath);
73
- if (!source) {
74
- return null;
75
- }
76
- return parseConfig(source);
77
- }
78
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorLoading`, { configPath }));
79
- return null;
80
- }
81
- exports.loadConfigFromFile = loadConfigFromFile;
82
- /**
83
- * @throws {Error}
84
- */
85
- function writeConfigToFile(config) {
86
- const source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
87
- const configPath = getConfigFilePath();
88
- try {
89
- fs_extra_1.default.ensureFileSync(configPath);
90
- fs_extra_1.default.writeFileSync(configPath, source);
91
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.writeSuccess`, { configPath }));
92
- }
93
- catch (err) {
94
- throw new FileSystemError_1.FileSystemError({ cause: err }, {
95
- filepath: configPath,
96
- operation: 'write',
97
- });
98
- }
99
- }
100
- exports.writeConfigToFile = writeConfigToFile;
@@ -1,5 +0,0 @@
1
- import { CLIConfig_NEW } from '../types/Config';
2
- import { AuthType, CLIAccount_NEW, PersonalAccessKeyOptions, OAuthOptions, APIKeyOptions } from '../types/Accounts';
3
- export declare function getOrderedAccount(unorderedAccount: CLIAccount_NEW): CLIAccount_NEW;
4
- export declare function getOrderedConfig(unorderedConfig: CLIConfig_NEW): CLIConfig_NEW;
5
- export declare function generateConfig(type: AuthType, options: PersonalAccessKeyOptions | OAuthOptions | APIKeyOptions): CLIConfig_NEW | null;