@hubspot/cli 6.4.0 → 7.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 (205) hide show
  1. package/bin/cli.js +110 -16
  2. package/bin/hs +2 -0
  3. package/bin/hscms +2 -0
  4. package/bin/silenceErrors.d.ts +2 -0
  5. package/bin/silenceErrors.js +12 -0
  6. package/commands/{accounts → account}/clean.js +10 -11
  7. package/commands/{accounts → account}/info.js +10 -16
  8. package/commands/{accounts → account}/list.js +16 -16
  9. package/commands/{accounts → account}/remove.js +12 -15
  10. package/commands/{accounts → account}/rename.js +4 -7
  11. package/commands/{accounts → account}/use.js +8 -14
  12. package/commands/account.js +26 -0
  13. package/commands/auth.js +30 -24
  14. package/commands/cms/getReactModule.js +70 -0
  15. package/commands/cms/lighthouseScore.js +19 -21
  16. package/commands/cms.js +4 -3
  17. package/commands/completion.js +22 -0
  18. package/commands/config/set.js +22 -24
  19. package/commands/config.js +2 -2
  20. package/commands/create.js +6 -3
  21. package/commands/customObject/create.js +19 -15
  22. package/commands/customObject/schema/create.js +15 -16
  23. package/commands/customObject/schema/delete.js +29 -11
  24. package/commands/customObject/schema/fetch-all.js +14 -11
  25. package/commands/customObject/schema/fetch.js +22 -14
  26. package/commands/customObject/schema/list.js +3 -6
  27. package/commands/customObject/schema/update.js +28 -18
  28. package/commands/customObject/schema.js +1 -1
  29. package/commands/customObject.js +3 -4
  30. package/commands/doctor.js +4 -2
  31. package/commands/feedback.js +2 -0
  32. package/commands/fetch.js +13 -13
  33. package/commands/filemanager/fetch.js +6 -7
  34. package/commands/filemanager/upload.js +10 -12
  35. package/commands/filemanager.js +1 -8
  36. package/commands/{functions → function}/deploy.js +13 -13
  37. package/commands/{functions → function}/list.js +7 -9
  38. package/commands/{functions → function}/server.js +5 -8
  39. package/commands/function.js +16 -0
  40. package/commands/hubdb/clear.js +14 -10
  41. package/commands/hubdb/create.js +37 -13
  42. package/commands/hubdb/delete.js +31 -10
  43. package/commands/hubdb/fetch.js +14 -9
  44. package/commands/hubdb.js +2 -3
  45. package/commands/init.js +37 -14
  46. package/commands/lint.js +6 -7
  47. package/commands/list.js +5 -7
  48. package/commands/logs.js +24 -15
  49. package/commands/module/marketplace-validate.js +6 -9
  50. package/commands/module.js +2 -1
  51. package/commands/mv.js +11 -13
  52. package/commands/open.js +11 -10
  53. package/commands/project/add.js +2 -5
  54. package/commands/project/cloneApp.js +28 -32
  55. package/commands/project/create.js +8 -10
  56. package/commands/project/deploy.js +19 -16
  57. package/commands/project/dev.js +17 -18
  58. package/commands/project/download.js +18 -15
  59. package/commands/project/listBuilds.js +36 -32
  60. package/commands/project/logs.js +6 -8
  61. package/commands/project/migrateApp.js +27 -27
  62. package/commands/project/open.js +9 -11
  63. package/commands/project/upload.js +30 -32
  64. package/commands/project/watch.js +17 -24
  65. package/commands/project.js +3 -4
  66. package/commands/remove.js +14 -13
  67. package/commands/sandbox/create.js +12 -15
  68. package/commands/sandbox/delete.js +19 -20
  69. package/commands/sandbox.js +4 -8
  70. package/commands/{secrets → secret}/addSecret.js +25 -12
  71. package/commands/secret/deleteSecret.js +71 -0
  72. package/commands/{secrets → secret}/listSecrets.js +7 -9
  73. package/commands/{secrets → secret}/updateSecret.js +21 -13
  74. package/commands/secret.js +22 -0
  75. package/commands/theme/generate-selectors.js +8 -8
  76. package/commands/theme/marketplace-validate.js +10 -13
  77. package/commands/theme/preview.js +7 -10
  78. package/commands/theme.js +3 -1
  79. package/commands/upload.js +32 -26
  80. package/commands/watch.js +19 -20
  81. package/lang/en.lyaml +200 -126
  82. package/lib/DevServerManager.js +1 -1
  83. package/lib/LocalDevManager.js +4 -4
  84. package/lib/buildAccount.js +5 -11
  85. package/lib/commonOpts.d.ts +15 -6
  86. package/lib/commonOpts.js +53 -39
  87. package/lib/configOptions.d.ts +13 -1
  88. package/lib/configOptions.js +54 -57
  89. package/lib/constants.d.ts +1 -4
  90. package/lib/dependencyManagement.d.ts +4 -1
  91. package/lib/dependencyManagement.js +2 -2
  92. package/lib/developerTestAccounts.d.ts +5 -1
  93. package/lib/developerTestAccounts.js +45 -39
  94. package/lib/doctor/DiagnosticInfoBuilder.js +8 -4
  95. package/lib/doctor/Doctor.js +11 -6
  96. package/lib/generateSelectors.d.ts +19 -0
  97. package/lib/generateSelectors.js +23 -23
  98. package/lib/localDev.js +3 -2
  99. package/lib/marketplaceValidate.d.ts +6 -1
  100. package/lib/marketplaceValidate.js +76 -77
  101. package/lib/oauth.d.ts +2 -1
  102. package/lib/oauth.js +49 -37
  103. package/lib/polling.d.ts +8 -0
  104. package/lib/polling.js +9 -12
  105. package/lib/projects/ProjectLogsManager.d.ts +20 -0
  106. package/lib/projects/ProjectLogsManager.js +105 -0
  107. package/lib/projects/buildAndDeploy.d.ts +16 -0
  108. package/lib/projects/buildAndDeploy.js +342 -0
  109. package/lib/projects/index.d.ts +24 -0
  110. package/lib/projects/index.js +256 -0
  111. package/lib/projects/structure.d.ts +78 -0
  112. package/lib/projects/structure.js +151 -0
  113. package/lib/projects/upload.d.ts +8 -0
  114. package/lib/projects/upload.js +107 -0
  115. package/lib/projects/urls.d.ts +4 -0
  116. package/lib/projects/urls.js +27 -0
  117. package/lib/{projectsWatch.js → projects/watch.js} +3 -3
  118. package/lib/prompts/accountNamePrompt.d.ts +11 -0
  119. package/lib/prompts/accountNamePrompt.js +45 -46
  120. package/lib/prompts/accountsPrompt.d.ts +1 -1
  121. package/lib/prompts/accountsPrompt.js +21 -19
  122. package/lib/prompts/cmsFieldPrompt.d.ts +1 -1
  123. package/lib/prompts/cmsFieldPrompt.js +23 -24
  124. package/lib/prompts/createApiSamplePrompt.d.ts +17 -0
  125. package/lib/prompts/createApiSamplePrompt.js +47 -44
  126. package/lib/prompts/createFunctionPrompt.d.ts +7 -0
  127. package/lib/prompts/createFunctionPrompt.js +17 -20
  128. package/lib/prompts/createModulePrompt.d.ts +8 -0
  129. package/lib/prompts/createModulePrompt.js +29 -17
  130. package/lib/prompts/createProjectPrompt.d.ts +13 -0
  131. package/lib/prompts/createProjectPrompt.js +48 -49
  132. package/lib/prompts/createTemplatePrompt.d.ts +8 -0
  133. package/lib/prompts/createTemplatePrompt.js +15 -17
  134. package/lib/prompts/downloadProjectPrompt.d.ts +8 -0
  135. package/lib/prompts/downloadProjectPrompt.js +25 -23
  136. package/lib/prompts/installPublicAppPrompt.d.ts +1 -1
  137. package/lib/prompts/installPublicAppPrompt.js +21 -19
  138. package/lib/prompts/personalAccessKeyPrompt.d.ts +28 -0
  139. package/lib/prompts/personalAccessKeyPrompt.js +46 -52
  140. package/lib/prompts/previewPrompt.d.ts +14 -0
  141. package/lib/prompts/previewPrompt.js +24 -24
  142. package/lib/prompts/projectAddPrompt.d.ts +9 -0
  143. package/lib/prompts/projectAddPrompt.js +11 -14
  144. package/lib/prompts/projectDevTargetAccountPrompt.d.ts +6 -1
  145. package/lib/prompts/projectDevTargetAccountPrompt.js +87 -69
  146. package/lib/prompts/projectsLogsPrompt.d.ts +11 -0
  147. package/lib/prompts/projectsLogsPrompt.js +8 -11
  148. package/lib/prompts/promptUtils.d.ts +7 -6
  149. package/lib/prompts/promptUtils.js +21 -8
  150. package/lib/prompts/sandboxesPrompt.d.ts +8 -0
  151. package/lib/prompts/sandboxesPrompt.js +43 -45
  152. package/lib/prompts/secretPrompt.d.ts +12 -0
  153. package/lib/prompts/secretPrompt.js +32 -19
  154. package/lib/prompts/selectHubDBTablePrompt.d.ts +12 -0
  155. package/lib/prompts/selectHubDBTablePrompt.js +69 -0
  156. package/lib/prompts/selectPublicAppPrompt.d.ts +8 -0
  157. package/lib/prompts/selectPublicAppPrompt.js +28 -27
  158. package/lib/prompts/setAsDefaultAccountPrompt.d.ts +1 -1
  159. package/lib/prompts/setAsDefaultAccountPrompt.js +12 -14
  160. package/lib/prompts/uploadPrompt.d.ts +8 -0
  161. package/lib/prompts/uploadPrompt.js +18 -18
  162. package/lib/sandboxSync.js +5 -2
  163. package/lib/sandboxes.js +12 -7
  164. package/lib/ui/index.d.ts +1 -1
  165. package/lib/ui/index.js +1 -1
  166. package/lib/usageTracking.d.ts +21 -2
  167. package/lib/usageTracking.js +53 -81
  168. package/lib/validation.d.ts +11 -1
  169. package/lib/validation.js +98 -91
  170. package/package.json +12 -6
  171. package/types/Projects.d.ts +43 -0
  172. package/types/Projects.js +2 -0
  173. package/types/Prompts.d.ts +25 -0
  174. package/types/Prompts.js +2 -0
  175. package/commands/accounts.js +0 -30
  176. package/commands/cms/reactModules.js +0 -60
  177. package/commands/functions.js +0 -24
  178. package/commands/secrets/deleteSecret.js +0 -46
  179. package/commands/secrets.js +0 -23
  180. package/lib/ProjectLogsManager.js +0 -91
  181. package/lib/projectStructure.js +0 -116
  182. package/lib/projects.d.ts +0 -4
  183. package/lib/projects.js +0 -681
  184. package/lib/projectsWatch.d.ts +0 -1
  185. package/lib/prompts/cleanUploadPrompt.d.ts +0 -1
  186. package/lib/prompts/cleanUploadPrompt.js +0 -20
  187. /package/commands/{accounts → account}/clean.d.ts +0 -0
  188. /package/commands/{accounts → account}/info.d.ts +0 -0
  189. /package/commands/{accounts → account}/list.d.ts +0 -0
  190. /package/commands/{accounts → account}/remove.d.ts +0 -0
  191. /package/commands/{accounts → account}/rename.d.ts +0 -0
  192. /package/commands/{accounts → account}/use.d.ts +0 -0
  193. /package/commands/{accounts.d.ts → account.d.ts} +0 -0
  194. /package/commands/cms/{reactModules.d.ts → getReactModule.d.ts} +0 -0
  195. /package/commands/{functions.d.ts → completion.d.ts} +0 -0
  196. /package/commands/{functions/list.d.ts → function/deploy.d.ts} +0 -0
  197. /package/commands/{functions/server.d.ts → function/list.d.ts} +0 -0
  198. /package/commands/{secrets.d.ts → function/server.d.ts} +0 -0
  199. /package/commands/{functions/deploy.d.ts → function.d.ts} +0 -0
  200. /package/commands/{secrets/deleteSecret.d.ts → secret/addSecret.d.ts} +0 -0
  201. /package/commands/{secrets/listSecrets.d.ts → secret/deleteSecret.d.ts} +0 -0
  202. /package/commands/{secrets/updateSecret.d.ts → secret/listSecrets.d.ts} +0 -0
  203. /package/{lib/ProjectLogsManager.d.ts → commands/secret/updateSecret.d.ts} +0 -0
  204. /package/commands/{secrets/addSecret.d.ts → secret.d.ts} +0 -0
  205. /package/lib/{projectStructure.d.ts → projects/watch.d.ts} +0 -0
