@hubspot/local-dev-lib 0.5.0-experimental.7 → 0.5.0-experimental.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/config/index.d.ts +1 -1
- package/config/index.js +20 -13
- package/config/utils.d.ts +6 -1
- package/config/utils.js +34 -9
- package/constants/config.d.ts +3 -0
- package/constants/config.js +3 -0
- package/lang/en.json +8 -1
- package/lib/personalAccessKey.js +1 -3
- package/models/HubSpotConfigError.d.ts +1 -1
- package/models/HubSpotConfigError.js +7 -2
- package/package.json +1 -1
package/config/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare function getConfigAccountIfExists(identifier: number | string): H
|
|
|
16
16
|
export declare function getConfigDefaultAccount(): HubSpotConfigAccount;
|
|
17
17
|
export declare function getConfigDefaultAccountIfExists(): HubSpotConfigAccount | undefined;
|
|
18
18
|
export declare function getAllConfigAccounts(): HubSpotConfigAccount[];
|
|
19
|
-
export declare function getConfigAccountEnvironment(identifier
|
|
19
|
+
export declare function getConfigAccountEnvironment(identifier: number | string): Environment;
|
|
20
20
|
export declare function addConfigAccount(accountToAdd: HubSpotConfigAccount): void;
|
|
21
21
|
export declare function updateConfigAccount(updatedAccount: HubSpotConfigAccount): void;
|
|
22
22
|
export declare function setConfigAccountAsDefault(identifier: number | string): void;
|
package/config/index.js
CHANGED
|
@@ -15,16 +15,16 @@ const environment_1 = require("../lib/environment");
|
|
|
15
15
|
const HubSpotConfigError_1 = require("../models/HubSpotConfigError");
|
|
16
16
|
const config_2 = require("../constants/config");
|
|
17
17
|
function localConfigFileExists() {
|
|
18
|
-
return Boolean((0, utils_1.
|
|
18
|
+
return Boolean((0, utils_1.getLocalConfigFilePath)());
|
|
19
19
|
}
|
|
20
20
|
exports.localConfigFileExists = localConfigFileExists;
|
|
21
21
|
function globalConfigFileExists() {
|
|
22
|
-
return
|
|
22
|
+
return (0, utils_1.doesConfigFileExistAtPath)((0, utils_1.getGlobalConfigFilePath)());
|
|
23
23
|
}
|
|
24
24
|
exports.globalConfigFileExists = globalConfigFileExists;
|
|
25
25
|
function configFileExists() {
|
|
26
26
|
try {
|
|
27
|
-
return
|
|
27
|
+
return (0, utils_1.doesConfigFileExistAtPath)(getConfigFilePath());
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
30
30
|
return false;
|
|
@@ -33,7 +33,7 @@ function configFileExists() {
|
|
|
33
33
|
exports.configFileExists = configFileExists;
|
|
34
34
|
function getConfigDefaultFilePath() {
|
|
35
35
|
const globalConfigFilePath = (0, utils_1.getGlobalConfigFilePath)();
|
|
36
|
-
if (
|
|
36
|
+
if ((0, utils_1.doesConfigFileExistAtPath)(globalConfigFilePath)) {
|
|
37
37
|
return globalConfigFilePath;
|
|
38
38
|
}
|
|
39
39
|
const localConfigFilePath = (0, utils_1.getLocalConfigFilePath)();
|
|
@@ -115,7 +115,15 @@ function createEmptyConfigFile(useGlobalConfig = false) {
|
|
|
115
115
|
exports.createEmptyConfigFile = createEmptyConfigFile;
|
|
116
116
|
function deleteConfigFile() {
|
|
117
117
|
const pathToDelete = getConfigFilePath();
|
|
118
|
-
|
|
118
|
+
try {
|
|
119
|
+
fs_extra_1.default.unlinkSync(pathToDelete);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
const { message, type } = (0, utils_1.handleConfigFileSystemError)(error, pathToDelete);
|
|
123
|
+
throw new HubSpotConfigError_1.HubSpotConfigError(message, type, config_1.HUBSPOT_CONFIG_OPERATIONS.DELETE, {
|
|
124
|
+
cause: error,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
119
127
|
}
|
|
120
128
|
exports.deleteConfigFile = deleteConfigFile;
|
|
121
129
|
function getConfigAccountById(accountId) {
|
|
@@ -185,15 +193,14 @@ function getAllConfigAccounts() {
|
|
|
185
193
|
}
|
|
186
194
|
exports.getAllConfigAccounts = getAllConfigAccounts;
|
|
187
195
|
function getConfigAccountEnvironment(identifier) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
196
|
+
const config = getConfig();
|
|
197
|
+
const account = (0, utils_1.getConfigAccountByInferredIdentifier)(config.accounts, identifier);
|
|
198
|
+
if (!account) {
|
|
199
|
+
throw new HubSpotConfigError_1.HubSpotConfigError((0, lang_1.i18n)('config.getConfigAccountEnvironment.accountNotFound', {
|
|
200
|
+
identifier,
|
|
201
|
+
}), config_2.HUBSPOT_CONFIG_ERROR_TYPES.ACCOUNT_NOT_FOUND, config_1.HUBSPOT_CONFIG_OPERATIONS.READ);
|
|
194
202
|
}
|
|
195
|
-
|
|
196
|
-
return (0, environment_1.getValidEnv)(defaultAccount.env);
|
|
203
|
+
return (0, environment_1.getValidEnv)(account.env);
|
|
197
204
|
}
|
|
198
205
|
exports.getConfigAccountEnvironment = getConfigAccountEnvironment;
|
|
199
206
|
function addConfigAccount(accountToAdd) {
|
package/config/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ACCOUNT_IDENTIFIERS } from '../constants/config';
|
|
2
|
-
import { HubSpotConfig, DeprecatedHubSpotConfigFields } from '../types/Config';
|
|
2
|
+
import { HubSpotConfig, DeprecatedHubSpotConfigFields, HubSpotConfigErrorType } from '../types/Config';
|
|
3
3
|
import { HubSpotConfigAccount, AccountType, TokenInfo } from '../types/Accounts';
|
|
4
4
|
import { ValueOf } from '../types/Utils';
|
|
5
5
|
export declare function getGlobalConfigFilePath(): string;
|
|
@@ -9,6 +9,7 @@ export declare function getConfigPathEnvironmentVariables(): {
|
|
|
9
9
|
useEnvironmentConfig: boolean;
|
|
10
10
|
configFilePathFromEnvironment: string | undefined;
|
|
11
11
|
};
|
|
12
|
+
export declare function doesConfigFileExistAtPath(path: string): boolean;
|
|
12
13
|
export declare function readConfigFile(configPath: string): string;
|
|
13
14
|
export declare function removeUndefinedFieldsFromConfigAccount<T extends HubSpotConfigAccount | Partial<HubSpotConfigAccount> = HubSpotConfigAccount>(account: T): T;
|
|
14
15
|
export declare function formatConfigForWrite(config: HubSpotConfig): {
|
|
@@ -72,3 +73,7 @@ export declare function getConfigAccountByIdentifier(accounts: Array<HubSpotConf
|
|
|
72
73
|
export declare function getConfigAccountByInferredIdentifier(accounts: Array<HubSpotConfigAccount>, accountIdentifier: string | number): HubSpotConfigAccount | undefined;
|
|
73
74
|
export declare function getConfigAccountIndexById(accounts: Array<HubSpotConfigAccount>, id: number): number;
|
|
74
75
|
export declare function isConfigAccountValid(account: Partial<HubSpotConfigAccount>): boolean;
|
|
76
|
+
export declare function handleConfigFileSystemError(error: unknown, path: string): {
|
|
77
|
+
message?: string;
|
|
78
|
+
type: HubSpotConfigErrorType;
|
|
79
|
+
};
|
package/config/utils.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.isConfigAccountValid = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = exports.normalizeParsedConfig = exports.writeConfigFile = exports.formatConfigForWrite = exports.removeUndefinedFieldsFromConfigAccount = exports.readConfigFile = exports.getConfigPathEnvironmentVariables = exports.getLocalConfigDefaultFilePath = exports.getLocalConfigFilePath = exports.getGlobalConfigFilePath = void 0;
|
|
6
|
+
exports.handleConfigFileSystemError = exports.isConfigAccountValid = exports.getConfigAccountIndexById = exports.getConfigAccountByInferredIdentifier = exports.getConfigAccountByIdentifier = exports.getAccountIdentifierAndType = exports.buildConfigFromEnvironment = exports.parseConfig = exports.normalizeParsedConfig = exports.writeConfigFile = exports.formatConfigForWrite = exports.removeUndefinedFieldsFromConfigAccount = exports.readConfigFile = exports.doesConfigFileExistAtPath = exports.getConfigPathEnvironmentVariables = exports.getLocalConfigDefaultFilePath = exports.getLocalConfigFilePath = exports.getGlobalConfigFilePath = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
9
|
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
@@ -44,18 +44,24 @@ function getConfigPathEnvironmentVariables() {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
exports.getConfigPathEnvironmentVariables = getConfigPathEnvironmentVariables;
|
|
47
|
+
function doesConfigFileExistAtPath(path) {
|
|
48
|
+
try {
|
|
49
|
+
return fs_extra_1.default.existsSync(path);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const { message, type } = handleConfigFileSystemError(error, path);
|
|
53
|
+
throw new HubSpotConfigError_1.HubSpotConfigError(message, type, config_1.HUBSPOT_CONFIG_OPERATIONS.READ, { cause: error });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.doesConfigFileExistAtPath = doesConfigFileExistAtPath;
|
|
47
57
|
function readConfigFile(configPath) {
|
|
48
|
-
let source = '';
|
|
49
58
|
try {
|
|
50
|
-
|
|
59
|
+
return fs_extra_1.default.readFileSync(configPath).toString();
|
|
51
60
|
}
|
|
52
61
|
catch (err) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
operation: 'read',
|
|
56
|
-
});
|
|
62
|
+
const { message, type } = handleConfigFileSystemError(err, configPath);
|
|
63
|
+
throw new HubSpotConfigError_1.HubSpotConfigError(message, type, config_1.HUBSPOT_CONFIG_OPERATIONS.READ, { cause: err });
|
|
57
64
|
}
|
|
58
|
-
return source;
|
|
59
65
|
}
|
|
60
66
|
exports.readConfigFile = readConfigFile;
|
|
61
67
|
function removeUndefinedFieldsFromConfigAccount(account) {
|
|
@@ -111,7 +117,7 @@ function formatConfigForWrite(config) {
|
|
|
111
117
|
}
|
|
112
118
|
exports.formatConfigForWrite = formatConfigForWrite;
|
|
113
119
|
function writeConfigFile(config, configPath) {
|
|
114
|
-
const source = js_yaml_1.default.dump(
|
|
120
|
+
const source = js_yaml_1.default.dump(formatConfigForWrite(config));
|
|
115
121
|
try {
|
|
116
122
|
fs_extra_1.default.ensureFileSync(configPath);
|
|
117
123
|
fs_extra_1.default.writeFileSync(configPath, source);
|
|
@@ -136,6 +142,9 @@ function getAccountType(sandboxAccountType) {
|
|
|
136
142
|
return config_1.HUBSPOT_ACCOUNT_TYPES.STANDARD;
|
|
137
143
|
}
|
|
138
144
|
function normalizeParsedConfig(parsedConfig) {
|
|
145
|
+
if (!parsedConfig.portals && !parsedConfig.accounts) {
|
|
146
|
+
parsedConfig.accounts = [];
|
|
147
|
+
}
|
|
139
148
|
if (parsedConfig.portals) {
|
|
140
149
|
parsedConfig.accounts = parsedConfig.portals.map(account => {
|
|
141
150
|
if (account.portalId) {
|
|
@@ -325,3 +334,19 @@ function isConfigAccountValid(account) {
|
|
|
325
334
|
return valid;
|
|
326
335
|
}
|
|
327
336
|
exports.isConfigAccountValid = isConfigAccountValid;
|
|
337
|
+
function handleConfigFileSystemError(error, path) {
|
|
338
|
+
let message;
|
|
339
|
+
let type = config_1.HUBSPOT_CONFIG_ERROR_TYPES.UNKNOWN;
|
|
340
|
+
if (error instanceof Error && 'code' in error) {
|
|
341
|
+
if (error.code === 'ENOENT') {
|
|
342
|
+
message = (0, lang_1.i18n)('config.utils.handleConfigFileSystemError.configNotFoundError', { path });
|
|
343
|
+
type = config_1.HUBSPOT_CONFIG_ERROR_TYPES.CONFIG_NOT_FOUND;
|
|
344
|
+
}
|
|
345
|
+
else if (error.code === 'EACCES') {
|
|
346
|
+
message = (0, lang_1.i18n)('config.utils.handleConfigFileSystemError.insufficientPermissionsError', { path });
|
|
347
|
+
type = config_1.HUBSPOT_CONFIG_ERROR_TYPES.INSUFFICIENT_PERMISSIONS;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return { message, type };
|
|
351
|
+
}
|
|
352
|
+
exports.handleConfigFileSystemError = handleConfigFileSystemError;
|
package/constants/config.d.ts
CHANGED
|
@@ -59,14 +59,17 @@ export declare const ACCOUNT_IDENTIFIERS: {
|
|
|
59
59
|
};
|
|
60
60
|
export declare const HUBSPOT_CONFIG_ERROR_TYPES: {
|
|
61
61
|
readonly CONFIG_NOT_FOUND: "CONFIG_NOT_FOUND";
|
|
62
|
+
readonly INSUFFICIENT_PERMISSIONS: "INSUFFICIENT_PERMISSIONS";
|
|
62
63
|
readonly ACCOUNT_NOT_FOUND: "ACCOUNT_NOT_FOUND";
|
|
63
64
|
readonly NO_DEFAULT_ACCOUNT: "NO_DEFAULT_ACCOUNT";
|
|
64
65
|
readonly INVALID_ENVIRONMENT_VARIABLES: "ENVIRONMENT_VARIABLES";
|
|
65
66
|
readonly YAML_PARSING: "YAML_PARSING";
|
|
66
67
|
readonly INVALID_ACCOUNT: "INVALID_ACCOUNT";
|
|
67
68
|
readonly INVALID_FIELD: "INVALID_FIELD";
|
|
69
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
68
70
|
};
|
|
69
71
|
export declare const HUBSPOT_CONFIG_OPERATIONS: {
|
|
70
72
|
readonly READ: "READ";
|
|
71
73
|
readonly WRITE: "WRITE";
|
|
74
|
+
readonly DELETE: "DELETE";
|
|
72
75
|
};
|
package/constants/config.js
CHANGED
|
@@ -68,14 +68,17 @@ exports.ACCOUNT_IDENTIFIERS = {
|
|
|
68
68
|
};
|
|
69
69
|
exports.HUBSPOT_CONFIG_ERROR_TYPES = {
|
|
70
70
|
CONFIG_NOT_FOUND: 'CONFIG_NOT_FOUND',
|
|
71
|
+
INSUFFICIENT_PERMISSIONS: 'INSUFFICIENT_PERMISSIONS',
|
|
71
72
|
ACCOUNT_NOT_FOUND: 'ACCOUNT_NOT_FOUND',
|
|
72
73
|
NO_DEFAULT_ACCOUNT: 'NO_DEFAULT_ACCOUNT',
|
|
73
74
|
INVALID_ENVIRONMENT_VARIABLES: 'ENVIRONMENT_VARIABLES',
|
|
74
75
|
YAML_PARSING: 'YAML_PARSING',
|
|
75
76
|
INVALID_ACCOUNT: 'INVALID_ACCOUNT',
|
|
76
77
|
INVALID_FIELD: 'INVALID_FIELD',
|
|
78
|
+
UNKNOWN: 'UNKNOWN',
|
|
77
79
|
};
|
|
78
80
|
exports.HUBSPOT_CONFIG_OPERATIONS = {
|
|
79
81
|
READ: 'READ',
|
|
80
82
|
WRITE: 'WRITE',
|
|
83
|
+
DELETE: 'DELETE',
|
|
81
84
|
};
|
package/lang/en.json
CHANGED
|
@@ -291,7 +291,14 @@
|
|
|
291
291
|
"updateDefaultCmsPublishMode": {
|
|
292
292
|
"invalidCmsPublishMode": "Error updating config default CMS publish mode: CMS publish can only be set to 'draft' or 'publish'"
|
|
293
293
|
},
|
|
294
|
+
"getConfigAccountEnvironment": {
|
|
295
|
+
"accountNotFound": "Attempted to get environment for account with identifier {{ identifier }}, but that account was not found in config"
|
|
296
|
+
},
|
|
294
297
|
"utils": {
|
|
298
|
+
"handleConfigFileSystemError": {
|
|
299
|
+
"configNotFoundError": "No config file found at {{ path }}.",
|
|
300
|
+
"insufficientPermissionsError": "Insufficient permissions to access config file at {{ path }}"
|
|
301
|
+
},
|
|
295
302
|
"isConfigAccountValid": {
|
|
296
303
|
"missingAccount": "Invalid config: at least one account in config is missing data",
|
|
297
304
|
"missingAuthType": "Invalid config: account {{ accountId }} has no authType",
|
|
@@ -382,7 +389,7 @@
|
|
|
382
389
|
}
|
|
383
390
|
},
|
|
384
391
|
"HubSpotConfigError": {
|
|
385
|
-
"baseMessage": "An error occurred while {{ operation }} your HubSpot config {{ configType }}
|
|
392
|
+
"baseMessage": "An error occurred while {{ operation }} your HubSpot config {{ configType }}{{ message }}"
|
|
386
393
|
}
|
|
387
394
|
},
|
|
388
395
|
"utils": {
|
package/lib/personalAccessKey.js
CHANGED
|
@@ -121,9 +121,7 @@ async function authorizedScopesForPortalAndUser(accountId) {
|
|
|
121
121
|
exports.authorizedScopesForPortalAndUser = authorizedScopesForPortalAndUser;
|
|
122
122
|
async function updateConfigWithAccessToken(token, personalAccessKey, env, name, makeDefault = false) {
|
|
123
123
|
const { portalId, accessToken, expiresAt, accountType } = token;
|
|
124
|
-
const account = name
|
|
125
|
-
? (0, config_1.getConfigAccountIfExists)(name)
|
|
126
|
-
: (0, config_1.getConfigDefaultAccountIfExists)();
|
|
124
|
+
const account = name ? (0, config_1.getConfigAccountIfExists)(name) : undefined;
|
|
127
125
|
const accountEnv = env || account?.env || environments_1.ENVIRONMENTS.PROD;
|
|
128
126
|
let parentAccountId;
|
|
129
127
|
try {
|
|
@@ -2,5 +2,5 @@ import { HubSpotConfigErrorType, HubSpotConfigOperation } from '../types/Config'
|
|
|
2
2
|
export declare class HubSpotConfigError extends Error {
|
|
3
3
|
type: HubSpotConfigErrorType;
|
|
4
4
|
operation: HubSpotConfigOperation;
|
|
5
|
-
constructor(message: string, type: HubSpotConfigErrorType, operation: HubSpotConfigOperation, options?: ErrorOptions);
|
|
5
|
+
constructor(message: string | undefined, type: HubSpotConfigErrorType, operation: HubSpotConfigOperation, options?: ErrorOptions);
|
|
6
6
|
}
|
|
@@ -4,6 +4,11 @@ exports.HubSpotConfigError = void 0;
|
|
|
4
4
|
const config_1 = require("../constants/config");
|
|
5
5
|
const lang_1 = require("../utils/lang");
|
|
6
6
|
const NAME = 'HubSpotConfigError';
|
|
7
|
+
const OPERATION_TEXT = {
|
|
8
|
+
[config_1.HUBSPOT_CONFIG_OPERATIONS.READ]: 'reading',
|
|
9
|
+
[config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE]: 'writing to',
|
|
10
|
+
[config_1.HUBSPOT_CONFIG_OPERATIONS.DELETE]: 'deleting',
|
|
11
|
+
};
|
|
7
12
|
function isEnvironmentError(type) {
|
|
8
13
|
return type === config_1.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES;
|
|
9
14
|
}
|
|
@@ -14,10 +19,10 @@ class HubSpotConfigError extends Error {
|
|
|
14
19
|
const configType = isEnvironmentError(type)
|
|
15
20
|
? 'environment variables'
|
|
16
21
|
: 'file';
|
|
17
|
-
const operationText = operation
|
|
22
|
+
const operationText = OPERATION_TEXT[operation];
|
|
18
23
|
const withBaseMessage = (0, lang_1.i18n)('models.HubSpotConfigError.baseMessage', {
|
|
19
24
|
configType,
|
|
20
|
-
message,
|
|
25
|
+
message: message ? `: ${message}` : '',
|
|
21
26
|
operation: operationText,
|
|
22
27
|
});
|
|
23
28
|
super(withBaseMessage, options);
|
package/package.json
CHANGED