@hubspot/local-dev-lib 4.0.4 → 5.0.0-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/api/appsDev.d.ts +2 -2
- package/api/appsDev.js +13 -22
- package/api/crm.d.ts +2 -2
- package/api/crm.js +9 -16
- package/api/customObjects.d.ts +2 -2
- package/api/customObjects.js +13 -22
- package/api/designManager.d.ts +2 -2
- package/api/designManager.js +5 -10
- package/api/devSecrets.d.ts +2 -2
- package/api/devSecrets.js +9 -16
- package/api/developerTestAccounts.d.ts +2 -4
- package/api/developerTestAccounts.js +23 -52
- package/api/fileManager.d.ts +2 -2
- package/api/fileManager.js +14 -24
- package/api/fileMapper.d.ts +2 -3
- package/api/fileMapper.js +34 -49
- package/api/fileTransport.d.ts +1 -1
- package/api/fileTransport.js +12 -21
- package/api/fireAlarm.d.ts +2 -3
- package/api/fireAlarm.js +5 -9
- package/api/functions.d.ts +2 -2
- package/api/functions.js +11 -19
- package/api/github.d.ts +2 -4
- package/api/github.js +16 -27
- package/api/hubdb.d.ts +2 -2
- package/api/hubdb.js +19 -31
- package/api/lighthouseScore.d.ts +2 -2
- package/api/lighthouseScore.js +7 -13
- package/api/localDevAuth.d.ts +3 -6
- package/api/localDevAuth.js +10 -37
- package/api/marketplaceValidation.d.ts +2 -2
- package/api/marketplaceValidation.js +7 -13
- package/api/projects.d.ts +6 -8
- package/api/projects.js +65 -100
- package/api/sandboxHubs.d.ts +2 -5
- package/api/sandboxHubs.js +15 -42
- package/api/sandboxSync.d.ts +2 -2
- package/api/sandboxSync.js +7 -12
- package/api/secrets.d.ts +2 -2
- package/api/secrets.js +9 -16
- package/api/validateHubl.d.ts +2 -2
- package/api/validateHubl.js +3 -7
- package/config/defaultAccountOverride.d.ts +2 -1
- package/config/defaultAccountOverride.js +16 -26
- package/config/index.d.ts +4 -4
- package/config/index.js +141 -177
- package/config/migrate.d.ts +2 -2
- package/config/migrate.js +26 -37
- package/config/state.d.ts +1 -1
- package/config/state.js +17 -45
- package/config/utils.d.ts +4 -4
- package/config/utils.js +85 -108
- package/constants/api.js +3 -6
- package/constants/auth.js +9 -12
- package/constants/config.js +37 -43
- package/constants/endpoints.d.ts +6 -0
- package/constants/endpoints.js +6 -0
- package/constants/environments.js +1 -4
- package/constants/extensions.js +6 -9
- package/constants/files.js +5 -8
- package/constants/ports.js +3 -6
- package/constants/projects.js +2 -5
- package/enums/build.d.ts +1 -0
- package/enums/build.js +6 -8
- package/enums/deploy.js +2 -5
- package/enums/project.js +1 -4
- package/errors/index.d.ts +4 -5
- package/errors/index.js +17 -39
- package/errors/isSystemError.d.ts +2 -0
- package/errors/isSystemError.js +9 -0
- package/http/addQueryParams.d.ts +1 -1
- package/http/addQueryParams.js +1 -5
- package/http/client.js +14 -42
- package/http/getAxiosConfig.d.ts +1 -1
- package/http/getAxiosConfig.js +21 -31
- package/http/index.d.ts +2 -2
- package/http/index.js +39 -46
- package/http/unauthed.d.ts +1 -1
- package/http/unauthed.js +15 -18
- package/lang/en.json +1 -1
- package/lib/archive.d.ts +1 -3
- package/lib/archive.js +37 -67
- package/lib/cms/functions.d.ts +1 -1
- package/lib/cms/functions.js +45 -55
- package/lib/cms/handleFieldsJS.js +36 -44
- package/lib/cms/modules.d.ts +2 -2
- package/lib/cms/modules.js +49 -59
- package/lib/cms/processFieldsJs.js +17 -32
- package/lib/cms/templates.js +17 -26
- package/lib/cms/themes.js +10 -18
- package/lib/cms/uploadFolder.d.ts +4 -4
- package/lib/cms/uploadFolder.js +55 -64
- package/lib/cms/validate.d.ts +1 -1
- package/lib/cms/validate.js +11 -18
- package/lib/cms/watch.d.ts +2 -2
- package/lib/cms/watch.js +66 -73
- package/lib/crm.d.ts +1 -1
- package/lib/crm.js +15 -23
- package/lib/customObjects.d.ts +1 -1
- package/lib/customObjects.js +15 -25
- package/lib/environment.d.ts +1 -1
- package/lib/environment.js +5 -11
- package/lib/escapeRegExp.js +1 -5
- package/lib/fileManager.js +43 -51
- package/lib/fileMapper.d.ts +1 -1
- package/lib/fileMapper.js +68 -84
- package/lib/fs.d.ts +1 -1
- package/lib/fs.js +18 -27
- package/lib/github.d.ts +1 -3
- package/lib/github.js +39 -51
- package/lib/gitignore.d.ts +1 -1
- package/lib/gitignore.js +16 -24
- package/lib/hubdb.d.ts +1 -1
- package/lib/hubdb.js +29 -40
- package/lib/ignoreRules.js +25 -34
- package/lib/isDeepEqual.js +1 -5
- package/lib/logger.d.ts +8 -20
- package/lib/logger.js +47 -59
- package/lib/notify.js +9 -16
- package/lib/oauth.d.ts +2 -2
- package/lib/oauth.js +12 -17
- package/lib/path.d.ts +0 -1
- package/lib/path.js +30 -48
- package/lib/personalAccessKey.d.ts +2 -4
- package/lib/personalAccessKey.js +43 -60
- package/lib/portManager.d.ts +2 -2
- package/lib/portManager.js +26 -41
- package/lib/text.js +2 -7
- package/lib/trackUsage.d.ts +0 -2
- package/lib/trackUsage.js +23 -29
- package/lib/urls.js +4 -9
- package/models/FileSystemError.d.ts +1 -1
- package/models/FileSystemError.js +12 -16
- package/models/HubSpotConfigError.d.ts +1 -1
- package/models/HubSpotConfigError.js +8 -12
- package/models/HubSpotHttpError.d.ts +1 -1
- package/models/HubSpotHttpError.js +22 -26
- package/models/OAuth2Manager.d.ts +1 -1
- package/models/OAuth2Manager.js +17 -24
- package/package.json +20 -16
- package/types/Accounts.d.ts +6 -5
- package/types/Accounts.js +1 -2
- package/types/Activity.d.ts +3 -3
- package/types/Activity.js +1 -2
- package/types/Api.d.ts +1 -1
- package/types/Api.js +1 -2
- package/types/Apps.js +1 -2
- package/types/Archive.js +1 -2
- package/types/Build.d.ts +4 -5
- package/types/Build.js +1 -2
- package/types/CLIOptions.js +1 -2
- package/types/ComponentStructure.d.ts +2 -2
- package/types/ComponentStructure.js +1 -2
- package/types/Config.d.ts +4 -6
- package/types/Config.js +1 -2
- package/types/Crm.js +1 -2
- package/types/Deploy.d.ts +5 -11
- package/types/Deploy.js +1 -2
- package/types/DesignManager.js +1 -2
- package/types/DevSecrets.js +1 -2
- package/types/Error.js +1 -2
- package/types/FieldsJS.js +1 -2
- package/types/FileManager.js +1 -2
- package/types/Files.d.ts +4 -4
- package/types/Files.js +1 -2
- package/types/FireAlarm.js +1 -2
- package/types/Functions.js +1 -2
- package/types/Github.d.ts +1 -1
- package/types/Github.js +1 -2
- package/types/Http.d.ts +0 -4
- package/types/Http.js +1 -2
- package/types/Hubdb.js +1 -2
- package/types/HublValidation.js +1 -2
- package/types/Lang.d.ts +1 -1
- package/types/Lang.js +1 -2
- package/types/Lighthouse.js +1 -2
- package/types/MarketplaceValidation.js +1 -2
- package/types/Migration.d.ts +2 -2
- package/types/Migration.js +1 -4
- package/types/Modules.js +1 -2
- package/types/PortManager.js +1 -2
- package/types/Project.d.ts +3 -21
- package/types/Project.js +1 -2
- package/types/ProjectComponents.d.ts +24 -0
- package/types/ProjectComponents.js +1 -0
- package/types/ProjectLog.js +1 -2
- package/types/Sandbox.js +2 -5
- package/types/Schemas.js +1 -2
- package/types/Secrets.js +1 -2
- package/types/Utils.js +1 -2
- package/types/developerTestAccounts.js +1 -2
- package/utils/PortManagerServer.d.ts +1 -2
- package/utils/PortManagerServer.js +32 -38
- package/utils/cms/fieldsJS.d.ts +1 -1
- package/utils/cms/fieldsJS.js +1 -5
- package/utils/cms/modules.d.ts +1 -1
- package/utils/cms/modules.js +13 -22
- package/utils/detectPort.js +12 -19
- package/utils/git.js +17 -26
- package/utils/lang.d.ts +1 -1
- package/utils/lang.js +5 -14
- package/utils/personalAccessKey.d.ts +8 -0
- package/utils/personalAccessKey.js +51 -0
- package/errors/errors_DEPRECATED.d.ts +0 -3
- package/errors/errors_DEPRECATED.js +0 -60
package/lib/personalAccessKey.js
CHANGED
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const localDevAuth_1 = require("../api/localDevAuth");
|
|
11
|
-
const sandboxHubs_1 = require("../api/sandboxHubs");
|
|
12
|
-
const config_1 = require("../config");
|
|
13
|
-
const config_2 = require("../constants/config");
|
|
14
|
-
const developerTestAccounts_1 = require("../api/developerTestAccounts");
|
|
15
|
-
const logger_1 = require("./logger");
|
|
16
|
-
const lang_1 = require("../utils/lang");
|
|
17
|
-
const errors_1 = require("../errors");
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
import { ENVIRONMENTS } from '../constants/environments.js';
|
|
3
|
+
import { PERSONAL_ACCESS_KEY_AUTH_METHOD } from '../constants/auth.js';
|
|
4
|
+
import { fetchAccessToken, fetchSandboxHubData, fetchDeveloperTestAccountData, } from '../utils/personalAccessKey.js';
|
|
5
|
+
import { getConfigAccountById, getConfigAccountIfExists, updateConfigAccount, addConfigAccount, setConfigAccountAsDefault, } from '../config/index.js';
|
|
6
|
+
import { HUBSPOT_ACCOUNT_TYPES } from '../constants/config.js';
|
|
7
|
+
import { logger } from './logger.js';
|
|
8
|
+
import { i18n } from '../utils/lang.js';
|
|
9
|
+
import { isHubSpotHttpError } from '../errors/index.js';
|
|
18
10
|
const i18nKey = 'lib.personalAccessKey';
|
|
19
11
|
const refreshRequests = new Map();
|
|
20
12
|
function getRefreshKey(personalAccessKey, expiration) {
|
|
21
13
|
return `${personalAccessKey}-${expiration || 'fresh'}`;
|
|
22
14
|
}
|
|
23
|
-
async function getAccessToken(personalAccessKey, env =
|
|
24
|
-
const axiosResponse = await
|
|
15
|
+
export async function getAccessToken(personalAccessKey, env = ENVIRONMENTS.PROD, accountId) {
|
|
16
|
+
const axiosResponse = await fetchAccessToken(personalAccessKey, env, accountId);
|
|
25
17
|
const response = axiosResponse.data;
|
|
26
18
|
return {
|
|
27
19
|
portalId: response.hubId,
|
|
28
20
|
accessToken: response.oauthAccessToken,
|
|
29
|
-
expiresAt: (
|
|
21
|
+
expiresAt: moment(response.expiresAtMillis).toISOString(),
|
|
30
22
|
scopeGroups: response.scopeGroups,
|
|
31
23
|
enabledFeatures: response.enabledFeatures,
|
|
32
24
|
encodedOAuthRefreshToken: response.encodedOAuthRefreshToken,
|
|
@@ -34,12 +26,11 @@ async function getAccessToken(personalAccessKey, env = environments_1.ENVIRONMEN
|
|
|
34
26
|
accountType: response.accountType,
|
|
35
27
|
};
|
|
36
28
|
}
|
|
37
|
-
exports.getAccessToken = getAccessToken;
|
|
38
29
|
async function refreshAccessToken(account) {
|
|
39
30
|
const { personalAccessKey, env, accountId } = account;
|
|
40
31
|
const accessTokenResponse = await getAccessToken(personalAccessKey, env, accountId);
|
|
41
32
|
const { accessToken, expiresAt } = accessTokenResponse;
|
|
42
|
-
|
|
33
|
+
updateConfigAccount({
|
|
43
34
|
...account,
|
|
44
35
|
auth: {
|
|
45
36
|
tokenInfo: {
|
|
@@ -73,25 +64,25 @@ async function getNewAccessToken(account) {
|
|
|
73
64
|
return accessTokenResponse;
|
|
74
65
|
}
|
|
75
66
|
async function getNewAccessTokenByAccountId(accountId) {
|
|
76
|
-
const account =
|
|
67
|
+
const account = getConfigAccountById(accountId);
|
|
77
68
|
if (!account) {
|
|
78
|
-
throw new Error(
|
|
69
|
+
throw new Error(i18n(`${i18nKey}.errors.accountNotFound`, { accountId }));
|
|
79
70
|
}
|
|
80
|
-
if (account.authType !==
|
|
81
|
-
throw new Error(
|
|
71
|
+
if (account.authType !== PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
72
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidAuthType`, {
|
|
82
73
|
accountId,
|
|
83
74
|
}));
|
|
84
75
|
}
|
|
85
76
|
const accessTokenResponse = await getNewAccessToken(account);
|
|
86
77
|
return accessTokenResponse;
|
|
87
78
|
}
|
|
88
|
-
async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false) {
|
|
89
|
-
const account =
|
|
79
|
+
export async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false) {
|
|
80
|
+
const account = getConfigAccountById(accountId);
|
|
90
81
|
if (!account) {
|
|
91
|
-
throw new Error(
|
|
82
|
+
throw new Error(i18n(`${i18nKey}.errors.accountNotFound`, { accountId }));
|
|
92
83
|
}
|
|
93
|
-
if (account.authType !==
|
|
94
|
-
throw new Error(
|
|
84
|
+
if (account.authType !== PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
85
|
+
throw new Error(i18n(`${i18nKey}.errors.invalidAuthType`, {
|
|
95
86
|
accountId,
|
|
96
87
|
}));
|
|
97
88
|
}
|
|
@@ -100,34 +91,27 @@ async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false)
|
|
|
100
91
|
const authDataExists = authTokenInfo && auth?.tokenInfo?.accessToken;
|
|
101
92
|
if (!authDataExists ||
|
|
102
93
|
forceRefresh ||
|
|
103
|
-
(
|
|
94
|
+
moment().add(5, 'minutes').isAfter(moment(authTokenInfo.expiresAt))) {
|
|
104
95
|
return getNewAccessToken(account).then(tokenInfo => tokenInfo.accessToken);
|
|
105
96
|
}
|
|
106
97
|
return auth.tokenInfo?.accessToken;
|
|
107
98
|
}
|
|
108
|
-
|
|
109
|
-
async function enabledFeaturesForPersonalAccessKey(accountId) {
|
|
99
|
+
export async function enabledFeaturesForPersonalAccessKey(accountId) {
|
|
110
100
|
const accessTokenResponse = await getNewAccessTokenByAccountId(accountId);
|
|
111
101
|
return accessTokenResponse?.enabledFeatures;
|
|
112
102
|
}
|
|
113
|
-
|
|
114
|
-
async function scopesOnAccessToken(accountId) {
|
|
103
|
+
export async function scopesOnAccessToken(accountId) {
|
|
115
104
|
return (await getNewAccessTokenByAccountId(accountId)).scopeGroups;
|
|
116
105
|
}
|
|
117
|
-
|
|
118
|
-
async function authorizedScopesForPortalAndUser(accountId) {
|
|
119
|
-
return (await (0, localDevAuth_1.fetchScopeAuthorizationData)(accountId)).data.results;
|
|
120
|
-
}
|
|
121
|
-
exports.authorizedScopesForPortalAndUser = authorizedScopesForPortalAndUser;
|
|
122
|
-
async function updateConfigWithAccessToken(token, personalAccessKey, env, name, makeDefault = false) {
|
|
106
|
+
export async function updateConfigWithAccessToken(token, personalAccessKey, env, name, makeDefault = false) {
|
|
123
107
|
const { portalId, accessToken, expiresAt, accountType } = token;
|
|
124
|
-
const account =
|
|
125
|
-
const accountEnv = env || account?.env ||
|
|
108
|
+
const account = getConfigAccountIfExists(portalId);
|
|
109
|
+
const accountEnv = env || account?.env || ENVIRONMENTS.PROD;
|
|
126
110
|
let parentAccountId;
|
|
127
111
|
try {
|
|
128
|
-
if (accountType ===
|
|
129
|
-
accountType ===
|
|
130
|
-
const { data: sandboxDataResponse } = await
|
|
112
|
+
if (accountType === HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX ||
|
|
113
|
+
accountType === HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
|
|
114
|
+
const { data: sandboxDataResponse } = await fetchSandboxHubData(accessToken, portalId, accountEnv);
|
|
131
115
|
if (sandboxDataResponse.parentHubId) {
|
|
132
116
|
parentAccountId = sandboxDataResponse.parentHubId;
|
|
133
117
|
}
|
|
@@ -135,14 +119,14 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
|
|
|
135
119
|
}
|
|
136
120
|
catch (err) {
|
|
137
121
|
// Log error but do not throw
|
|
138
|
-
if (
|
|
139
|
-
|
|
122
|
+
if (isHubSpotHttpError(err)) {
|
|
123
|
+
logger.debug(err.message);
|
|
140
124
|
}
|
|
141
|
-
|
|
125
|
+
logger.debug(err);
|
|
142
126
|
}
|
|
143
127
|
try {
|
|
144
|
-
if (accountType ===
|
|
145
|
-
const { data: developerTestAccountResponse } = await
|
|
128
|
+
if (accountType === HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST) {
|
|
129
|
+
const { data: developerTestAccountResponse } = await fetchDeveloperTestAccountData(accessToken, portalId, accountEnv);
|
|
146
130
|
if (developerTestAccountResponse) {
|
|
147
131
|
parentAccountId = developerTestAccountResponse.parentPortalId;
|
|
148
132
|
}
|
|
@@ -150,31 +134,30 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
|
|
|
150
134
|
}
|
|
151
135
|
catch (err) {
|
|
152
136
|
// Log error but do not throw
|
|
153
|
-
if (
|
|
154
|
-
|
|
137
|
+
if (isHubSpotHttpError(err)) {
|
|
138
|
+
logger.debug(err.message);
|
|
155
139
|
}
|
|
156
|
-
|
|
140
|
+
logger.debug(err);
|
|
157
141
|
}
|
|
158
142
|
const updatedAccount = {
|
|
159
143
|
accountId: portalId,
|
|
160
144
|
accountType,
|
|
161
145
|
personalAccessKey,
|
|
162
146
|
name: name || account?.name,
|
|
163
|
-
authType:
|
|
147
|
+
authType: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
164
148
|
auth: { tokenInfo: { accessToken, expiresAt } },
|
|
165
149
|
parentAccountId,
|
|
166
150
|
env: accountEnv,
|
|
167
151
|
}; // Account may temporarily not have a name before prompted to add one in the CLI
|
|
168
152
|
// Add new account if it doesn't exist, otherwise update existing account
|
|
169
153
|
if (account) {
|
|
170
|
-
|
|
154
|
+
updateConfigAccount(updatedAccount);
|
|
171
155
|
}
|
|
172
156
|
else {
|
|
173
|
-
|
|
157
|
+
addConfigAccount(updatedAccount);
|
|
174
158
|
}
|
|
175
159
|
if (makeDefault) {
|
|
176
|
-
|
|
160
|
+
setConfigAccountAsDefault(updatedAccount.accountId);
|
|
177
161
|
}
|
|
178
162
|
return updatedAccount;
|
|
179
163
|
}
|
|
180
|
-
exports.updateConfigWithAccessToken = updateConfigWithAccessToken;
|
package/lib/portManager.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RequestPortsData, ServerPortMap } from '../types/PortManager';
|
|
2
|
-
export declare const BASE_URL:
|
|
1
|
+
import { RequestPortsData, ServerPortMap } from '../types/PortManager.js';
|
|
2
|
+
export declare const BASE_URL = "http://localhost:8080";
|
|
3
3
|
export declare function isPortManagerPortAvailable(): Promise<boolean>;
|
|
4
4
|
export declare function isPortManagerServerRunning(): Promise<boolean>;
|
|
5
5
|
export declare function startPortManagerServer(): Promise<void>;
|
package/lib/portManager.js
CHANGED
|
@@ -1,66 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const logger_1 = require("./logger");
|
|
11
|
-
exports.BASE_URL = `http://localhost:${ports_1.PORT_MANAGER_SERVER_PORT}`;
|
|
12
|
-
async function isPortManagerPortAvailable() {
|
|
13
|
-
return PortManagerServer_1.PortManagerServer.portAvailable();
|
|
14
|
-
}
|
|
15
|
-
exports.isPortManagerPortAvailable = isPortManagerPortAvailable;
|
|
16
|
-
async function isPortManagerServerRunning() {
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { HEALTH_CHECK_PATH, PortManagerServer, SERVICE_HEALTHY, } from '../utils/PortManagerServer.js';
|
|
3
|
+
import { PORT_MANAGER_SERVER_PORT } from '../constants/ports.js';
|
|
4
|
+
import { logger } from './logger.js';
|
|
5
|
+
export const BASE_URL = `http://localhost:${PORT_MANAGER_SERVER_PORT}`;
|
|
6
|
+
export async function isPortManagerPortAvailable() {
|
|
7
|
+
return PortManagerServer.portAvailable();
|
|
8
|
+
}
|
|
9
|
+
export async function isPortManagerServerRunning() {
|
|
17
10
|
try {
|
|
18
|
-
const { data } = await
|
|
19
|
-
return data.status ===
|
|
11
|
+
const { data } = await axios.get(`${BASE_URL}${HEALTH_CHECK_PATH}`);
|
|
12
|
+
return data.status === SERVICE_HEALTHY;
|
|
20
13
|
}
|
|
21
14
|
catch (e) {
|
|
22
|
-
|
|
15
|
+
logger.debug(e);
|
|
23
16
|
return false;
|
|
24
17
|
}
|
|
25
18
|
}
|
|
26
|
-
|
|
27
|
-
async function startPortManagerServer() {
|
|
19
|
+
export async function startPortManagerServer() {
|
|
28
20
|
const isRunning = await isPortManagerServerRunning();
|
|
29
21
|
if (!isRunning) {
|
|
30
|
-
await
|
|
22
|
+
await PortManagerServer.init();
|
|
31
23
|
}
|
|
32
24
|
}
|
|
33
|
-
|
|
34
|
-
async function stopPortManagerServer() {
|
|
25
|
+
export async function stopPortManagerServer() {
|
|
35
26
|
const isRunning = await isPortManagerServerRunning();
|
|
36
27
|
if (isRunning) {
|
|
37
|
-
await
|
|
28
|
+
await axios.post(`${BASE_URL}/close`);
|
|
38
29
|
}
|
|
39
30
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const { data } = await axios_1.default.post(`${exports.BASE_URL}/servers`, {
|
|
31
|
+
export async function requestPorts(portData) {
|
|
32
|
+
const { data } = await axios.post(`${BASE_URL}/servers`, {
|
|
43
33
|
portData: portData,
|
|
44
34
|
});
|
|
45
35
|
return data.ports;
|
|
46
36
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const { data } = await axios_1.default.get(`${exports.BASE_URL}/servers`);
|
|
37
|
+
export async function getActiveServers() {
|
|
38
|
+
const { data } = await axios.get(`${BASE_URL}/servers`);
|
|
50
39
|
return data.servers;
|
|
51
40
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const { data } = await axios_1.default.get(`${exports.BASE_URL}/servers/${serverInstanceId}`);
|
|
41
|
+
export async function getServerPortByInstanceId(serverInstanceId) {
|
|
42
|
+
const { data } = await axios.get(`${BASE_URL}/servers/${serverInstanceId}`);
|
|
55
43
|
return data.port;
|
|
56
44
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
await axios_1.default.delete(`${exports.BASE_URL}/servers/${serverInstanceId}`);
|
|
45
|
+
export async function deleteServerInstance(serverInstanceId) {
|
|
46
|
+
await axios.delete(`${BASE_URL}/servers/${serverInstanceId}`);
|
|
60
47
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const { data } = await axios_1.default.get(`${exports.BASE_URL}/servers`);
|
|
48
|
+
export async function portManagerHasActiveServers() {
|
|
49
|
+
const { data } = await axios.get(`${BASE_URL}/servers`);
|
|
64
50
|
return data.count > 0;
|
|
65
51
|
}
|
|
66
|
-
exports.portManagerHasActiveServers = portManagerHasActiveServers;
|
package/lib/text.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toKebabCase = exports.commaSeparatedValues = void 0;
|
|
4
|
-
function commaSeparatedValues(arr, conjunction = 'and', ifempty = '') {
|
|
1
|
+
export function commaSeparatedValues(arr, conjunction = 'and', ifempty = '') {
|
|
5
2
|
const l = arr.length;
|
|
6
3
|
if (!l)
|
|
7
4
|
return ifempty;
|
|
@@ -13,8 +10,7 @@ function commaSeparatedValues(arr, conjunction = 'and', ifempty = '') {
|
|
|
13
10
|
arr[l - 1] = `${conjunction} ${arr[l - 1]}`;
|
|
14
11
|
return arr.join(', ');
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
function toKebabCase(str) {
|
|
13
|
+
export function toKebabCase(str) {
|
|
18
14
|
if (!str) {
|
|
19
15
|
return '';
|
|
20
16
|
}
|
|
@@ -24,4 +20,3 @@ function toKebabCase(str) {
|
|
|
24
20
|
.join('-')
|
|
25
21
|
.toLowerCase();
|
|
26
22
|
}
|
|
27
|
-
exports.toKebabCase = toKebabCase;
|
package/lib/trackUsage.d.ts
CHANGED
package/lib/trackUsage.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const fileMapper_1 = require("../api/fileMapper");
|
|
10
|
-
const lang_1 = require("../utils/lang");
|
|
11
|
-
const environment_1 = require("./environment");
|
|
1
|
+
import { httpClient } from '../http/client.js';
|
|
2
|
+
import { getAxiosConfig } from '../http/getAxiosConfig.js';
|
|
3
|
+
import { logger } from './logger.js';
|
|
4
|
+
import { http } from '../http/index.js';
|
|
5
|
+
import { getConfigAccountById, getConfigAccountEnvironment, } from '../config/index.js';
|
|
6
|
+
import { FILE_MAPPER_API_PATH, CMS_CLI_USAGE_PATH, VSCODE_USAGE_PATH, } from '../constants/endpoints.js';
|
|
7
|
+
import { i18n } from '../utils/lang.js';
|
|
8
|
+
import { getValidEnv } from './environment.js';
|
|
12
9
|
const i18nKey = 'lib.trackUsage';
|
|
13
|
-
|
|
14
|
-
exports.VSCODE_USAGE_PATH = `${fileMapper_1.FILE_MAPPER_API_PATH}/vscode-extension-usage`;
|
|
15
|
-
async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
10
|
+
export async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
16
11
|
const usageEvent = {
|
|
17
12
|
accountId,
|
|
18
13
|
eventName,
|
|
@@ -23,22 +18,22 @@ async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
|
23
18
|
VSCODE_EXTENSION_INTERACTION: 'vscode-extension-interaction',
|
|
24
19
|
CLI_INTERACTION: 'cli-interaction',
|
|
25
20
|
};
|
|
26
|
-
let path =
|
|
21
|
+
let path = FILE_MAPPER_API_PATH;
|
|
27
22
|
switch (eventName) {
|
|
28
23
|
case EVENT_TYPES.CLI_INTERACTION:
|
|
29
|
-
path =
|
|
24
|
+
path = CMS_CLI_USAGE_PATH;
|
|
30
25
|
break;
|
|
31
26
|
case EVENT_TYPES.VSCODE_EXTENSION_INTERACTION:
|
|
32
|
-
path =
|
|
27
|
+
path = VSCODE_USAGE_PATH;
|
|
33
28
|
break;
|
|
34
29
|
default:
|
|
35
|
-
|
|
30
|
+
logger.debug(i18n(`${i18nKey}.invalidEvent`, { eventName }));
|
|
36
31
|
}
|
|
37
|
-
const account = accountId &&
|
|
32
|
+
const account = accountId && getConfigAccountById(accountId);
|
|
38
33
|
if (account && account.authType === 'personalaccesskey') {
|
|
39
|
-
|
|
34
|
+
logger.debug(i18n(`${i18nKey}.sendingEventAuthenticated`));
|
|
40
35
|
try {
|
|
41
|
-
await
|
|
36
|
+
await http.post(accountId, {
|
|
42
37
|
url: `${path}/authenticated`,
|
|
43
38
|
data: usageEvent,
|
|
44
39
|
resolveWithFullResponse: true,
|
|
@@ -46,24 +41,23 @@ async function trackUsage(eventName, eventClass, meta = {}, accountId) {
|
|
|
46
41
|
return;
|
|
47
42
|
}
|
|
48
43
|
catch (e) {
|
|
49
|
-
|
|
44
|
+
logger.debug(i18n(`${i18nKey}.retryingEventUnauthenticated`));
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
47
|
const env = accountId
|
|
53
|
-
?
|
|
54
|
-
:
|
|
55
|
-
const axiosConfig =
|
|
48
|
+
? getConfigAccountEnvironment(accountId)
|
|
49
|
+
: getValidEnv();
|
|
50
|
+
const axiosConfig = getAxiosConfig({
|
|
56
51
|
env,
|
|
57
52
|
url: path,
|
|
58
53
|
data: usageEvent,
|
|
59
54
|
resolveWithFullResponse: true,
|
|
60
55
|
});
|
|
61
|
-
|
|
56
|
+
logger.debug(i18n(`${i18nKey}.sendingEventUnauthenticated`));
|
|
62
57
|
try {
|
|
63
|
-
await
|
|
58
|
+
await httpClient({ ...axiosConfig, method: 'post' });
|
|
64
59
|
}
|
|
65
60
|
catch (e) {
|
|
66
|
-
|
|
61
|
+
logger.debug(i18n(`${i18nKey}.unauthenticatedSendFailed`));
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
|
-
exports.trackUsage = trackUsage;
|
package/lib/urls.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHubSpotApiOrigin = exports.getHubSpotWebsiteOrigin = void 0;
|
|
4
|
-
const environments_1 = require("../constants/environments");
|
|
1
|
+
import { ENVIRONMENTS } from '../constants/environments.js';
|
|
5
2
|
function getEnvUrlString(env) {
|
|
6
3
|
if (typeof env !== 'string') {
|
|
7
4
|
return '';
|
|
8
5
|
}
|
|
9
|
-
return env.toLowerCase() ===
|
|
6
|
+
return env.toLowerCase() === ENVIRONMENTS.QA ? ENVIRONMENTS.QA : '';
|
|
10
7
|
}
|
|
11
|
-
const getHubSpotWebsiteOrigin = (env) => `https://app.hubspot${getEnvUrlString(env)}.com`;
|
|
12
|
-
|
|
13
|
-
function getHubSpotApiOrigin(env, useLocalHost) {
|
|
8
|
+
export const getHubSpotWebsiteOrigin = (env) => `https://app.hubspot${getEnvUrlString(env)}.com`;
|
|
9
|
+
export function getHubSpotApiOrigin(env, useLocalHost) {
|
|
14
10
|
let domain;
|
|
15
11
|
const domainOverride = process.env.HUBAPI_DOMAIN_OVERRIDE;
|
|
16
12
|
if (domainOverride && typeof domainOverride === 'string') {
|
|
@@ -21,4 +17,3 @@ function getHubSpotApiOrigin(env, useLocalHost) {
|
|
|
21
17
|
}
|
|
22
18
|
return `https://${domain}.com`;
|
|
23
19
|
}
|
|
24
|
-
exports.getHubSpotApiOrigin = getHubSpotApiOrigin;
|
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FileSystemError = exports.FilerSystemErrorName = void 0;
|
|
4
|
-
const lang_1 = require("../utils/lang");
|
|
5
|
-
const errors_1 = require("../errors");
|
|
1
|
+
import { i18n } from '../utils/lang.js';
|
|
2
|
+
import { isSystemError } from '../errors/isSystemError.js';
|
|
6
3
|
const i18nKey = 'errors.fileSystemErrors';
|
|
7
|
-
|
|
8
|
-
class FileSystemError extends Error {
|
|
4
|
+
export const FilerSystemErrorName = 'FilerSystemError';
|
|
5
|
+
export class FileSystemError extends Error {
|
|
9
6
|
context;
|
|
10
7
|
constructor(options, context) {
|
|
11
8
|
super('', options);
|
|
12
|
-
this.name =
|
|
9
|
+
this.name = FilerSystemErrorName;
|
|
13
10
|
this.context = context;
|
|
14
11
|
if (context) {
|
|
15
12
|
let fileAction = '';
|
|
16
13
|
if (context.operation === 'read') {
|
|
17
|
-
fileAction =
|
|
14
|
+
fileAction = i18n(`${i18nKey}.readAction`);
|
|
18
15
|
}
|
|
19
16
|
else if (context.operation === 'write') {
|
|
20
|
-
fileAction =
|
|
17
|
+
fileAction = i18n(`${i18nKey}.writeAction`);
|
|
21
18
|
}
|
|
22
19
|
else {
|
|
23
|
-
fileAction =
|
|
20
|
+
fileAction = i18n(`${i18nKey}.otherAction`);
|
|
24
21
|
}
|
|
25
22
|
const filepath = context.filepath
|
|
26
23
|
? `"${context.filepath}"`
|
|
27
|
-
:
|
|
24
|
+
: i18n(`${i18nKey}.unknownFilepath`);
|
|
28
25
|
const messages = [
|
|
29
|
-
|
|
26
|
+
i18n(`${i18nKey}.baseMessage`, { fileAction, filepath }),
|
|
30
27
|
];
|
|
31
28
|
// Many `fs` errors will be `SystemError`s
|
|
32
|
-
if (
|
|
33
|
-
messages.push(
|
|
29
|
+
if (isSystemError(options?.cause)) {
|
|
30
|
+
messages.push(i18n(`${i18nKey}.baseMessage`, {
|
|
34
31
|
errorMessage: options?.cause?.message || '',
|
|
35
32
|
}));
|
|
36
33
|
}
|
|
@@ -45,4 +42,3 @@ class FileSystemError extends Error {
|
|
|
45
42
|
return baseString;
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
|
-
exports.FileSystemError = FileSystemError;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HubSpotConfigErrorType, HubSpotConfigOperation } from '../types/Config';
|
|
1
|
+
import { HubSpotConfigErrorType, HubSpotConfigOperation } from '../types/Config.js';
|
|
2
2
|
export declare class HubSpotConfigError extends Error {
|
|
3
3
|
type: HubSpotConfigErrorType;
|
|
4
4
|
operation: HubSpotConfigOperation;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.HubSpotConfigError = void 0;
|
|
4
|
-
const config_1 = require("../constants/config");
|
|
5
|
-
const lang_1 = require("../utils/lang");
|
|
1
|
+
import { HUBSPOT_CONFIG_ERROR_TYPES, HUBSPOT_CONFIG_OPERATIONS, } from '../constants/config.js';
|
|
2
|
+
import { i18n } from '../utils/lang.js';
|
|
6
3
|
const NAME = 'HubSpotConfigError';
|
|
7
4
|
const OPERATION_TEXT = {
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
5
|
+
[HUBSPOT_CONFIG_OPERATIONS.READ]: 'reading',
|
|
6
|
+
[HUBSPOT_CONFIG_OPERATIONS.WRITE]: 'writing to',
|
|
7
|
+
[HUBSPOT_CONFIG_OPERATIONS.DELETE]: 'deleting',
|
|
11
8
|
};
|
|
12
9
|
function isEnvironmentError(type) {
|
|
13
|
-
return type ===
|
|
10
|
+
return type === HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES;
|
|
14
11
|
}
|
|
15
|
-
class HubSpotConfigError extends Error {
|
|
12
|
+
export class HubSpotConfigError extends Error {
|
|
16
13
|
type;
|
|
17
14
|
operation;
|
|
18
15
|
constructor(message, type, operation, options) {
|
|
@@ -20,7 +17,7 @@ class HubSpotConfigError extends Error {
|
|
|
20
17
|
? 'environment variables'
|
|
21
18
|
: 'file';
|
|
22
19
|
const operationText = OPERATION_TEXT[operation];
|
|
23
|
-
const withBaseMessage =
|
|
20
|
+
const withBaseMessage = i18n('models.HubSpotConfigError.baseMessage', {
|
|
24
21
|
configType,
|
|
25
22
|
message: message ? `: ${message}` : '',
|
|
26
23
|
operation: operationText,
|
|
@@ -31,4 +28,3 @@ class HubSpotConfigError extends Error {
|
|
|
31
28
|
this.operation = operation;
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
|
-
exports.HubSpotConfigError = HubSpotConfigError;
|