@hubspot/local-dev-lib 4.0.4-beta.0 → 5.0.0-beta.0

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 (194) 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 +3 -3
  12. package/api/developerTestAccounts.js +29 -40
  13. package/api/fileManager.d.ts +2 -2
  14. package/api/fileManager.js +14 -24
  15. package/api/fileMapper.d.ts +2 -2
  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 -2
  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 +5 -5
  30. package/api/localDevAuth.js +17 -25
  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 +3 -3
  36. package/api/sandboxHubs.js +21 -30
  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.js +18 -26
  44. package/config/index.d.ts +4 -4
  45. package/config/index.js +141 -177
  46. package/config/migrate.d.ts +2 -2
  47. package/config/migrate.js +26 -37
  48. package/config/state.d.ts +1 -1
  49. package/config/state.js +17 -45
  50. package/config/utils.d.ts +4 -4
  51. package/config/utils.js +85 -108
  52. package/constants/api.js +3 -6
  53. package/constants/auth.js +9 -12
  54. package/constants/config.js +37 -43
  55. package/constants/environments.js +1 -4
  56. package/constants/extensions.js +6 -9
  57. package/constants/files.js +5 -8
  58. package/constants/ports.js +3 -6
  59. package/constants/projects.js +2 -5
  60. package/enums/build.js +5 -8
  61. package/enums/deploy.js +2 -5
  62. package/enums/project.js +1 -4
  63. package/errors/errors_DEPRECATED.d.ts +1 -1
  64. package/errors/errors_DEPRECATED.js +2 -7
  65. package/errors/index.d.ts +4 -4
  66. package/errors/index.js +17 -31
  67. package/http/addQueryParams.d.ts +1 -1
  68. package/http/addQueryParams.js +1 -5
  69. package/http/client.js +16 -42
  70. package/http/getAxiosConfig.d.ts +1 -1
  71. package/http/getAxiosConfig.js +21 -31
  72. package/http/index.d.ts +2 -2
  73. package/http/index.js +39 -46
  74. package/http/unauthed.d.ts +1 -1
  75. package/http/unauthed.js +15 -18
  76. package/lib/archive.d.ts +1 -3
  77. package/lib/archive.js +38 -67
  78. package/lib/cms/functions.d.ts +1 -1
  79. package/lib/cms/functions.js +45 -55
  80. package/lib/cms/handleFieldsJS.js +36 -44
  81. package/lib/cms/modules.d.ts +2 -2
  82. package/lib/cms/modules.js +49 -59
  83. package/lib/cms/processFieldsJs.js +17 -32
  84. package/lib/cms/templates.js +17 -26
  85. package/lib/cms/themes.js +10 -18
  86. package/lib/cms/uploadFolder.d.ts +4 -4
  87. package/lib/cms/uploadFolder.js +55 -64
  88. package/lib/cms/validate.d.ts +1 -1
  89. package/lib/cms/validate.js +11 -18
  90. package/lib/cms/watch.d.ts +2 -2
  91. package/lib/cms/watch.js +66 -73
  92. package/lib/crm.d.ts +1 -1
  93. package/lib/crm.js +16 -23
  94. package/lib/customObjects.d.ts +1 -1
  95. package/lib/customObjects.js +15 -25
  96. package/lib/environment.d.ts +1 -1
  97. package/lib/environment.js +5 -11
  98. package/lib/escapeRegExp.js +1 -5
  99. package/lib/fileManager.js +43 -51
  100. package/lib/fileMapper.d.ts +1 -1
  101. package/lib/fileMapper.js +70 -84
  102. package/lib/fs.d.ts +1 -1
  103. package/lib/fs.js +18 -27
  104. package/lib/github.d.ts +1 -3
  105. package/lib/github.js +39 -51
  106. package/lib/gitignore.d.ts +1 -1
  107. package/lib/gitignore.js +16 -24
  108. package/lib/hubdb.d.ts +1 -1
  109. package/lib/hubdb.js +29 -40
  110. package/lib/ignoreRules.js +25 -34
  111. package/lib/isDeepEqual.js +1 -5
  112. package/lib/logger.d.ts +8 -20
  113. package/lib/logger.js +47 -59
  114. package/lib/notify.js +9 -16
  115. package/lib/oauth.d.ts +2 -2
  116. package/lib/oauth.js +12 -17
  117. package/lib/path.d.ts +0 -1
  118. package/lib/path.js +30 -48
  119. package/lib/personalAccessKey.d.ts +3 -3
  120. package/lib/personalAccessKey.js +47 -59
  121. package/lib/portManager.d.ts +2 -2
  122. package/lib/portManager.js +26 -41
  123. package/lib/text.js +2 -7
  124. package/lib/trackUsage.d.ts +2 -2
  125. package/lib/trackUsage.js +26 -29
  126. package/lib/urls.js +4 -9
  127. package/models/FileSystemError.d.ts +1 -1
  128. package/models/FileSystemError.js +12 -16
  129. package/models/HubSpotConfigError.d.ts +1 -1
  130. package/models/HubSpotConfigError.js +8 -12
  131. package/models/HubSpotHttpError.d.ts +1 -1
  132. package/models/HubSpotHttpError.js +22 -26
  133. package/models/OAuth2Manager.d.ts +1 -1
  134. package/models/OAuth2Manager.js +17 -24
  135. package/package.json +17 -16
  136. package/types/Accounts.d.ts +5 -5
  137. package/types/Accounts.js +1 -2
  138. package/types/Activity.d.ts +3 -3
  139. package/types/Activity.js +1 -2
  140. package/types/Api.d.ts +1 -1
  141. package/types/Api.js +1 -2
  142. package/types/Apps.js +1 -2
  143. package/types/Archive.js +1 -2
  144. package/types/Build.d.ts +5 -5
  145. package/types/Build.js +1 -2
  146. package/types/CLIOptions.js +1 -2
  147. package/types/ComponentStructure.d.ts +2 -2
  148. package/types/ComponentStructure.js +1 -2
  149. package/types/Config.d.ts +5 -5
  150. package/types/Config.js +1 -2
  151. package/types/Crm.js +1 -2
  152. package/types/Deploy.d.ts +5 -5
  153. package/types/Deploy.js +1 -2
  154. package/types/DesignManager.js +1 -2
  155. package/types/DevSecrets.js +1 -2
  156. package/types/Error.js +1 -2
  157. package/types/FieldsJS.js +1 -2
  158. package/types/FileManager.js +1 -2
  159. package/types/Files.d.ts +4 -4
  160. package/types/Files.js +1 -2
  161. package/types/FireAlarm.js +1 -2
  162. package/types/Functions.js +1 -2
  163. package/types/Github.d.ts +1 -1
  164. package/types/Github.js +1 -2
  165. package/types/Http.d.ts +0 -4
  166. package/types/Http.js +1 -2
  167. package/types/Hubdb.js +1 -2
  168. package/types/HublValidation.js +1 -2
  169. package/types/Lang.d.ts +1 -1
  170. package/types/Lang.js +1 -2
  171. package/types/Lighthouse.js +1 -2
  172. package/types/MarketplaceValidation.js +1 -2
  173. package/types/Migration.d.ts +2 -2
  174. package/types/Migration.js +1 -4
  175. package/types/Modules.js +1 -2
  176. package/types/PortManager.js +1 -2
  177. package/types/Project.d.ts +3 -3
  178. package/types/Project.js +1 -2
  179. package/types/ProjectLog.js +1 -2
  180. package/types/Sandbox.js +2 -5
  181. package/types/Schemas.js +1 -2
  182. package/types/Secrets.js +1 -2
  183. package/types/Utils.js +1 -2
  184. package/types/developerTestAccounts.js +1 -2
  185. package/utils/PortManagerServer.d.ts +1 -2
  186. package/utils/PortManagerServer.js +32 -38
  187. package/utils/cms/fieldsJS.d.ts +1 -1
  188. package/utils/cms/fieldsJS.js +1 -5
  189. package/utils/cms/modules.d.ts +1 -1
  190. package/utils/cms/modules.js +13 -22
  191. package/utils/detectPort.js +12 -19
  192. package/utils/git.js +17 -26
  193. package/utils/lang.d.ts +1 -1
  194. package/utils/lang.js +5 -14
