@hubspot/local-dev-lib 0.0.1-experimental.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +12 -0
- package/README.md +17 -0
- package/api/appsDev.d.ts +6 -0
- package/api/appsDev.js +29 -0
- package/api/customObjects.d.ts +8 -0
- package/api/customObjects.js +45 -0
- package/api/designManager.d.ts +5 -0
- package/api/designManager.js +18 -0
- package/api/developerTestAccounts.d.ts +7 -0
- package/api/developerTestAccounts.js +48 -0
- package/api/fileManager.d.ts +6 -0
- package/api/fileManager.js +63 -0
- package/api/fileMapper.d.ts +12 -0
- package/api/fileMapper.js +106 -0
- package/api/fileTransport.d.ts +4 -0
- package/api/fileTransport.js +39 -0
- package/api/functions.d.ts +8 -0
- package/api/functions.js +43 -0
- package/api/github.d.ts +11 -0
- package/api/github.js +71 -0
- package/api/hubdb.d.ts +12 -0
- package/api/hubdb.js +67 -0
- package/api/lighthouseScore.d.ts +6 -0
- package/api/lighthouseScore.js +26 -0
- package/api/localDevAuth.d.ts +8 -0
- package/api/localDevAuth.js +53 -0
- package/api/marketplaceValidation.d.ts +6 -0
- package/api/marketplaceValidation.js +26 -0
- package/api/projects.d.ts +40 -0
- package/api/projects.js +216 -0
- package/api/sandboxHubs.d.ts +7 -0
- package/api/sandboxHubs.js +49 -0
- package/api/sandboxSync.d.ts +4 -0
- package/api/sandboxSync.js +26 -0
- package/api/secrets.d.ts +6 -0
- package/api/secrets.js +37 -0
- package/api/validateHubl.d.ts +3 -0
- package/api/validateHubl.js +15 -0
- package/config/CLIConfiguration.d.ts +62 -0
- package/config/CLIConfiguration.js +467 -0
- package/config/configFile.d.ts +21 -0
- package/config/configFile.js +102 -0
- package/config/configUtils.d.ts +5 -0
- package/config/configUtils.js +87 -0
- package/config/config_DEPRECATED.d.ts +75 -0
- package/config/config_DEPRECATED.js +678 -0
- package/config/environment.d.ts +2 -0
- package/config/environment.js +60 -0
- package/config/getAccountIdentifier.d.ts +2 -0
- package/config/getAccountIdentifier.js +15 -0
- package/config/index.d.ts +41 -0
- package/config/index.js +260 -0
- package/constants/api.d.ts +15 -0
- package/constants/api.js +18 -0
- package/constants/auth.d.ts +37 -0
- package/constants/auth.js +38 -0
- package/constants/config.d.ts +18 -0
- package/constants/config.js +22 -0
- package/constants/environments.d.ts +15 -0
- package/constants/environments.js +18 -0
- package/constants/extensions.d.ts +6 -0
- package/constants/extensions.js +28 -0
- package/constants/files.d.ts +21 -0
- package/constants/files.js +24 -0
- package/constants/ports.d.ts +3 -0
- package/constants/ports.js +6 -0
- package/enums/build.d.ts +36 -0
- package/enums/build.js +39 -0
- package/enums/deploy.d.ts +11 -0
- package/enums/deploy.js +14 -0
- package/enums/project.d.ts +6 -0
- package/enums/project.js +9 -0
- package/errors/errors_DEPRECATED.d.ts +3 -0
- package/errors/errors_DEPRECATED.js +60 -0
- 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 +9 -0
- package/http/getAxiosConfig.js +66 -0
- package/http/index.d.ts +17 -0
- package/http/index.js +173 -0
- package/http/unauthed.d.ts +15 -0
- package/http/unauthed.js +38 -0
- package/lang/en.json +389 -0
- package/lib/archive.d.ts +3 -0
- package/lib/archive.js +117 -0
- package/lib/cms/functions.d.ts +8 -0
- package/lib/cms/functions.js +181 -0
- package/lib/cms/handleFieldsJS.d.ts +33 -0
- package/lib/cms/handleFieldsJS.js +148 -0
- package/lib/cms/modules.d.ts +14 -0
- package/lib/cms/modules.js +186 -0
- package/lib/cms/processFieldsJs.d.ts +1 -0
- package/lib/cms/processFieldsJs.js +97 -0
- package/lib/cms/templates.d.ts +65 -0
- package/lib/cms/templates.js +107 -0
- package/lib/cms/themes.d.ts +2 -0
- package/lib/cms/themes.js +34 -0
- package/lib/cms/uploadFolder.d.ts +7 -0
- package/lib/cms/uploadFolder.js +202 -0
- package/lib/cms/validate.d.ts +2 -0
- package/lib/cms/validate.js +40 -0
- package/lib/cms/watch.d.ts +4 -0
- package/lib/cms/watch.js +201 -0
- package/lib/customObjects.d.ts +5 -0
- package/lib/customObjects.js +42 -0
- package/lib/environment.d.ts +2 -0
- package/lib/environment.js +16 -0
- package/lib/escapeRegExp.d.ts +1 -0
- package/lib/escapeRegExp.js +7 -0
- package/lib/fileManager.d.ts +2 -0
- package/lib/fileManager.js +184 -0
- package/lib/fileMapper.d.ts +18 -0
- package/lib/fileMapper.js +317 -0
- package/lib/fs.d.ts +4 -0
- package/lib/fs.js +71 -0
- package/lib/github.d.ts +8 -0
- package/lib/github.js +167 -0
- package/lib/gitignore.d.ts +3 -0
- package/lib/gitignore.js +49 -0
- package/lib/hubdb.d.ts +17 -0
- package/lib/hubdb.js +133 -0
- package/lib/ignoreRules.d.ts +3 -0
- package/lib/ignoreRules.js +69 -0
- package/lib/logger.d.ts +56 -0
- package/lib/logger.js +146 -0
- package/lib/notify.d.ts +1 -0
- package/lib/notify.js +43 -0
- package/lib/oauth.d.ts +4 -0
- package/lib/oauth.js +34 -0
- package/lib/path.d.ts +14 -0
- package/lib/path.js +134 -0
- package/lib/personalAccessKey.d.ts +10 -0
- package/lib/personalAccessKey.js +163 -0
- package/lib/portManager.d.ts +10 -0
- package/lib/portManager.js +46 -0
- package/lib/text.d.ts +2 -0
- package/lib/text.js +24 -0
- package/lib/trackUsage.d.ts +1 -0
- package/lib/trackUsage.js +63 -0
- package/lib/urls.d.ts +2 -0
- package/lib/urls.js +24 -0
- 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 +12 -0
- package/models/OAuth2Manager.js +105 -0
- package/package.json +81 -0
- package/types/Accounts.d.ts +178 -0
- package/types/Accounts.js +2 -0
- package/types/Activity.d.ts +20 -0
- package/types/Activity.js +2 -0
- package/types/Api.d.ts +2 -0
- package/types/Api.js +2 -0
- package/types/Apps.d.ts +77 -0
- package/types/Apps.js +2 -0
- package/types/Archive.d.ts +9 -0
- package/types/Archive.js +2 -0
- package/types/Build.d.ts +41 -0
- package/types/Build.js +2 -0
- package/types/CLIOptions.d.ts +8 -0
- package/types/CLIOptions.js +2 -0
- package/types/ComponentStructure.d.ts +40 -0
- package/types/ComponentStructure.js +2 -0
- package/types/Config.d.ts +37 -0
- package/types/Config.js +2 -0
- package/types/Deploy.d.ts +42 -0
- package/types/Deploy.js +2 -0
- package/types/DesignManager.d.ts +10 -0
- package/types/DesignManager.js +2 -0
- package/types/Error.d.ts +37 -0
- package/types/Error.js +2 -0
- package/types/FieldsJS.d.ts +1 -0
- package/types/FieldsJS.js +2 -0
- package/types/FileManager.d.ts +71 -0
- package/types/FileManager.js +2 -0
- package/types/Files.d.ts +79 -0
- package/types/Files.js +2 -0
- package/types/Functions.d.ts +66 -0
- package/types/Functions.js +2 -0
- package/types/Github.d.ts +76 -0
- package/types/Github.js +2 -0
- package/types/Http.d.ts +29 -0
- package/types/Http.js +2 -0
- package/types/Hubdb.d.ts +109 -0
- package/types/Hubdb.js +2 -0
- package/types/HublValidation.d.ts +59 -0
- package/types/HublValidation.js +2 -0
- package/types/Lang.d.ts +10 -0
- package/types/Lang.js +2 -0
- package/types/Lighthouse.d.ts +25 -0
- package/types/Lighthouse.js +2 -0
- package/types/MarketplaceValidation.d.ts +28 -0
- package/types/MarketplaceValidation.js +2 -0
- package/types/Migration.d.ts +28 -0
- package/types/Migration.js +10 -0
- package/types/Modules.d.ts +16 -0
- package/types/Modules.js +2 -0
- package/types/PortManager.d.ts +11 -0
- package/types/PortManager.js +2 -0
- package/types/Project.d.ts +42 -0
- package/types/Project.js +2 -0
- package/types/ProjectLog.d.ts +9 -0
- package/types/ProjectLog.js +2 -0
- package/types/Sandbox.d.ts +155 -0
- package/types/Sandbox.js +2 -0
- package/types/Schemas.d.ts +39 -0
- package/types/Schemas.js +2 -0
- package/types/Secrets.d.ts +3 -0
- package/types/Secrets.js +2 -0
- package/types/Utils.d.ts +6 -0
- package/types/Utils.js +2 -0
- package/types/developerTestAccounts.d.ts +12 -0
- package/types/developerTestAccounts.js +2 -0
- package/utils/PortManagerServer.d.ts +26 -0
- package/utils/PortManagerServer.js +158 -0
- package/utils/accounts.d.ts +4 -0
- package/utils/accounts.js +28 -0
- package/utils/cms/fieldsJS.d.ts +2 -0
- package/utils/cms/fieldsJS.js +18 -0
- package/utils/cms/modules.d.ts +4 -0
- package/utils/cms/modules.js +54 -0
- package/utils/detectPort.d.ts +1 -0
- package/utils/detectPort.js +102 -0
- package/utils/git.d.ts +3 -0
- package/utils/git.js +71 -0
- package/utils/lang.d.ts +6 -0
- package/utils/lang.js +88 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CLIConfig_NEW, Environment } from '../types/Config';
|
|
2
|
+
import { CLIAccount_NEW, FlatAccountFields_NEW, AccountType } from '../types/Accounts';
|
|
3
|
+
import { CLIOptions } from '../types/CLIOptions';
|
|
4
|
+
declare class _CLIConfiguration {
|
|
5
|
+
options: CLIOptions;
|
|
6
|
+
useEnvConfig: boolean;
|
|
7
|
+
config: CLIConfig_NEW | null;
|
|
8
|
+
active: boolean;
|
|
9
|
+
constructor();
|
|
10
|
+
setActive(isActive: boolean): void;
|
|
11
|
+
isActive(): boolean;
|
|
12
|
+
init(options?: CLIOptions): CLIConfig_NEW | null;
|
|
13
|
+
load(): CLIConfig_NEW | null;
|
|
14
|
+
configIsEmpty(): boolean;
|
|
15
|
+
delete(): void;
|
|
16
|
+
write(updatedConfig?: CLIConfig_NEW): CLIConfig_NEW | null;
|
|
17
|
+
validate(): boolean;
|
|
18
|
+
getAccount(nameOrId: string | number | undefined): CLIAccount_NEW | null;
|
|
19
|
+
isConfigFlagEnabled(flag: keyof CLIConfig_NEW, defaultValue?: boolean): boolean;
|
|
20
|
+
getAccountId(nameOrId?: string | number): number | null;
|
|
21
|
+
getDefaultAccount(): string | number | null;
|
|
22
|
+
getResolvedDefaultAccountForCWD(nameOrId: string | number): CLIAccount_NEW | null;
|
|
23
|
+
getAccountIndex(accountId: number): number;
|
|
24
|
+
getConfigForAccount(accountId?: number): CLIAccount_NEW | null;
|
|
25
|
+
getConfigAccounts(): Array<CLIAccount_NEW> | null;
|
|
26
|
+
isAccountInConfig(nameOrId: string | number): boolean;
|
|
27
|
+
getAndLoadConfigIfNeeded(options?: CLIOptions): CLIConfig_NEW;
|
|
28
|
+
getEnv(nameOrId?: string | number): Environment;
|
|
29
|
+
getAccountType(accountType?: AccountType | null, sandboxAccountType?: string | null): AccountType;
|
|
30
|
+
/**
|
|
31
|
+
* @throws {Error}
|
|
32
|
+
*/
|
|
33
|
+
addOrUpdateAccount(updatedAccountFields: Partial<FlatAccountFields_NEW>, writeUpdate?: boolean): FlatAccountFields_NEW | null;
|
|
34
|
+
/**
|
|
35
|
+
* @throws {Error}
|
|
36
|
+
*/
|
|
37
|
+
updateDefaultAccount(defaultAccount: string | number): CLIConfig_NEW | null;
|
|
38
|
+
/**
|
|
39
|
+
* @throws {Error}
|
|
40
|
+
*/
|
|
41
|
+
renameAccount(currentName: string, newName: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* @throws {Error}
|
|
44
|
+
* TODO: this does not account for the special handling of sandbox account deletes
|
|
45
|
+
*/
|
|
46
|
+
removeAccountFromConfig(nameOrId: string | number): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* @throws {Error}
|
|
49
|
+
*/
|
|
50
|
+
updateDefaultMode(defaultMode: string): CLIConfig_NEW | null;
|
|
51
|
+
/**
|
|
52
|
+
* @throws {Error}
|
|
53
|
+
*/
|
|
54
|
+
updateHttpTimeout(timeout: string): CLIConfig_NEW | null;
|
|
55
|
+
/**
|
|
56
|
+
* @throws {Error}
|
|
57
|
+
*/
|
|
58
|
+
updateAllowUsageTracking(isEnabled: boolean): CLIConfig_NEW | null;
|
|
59
|
+
isTrackingAllowed(): boolean;
|
|
60
|
+
}
|
|
61
|
+
export declare const CLIConfiguration: _CLIConfiguration;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLIConfiguration = void 0;
|
|
4
|
+
const logger_1 = require("../lib/logger");
|
|
5
|
+
const environment_1 = require("./environment");
|
|
6
|
+
const environment_2 = require("../lib/environment");
|
|
7
|
+
const configFile_1 = require("./configFile");
|
|
8
|
+
const text_1 = require("../lib/text");
|
|
9
|
+
const environments_1 = require("../constants/environments");
|
|
10
|
+
const auth_1 = require("../constants/auth");
|
|
11
|
+
const config_1 = require("../constants/config");
|
|
12
|
+
const files_1 = require("../constants/files");
|
|
13
|
+
const lang_1 = require("../utils/lang");
|
|
14
|
+
const i18nKey = 'config.cliConfiguration';
|
|
15
|
+
class _CLIConfiguration {
|
|
16
|
+
options;
|
|
17
|
+
useEnvConfig;
|
|
18
|
+
config;
|
|
19
|
+
active;
|
|
20
|
+
constructor() {
|
|
21
|
+
this.options = {};
|
|
22
|
+
this.useEnvConfig = false;
|
|
23
|
+
this.config = null;
|
|
24
|
+
this.active = false;
|
|
25
|
+
}
|
|
26
|
+
setActive(isActive) {
|
|
27
|
+
this.active = isActive;
|
|
28
|
+
}
|
|
29
|
+
isActive() {
|
|
30
|
+
return this.active;
|
|
31
|
+
}
|
|
32
|
+
init(options = {}) {
|
|
33
|
+
this.options = options;
|
|
34
|
+
this.load();
|
|
35
|
+
this.setActive(true);
|
|
36
|
+
return this.config;
|
|
37
|
+
}
|
|
38
|
+
load() {
|
|
39
|
+
if (this.options.useEnv) {
|
|
40
|
+
const configFromEnv = (0, environment_1.loadConfigFromEnvironment)();
|
|
41
|
+
if (configFromEnv) {
|
|
42
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.configFromEnv`, {
|
|
43
|
+
accountId: configFromEnv.accounts[0].accountId,
|
|
44
|
+
}));
|
|
45
|
+
this.useEnvConfig = true;
|
|
46
|
+
this.config = configFromEnv;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const configFromFile = (0, configFile_1.loadConfigFromFile)();
|
|
51
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.configFromFile`));
|
|
52
|
+
if (!configFromFile) {
|
|
53
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.empty`));
|
|
54
|
+
this.config = { accounts: [] };
|
|
55
|
+
}
|
|
56
|
+
this.useEnvConfig = false;
|
|
57
|
+
this.config = configFromFile;
|
|
58
|
+
}
|
|
59
|
+
return this.config;
|
|
60
|
+
}
|
|
61
|
+
configIsEmpty() {
|
|
62
|
+
if (!(0, configFile_1.configFileExists)() || (0, configFile_1.configFileIsBlank)()) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.load();
|
|
67
|
+
if (!!this.config &&
|
|
68
|
+
Object.keys(this.config).length === 1 &&
|
|
69
|
+
!!this.config.accounts) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
delete() {
|
|
76
|
+
if (!this.useEnvConfig && this.configIsEmpty()) {
|
|
77
|
+
(0, configFile_1.deleteConfigFile)();
|
|
78
|
+
this.config = null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
write(updatedConfig) {
|
|
82
|
+
if (!this.useEnvConfig) {
|
|
83
|
+
if (updatedConfig) {
|
|
84
|
+
this.config = updatedConfig;
|
|
85
|
+
}
|
|
86
|
+
if (this.config) {
|
|
87
|
+
(0, configFile_1.writeConfigToFile)(this.config);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return this.config;
|
|
91
|
+
}
|
|
92
|
+
validate() {
|
|
93
|
+
if (!this.config) {
|
|
94
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noConfig`));
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
if (!Array.isArray(this.config.accounts)) {
|
|
98
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noConfigAccounts`));
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
const accountIdsMap = {};
|
|
102
|
+
const accountNamesMap = {};
|
|
103
|
+
return this.config.accounts.every(accountConfig => {
|
|
104
|
+
if (!accountConfig) {
|
|
105
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.emptyAccountConfig`));
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (!accountConfig.accountId) {
|
|
109
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.noAccountId`));
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
if (accountIdsMap[accountConfig.accountId]) {
|
|
113
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.duplicateAccountIds`, {
|
|
114
|
+
accountId: accountConfig.accountId,
|
|
115
|
+
}));
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (accountConfig.name) {
|
|
119
|
+
if (accountNamesMap[accountConfig.name.toLowerCase()]) {
|
|
120
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.duplicateAccountNames`, {
|
|
121
|
+
accountName: accountConfig.name,
|
|
122
|
+
}));
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (/\s+/.test(accountConfig.name)) {
|
|
126
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.validate.nameContainsSpaces`, {
|
|
127
|
+
accountName: accountConfig.name,
|
|
128
|
+
}));
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
accountNamesMap[accountConfig.name] = true;
|
|
132
|
+
}
|
|
133
|
+
if (!accountConfig.accountType) {
|
|
134
|
+
this.addOrUpdateAccount({
|
|
135
|
+
...accountConfig,
|
|
136
|
+
accountId: accountConfig.accountId,
|
|
137
|
+
accountType: this.getAccountType(undefined, accountConfig.sandboxAccountType),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
accountIdsMap[accountConfig.accountId] = true;
|
|
141
|
+
return true;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
getAccount(nameOrId) {
|
|
145
|
+
let name = null;
|
|
146
|
+
let accountId = null;
|
|
147
|
+
if (!this.config) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
const nameOrIdToCheck = nameOrId ? nameOrId : this.getDefaultAccount();
|
|
151
|
+
if (!nameOrIdToCheck) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
if (typeof nameOrIdToCheck === 'number') {
|
|
155
|
+
accountId = nameOrIdToCheck;
|
|
156
|
+
}
|
|
157
|
+
else if (/^\d+$/.test(nameOrIdToCheck)) {
|
|
158
|
+
accountId = parseInt(nameOrIdToCheck, 10);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
name = nameOrIdToCheck;
|
|
162
|
+
}
|
|
163
|
+
if (name) {
|
|
164
|
+
return this.config.accounts.find(a => a.name === name) || null;
|
|
165
|
+
}
|
|
166
|
+
else if (accountId) {
|
|
167
|
+
return this.config.accounts.find(a => accountId === a.accountId) || null;
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
isConfigFlagEnabled(flag, defaultValue = false) {
|
|
172
|
+
if (this.config && typeof this.config[flag] !== 'undefined') {
|
|
173
|
+
return Boolean(this.config[flag]);
|
|
174
|
+
}
|
|
175
|
+
return defaultValue;
|
|
176
|
+
}
|
|
177
|
+
getAccountId(nameOrId) {
|
|
178
|
+
const account = this.getAccount(nameOrId);
|
|
179
|
+
return account ? account.accountId : null;
|
|
180
|
+
}
|
|
181
|
+
getDefaultAccount() {
|
|
182
|
+
return this.config && this.config.defaultAccount
|
|
183
|
+
? this.config.defaultAccount
|
|
184
|
+
: null;
|
|
185
|
+
}
|
|
186
|
+
// TODO a util that returns the account to use, respecting the values set in
|
|
187
|
+
// "defaultAccountOverrides"
|
|
188
|
+
// Example "defaultAccountOverrides":
|
|
189
|
+
// - /src/brodgers/customer-project-1: customer-account1
|
|
190
|
+
// - /src/brodgers/customer-project-2: customer-account2
|
|
191
|
+
// "/src/brodgers/customer-project-1" is the path to the project dir
|
|
192
|
+
// "customer-account1" is the name of the account to use as the default for the specified dir
|
|
193
|
+
// These defaults take precedence over the standard default account specified in the config
|
|
194
|
+
getResolvedDefaultAccountForCWD(nameOrId) {
|
|
195
|
+
return this.getAccount(nameOrId);
|
|
196
|
+
}
|
|
197
|
+
getAccountIndex(accountId) {
|
|
198
|
+
return this.config
|
|
199
|
+
? this.config.accounts.findIndex(account => account.accountId === accountId)
|
|
200
|
+
: -1;
|
|
201
|
+
}
|
|
202
|
+
getConfigForAccount(accountId) {
|
|
203
|
+
if (this.config) {
|
|
204
|
+
return (this.config.accounts.find(account => account.accountId === accountId) ||
|
|
205
|
+
null);
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
getConfigAccounts() {
|
|
210
|
+
if (this.config) {
|
|
211
|
+
return this.config.accounts || null;
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
isAccountInConfig(nameOrId) {
|
|
216
|
+
if (typeof nameOrId === 'string') {
|
|
217
|
+
return (!!this.config &&
|
|
218
|
+
this.config.accounts &&
|
|
219
|
+
!!this.getAccountId(nameOrId.toLowerCase()));
|
|
220
|
+
}
|
|
221
|
+
return (!!this.config && this.config.accounts && !!this.getAccountId(nameOrId));
|
|
222
|
+
}
|
|
223
|
+
getAndLoadConfigIfNeeded(options) {
|
|
224
|
+
if (!this.config) {
|
|
225
|
+
this.init(options);
|
|
226
|
+
}
|
|
227
|
+
return this.config;
|
|
228
|
+
}
|
|
229
|
+
getEnv(nameOrId) {
|
|
230
|
+
const accountConfig = this.getAccount(nameOrId);
|
|
231
|
+
if (accountConfig && accountConfig.accountId && accountConfig.env) {
|
|
232
|
+
return accountConfig.env;
|
|
233
|
+
}
|
|
234
|
+
if (this.config && this.config.env) {
|
|
235
|
+
return this.config.env;
|
|
236
|
+
}
|
|
237
|
+
return environments_1.ENVIRONMENTS.PROD;
|
|
238
|
+
}
|
|
239
|
+
// Deprecating sandboxAccountType in favor of accountType
|
|
240
|
+
getAccountType(accountType, sandboxAccountType) {
|
|
241
|
+
if (accountType) {
|
|
242
|
+
return accountType;
|
|
243
|
+
}
|
|
244
|
+
if (typeof sandboxAccountType === 'string') {
|
|
245
|
+
if (sandboxAccountType.toUpperCase() === 'DEVELOPER') {
|
|
246
|
+
return config_1.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX;
|
|
247
|
+
}
|
|
248
|
+
if (sandboxAccountType.toUpperCase() === 'STANDARD') {
|
|
249
|
+
return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD;
|
|
253
|
+
}
|
|
254
|
+
/*
|
|
255
|
+
* Config Update Utils
|
|
256
|
+
*/
|
|
257
|
+
/**
|
|
258
|
+
* @throws {Error}
|
|
259
|
+
*/
|
|
260
|
+
addOrUpdateAccount(updatedAccountFields, writeUpdate = true) {
|
|
261
|
+
const { accountId, accountType, apiKey, authType, clientId, clientSecret, defaultMode, env, name, parentAccountId, personalAccessKey, sandboxAccountType, scopes, tokenInfo, } = updatedAccountFields;
|
|
262
|
+
if (!accountId) {
|
|
263
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAccount.errors.accountIdRequired`));
|
|
264
|
+
}
|
|
265
|
+
if (!this.config) {
|
|
266
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.noConfigToUpdate`));
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
// Check whether the account is already listed in the config.yml file.
|
|
270
|
+
const currentAccountConfig = this.getAccount(accountId);
|
|
271
|
+
// For accounts that are already in the config.yml file, sets the auth property.
|
|
272
|
+
let auth = (currentAccountConfig && currentAccountConfig.auth) || {};
|
|
273
|
+
// For accounts not already in the config.yml file, sets the auth property.
|
|
274
|
+
if (clientId || clientSecret || scopes || tokenInfo) {
|
|
275
|
+
auth = {
|
|
276
|
+
...(currentAccountConfig ? currentAccountConfig.auth : {}),
|
|
277
|
+
clientId,
|
|
278
|
+
clientSecret,
|
|
279
|
+
scopes,
|
|
280
|
+
tokenInfo,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
const nextAccountConfig = {
|
|
284
|
+
...(currentAccountConfig ? currentAccountConfig : {}),
|
|
285
|
+
};
|
|
286
|
+
// Allow everything except for 'undefined' values to override the existing values
|
|
287
|
+
function safelyApplyUpdates(fieldName,
|
|
288
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
289
|
+
newValue) {
|
|
290
|
+
if (typeof newValue !== 'undefined') {
|
|
291
|
+
nextAccountConfig[fieldName] = newValue;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const updatedEnv = (0, environment_2.getValidEnv)(env || (currentAccountConfig && currentAccountConfig.env));
|
|
295
|
+
const updatedDefaultMode = defaultMode && defaultMode.toLowerCase();
|
|
296
|
+
const updatedAccountType = accountType || (currentAccountConfig && currentAccountConfig.accountType);
|
|
297
|
+
safelyApplyUpdates('name', name);
|
|
298
|
+
safelyApplyUpdates('env', updatedEnv);
|
|
299
|
+
safelyApplyUpdates('accountId', accountId);
|
|
300
|
+
safelyApplyUpdates('authType', authType);
|
|
301
|
+
safelyApplyUpdates('auth', auth);
|
|
302
|
+
if (nextAccountConfig.authType === auth_1.API_KEY_AUTH_METHOD.value) {
|
|
303
|
+
safelyApplyUpdates('apiKey', apiKey);
|
|
304
|
+
}
|
|
305
|
+
if (typeof updatedDefaultMode !== 'undefined') {
|
|
306
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
307
|
+
safelyApplyUpdates('defaultMode', files_1.MODE[updatedDefaultMode]);
|
|
308
|
+
}
|
|
309
|
+
safelyApplyUpdates('personalAccessKey', personalAccessKey);
|
|
310
|
+
// Deprecating sandboxAccountType in favor of the more generic accountType
|
|
311
|
+
safelyApplyUpdates('sandboxAccountType', sandboxAccountType);
|
|
312
|
+
safelyApplyUpdates('accountType', this.getAccountType(updatedAccountType, sandboxAccountType));
|
|
313
|
+
safelyApplyUpdates('parentAccountId', parentAccountId);
|
|
314
|
+
const completedAccountConfig = nextAccountConfig;
|
|
315
|
+
if (!Object.hasOwn(this.config, 'accounts')) {
|
|
316
|
+
this.config.accounts = [];
|
|
317
|
+
}
|
|
318
|
+
if (currentAccountConfig) {
|
|
319
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.updating`, {
|
|
320
|
+
accountId,
|
|
321
|
+
}));
|
|
322
|
+
const index = this.getAccountIndex(accountId);
|
|
323
|
+
if (index < 0) {
|
|
324
|
+
this.config.accounts.push(completedAccountConfig);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
this.config.accounts[index] = completedAccountConfig;
|
|
328
|
+
}
|
|
329
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.updateAccount.addingConfigEntry`, {
|
|
330
|
+
accountId,
|
|
331
|
+
}));
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
this.config.accounts.push(completedAccountConfig);
|
|
335
|
+
}
|
|
336
|
+
if (writeUpdate) {
|
|
337
|
+
this.write();
|
|
338
|
+
}
|
|
339
|
+
return completedAccountConfig;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* @throws {Error}
|
|
343
|
+
*/
|
|
344
|
+
updateDefaultAccount(defaultAccount) {
|
|
345
|
+
if (!this.config) {
|
|
346
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
347
|
+
}
|
|
348
|
+
if (!defaultAccount ||
|
|
349
|
+
(typeof defaultAccount !== 'number' && typeof defaultAccount !== 'string')) {
|
|
350
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultAccount.errors.invalidInput`));
|
|
351
|
+
}
|
|
352
|
+
this.config.defaultAccount = defaultAccount;
|
|
353
|
+
return this.write();
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* @throws {Error}
|
|
357
|
+
*/
|
|
358
|
+
renameAccount(currentName, newName) {
|
|
359
|
+
if (!this.config) {
|
|
360
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
361
|
+
}
|
|
362
|
+
const accountId = this.getAccountId(currentName);
|
|
363
|
+
let accountConfigToRename = null;
|
|
364
|
+
if (accountId) {
|
|
365
|
+
accountConfigToRename = this.getAccount(accountId);
|
|
366
|
+
}
|
|
367
|
+
if (!accountConfigToRename) {
|
|
368
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.renameAccount.errors.invalidName`, {
|
|
369
|
+
currentName,
|
|
370
|
+
}));
|
|
371
|
+
}
|
|
372
|
+
if (accountId) {
|
|
373
|
+
this.addOrUpdateAccount({
|
|
374
|
+
accountId,
|
|
375
|
+
name: newName,
|
|
376
|
+
env: this.getEnv(),
|
|
377
|
+
accountType: accountConfigToRename.accountType,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
if (accountConfigToRename.name === this.getDefaultAccount()) {
|
|
381
|
+
this.updateDefaultAccount(newName);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* @throws {Error}
|
|
386
|
+
* TODO: this does not account for the special handling of sandbox account deletes
|
|
387
|
+
*/
|
|
388
|
+
removeAccountFromConfig(nameOrId) {
|
|
389
|
+
if (!this.config) {
|
|
390
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
391
|
+
}
|
|
392
|
+
const accountId = this.getAccountId(nameOrId);
|
|
393
|
+
if (!accountId) {
|
|
394
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.errors.invalidId`, {
|
|
395
|
+
nameOrId,
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
let removedAccountIsDefault = false;
|
|
399
|
+
const accountConfig = this.getAccount(accountId);
|
|
400
|
+
if (accountConfig) {
|
|
401
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId }));
|
|
402
|
+
const index = this.getAccountIndex(accountId);
|
|
403
|
+
this.config.accounts.splice(index, 1);
|
|
404
|
+
if (this.getDefaultAccount() === accountConfig.name) {
|
|
405
|
+
removedAccountIsDefault = true;
|
|
406
|
+
}
|
|
407
|
+
this.write();
|
|
408
|
+
}
|
|
409
|
+
return removedAccountIsDefault;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* @throws {Error}
|
|
413
|
+
*/
|
|
414
|
+
updateDefaultMode(defaultMode) {
|
|
415
|
+
if (!this.config) {
|
|
416
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
417
|
+
}
|
|
418
|
+
const ALL_MODES = Object.values(files_1.MODE);
|
|
419
|
+
if (!defaultMode || !ALL_MODES.find(m => m === defaultMode)) {
|
|
420
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateDefaultMode.errors.invalidMode`, {
|
|
421
|
+
defaultMode,
|
|
422
|
+
validModes: (0, text_1.commaSeparatedValues)(ALL_MODES),
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
this.config.defaultMode = defaultMode;
|
|
426
|
+
return this.write();
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* @throws {Error}
|
|
430
|
+
*/
|
|
431
|
+
updateHttpTimeout(timeout) {
|
|
432
|
+
if (!this.config) {
|
|
433
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
434
|
+
}
|
|
435
|
+
const parsedTimeout = parseInt(timeout);
|
|
436
|
+
if (isNaN(parsedTimeout) || parsedTimeout < config_1.MIN_HTTP_TIMEOUT) {
|
|
437
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateHttpTimeout.errors.invalidTimeout`, {
|
|
438
|
+
timeout,
|
|
439
|
+
minTimeout: config_1.MIN_HTTP_TIMEOUT,
|
|
440
|
+
}));
|
|
441
|
+
}
|
|
442
|
+
this.config.httpTimeout = parsedTimeout;
|
|
443
|
+
return this.write();
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* @throws {Error}
|
|
447
|
+
*/
|
|
448
|
+
updateAllowUsageTracking(isEnabled) {
|
|
449
|
+
if (!this.config) {
|
|
450
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigLoaded`));
|
|
451
|
+
}
|
|
452
|
+
if (typeof isEnabled !== 'boolean') {
|
|
453
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.updateAllowUsageTracking.errors.invalidInput`, {
|
|
454
|
+
isEnabled: `${isEnabled}`,
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
this.config.allowUsageTracking = isEnabled;
|
|
458
|
+
return this.write();
|
|
459
|
+
}
|
|
460
|
+
isTrackingAllowed() {
|
|
461
|
+
if (!this.config) {
|
|
462
|
+
return true;
|
|
463
|
+
}
|
|
464
|
+
return this.config.allowUsageTracking !== false;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
exports.CLIConfiguration = new _CLIConfiguration();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CLIConfig_NEW } from '../types/Config';
|
|
2
|
+
export declare function getConfigFilePath(): string;
|
|
3
|
+
export declare function configFileExists(): boolean;
|
|
4
|
+
export declare function configFileIsBlank(): boolean;
|
|
5
|
+
export declare function deleteConfigFile(): void;
|
|
6
|
+
/**
|
|
7
|
+
* @throws {Error}
|
|
8
|
+
*/
|
|
9
|
+
export declare function readConfigFile(configPath: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* @throws {Error}
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseConfig(configSource: string): CLIConfig_NEW;
|
|
14
|
+
/**
|
|
15
|
+
* @throws {Error}
|
|
16
|
+
*/
|
|
17
|
+
export declare function loadConfigFromFile(): CLIConfig_NEW | null;
|
|
18
|
+
/**
|
|
19
|
+
* @throws {Error}
|
|
20
|
+
*/
|
|
21
|
+
export declare function writeConfigToFile(config: CLIConfig_NEW): void;
|
|
@@ -0,0 +1,102 @@
|
|
|
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("../lib/logger");
|
|
12
|
+
const config_1 = require("../constants/config");
|
|
13
|
+
const configUtils_1 = require("./configUtils");
|
|
14
|
+
const lang_1 = require("../utils/lang");
|
|
15
|
+
const FileSystemError_1 = require("../models/FileSystemError");
|
|
16
|
+
const i18nKey = 'config.configFile';
|
|
17
|
+
function getConfigFilePath() {
|
|
18
|
+
return path_1.default.join(os_1.default.homedir(), config_1.HUBSPOT_CONFIGURATION_FOLDER, config_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
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorReading`, { configPath }));
|
|
46
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
47
|
+
filepath: configPath,
|
|
48
|
+
operation: 'read',
|
|
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
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.parsing`), { cause: 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
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorLoading`, { configPath }));
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
exports.loadConfigFromFile = loadConfigFromFile;
|
|
84
|
+
/**
|
|
85
|
+
* @throws {Error}
|
|
86
|
+
*/
|
|
87
|
+
function writeConfigToFile(config) {
|
|
88
|
+
const source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
|
|
89
|
+
const configPath = getConfigFilePath();
|
|
90
|
+
try {
|
|
91
|
+
fs_extra_1.default.ensureFileSync(configPath);
|
|
92
|
+
fs_extra_1.default.writeFileSync(configPath, source);
|
|
93
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.writeSuccess`, { configPath }));
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
97
|
+
filepath: configPath,
|
|
98
|
+
operation: 'write',
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.writeConfigToFile = writeConfigToFile;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CLIConfig_NEW } from '../types/Config';
|
|
2
|
+
import { AuthType, CLIAccount_NEW, PersonalAccessKeyOptions, OAuthOptions, APIKeyOptions } from '../types/Accounts';
|
|
3
|
+
export declare function getOrderedAccount(unorderedAccount: CLIAccount_NEW): CLIAccount_NEW;
|
|
4
|
+
export declare function getOrderedConfig(unorderedConfig: CLIConfig_NEW): CLIConfig_NEW;
|
|
5
|
+
export declare function generateConfig(type: AuthType, options: PersonalAccessKeyOptions | OAuthOptions | APIKeyOptions): CLIConfig_NEW | null;
|