@hubspot/local-dev-lib 0.0.8 → 0.0.9
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.
- package/api/fileMapper.d.ts +2 -0
- package/api/fileMapper.js +3 -2
- package/config/CLIConfiguration.js +20 -18
- package/config/configFile.js +1 -2
- package/config/configUtils.js +2 -1
- package/config/config_DEPRECATED.js +24 -23
- package/config/environment.js +4 -3
- package/constants/ports.d.ts +3 -0
- package/constants/ports.js +6 -0
- package/errors/apiErrors.js +1 -1
- package/errors/fileSystemErrors.js +1 -1
- package/errors/standardErrors.d.ts +4 -3
- package/errors/standardErrors.js +2 -2
- package/http/index.js +7 -4
- package/lang/en.json +383 -0
- package/lang/lang/en.json +383 -0
- package/lib/archive.js +10 -9
- package/lib/cms/functions.js +13 -13
- package/lib/cms/handleFieldsJS.js +8 -6
- package/lib/cms/modules.js +5 -4
- package/lib/cms/processFieldsJs.js +6 -8
- package/lib/cms/templates.js +10 -5
- package/lib/cms/uploadFolder.js +11 -7
- package/lib/cms/watch.js +33 -21
- package/lib/customObjects.d.ts +4 -4
- package/lib/customObjects.js +21 -4
- package/lib/fileMapper.js +27 -20
- package/lib/github.js +15 -11
- package/lib/gitignore.js +2 -1
- package/lib/hubdb.js +4 -3
- package/lib/logging/git.js +1 -1
- package/lib/logging/logs.js +5 -1
- package/lib/oauth.js +5 -4
- package/lib/personalAccessKey.js +3 -2
- package/lib/portManager.d.ts +13 -0
- package/lib/portManager.js +45 -0
- package/lib/sandboxes.js +7 -7
- package/lib/trackUsage.js +1 -1
- package/models/OAuth2Manager.js +2 -2
- package/package.json +6 -1
- package/types/Lang.d.ts +7 -0
- package/types/Lang.js +2 -0
- package/types/PortManager.d.ts +4 -0
- package/types/PortManager.js +2 -0
- package/types/Schemas.d.ts +18 -33
- package/types/Utils.d.ts +5 -0
- package/utils/PortManagerServer.d.ts +29 -0
- package/utils/PortManagerServer.js +158 -0
- package/utils/cms/modules.js +2 -1
- package/utils/detectPort.d.ts +1 -0
- package/utils/detectPort.js +102 -0
- package/utils/lang.d.ts +2 -4
- package/utils/lang.js +12 -14
- package/utils/logger.d.ts +4 -3
- package/utils/logger.js +4 -3
- package/utils/notify.js +2 -1
- package/lang/en.lyaml +0 -247
package/api/fileMapper.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
1
2
|
import { FileMapperNode, FileMapperOptions, FileTree } from '../types/Files';
|
|
2
3
|
export declare const FILE_MAPPER_API_PATH = "content/filemapper/v1";
|
|
4
|
+
export declare function createFileMapperNodeFromStreamResponse(filePath: string, response: Partial<AxiosResponse>): FileMapperNode;
|
|
3
5
|
export declare function upload(accountId: number, src: string, dest: string, options?: FileMapperOptions): Promise<void>;
|
|
4
6
|
export declare function fetchModule(accountId: number, moduleId: number, options?: FileMapperOptions): Promise<FileTree>;
|
|
5
7
|
export declare function fetchFileStream(accountId: number, filePath: string, destination: string, options?: FileMapperOptions): Promise<FileMapperNode>;
|
package/api/fileMapper.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getDirectoryContentsByPath = exports.moveFile = exports.deleteFile = exports.downloadDefault = exports.download = exports.fetchFileStream = exports.fetchModule = exports.upload = exports.FILE_MAPPER_API_PATH = void 0;
|
|
6
|
+
exports.getDirectoryContentsByPath = exports.moveFile = exports.deleteFile = exports.downloadDefault = exports.download = exports.fetchFileStream = exports.fetchModule = exports.upload = exports.createFileMapperNodeFromStreamResponse = exports.FILE_MAPPER_API_PATH = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const content_disposition_1 = __importDefault(require("content-disposition"));
|
|
@@ -37,6 +37,7 @@ function createFileMapperNodeFromStreamResponse(filePath, response) {
|
|
|
37
37
|
updatedAt: parseInt(parameters['modification-date'], 10) || 0,
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
+
exports.createFileMapperNodeFromStreamResponse = createFileMapperNodeFromStreamResponse;
|
|
40
41
|
async function upload(accountId, src, dest, options = {}) {
|
|
41
42
|
return http_1.default.post(accountId, {
|
|
42
43
|
url: `${exports.FILE_MAPPER_API_PATH}/upload/${encodeURIComponent(dest)}`,
|
|
@@ -55,7 +56,7 @@ async function fetchModule(accountId, moduleId, options = {}) {
|
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
exports.fetchModule = fetchModule;
|
|
58
|
-
//Fetch a file by file path.
|
|
59
|
+
// Fetch a file by file path.
|
|
59
60
|
async function fetchFileStream(accountId, filePath, destination, options = {}) {
|
|
60
61
|
const response = await http_1.default.getOctetStream(accountId, {
|
|
61
62
|
url: `${exports.FILE_MAPPER_API_PATH}/stream/${encodeURIComponent(filePath)}`,
|
|
@@ -98,7 +98,7 @@ class CLIConfiguration {
|
|
|
98
98
|
return this.config;
|
|
99
99
|
}
|
|
100
100
|
validate(logCallbacks) {
|
|
101
|
-
const validateLogger = (0, logger_1.makeTypedLogger)(logCallbacks
|
|
101
|
+
const validateLogger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
102
102
|
if (!this.config) {
|
|
103
103
|
validateLogger('noConfig');
|
|
104
104
|
return false;
|
|
@@ -119,20 +119,20 @@ class CLIConfiguration {
|
|
|
119
119
|
return false;
|
|
120
120
|
}
|
|
121
121
|
if (accountIdsMap[accountConfig.accountId]) {
|
|
122
|
-
validateLogger('duplicateAccountIds', {
|
|
122
|
+
validateLogger('duplicateAccountIds', `${i18nKey}.validate.duplicateAccountIds`, {
|
|
123
123
|
accountId: accountConfig.accountId,
|
|
124
124
|
});
|
|
125
125
|
return false;
|
|
126
126
|
}
|
|
127
127
|
if (accountConfig.name) {
|
|
128
128
|
if (accountNamesMap[accountConfig.name]) {
|
|
129
|
-
validateLogger('duplicateAccountNames', {
|
|
129
|
+
validateLogger('duplicateAccountNames', `${i18nKey}.validate.duplicateAccountNames`, {
|
|
130
130
|
accountName: accountConfig.name,
|
|
131
131
|
});
|
|
132
132
|
return false;
|
|
133
133
|
}
|
|
134
134
|
if (/\s+/.test(accountConfig.name)) {
|
|
135
|
-
validateLogger('nameContainsSpaces', {
|
|
135
|
+
validateLogger('nameContainsSpaces', `${i18nKey}.validate.nameContainsSpaces`, {
|
|
136
136
|
accountName: accountConfig.name,
|
|
137
137
|
});
|
|
138
138
|
return false;
|
|
@@ -236,7 +236,7 @@ class CLIConfiguration {
|
|
|
236
236
|
updateAccount(updatedAccountFields, writeUpdate = true) {
|
|
237
237
|
const { accountId, apiKey, authType, clientId, clientSecret, defaultMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
|
|
238
238
|
if (!accountId) {
|
|
239
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAccount`);
|
|
239
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAccount.errors.accountIdRequired`);
|
|
240
240
|
}
|
|
241
241
|
if (!this.config) {
|
|
242
242
|
(0, logger_1.debug)(`${i18nKey}.updateAccount.noConfigToUpdate`);
|
|
@@ -308,11 +308,11 @@ class CLIConfiguration {
|
|
|
308
308
|
*/
|
|
309
309
|
updateDefaultAccount(defaultAccount) {
|
|
310
310
|
if (!this.config) {
|
|
311
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
|
|
311
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
|
|
312
312
|
}
|
|
313
313
|
if (!defaultAccount ||
|
|
314
314
|
(typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')) {
|
|
315
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultAccount`);
|
|
315
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`);
|
|
316
316
|
}
|
|
317
317
|
this.config.defaultAccount = defaultAccount;
|
|
318
318
|
return this.write();
|
|
@@ -322,7 +322,7 @@ class CLIConfiguration {
|
|
|
322
322
|
*/
|
|
323
323
|
renameAccount(currentName, newName) {
|
|
324
324
|
if (!this.config) {
|
|
325
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
|
|
325
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
|
|
326
326
|
}
|
|
327
327
|
const accountId = this.getAccountId(currentName);
|
|
328
328
|
let accountConfigToRename = null;
|
|
@@ -330,7 +330,9 @@ class CLIConfiguration {
|
|
|
330
330
|
accountConfigToRename = this.getAccount(accountId);
|
|
331
331
|
}
|
|
332
332
|
if (!accountConfigToRename) {
|
|
333
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.renameAccount`, {
|
|
333
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.renameAccount.errors.invalidName`, {
|
|
334
|
+
currentName,
|
|
335
|
+
});
|
|
334
336
|
}
|
|
335
337
|
if (accountId) {
|
|
336
338
|
this.updateAccount({ accountId, name: newName, env: this.getEnv() });
|
|
@@ -344,16 +346,16 @@ class CLIConfiguration {
|
|
|
344
346
|
*/
|
|
345
347
|
removeAccountFromConfig(nameOrId) {
|
|
346
348
|
if (!this.config) {
|
|
347
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
|
|
349
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
|
|
348
350
|
}
|
|
349
351
|
const accountId = this.getAccountId(nameOrId);
|
|
350
352
|
if (!accountId) {
|
|
351
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.removeAccountFromConfig`, { nameOrId });
|
|
353
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, { nameOrId });
|
|
352
354
|
}
|
|
353
355
|
let removedAccountIsDefault = false;
|
|
354
356
|
const accountConfig = this.getAccount(accountId);
|
|
355
357
|
if (accountConfig) {
|
|
356
|
-
(0, logger_1.debug)(`${i18nKey}.removeAccountFromConfig`, { accountId });
|
|
358
|
+
(0, logger_1.debug)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId });
|
|
357
359
|
const index = this.getConfigAccountIndex(accountId);
|
|
358
360
|
this.config.accounts.splice(index, 1);
|
|
359
361
|
if (this.getDefaultAccount() === accountConfig.name) {
|
|
@@ -368,11 +370,11 @@ class CLIConfiguration {
|
|
|
368
370
|
*/
|
|
369
371
|
updateDefaultMode(defaultMode) {
|
|
370
372
|
if (!this.config) {
|
|
371
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
|
|
373
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
|
|
372
374
|
}
|
|
373
375
|
const ALL_MODES = Object.values(files_1.MODE);
|
|
374
376
|
if (!defaultMode || !ALL_MODES.find(m => m === defaultMode)) {
|
|
375
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultMode`, {
|
|
377
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateDefaultMode.errors.invalidMode`, {
|
|
376
378
|
defaultMode,
|
|
377
379
|
validModes: (0, text_1.commaSeparatedValues)(ALL_MODES),
|
|
378
380
|
});
|
|
@@ -385,11 +387,11 @@ class CLIConfiguration {
|
|
|
385
387
|
*/
|
|
386
388
|
updateHttpTimeout(timeout) {
|
|
387
389
|
if (!this.config) {
|
|
388
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
|
|
390
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
|
|
389
391
|
}
|
|
390
392
|
const parsedTimeout = parseInt(timeout);
|
|
391
393
|
if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
|
|
392
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateHttpTimeout`, {
|
|
394
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
|
|
393
395
|
timeout,
|
|
394
396
|
minTimeout: config_1.MIN_HTTP_TIMEOUT,
|
|
395
397
|
});
|
|
@@ -402,10 +404,10 @@ class CLIConfiguration {
|
|
|
402
404
|
*/
|
|
403
405
|
updateAllowUsageTracking(isEnabled) {
|
|
404
406
|
if (!this.config) {
|
|
405
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.noConfigLoaded`);
|
|
407
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.noConfigLoaded`);
|
|
406
408
|
}
|
|
407
409
|
if (typeof isEnabled !== 'boolean') {
|
|
408
|
-
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAllowUsageTracking`, {
|
|
410
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
|
|
409
411
|
isEnabled: `${isEnabled}`,
|
|
410
412
|
});
|
|
411
413
|
}
|
package/config/configFile.js
CHANGED
|
@@ -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}.parsing`, {}, err);
|
|
63
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.parsing`, {}, err);
|
|
64
64
|
}
|
|
65
65
|
return parsed;
|
|
66
66
|
}
|
|
@@ -77,7 +77,6 @@ function loadConfigFromFile() {
|
|
|
77
77
|
}
|
|
78
78
|
return parseConfig(source);
|
|
79
79
|
}
|
|
80
|
-
// TODO: Maybe use log callbacks here
|
|
81
80
|
(0, logger_1.debug)(`${i18nKey}.errorLoading`, { configPath });
|
|
82
81
|
return null;
|
|
83
82
|
}
|
package/config/configUtils.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateConfig = exports.getOrderedConfig = exports.getOrderedAccount = void 0;
|
|
4
4
|
const logger_1 = require("../utils/logger");
|
|
5
5
|
const auth_1 = require("../constants/auth");
|
|
6
|
+
const i18nKey = 'config.configUtils';
|
|
6
7
|
function getOrderedAccount(unorderedAccount) {
|
|
7
8
|
const { name, accountId, env, authType, ...rest } = unorderedAccount;
|
|
8
9
|
return {
|
|
@@ -74,7 +75,7 @@ function generateConfig(type, options) {
|
|
|
74
75
|
configAccount = generateOauthAccountConfig(options);
|
|
75
76
|
break;
|
|
76
77
|
default:
|
|
77
|
-
(0, logger_1.debug)(
|
|
78
|
+
(0, logger_1.debug)(`${i18nKey}.unknownType`, { type });
|
|
78
79
|
return null;
|
|
79
80
|
}
|
|
80
81
|
if (configAccount) {
|
|
@@ -13,6 +13,7 @@ const environments_1 = require("../constants/environments");
|
|
|
13
13
|
const auth_1 = require("../constants/auth");
|
|
14
14
|
const files_1 = require("../constants/files");
|
|
15
15
|
const environment_1 = require("../lib/environment");
|
|
16
|
+
const logger_1 = require("../lib/logging/logger");
|
|
16
17
|
const git_1 = require("../utils/git");
|
|
17
18
|
const errors_DEPRECATED_1 = require("../errors/errors_DEPRECATED");
|
|
18
19
|
const ALL_MODES = Object.values(files_1.MODE);
|
|
@@ -69,37 +70,37 @@ exports.getConfigPath = getConfigPath;
|
|
|
69
70
|
function validateConfig() {
|
|
70
71
|
const config = (0, exports.getConfig)();
|
|
71
72
|
if (!config) {
|
|
72
|
-
|
|
73
|
+
logger_1.logger.error('No config was found');
|
|
73
74
|
return false;
|
|
74
75
|
}
|
|
75
76
|
const accounts = getConfigAccounts();
|
|
76
77
|
if (!Array.isArray(accounts)) {
|
|
77
|
-
|
|
78
|
+
logger_1.logger.error('config.portals[] is not defined');
|
|
78
79
|
return false;
|
|
79
80
|
}
|
|
80
81
|
const accountIdsHash = {};
|
|
81
82
|
const accountNamesHash = {};
|
|
82
83
|
return accounts.every(cfg => {
|
|
83
84
|
if (!cfg) {
|
|
84
|
-
|
|
85
|
+
logger_1.logger.error('config.portals[] has an empty entry');
|
|
85
86
|
return false;
|
|
86
87
|
}
|
|
87
88
|
const accountId = getConfigAccountId(cfg);
|
|
88
89
|
if (!accountId) {
|
|
89
|
-
|
|
90
|
+
logger_1.logger.error('config.portals[] has an entry missing portalId');
|
|
90
91
|
return false;
|
|
91
92
|
}
|
|
92
93
|
if (accountIdsHash[accountId]) {
|
|
93
|
-
|
|
94
|
+
logger_1.logger.error(`config.portals[] has multiple entries with portalId=${accountId}`);
|
|
94
95
|
return false;
|
|
95
96
|
}
|
|
96
97
|
if (cfg.name) {
|
|
97
98
|
if (accountNamesHash[cfg.name]) {
|
|
98
|
-
|
|
99
|
+
logger_1.logger.error(`config.name has multiple entries with portalId=${accountId}`);
|
|
99
100
|
return false;
|
|
100
101
|
}
|
|
101
102
|
if (/\s+/.test(cfg.name)) {
|
|
102
|
-
|
|
103
|
+
logger_1.logger.error(`config.name '${cfg.name}' cannot contain spaces`);
|
|
103
104
|
return false;
|
|
104
105
|
}
|
|
105
106
|
accountNamesHash[cfg.name] = cfg;
|
|
@@ -158,7 +159,7 @@ function writeConfig(options = {}) {
|
|
|
158
159
|
}
|
|
159
160
|
const configPath = options.path || _configPath;
|
|
160
161
|
try {
|
|
161
|
-
|
|
162
|
+
logger_1.logger.debug(`Writing current config to ${configPath}`);
|
|
162
163
|
fs_extra_1.default.ensureFileSync(configPath || '');
|
|
163
164
|
fs_extra_1.default.writeFileSync(configPath || '', source);
|
|
164
165
|
setConfig(parseConfig(source).parsed);
|
|
@@ -183,7 +184,7 @@ function readConfigFile() {
|
|
|
183
184
|
}
|
|
184
185
|
catch (err) {
|
|
185
186
|
error = err;
|
|
186
|
-
|
|
187
|
+
logger_1.logger.error('Config file could not be read "%s"', _configPath);
|
|
187
188
|
(0, errors_DEPRECATED_1.logFileSystemErrorInstance)(error, { filepath: _configPath, read: true });
|
|
188
189
|
}
|
|
189
190
|
return { source: source && source.toString(), error };
|
|
@@ -199,7 +200,7 @@ function parseConfig(configSource) {
|
|
|
199
200
|
}
|
|
200
201
|
catch (err) {
|
|
201
202
|
error = err;
|
|
202
|
-
|
|
203
|
+
logger_1.logger.error('Config file could not be parsed "%s"', _configPath);
|
|
203
204
|
(0, errors_DEPRECATED_1.logErrorInstance)(err);
|
|
204
205
|
}
|
|
205
206
|
return { parsed, error };
|
|
@@ -208,14 +209,14 @@ function loadConfigFromFile(path, options = {}) {
|
|
|
208
209
|
setConfigPath(getConfigPath(path));
|
|
209
210
|
if (!_configPath) {
|
|
210
211
|
if (!options.silenceErrors) {
|
|
211
|
-
|
|
212
|
+
logger_1.logger.error(`A ${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME} file could not be found. To create a new config file, use the "hs init" command.`);
|
|
212
213
|
}
|
|
213
214
|
else {
|
|
214
|
-
|
|
215
|
+
logger_1.logger.debug(`A ${config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME} file could not be found`);
|
|
215
216
|
}
|
|
216
217
|
return;
|
|
217
218
|
}
|
|
218
|
-
|
|
219
|
+
logger_1.logger.debug(`Reading config from ${_configPath}`);
|
|
219
220
|
const { source, error: sourceError } = readConfigFile();
|
|
220
221
|
if (sourceError)
|
|
221
222
|
return;
|
|
@@ -224,8 +225,8 @@ function loadConfigFromFile(path, options = {}) {
|
|
|
224
225
|
return;
|
|
225
226
|
setConfig(parsed);
|
|
226
227
|
if (!(0, exports.getConfig)()) {
|
|
227
|
-
|
|
228
|
-
|
|
228
|
+
logger_1.logger.debug('The config file was empty config');
|
|
229
|
+
logger_1.logger.debug('Initializing an empty config');
|
|
229
230
|
setConfig({ portals: [] });
|
|
230
231
|
}
|
|
231
232
|
return (0, exports.getConfig)();
|
|
@@ -234,11 +235,11 @@ function loadConfig(path, options = {
|
|
|
234
235
|
useEnv: false,
|
|
235
236
|
}) {
|
|
236
237
|
if (options.useEnv && loadEnvironmentVariableConfig(options)) {
|
|
237
|
-
|
|
238
|
+
logger_1.logger.debug('Loaded environment variable config');
|
|
238
239
|
environmentVariableConfigLoaded = true;
|
|
239
240
|
}
|
|
240
241
|
else {
|
|
241
|
-
path &&
|
|
242
|
+
path && logger_1.logger.debug(`Loading config from ${path}`);
|
|
242
243
|
loadConfigFromFile(path, options);
|
|
243
244
|
environmentVariableConfigLoaded = false;
|
|
244
245
|
}
|
|
@@ -349,7 +350,7 @@ function removeSandboxAccountFromConfig(nameOrId) {
|
|
|
349
350
|
}
|
|
350
351
|
const accounts = getConfigAccounts(config);
|
|
351
352
|
if (accountConfig && accounts) {
|
|
352
|
-
|
|
353
|
+
logger_1.logger.debug(`Deleting config for ${accountId}`);
|
|
353
354
|
const index = accounts.indexOf(accountConfig);
|
|
354
355
|
accounts.splice(index, 1);
|
|
355
356
|
}
|
|
@@ -396,12 +397,12 @@ function updateAccountConfig(configOptions) {
|
|
|
396
397
|
};
|
|
397
398
|
let accounts = getConfigAccounts(config);
|
|
398
399
|
if (accountConfig && accounts) {
|
|
399
|
-
|
|
400
|
+
logger_1.logger.debug(`Updating config for ${portalId}`);
|
|
400
401
|
const index = accounts.indexOf(accountConfig);
|
|
401
402
|
accounts[index] = nextAccountConfig;
|
|
402
403
|
}
|
|
403
404
|
else {
|
|
404
|
-
|
|
405
|
+
logger_1.logger.debug(`Adding config entry for ${portalId}`);
|
|
405
406
|
if (accounts) {
|
|
406
407
|
accounts.push(nextAccountConfig);
|
|
407
408
|
}
|
|
@@ -601,7 +602,7 @@ function loadConfigFromEnvironment({ useEnv = false, } = {}) {
|
|
|
601
602
|
const { apiKey, clientId, clientSecret, personalAccessKey, portalId, refreshToken, env, } = getConfigVariablesFromEnv();
|
|
602
603
|
const unableToLoadEnvConfigError = 'Unable to load config from environment variables.';
|
|
603
604
|
if (!portalId) {
|
|
604
|
-
useEnv &&
|
|
605
|
+
useEnv && logger_1.logger.error(unableToLoadEnvConfigError);
|
|
605
606
|
return;
|
|
606
607
|
}
|
|
607
608
|
if (personalAccessKey) {
|
|
@@ -614,7 +615,7 @@ function loadConfigFromEnvironment({ useEnv = false, } = {}) {
|
|
|
614
615
|
return generateApiKeyConfig(portalId, apiKey, env);
|
|
615
616
|
}
|
|
616
617
|
else {
|
|
617
|
-
useEnv &&
|
|
618
|
+
useEnv && logger_1.logger.error(unableToLoadEnvConfigError);
|
|
618
619
|
return;
|
|
619
620
|
}
|
|
620
621
|
}
|
|
@@ -625,7 +626,7 @@ function loadEnvironmentVariableConfig(options) {
|
|
|
625
626
|
return null;
|
|
626
627
|
}
|
|
627
628
|
const { portalId } = getConfigVariablesFromEnv();
|
|
628
|
-
|
|
629
|
+
logger_1.logger.debug(`Loaded config from environment variables for account ${portalId}`);
|
|
629
630
|
return setConfig(envConfig);
|
|
630
631
|
}
|
|
631
632
|
function isConfigFlagEnabled(flag) {
|
package/config/environment.js
CHANGED
|
@@ -6,6 +6,7 @@ const environments_1 = require("../constants/environments");
|
|
|
6
6
|
const auth_1 = require("../constants/auth");
|
|
7
7
|
const configUtils_1 = require("./configUtils");
|
|
8
8
|
const environment_1 = require("../lib/environment");
|
|
9
|
+
const i18nKey = 'config.environment';
|
|
9
10
|
function getConfigVariablesFromEnv() {
|
|
10
11
|
const env = process.env;
|
|
11
12
|
return {
|
|
@@ -21,11 +22,11 @@ function getConfigVariablesFromEnv() {
|
|
|
21
22
|
function loadConfigFromEnvironment() {
|
|
22
23
|
const { apiKey, clientId, clientSecret, personalAccessKey, accountId, refreshToken, env, } = getConfigVariablesFromEnv();
|
|
23
24
|
if (!accountId) {
|
|
24
|
-
(0, logger_1.debug)(
|
|
25
|
+
(0, logger_1.debug)(`${i18nKey}.loadConfig.missingAccountId`);
|
|
25
26
|
return null;
|
|
26
27
|
}
|
|
27
28
|
if (!env) {
|
|
28
|
-
(0, logger_1.debug)(
|
|
29
|
+
(0, logger_1.debug)(`${i18nKey}.loadConfig.missingEnv`);
|
|
29
30
|
return null;
|
|
30
31
|
}
|
|
31
32
|
if (personalAccessKey) {
|
|
@@ -52,7 +53,7 @@ function loadConfigFromEnvironment() {
|
|
|
52
53
|
env,
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
|
-
(0, logger_1.debug)(
|
|
56
|
+
(0, logger_1.debug)(`${i18nKey}.loadConfig.unknownAuthType`);
|
|
56
57
|
return null;
|
|
57
58
|
}
|
|
58
59
|
exports.loadConfigFromEnvironment = loadConfigFromEnvironment;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PORT_MANAGER_SERVER_PORT = exports.MAX_PORT_NUMBER = exports.MIN_PORT_NUMBER = void 0;
|
|
4
|
+
exports.MIN_PORT_NUMBER = 1024;
|
|
5
|
+
exports.MAX_PORT_NUMBER = 65535;
|
|
6
|
+
exports.PORT_MANAGER_SERVER_PORT = 8080;
|
package/errors/apiErrors.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.throwApiUploadError = exports.throwApiError = exports.throwApiStatusCode
|
|
|
4
4
|
const api_1 = require("../constants/api");
|
|
5
5
|
const lang_1 = require("../utils/lang");
|
|
6
6
|
const standardErrors_1 = require("./standardErrors");
|
|
7
|
+
const i18nKey = 'errors.apiErrors';
|
|
7
8
|
function isApiStatusCodeError(err) {
|
|
8
9
|
return (err.name === 'StatusCodeError' ||
|
|
9
10
|
(!!err.status && err.status >= 100 && err.status < 600));
|
|
@@ -87,7 +88,6 @@ exports.throwStatusCodeError = throwStatusCodeError;
|
|
|
87
88
|
* @throws
|
|
88
89
|
*/
|
|
89
90
|
function throwApiStatusCodeError(error, context = {}) {
|
|
90
|
-
const i18nKey = 'errors.errorTypes.api';
|
|
91
91
|
const { status } = error;
|
|
92
92
|
const { method } = error.options || {};
|
|
93
93
|
const { projectName } = context;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.throwFileSystemError = void 0;
|
|
4
4
|
const lang_1 = require("../utils/lang");
|
|
5
5
|
const standardErrors_1 = require("./standardErrors");
|
|
6
|
-
const i18nKey = 'errors.
|
|
6
|
+
const i18nKey = 'errors.fileSystemErrors';
|
|
7
7
|
function throwFileSystemError(error, context) {
|
|
8
8
|
let fileAction = '';
|
|
9
9
|
if (context.read) {
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { BaseError, StatusCodeError } from '../types/Error';
|
|
2
|
+
import { LangKey } from '../types/Lang';
|
|
2
3
|
export declare function isSystemError(err: BaseError): boolean;
|
|
3
4
|
export declare function isFatalError(err: BaseError): boolean;
|
|
4
5
|
/**
|
|
5
6
|
* @throws
|
|
6
7
|
*/
|
|
7
|
-
export declare function throwErrorWithMessage(identifier:
|
|
8
|
+
export declare function throwErrorWithMessage(identifier: LangKey, interpolation?: {
|
|
8
9
|
[key: string]: string | number;
|
|
9
10
|
}, cause?: BaseError): never;
|
|
10
11
|
/**
|
|
11
12
|
* @throws
|
|
12
13
|
*/
|
|
13
|
-
export declare function throwTypeErrorWithMessage(identifier:
|
|
14
|
+
export declare function throwTypeErrorWithMessage(identifier: LangKey, interpolation?: {
|
|
14
15
|
[key: string]: string | number;
|
|
15
16
|
}, cause?: BaseError): never;
|
|
16
17
|
/**
|
|
17
18
|
* @throws
|
|
18
19
|
*/
|
|
19
|
-
export declare function throwAuthErrorWithMessage(identifier:
|
|
20
|
+
export declare function throwAuthErrorWithMessage(identifier: LangKey, interpolation?: {
|
|
20
21
|
[key: string]: string | number;
|
|
21
22
|
}, cause?: StatusCodeError): never;
|
|
22
23
|
/**
|
package/errors/standardErrors.js
CHANGED
|
@@ -13,7 +13,7 @@ function isFatalError(err) {
|
|
|
13
13
|
}
|
|
14
14
|
exports.isFatalError = isFatalError;
|
|
15
15
|
function genericThrowErrorWithMessage(ErrorType, identifier, interpolation, cause) {
|
|
16
|
-
const message = (0, lang_1.i18n)(
|
|
16
|
+
const message = (0, lang_1.i18n)(identifier, interpolation);
|
|
17
17
|
if (cause) {
|
|
18
18
|
throw new ErrorType(message, { cause });
|
|
19
19
|
}
|
|
@@ -52,7 +52,7 @@ function throwError(error) {
|
|
|
52
52
|
else {
|
|
53
53
|
// Error or Error subclass
|
|
54
54
|
const name = error.name || 'Error';
|
|
55
|
-
const message = [(0, lang_1.i18n)('errors.
|
|
55
|
+
const message = [(0, lang_1.i18n)('errors.generic', { name })];
|
|
56
56
|
[error.message, error.reason].forEach(msg => {
|
|
57
57
|
if (msg) {
|
|
58
58
|
message.push(msg);
|
package/http/index.js
CHANGED
|
@@ -13,11 +13,12 @@ const oauth_1 = require("../lib/oauth");
|
|
|
13
13
|
const standardErrors_1 = require("../errors/standardErrors");
|
|
14
14
|
const logger_1 = require("../utils/logger");
|
|
15
15
|
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const i18nKey = 'http.index';
|
|
16
17
|
async function withOauth(accountId, accountConfig, axiosConfig) {
|
|
17
18
|
const { headers } = axiosConfig;
|
|
18
19
|
const oauth = (0, oauth_1.getOauthManager)(accountId, accountConfig);
|
|
19
20
|
if (!oauth) {
|
|
20
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
21
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.withOauth`, { accountId });
|
|
21
22
|
}
|
|
22
23
|
const accessToken = await oauth.accessToken();
|
|
23
24
|
return {
|
|
@@ -52,7 +53,7 @@ function withPortalId(portalId, axiosConfig) {
|
|
|
52
53
|
async function withAuth(accountId, options) {
|
|
53
54
|
const accountConfig = (0, config_1.getAccountConfig)(accountId);
|
|
54
55
|
if (!accountConfig) {
|
|
55
|
-
(0, standardErrors_1.throwErrorWithMessage)(
|
|
56
|
+
(0, standardErrors_1.throwErrorWithMessage)(`${i18nKey}.errors.withAuth`, { accountId });
|
|
56
57
|
}
|
|
57
58
|
const { env, authType, apiKey } = accountConfig;
|
|
58
59
|
const axiosConfig = withPortalId(accountId, (0, getAxiosConfig_1.getAxiosConfig)({ env, ...options }));
|
|
@@ -113,7 +114,7 @@ function createGetRequestStream(contentType) {
|
|
|
113
114
|
return async (accountId, options, destPath, logCallbacks) => {
|
|
114
115
|
const { query, ...rest } = options;
|
|
115
116
|
const axiosConfig = addQueryParams(rest, query);
|
|
116
|
-
const logger = (0, logger_1.makeTypedLogger)(logCallbacks
|
|
117
|
+
const logger = (0, logger_1.makeTypedLogger)(logCallbacks);
|
|
117
118
|
// eslint-disable-next-line no-async-promise-executor
|
|
118
119
|
return new Promise(async (resolve, reject) => {
|
|
119
120
|
try {
|
|
@@ -150,7 +151,9 @@ function createGetRequestStream(contentType) {
|
|
|
150
151
|
reject(err);
|
|
151
152
|
});
|
|
152
153
|
writeStream.on('close', async () => {
|
|
153
|
-
logger('onWrite', {
|
|
154
|
+
logger('onWrite', `${i18nKey}.createGetRequestStream.onWrite`, {
|
|
155
|
+
filepath,
|
|
156
|
+
});
|
|
154
157
|
resolve(res);
|
|
155
158
|
});
|
|
156
159
|
}
|