@@ -1,32 +1,26 @@
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, fetchScopeAuthorizationData, } from '../api/localDevAuth.js';
5
+ import { fetchSandboxHubData } from '../api/sandboxHubs.js';
6
+ import { getConfigAccountById, getConfigAccountIfExists, updateConfigAccount, addConfigAccount, setConfigAccountAsDefault, } from '../config/index.js';
7
+ import { HUBSPOT_ACCOUNT_TYPES } from '../constants/config.js';
8
+ import { fetchDeveloperTestAccountData } from '../api/developerTestAccounts.js';
9
+ import { logger } from './logger.js';
10
+ import { i18n } from '../utils/lang.js';
11
+ import { isHubSpotHttpError } from '../errors/index.js';
18
12
  const i18nKey = 'lib.personalAccessKey';
19
13
  const refreshRequests = new Map();
20
14
  function getRefreshKey(personalAccessKey, expiration) {
21
15
  return `${personalAccessKey}-${expiration || 'fresh'}`;
22
16
  }
23
- async function getAccessToken(personalAccessKey, env = environments_1.ENVIRONMENTS.PROD, accountId) {
24
- const axiosResponse = await (0, localDevAuth_1.fetchAccessToken)(personalAccessKey, env, accountId);
17
+ export async function getAccessToken(personalAccessKey, env = ENVIRONMENTS.PROD, accountId) {
18
+ const axiosResponse = await fetchAccessToken(personalAccessKey, env, accountId);
25
19
  const response = axiosResponse.data;
26
20
  return {
27
21
  portalId: response.hubId,
28
22
  accessToken: response.oauthAccessToken,
29
- expiresAt: (0, moment_1.default)(response.expiresAtMillis).toISOString(),
23
+ expiresAt: moment(response.expiresAtMillis).toISOString(),
30
24
  scopeGroups: response.scopeGroups,
31
25
  enabledFeatures: response.enabledFeatures,
32
26
  encodedOAuthRefreshToken: response.encodedOAuthRefreshToken,
@@ -34,12 +28,11 @@ async function getAccessToken(personalAccessKey, env = environments_1.ENVIRONMEN
34
28
  accountType: response.accountType,
35
29
  };
36
30
  }
37
- exports.getAccessToken = getAccessToken;
38
31
  async function refreshAccessToken(account) {
39
32
  const { personalAccessKey, env, accountId } = account;
40
33
  const accessTokenResponse = await getAccessToken(personalAccessKey, env, accountId);
41
34
  const { accessToken, expiresAt } = accessTokenResponse;
42
- (0, config_1.updateConfigAccount)({
35
+ updateConfigAccount({
43
36
  ...account,
44
37
  auth: {
45
38
  tokenInfo: {
@@ -73,25 +66,25 @@ async function getNewAccessToken(account) {
73
66
  return accessTokenResponse;
74
67
  }
75
68
  async function getNewAccessTokenByAccountId(accountId) {
76
- const account = (0, config_1.getConfigAccountById)(accountId);
69
+ const account = getConfigAccountById(accountId);
77
70
  if (!account) {
78
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
71
+ throw new Error(i18n(`${i18nKey}.errors.accountNotFound`, { accountId }));
79
72
  }
80
- if (account.authType !== auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
81
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidAuthType`, {
73
+ if (account.authType !== PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
74
+ throw new Error(i18n(`${i18nKey}.errors.invalidAuthType`, {
82
75
  accountId,
83
76
  }));
84
77
  }
85
78
  const accessTokenResponse = await getNewAccessToken(account);
86
79
  return accessTokenResponse;
87
80
  }
88
- async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false) {
89
- const account = (0, config_1.getConfigAccountById)(accountId);
81
+ export async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false) {
82
+ const account = getConfigAccountById(accountId);
90
83
  if (!account) {
91
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.accountNotFound`, { accountId }));
84
+ throw new Error(i18n(`${i18nKey}.errors.accountNotFound`, { accountId }));
92
85
  }
93
- if (account.authType !== auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
94
- throw new Error((0, lang_1.i18n)(`${i18nKey}.errors.invalidAuthType`, {
86
+ if (account.authType !== PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
87
+ throw new Error(i18n(`${i18nKey}.errors.invalidAuthType`, {
95
88
  accountId,
96
89
  }));
97
90
  }
@@ -100,34 +93,30 @@ async function accessTokenForPersonalAccessKey(accountId, forceRefresh = false)
100
93
  const authDataExists = authTokenInfo && auth?.tokenInfo?.accessToken;
101
94
  if (!authDataExists ||
102
95
  forceRefresh ||
103
- (0, moment_1.default)().add(5, 'minutes').isAfter((0, moment_1.default)(authTokenInfo.expiresAt))) {
96
+ moment().add(5, 'minutes').isAfter(moment(authTokenInfo.expiresAt))) {
104
97
  return getNewAccessToken(account).then(tokenInfo => tokenInfo.accessToken);
105
98
  }
106
99
  return auth.tokenInfo?.accessToken;
107
100
  }
108
- exports.accessTokenForPersonalAccessKey = accessTokenForPersonalAccessKey;
109
- async function enabledFeaturesForPersonalAccessKey(accountId) {
101
+ export async function enabledFeaturesForPersonalAccessKey(accountId) {
110
102
  const accessTokenResponse = await getNewAccessTokenByAccountId(accountId);
111
103
  return accessTokenResponse?.enabledFeatures;
112
104
  }
113
- exports.enabledFeaturesForPersonalAccessKey = enabledFeaturesForPersonalAccessKey;
114
- async function scopesOnAccessToken(accountId) {
105
+ export async function scopesOnAccessToken(accountId) {
115
106
  return (await getNewAccessTokenByAccountId(accountId)).scopeGroups;
116
107
  }
117
- exports.scopesOnAccessToken = scopesOnAccessToken;
118
- async function authorizedScopesForPortalAndUser(accountId) {
119
- return (await (0, localDevAuth_1.fetchScopeAuthorizationData)(accountId)).data.results;
108
+ export async function authorizedScopesForPortalAndUser(accountId) {
109
+ return (await fetchScopeAuthorizationData(accountId)).data.results;
120
110
  }
121
- exports.authorizedScopesForPortalAndUser = authorizedScopesForPortalAndUser;
122
- async function updateConfigWithAccessToken(token, personalAccessKey, env, name, makeDefault = false) {
111
+ export async function updateConfigWithAccessToken(token, personalAccessKey, env, name, makeDefault = false) {
123
112
  const { portalId, accessToken, expiresAt, accountType } = token;
124
- const account = (0, config_1.getConfigAccountIfExists)(portalId);
125
- const accountEnv = env || account?.env || environments_1.ENVIRONMENTS.PROD;
113
+ const account = getConfigAccountIfExists(portalId);
114
+ const accountEnv = env || account?.env || ENVIRONMENTS.PROD;
126
115
  let parentAccountId;
127
116
  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);
117
+ if (accountType === HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX ||
118
+ accountType === HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX) {
119
+ const { data: sandboxDataResponse } = await fetchSandboxHubData(accessToken, portalId, accountEnv);
131
120
  if (sandboxDataResponse.parentHubId) {
132
121
  parentAccountId = sandboxDataResponse.parentHubId;
133
122
  }
@@ -135,14 +124,14 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
135
124
  }
136
125
  catch (err) {
137
126
  // Log error but do not throw
138
- if ((0, errors_1.isHubSpotHttpError)(err)) {
139
- logger_1.logger.debug(err.message);
127
+ if (isHubSpotHttpError(err)) {
128
+ logger.debug(err.message);
140
129
  }
141
- logger_1.logger.debug(err);
130
+ logger.debug(err);
142
131
  }
143
132
  try {
144
- if (accountType === config_2.HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST) {
145
- const { data: developerTestAccountResponse } = await (0, developerTestAccounts_1.fetchDeveloperTestAccountData)(accessToken, portalId, accountEnv);
133
+ if (accountType === HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST) {
134
+ const { data: developerTestAccountResponse } = await fetchDeveloperTestAccountData(accessToken, portalId, accountEnv);
146
135
  if (developerTestAccountResponse) {
147
136
  parentAccountId = developerTestAccountResponse.parentPortalId;
148
137
  }
@@ -150,31 +139,30 @@ async function updateConfigWithAccessToken(token, personalAccessKey, env, name,
150
139
  }
151
140
  catch (err) {
152
141
  // Log error but do not throw
153
- if ((0, errors_1.isHubSpotHttpError)(err)) {
154
- logger_1.logger.debug(err.message);
142
+ if (isHubSpotHttpError(err)) {
143
+ logger.debug(err.message);
155
144
  }
156
- logger_1.logger.debug(err);
145
+ logger.debug(err);
157
146
  }
158
147
  const updatedAccount = {
159
148
  accountId: portalId,
160
149
  accountType,
161
150
  personalAccessKey,
162
151
  name: name || account?.name,
163
- authType: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
152
+ authType: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
164
153
  auth: { tokenInfo: { accessToken, expiresAt } },
165
154
  parentAccountId,
166
155
  env: accountEnv,
167
156
  }; // Account may temporarily not have a name before prompted to add one in the CLI
168
157
  // Add new account if it doesn't exist, otherwise update existing account
169
158
  if (account) {
170
- (0, config_1.updateConfigAccount)(updatedAccount);
159
+ updateConfigAccount(updatedAccount);
171
160
  }
172
161
  else {
173
- (0, config_1.addConfigAccount)(updatedAccount);
162
+ addConfigAccount(updatedAccount);
174
163
  }
175
164
  if (makeDefault) {
176
- (0, config_1.setConfigAccountAsDefault)(updatedAccount.accountId);
165
+ setConfigAccountAsDefault(updatedAccount.accountId);
177
166
  }
178
167
  return updatedAccount;
179
168
  }
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,3 @@
1
- export declare const CMS_CLI_USAGE_PATH: string;
2
- export declare const VSCODE_USAGE_PATH: string;
1
+ export declare const CMS_CLI_USAGE_PATH = "content/filemapper/v1/cms-cli-usage";
2
+ export declare const VSCODE_USAGE_PATH = "content/filemapper/v1/vscode-extension-usage";
3
3
  export declare function trackUsage(eventName: string, eventClass: string, meta?: {}, accountId?: number): Promise<void>;
package/lib/trackUsage.js CHANGED
@@ -1,18 +1,15 @@
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 } from '../api/fileMapper.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 const CMS_CLI_USAGE_PATH = `${FILE_MAPPER_API_PATH}/cms-cli-usage`;
11
+ export const VSCODE_USAGE_PATH = `${FILE_MAPPER_API_PATH}/vscode-extension-usage`;
12
+ export async function trackUsage(eventName, eventClass, meta = {}, accountId) {
16
13
  const usageEvent = {
17
14
  accountId,
18
15
  eventName,
@@ -23,47 +20,47 @@ async function trackUsage(eventName, eventClass, meta = {}, accountId) {
23
20
  VSCODE_EXTENSION_INTERACTION: 'vscode-extension-interaction',
24
21
  CLI_INTERACTION: 'cli-interaction',
25
22
  };
26
- let path = fileMapper_1.FILE_MAPPER_API_PATH;
23
+ let path = FILE_MAPPER_API_PATH;
27
24
  switch (eventName) {
28
25
  case EVENT_TYPES.CLI_INTERACTION:
29
- path = exports.CMS_CLI_USAGE_PATH;
26
+ path = CMS_CLI_USAGE_PATH;
30
27
  break;
31
28
  case EVENT_TYPES.VSCODE_EXTENSION_INTERACTION:
32
- path = exports.VSCODE_USAGE_PATH;
29
+ path = VSCODE_USAGE_PATH;
33
30
  break;
34
31
  default:
35
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.invalidEvent`, { eventName }));
32
+ logger.debug(i18n(`${i18nKey}.invalidEvent`, { eventName }));
36
33
  }
37
- const account = accountId && (0, config_1.getConfigAccountById)(accountId);
34
+ const account = accountId && getConfigAccountById(accountId);
38
35
  if (account && account.authType === 'personalaccesskey') {
39
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventAuthenticated`));
36
+ logger.debug(i18n(`${i18nKey}.sendingEventAuthenticated`));
40
37
  try {
41
- await http_1.http.post(accountId, {
38
+ await http.post(accountId, {
42
39
  url: `${path}/authenticated`,
43
40
  data: usageEvent,
44
41
  resolveWithFullResponse: true,
45
42
  });
46
43
  return;
44
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
47
45
  }
48
46
  catch (e) {
49
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.retryingEventUnauthenticated`));
47
+ logger.debug(i18n(`${i18nKey}.retryingEventUnauthenticated`));
50
48
  }
51
49
  }
52
50
  const env = accountId
53
- ? (0, config_1.getConfigAccountEnvironment)(accountId)
54
- : (0, environment_1.getValidEnv)();
55
- const axiosConfig = (0, getAxiosConfig_1.getAxiosConfig)({
51
+ ? getConfigAccountEnvironment(accountId)
52
+ : getValidEnv();
53
+ const axiosConfig = getAxiosConfig({
56
54
  env,
57
55
  url: path,
58
56
  data: usageEvent,
59
57
  resolveWithFullResponse: true,
60
58
  });
61
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.sendingEventUnauthenticated`));
59
+ logger.debug(i18n(`${i18nKey}.sendingEventUnauthenticated`));
62
60
  try {
63
- await (0, client_1.httpClient)({ ...axiosConfig, method: 'post' });
61
+ await httpClient({ ...axiosConfig, method: 'post' });
64
62
  }
65
63
  catch (e) {
66
- logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.unauthenticatedSendFailed`));
64
+ logger.debug(i18n(`${i18nKey}.unauthenticatedSendFailed`));
67
65
  }
68
66
  }
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/index.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;