@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.
Files changed (205) hide show
  1. package/api/appsDev.d.ts +2 -2
  2. package/api/appsDev.js +13 -22
  3. package/api/crm.d.ts +2 -2
  4. package/api/crm.js +9 -16
  5. package/api/customObjects.d.ts +2 -2
  6. package/api/customObjects.js +13 -22
  7. package/api/designManager.d.ts +2 -2
  8. package/api/designManager.js +5 -10
  9. package/api/devSecrets.d.ts +2 -2
  10. package/api/devSecrets.js +9 -16
  11. package/api/developerTestAccounts.d.ts +2 -4
  12. package/api/developerTestAccounts.js +23 -52
  13. package/api/fileManager.d.ts +2 -2
  14. package/api/fileManager.js +14 -24
  15. package/api/fileMapper.d.ts +2 -3
  16. package/api/fileMapper.js +34 -49
  17. package/api/fileTransport.d.ts +1 -1
  18. package/api/fileTransport.js +12 -21
  19. package/api/fireAlarm.d.ts +2 -3
  20. package/api/fireAlarm.js +5 -9
  21. package/api/functions.d.ts +2 -2
  22. package/api/functions.js +11 -19
  23. package/api/github.d.ts +2 -4
  24. package/api/github.js +16 -27
  25. package/api/hubdb.d.ts +2 -2
  26. package/api/hubdb.js +19 -31
  27. package/api/lighthouseScore.d.ts +2 -2
  28. package/api/lighthouseScore.js +7 -13
  29. package/api/localDevAuth.d.ts +3 -6
  30. package/api/localDevAuth.js +10 -37
  31. package/api/marketplaceValidation.d.ts +2 -2
  32. package/api/marketplaceValidation.js +7 -13
  33. package/api/projects.d.ts +6 -8
  34. package/api/projects.js +65 -100
  35. package/api/sandboxHubs.d.ts +2 -5
  36. package/api/sandboxHubs.js +15 -42
  37. package/api/sandboxSync.d.ts +2 -2
  38. package/api/sandboxSync.js +7 -12
  39. package/api/secrets.d.ts +2 -2
  40. package/api/secrets.js +9 -16
  41. package/api/validateHubl.d.ts +2 -2
  42. package/api/validateHubl.js +3 -7
  43. package/config/defaultAccountOverride.d.ts +2 -1
  44. package/config/defaultAccountOverride.js +16 -26
  45. package/config/index.d.ts +4 -4
  46. package/config/index.js +141 -177
  47. package/config/migrate.d.ts +2 -2
  48. package/config/migrate.js +26 -37
  49. package/config/state.d.ts +1 -1
  50. package/config/state.js +17 -45
  51. package/config/utils.d.ts +4 -4
  52. package/config/utils.js +85 -108
  53. package/constants/api.js +3 -6
  54. package/constants/auth.js +9 -12
  55. package/constants/config.js +37 -43
  56. package/constants/endpoints.d.ts +6 -0
  57. package/constants/endpoints.js +6 -0
  58. package/constants/environments.js +1 -4
  59. package/constants/extensions.js +6 -9
  60. package/constants/files.js +5 -8
  61. package/constants/ports.js +3 -6
  62. package/constants/projects.js +2 -5
  63. package/enums/build.d.ts +1 -0
  64. package/enums/build.js +6 -8
  65. package/enums/deploy.js +2 -5
  66. package/enums/project.js +1 -4
  67. package/errors/index.d.ts +4 -5
  68. package/errors/index.js +17 -39
  69. package/errors/isSystemError.d.ts +2 -0
  70. package/errors/isSystemError.js +9 -0
  71. package/http/addQueryParams.d.ts +1 -1
  72. package/http/addQueryParams.js +1 -5
  73. package/http/client.js +14 -42
  74. package/http/getAxiosConfig.d.ts +1 -1
  75. package/http/getAxiosConfig.js +21 -31
  76. package/http/index.d.ts +2 -2
  77. package/http/index.js +39 -46
  78. package/http/unauthed.d.ts +1 -1
  79. package/http/unauthed.js +15 -18
  80. package/lang/en.json +1 -1
  81. package/lib/archive.d.ts +1 -3
  82. package/lib/archive.js +37 -67
  83. package/lib/cms/functions.d.ts +1 -1
  84. package/lib/cms/functions.js +45 -55
  85. package/lib/cms/handleFieldsJS.js +36 -44
  86. package/lib/cms/modules.d.ts +2 -2
  87. package/lib/cms/modules.js +49 -59
  88. package/lib/cms/processFieldsJs.js +17 -32
  89. package/lib/cms/templates.js +17 -26
  90. package/lib/cms/themes.js +10 -18
  91. package/lib/cms/uploadFolder.d.ts +4 -4
  92. package/lib/cms/uploadFolder.js +55 -64
  93. package/lib/cms/validate.d.ts +1 -1
  94. package/lib/cms/validate.js +11 -18
  95. package/lib/cms/watch.d.ts +2 -2
  96. package/lib/cms/watch.js +66 -73
  97. package/lib/crm.d.ts +1 -1
  98. package/lib/crm.js +15 -23
  99. package/lib/customObjects.d.ts +1 -1
  100. package/lib/customObjects.js +15 -25
  101. package/lib/environment.d.ts +1 -1
  102. package/lib/environment.js +5 -11
  103. package/lib/escapeRegExp.js +1 -5
  104. package/lib/fileManager.js +43 -51
  105. package/lib/fileMapper.d.ts +1 -1
  106. package/lib/fileMapper.js +68 -84
  107. package/lib/fs.d.ts +1 -1
  108. package/lib/fs.js +18 -27
  109. package/lib/github.d.ts +1 -3
  110. package/lib/github.js +39 -51
  111. package/lib/gitignore.d.ts +1 -1
  112. package/lib/gitignore.js +16 -24
  113. package/lib/hubdb.d.ts +1 -1
  114. package/lib/hubdb.js +29 -40
  115. package/lib/ignoreRules.js +25 -34
  116. package/lib/isDeepEqual.js +1 -5
  117. package/lib/logger.d.ts +8 -20
  118. package/lib/logger.js +47 -59
  119. package/lib/notify.js +9 -16
  120. package/lib/oauth.d.ts +2 -2
  121. package/lib/oauth.js +12 -17
  122. package/lib/path.d.ts +0 -1
  123. package/lib/path.js +30 -48
  124. package/lib/personalAccessKey.d.ts +2 -4
  125. package/lib/personalAccessKey.js +43 -60
  126. package/lib/portManager.d.ts +2 -2
  127. package/lib/portManager.js +26 -41
  128. package/lib/text.js +2 -7
  129. package/lib/trackUsage.d.ts +0 -2
  130. package/lib/trackUsage.js +23 -29
  131. package/lib/urls.js +4 -9
  132. package/models/FileSystemError.d.ts +1 -1
  133. package/models/FileSystemError.js +12 -16
  134. package/models/HubSpotConfigError.d.ts +1 -1
  135. package/models/HubSpotConfigError.js +8 -12
  136. package/models/HubSpotHttpError.d.ts +1 -1
  137. package/models/HubSpotHttpError.js +22 -26
  138. package/models/OAuth2Manager.d.ts +1 -1
  139. package/models/OAuth2Manager.js +17 -24
  140. package/package.json +20 -16
  141. package/types/Accounts.d.ts +6 -5
  142. package/types/Accounts.js +1 -2
  143. package/types/Activity.d.ts +3 -3
  144. package/types/Activity.js +1 -2
  145. package/types/Api.d.ts +1 -1
  146. package/types/Api.js +1 -2
  147. package/types/Apps.js +1 -2
  148. package/types/Archive.js +1 -2
  149. package/types/Build.d.ts +4 -5
  150. package/types/Build.js +1 -2
  151. package/types/CLIOptions.js +1 -2
  152. package/types/ComponentStructure.d.ts +2 -2
  153. package/types/ComponentStructure.js +1 -2
  154. package/types/Config.d.ts +4 -6
  155. package/types/Config.js +1 -2
  156. package/types/Crm.js +1 -2
  157. package/types/Deploy.d.ts +5 -11
  158. package/types/Deploy.js +1 -2
  159. package/types/DesignManager.js +1 -2
  160. package/types/DevSecrets.js +1 -2
  161. package/types/Error.js +1 -2
  162. package/types/FieldsJS.js +1 -2
  163. package/types/FileManager.js +1 -2
  164. package/types/Files.d.ts +4 -4
  165. package/types/Files.js +1 -2
  166. package/types/FireAlarm.js +1 -2
  167. package/types/Functions.js +1 -2
  168. package/types/Github.d.ts +1 -1
  169. package/types/Github.js +1 -2
  170. package/types/Http.d.ts +0 -4
  171. package/types/Http.js +1 -2
  172. package/types/Hubdb.js +1 -2
  173. package/types/HublValidation.js +1 -2
  174. package/types/Lang.d.ts +1 -1
  175. package/types/Lang.js +1 -2
  176. package/types/Lighthouse.js +1 -2
  177. package/types/MarketplaceValidation.js +1 -2
  178. package/types/Migration.d.ts +2 -2
  179. package/types/Migration.js +1 -4
  180. package/types/Modules.js +1 -2
  181. package/types/PortManager.js +1 -2
  182. package/types/Project.d.ts +3 -21
  183. package/types/Project.js +1 -2
  184. package/types/ProjectComponents.d.ts +24 -0
  185. package/types/ProjectComponents.js +1 -0
  186. package/types/ProjectLog.js +1 -2
  187. package/types/Sandbox.js +2 -5
  188. package/types/Schemas.js +1 -2
  189. package/types/Secrets.js +1 -2
  190. package/types/Utils.js +1 -2
  191. package/types/developerTestAccounts.js +1 -2
  192. package/utils/PortManagerServer.d.ts +1 -2
  193. package/utils/PortManagerServer.js +32 -38
  194. package/utils/cms/fieldsJS.d.ts +1 -1
  195. package/utils/cms/fieldsJS.js +1 -5
  196. package/utils/cms/modules.d.ts +1 -1
  197. package/utils/cms/modules.js +13 -22
  198. package/utils/detectPort.js +12 -19
  199. package/utils/git.js +17 -26
  200. package/utils/lang.d.ts +1 -1
  201. package/utils/lang.js +5 -14
  202. package/utils/personalAccessKey.d.ts +8 -0
  203. package/utils/personalAccessKey.js +51 -0
  204. package/errors/errors_DEPRECATED.d.ts +0 -3
  205. package/errors/errors_DEPRECATED.js +0 -60
