@hubspot/local-dev-lib 0.2.1-experimental.1 → 0.2.2-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/api/github.d.ts +0 -1
- package/api/projects.d.ts +0 -1
- package/config/CLIConfiguration.d.ts +65 -0
- package/config/CLIConfiguration.js +509 -0
- package/config/configFile.d.ts +21 -0
- package/config/configFile.js +100 -0
- package/config/configUtils.d.ts +5 -0
- package/config/configUtils.js +87 -0
- package/config/config_DEPRECATED.d.ts +76 -0
- package/config/config_DEPRECATED.js +693 -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 -25
- package/config/index.js +236 -248
- package/config/migrate.d.ts +20 -0
- package/config/migrate.js +150 -0
- package/constants/config.d.ts +7 -24
- package/constants/config.js +13 -25
- package/constants/environments.d.ts +11 -0
- package/constants/environments.js +12 -1
- package/http/getAxiosConfig.js +1 -7
- package/http/index.js +19 -23
- package/lang/en.json +81 -67
- package/lib/archive.d.ts +0 -1
- package/lib/cms/themes.js +1 -3
- package/lib/environment.d.ts +1 -1
- package/lib/github.d.ts +0 -1
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +16 -8
- package/lib/personalAccessKey.d.ts +2 -2
- package/lib/personalAccessKey.js +30 -39
- package/lib/trackUsage.js +3 -6
- package/models/OAuth2Manager.d.ts +4 -3
- package/models/OAuth2Manager.js +29 -20
- package/package.json +4 -3
- package/types/Accounts.d.ts +109 -20
- package/types/Config.d.ts +24 -11
- package/types/Http.d.ts +0 -1
- package/utils/accounts.d.ts +4 -0
- package/utils/accounts.js +28 -0
- package/config/defaultAccountOverride.d.ts +0 -2
- package/config/defaultAccountOverride.js +0 -57
- package/config/utils.d.ts +0 -70
- package/config/utils.js +0 -328
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.writeConfigToFile = exports.loadConfigFromFile = exports.parseConfig = exports.readConfigFile = exports.deleteConfigFile = exports.configFileIsBlank = exports.configFileExists = exports.getConfigFilePath = void 0;
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
|
+
const logger_1 = require("../lib/logger");
|
|
10
|
+
const config_1 = require("../constants/config");
|
|
11
|
+
const configUtils_1 = require("./configUtils");
|
|
12
|
+
const lang_1 = require("../utils/lang");
|
|
13
|
+
const FileSystemError_1 = require("../models/FileSystemError");
|
|
14
|
+
const i18nKey = 'config.configFile';
|
|
15
|
+
function getConfigFilePath() {
|
|
16
|
+
return config_1.GLOBAL_CONFIG_PATH;
|
|
17
|
+
}
|
|
18
|
+
exports.getConfigFilePath = getConfigFilePath;
|
|
19
|
+
function configFileExists() {
|
|
20
|
+
const configPath = getConfigFilePath();
|
|
21
|
+
return !!configPath && fs_extra_1.default.existsSync(configPath);
|
|
22
|
+
}
|
|
23
|
+
exports.configFileExists = configFileExists;
|
|
24
|
+
function configFileIsBlank() {
|
|
25
|
+
const configPath = getConfigFilePath();
|
|
26
|
+
return !!configPath && fs_extra_1.default.readFileSync(configPath).length === 0;
|
|
27
|
+
}
|
|
28
|
+
exports.configFileIsBlank = configFileIsBlank;
|
|
29
|
+
function deleteConfigFile() {
|
|
30
|
+
const configPath = getConfigFilePath();
|
|
31
|
+
fs_extra_1.default.unlinkSync(configPath);
|
|
32
|
+
}
|
|
33
|
+
exports.deleteConfigFile = deleteConfigFile;
|
|
34
|
+
/**
|
|
35
|
+
* @throws {Error}
|
|
36
|
+
*/
|
|
37
|
+
function readConfigFile(configPath) {
|
|
38
|
+
let source = '';
|
|
39
|
+
try {
|
|
40
|
+
source = fs_extra_1.default.readFileSync(configPath).toString();
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorReading`, { configPath }));
|
|
44
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
45
|
+
filepath: configPath,
|
|
46
|
+
operation: 'read',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return source;
|
|
50
|
+
}
|
|
51
|
+
exports.readConfigFile = readConfigFile;
|
|
52
|
+
/**
|
|
53
|
+
* @throws {Error}
|
|
54
|
+
*/
|
|
55
|
+
function parseConfig(configSource) {
|
|
56
|
+
let parsed;
|
|
57
|
+
try {
|
|
58
|
+
parsed = js_yaml_1.default.load(configSource);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.parsing`), { cause: err });
|
|
62
|
+
}
|
|
63
|
+
return parsed;
|
|
64
|
+
}
|
|
65
|
+
exports.parseConfig = parseConfig;
|
|
66
|
+
/**
|
|
67
|
+
* @throws {Error}
|
|
68
|
+
*/
|
|
69
|
+
function loadConfigFromFile() {
|
|
70
|
+
const configPath = getConfigFilePath();
|
|
71
|
+
if (configPath) {
|
|
72
|
+
const source = readConfigFile(configPath);
|
|
73
|
+
if (!source) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return parseConfig(source);
|
|
77
|
+
}
|
|
78
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorLoading`, { configPath }));
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
exports.loadConfigFromFile = loadConfigFromFile;
|
|
82
|
+
/**
|
|
83
|
+
* @throws {Error}
|
|
84
|
+
*/
|
|
85
|
+
function writeConfigToFile(config) {
|
|
86
|
+
const source = js_yaml_1.default.dump(JSON.parse(JSON.stringify((0, configUtils_1.getOrderedConfig)(config), null, 2)));
|
|
87
|
+
const configPath = getConfigFilePath();
|
|
88
|
+
try {
|
|
89
|
+
fs_extra_1.default.ensureFileSync(configPath);
|
|
90
|
+
fs_extra_1.default.writeFileSync(configPath, source);
|
|
91
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.writeSuccess`, { configPath }));
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
throw new FileSystemError_1.FileSystemError({ cause: err }, {
|
|
95
|
+
filepath: configPath,
|
|
96
|
+
operation: 'write',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.writeConfigToFile = writeConfigToFile;
|
|
@@ -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;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateConfig = exports.getOrderedConfig = exports.getOrderedAccount = void 0;
|
|
4
|
+
const logger_1 = require("../lib/logger");
|
|
5
|
+
const auth_1 = require("../constants/auth");
|
|
6
|
+
const lang_1 = require("../utils/lang");
|
|
7
|
+
const i18nKey = 'config.configUtils';
|
|
8
|
+
function getOrderedAccount(unorderedAccount) {
|
|
9
|
+
const { name, accountId, env, authType, ...rest } = unorderedAccount;
|
|
10
|
+
return {
|
|
11
|
+
name,
|
|
12
|
+
accountId,
|
|
13
|
+
env,
|
|
14
|
+
authType,
|
|
15
|
+
...rest,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.getOrderedAccount = getOrderedAccount;
|
|
19
|
+
function getOrderedConfig(unorderedConfig) {
|
|
20
|
+
const { defaultAccount, defaultCmsPublishMode, httpTimeout, allowUsageTracking, accounts, ...rest } = unorderedConfig;
|
|
21
|
+
return {
|
|
22
|
+
...(defaultAccount && { defaultAccount }),
|
|
23
|
+
defaultCmsPublishMode,
|
|
24
|
+
httpTimeout,
|
|
25
|
+
allowUsageTracking,
|
|
26
|
+
...rest,
|
|
27
|
+
accounts: accounts.map(getOrderedAccount),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports.getOrderedConfig = getOrderedConfig;
|
|
31
|
+
function generatePersonalAccessKeyAccountConfig({ accountId, personalAccessKey, env, }) {
|
|
32
|
+
return {
|
|
33
|
+
authType: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
34
|
+
accountId,
|
|
35
|
+
personalAccessKey,
|
|
36
|
+
env,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function generateOauthAccountConfig({ accountId, clientId, clientSecret, refreshToken, scopes, env, }) {
|
|
40
|
+
return {
|
|
41
|
+
authType: auth_1.OAUTH_AUTH_METHOD.value,
|
|
42
|
+
accountId,
|
|
43
|
+
auth: {
|
|
44
|
+
clientId,
|
|
45
|
+
clientSecret,
|
|
46
|
+
scopes,
|
|
47
|
+
tokenInfo: {
|
|
48
|
+
refreshToken,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
env,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function generateApiKeyAccountConfig({ accountId, apiKey, env, }) {
|
|
55
|
+
return {
|
|
56
|
+
authType: auth_1.API_KEY_AUTH_METHOD.value,
|
|
57
|
+
accountId,
|
|
58
|
+
apiKey,
|
|
59
|
+
env,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function generateConfig(type, options) {
|
|
63
|
+
if (!options) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const config = { accounts: [] };
|
|
67
|
+
let configAccount;
|
|
68
|
+
switch (type) {
|
|
69
|
+
case auth_1.API_KEY_AUTH_METHOD.value:
|
|
70
|
+
configAccount = generateApiKeyAccountConfig(options);
|
|
71
|
+
break;
|
|
72
|
+
case auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value:
|
|
73
|
+
configAccount = generatePersonalAccessKeyAccountConfig(options);
|
|
74
|
+
break;
|
|
75
|
+
case auth_1.OAUTH_AUTH_METHOD.value:
|
|
76
|
+
configAccount = generateOauthAccountConfig(options);
|
|
77
|
+
break;
|
|
78
|
+
default:
|
|
79
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.unknownType`, { type }));
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
if (configAccount) {
|
|
83
|
+
config.accounts.push(configAccount);
|
|
84
|
+
}
|
|
85
|
+
return config;
|
|
86
|
+
}
|
|
87
|
+
exports.generateConfig = generateConfig;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CLIConfig_DEPRECATED, Environment } from '../types/Config';
|
|
2
|
+
import { AccountType, CLIAccount_DEPRECATED, FlatAccountFields_DEPRECATED, UpdateAccountConfigOptions } from '../types/Accounts';
|
|
3
|
+
import { CmsPublishMode } from '../types/Files';
|
|
4
|
+
import { CLIOptions, WriteConfigOptions } from '../types/CLIOptions';
|
|
5
|
+
export declare const getConfig: () => CLIConfig_DEPRECATED | null;
|
|
6
|
+
export declare function setConfig(updatedConfig?: CLIConfig_DEPRECATED): CLIConfig_DEPRECATED | null;
|
|
7
|
+
export declare function getConfigAccounts(config?: CLIConfig_DEPRECATED): Array<CLIAccount_DEPRECATED> | undefined;
|
|
8
|
+
export declare function getConfigDefaultAccount(config?: CLIConfig_DEPRECATED): string | number | undefined;
|
|
9
|
+
export declare function getConfigAccountId(account: CLIAccount_DEPRECATED): number | undefined;
|
|
10
|
+
export declare function setConfigPath(path: string | null): string | null;
|
|
11
|
+
export declare function getConfigPath(path?: string | null): string | null;
|
|
12
|
+
export declare function validateConfig(): boolean;
|
|
13
|
+
export declare function accountNameExistsInConfig(name: string): boolean;
|
|
14
|
+
export declare function getOrderedAccount(unorderedAccount: CLIAccount_DEPRECATED): CLIAccount_DEPRECATED;
|
|
15
|
+
export declare function getOrderedConfig(unorderedConfig: CLIConfig_DEPRECATED): {
|
|
16
|
+
portals: CLIAccount_DEPRECATED[];
|
|
17
|
+
defaultMode?: CmsPublishMode | undefined;
|
|
18
|
+
env?: Environment | undefined;
|
|
19
|
+
httpUseLocalhost?: boolean | undefined;
|
|
20
|
+
defaultCmsPublishMode: CmsPublishMode | undefined;
|
|
21
|
+
httpTimeout: number | undefined;
|
|
22
|
+
allowUsageTracking: boolean | undefined;
|
|
23
|
+
defaultPortal?: string | number | undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare function writeConfig(options?: WriteConfigOptions): void;
|
|
26
|
+
export declare function loadConfig(path?: string, options?: CLIOptions): CLIConfig_DEPRECATED | null;
|
|
27
|
+
export declare function isTrackingAllowed(): boolean;
|
|
28
|
+
export declare function getAndLoadConfigIfNeeded(options?: {}): Partial<CLIConfig_DEPRECATED>;
|
|
29
|
+
export declare function findConfig(directory: string): string | null;
|
|
30
|
+
export declare function getEnv(nameOrId?: string | number): Environment;
|
|
31
|
+
export declare function getAccountType(accountType?: AccountType, sandboxAccountType?: string | null): AccountType;
|
|
32
|
+
export declare function getAccountConfig(accountId: number | undefined): CLIAccount_DEPRECATED | undefined;
|
|
33
|
+
export declare function getAccountId(nameOrId?: string | number): number | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* @throws {Error}
|
|
36
|
+
*/
|
|
37
|
+
export declare function removeSandboxAccountFromConfig(nameOrId: string | number): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* @throws {Error}
|
|
40
|
+
*/
|
|
41
|
+
export declare function updateAccountConfig(configOptions: UpdateAccountConfigOptions): FlatAccountFields_DEPRECATED;
|
|
42
|
+
/**
|
|
43
|
+
* @throws {Error}
|
|
44
|
+
*/
|
|
45
|
+
export declare function updateDefaultAccount(defaultAccount: string | number): void;
|
|
46
|
+
/**
|
|
47
|
+
* @throws {Error}
|
|
48
|
+
*/
|
|
49
|
+
export declare function updateDefaultCmsPublishMode(defaultCmsPublishMode: CmsPublishMode): void;
|
|
50
|
+
/**
|
|
51
|
+
* @throws {Error}
|
|
52
|
+
*/
|
|
53
|
+
export declare function updateHttpTimeout(timeout: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* @throws {Error}
|
|
56
|
+
*/
|
|
57
|
+
export declare function updateAllowUsageTracking(isEnabled: boolean): void;
|
|
58
|
+
/**
|
|
59
|
+
* @throws {Error}
|
|
60
|
+
*/
|
|
61
|
+
export declare function renameAccount(currentName: string, newName: string): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* @throws {Error}
|
|
64
|
+
*/
|
|
65
|
+
export declare function deleteAccount(accountName: string): Promise<void>;
|
|
66
|
+
export declare function createEmptyConfigFile({ path }?: {
|
|
67
|
+
path?: string;
|
|
68
|
+
}): void;
|
|
69
|
+
export declare function deleteEmptyConfigFile(): void;
|
|
70
|
+
export declare function deleteConfigFile(): void;
|
|
71
|
+
export declare function loadConfigFromEnvironment({ useEnv, }?: {
|
|
72
|
+
useEnv?: boolean;
|
|
73
|
+
}): {
|
|
74
|
+
portals: Array<CLIAccount_DEPRECATED>;
|
|
75
|
+
} | undefined;
|
|
76
|
+
export declare function isConfigFlagEnabled(flag: keyof CLIConfig_DEPRECATED): boolean;
|