@hubspot/local-dev-lib 1.13.1 → 2.0.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.
- package/api/appsDev.d.ts +6 -5
- package/api/appsDev.js +6 -10
- package/api/customObjects.d.ts +7 -6
- package/api/customObjects.js +13 -16
- package/api/designManager.d.ts +3 -2
- package/api/designManager.js +5 -8
- package/api/developerTestAccounts.d.ts +5 -4
- package/api/developerTestAccounts.js +9 -10
- package/api/fileManager.d.ts +5 -4
- package/api/fileManager.js +9 -9
- package/api/fileMapper.d.ts +8 -8
- package/api/fileMapper.js +16 -16
- package/api/fileTransport.d.ts +4 -3
- package/api/fileTransport.js +5 -5
- package/api/functions.d.ts +6 -5
- package/api/functions.js +11 -14
- package/api/github.d.ts +6 -6
- package/api/github.js +5 -5
- package/api/hubdb.d.ts +9 -8
- package/api/hubdb.js +17 -20
- package/api/lighthouseScore.d.ts +4 -3
- package/api/lighthouseScore.js +7 -10
- package/api/localDevAuth.d.ts +5 -4
- package/api/localDevAuth.js +8 -9
- package/api/marketplaceValidation.d.ts +4 -3
- package/api/marketplaceValidation.js +4 -7
- package/api/projects.d.ts +31 -30
- package/api/projects.js +52 -52
- package/api/sandboxHubs.d.ts +5 -4
- package/api/sandboxHubs.js +9 -10
- package/api/sandboxSync.d.ts +4 -4
- package/api/sandboxSync.js +5 -14
- package/api/secrets.d.ts +5 -4
- package/api/secrets.js +9 -12
- package/api/validateHubl.d.ts +2 -1
- package/api/validateHubl.js +3 -6
- package/config/CLIConfiguration.d.ts +3 -3
- package/config/CLIConfiguration.js +22 -20
- package/config/configFile.js +7 -14
- package/config/config_DEPRECATED.js +5 -2
- package/config/index.js +45 -48
- package/errors/errors_DEPRECATED.js +2 -2
- package/errors/index.d.ts +18 -0
- package/errors/index.js +63 -0
- package/http/addQueryParams.d.ts +2 -0
- package/http/addQueryParams.js +14 -0
- package/http/getAxiosConfig.d.ts +2 -2
- package/http/getAxiosConfig.js +10 -2
- package/http/index.d.ts +9 -14
- package/http/index.js +28 -53
- package/http/unauthed.d.ts +15 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +1 -2
- package/lang/lang/en.json +1 -2
- package/lib/archive.js +11 -10
- package/lib/cms/functions.js +18 -17
- package/lib/cms/handleFieldsJS.js +8 -7
- package/lib/cms/modules.js +4 -5
- package/lib/cms/processFieldsJs.js +8 -7
- package/lib/cms/templates.js +2 -3
- package/lib/cms/uploadFolder.js +16 -14
- package/lib/cms/validate.js +1 -1
- package/lib/cms/watch.js +16 -9
- package/lib/customObjects.js +4 -15
- package/lib/fileManager.js +22 -21
- package/lib/fileMapper.js +24 -31
- package/lib/fs.js +2 -2
- package/lib/github.js +21 -21
- package/lib/gitignore.js +2 -2
- package/lib/hubdb.d.ts +3 -2
- package/lib/hubdb.js +11 -9
- package/lib/notify.js +2 -2
- package/lib/oauth.d.ts +1 -1
- package/lib/oauth.js +8 -17
- package/lib/personalAccessKey.js +16 -21
- package/lib/portManager.js +2 -2
- package/lib/trackUsage.js +3 -3
- package/models/FileSystemError.d.ts +6 -0
- package/models/FileSystemError.js +47 -0
- package/models/HubSpotHttpError.d.ts +24 -0
- package/models/HubSpotHttpError.js +197 -0
- package/models/OAuth2Manager.d.ts +1 -2
- package/models/OAuth2Manager.js +13 -28
- package/package.json +2 -1
- package/types/Error.d.ts +7 -5
- package/types/Files.d.ts +4 -4
- package/types/Http.d.ts +6 -10
- package/types/Sandbox.d.ts +0 -5
- package/utils/PortManagerServer.d.ts +3 -3
- package/utils/PortManagerServer.js +9 -9
- package/utils/cms/modules.js +2 -2
- package/utils/detectPort.js +3 -3
- package/errors/apiErrors.d.ts +0 -25
- package/errors/apiErrors.js +0 -176
- package/errors/fileSystemErrors.d.ts +0 -6
- package/errors/fileSystemErrors.js +0 -35
- package/errors/standardErrors.d.ts +0 -20
- package/errors/standardErrors.js +0 -62
- package/lib/developerTestAccounts.d.ts +0 -4
- package/lib/developerTestAccounts.js +0 -35
- package/lib/sandboxes.d.ts +0 -14
- package/lib/sandboxes.js +0 -70
- package/models/HubSpotAuthError.d.ts +0 -12
- package/models/HubSpotAuthError.js +0 -20
package/api/sandboxSync.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function fetchTypes(accountId: number, toHubId: number):
|
|
1
|
+
import { AxiosPromise } from 'axios';
|
|
2
|
+
import { InitiateSyncResponse, FetchTypesResponse, TaskRequestData } from '../types/Sandbox';
|
|
3
|
+
export declare function initiateSync(fromHubId: number, toHubId: number, tasks: Array<TaskRequestData>, sandboxHubId: number): AxiosPromise<InitiateSyncResponse>;
|
|
4
|
+
export declare function fetchTypes(accountId: number, toHubId: number): AxiosPromise<FetchTypesResponse>;
|
package/api/sandboxSync.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchTypes = exports.
|
|
7
|
-
const http_1 =
|
|
3
|
+
exports.fetchTypes = exports.initiateSync = void 0;
|
|
4
|
+
const http_1 = require("../http");
|
|
8
5
|
const api_1 = require("../constants/api");
|
|
9
6
|
const SANDBOXES_SYNC_API_PATH = 'sandboxes-sync/v1';
|
|
10
|
-
|
|
11
|
-
return http_1.
|
|
7
|
+
function initiateSync(fromHubId, toHubId, tasks, sandboxHubId) {
|
|
8
|
+
return http_1.http.post(fromHubId, {
|
|
12
9
|
data: {
|
|
13
10
|
command: 'SYNC',
|
|
14
11
|
fromHubId,
|
|
@@ -21,14 +18,8 @@ async function initiateSync(fromHubId, toHubId, tasks, sandboxHubId) {
|
|
|
21
18
|
});
|
|
22
19
|
}
|
|
23
20
|
exports.initiateSync = initiateSync;
|
|
24
|
-
async function fetchTaskStatus(accountId, taskId) {
|
|
25
|
-
return http_1.default.get(accountId, {
|
|
26
|
-
url: `${SANDBOXES_SYNC_API_PATH}/tasks/${taskId}/status`,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
exports.fetchTaskStatus = fetchTaskStatus;
|
|
30
21
|
async function fetchTypes(accountId, toHubId) {
|
|
31
|
-
return http_1.
|
|
22
|
+
return http_1.http.get(accountId, {
|
|
32
23
|
url: `${SANDBOXES_SYNC_API_PATH}/types${toHubId ? `?toHubId=${toHubId}` : ''}`,
|
|
33
24
|
});
|
|
34
25
|
}
|
package/api/secrets.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { AxiosPromise } from 'axios';
|
|
1
2
|
import { FetchSecretsResponse } from '../types/Secrets';
|
|
2
|
-
export declare function addSecret(accountId: number, key: string, value: string):
|
|
3
|
-
export declare function updateSecret(accountId: number, key: string, value: string):
|
|
4
|
-
export declare function deleteSecret(accountId: number, key: string):
|
|
5
|
-
export declare function fetchSecrets(accountId: number):
|
|
3
|
+
export declare function addSecret(accountId: number, key: string, value: string): AxiosPromise<void>;
|
|
4
|
+
export declare function updateSecret(accountId: number, key: string, value: string): AxiosPromise<void>;
|
|
5
|
+
export declare function deleteSecret(accountId: number, key: string): AxiosPromise<void>;
|
|
6
|
+
export declare function fetchSecrets(accountId: number): AxiosPromise<FetchSecretsResponse>;
|
package/api/secrets.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.fetchSecrets = exports.deleteSecret = exports.updateSecret = exports.addSecret = void 0;
|
|
7
|
-
const http_1 =
|
|
4
|
+
const http_1 = require("../http");
|
|
8
5
|
const SECRETS_API_PATH = 'cms/v3/functions/secrets';
|
|
9
|
-
|
|
10
|
-
return http_1.
|
|
6
|
+
function addSecret(accountId, key, value) {
|
|
7
|
+
return http_1.http.post(accountId, {
|
|
11
8
|
url: SECRETS_API_PATH,
|
|
12
9
|
data: {
|
|
13
10
|
key,
|
|
@@ -16,8 +13,8 @@ async function addSecret(accountId, key, value) {
|
|
|
16
13
|
});
|
|
17
14
|
}
|
|
18
15
|
exports.addSecret = addSecret;
|
|
19
|
-
|
|
20
|
-
return http_1.
|
|
16
|
+
function updateSecret(accountId, key, value) {
|
|
17
|
+
return http_1.http.put(accountId, {
|
|
21
18
|
url: SECRETS_API_PATH,
|
|
22
19
|
data: {
|
|
23
20
|
key,
|
|
@@ -26,14 +23,14 @@ async function updateSecret(accountId, key, value) {
|
|
|
26
23
|
});
|
|
27
24
|
}
|
|
28
25
|
exports.updateSecret = updateSecret;
|
|
29
|
-
|
|
30
|
-
return http_1.
|
|
26
|
+
function deleteSecret(accountId, key) {
|
|
27
|
+
return http_1.http.delete(accountId, {
|
|
31
28
|
url: `${SECRETS_API_PATH}/${key}`,
|
|
32
29
|
});
|
|
33
30
|
}
|
|
34
31
|
exports.deleteSecret = deleteSecret;
|
|
35
|
-
|
|
36
|
-
return http_1.
|
|
32
|
+
function fetchSecrets(accountId) {
|
|
33
|
+
return http_1.http.get(accountId, {
|
|
37
34
|
url: `${SECRETS_API_PATH}`,
|
|
38
35
|
});
|
|
39
36
|
}
|
package/api/validateHubl.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { AxiosPromise } from 'axios';
|
|
1
2
|
import { Validation, HublValidationOptions } from '../types/HublValidation';
|
|
2
|
-
export declare function validateHubl(accountId: number, sourceCode: string, hublValidationOptions?: HublValidationOptions):
|
|
3
|
+
export declare function validateHubl(accountId: number, sourceCode: string, hublValidationOptions?: HublValidationOptions): AxiosPromise<Validation>;
|
package/api/validateHubl.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.validateHubl = void 0;
|
|
7
|
-
const http_1 =
|
|
4
|
+
const http_1 = require("../http");
|
|
8
5
|
const HUBL_VALIDATE_API_PATH = 'cos-rendering/v1/internal/validate';
|
|
9
|
-
|
|
10
|
-
return http_1.
|
|
6
|
+
function validateHubl(accountId, sourceCode, hublValidationOptions) {
|
|
7
|
+
return http_1.http.post(accountId, {
|
|
11
8
|
url: HUBL_VALIDATE_API_PATH,
|
|
12
9
|
data: {
|
|
13
10
|
template_source: sourceCode,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CLIConfig_NEW, Environment } from '../types/Config';
|
|
2
2
|
import { CLIAccount_NEW, FlatAccountFields_NEW, AccountType } from '../types/Accounts';
|
|
3
3
|
import { CLIOptions } from '../types/CLIOptions';
|
|
4
|
-
declare class
|
|
4
|
+
declare class _CLIConfiguration {
|
|
5
5
|
options: CLIOptions;
|
|
6
6
|
useEnvConfig: boolean;
|
|
7
7
|
config: CLIConfig_NEW | null;
|
|
@@ -57,5 +57,5 @@ declare class CLIConfiguration {
|
|
|
57
57
|
updateAllowUsageTracking(isEnabled: boolean): CLIConfig_NEW | null;
|
|
58
58
|
isTrackingAllowed(): boolean;
|
|
59
59
|
}
|
|
60
|
-
declare const
|
|
61
|
-
export
|
|
60
|
+
export declare const CLIConfiguration: _CLIConfiguration;
|
|
61
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLIConfiguration = void 0;
|
|
3
4
|
const logger_1 = require("../lib/logger");
|
|
4
|
-
const standardErrors_1 = require("../errors/standardErrors");
|
|
5
5
|
const environment_1 = require("./environment");
|
|
6
6
|
const environment_2 = require("../lib/environment");
|
|
7
7
|
const configFile_1 = require("./configFile");
|
|
@@ -12,7 +12,7 @@ const config_1 = require("../constants/config");
|
|
|
12
12
|
const files_1 = require("../constants/files");
|
|
13
13
|
const lang_1 = require("../utils/lang");
|
|
14
14
|
const i18nKey = 'config.cliConfiguration';
|
|
15
|
-
class
|
|
15
|
+
class _CLIConfiguration {
|
|
16
16
|
options;
|
|
17
17
|
useEnvConfig;
|
|
18
18
|
config;
|
|
@@ -249,7 +249,7 @@ class CLIConfiguration {
|
|
|
249
249
|
updateAccount(updatedAccountFields, writeUpdate = true) {
|
|
250
250
|
const { accountId, accountType, apiKey, authType, clientId, clientSecret, defaultMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
|
|
251
251
|
if (!accountId) {
|
|
252
|
-
(0,
|
|
252
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAccount.errors.accountIdRequired`));
|
|
253
253
|
}
|
|
254
254
|
if (!this.config) {
|
|
255
255
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.noConfigToUpdate`));
|
|
@@ -323,11 +323,11 @@ class CLIConfiguration {
|
|
|
323
323
|
*/
|
|
324
324
|
updateDefaultAccount(defaultAccount) {
|
|
325
325
|
if (!this.config) {
|
|
326
|
-
(0,
|
|
326
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
327
327
|
}
|
|
328
328
|
if (!defaultAccount ||
|
|
329
329
|
(typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')) {
|
|
330
|
-
(0,
|
|
330
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`));
|
|
331
331
|
}
|
|
332
332
|
this.config.defaultAccount = defaultAccount;
|
|
333
333
|
return this.write();
|
|
@@ -337,7 +337,7 @@ class CLIConfiguration {
|
|
|
337
337
|
*/
|
|
338
338
|
renameAccount(currentName, newName) {
|
|
339
339
|
if (!this.config) {
|
|
340
|
-
(0,
|
|
340
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
341
341
|
}
|
|
342
342
|
const accountId = this.getAccountId(currentName);
|
|
343
343
|
let accountConfigToRename = null;
|
|
@@ -345,9 +345,9 @@ class CLIConfiguration {
|
|
|
345
345
|
accountConfigToRename = this.getAccount(accountId);
|
|
346
346
|
}
|
|
347
347
|
if (!accountConfigToRename) {
|
|
348
|
-
(0,
|
|
348
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.renameAccount.errors.invalidName`, {
|
|
349
349
|
currentName,
|
|
350
|
-
});
|
|
350
|
+
}));
|
|
351
351
|
}
|
|
352
352
|
if (accountId) {
|
|
353
353
|
this.updateAccount({ accountId, name: newName, env: this.getEnv() });
|
|
@@ -362,11 +362,13 @@ class CLIConfiguration {
|
|
|
362
362
|
*/
|
|
363
363
|
removeAccountFromConfig(nameOrId) {
|
|
364
364
|
if (!this.config) {
|
|
365
|
-
(0,
|
|
365
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
366
366
|
}
|
|
367
367
|
const accountId = this.getAccountId(nameOrId);
|
|
368
368
|
if (!accountId) {
|
|
369
|
-
(0,
|
|
369
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, {
|
|
370
|
+
nameOrId,
|
|
371
|
+
}));
|
|
370
372
|
}
|
|
371
373
|
let removedAccountIsDefault = false;
|
|
372
374
|
const accountConfig = this.getAccount(accountId);
|
|
@@ -386,14 +388,14 @@ class CLIConfiguration {
|
|
|
386
388
|
*/
|
|
387
389
|
updateDefaultMode(defaultMode) {
|
|
388
390
|
if (!this.config) {
|
|
389
|
-
(0,
|
|
391
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
390
392
|
}
|
|
391
393
|
const ALL_MODES = Object.values(files_1.MODE);
|
|
392
394
|
if (!defaultMode || !ALL_MODES.find(m => m === defaultMode)) {
|
|
393
|
-
(0,
|
|
395
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultMode.errors.invalidMode`, {
|
|
394
396
|
defaultMode,
|
|
395
397
|
validModes: (0, text_1.commaSeparatedValues)(ALL_MODES),
|
|
396
|
-
});
|
|
398
|
+
}));
|
|
397
399
|
}
|
|
398
400
|
this.config.defaultMode = defaultMode;
|
|
399
401
|
return this.write();
|
|
@@ -403,14 +405,14 @@ class CLIConfiguration {
|
|
|
403
405
|
*/
|
|
404
406
|
updateHttpTimeout(timeout) {
|
|
405
407
|
if (!this.config) {
|
|
406
|
-
(0,
|
|
408
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
407
409
|
}
|
|
408
410
|
const parsedTimeout = parseInt(timeout);
|
|
409
411
|
if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
|
|
410
|
-
(0,
|
|
412
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
|
|
411
413
|
timeout,
|
|
412
414
|
minTimeout: config_1.MIN_HTTP_TIMEOUT,
|
|
413
|
-
});
|
|
415
|
+
}));
|
|
414
416
|
}
|
|
415
417
|
this.config.httpTimeout = parsedTimeout;
|
|
416
418
|
return this.write();
|
|
@@ -420,12 +422,12 @@ class CLIConfiguration {
|
|
|
420
422
|
*/
|
|
421
423
|
updateAllowUsageTracking(isEnabled) {
|
|
422
424
|
if (!this.config) {
|
|
423
|
-
(0,
|
|
425
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
424
426
|
}
|
|
425
427
|
if (typeof isEnabled !== 'boolean') {
|
|
426
|
-
(0,
|
|
428
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
|
|
427
429
|
isEnabled: `${isEnabled}`,
|
|
428
|
-
});
|
|
430
|
+
}));
|
|
429
431
|
}
|
|
430
432
|
this.config.allowUsageTracking = isEnabled;
|
|
431
433
|
return this.write();
|
|
@@ -437,4 +439,4 @@ class CLIConfiguration {
|
|
|
437
439
|
return this.config.allowUsageTracking !== false;
|
|
438
440
|
}
|
|
439
441
|
}
|
|
440
|
-
exports.
|
|
442
|
+
exports.CLIConfiguration = new _CLIConfiguration();
|
package/config/configFile.js
CHANGED
|
@@ -9,11 +9,10 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const os_1 = __importDefault(require("os"));
|
|
10
10
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
11
11
|
const logger_1 = require("../lib/logger");
|
|
12
|
-
const fileSystemErrors_1 = require("../errors/fileSystemErrors");
|
|
13
|
-
const standardErrors_1 = require("../errors/standardErrors");
|
|
14
12
|
const config_1 = require("../constants/config");
|
|
15
13
|
const configUtils_1 = require("./configUtils");
|
|
16
14
|
const lang_1 = require("../utils/lang");
|
|
15
|
+
const FileSystemError_1 = require("../models/FileSystemError");
|
|
17
16
|
const i18nKey = 'config.configFile';
|
|
18
17
|
function getConfigFilePath() {
|
|
19
18
|
return path_1.default.join(os_1.default.homedir(), config_1.HUBSPOT_CONFIGURATION_FOLDER, config_1.HUBSPOT_CONFIGURATION_FILE);
|
|
@@ -44,9 +43,9 @@ function readConfigFile(configPath) {
|
|
|
44
43
|
}
|
|
45
44
|
catch (err) {
|
|
46
45
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorReading`, { configPath }));
|
|
47
|
-
|
|
46
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
48
47
|
filepath: configPath,
|
|
49
|
-
|
|
48
|
+
operation: 'read',
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
return source;
|
|
@@ -61,7 +60,7 @@ function parseConfig(configSource) {
|
|
|
61
60
|
parsed = js_yaml_1.default.load(configSource);
|
|
62
61
|
}
|
|
63
62
|
catch (err) {
|
|
64
|
-
(0,
|
|
63
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.parsing`), { cause: err });
|
|
65
64
|
}
|
|
66
65
|
return parsed;
|
|
67
66
|
}
|
|
@@ -86,13 +85,7 @@ exports.loadConfigFromFile = loadConfigFromFile;
|
|
|
86
85
|
* @throws {Error}
|
|
87
86
|
*/
|
|
88
87
|
function writeConfigToFile(config) {
|
|
89
|
-
|
|
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
|
-
}
|
|
88
|
+
const source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
|
|
96
89
|
const configPath = getConfigFilePath();
|
|
97
90
|
try {
|
|
98
91
|
fs_extra_1.default.ensureFileSync(configPath);
|
|
@@ -100,9 +93,9 @@ function writeConfigToFile(config) {
|
|
|
100
93
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.writeSuccess`, { configPath }));
|
|
101
94
|
}
|
|
102
95
|
catch (err) {
|
|
103
|
-
|
|
96
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
104
97
|
filepath: configPath,
|
|
105
|
-
|
|
98
|
+
operation: 'write',
|
|
106
99
|
});
|
|
107
100
|
}
|
|
108
101
|
}
|
|
@@ -175,7 +175,7 @@ function writeConfig(options = {}) {
|
|
|
175
175
|
catch (err) {
|
|
176
176
|
(0, errors_DEPRECATED_1.logFileSystemErrorInstance)(err, {
|
|
177
177
|
filepath: configPath || '',
|
|
178
|
-
|
|
178
|
+
operation: 'write',
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -193,7 +193,10 @@ function readConfigFile() {
|
|
|
193
193
|
catch (err) {
|
|
194
194
|
error = err;
|
|
195
195
|
logger_1.logger.error('Config file could not be read "%s"', _configPath);
|
|
196
|
-
(0, errors_DEPRECATED_1.logFileSystemErrorInstance)(error, {
|
|
196
|
+
(0, errors_DEPRECATED_1.logFileSystemErrorInstance)(error, {
|
|
197
|
+
filepath: _configPath,
|
|
198
|
+
operation: 'read',
|
|
199
|
+
});
|
|
197
200
|
}
|
|
198
201
|
return { source: source && source.toString(), error };
|
|
199
202
|
}
|
package/config/index.js
CHANGED
|
@@ -22,48 +22,45 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
26
|
exports.updateDefaultMode = exports.findConfig = exports.setConfigPath = exports.setConfig = exports.getOrderedConfig = exports.getOrderedAccount = exports.getConfigAccountId = exports.getConfigDefaultAccount = exports.getConfigAccounts = exports.getAccountType = exports.getEnv = exports.isTrackingAllowed = exports.isConfigFlagEnabled = exports.deleteConfigFile = exports.updateAllowUsageTracking = exports.updateHttpTimeout = exports.deleteAccount = exports.removeSandboxAccountFromConfig = exports.getAccountId = exports.renameAccount = exports.updateDefaultAccount = exports.updateAccountConfig = exports.accountNameExistsInConfig = exports.getAccountConfig = exports.getConfigPath = exports.writeConfig = exports.getConfig = exports.deleteEmptyConfigFile = exports.createEmptyConfigFile = exports.loadConfigFromEnvironment = exports.validateConfig = exports.getAndLoadConfigIfNeeded = exports.loadConfig = void 0;
|
|
30
27
|
const config_DEPRECATED = __importStar(require("./config_DEPRECATED"));
|
|
31
|
-
const CLIConfiguration_1 =
|
|
28
|
+
const CLIConfiguration_1 = require("./CLIConfiguration");
|
|
32
29
|
const configFile_1 = require("./configFile");
|
|
33
30
|
const getAccountIdentifier_1 = require("../utils/getAccountIdentifier");
|
|
34
31
|
// Use new config if it exists
|
|
35
32
|
function loadConfig(path, options = {}) {
|
|
36
33
|
// Attempt to load the root config
|
|
37
34
|
if ((0, configFile_1.configFileExists)()) {
|
|
38
|
-
return CLIConfiguration_1.
|
|
35
|
+
return CLIConfiguration_1.CLIConfiguration.init(options);
|
|
39
36
|
}
|
|
40
37
|
return config_DEPRECATED.loadConfig(path, options);
|
|
41
38
|
}
|
|
42
39
|
exports.loadConfig = loadConfig;
|
|
43
40
|
function getAndLoadConfigIfNeeded(options) {
|
|
44
|
-
if (CLIConfiguration_1.
|
|
45
|
-
return CLIConfiguration_1.
|
|
41
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
42
|
+
return CLIConfiguration_1.CLIConfiguration.config;
|
|
46
43
|
}
|
|
47
44
|
return config_DEPRECATED.getAndLoadConfigIfNeeded(options);
|
|
48
45
|
}
|
|
49
46
|
exports.getAndLoadConfigIfNeeded = getAndLoadConfigIfNeeded;
|
|
50
47
|
function validateConfig() {
|
|
51
|
-
if (CLIConfiguration_1.
|
|
52
|
-
return CLIConfiguration_1.
|
|
48
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
49
|
+
return CLIConfiguration_1.CLIConfiguration.validate();
|
|
53
50
|
}
|
|
54
51
|
return config_DEPRECATED.validateConfig();
|
|
55
52
|
}
|
|
56
53
|
exports.validateConfig = validateConfig;
|
|
57
54
|
function loadConfigFromEnvironment() {
|
|
58
|
-
if (CLIConfiguration_1.
|
|
59
|
-
return CLIConfiguration_1.
|
|
55
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
56
|
+
return CLIConfiguration_1.CLIConfiguration.useEnvConfig;
|
|
60
57
|
}
|
|
61
58
|
return Boolean(config_DEPRECATED.loadConfigFromEnvironment());
|
|
62
59
|
}
|
|
63
60
|
exports.loadConfigFromEnvironment = loadConfigFromEnvironment;
|
|
64
61
|
function createEmptyConfigFile(options = {}, useRootConfig = false) {
|
|
65
62
|
if (useRootConfig) {
|
|
66
|
-
CLIConfiguration_1.
|
|
63
|
+
CLIConfiguration_1.CLIConfiguration.write({ accounts: [] });
|
|
67
64
|
}
|
|
68
65
|
else {
|
|
69
66
|
return config_DEPRECATED.createEmptyConfigFile(options);
|
|
@@ -71,25 +68,25 @@ function createEmptyConfigFile(options = {}, useRootConfig = false) {
|
|
|
71
68
|
}
|
|
72
69
|
exports.createEmptyConfigFile = createEmptyConfigFile;
|
|
73
70
|
function deleteEmptyConfigFile() {
|
|
74
|
-
if (CLIConfiguration_1.
|
|
75
|
-
return CLIConfiguration_1.
|
|
71
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
72
|
+
return CLIConfiguration_1.CLIConfiguration.delete();
|
|
76
73
|
}
|
|
77
74
|
return config_DEPRECATED.deleteEmptyConfigFile();
|
|
78
75
|
}
|
|
79
76
|
exports.deleteEmptyConfigFile = deleteEmptyConfigFile;
|
|
80
77
|
function getConfig() {
|
|
81
|
-
if (CLIConfiguration_1.
|
|
82
|
-
return CLIConfiguration_1.
|
|
78
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
79
|
+
return CLIConfiguration_1.CLIConfiguration.config;
|
|
83
80
|
}
|
|
84
81
|
return config_DEPRECATED.getConfig();
|
|
85
82
|
}
|
|
86
83
|
exports.getConfig = getConfig;
|
|
87
84
|
function writeConfig(options = {}) {
|
|
88
|
-
if (CLIConfiguration_1.
|
|
85
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
89
86
|
const config = options.source
|
|
90
87
|
? JSON.parse(options.source)
|
|
91
88
|
: undefined;
|
|
92
|
-
CLIConfiguration_1.
|
|
89
|
+
CLIConfiguration_1.CLIConfiguration.write(config);
|
|
93
90
|
}
|
|
94
91
|
else {
|
|
95
92
|
config_DEPRECATED.writeConfig(options);
|
|
@@ -97,30 +94,30 @@ function writeConfig(options = {}) {
|
|
|
97
94
|
}
|
|
98
95
|
exports.writeConfig = writeConfig;
|
|
99
96
|
function getConfigPath(path) {
|
|
100
|
-
if (CLIConfiguration_1.
|
|
97
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
101
98
|
return (0, configFile_1.getConfigFilePath)();
|
|
102
99
|
}
|
|
103
100
|
return config_DEPRECATED.getConfigPath(path);
|
|
104
101
|
}
|
|
105
102
|
exports.getConfigPath = getConfigPath;
|
|
106
103
|
function getAccountConfig(accountId) {
|
|
107
|
-
if (CLIConfiguration_1.
|
|
108
|
-
return CLIConfiguration_1.
|
|
104
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
105
|
+
return CLIConfiguration_1.CLIConfiguration.getConfigForAccount(accountId);
|
|
109
106
|
}
|
|
110
107
|
return config_DEPRECATED.getAccountConfig(accountId) || null;
|
|
111
108
|
}
|
|
112
109
|
exports.getAccountConfig = getAccountConfig;
|
|
113
110
|
function accountNameExistsInConfig(name) {
|
|
114
|
-
if (CLIConfiguration_1.
|
|
115
|
-
return CLIConfiguration_1.
|
|
111
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
112
|
+
return CLIConfiguration_1.CLIConfiguration.isAccountInConfig(name);
|
|
116
113
|
}
|
|
117
114
|
return config_DEPRECATED.accountNameExistsInConfig(name);
|
|
118
115
|
}
|
|
119
116
|
exports.accountNameExistsInConfig = accountNameExistsInConfig;
|
|
120
117
|
function updateAccountConfig(configOptions) {
|
|
121
118
|
const accountIdentifier = (0, getAccountIdentifier_1.getAccountIdentifier)(configOptions);
|
|
122
|
-
if (CLIConfiguration_1.
|
|
123
|
-
return CLIConfiguration_1.
|
|
119
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
120
|
+
return CLIConfiguration_1.CLIConfiguration.updateAccount({
|
|
124
121
|
...configOptions,
|
|
125
122
|
accountId: accountIdentifier,
|
|
126
123
|
});
|
|
@@ -132,8 +129,8 @@ function updateAccountConfig(configOptions) {
|
|
|
132
129
|
}
|
|
133
130
|
exports.updateAccountConfig = updateAccountConfig;
|
|
134
131
|
function updateDefaultAccount(nameOrId) {
|
|
135
|
-
if (CLIConfiguration_1.
|
|
136
|
-
CLIConfiguration_1.
|
|
132
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
133
|
+
CLIConfiguration_1.CLIConfiguration.updateDefaultAccount(nameOrId);
|
|
137
134
|
}
|
|
138
135
|
else {
|
|
139
136
|
config_DEPRECATED.updateDefaultAccount(nameOrId);
|
|
@@ -141,8 +138,8 @@ function updateDefaultAccount(nameOrId) {
|
|
|
141
138
|
}
|
|
142
139
|
exports.updateDefaultAccount = updateDefaultAccount;
|
|
143
140
|
async function renameAccount(currentName, newName) {
|
|
144
|
-
if (CLIConfiguration_1.
|
|
145
|
-
CLIConfiguration_1.
|
|
141
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
142
|
+
CLIConfiguration_1.CLIConfiguration.renameAccount(currentName, newName);
|
|
146
143
|
}
|
|
147
144
|
else {
|
|
148
145
|
config_DEPRECATED.renameAccount(currentName, newName);
|
|
@@ -150,22 +147,22 @@ async function renameAccount(currentName, newName) {
|
|
|
150
147
|
}
|
|
151
148
|
exports.renameAccount = renameAccount;
|
|
152
149
|
function getAccountId(nameOrId) {
|
|
153
|
-
if (CLIConfiguration_1.
|
|
154
|
-
return CLIConfiguration_1.
|
|
150
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
151
|
+
return CLIConfiguration_1.CLIConfiguration.getAccountId(nameOrId);
|
|
155
152
|
}
|
|
156
153
|
return config_DEPRECATED.getAccountId(nameOrId) || null;
|
|
157
154
|
}
|
|
158
155
|
exports.getAccountId = getAccountId;
|
|
159
156
|
function removeSandboxAccountFromConfig(nameOrId) {
|
|
160
|
-
if (CLIConfiguration_1.
|
|
161
|
-
return CLIConfiguration_1.
|
|
157
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
158
|
+
return CLIConfiguration_1.CLIConfiguration.removeAccountFromConfig(nameOrId);
|
|
162
159
|
}
|
|
163
160
|
return config_DEPRECATED.removeSandboxAccountFromConfig(nameOrId);
|
|
164
161
|
}
|
|
165
162
|
exports.removeSandboxAccountFromConfig = removeSandboxAccountFromConfig;
|
|
166
163
|
async function deleteAccount(accountName) {
|
|
167
|
-
if (CLIConfiguration_1.
|
|
168
|
-
CLIConfiguration_1.
|
|
164
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
165
|
+
CLIConfiguration_1.CLIConfiguration.removeAccountFromConfig(accountName);
|
|
169
166
|
}
|
|
170
167
|
else {
|
|
171
168
|
config_DEPRECATED.deleteAccount(accountName);
|
|
@@ -173,8 +170,8 @@ async function deleteAccount(accountName) {
|
|
|
173
170
|
}
|
|
174
171
|
exports.deleteAccount = deleteAccount;
|
|
175
172
|
function updateHttpTimeout(timeout) {
|
|
176
|
-
if (CLIConfiguration_1.
|
|
177
|
-
CLIConfiguration_1.
|
|
173
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
174
|
+
CLIConfiguration_1.CLIConfiguration.updateHttpTimeout(timeout);
|
|
178
175
|
}
|
|
179
176
|
else {
|
|
180
177
|
config_DEPRECATED.updateHttpTimeout(timeout);
|
|
@@ -182,8 +179,8 @@ function updateHttpTimeout(timeout) {
|
|
|
182
179
|
}
|
|
183
180
|
exports.updateHttpTimeout = updateHttpTimeout;
|
|
184
181
|
function updateAllowUsageTracking(isEnabled) {
|
|
185
|
-
if (CLIConfiguration_1.
|
|
186
|
-
CLIConfiguration_1.
|
|
182
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
183
|
+
CLIConfiguration_1.CLIConfiguration.updateAllowUsageTracking(isEnabled);
|
|
187
184
|
}
|
|
188
185
|
else {
|
|
189
186
|
config_DEPRECATED.updateAllowUsageTracking(isEnabled);
|
|
@@ -191,7 +188,7 @@ function updateAllowUsageTracking(isEnabled) {
|
|
|
191
188
|
}
|
|
192
189
|
exports.updateAllowUsageTracking = updateAllowUsageTracking;
|
|
193
190
|
function deleteConfigFile() {
|
|
194
|
-
if (CLIConfiguration_1.
|
|
191
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
195
192
|
(0, configFile_1.deleteConfigFile)();
|
|
196
193
|
}
|
|
197
194
|
else {
|
|
@@ -200,29 +197,29 @@ function deleteConfigFile() {
|
|
|
200
197
|
}
|
|
201
198
|
exports.deleteConfigFile = deleteConfigFile;
|
|
202
199
|
function isConfigFlagEnabled(flag) {
|
|
203
|
-
if (CLIConfiguration_1.
|
|
204
|
-
return CLIConfiguration_1.
|
|
200
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
201
|
+
return CLIConfiguration_1.CLIConfiguration.isConfigFlagEnabled(flag);
|
|
205
202
|
}
|
|
206
203
|
return config_DEPRECATED.isConfigFlagEnabled(flag);
|
|
207
204
|
}
|
|
208
205
|
exports.isConfigFlagEnabled = isConfigFlagEnabled;
|
|
209
206
|
function isTrackingAllowed() {
|
|
210
|
-
if (CLIConfiguration_1.
|
|
211
|
-
return CLIConfiguration_1.
|
|
207
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
208
|
+
return CLIConfiguration_1.CLIConfiguration.isTrackingAllowed();
|
|
212
209
|
}
|
|
213
210
|
return config_DEPRECATED.isTrackingAllowed();
|
|
214
211
|
}
|
|
215
212
|
exports.isTrackingAllowed = isTrackingAllowed;
|
|
216
213
|
function getEnv(nameOrId) {
|
|
217
|
-
if (CLIConfiguration_1.
|
|
218
|
-
return CLIConfiguration_1.
|
|
214
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
215
|
+
return CLIConfiguration_1.CLIConfiguration.getEnv(nameOrId);
|
|
219
216
|
}
|
|
220
217
|
return config_DEPRECATED.getEnv(nameOrId);
|
|
221
218
|
}
|
|
222
219
|
exports.getEnv = getEnv;
|
|
223
220
|
function getAccountType(accountType, sandboxAccountType) {
|
|
224
|
-
if (CLIConfiguration_1.
|
|
225
|
-
return CLIConfiguration_1.
|
|
221
|
+
if (CLIConfiguration_1.CLIConfiguration.isActive()) {
|
|
222
|
+
return CLIConfiguration_1.CLIConfiguration.getAccountType(accountType, sandboxAccountType);
|
|
226
223
|
}
|
|
227
224
|
return config_DEPRECATED.getAccountType(accountType, sandboxAccountType);
|
|
228
225
|
}
|
|
@@ -37,10 +37,10 @@ function logErrorInstance(error, context) {
|
|
|
37
37
|
exports.logErrorInstance = logErrorInstance;
|
|
38
38
|
function logFileSystemErrorInstance(error, context) {
|
|
39
39
|
let fileAction = '';
|
|
40
|
-
if (context.read) {
|
|
40
|
+
if (context.operation === 'read') {
|
|
41
41
|
fileAction = 'reading from';
|
|
42
42
|
}
|
|
43
|
-
else if (context.write) {
|
|
43
|
+
else if (context.operation === 'write') {
|
|
44
44
|
fileAction = 'writing to';
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HubSpotHttpError } from '../models/HubSpotHttpError';
|
|
2
|
+
import { BaseError } from '../types/Error';
|
|
3
|
+
import { FileSystemError } from '../models/FileSystemError';
|
|
4
|
+
export declare function isSpecifiedError(err: unknown, { statusCode, category, subCategory, errorType, code, }: {
|
|
5
|
+
statusCode?: number;
|
|
6
|
+
category?: string;
|
|
7
|
+
subCategory?: string;
|
|
8
|
+
errorType?: string;
|
|
9
|
+
code?: string;
|
|
10
|
+
}): err is HubSpotHttpError;
|
|
11
|
+
export declare function isMissingScopeError(err: unknown): err is HubSpotHttpError;
|
|
12
|
+
export declare function isGatingError(err: unknown): err is HubSpotHttpError;
|
|
13
|
+
export declare function isTimeoutError(err: unknown): err is HubSpotHttpError;
|
|
14
|
+
export declare function isAuthError(err: unknown): err is HubSpotHttpError;
|
|
15
|
+
export declare function isValidationError(err: unknown): boolean;
|
|
16
|
+
export declare function isHubSpotHttpError(error?: unknown): error is HubSpotHttpError;
|
|
17
|
+
export declare function isSystemError(err: unknown): err is BaseError;
|
|
18
|
+
export declare function isFileSystemError(err: unknown): err is FileSystemError;
|