@@ -1,32 +1,24 @@
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.updateConfigWithAccessToken = exports.authorizedScopesForPortalAndUser = exports.scopesOnAccessToken = exports.enabledFeaturesForPersonalAccessKey = exports.accessTokenForPersonalAccessKey = exports.getAccessToken = void 0;
7
- const moment_1 = __importDefault(require("moment"));
8
- const environments_1 = require("../constants/environments");
9
- const auth_1 = require("../constants/auth");
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 = environments_1.ENVIRONMENTS.PROD, accountId) {
24
- const axiosResponse = await (0, localDevAuth_1.fetchAccessToken)(personalAccessKey, env, accountId);
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: (0, moment_1.default)(response.expiresAtMillis).toISOString(),
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
- (0, config_1.updateConfigAccount)({
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 = (0, config_1.getConfigAccountById)(accountId);
67
+ const account = getConfigAccountById(accountId);
77
68
  if (!account) {
78
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
69
+ throw new Error(i18n(`${i18nKey}.errors.accountNotFound`, { accountId }));
79
70
  }
80
- if (account.authType !== auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
81
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidAuthType`, {
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 = (0, config_1.getConfigAccountById)(accountId);
79
+ export async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false) {
80
+ const account = getConfigAccountById(accountId);
90
81
  if (!account) {
91
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
82
+ throw new Error(i18n(`${i18nKey}.errors.accountNotFound`, { accountId }));
92
83
  }
93
- if (account.authType !== auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
94
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidAuthType`, {
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
- (0, moment_1.default)().add(5, 'minutes').isAfter((0, moment_1.default)(authTokenInfo.expiresAt))) {
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
- exports.accessTokenForPersonalAccessKey = accessTokenForPersonalAccessKey;
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
- exports.enabledFeaturesForPersonalAccessKey = enabledFeaturesForPersonalAccessKey;
114
- async function scopesOnAccessToken(accountId) {
103
+ export async function scopesOnAccessToken(accountId) {
115
104
  return (await getNewAccessTokenByAccountId(accountId)).scopeGroups;
116
105
  }
117
- exports.scopesOnAccessToken = scopesOnAccessToken;
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 = (0, config_1.getConfigAccountIfExists)(portalId);
125
- const accountEnv = env || account?.env || environments_1.ENVIRONMENTS.PROD;
108
+ const account = getConfigAccountIfExists(portalId);
109
+ const accountEnv = env || account?.env || ENVIRONMENTS.PROD;
126
110
  let parentAccountId;
127
111
  try {
128
- if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX ||
129
- accountType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
130
- const { data: sandboxDataResponse } = await (0, sandboxHubs_1.fetchSandboxHubData)(accessToken, portalId, accountEnv);
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 ((0, errors_1.isHubSpotHttpError)(err)) {
139
- logger_1.logger.debug(err.message);
122
+ if (isHubSpotHttpError(err)) {
123
+ logger.debug(err.message);
140
124
  }
141
- logger_1.logger.debug(err);
125
+ logger.debug(err);
142
126
  }
143
127
  try {
144
- if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST) {
145
- const { data: developerTestAccountResponse } = await (0, developerTestAccounts_1.fetchDeveloperTestAccountData)(accessToken, portalId, accountEnv);
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 ((0, errors_1.isHubSpotHttpError)(err)) {
154
- logger_1.logger.debug(err.message);
137
+ if (isHubSpotHttpError(err)) {
138
+ logger.debug(err.message);
155
139
  }
156
- logger_1.logger.debug(err);
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: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
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
- (0, config_1.updateConfigAccount)(updatedAccount);
154
+ updateConfigAccount(updatedAccount);
171
155
  }
172
156
  else {
173
- (0, config_1.addConfigAccount)(updatedAccount);
157
+ addConfigAccount(updatedAccount);
174
158
  }
175
159
  if (makeDefault) {
176
- (0, config_1.setConfigAccountAsDefault)(updatedAccount.accountId);
160
+ setConfigAccountAsDefault(updatedAccount.accountId);
177
161
  }
178
162
  return updatedAccount;
179
163
  }
180
- exports.updateConfigWithAccessToken = updateConfigWithAccessToken;
@@ -1,5 +1,5 @@
1
- import { RequestPortsData, ServerPortMap } from '../types/PortManager';
2
- export declare const BASE_URL: string;
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>;
@@ -1,66 +1,51 @@
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.portManagerHasActiveServers = exports.deleteServerInstance = exports.getServerPortByInstanceId = exports.getActiveServers = exports.requestPorts = exports.stopPortManagerServer = exports.startPortManagerServer = exports.isPortManagerServerRunning = exports.isPortManagerPortAvailable = exports.BASE_URL = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const PortManagerServer_1 = require("../utils/PortManagerServer");
9
- const ports_1 = require("../constants/ports");
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 axios_1.default.get(`${exports.BASE_URL}${PortManagerServer_1.HEALTH_CHECK_PATH}`);
19
- return data.status === PortManagerServer_1.SERVICE_HEALTHY;
11
+ const { data } = await axios.get(`${BASE_URL}${HEALTH_CHECK_PATH}`);
12
+ return data.status === SERVICE_HEALTHY;
20
13
  }
21
14
  catch (e) {
22
- logger_1.logger.debug(e);
15
+ logger.debug(e);
23
16
  return false;
24
17
  }
25
18
  }
26
- exports.isPortManagerServerRunning = isPortManagerServerRunning;
27
- async function startPortManagerServer() {
19
+ export async function startPortManagerServer() {
28
20
  const isRunning = await isPortManagerServerRunning();
29
21
  if (!isRunning) {
30
- await PortManagerServer_1.PortManagerServer.init();
22
+ await PortManagerServer.init();
31
23
  }
32
24
  }
33
- exports.startPortManagerServer = startPortManagerServer;
34
- async function stopPortManagerServer() {
25
+ export async function stopPortManagerServer() {
35
26
  const isRunning = await isPortManagerServerRunning();
36
27
  if (isRunning) {
37
- await axios_1.default.post(`${exports.BASE_URL}/close`);
28
+ await axios.post(`${BASE_URL}/close`);
38
29
  }
39
30
  }
40
- exports.stopPortManagerServer = stopPortManagerServer;
41
- async function requestPorts(portData) {
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
- exports.requestPorts = requestPorts;
48
- async function getActiveServers() {
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
- exports.getActiveServers = getActiveServers;
53
- async function getServerPortByInstanceId(serverInstanceId) {
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
- exports.getServerPortByInstanceId = getServerPortByInstanceId;
58
- async function deleteServerInstance(serverInstanceId) {
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
- exports.deleteServerInstance = deleteServerInstance;
62
- async function portManagerHasActiveServers() {
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
- "use strict";
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
- exports.commaSeparatedValues = commaSeparatedValues;
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;
@@ -1,3 +1 @@
1
- export declare const CMS_CLI_USAGE_PATH: string;
2
- export declare const VSCODE_USAGE_PATH: string;
3
1
  export declare function trackUsage(eventName: string, eventClass: string, meta?: {}, accountId?: number): Promise<void>;
package/lib/trackUsage.js CHANGED
@@ -1,18 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trackUsage = exports.VSCODE_USAGE_PATH = exports.CMS_CLI_USAGE_PATH = void 0;
4
- const client_1 = require("../http/client");
5
- const getAxiosConfig_1 = require("../http/getAxiosConfig");
6
- const logger_1 = require("./logger");
7
- const http_1 = require("../http");
8
- const config_1 = require("../config");
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
- exports.CMS_CLI_USAGE_PATH = `${fileMapper_1.FILE_MAPPER_API_PATH}/cms-cli-usage`;
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 = fileMapper_1.FILE_MAPPER_API_PATH;
21
+ let path = FILE_MAPPER_API_PATH;
27
22
  switch (eventName) {
28
23
  case EVENT_TYPES.CLI_INTERACTION:
29
- path = exports.CMS_CLI_USAGE_PATH;
24
+ path = CMS_CLI_USAGE_PATH;
30
25
  break;
31
26
  case EVENT_TYPES.VSCODE_EXTENSION_INTERACTION:
32
- path = exports.VSCODE_USAGE_PATH;
27
+ path = VSCODE_USAGE_PATH;
33
28
  break;
34
29
  default:
35
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.invalidEvent`, { eventName }));
30
+ logger.debug(i18n(`${i18nKey}.invalidEvent`, { eventName }));
36
31
  }
37
- const account = accountId && (0, config_1.getConfigAccountById)(accountId);
32
+ const account = accountId && getConfigAccountById(accountId);
38
33
  if (account && account.authType === 'personalaccesskey') {
39
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventAuthenticated`));
34
+ logger.debug(i18n(`${i18nKey}.sendingEventAuthenticated`));
40
35
  try {
41
- await http_1.http.post(accountId, {
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
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.retryingEventUnauthenticated`));
44
+ logger.debug(i18n(`${i18nKey}.retryingEventUnauthenticated`));
50
45
  }
51
46
  }
52
47
  const env = accountId
53
- ? (0, config_1.getConfigAccountEnvironment)(accountId)
54
- : (0, environment_1.getValidEnv)();
55
- const axiosConfig = (0, getAxiosConfig_1.getAxiosConfig)({
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
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventUnauthenticated`));
56
+ logger.debug(i18n(`${i18nKey}.sendingEventUnauthenticated`));
62
57
  try {
63
- await (0, client_1.httpClient)({ ...axiosConfig, method: 'post' });
58
+ await httpClient({ ...axiosConfig, method: 'post' });
64
59
  }
65
60
  catch (e) {
66
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.unauthenticatedSendFailed`));
61
+ logger.debug(i18n(`${i18nKey}.unauthenticatedSendFailed`));
67
62
  }
68
63
  }
69
- exports.trackUsage = trackUsage;
package/lib/urls.js CHANGED
@@ -1,16 +1,12 @@
1
- "use strict";
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() === environments_1.ENVIRONMENTS.QA ? environments_1.ENVIRONMENTS.QA : '';
6
+ return env.toLowerCase() === ENVIRONMENTS.QA ? ENVIRONMENTS.QA : '';
10
7
  }
11
- const getHubSpotWebsiteOrigin = (env) => `https://app.hubspot${getEnvUrlString(env)}.com`;
12
- exports.getHubSpotWebsiteOrigin = getHubSpotWebsiteOrigin;
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,4 +1,4 @@
1
- import { FileSystemErrorContext } from '../types/Error';
1
+ import { FileSystemErrorContext } from '../types/Error.js';
2
2
  export declare const FilerSystemErrorName = "FilerSystemError";
3
3
  export declare class FileSystemError extends Error {
4
4
  private context;
@@ -1,36 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- exports.FilerSystemErrorName = 'FilerSystemError';
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 = exports.FilerSystemErrorName;
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 = (0, lang_1.i18n)(`${i18nKey}.readAction`);
14
+ fileAction = i18n(`${i18nKey}.readAction`);
18
15
  }
19
16
  else if (context.operation === 'write') {
20
- fileAction = (0, lang_1.i18n)(`${i18nKey}.writeAction`);
17
+ fileAction = i18n(`${i18nKey}.writeAction`);
21
18
  }
22
19
  else {
23
- fileAction = (0, lang_1.i18n)(`${i18nKey}.otherAction`);
20
+ fileAction = i18n(`${i18nKey}.otherAction`);
24
21
  }
25
22
  const filepath = context.filepath
26
23
  ? `"${context.filepath}"`
27
- : (0, lang_1.i18n)(`${i18nKey}.unknownFilepath`);
24
+ : i18n(`${i18nKey}.unknownFilepath`);
28
25
  const messages = [
29
- (0, lang_1.i18n)(`${i18nKey}.baseMessage`, { fileAction, filepath }),
26
+ i18n(`${i18nKey}.baseMessage`, { fileAction, filepath }),
30
27
  ];
31
28
  // Many `fs` errors will be `SystemError`s
32
- if ((0, errors_1.isSystemError)(options?.cause)) {
33
- messages.push((0, lang_1.i18n)(`${i18nKey}.baseMessage`, {
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- [config_1.HUBSPOT_CONFIG_OPERATIONS.READ]: 'reading',
9
- [config_1.HUBSPOT_CONFIG_OPERATIONS.WRITE]: 'writing to',
10
- [config_1.HUBSPOT_CONFIG_OPERATIONS.DELETE]: 'deleting',
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 === config_1.HUBSPOT_CONFIG_ERROR_TYPES.INVALID_ENVIRONMENT_VARIABLES;
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 = (0, lang_1.i18n)('models.HubSpotConfigError.baseMessage', {
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;
@@ -1,4 +1,4 @@
1
- import { HubSpotHttpErrorContext } from '../types/Error';
1
+ import { HubSpotHttpErrorContext } from '../types/Error.js';
2
2
  export declare const HubSpotHttpErrorName = "HubSpotHttpError";
3
3
  export declare class HubSpotHttpError<T = any> extends Error {
4
4
  status?: number;