@hubspot/local-dev-lib 0.0.3 → 0.0.4

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 (141) hide show
  1. package/config/CLIConfiguration.d.ts +6 -6
  2. package/config/CLIConfiguration.js +11 -11
  3. package/config/configFile.js +1 -2
  4. package/constants/extensions.d.ts +1 -0
  5. package/constants/extensions.js +2 -1
  6. package/errors/fileSystemErrors.d.ts +7 -1
  7. package/errors/fileSystemErrors.js +1 -2
  8. package/errors/standardErrors.d.ts +14 -4
  9. package/errors/standardErrors.js +38 -34
  10. package/{src/http → http}/requestOptions.js +1 -1
  11. package/lib/archive.js +2 -4
  12. package/lib/path.d.ts +0 -3
  13. package/lib/path.js +2 -19
  14. package/package.json +8 -8
  15. package/types/Config.d.ts +1 -1
  16. package/types/Error.d.ts +6 -13
  17. package/utils/git.d.ts +2 -1
  18. package/utils/git.js +4 -68
  19. package/utils/lang.d.ts +5 -0
  20. package/utils/lang.js +30 -5
  21. package/errors/cmsFieldsJsErrors.d.ts +0 -9
  22. package/errors/cmsFieldsJsErrors.js +0 -31
  23. package/index.d.ts +0 -2
  24. package/index.js +0 -5
  25. package/src/config/CLIConfiguration.d.ts +0 -55
  26. package/src/config/CLIConfiguration.js +0 -392
  27. package/src/config/configFile.d.ts +0 -21
  28. package/src/config/configFile.js +0 -109
  29. package/src/config/configUtils.d.ts +0 -24
  30. package/src/config/configUtils.js +0 -85
  31. package/src/config/environment.d.ts +0 -3
  32. package/src/config/environment.js +0 -64
  33. package/src/constants/auth.d.ts +0 -24
  34. package/src/constants/auth.js +0 -31
  35. package/src/constants/config.d.ts +0 -8
  36. package/src/constants/config.js +0 -12
  37. package/src/constants/environments.d.ts +0 -13
  38. package/src/constants/environments.js +0 -16
  39. package/src/constants/extensions.d.ts +0 -2
  40. package/src/constants/extensions.js +0 -23
  41. package/src/constants/index.d.ts +0 -16
  42. package/src/constants/index.js +0 -12
  43. package/src/errors/HubSpotAuthError.d.ts +0 -3
  44. package/src/errors/HubSpotAuthError.js +0 -6
  45. package/src/errors/cmsFieldsJsErrors.d.ts +0 -9
  46. package/src/errors/cmsFieldsJsErrors.js +0 -31
  47. package/src/errors/fileSystemErrors.d.ts +0 -8
  48. package/src/errors/fileSystemErrors.js +0 -28
  49. package/src/errors/standardErrors.d.ts +0 -19
  50. package/src/errors/standardErrors.js +0 -67
  51. package/src/index.d.ts +0 -2
  52. package/src/index.js +0 -5
  53. package/src/lib/archive.d.ts +0 -7
  54. package/src/lib/archive.js +0 -111
  55. package/src/lib/modules.d.ts +0 -28
  56. package/src/lib/modules.js +0 -174
  57. package/src/lib/path.d.ts +0 -10
  58. package/src/lib/path.js +0 -84
  59. package/src/types/Accounts.d.ts +0 -50
  60. package/src/types/Accounts.js +0 -2
  61. package/src/types/CLIOptions.d.ts +0 -3
  62. package/src/types/CLIOptions.js +0 -2
  63. package/src/types/Config.d.ts +0 -10
  64. package/src/types/Config.js +0 -2
  65. package/src/types/Error.d.ts +0 -31
  66. package/src/types/Error.js +0 -2
  67. package/src/types/LogCallbacks.d.ts +0 -6
  68. package/src/types/LogCallbacks.js +0 -2
  69. package/src/types/Utils.d.ts +0 -1
  70. package/src/types/Utils.js +0 -2
  71. package/src/utils/encoding.d.ts +0 -1
  72. package/src/utils/encoding.js +0 -11
  73. package/src/utils/environment.d.ts +0 -1
  74. package/src/utils/environment.js +0 -16
  75. package/src/utils/escapeRegExp.d.ts +0 -1
  76. package/src/utils/escapeRegExp.js +0 -7
  77. package/src/utils/files.d.ts +0 -3
  78. package/src/utils/files.js +0 -35
  79. package/src/utils/fs/read.d.ts +0 -4
  80. package/src/utils/fs/read.js +0 -55
  81. package/src/utils/fs/walk.d.ts +0 -2
  82. package/src/utils/fs/walk.js +0 -44
  83. package/src/utils/git.d.ts +0 -4
  84. package/src/utils/git.js +0 -40
  85. package/src/utils/handleFieldsJS.d.ts +0 -35
  86. package/src/utils/handleFieldsJS.js +0 -158
  87. package/src/utils/interpolation.d.ts +0 -5
  88. package/src/utils/interpolation.js +0 -31
  89. package/src/utils/lang.d.ts +0 -8
  90. package/src/utils/lang.js +0 -83
  91. package/src/utils/logger.d.ts +0 -10
  92. package/src/utils/logger.js +0 -22
  93. package/src/utils/text.d.ts +0 -1
  94. package/src/utils/text.js +0 -16
  95. package/src/utils/urls.d.ts +0 -2
  96. package/src/utils/urls.js +0 -20
  97. package/utils/encoding.d.ts +0 -1
  98. package/utils/encoding.js +0 -11
  99. package/utils/environment.d.ts +0 -1
  100. package/utils/environment.js +0 -16
  101. package/utils/interpolation.d.ts +0 -5
  102. package/utils/interpolation.js +0 -31
  103. package/utils/text.d.ts +0 -1
  104. package/utils/text.js +0 -16
  105. /package/{src/constants → constants}/files.d.ts +0 -0
  106. /package/{src/constants → constants}/files.js +0 -0
  107. /package/{src/constants → constants}/github.d.ts +0 -0
  108. /package/{src/constants → constants}/github.js +0 -0
  109. /package/{src/http → http}/requestOptions.d.ts +0 -0
  110. /package/{src/lib → lib}/cms/handleFieldsJS.d.ts +0 -0
  111. /package/{src/lib → lib}/cms/handleFieldsJS.js +0 -0
  112. /package/{src/lib → lib}/cms/index.d.ts +0 -0
  113. /package/{src/lib → lib}/cms/index.js +0 -0
  114. /package/{src/lib → lib}/cms/modules.d.ts +0 -0
  115. /package/{src/lib → lib}/cms/modules.js +0 -0
  116. /package/{src/lib → lib}/cms/themes.d.ts +0 -0
  117. /package/{src/lib → lib}/cms/themes.js +0 -0
  118. /package/{src/lib → lib}/environment.d.ts +0 -0
  119. /package/{src/lib → lib}/environment.js +0 -0
  120. /package/{src/lib → lib}/fs.d.ts +0 -0
  121. /package/{src/lib → lib}/fs.js +0 -0
  122. /package/{src/lib → lib}/github.d.ts +0 -0
  123. /package/{src/lib → lib}/github.js +0 -0
  124. /package/{src/lib → lib}/gitignore.d.ts +0 -0
  125. /package/{src/lib → lib}/gitignore.js +0 -0
  126. /package/{src/lib → lib}/index.d.ts +0 -0
  127. /package/{src/lib → lib}/index.js +0 -0
  128. /package/{src/lib → lib}/text.d.ts +0 -0
  129. /package/{src/lib → lib}/text.js +0 -0
  130. /package/{src/lib → lib}/urls.d.ts +0 -0
  131. /package/{src/lib → lib}/urls.js +0 -0
  132. /package/{src/types → types}/Files.d.ts +0 -0
  133. /package/{src/types → types}/Files.js +0 -0
  134. /package/{src/types → types}/Github.d.ts +0 -0
  135. /package/{src/types → types}/Github.js +0 -0
  136. /package/{src/types → types}/Modules.d.ts +0 -0
  137. /package/{src/types → types}/Modules.js +0 -0
  138. /package/{src/utils → utils}/fieldsJS.d.ts +0 -0
  139. /package/{src/utils → utils}/fieldsJS.js +0 -0
  140. /package/{src/utils → utils}/modules.d.ts +0 -0
  141. /package/{src/utils → utils}/modules.js +0 -0
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.throwFieldsJsError = exports.FieldErrors = void 0;
4
- const standardErrors_1 = require("./standardErrors");
5
- const i18nKey = 'errorTypes.cmsFields';
6
- exports.FieldErrors = {
7
- IsNotFunction: 'IsNotFunction',
8
- DoesNotReturnArray: 'DoesNotReturnArray',
9
- };
10
- function throwFieldsJsError(e, path, info = {}) {
11
- if (e instanceof SyntaxError ||
12
- (typeof e === 'object' && e.code === 'MODULE_NOT_FOUND')) {
13
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.syntaxError`, { path });
14
- }
15
- if (e === exports.FieldErrors.IsNotFunction) {
16
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.notFunction`, {
17
- path,
18
- returned: info.returned || '',
19
- });
20
- }
21
- if (e === exports.FieldErrors.DoesNotReturnArray) {
22
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.notReturnArray`, {
23
- path,
24
- returned: info.returned || '',
25
- });
26
- }
27
- if (typeof e === 'object' && e.code === 'ENOENT') {
28
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.invalidPath`, { path });
29
- }
30
- }
31
- exports.throwFieldsJsError = throwFieldsJsError;
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { extractZipArchive as __extractZipArchive } from './lib/archive';
2
- export declare const extractZipArchive: typeof __extractZipArchive;
package/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractZipArchive = void 0;
4
- const archive_1 = require("./lib/archive");
5
- exports.extractZipArchive = archive_1.extractZipArchive;
@@ -1,55 +0,0 @@
1
- import { CLIConfig } from '../types/Config';
2
- import { CLIAccount, FlatAccountFields, OauthTokenInfo } from '../types/Accounts';
3
- import { CLIOptions } from '../types/CLIOptions';
4
- import { LogCallbacksArg } from '../types/LogCallbacks';
5
- declare const validateLogCallbackKeys: readonly ["noConfig", "noConfigAccounts", "emptyAccountConfig", "noAccountId", "duplicateAccountIds", "duplicateAccountNames", "nameContainsSpaces"];
6
- declare class CLIConfiguration {
7
- options: CLIOptions;
8
- useEnvConfig: boolean;
9
- config: CLIConfig | null;
10
- constructor();
11
- init(options?: CLIOptions): void;
12
- load(): CLIConfig | null;
13
- configIsEmpty(): boolean;
14
- delete(): void;
15
- write(updatedConfig?: CLIConfig): CLIConfig | null;
16
- validate(logCallbacks?: LogCallbacksArg<typeof validateLogCallbackKeys>): boolean;
17
- getAccount(nameOrId: string | number | undefined): CLIAccount | null;
18
- getAccountId(nameOrId: string | number): number | null;
19
- getDefaultAccount(): string | number | null;
20
- getResolvedDefaultAccountForCWD(nameOrId: string | number): CLIAccount | null;
21
- getConfigAccountIndex(accountId: number): number;
22
- isAccountInConfig(nameOrId: string | number): boolean;
23
- getAndLoadConfigIfNeeded(options?: CLIOptions): CLIConfig;
24
- getEnv(nameOrId?: string | number): string;
25
- /**
26
- * @throws {Error}
27
- */
28
- updateAccount(updatedAccountFields: FlatAccountFields<OauthTokenInfo>, writeUpdate?: boolean): CLIAccount | null;
29
- /**
30
- * @throws {Error}
31
- */
32
- updateDefaultAccount(defaultAccount: string | number): CLIConfig | null;
33
- /**
34
- * @throws {Error}
35
- */
36
- renameAccount(currentName: string, newName: string): void;
37
- /**
38
- * @throws {Error}
39
- */
40
- removeAccountFromConfig(nameOrId: string | number): boolean;
41
- /**
42
- * @throws {Error}
43
- */
44
- updateDefaultMode(defaultMode: string): CLIConfig | null;
45
- /**
46
- * @throws {Error}
47
- */
48
- updateHttpTimeout(timeout: string): CLIConfig | null;
49
- /**
50
- * @throws {Error}
51
- */
52
- updateAllowUsageTracking(isEnabled: boolean): CLIConfig | null;
53
- }
54
- declare const _default: CLIConfiguration;
55
- export default _default;
@@ -1,392 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const logger_1 = require("../utils/logger");
4
- const standardErrors_1 = require("../errors/standardErrors");
5
- const environment_1 = require("./environment");
6
- const configFile_1 = require("./configFile");
7
- const text_1 = require("../lib/text");
8
- const constants_1 = require("../constants");
9
- const auth_1 = require("../constants/auth");
10
- const config_1 = require("../constants/config");
11
- const i18nKey = 'config.cliConfiguration';
12
- const validateLogCallbackKeys = [
13
- 'noConfig',
14
- 'noConfigAccounts',
15
- 'emptyAccountConfig',
16
- 'noAccountId',
17
- 'duplicateAccountIds',
18
- 'duplicateAccountNames',
19
- 'nameContainsSpaces',
20
- ];
21
- class CLIConfiguration {
22
- options;
23
- useEnvConfig;
24
- config;
25
- constructor() {
26
- this.options = {};
27
- this.useEnvConfig = false;
28
- this.config = null;
29
- }
30
- init(options = {}) {
31
- this.options = options;
32
- this.load();
33
- }
34
- load() {
35
- if (this.options.useEnv) {
36
- const configFromEnv = (0, environment_1.loadConfigFromEnvironment)();
37
- if (configFromEnv) {
38
- (0, logger_1.debug)(`${i18nKey}.load.configFromEnv`, {
39
- accountId: configFromEnv.accounts[0].accountId,
40
- });
41
- this.useEnvConfig = true;
42
- this.config = configFromEnv;
43
- }
44
- }
45
- else {
46
- const configFromFile = (0, configFile_1.loadConfigFromFile)();
47
- (0, logger_1.debug)(`${i18nKey}.load.configFromFile`);
48
- if (!configFromFile) {
49
- (0, logger_1.debug)(`${i18nKey}.load.empty`);
50
- this.config = { accounts: [] };
51
- }
52
- this.useEnvConfig = false;
53
- this.config = configFromFile;
54
- }
55
- return this.config;
56
- }
57
- configIsEmpty() {
58
- if (!(0, configFile_1.configFileExists)() || (0, configFile_1.configFileIsBlank)()) {
59
- return true;
60
- }
61
- else {
62
- this.load();
63
- if (!!this.config &&
64
- Object.keys(this.config).length === 1 &&
65
- !!this.config.accounts) {
66
- return true;
67
- }
68
- }
69
- return false;
70
- }
71
- delete() {
72
- if (!this.useEnvConfig && this.configIsEmpty()) {
73
- (0, configFile_1.deleteConfigFile)();
74
- this.config = null;
75
- }
76
- }
77
- write(updatedConfig) {
78
- if (!this.useEnvConfig) {
79
- if (updatedConfig) {
80
- this.config = updatedConfig;
81
- }
82
- if (this.config) {
83
- (0, configFile_1.writeConfigToFile)(this.config);
84
- }
85
- }
86
- return this.config;
87
- }
88
- validate(logCallbacks) {
89
- const validateLogger = (0, logger_1.makeTypedLogger)(logCallbacks, 'config.cliConfiguration.validate');
90
- if (!this.config) {
91
- validateLogger('noConfig');
92
- return false;
93
- }
94
- if (!Array.isArray(this.config.accounts)) {
95
- validateLogger('noConfigAccounts');
96
- return false;
97
- }
98
- const accountIdsMap = {};
99
- const accountNamesMap = {};
100
- return this.config.accounts.every(accountConfig => {
101
- if (!accountConfig) {
102
- validateLogger('emptyAccountConfig');
103
- return false;
104
- }
105
- if (!accountConfig.accountId) {
106
- validateLogger('noAccountId');
107
- return false;
108
- }
109
- if (accountIdsMap[accountConfig.accountId]) {
110
- validateLogger('duplicateAccountIds', {
111
- accountId: accountConfig.accountId,
112
- });
113
- return false;
114
- }
115
- if (accountConfig.name) {
116
- if (accountNamesMap[accountConfig.name]) {
117
- validateLogger('duplicateAccountNames', {
118
- accountName: accountConfig.name,
119
- });
120
- return false;
121
- }
122
- if (/\s+/.test(accountConfig.name)) {
123
- validateLogger('nameContainsSpaces', {
124
- accountName: accountConfig.name,
125
- });
126
- return false;
127
- }
128
- accountNamesMap[accountConfig.name] = true;
129
- }
130
- accountIdsMap[accountConfig.accountId] = true;
131
- return true;
132
- });
133
- }
134
- getAccount(nameOrId) {
135
- let name = null;
136
- let accountId = null;
137
- if (!this.config) {
138
- return null;
139
- }
140
- const nameOrIdToCheck = nameOrId ? nameOrId : this.getDefaultAccount();
141
- if (!nameOrIdToCheck) {
142
- return null;
143
- }
144
- if (typeof nameOrIdToCheck === 'number') {
145
- accountId = nameOrIdToCheck;
146
- }
147
- else if (/^\d+$/.test(nameOrIdToCheck)) {
148
- accountId = parseInt(nameOrIdToCheck, 10);
149
- }
150
- else {
151
- name = nameOrIdToCheck;
152
- }
153
- if (name) {
154
- return this.config.accounts.find(a => a.name === name) || null;
155
- }
156
- else if (accountId) {
157
- return this.config.accounts.find(a => accountId === a.accountId) || null;
158
- }
159
- return null;
160
- }
161
- getAccountId(nameOrId) {
162
- const account = this.getAccount(nameOrId);
163
- return account ? account.accountId : null;
164
- }
165
- getDefaultAccount() {
166
- return this.config && this.config.defaultAccount
167
- ? this.config.defaultAccount
168
- : null;
169
- }
170
- // TODO a util that returns the account to use, respecting the values set in
171
- // "defaultAccountOverrides"
172
- // Example "defaultAccountOverrides":
173
- // - /src/brodgers/customer-project-1: customer-account1
174
- // - /src/brodgers/customer-project-2: customer-account2
175
- // "/src/brodgers/customer-project-1" is the path to the project dir
176
- // "customer-account1" is the name of the account to use as the default for the specified dir
177
- // These defaults take precedence over the standard default account specified in the config
178
- getResolvedDefaultAccountForCWD(nameOrId) {
179
- return this.getAccount(nameOrId);
180
- }
181
- getConfigAccountIndex(accountId) {
182
- return this.config
183
- ? this.config.accounts.findIndex(account => account.accountId === accountId)
184
- : -1;
185
- }
186
- isAccountInConfig(nameOrId) {
187
- return (!!this.config && this.config.accounts && !!this.getAccountId(nameOrId));
188
- }
189
- getAndLoadConfigIfNeeded(options) {
190
- if (!this.config) {
191
- this.init(options);
192
- }
193
- return this.config;
194
- }
195
- getEnv(nameOrId) {
196
- const accountConfig = this.getAccount(nameOrId);
197
- if (accountConfig && accountConfig.accountId && accountConfig.env) {
198
- return accountConfig.env;
199
- }
200
- if (this.config && this.config.env) {
201
- return this.config.env;
202
- }
203
- return constants_1.ENVIRONMENTS.PROD;
204
- }
205
- /*
206
- * Config Update Utils
207
- */
208
- /**
209
- * @throws {Error}
210
- */
211
- updateAccount(updatedAccountFields, writeUpdate = true) {
212
- const { accountId, apiKey, authType, clientId, clientSecret, defaultMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
213
- if (!accountId) {
214
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAccount`);
215
- }
216
- if (!this.config) {
217
- (0, logger_1.debug)(`${i18nKey}.updateAccount.noConfigToUpdate`);
218
- return null;
219
- }
220
- const currentAccountConfig = this.getAccount(accountId);
221
- let auth;
222
- if (clientId || clientSecret || scopes || tokenInfo) {
223
- auth = {
224
- ...(currentAccountConfig ? currentAccountConfig.auth : {}),
225
- clientId,
226
- clientSecret,
227
- scopes,
228
- tokenInfo,
229
- };
230
- }
231
- const nextAccountConfig = {
232
- ...(currentAccountConfig ? currentAccountConfig : {}),
233
- };
234
- // Allow everything except for 'undefined' values to override the existing values
235
- function safelyApplyUpdates(fieldName,
236
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
237
- newValue) {
238
- if (typeof newValue !== 'undefined') {
239
- nextAccountConfig[fieldName] = newValue;
240
- }
241
- }
242
- const updatedEnv = (0, environment_1.getValidEnv)(env || (currentAccountConfig && currentAccountConfig.env), false);
243
- const updatedDefaultMode = defaultMode &&
244
- defaultMode.toLowerCase();
245
- safelyApplyUpdates('name', name);
246
- safelyApplyUpdates('env', updatedEnv);
247
- safelyApplyUpdates('accountId', accountId);
248
- safelyApplyUpdates('authType', authType);
249
- safelyApplyUpdates('auth', auth);
250
- if (nextAccountConfig.authType === auth_1.API_KEY_AUTH_METHOD.value) {
251
- safelyApplyUpdates('apiKey', apiKey);
252
- }
253
- if (typeof updatedDefaultMode !== 'undefined') {
254
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
255
- safelyApplyUpdates('defaultMode', config_1.DEFAULT_MODES[updatedDefaultMode]);
256
- }
257
- safelyApplyUpdates('personalAccessKey', personalAccessKey);
258
- safelyApplyUpdates('sandboxAccountType', sandboxAccountType);
259
- safelyApplyUpdates('parentAccountId', parentAccountId);
260
- const completedAccountConfig = nextAccountConfig;
261
- if (currentAccountConfig) {
262
- (0, logger_1.debug)(`${i18nKey}.updateAccount.updating`, {
263
- accountId,
264
- });
265
- const index = this.getConfigAccountIndex(accountId);
266
- this.config.accounts[index] = completedAccountConfig;
267
- (0, logger_1.debug)(`${i18nKey}.updateAccount.addingConfigEntry`, {
268
- accountId,
269
- });
270
- if (this.config.accounts) {
271
- this.config.accounts.push(completedAccountConfig);
272
- }
273
- else {
274
- this.config.accounts = [completedAccountConfig];
275
- }
276
- }
277
- if (writeUpdate) {
278
- this.write();
279
- }
280
- return completedAccountConfig;
281
- }
282
- /**
283
- * @throws {Error}
284
- */
285
- updateDefaultAccount(defaultAccount) {
286
- if (!this.config) {
287
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
288
- }
289
- if (!defaultAccount ||
290
- (typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')) {
291
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultAccount`);
292
- }
293
- this.config.defaultAccount = defaultAccount;
294
- return this.write();
295
- }
296
- /**
297
- * @throws {Error}
298
- */
299
- renameAccount(currentName, newName) {
300
- if (!this.config) {
301
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
302
- }
303
- const accountId = this.getAccountId(currentName);
304
- let accountConfigToRename = null;
305
- if (accountId) {
306
- accountConfigToRename = this.getAccount(accountId);
307
- }
308
- if (!accountConfigToRename) {
309
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.renameAccount`, { currentName });
310
- }
311
- if (accountId) {
312
- this.updateAccount({ accountId, name: newName });
313
- }
314
- if (accountConfigToRename.name === this.getDefaultAccount()) {
315
- this.updateDefaultAccount(newName);
316
- }
317
- }
318
- /**
319
- * @throws {Error}
320
- */
321
- removeAccountFromConfig(nameOrId) {
322
- if (!this.config) {
323
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
324
- }
325
- const accountId = this.getAccountId(nameOrId);
326
- if (!accountId) {
327
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.removeAccountFromConfig`, { nameOrId });
328
- }
329
- let removedAccountIsDefault = false;
330
- const accountConfig = this.getAccount(accountId);
331
- if (accountConfig) {
332
- (0, logger_1.debug)(`${i18nKey}.removeAccountFromConfig`, { accountId });
333
- const index = this.getConfigAccountIndex(accountId);
334
- this.config.accounts.splice(index, 1);
335
- if (this.getDefaultAccount() === accountConfig.name) {
336
- removedAccountIsDefault = true;
337
- }
338
- this.write();
339
- }
340
- return removedAccountIsDefault;
341
- }
342
- /**
343
- * @throws {Error}
344
- */
345
- updateDefaultMode(defaultMode) {
346
- if (!this.config) {
347
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
348
- }
349
- const ALL_MODES = Object.values(config_1.DEFAULT_MODES);
350
- if (!defaultMode || !ALL_MODES.find(m => m === defaultMode)) {
351
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultMode`, {
352
- defaultMode,
353
- validModes: (0, text_1.commaSeparatedValues)(ALL_MODES),
354
- });
355
- }
356
- this.config.defaultMode = defaultMode;
357
- return this.write();
358
- }
359
- /**
360
- * @throws {Error}
361
- */
362
- updateHttpTimeout(timeout) {
363
- if (!this.config) {
364
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
365
- }
366
- const parsedTimeout = parseInt(timeout);
367
- if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
368
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateHttpTimeout`, {
369
- timeout,
370
- minTimeout: config_1.MIN_HTTP_TIMEOUT,
371
- });
372
- }
373
- this.config.httpTimeout = parsedTimeout;
374
- return this.write();
375
- }
376
- /**
377
- * @throws {Error}
378
- */
379
- updateAllowUsageTracking(isEnabled) {
380
- if (!this.config) {
381
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
382
- }
383
- if (typeof isEnabled !== 'boolean') {
384
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAllowUsageTracking`, {
385
- isEnabled: `${isEnabled}`,
386
- });
387
- }
388
- this.config.allowUsageTracking = isEnabled;
389
- return this.write();
390
- }
391
- }
392
- exports.default = new CLIConfiguration();
@@ -1,21 +0,0 @@
1
- import { CLIConfig } 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;
14
- /**
15
- * @throws {Error}
16
- */
17
- export declare function loadConfigFromFile(): CLIConfig | null;
18
- /**
19
- * @throws {Error}
20
- */
21
- export declare function writeConfigToFile(config: CLIConfig): void;
@@ -1,109 +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 path_1 = __importDefault(require("path"));
9
- const os_1 = __importDefault(require("os"));
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");
14
- const constants_1 = require("../constants");
15
- const configUtils_1 = require("./configUtils");
16
- const i18nKey = 'config.configFile';
17
- function getConfigFilePath() {
18
- return path_1.default.join(os_1.default.homedir(), constants_1.HUBSPOT_CONFIGURATION_FOLDER, constants_1.HUBSPOT_CONFIGURATION_FILE);
19
- }
20
- exports.getConfigFilePath = getConfigFilePath;
21
- function configFileExists() {
22
- const configPath = getConfigFilePath();
23
- return !!configPath && fs_extra_1.default.existsSync(configPath);
24
- }
25
- exports.configFileExists = configFileExists;
26
- function configFileIsBlank() {
27
- const configPath = getConfigFilePath();
28
- return !!configPath && fs_extra_1.default.readFileSync(configPath).length === 0;
29
- }
30
- exports.configFileIsBlank = configFileIsBlank;
31
- function deleteConfigFile() {
32
- const configPath = getConfigFilePath();
33
- fs_extra_1.default.unlinkSync(configPath);
34
- }
35
- exports.deleteConfigFile = deleteConfigFile;
36
- /**
37
- * @throws {Error}
38
- */
39
- function readConfigFile(configPath) {
40
- let source = '';
41
- try {
42
- source = fs_extra_1.default.readFileSync(configPath).toString();
43
- }
44
- catch (err) {
45
- (0, logger_1.debug)(`${i18nKey}.errorReading`, { configPath });
46
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
47
- filepath: configPath,
48
- read: true,
49
- });
50
- }
51
- return source;
52
- }
53
- exports.readConfigFile = readConfigFile;
54
- /**
55
- * @throws {Error}
56
- */
57
- function parseConfig(configSource) {
58
- let parsed;
59
- try {
60
- parsed = js_yaml_1.default.load(configSource);
61
- }
62
- catch (err) {
63
- (0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.parsing`, {}, err);
64
- }
65
- return parsed;
66
- }
67
- exports.parseConfig = parseConfig;
68
- /**
69
- * @throws {Error}
70
- */
71
- function loadConfigFromFile() {
72
- const configPath = getConfigFilePath();
73
- if (configPath) {
74
- const source = readConfigFile(configPath);
75
- if (!source) {
76
- return null;
77
- }
78
- return parseConfig(source);
79
- }
80
- // TODO: Maybe use log callbacks here
81
- (0, logger_1.debug)(`${i18nKey}.errorLoading`, { configPath });
82
- return null;
83
- }
84
- exports.loadConfigFromFile = loadConfigFromFile;
85
- /**
86
- * @throws {Error}
87
- */
88
- function writeConfigToFile(config) {
89
- let source;
90
- try {
91
- source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
92
- }
93
- catch (err) {
94
- (0, standardErrors_1.throwError)(err);
95
- }
96
- const configPath = getConfigFilePath();
97
- try {
98
- fs_extra_1.default.ensureFileSync(configPath);
99
- fs_extra_1.default.writeFileSync(configPath, source);
100
- (0, logger_1.debug)(`${i18nKey}.writeSuccess`, { configPath });
101
- }
102
- catch (err) {
103
- (0, fileSystemErrors_1.throwFileSystemError)(err, {
104
- filepath: configPath,
105
- write: true,
106
- });
107
- }
108
- }
109
- exports.writeConfigToFile = writeConfigToFile;
@@ -1,24 +0,0 @@
1
- import { CLIConfig } from '../types/Config';
2
- import { AuthType, CLIAccount } from '../types/Accounts';
3
- export declare function getOrderedAccount(unorderedAccount: CLIAccount): CLIAccount;
4
- export declare function getOrderedConfig(unorderedConfig: CLIConfig): CLIConfig;
5
- type PersonalAccessKeyOptions = {
6
- accountId: number;
7
- personalAccessKey: string;
8
- env: string;
9
- };
10
- type OAuthOptions = {
11
- accountId: number;
12
- clientId: string;
13
- clientSecret: string;
14
- refreshToken: string;
15
- scopes: Array<string>;
16
- env: string;
17
- };
18
- type APIKeyOptions = {
19
- accountId: number;
20
- apiKey: string;
21
- env: string;
22
- };
23
- export declare function generateConfig(type: AuthType, options: PersonalAccessKeyOptions | OAuthOptions | APIKeyOptions): CLIConfig | null;
24
- export {};