@hubspot/local-dev-lib 0.5.0-experimental.2 → 0.5.0-experimental.3
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/state.d.ts +3 -3
- package/config/state.js +30 -13
- package/constants/config.d.ts +1 -0
- package/constants/config.js +2 -1
- package/http/index.js +19 -12
- package/lang/en.json +3 -0
- package/lib/portManager.js +1 -2
- package/lib/trackUsage.d.ts +2 -0
- package/lib/trackUsage.js +6 -5
- package/package.json +1 -1
- package/types/Config.d.ts +1 -1
- package/utils/PortManagerServer.d.ts +14 -15
- package/utils/PortManagerServer.js +10 -13
package/config/state.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function getStateValue<K extends keyof
|
|
3
|
-
export declare function setStateValue<K extends keyof
|
|
1
|
+
import { HubSpotState } from '../types/Config';
|
|
2
|
+
export declare function getStateValue<K extends keyof HubSpotState>(key: K): HubSpotState[K];
|
|
3
|
+
export declare function setStateValue<K extends keyof HubSpotState>(key: K, value: HubSpotState[K]): void;
|
package/config/state.js
CHANGED
|
@@ -29,9 +29,10 @@ const path = __importStar(require("path"));
|
|
|
29
29
|
const lang_1 = require("../utils/lang");
|
|
30
30
|
const config_1 = require("../constants/config");
|
|
31
31
|
const logger_1 = require("../lib/logger");
|
|
32
|
+
const config_2 = require("../constants/config");
|
|
32
33
|
const i18nKey = 'config.state';
|
|
33
34
|
const DEFAULT_STATE = {
|
|
34
|
-
|
|
35
|
+
[config_2.MCP_TOTAL_TOOL_CALLS_STATE]: 0,
|
|
35
36
|
};
|
|
36
37
|
function ensureCLIDirectory() {
|
|
37
38
|
try {
|
|
@@ -46,19 +47,41 @@ function ensureCLIDirectory() {
|
|
|
46
47
|
}));
|
|
47
48
|
}
|
|
48
49
|
}
|
|
50
|
+
function sanitizeAndMerge(parsed) {
|
|
51
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
52
|
+
return structuredClone(DEFAULT_STATE);
|
|
53
|
+
}
|
|
54
|
+
const state = parsed;
|
|
55
|
+
const result = structuredClone(DEFAULT_STATE);
|
|
56
|
+
for (const key in DEFAULT_STATE) {
|
|
57
|
+
const typedKey = key;
|
|
58
|
+
if (key in state &&
|
|
59
|
+
typeof state[typedKey] === typeof DEFAULT_STATE[typedKey]) {
|
|
60
|
+
result[typedKey] = state[typedKey];
|
|
61
|
+
}
|
|
62
|
+
// keys not in parsed file remain as DEFAULT values
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
49
66
|
function getCurrentState() {
|
|
50
67
|
try {
|
|
51
|
-
if (fs.existsSync(config_1.STATE_FILE_PATH)) {
|
|
52
|
-
|
|
53
|
-
return JSON.parse(data);
|
|
68
|
+
if (!fs.existsSync(config_1.STATE_FILE_PATH)) {
|
|
69
|
+
return structuredClone(DEFAULT_STATE);
|
|
54
70
|
}
|
|
71
|
+
const data = fs.readFileSync(config_1.STATE_FILE_PATH, 'utf-8');
|
|
72
|
+
if (!data?.trim()) {
|
|
73
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.getCurrentState.debug.emptyStateFile`));
|
|
74
|
+
return structuredClone(DEFAULT_STATE);
|
|
75
|
+
}
|
|
76
|
+
const parsed = JSON.parse(data);
|
|
77
|
+
return sanitizeAndMerge(parsed);
|
|
55
78
|
}
|
|
56
79
|
catch (error) {
|
|
57
|
-
|
|
80
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.getCurrentState.errors.errorReading`, {
|
|
58
81
|
error: error instanceof Error ? error.message : String(error),
|
|
59
82
|
}));
|
|
83
|
+
return structuredClone(DEFAULT_STATE);
|
|
60
84
|
}
|
|
61
|
-
return DEFAULT_STATE;
|
|
62
85
|
}
|
|
63
86
|
function getStateValue(key) {
|
|
64
87
|
ensureCLIDirectory();
|
|
@@ -68,13 +91,7 @@ function getStateValue(key) {
|
|
|
68
91
|
exports.getStateValue = getStateValue;
|
|
69
92
|
function setStateValue(key, value) {
|
|
70
93
|
ensureCLIDirectory();
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
currentState = getCurrentState();
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
logger_1.logger.debug(error);
|
|
77
|
-
}
|
|
94
|
+
const currentState = getCurrentState();
|
|
78
95
|
const newState = { ...currentState, [key]: value };
|
|
79
96
|
try {
|
|
80
97
|
fs.writeFileSync(config_1.STATE_FILE_PATH, JSON.stringify(newState, null, 2), 'utf-8');
|
package/constants/config.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare const ALLOW_AUTO_UPDATES = "allowAutoUpdates";
|
|
|
18
18
|
export declare const DEFAULT_ACCOUNT = "defaultAccount";
|
|
19
19
|
export declare const DEFAULT_PORTAL = "defaultPortal";
|
|
20
20
|
export declare const MIN_HTTP_TIMEOUT = 3000;
|
|
21
|
+
export declare const MCP_TOTAL_TOOL_CALLS_STATE = "mcpTotalToolCalls";
|
|
21
22
|
export declare const HUBSPOT_ACCOUNT_TYPES: {
|
|
22
23
|
readonly DEVELOPMENT_SANDBOX: "DEVELOPMENT_SANDBOX";
|
|
23
24
|
readonly DEVELOPER_TEST: "DEVELOPER_TEST";
|
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_CONFIG_OPERATIONS = exports.HUBSPOT_CONFIG_ERROR_TYPES = exports.ACCOUNT_IDENTIFIERS = exports.ENVIRONMENT_VARIABLES = exports.CONFIG_FLAGS = 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;
|
|
6
|
+
exports.HUBSPOT_CONFIG_OPERATIONS = exports.HUBSPOT_CONFIG_ERROR_TYPES = exports.ACCOUNT_IDENTIFIERS = exports.ENVIRONMENT_VARIABLES = exports.CONFIG_FLAGS = exports.HUBSPOT_ACCOUNT_TYPE_STRINGS = exports.HUBSPOT_ACCOUNT_TYPES = exports.MCP_TOTAL_TOOL_CALLS_STATE = 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"));
|
|
@@ -27,6 +27,7 @@ exports.ALLOW_AUTO_UPDATES = 'allowAutoUpdates';
|
|
|
27
27
|
exports.DEFAULT_ACCOUNT = 'defaultAccount';
|
|
28
28
|
exports.DEFAULT_PORTAL = 'defaultPortal';
|
|
29
29
|
exports.MIN_HTTP_TIMEOUT = 3000;
|
|
30
|
+
exports.MCP_TOTAL_TOOL_CALLS_STATE = 'mcpTotalToolCalls';
|
|
30
31
|
exports.HUBSPOT_ACCOUNT_TYPES = {
|
|
31
32
|
DEVELOPMENT_SANDBOX: 'DEVELOPMENT_SANDBOX',
|
|
32
33
|
DEVELOPER_TEST: 'DEVELOPER_TEST',
|
package/http/index.js
CHANGED
|
@@ -42,22 +42,29 @@ const HubSpotHttpError_1 = require("../models/HubSpotHttpError");
|
|
|
42
42
|
const auth_1 = require("../constants/auth");
|
|
43
43
|
const localDevAuth_1 = require("../api/localDevAuth");
|
|
44
44
|
const util = __importStar(require("util"));
|
|
45
|
+
const trackUsage_1 = require("../lib/trackUsage");
|
|
45
46
|
const i18nKey = 'http.index';
|
|
47
|
+
const IGNORE_URLS_NETWORK_DEBUG = [
|
|
48
|
+
localDevAuth_1.LOCALDEVAUTH_ACCESS_TOKEN_PATH,
|
|
49
|
+
trackUsage_1.CMS_CLI_USAGE_PATH,
|
|
50
|
+
trackUsage_1.VSCODE_USAGE_PATH,
|
|
51
|
+
];
|
|
46
52
|
function logRequest(response) {
|
|
47
53
|
try {
|
|
48
|
-
if (process.env.HUBSPOT_NETWORK_LOGGING) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
method: response.config.method,
|
|
55
|
-
baseURL: response.config.baseURL,
|
|
56
|
-
url: response.config.url,
|
|
57
|
-
data: response.data,
|
|
58
|
-
status: response.status,
|
|
59
|
-
}, false, null, true));
|
|
54
|
+
if (!process.env.HUBSPOT_NETWORK_LOGGING) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (response?.config?.url &&
|
|
58
|
+
IGNORE_URLS_NETWORK_DEBUG.includes(response.config.url)) {
|
|
59
|
+
return;
|
|
60
60
|
}
|
|
61
|
+
logger_1.logger.debug(util.inspect({
|
|
62
|
+
method: response.config.method,
|
|
63
|
+
baseURL: response.config.baseURL,
|
|
64
|
+
url: response.config.url,
|
|
65
|
+
data: response.data,
|
|
66
|
+
status: response.status,
|
|
67
|
+
}, false, null, true));
|
|
61
68
|
}
|
|
62
69
|
catch (error) {
|
|
63
70
|
// Ignore any errors that occur while logging the response
|
package/lang/en.json
CHANGED
package/lib/portManager.js
CHANGED
|
@@ -7,11 +7,10 @@ exports.portManagerHasActiveServers = exports.deleteServerInstance = exports.get
|
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const PortManagerServer_1 = require("../utils/PortManagerServer");
|
|
9
9
|
const ports_1 = require("../constants/ports");
|
|
10
|
-
const detectPort_1 = require("../utils/detectPort");
|
|
11
10
|
const logger_1 = require("./logger");
|
|
12
11
|
exports.BASE_URL = `http://localhost:${ports_1.PORT_MANAGER_SERVER_PORT}`;
|
|
13
12
|
async function isPortManagerPortAvailable() {
|
|
14
|
-
return
|
|
13
|
+
return PortManagerServer_1.PortManagerServer.portAvailable();
|
|
15
14
|
}
|
|
16
15
|
exports.isPortManagerPortAvailable = isPortManagerPortAvailable;
|
|
17
16
|
async function isPortManagerServerRunning() {
|
package/lib/trackUsage.d.ts
CHANGED
package/lib/trackUsage.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.trackUsage = void 0;
|
|
6
|
+
exports.trackUsage = exports.VSCODE_USAGE_PATH = exports.CMS_CLI_USAGE_PATH = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const getAxiosConfig_1 = require("../http/getAxiosConfig");
|
|
9
9
|
const logger_1 = require("./logger");
|
|
@@ -13,6 +13,8 @@ const fileMapper_1 = require("../api/fileMapper");
|
|
|
13
13
|
const lang_1 = require("../utils/lang");
|
|
14
14
|
const environment_1 = require("./environment");
|
|
15
15
|
const i18nKey = 'lib.trackUsage';
|
|
16
|
+
exports.CMS_CLI_USAGE_PATH = `${fileMapper_1.FILE_MAPPER_API_PATH}/cms-cli-usage`;
|
|
17
|
+
exports.VSCODE_USAGE_PATH = `${fileMapper_1.FILE_MAPPER_API_PATH}/vscode-extension-usage`;
|
|
16
18
|
async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
17
19
|
const usageEvent = {
|
|
18
20
|
accountId,
|
|
@@ -24,18 +26,17 @@ async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
|
24
26
|
VSCODE_EXTENSION_INTERACTION: 'vscode-extension-interaction',
|
|
25
27
|
CLI_INTERACTION: 'cli-interaction',
|
|
26
28
|
};
|
|
27
|
-
let
|
|
29
|
+
let path = fileMapper_1.FILE_MAPPER_API_PATH;
|
|
28
30
|
switch (eventName) {
|
|
29
31
|
case EVENT_TYPES.CLI_INTERACTION:
|
|
30
|
-
|
|
32
|
+
path = exports.CMS_CLI_USAGE_PATH;
|
|
31
33
|
break;
|
|
32
34
|
case EVENT_TYPES.VSCODE_EXTENSION_INTERACTION:
|
|
33
|
-
|
|
35
|
+
path = exports.VSCODE_USAGE_PATH;
|
|
34
36
|
break;
|
|
35
37
|
default:
|
|
36
38
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.invalidEvent`, { eventName }));
|
|
37
39
|
}
|
|
38
|
-
const path = `${fileMapper_1.FILE_MAPPER_API_PATH}/${analyticsEndpoint}`;
|
|
39
40
|
const account = accountId && (0, config_1.getConfigAccountById)(accountId);
|
|
40
41
|
if (account && account.authType === 'personalaccesskey') {
|
|
41
42
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventAuthenticated`));
|
package/package.json
CHANGED
package/types/Config.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type GitInclusionResult = {
|
|
|
29
29
|
gitignoreFiles: Array<string>;
|
|
30
30
|
};
|
|
31
31
|
export type ConfigFlag = ValueOf<typeof CONFIG_FLAGS>;
|
|
32
|
-
export type
|
|
32
|
+
export type HubSpotState = {
|
|
33
33
|
mcpTotalToolCalls: number;
|
|
34
34
|
};
|
|
35
35
|
export type HubSpotConfigErrorType = ValueOf<typeof HUBSPOT_CONFIG_ERROR_TYPES>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Express
|
|
2
|
+
import { Express } from 'express';
|
|
3
3
|
import { Server } from 'http';
|
|
4
|
-
import {
|
|
4
|
+
import { ServerPortMap } from '../types/PortManager';
|
|
5
5
|
export declare const HEALTH_CHECK_PATH = "/port-manager-health-check";
|
|
6
6
|
export declare const SERVICE_HEALTHY = "OK";
|
|
7
7
|
declare class _PortManagerServer {
|
|
@@ -10,19 +10,18 @@ declare class _PortManagerServer {
|
|
|
10
10
|
serverPortMap: ServerPortMap;
|
|
11
11
|
constructor();
|
|
12
12
|
init(): Promise<void>;
|
|
13
|
-
reset
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
closeServer: (req: Request, res: Response) => void;
|
|
13
|
+
private reset;
|
|
14
|
+
portAvailable(): Promise<boolean>;
|
|
15
|
+
private listen;
|
|
16
|
+
private setupRoutes;
|
|
17
|
+
private setPort;
|
|
18
|
+
private deletePort;
|
|
19
|
+
private send404;
|
|
20
|
+
private getServers;
|
|
21
|
+
private getServerPortByInstanceId;
|
|
22
|
+
private assignPortsToServers;
|
|
23
|
+
private deleteServerInstance;
|
|
24
|
+
private closeServer;
|
|
26
25
|
}
|
|
27
26
|
export declare const PortManagerServer: _PortManagerServer;
|
|
28
27
|
export {};
|
|
@@ -8,7 +8,6 @@ const express_1 = __importDefault(require("express"));
|
|
|
8
8
|
const cors_1 = __importDefault(require("cors"));
|
|
9
9
|
const detectPort_1 = require("./detectPort");
|
|
10
10
|
const ports_1 = require("../constants/ports");
|
|
11
|
-
const errors_1 = require("../errors");
|
|
12
11
|
const logger_1 = require("../lib/logger");
|
|
13
12
|
const lang_1 = require("./lang");
|
|
14
13
|
const i18nKey = 'utils.PortManagerServer';
|
|
@@ -22,6 +21,11 @@ class _PortManagerServer {
|
|
|
22
21
|
this.serverPortMap = {};
|
|
23
22
|
}
|
|
24
23
|
async init() {
|
|
24
|
+
if (!(await this.portAvailable())) {
|
|
25
|
+
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.portInUse`, {
|
|
26
|
+
port: ports_1.PORT_MANAGER_SERVER_PORT,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
25
29
|
if (this.app) {
|
|
26
30
|
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.duplicateInstance`));
|
|
27
31
|
}
|
|
@@ -29,24 +33,17 @@ class _PortManagerServer {
|
|
|
29
33
|
this.app.use(express_1.default.json());
|
|
30
34
|
this.app.use((0, cors_1.default)());
|
|
31
35
|
this.setupRoutes();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
logger_1.logger.debug(this.server);
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
if ((0, errors_1.isSystemError)(e) && e.code === 'EADDRINUSE') {
|
|
38
|
-
throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.portInUse`, {
|
|
39
|
-
port: ports_1.PORT_MANAGER_SERVER_PORT,
|
|
40
|
-
}), { cause: e });
|
|
41
|
-
}
|
|
42
|
-
throw e;
|
|
43
|
-
}
|
|
36
|
+
this.server = await this.listen();
|
|
37
|
+
logger_1.logger.debug(this.server);
|
|
44
38
|
}
|
|
45
39
|
reset() {
|
|
46
40
|
this.app = undefined;
|
|
47
41
|
this.server = undefined;
|
|
48
42
|
this.serverPortMap = {};
|
|
49
43
|
}
|
|
44
|
+
async portAvailable() {
|
|
45
|
+
return ((await (0, detectPort_1.detectPort)(ports_1.PORT_MANAGER_SERVER_PORT)) === ports_1.PORT_MANAGER_SERVER_PORT);
|
|
46
|
+
}
|
|
50
47
|
listen() {
|
|
51
48
|
return new Promise((resolve, reject) => {
|
|
52
49
|
const server = this.app.listen(ports_1.PORT_MANAGER_SERVER_PORT, () => {
|