@@ -39,7 +39,8 @@ class Doctor {
39
39
  SpinniesManager_1.default.add('runningDiagnostics', {
40
40
  text: i18n(`${i18nKey}.runningDiagnostics`),
41
41
  });
42
- this.diagnosticInfo = await this.diagnosticInfoBuilder.generateDiagnosticInfo();
42
+ this.diagnosticInfo =
43
+ await this.diagnosticInfoBuilder.generateDiagnosticInfo();
43
44
  this.projectConfig = this.diagnosticInfo?.project.config;
44
45
  this.diagnosis = new Diagnosis_1.Diagnosis({
45
46
  diagnosticInfo: this.diagnosticInfo,
@@ -189,8 +190,11 @@ class Doctor {
189
190
  }
190
191
  async checkCLIVersion() {
191
192
  let latestCLIVersion;
193
+ let nextCliVersion;
192
194
  try {
193
- latestCLIVersion = await (0, dependencyManagement_1.getLatestCliVersion)();
195
+ const { latest, next } = await (0, dependencyManagement_1.getLatestCliVersion)();
196
+ latestCLIVersion = latest;
197
+ nextCliVersion = next;
194
198
  }
195
199
  catch (e) {
196
200
  return this.diagnosis?.addCliSection({
@@ -202,14 +206,15 @@ class Doctor {
202
206
  }),
203
207
  });
204
208
  }
205
- if (latestCLIVersion !== package_json_1.default.version) {
209
+ if (latestCLIVersion !== package_json_1.default.version && nextCliVersion !== package_json_1.default.version) {
210
+ const onNextTag = package_json_1.default.version.includes('beta');
206
211
  this.diagnosis?.addCliSection({
207
212
  type: 'warning',
208
213
  message: i18n(`${i18nKey}.hsChecks.notLatest`, {
209
214
  hsVersion: package_json_1.default.version,
210
215
  }),
211
216
  secondaryMessaging: i18n(`${i18nKey}.hsChecks.notLatestSecondary`, {
212
- hsVersion: package_json_1.default.version,
217
+ hsVersion: onNextTag ? nextCliVersion : latestCLIVersion,
213
218
  command: (0, ui_1.uiCommandReference)(`npm install -g ${package_json_1.default.name}`),
214
219
  }),
215
220
  });
@@ -229,7 +234,7 @@ class Doctor {
229
234
  for (const packageFile of this.diagnosticInfo?.packageFiles || []) {
230
235
  const packageDirName = path_1.default.dirname(packageFile);
231
236
  try {
232
- const needsInstall = await (0, dependencyManagement_1.hasMissingPackages)(path_1.default.join(this.projectConfig?.projectDir, packageDirName));
237
+ const needsInstall = await (0, dependencyManagement_1.hasMissingPackages)(path_1.default.join(this.projectConfig?.projectDir || '', packageDirName));
233
238
  if (needsInstall) {
234
239
  foundError = true;
235
240
  this.diagnosis?.addProjectSection({
@@ -285,7 +290,7 @@ class Doctor {
285
290
  async checkProjectConfigJsonFiles() {
286
291
  let foundError = false;
287
292
  for (const jsonFile of this.diagnosticInfo?.jsonFiles || []) {
288
- const fileToCheck = path_1.default.join(this.projectConfig?.projectDir, jsonFile);
293
+ const fileToCheck = path_1.default.join(this.projectConfig?.projectDir || '', jsonFile);
289
294
  if (!(await this.isValidJsonFile(fileToCheck))) {
290
295
  foundError = true;
291
296
  this.diagnosis?.addProjectSection({
@@ -1 +1,20 @@
1
+ export declare function getMaxFieldsDepth(): number;
2
+ export declare function findFieldsJsonPath(basePath: string): string | null;
3
+ export declare function combineThemeCss(basePath: string, cssString?: string): string | null;
4
+ type Field = {
5
+ name: string;
6
+ children: Field[];
7
+ selectors?: string[];
8
+ inherited_value?: {
9
+ property_value_paths?: {
10
+ [key: string]: string;
11
+ };
12
+ };
13
+ };
14
+ export declare function setPreviewSelectors(fields: Field[], fieldPath: string[], selectors: string[], depth?: number): Field[];
15
+ export declare function generateInheritedSelectors(fields: Field[]): Field[];
16
+ type SelectorsMap = {
17
+ [key: string]: string[] | undefined;
18
+ };
19
+ export declare function generateSelectorsMap(fields: Field[], fieldKey?: string[]): SelectorsMap;
1
20
  export {};
@@ -1,10 +1,18 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // @ts-nocheck
4
- const fs = require('fs');
5
- const { EXIT_CODES } = require('./enums/exitCodes');
6
- const { logger } = require('@hubspot/local-dev-lib/logger');
7
- const { i18n } = require('./lang');
6
+ exports.getMaxFieldsDepth = getMaxFieldsDepth;
7
+ exports.findFieldsJsonPath = findFieldsJsonPath;
8
+ exports.combineThemeCss = combineThemeCss;
9
+ exports.setPreviewSelectors = setPreviewSelectors;
10
+ exports.generateInheritedSelectors = generateInheritedSelectors;
11
+ exports.generateSelectorsMap = generateSelectorsMap;
12
+ const fs_1 = __importDefault(require("fs"));
13
+ const logger_1 = require("@hubspot/local-dev-lib/logger");
14
+ const exitCodes_1 = require("./enums/exitCodes");
15
+ const lang_1 = require("./lang");
8
16
  const CSS_COMMENTS_REGEX = new RegExp(/\/\*.*\*\//, 'g');
9
17
  const CSS_PSEUDO_CLASS_REGEX = new RegExp(/:active|:checked|:disabled|:empty|:enabled|:first-of-type|:focus|:hover|:in-range|:invalid|:link|:optional|:out-of-range|:read-only|:read-write|:required|:target|:valid|:visited/, 'g');
10
18
  const i18nKey = 'commands.theme.subcommands.generateSelectors';
@@ -14,19 +22,19 @@ function getMaxFieldsDepth() {
14
22
  }
15
23
  function findFieldsJsonPath(basePath) {
16
24
  const _path = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;
17
- if (!fs.existsSync(_path)) {
18
- logger.error(i18n(`${i18nKey}.errors.invalidPath`, {
25
+ if (!fs_1.default.existsSync(_path)) {
26
+ logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.invalidPath`, {
19
27
  themePath: basePath,
20
28
  }));
21
- process.exit(EXIT_CODES.ERROR);
29
+ process.exit(exitCodes_1.EXIT_CODES.ERROR);
22
30
  }
23
- const files = fs.readdirSync(_path);
31
+ const files = fs_1.default.readdirSync(_path);
24
32
  if (files.includes('fields.json')) {
25
33
  return `${_path}/fields.json`;
26
34
  }
27
35
  for (let i = 0; i < files.length; i++) {
28
36
  const fileName = files[i];
29
- const isDirectory = fs.lstatSync(`${_path}/${fileName}`).isDirectory();
37
+ const isDirectory = fs_1.default.lstatSync(`${_path}/${fileName}`).isDirectory();
30
38
  if (isDirectory && !fileName.includes('.module')) {
31
39
  const fieldsJsonPath = findFieldsJsonPath(`${_path}/${fileName}`);
32
40
  if (fieldsJsonPath)
@@ -37,16 +45,16 @@ function findFieldsJsonPath(basePath) {
37
45
  }
38
46
  function combineThemeCss(basePath, cssString = '') {
39
47
  const _path = basePath.endsWith('/') ? basePath.slice(0, -1) : basePath;
40
- const isDirectory = fs.lstatSync(_path).isDirectory();
48
+ const isDirectory = fs_1.default.lstatSync(_path).isDirectory();
41
49
  if (isDirectory) {
42
- const filesList = fs.readdirSync(_path);
50
+ const filesList = fs_1.default.readdirSync(_path);
43
51
  return filesList.reduce((css, fileName) => {
44
52
  const newCss = combineThemeCss(`${_path}/${fileName}`);
45
53
  return newCss ? `${css}\n${newCss}` : css;
46
54
  }, cssString);
47
55
  }
48
56
  else if (_path.includes('.css') && !_path.includes('.module')) {
49
- return `${cssString}\n${fs.readFileSync(_path, 'utf8')}`;
57
+ return `${cssString}\n${fs_1.default.readFileSync(_path, 'utf8')}`;
50
58
  }
51
59
  return null;
52
60
  }
@@ -78,7 +86,7 @@ function setPreviewSelectors(fields, fieldPath, selectors, depth = 0) {
78
86
  }
79
87
  function generateInheritedSelectors(fields) {
80
88
  let finalFieldsJson = [...fields];
81
- const _generateInheritedSelectors = fieldsToCheck => {
89
+ function _generateInheritedSelectors(fieldsToCheck) {
82
90
  fieldsToCheck.forEach(field => {
83
91
  if (field.children) {
84
92
  _generateInheritedSelectors(field.children);
@@ -94,7 +102,7 @@ function generateInheritedSelectors(fields) {
94
102
  });
95
103
  }
96
104
  });
97
- };
105
+ }
98
106
  _generateInheritedSelectors(fields);
99
107
  return finalFieldsJson;
100
108
  }
@@ -115,11 +123,3 @@ function generateSelectorsMap(fields, fieldKey = []) {
115
123
  });
116
124
  return selectorsMap;
117
125
  }
118
- module.exports = {
119
- findFieldsJsonPath,
120
- combineThemeCss,
121
- setPreviewSelectors,
122
- generateInheritedSelectors,
123
- generateSelectorsMap,
124
- getMaxFieldsDepth,
125
- };
package/lib/localDev.js CHANGED
@@ -19,7 +19,8 @@ const { i18n } = require('./lang');
19
19
  const { EXIT_CODES } = require('./enums/exitCodes');
20
20
  const { trackCommandMetadataUsage } = require('./usageTracking');
21
21
  const { isAppDeveloperAccount, isDeveloperTestAccount, } = require('./accountTypes');
22
- const { handleProjectUpload, pollProjectBuildAndDeploy, } = require('./projects');
22
+ const { handleProjectUpload } = require('./projects/upload');
23
+ const { pollProjectBuildAndDeploy } = require('./projects/buildAndDeploy');
23
24
  const { PROJECT_ERROR_TYPES, PROJECT_BUILD_TEXT, PROJECT_DEPLOY_TEXT, } = require('./constants');
24
25
  const { logError, ApiErrorContext } = require('./errorHandlers/index');
25
26
  const { PERSONAL_ACCESS_KEY_AUTH_METHOD, } = require('@hubspot/local-dev-lib/constants/auth');
@@ -71,7 +72,7 @@ const checkIfParentAccountIsAuthed = accountConfig => {
71
72
  // Confirm the default account is a developer account if developing public apps
72
73
  const checkIfAccountFlagIsSupported = (accountConfig, hasPublicApps) => {
73
74
  if (hasPublicApps) {
74
- if (!isDeveloperTestAccount) {
75
+ if (!isDeveloperTestAccount(accountConfig)) {
75
76
  logger.error(i18n(`${i18nKey}.validateAccountOption.invalidPublicAppAccount`, {
76
77
  useCommand: uiCommandReference('hs accounts use'),
77
78
  devCommand: uiCommandReference('hs project dev'),
@@ -1 +1,6 @@
1
- export {};
1
+ import { GetValidationResultsResponse } from '@hubspot/local-dev-lib/types/MarketplaceValidation';
2
+ export declare function kickOffValidation(accountId: number, assetType: string, src: string): Promise<number>;
3
+ export declare function pollForValidationFinish(accountId: number, validationId: string): Promise<void>;
4
+ export declare function fetchValidationResults(accountId: number, validationId: string): Promise<GetValidationResultsResponse>;
5
+ export declare function processValidationErrors(i18nKey: string, validationResults: GetValidationResultsResponse): void;
6
+ export declare function displayValidationResults(i18nKey: string, validationResults: GetValidationResultsResponse): void;
@@ -1,16 +1,23 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // @ts-nocheck
4
- const chalk = require('chalk');
5
- const { logger } = require('@hubspot/local-dev-lib/logger');
6
- const { requestValidation, getValidationStatus, getValidationResults, } = require('@hubspot/local-dev-lib/api/marketplaceValidation');
7
- const { i18n } = require('./lang');
8
- const { EXIT_CODES } = require('./enums/exitCodes');
6
+ exports.kickOffValidation = kickOffValidation;
7
+ exports.pollForValidationFinish = pollForValidationFinish;
8
+ exports.fetchValidationResults = fetchValidationResults;
9
+ exports.processValidationErrors = processValidationErrors;
10
+ exports.displayValidationResults = displayValidationResults;
11
+ const chalk_1 = __importDefault(require("chalk"));
12
+ const marketplaceValidation_1 = require("@hubspot/local-dev-lib/api/marketplaceValidation");
13
+ const logger_1 = require("@hubspot/local-dev-lib/logger");
14
+ const lang_1 = require("./lang");
15
+ const exitCodes_1 = require("./enums/exitCodes");
9
16
  const SLEEP_TIME = 2000;
10
- const kickOffValidation = async (accountId, assetType, src) => {
17
+ async function kickOffValidation(accountId, assetType, src) {
11
18
  const requestGroup = 'EXTERNAL_DEVELOPER';
12
19
  try {
13
- const { data: requestResult } = await requestValidation(accountId, {
20
+ const { data: requestResult } = await (0, marketplaceValidation_1.requestValidation)(accountId, {
14
21
  path: src,
15
22
  assetType,
16
23
  requestGroup,
@@ -18,14 +25,14 @@ const kickOffValidation = async (accountId, assetType, src) => {
18
25
  return requestResult;
19
26
  }
20
27
  catch (err) {
21
- logger.debug(err);
22
- process.exit(EXIT_CODES.ERROR);
28
+ logger_1.logger.debug(err);
29
+ process.exit(exitCodes_1.EXIT_CODES.ERROR);
23
30
  }
24
- };
25
- const pollForValidationFinish = async (accountId, validationId) => {
31
+ }
32
+ async function pollForValidationFinish(accountId, validationId) {
26
33
  try {
27
34
  const checkValidationStatus = async () => {
28
- const { data: validationStatus } = await getValidationStatus(accountId, {
35
+ const { data: validationStatus } = await (0, marketplaceValidation_1.getValidationStatus)(accountId, {
29
36
  validationId,
30
37
  });
31
38
  if (validationStatus === 'REQUESTED') {
@@ -36,89 +43,81 @@ const pollForValidationFinish = async (accountId, validationId) => {
36
43
  await checkValidationStatus();
37
44
  }
38
45
  catch (err) {
39
- logger.debug(err);
40
- process.exit(EXIT_CODES.ERROR);
46
+ logger_1.logger.debug(err);
47
+ process.exit(exitCodes_1.EXIT_CODES.ERROR);
41
48
  }
42
- };
43
- const fetchValidationResults = async (accountId, validationId) => {
49
+ }
50
+ async function fetchValidationResults(accountId, validationId) {
44
51
  try {
45
- const { data: validationResults } = await getValidationResults(accountId, {
52
+ const { data: validationResults } = await (0, marketplaceValidation_1.getValidationResults)(accountId, {
46
53
  validationId,
47
54
  });
48
55
  return validationResults;
49
56
  }
50
57
  catch (err) {
51
- logger.debug(err);
52
- process.exit(EXIT_CODES.ERROR);
58
+ logger_1.logger.debug(err);
59
+ process.exit(exitCodes_1.EXIT_CODES.ERROR);
53
60
  }
54
- };
55
- const processValidationErrors = (i18nKey, validationResults) => {
61
+ }
62
+ function processValidationErrors(i18nKey, validationResults) {
56
63
  if (validationResults.errors.length) {
57
64
  const { assetPath, errors } = validationResults;
58
65
  errors.forEach(err => {
59
66
  if (err.failureReasonType === 'DOWNLOAD_EMPTY') {
60
- logger.error(i18n(`${i18nKey}.errors.invalidPath`, {
67
+ logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.invalidPath`, {
61
68
  path: assetPath,
62
69
  }));
63
70
  }
64
71
  else {
65
- logger.error(`${err.context}`);
72
+ logger_1.logger.error(`${err.context}`);
66
73
  }
67
74
  });
68
- process.exit(EXIT_CODES.ERROR);
75
+ process.exit(exitCodes_1.EXIT_CODES.ERROR);
69
76
  }
70
- };
71
- const displayValidationResults = (i18nKey, validationResults) => {
72
- const displayResults = checks => {
73
- const displayFileInfo = (file, line) => {
74
- if (file) {
75
- logger.log(i18n(`${i18nKey}.results.warnings.file`, {
76
- file,
77
- }));
78
- }
79
- if (line) {
80
- logger.log(i18n(`${i18nKey}.results.warnings.lineNumber`, {
81
- line,
82
- }));
83
- }
84
- return null;
85
- };
86
- if (checks) {
87
- const { status, results } = checks;
88
- if (status === 'FAIL') {
89
- const failedValidations = results.filter(test => test.status === 'FAIL');
90
- const warningValidations = results.filter(test => test.status === 'WARN');
91
- failedValidations.forEach(val => {
92
- logger.error(`${val.message}`);
93
- displayFileInfo(val.file, val.line);
94
- });
95
- warningValidations.forEach(val => {
96
- logger.warn(`${val.message}`);
97
- displayFileInfo(val.file, val.line);
98
- });
99
- }
100
- if (status === 'PASS') {
101
- logger.success(i18n(`${i18nKey}.results.noErrors`));
102
- results.forEach(test => {
103
- if (test.status === 'WARN') {
104
- logger.warn(`${test.message}`);
105
- displayFileInfo(test.file, test.line);
106
- }
107
- });
108
- }
77
+ }
78
+ function displayFileInfo(file, line, i18nKey) {
79
+ if (file) {
80
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.results.warnings.file`, {
81
+ file,
82
+ }));
83
+ }
84
+ if (line) {
85
+ logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.results.warnings.lineNumber`, {
86
+ line,
87
+ }));
88
+ }
89
+ }
90
+ function displayResults(checks, i18nKey) {
91
+ if (checks) {
92
+ const { status, results } = checks;
93
+ if (status === 'FAIL') {
94
+ const failedValidations = results.filter(test => test.status === 'FAIL');
95
+ const warningValidations = results.filter(test => test.status === 'WARN');
96
+ failedValidations.forEach(val => {
97
+ logger_1.logger.error(`${val.message}`);
98
+ displayFileInfo(val.file, val.line, i18nKey);
99
+ });
100
+ warningValidations.forEach(val => {
101
+ logger_1.logger.warn(`${val.message}`);
102
+ displayFileInfo(val.file, val.line, i18nKey);
103
+ });
109
104
  }
110
- return null;
111
- };
105
+ if (status === 'PASS') {
106
+ logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.results.noErrors`));
107
+ results.forEach(test => {
108
+ if (test.status === 'WARN') {
109
+ logger_1.logger.warn(`${test.message}`);
110
+ displayFileInfo(test.file, test.line, i18nKey);
111
+ }
112
+ });
113
+ }
114
+ }
115
+ return;
116
+ }
117
+ function displayValidationResults(i18nKey, validationResults) {
112
118
  Object.keys(validationResults.results).forEach(type => {
113
- logger.log(chalk.bold(i18n(`${i18nKey}.results.${type.toLowerCase()}`)));
114
- displayResults(validationResults.results[type]);
115
- logger.log();
119
+ logger_1.logger.log(chalk_1.default.bold((0, lang_1.i18n)(`${i18nKey}.results.${type.toLowerCase()}`)));
120
+ displayResults(validationResults.results[type], i18nKey);
121
+ logger_1.logger.log();
116
122
  });
117
- };
118
- module.exports = {
119
- kickOffValidation,
120
- pollForValidationFinish,
121
- fetchValidationResults,
122
- processValidationErrors,
123
- displayValidationResults,
124
- };
123
+ }
package/lib/oauth.d.ts CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ import { OAuth2ManagerAccountConfig } from '@hubspot/local-dev-lib/types/Accounts';
2
+ export declare function authenticateWithOauth(accountConfig: OAuth2ManagerAccountConfig): Promise<void>;
package/lib/oauth.js CHANGED
@@ -1,38 +1,53 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // @ts-nocheck
4
- const express = require('express');
5
- const open = require('open');
6
- const { OAuth2Manager, } = require('@hubspot/local-dev-lib/models/OAuth2Manager');
7
- const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
8
- const { addOauthToAccountConfig } = require('@hubspot/local-dev-lib/oauth');
9
- const { handleExit } = require('./process');
10
- const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
11
- const { logger } = require('@hubspot/local-dev-lib/logger');
12
- const { ENVIRONMENTS, } = require('@hubspot/local-dev-lib/constants/environments');
6
+ exports.authenticateWithOauth = authenticateWithOauth;
7
+ const express_1 = __importDefault(require("express"));
8
+ const open_1 = __importDefault(require("open"));
9
+ const OAuth2Manager_1 = require("@hubspot/local-dev-lib/models/OAuth2Manager");
10
+ const config_1 = require("@hubspot/local-dev-lib/config");
11
+ const getAccountIdentifier_1 = require("@hubspot/local-dev-lib/config/getAccountIdentifier");
12
+ const oauth_1 = require("@hubspot/local-dev-lib/oauth");
13
+ const urls_1 = require("@hubspot/local-dev-lib/urls");
14
+ const logger_1 = require("@hubspot/local-dev-lib/logger");
15
+ const environments_1 = require("@hubspot/local-dev-lib/constants/environments");
16
+ const auth_1 = require("@hubspot/local-dev-lib/constants/auth");
17
+ const process_1 = require("./process");
18
+ const lang_1 = require("./lang");
19
+ const exitCodes_1 = require("./enums/exitCodes");
13
20
  const PORT = 3000;
14
21
  const redirectUri = `http://localhost:${PORT}/oauth-callback`;
15
- const buildAuthUrl = oauthManager => {
16
- return (`${getHubSpotWebsiteOrigin(oauthManager.account.env)}/oauth/${oauthManager.account.accountId}/authorize` +
17
- `?client_id=${encodeURIComponent(oauthManager.account.clientId)}` + // app's client ID
18
- `&scope=${encodeURIComponent(oauthManager.account.scopes.join(' '))}` + // scopes being requested by the app
22
+ const i18nKey = 'lib.oauth';
23
+ function buildAuthUrl(oauthManager) {
24
+ const { env: accountEnv, clientId, scopes: accountScopes, } = oauthManager.account;
25
+ const env = accountEnv || environments_1.ENVIRONMENTS.PROD;
26
+ const scopes = accountScopes || auth_1.DEFAULT_OAUTH_SCOPES;
27
+ if (!clientId) {
28
+ logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.missingClientId`));
29
+ process.exit(exitCodes_1.EXIT_CODES.ERROR);
30
+ }
31
+ return (`${(0, urls_1.getHubSpotWebsiteOrigin)(env)}/oauth/${oauthManager.account.accountId}/authorize` +
32
+ `?client_id=${encodeURIComponent(clientId)}` + // app's client ID
33
+ `&scope=${encodeURIComponent(scopes.join(' '))}` + // scopes being requested by the app
19
34
  `&redirect_uri=${encodeURIComponent(redirectUri)}` // where to send the user after the consent page
20
35
  );
21
- };
22
- const handleServerOnProcessEnd = server => {
36
+ }
37
+ function handleServerOnProcessEnd(server) {
23
38
  const shutdownServerIfRunning = () => {
24
39
  server?.close();
25
40
  };
26
- handleExit(shutdownServerIfRunning);
27
- };
28
- const authorize = async (oauthManager) => {
41
+ (0, process_1.handleExit)(shutdownServerIfRunning);
42
+ }
43
+ async function authorize(oauthManager) {
29
44
  if (process.env.BROWSER !== 'none') {
30
- open(buildAuthUrl(oauthManager), { url: true });
45
+ (0, open_1.default)(buildAuthUrl(oauthManager), { url: true });
31
46
  }
32
47
  // eslint-disable-next-line no-async-promise-executor
33
48
  return new Promise(async (resolve, reject) => {
34
49
  let server;
35
- const app = express();
50
+ const app = (0, express_1.default)();
36
51
  app.get('/oauth-callback', async (req, res) => {
37
52
  if (req.query.code) {
38
53
  const authCodeProof = {
@@ -69,24 +84,21 @@ const authorize = async (oauthManager) => {
69
84
  reject();
70
85
  }
71
86
  });
72
- server = app.listen(PORT, () => logger.log(`Waiting for authorization...`));
87
+ server = app.listen(PORT, () => logger_1.logger.log(`Waiting for authorization...`));
73
88
  handleServerOnProcessEnd(server);
74
89
  });
75
- };
76
- const setupOauth = accountConfig => {
77
- const accountId = parseInt(accountConfig.portalId, 10);
78
- const config = getAccountConfig(accountId) || {};
79
- return new OAuth2Manager({
90
+ }
91
+ function setupOauth(accountConfig) {
92
+ const accountId = (0, getAccountIdentifier_1.getAccountIdentifier)(accountConfig);
93
+ const config = (0, config_1.getAccountConfig)(accountId);
94
+ return new OAuth2Manager_1.OAuth2Manager({
80
95
  ...accountConfig,
81
- environment: accountConfig.env || config.env || ENVIRONMENTS.PROD,
96
+ env: accountConfig.env || config?.env || environments_1.ENVIRONMENTS.PROD,
82
97
  });
83
- };
84
- const authenticateWithOauth = async (configData) => {
85
- const oauthManager = setupOauth(configData);
86
- logger.log('Authorizing');
98
+ }
99
+ async function authenticateWithOauth(accountConfig) {
100
+ const oauthManager = setupOauth(accountConfig);
101
+ logger_1.logger.log('Authorizing');
87
102
  await authorize(oauthManager);
88
- addOauthToAccountConfig(oauthManager);
89
- };
90
- module.exports = {
91
- authenticateWithOauth,
92
- };
103
+ (0, oauth_1.addOauthToAccountConfig)(oauthManager);
104
+ }
package/lib/polling.d.ts CHANGED
@@ -1 +1,9 @@
1
+ import { HubSpotPromise } from '@hubspot/local-dev-lib/types/Http';
2
+ import { ValueOf } from '@hubspot/local-dev-lib/types/Utils';
3
+ import { POLLING_STATUS } from './constants';
4
+ type GenericPollingResponse = {
5
+ status: ValueOf<typeof POLLING_STATUS>;
6
+ };
7
+ type PollingCallback<T extends GenericPollingResponse> = (accountId: number, taskId: number | string) => HubSpotPromise<T>;
8
+ export declare function poll<T extends GenericPollingResponse>(callback: PollingCallback<T>, accountId: number, taskId: number | string): Promise<T>;
1
9
  export {};
package/lib/polling.js CHANGED
@@ -1,20 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // @ts-nocheck
4
- const { POLLING_DELAY, POLLING_STATUS } = require('./constants');
5
- const poll = (callback, accountId, taskId) => {
3
+ exports.poll = poll;
4
+ const constants_1 = require("./constants");
5
+ function poll(callback, accountId, taskId) {
6
6
  return new Promise((resolve, reject) => {
7
7
  const pollInterval = setInterval(async () => {
8
8
  try {
9
9
  const { data: pollResp } = await callback(accountId, taskId);
10
10
  const { status } = pollResp;
11
- if (status === POLLING_STATUS.SUCCESS) {
11
+ if (status === constants_1.POLLING_STATUS.SUCCESS) {
12
12
  clearInterval(pollInterval);
13
13
  resolve(pollResp);
14
14
  }
15
- else if (status === POLLING_STATUS.ERROR ||
16
- status === POLLING_STATUS.REVERTED ||
17
- status === POLLING_STATUS.FAILURE) {
15
+ else if (status === constants_1.POLLING_STATUS.ERROR ||
16
+ status === constants_1.POLLING_STATUS.REVERTED ||
17
+ status === constants_1.POLLING_STATUS.FAILURE) {
18
18
  clearInterval(pollInterval);
19
19
  reject(pollResp);
20
20
  }
@@ -23,9 +23,6 @@ const poll = (callback, accountId, taskId) => {
23
23
  clearInterval(pollInterval);
24
24
  reject(error);
25
25
  }
26
- }, POLLING_DELAY);
26
+ }, constants_1.POLLING_DELAY);
27
27
  });
28
- };
29
- module.exports = {
30
- poll,
31
- };
28
+ }
@@ -0,0 +1,20 @@
1
+ import { AppFunctionComponentMetadata } from '@hubspot/local-dev-lib/types/ComponentStructure';
2
+ declare class _ProjectLogsManager {
3
+ projectName: string | undefined;
4
+ projectId: number | undefined;
5
+ accountId: number | undefined;
6
+ functions: AppFunctionComponentMetadata[];
7
+ selectedFunction: AppFunctionComponentMetadata | undefined;
8
+ functionName: string | undefined;
9
+ appId: number | undefined;
10
+ isPublicFunction: boolean | undefined;
11
+ endpointName: string | undefined;
12
+ reset(): void;
13
+ constructor();
14
+ init(accountId: number): Promise<void>;
15
+ fetchFunctionDetails(): Promise<void>;
16
+ getFunctionNames(): string[];
17
+ setFunction(functionName: string): void;
18
+ }
19
+ export declare const ProjectLogsManager: _ProjectLogsManager;
20
+ export {};