@hubspot/local-dev-lib 3.21.0 → 3.21.1-beta.1
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/CLIConfiguration.js +11 -8
- package/config/configUtils.js +2 -2
- package/config/migrate.js +2 -0
- package/config/state.d.ts +3 -0
- package/config/state.js +104 -0
- package/constants/config.d.ts +4 -0
- package/constants/config.js +5 -1
- package/lang/en.json +20 -0
- package/package.json +2 -1
- package/types/Config.d.ts +4 -1
- package/utils/accounts.js +2 -2
|
@@ -46,7 +46,7 @@ class _CLIConfiguration {
|
|
|
46
46
|
const configFromEnv = (0, environment_1.loadConfigFromEnvironment)();
|
|
47
47
|
if (configFromEnv) {
|
|
48
48
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.load.configFromEnv`, {
|
|
49
|
-
accountId: configFromEnv.accounts[0].accountId
|
|
49
|
+
accountId: `${configFromEnv.accounts?.[0].accountId}`,
|
|
50
50
|
}));
|
|
51
51
|
this.useEnvConfig = true;
|
|
52
52
|
this.config = this.handleLegacyCmsPublishMode(configFromEnv);
|
|
@@ -168,11 +168,11 @@ class _CLIConfiguration {
|
|
|
168
168
|
}
|
|
169
169
|
let account = null;
|
|
170
170
|
if (name) {
|
|
171
|
-
account = this.config.accounts
|
|
171
|
+
account = this.config.accounts?.find(a => a.name === name) || null;
|
|
172
172
|
}
|
|
173
173
|
if (accountId && !account) {
|
|
174
174
|
account =
|
|
175
|
-
this.config.accounts
|
|
175
|
+
this.config.accounts?.find(a => accountId === a.accountId) || null;
|
|
176
176
|
}
|
|
177
177
|
return account;
|
|
178
178
|
}
|
|
@@ -230,7 +230,7 @@ class _CLIConfiguration {
|
|
|
230
230
|
return account.name || account.accountId;
|
|
231
231
|
}
|
|
232
232
|
getAccountIndex(accountId) {
|
|
233
|
-
return this.config
|
|
233
|
+
return this.config && Array.isArray(this.config.accounts)
|
|
234
234
|
? this.config.accounts.findIndex(account => account.accountId === accountId)
|
|
235
235
|
: -1;
|
|
236
236
|
}
|
|
@@ -243,10 +243,10 @@ class _CLIConfiguration {
|
|
|
243
243
|
isAccountInConfig(nameOrId) {
|
|
244
244
|
if (typeof nameOrId === 'string') {
|
|
245
245
|
return (!!this.config &&
|
|
246
|
-
this.config.accounts &&
|
|
246
|
+
!!this.config.accounts &&
|
|
247
247
|
!!this.getAccountId(nameOrId.toLowerCase()));
|
|
248
248
|
}
|
|
249
|
-
return (!!this.config && this.config.accounts && !!this.getAccountId(nameOrId));
|
|
249
|
+
return (!!this.config && !!this.config.accounts && !!this.getAccountId(nameOrId));
|
|
250
250
|
}
|
|
251
251
|
getAndLoadConfigIfNeeded(options) {
|
|
252
252
|
if (!this.config) {
|
|
@@ -341,7 +341,7 @@ class _CLIConfiguration {
|
|
|
341
341
|
safelyApplyUpdates('accountType', this.getAccountType(updatedAccountType, sandboxAccountType));
|
|
342
342
|
safelyApplyUpdates('parentAccountId', parentAccountId);
|
|
343
343
|
const completedAccountConfig = nextAccountConfig;
|
|
344
|
-
if (!
|
|
344
|
+
if (!Array.isArray(this.config.accounts)) {
|
|
345
345
|
this.config.accounts = [];
|
|
346
346
|
}
|
|
347
347
|
if (currentAccountConfig) {
|
|
@@ -429,7 +429,10 @@ class _CLIConfiguration {
|
|
|
429
429
|
if (accountConfig) {
|
|
430
430
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.removeAccountFromConfig.deleting`, { accountId }));
|
|
431
431
|
const index = this.getAccountIndex(accountId);
|
|
432
|
-
|
|
432
|
+
if (index === -1) {
|
|
433
|
+
return removedAccountIsDefault;
|
|
434
|
+
}
|
|
435
|
+
this.config.accounts?.splice(index, 1);
|
|
433
436
|
if (this.getDefaultAccount() === accountConfig.name) {
|
|
434
437
|
removedAccountIsDefault = true;
|
|
435
438
|
}
|
package/config/configUtils.js
CHANGED
|
@@ -24,7 +24,7 @@ function getOrderedConfig(unorderedConfig) {
|
|
|
24
24
|
httpTimeout,
|
|
25
25
|
allowUsageTracking,
|
|
26
26
|
...rest,
|
|
27
|
-
accounts: accounts
|
|
27
|
+
accounts: accounts?.map(getOrderedAccount) || [],
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
exports.getOrderedConfig = getOrderedConfig;
|
|
@@ -80,7 +80,7 @@ function generateConfig(type, options) {
|
|
|
80
80
|
return null;
|
|
81
81
|
}
|
|
82
82
|
if (configAccount) {
|
|
83
|
-
config.accounts
|
|
83
|
+
config.accounts?.push(configAccount);
|
|
84
84
|
}
|
|
85
85
|
return config;
|
|
86
86
|
}
|
package/config/migrate.js
CHANGED
|
@@ -105,6 +105,8 @@ function mergeConfigProperties(globalConfig, deprecatedConfig, force) {
|
|
|
105
105
|
config_1.ENV,
|
|
106
106
|
config_1.HTTP_USE_LOCALHOST,
|
|
107
107
|
config_1.ALLOW_USAGE_TRACKING,
|
|
108
|
+
config_1.AUTO_OPEN_BROWSER,
|
|
109
|
+
config_1.ALLOW_AUTO_UPDATES,
|
|
108
110
|
];
|
|
109
111
|
const conflicts = [];
|
|
110
112
|
propertiesToCheck.forEach(prop => {
|
package/config/state.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.setStateValue = exports.getStateValue = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const lang_1 = require("../utils/lang");
|
|
30
|
+
const config_1 = require("../constants/config");
|
|
31
|
+
const logger_1 = require("../lib/logger");
|
|
32
|
+
const i18nKey = 'config.state';
|
|
33
|
+
const DEFAULT_STATE = {
|
|
34
|
+
mcpTotalToolCalls: 0,
|
|
35
|
+
};
|
|
36
|
+
function ensureCLIDirectory() {
|
|
37
|
+
try {
|
|
38
|
+
const dir = path.dirname(config_1.STATE_FILE_PATH);
|
|
39
|
+
if (!fs.existsSync(dir)) {
|
|
40
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.ensureCLIDirectory.errors.cannotCreateDirectory`, {
|
|
45
|
+
error: error instanceof Error ? error.message : String(error),
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function sanitizeAndMerge(parsed) {
|
|
50
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
51
|
+
return structuredClone(DEFAULT_STATE);
|
|
52
|
+
}
|
|
53
|
+
const state = parsed;
|
|
54
|
+
const result = structuredClone(DEFAULT_STATE);
|
|
55
|
+
for (const key in DEFAULT_STATE) {
|
|
56
|
+
const typedKey = key;
|
|
57
|
+
if (key in state &&
|
|
58
|
+
typeof state[typedKey] === typeof DEFAULT_STATE[typedKey]) {
|
|
59
|
+
result[typedKey] = state[typedKey];
|
|
60
|
+
}
|
|
61
|
+
// keys not in parsed file remain as DEFAULT values
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
function getCurrentState() {
|
|
66
|
+
try {
|
|
67
|
+
if (!fs.existsSync(config_1.STATE_FILE_PATH)) {
|
|
68
|
+
return structuredClone(DEFAULT_STATE);
|
|
69
|
+
}
|
|
70
|
+
const data = fs.readFileSync(config_1.STATE_FILE_PATH, 'utf-8');
|
|
71
|
+
if (!data?.trim()) {
|
|
72
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.getCurrentState.debug.emptyStateFile`));
|
|
73
|
+
return structuredClone(DEFAULT_STATE);
|
|
74
|
+
}
|
|
75
|
+
const parsed = JSON.parse(data);
|
|
76
|
+
return sanitizeAndMerge(parsed);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.getCurrentState.errors.errorReading`, {
|
|
80
|
+
error: error instanceof Error ? error.message : String(error),
|
|
81
|
+
}));
|
|
82
|
+
return structuredClone(DEFAULT_STATE);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function getStateValue(key) {
|
|
86
|
+
ensureCLIDirectory();
|
|
87
|
+
const state = getCurrentState();
|
|
88
|
+
return state[key];
|
|
89
|
+
}
|
|
90
|
+
exports.getStateValue = getStateValue;
|
|
91
|
+
function setStateValue(key, value) {
|
|
92
|
+
ensureCLIDirectory();
|
|
93
|
+
const currentState = getCurrentState();
|
|
94
|
+
const newState = { ...currentState, [key]: value };
|
|
95
|
+
try {
|
|
96
|
+
fs.writeFileSync(config_1.STATE_FILE_PATH, JSON.stringify(newState, null, 2), 'utf-8');
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.setStateValue.errors.failedToWrite`, {
|
|
100
|
+
error: error instanceof Error ? error.message : String(error),
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.setStateValue = setStateValue;
|
package/constants/config.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ export declare const DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = "hubspot.config.yml
|
|
|
2
2
|
export declare const ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME = "archived.hubspot.config.yml";
|
|
3
3
|
export declare const HUBSPOT_CONFIGURATION_FOLDER = ".hscli";
|
|
4
4
|
export declare const HUBSPOT_CONFIGURATION_FILE = "config.yml";
|
|
5
|
+
export declare const HUBSPOT_STATE_FILE = "state.json";
|
|
5
6
|
export declare const GLOBAL_CONFIG_PATH: string;
|
|
7
|
+
export declare const STATE_FILE_PATH: string;
|
|
6
8
|
export declare const DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME = ".hsaccount";
|
|
7
9
|
export declare const DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID = "DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID";
|
|
8
10
|
export declare const DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND = "DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND";
|
|
@@ -11,6 +13,8 @@ export declare const HTTP_TIMEOUT = "httpTimeout";
|
|
|
11
13
|
export declare const ENV = "env";
|
|
12
14
|
export declare const HTTP_USE_LOCALHOST = "httpUseLocalhost";
|
|
13
15
|
export declare const ALLOW_USAGE_TRACKING = "allowUsageTracking";
|
|
16
|
+
export declare const AUTO_OPEN_BROWSER = "autoOpenBrowser";
|
|
17
|
+
export declare const ALLOW_AUTO_UPDATES = "allowAutoUpdates";
|
|
14
18
|
export declare const DEFAULT_ACCOUNT = "defaultAccount";
|
|
15
19
|
export declare const DEFAULT_PORTAL = "defaultPortal";
|
|
16
20
|
export declare const MIN_HTTP_TIMEOUT = 3000;
|
package/constants/config.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.HUBSPOT_ACCOUNT_TYPE_STRINGS = exports.HUBSPOT_ACCOUNT_TYPES = exports.MIN_HTTP_TIMEOUT = exports.DEFAULT_PORTAL = exports.DEFAULT_ACCOUNT = exports.ALLOW_USAGE_TRACKING = exports.HTTP_USE_LOCALHOST = exports.ENV = exports.HTTP_TIMEOUT = exports.DEFAULT_CMS_PUBLISH_MODE = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID = exports.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME = exports.GLOBAL_CONFIG_PATH = exports.HUBSPOT_CONFIGURATION_FILE = exports.HUBSPOT_CONFIGURATION_FOLDER = exports.ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME = exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = void 0;
|
|
6
|
+
exports.HUBSPOT_ACCOUNT_TYPE_STRINGS = exports.HUBSPOT_ACCOUNT_TYPES = exports.MIN_HTTP_TIMEOUT = exports.DEFAULT_PORTAL = exports.DEFAULT_ACCOUNT = exports.ALLOW_AUTO_UPDATES = exports.AUTO_OPEN_BROWSER = exports.ALLOW_USAGE_TRACKING = exports.HTTP_USE_LOCALHOST = exports.ENV = exports.HTTP_TIMEOUT = exports.DEFAULT_CMS_PUBLISH_MODE = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND = exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID = exports.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME = exports.STATE_FILE_PATH = exports.GLOBAL_CONFIG_PATH = exports.HUBSPOT_STATE_FILE = exports.HUBSPOT_CONFIGURATION_FILE = exports.HUBSPOT_CONFIGURATION_FOLDER = exports.ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME = exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = void 0;
|
|
7
7
|
const lang_1 = require("../utils/lang");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const os_1 = __importDefault(require("os"));
|
|
@@ -11,7 +11,9 @@ exports.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME = 'hubspot.config.yml';
|
|
|
11
11
|
exports.ARCHIVED_HUBSPOT_CONFIG_YAML_FILE_NAME = 'archived.hubspot.config.yml';
|
|
12
12
|
exports.HUBSPOT_CONFIGURATION_FOLDER = '.hscli';
|
|
13
13
|
exports.HUBSPOT_CONFIGURATION_FILE = 'config.yml';
|
|
14
|
+
exports.HUBSPOT_STATE_FILE = 'state.json';
|
|
14
15
|
exports.GLOBAL_CONFIG_PATH = path_1.default.join(os_1.default.homedir(), exports.HUBSPOT_CONFIGURATION_FOLDER, exports.HUBSPOT_CONFIGURATION_FILE);
|
|
16
|
+
exports.STATE_FILE_PATH = path_1.default.join(os_1.default.homedir(), exports.HUBSPOT_CONFIGURATION_FOLDER, exports.HUBSPOT_STATE_FILE);
|
|
15
17
|
exports.DEFAULT_ACCOUNT_OVERRIDE_FILE_NAME = '.hsaccount';
|
|
16
18
|
exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID = 'DEFAULT_ACCOUNT_OVERRIDE_ERROR_INVALID_ID';
|
|
17
19
|
exports.DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND = 'DEFAULT_ACCOUNT_OVERRIDE_ERROR_ACCOUNT_NOT_FOUND';
|
|
@@ -20,6 +22,8 @@ exports.HTTP_TIMEOUT = 'httpTimeout';
|
|
|
20
22
|
exports.ENV = 'env';
|
|
21
23
|
exports.HTTP_USE_LOCALHOST = 'httpUseLocalhost';
|
|
22
24
|
exports.ALLOW_USAGE_TRACKING = 'allowUsageTracking';
|
|
25
|
+
exports.AUTO_OPEN_BROWSER = 'autoOpenBrowser';
|
|
26
|
+
exports.ALLOW_AUTO_UPDATES = 'allowAutoUpdates';
|
|
23
27
|
exports.DEFAULT_ACCOUNT = 'defaultAccount';
|
|
24
28
|
exports.DEFAULT_PORTAL = 'defaultPortal';
|
|
25
29
|
exports.MIN_HTTP_TIMEOUT = 3000;
|
package/lang/en.json
CHANGED
|
@@ -320,6 +320,26 @@
|
|
|
320
320
|
"configUtils": {
|
|
321
321
|
"unknownType": "Unknown auth type {{ type }}"
|
|
322
322
|
},
|
|
323
|
+
"state": {
|
|
324
|
+
"ensureCLIDirectory": {
|
|
325
|
+
"errors": {
|
|
326
|
+
"cannotCreateDirectory": "Cannot create CLI state directory: {{ error }}"
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
"getCurrentState": {
|
|
330
|
+
"debug": {
|
|
331
|
+
"emptyStateFile": "State file is empty, using default state"
|
|
332
|
+
},
|
|
333
|
+
"errors": {
|
|
334
|
+
"errorReading": "Error reading CLI state, using defaults: {{ error }}"
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
"setStateValue": {
|
|
338
|
+
"errors": {
|
|
339
|
+
"failedToWrite": "Failed to write CLI state: {{ error }}"
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
},
|
|
323
343
|
"environment": {
|
|
324
344
|
"loadConfig": {
|
|
325
345
|
"missingAccountId": "Unable to load config from environment variables: Missing accountId",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/local-dev-lib",
|
|
3
|
-
"version": "3.21.
|
|
3
|
+
"version": "3.21.1-beta.1",
|
|
4
4
|
"description": "Provides library functionality for HubSpot local development tooling, including the HubSpot CLI",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"./http/*": "./http/*.js",
|
|
53
53
|
"./config/getAccountIdentifier": "./config/getAccountIdentifier.js",
|
|
54
54
|
"./config/migrate": "./config/migrate.js",
|
|
55
|
+
"./config/state": "./config/state.js",
|
|
55
56
|
"./config": "./config/index.js",
|
|
56
57
|
"./constants/*": "./constants/*.js",
|
|
57
58
|
"./models/*": "./models/*.js",
|
package/types/Config.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CLIAccount_NEW, CLIAccount_DEPRECATED } from './Accounts';
|
|
|
3
3
|
import { CmsPublishMode } from './Files';
|
|
4
4
|
import { ValueOf } from './Utils';
|
|
5
5
|
export interface CLIConfig_NEW {
|
|
6
|
-
accounts
|
|
6
|
+
accounts?: Array<CLIAccount_NEW>;
|
|
7
7
|
allowUsageTracking?: boolean;
|
|
8
8
|
allowAutoUpdates?: boolean;
|
|
9
9
|
defaultAccount?: string | number;
|
|
@@ -44,3 +44,6 @@ export type GitInclusionResult = {
|
|
|
44
44
|
configIgnored: boolean;
|
|
45
45
|
gitignoreFiles: Array<string>;
|
|
46
46
|
};
|
|
47
|
+
export type HubSpotState = {
|
|
48
|
+
mcpTotalToolCalls: number;
|
|
49
|
+
};
|
package/utils/accounts.js
CHANGED
|
@@ -5,10 +5,10 @@ function getAccounts(config) {
|
|
|
5
5
|
if (!config) {
|
|
6
6
|
return [];
|
|
7
7
|
}
|
|
8
|
-
else if (
|
|
8
|
+
else if ('portals' in config && Array.isArray(config.portals)) {
|
|
9
9
|
return config.portals;
|
|
10
10
|
}
|
|
11
|
-
else if (
|
|
11
|
+
else if ('accounts' in config && Array.isArray(config.accounts)) {
|
|
12
12
|
return config.accounts;
|
|
13
13
|
}
|
|
14
14
|
return [];
|