@hubspot/cli 7.8.12-experimental.1 → 7.9.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 (276) hide show
  1. package/commands/__tests__/cms.test.js +44 -1
  2. package/commands/__tests__/customObject.test.js +22 -1
  3. package/commands/__tests__/project.test.js +2 -0
  4. package/commands/account/auth.js +1 -0
  5. package/commands/auth.js +1 -0
  6. package/commands/{__tests__/remove.test.js → cms/__tests__/delete.test.js} +8 -8
  7. package/commands/{__tests__ → cms/__tests__}/fetch.test.js +3 -3
  8. package/commands/{__tests__ → cms/__tests__}/function.test.js +7 -3
  9. package/commands/{__tests__ → cms/__tests__}/lint.test.js +3 -3
  10. package/commands/{__tests__ → cms/__tests__}/list.test.js +3 -3
  11. package/commands/{__tests__ → cms/__tests__}/mv.test.js +3 -3
  12. package/commands/{__tests__ → cms/__tests__}/theme.test.js +9 -2
  13. package/commands/cms/app/create.d.ts +9 -0
  14. package/commands/cms/app/create.js +82 -0
  15. package/commands/cms/app.d.ts +3 -0
  16. package/commands/cms/app.js +17 -0
  17. package/commands/cms/delete.d.ts +6 -0
  18. package/commands/cms/delete.js +43 -0
  19. package/commands/cms/fetch.d.ts +12 -0
  20. package/commands/cms/fetch.js +79 -0
  21. package/commands/{__tests__ → cms/function/__tests__}/logs.test.js +4 -5
  22. package/commands/cms/function/create.d.ts +12 -0
  23. package/commands/cms/function/create.js +84 -0
  24. package/commands/cms/function/deploy.d.ts +6 -0
  25. package/commands/cms/function/deploy.js +89 -0
  26. package/commands/cms/function/list.d.ts +6 -0
  27. package/commands/cms/function/list.js +60 -0
  28. package/commands/cms/function/logs.d.ts +10 -0
  29. package/commands/cms/function/logs.js +135 -0
  30. package/commands/cms/function/server.d.ts +10 -0
  31. package/commands/cms/function/server.js +69 -0
  32. package/commands/cms/function.d.ts +3 -0
  33. package/commands/cms/function.js +27 -0
  34. package/commands/cms/lint.d.ts +6 -0
  35. package/commands/cms/lint.js +83 -0
  36. package/commands/cms/list.d.ts +6 -0
  37. package/commands/cms/list.js +96 -0
  38. package/commands/cms/module/create.d.ts +11 -0
  39. package/commands/cms/module/create.js +84 -0
  40. package/commands/cms/module/marketplace-validate.d.ts +6 -0
  41. package/commands/cms/module/marketplace-validate.js +45 -0
  42. package/commands/cms/module.d.ts +3 -0
  43. package/commands/cms/module.js +17 -0
  44. package/commands/cms/mv.d.ts +7 -0
  45. package/commands/cms/mv.js +60 -0
  46. package/commands/cms/template/create.d.ts +9 -0
  47. package/commands/cms/template/create.js +72 -0
  48. package/commands/cms/template.d.ts +3 -0
  49. package/commands/cms/template.js +17 -0
  50. package/commands/{theme → cms/theme}/__tests__/marketplace-validate.test.js +2 -2
  51. package/commands/{theme → cms/theme}/__tests__/preview.test.js +2 -2
  52. package/commands/cms/theme/create.d.ts +6 -0
  53. package/commands/cms/theme/create.js +58 -0
  54. package/commands/cms/theme/generate-selectors.d.ts +6 -0
  55. package/commands/cms/theme/generate-selectors.js +171 -0
  56. package/commands/cms/theme/marketplace-validate.d.ts +6 -0
  57. package/commands/cms/theme/marketplace-validate.js +46 -0
  58. package/commands/cms/theme/preview.d.ts +12 -0
  59. package/commands/cms/theme/preview.js +224 -0
  60. package/commands/cms/theme.d.ts +3 -0
  61. package/commands/cms/theme.js +25 -0
  62. package/commands/cms/upload.d.ts +12 -0
  63. package/commands/cms/upload.js +212 -0
  64. package/commands/cms/watch.d.ts +14 -0
  65. package/commands/cms/watch.js +138 -0
  66. package/commands/cms/webpack/create.d.ts +6 -0
  67. package/commands/cms/webpack/create.js +58 -0
  68. package/commands/cms/webpack.d.ts +3 -0
  69. package/commands/cms/webpack.js +17 -0
  70. package/commands/cms.js +26 -0
  71. package/commands/create.js +4 -2
  72. package/commands/customObject/{schema/__tests__/create.test.js → __tests__/createSchema.test.js} +5 -5
  73. package/commands/customObject/{schema/__tests__/delete.test.js → __tests__/deleteSchema.test.js} +5 -5
  74. package/commands/customObject/{schema/__tests__/fetch-all.test.js → __tests__/fetch-all-schemas.test.js} +5 -5
  75. package/commands/customObject/{schema/__tests__/fetch.test.js → __tests__/fetchSchema.test.js} +5 -5
  76. package/commands/customObject/{schema/__tests__/list.test.js → __tests__/listSchemas.test.js} +5 -5
  77. package/commands/customObject/{schema/__tests__/update.test.js → __tests__/updateSchema.test.js} +5 -5
  78. package/commands/customObject/createSchema.d.ts +6 -0
  79. package/commands/customObject/createSchema.js +56 -0
  80. package/commands/customObject/deleteSchema.d.ts +7 -0
  81. package/commands/customObject/deleteSchema.js +69 -0
  82. package/commands/customObject/fetchAllSchemas.d.ts +6 -0
  83. package/commands/customObject/fetchAllSchemas.js +57 -0
  84. package/commands/customObject/fetchSchema.d.ts +7 -0
  85. package/commands/customObject/fetchSchema.js +67 -0
  86. package/commands/customObject/listSchemas.d.ts +4 -0
  87. package/commands/customObject/listSchemas.js +35 -0
  88. package/commands/customObject/schema/create.d.ts +4 -6
  89. package/commands/customObject/schema/create.js +13 -36
  90. package/commands/customObject/schema/delete.d.ts +4 -7
  91. package/commands/customObject/schema/delete.js +15 -50
  92. package/commands/customObject/schema/fetch-all.d.ts +4 -6
  93. package/commands/customObject/schema/fetch-all.js +14 -41
  94. package/commands/customObject/schema/fetch.d.ts +4 -7
  95. package/commands/customObject/schema/fetch.js +14 -49
  96. package/commands/customObject/schema/list.d.ts +4 -4
  97. package/commands/customObject/schema/list.js +10 -19
  98. package/commands/customObject/schema/update.d.ts +4 -7
  99. package/commands/customObject/schema/update.js +15 -50
  100. package/commands/customObject/schema.js +4 -2
  101. package/commands/customObject/updateSchema.d.ts +7 -0
  102. package/commands/customObject/updateSchema.js +71 -0
  103. package/commands/customObject.js +16 -1
  104. package/commands/feedback.js +1 -1
  105. package/commands/fetch.d.ts +4 -12
  106. package/commands/fetch.js +19 -46
  107. package/commands/function/deploy.d.ts +4 -6
  108. package/commands/function/deploy.js +14 -71
  109. package/commands/function/list.d.ts +4 -6
  110. package/commands/function/list.js +14 -40
  111. package/commands/function/server.d.ts +4 -10
  112. package/commands/function/server.js +22 -29
  113. package/commands/function.d.ts +2 -4
  114. package/commands/function.js +25 -14
  115. package/commands/lint.d.ts +4 -6
  116. package/commands/lint.js +13 -65
  117. package/commands/list.d.ts +4 -6
  118. package/commands/list.js +13 -74
  119. package/commands/logs.d.ts +4 -10
  120. package/commands/logs.js +24 -87
  121. package/commands/module/marketplace-validate.d.ts +4 -6
  122. package/commands/module/marketplace-validate.js +15 -27
  123. package/commands/module.d.ts +2 -2
  124. package/commands/module.js +17 -15
  125. package/commands/mv.d.ts +4 -7
  126. package/commands/mv.js +13 -39
  127. package/commands/project/__tests__/add.test.js +12 -12
  128. package/commands/project/__tests__/devUnifiedFlow.test.js +32 -0
  129. package/commands/project/__tests__/list.test.js +31 -0
  130. package/commands/project/__tests__/migrate.test.js +1 -0
  131. package/commands/project/add.d.ts +2 -2
  132. package/commands/project/add.js +3 -2
  133. package/commands/project/create.js +1 -1
  134. package/commands/project/dev/deprecatedFlow.js +2 -2
  135. package/commands/project/dev/index.js +5 -5
  136. package/commands/project/dev/unifiedFlow.js +8 -3
  137. package/commands/project/download.js +5 -2
  138. package/commands/project/installDeps.d.ts +2 -2
  139. package/commands/project/installDeps.js +1 -0
  140. package/commands/project/list.d.ts +4 -0
  141. package/commands/project/list.js +62 -0
  142. package/commands/project/migrate.js +5 -2
  143. package/commands/project.js +2 -0
  144. package/commands/remove.d.ts +4 -6
  145. package/commands/remove.js +12 -24
  146. package/commands/testAccount/create.js +2 -2
  147. package/commands/testAccount/delete.js +1 -1
  148. package/commands/theme/generate-selectors.d.ts +4 -6
  149. package/commands/theme/generate-selectors.js +14 -152
  150. package/commands/theme/marketplace-validate.d.ts +4 -6
  151. package/commands/theme/marketplace-validate.js +14 -25
  152. package/commands/theme/preview.d.ts +4 -12
  153. package/commands/theme/preview.js +18 -180
  154. package/commands/theme.d.ts +2 -2
  155. package/commands/theme.js +19 -13
  156. package/commands/upload.d.ts +4 -12
  157. package/commands/upload.js +19 -169
  158. package/commands/watch.d.ts +4 -14
  159. package/commands/watch.js +23 -88
  160. package/lang/en.d.ts +561 -425
  161. package/lang/en.js +563 -427
  162. package/lang/en.lyaml +2 -2
  163. package/lib/__tests__/buildAccount.test.js +2 -2
  164. package/lib/__tests__/http.test.js +40 -0
  165. package/lib/buildAccount.d.ts +2 -2
  166. package/lib/buildAccount.js +7 -7
  167. package/lib/configMigrate.js +88 -9
  168. package/lib/constants.d.ts +9 -0
  169. package/lib/constants.js +9 -0
  170. package/lib/generateSelectors.js +1 -1
  171. package/lib/http.d.ts +1 -0
  172. package/lib/http.js +26 -0
  173. package/lib/middleware/autoUpdateMiddleware.d.ts +2 -1
  174. package/lib/middleware/autoUpdateMiddleware.js +12 -2
  175. package/lib/middleware/commandTargetingUtils.d.ts +1 -1
  176. package/lib/middleware/commandTargetingUtils.js +16 -20
  177. package/lib/projects/__tests__/AppDevModeInterface.test.js +95 -109
  178. package/lib/projects/__tests__/DevServerManager.test.d.ts +1 -0
  179. package/lib/projects/__tests__/DevServerManager.test.js +183 -0
  180. package/lib/projects/__tests__/LocalDevProcess.test.js +6 -5
  181. package/lib/projects/__tests__/LocalDevWebsocketServer.test.js +6 -6
  182. package/lib/projects/__tests__/UIExtensionsDevModeInterface.test.d.ts +1 -0
  183. package/lib/projects/__tests__/UIExtensionsDevModeInterface.test.js +161 -0
  184. package/lib/projects/__tests__/deploy.test.js +9 -9
  185. package/lib/projects/__tests__/upload.test.js +2 -2
  186. package/lib/projects/add/__tests__/v2AddComponent.test.d.ts +1 -0
  187. package/lib/projects/add/__tests__/{v3AddComponent.test.js → v2AddComponent.test.js} +35 -35
  188. package/lib/projects/add/{v3AddComponent.d.ts → v2AddComponent.d.ts} +1 -1
  189. package/lib/projects/add/{v3AddComponent.js → v2AddComponent.js} +5 -5
  190. package/lib/projects/create/__tests__/v2.test.d.ts +1 -0
  191. package/lib/projects/create/__tests__/{v3.test.js → v2.test.js} +2 -2
  192. package/lib/projects/create/index.js +2 -2
  193. package/lib/projects/create/{v3.d.ts → v2.d.ts} +3 -3
  194. package/lib/projects/create/{v3.js → v2.js} +3 -3
  195. package/lib/projects/deploy.d.ts +1 -1
  196. package/lib/projects/deploy.js +2 -2
  197. package/lib/projects/localDev/AppDevModeInterface.d.ts +10 -3
  198. package/lib/projects/localDev/AppDevModeInterface.js +132 -105
  199. package/lib/projects/localDev/DevServerManager.d.ts +10 -29
  200. package/lib/projects/localDev/DevServerManager.js +20 -76
  201. package/lib/projects/localDev/DevServerManager_DEPRECATED.d.ts +40 -0
  202. package/lib/projects/localDev/DevServerManager_DEPRECATED.js +120 -0
  203. package/lib/projects/localDev/{LocalDevManager.js → LocalDevManager_DEPRECATED.js} +6 -6
  204. package/lib/projects/localDev/LocalDevProcess.js +3 -2
  205. package/lib/projects/localDev/LocalDevState.d.ts +3 -0
  206. package/lib/projects/localDev/LocalDevState.js +9 -0
  207. package/lib/projects/localDev/LocalDevWebsocketServer.d.ts +4 -0
  208. package/lib/projects/localDev/LocalDevWebsocketServer.js +39 -6
  209. package/lib/projects/localDev/UIExtensionsDevModeInterface.d.ts +13 -0
  210. package/lib/projects/localDev/UIExtensionsDevModeInterface.js +37 -0
  211. package/lib/projects/localDev/helpers/account.d.ts +1 -1
  212. package/lib/projects/localDev/helpers/account.js +2 -2
  213. package/lib/projects/localDev/helpers/process.d.ts +1 -0
  214. package/lib/projects/localDev/helpers/process.js +15 -0
  215. package/lib/projects/localDev/helpers/project.js +2 -3
  216. package/lib/projects/localDev/localDevWebsocketServerUtils.d.ts +3 -0
  217. package/lib/projects/localDev/localDevWebsocketServerUtils.js +9 -0
  218. package/lib/projects/urls.d.ts +0 -1
  219. package/lib/projects/urls.js +0 -3
  220. package/lib/prompts/__tests__/projectAddPrompt.test.js +10 -10
  221. package/lib/prompts/installAppPrompt.d.ts +1 -6
  222. package/lib/prompts/installAppPrompt.js +1 -6
  223. package/lib/prompts/projectAddPrompt.d.ts +2 -2
  224. package/lib/prompts/projectAddPrompt.js +1 -1
  225. package/lib/theme/__tests__/migrate.test.js +4 -4
  226. package/lib/ui/index.d.ts +2 -0
  227. package/lib/ui/index.js +8 -0
  228. package/lib/ui/uiMessages.d.ts +5 -0
  229. package/lib/ui/uiMessages.js +5 -0
  230. package/mcp-server/tools/cms/HsCreateModuleTool.d.ts +2 -2
  231. package/mcp-server/tools/project/__tests__/CreateProjectTool.test.js +1 -1
  232. package/package.json +6 -5
  233. package/types/Cms.d.ts +6 -6
  234. package/lib/projects/localDev/DevServerManagerV2.d.ts +0 -22
  235. package/lib/projects/localDev/DevServerManagerV2.js +0 -81
  236. /package/commands/{customObject/schema → cms}/__tests__/delete.test.d.ts +0 -0
  237. /package/commands/{__tests__ → cms/__tests__}/fetch.test.d.ts +0 -0
  238. /package/commands/{__tests__ → cms/__tests__}/function.test.d.ts +0 -0
  239. /package/commands/{__tests__ → cms/__tests__}/lint.test.d.ts +0 -0
  240. /package/commands/{__tests__ → cms/__tests__}/list.test.d.ts +0 -0
  241. /package/commands/{__tests__ → cms/__tests__}/mv.test.d.ts +0 -0
  242. /package/commands/{__tests__ → cms/__tests__}/theme.test.d.ts +0 -0
  243. /package/commands/{__tests__ → cms/function/__tests__}/logs.test.d.ts +0 -0
  244. /package/commands/{theme → cms/theme}/__tests__/generate-selectors.test.d.ts +0 -0
  245. /package/commands/{theme → cms/theme}/__tests__/generate-selectors.test.js +0 -0
  246. /package/commands/{theme → cms/theme}/__tests__/marketplace-validate.test.d.ts +0 -0
  247. /package/commands/{theme → cms/theme}/__tests__/preview.test.d.ts +0 -0
  248. /package/commands/{__tests__/remove.test.d.ts → customObject/__tests__/createSchema.test.d.ts} +0 -0
  249. /package/commands/customObject/{schema/__tests__/create.test.d.ts → __tests__/deleteSchema.test.d.ts} +0 -0
  250. /package/commands/customObject/{schema/__tests__/fetch-all.test.d.ts → __tests__/fetch-all-schemas.test.d.ts} +0 -0
  251. /package/commands/customObject/{schema/__tests__/fetch.test.d.ts → __tests__/fetchSchema.test.d.ts} +0 -0
  252. /package/commands/customObject/{schema/__tests__/list.test.d.ts → __tests__/listSchemas.test.d.ts} +0 -0
  253. /package/commands/customObject/{schema/__tests__/update.test.d.ts → __tests__/updateSchema.test.d.ts} +0 -0
  254. /package/{lib/projects/add/__tests__/v3AddComponent.test.d.ts → commands/project/__tests__/list.test.d.ts} +0 -0
  255. /package/lib/{projects/create/__tests__/v3.test.d.ts → __tests__/http.test.d.ts} +0 -0
  256. /package/{commands/create → lib/cmsAssets}/api-sample.d.ts +0 -0
  257. /package/{commands/create → lib/cmsAssets}/api-sample.js +0 -0
  258. /package/{commands/create → lib/cmsAssets}/app.d.ts +0 -0
  259. /package/{commands/create → lib/cmsAssets}/app.js +0 -0
  260. /package/{commands/create → lib/cmsAssets}/function.d.ts +0 -0
  261. /package/{commands/create → lib/cmsAssets}/function.js +0 -0
  262. /package/{commands/create → lib/cmsAssets}/index.d.ts +0 -0
  263. /package/{commands/create → lib/cmsAssets}/index.js +0 -0
  264. /package/{commands/create → lib/cmsAssets}/module.d.ts +0 -0
  265. /package/{commands/create → lib/cmsAssets}/module.js +0 -0
  266. /package/{commands/create → lib/cmsAssets}/react-app.d.ts +0 -0
  267. /package/{commands/create → lib/cmsAssets}/react-app.js +0 -0
  268. /package/{commands/create → lib/cmsAssets}/template.d.ts +0 -0
  269. /package/{commands/create → lib/cmsAssets}/template.js +0 -0
  270. /package/{commands/create → lib/cmsAssets}/vue-app.d.ts +0 -0
  271. /package/{commands/create → lib/cmsAssets}/vue-app.js +0 -0
  272. /package/{commands/create → lib/cmsAssets}/webpack-serverless.d.ts +0 -0
  273. /package/{commands/create → lib/cmsAssets}/webpack-serverless.js +0 -0
  274. /package/{commands/create → lib/cmsAssets}/website-theme.d.ts +0 -0
  275. /package/{commands/create → lib/cmsAssets}/website-theme.js +0 -0
  276. /package/lib/projects/localDev/{LocalDevManager.d.ts → LocalDevManager_DEPRECATED.d.ts} +0 -0
@@ -10,6 +10,7 @@ declare class AppDevModeInterface {
10
10
  localDevLogger: LocalDevLogger;
11
11
  _appNode?: AppIRNode | null;
12
12
  marketplaceAppInstalls?: number;
13
+ private appInstallResolve?;
13
14
  constructor(options: AppDevModeInterfaceConstructorOptions);
14
15
  private getAppNodeFromProjectNodes;
15
16
  private get appNode();
@@ -17,18 +18,24 @@ declare class AppDevModeInterface {
17
18
  private set appData(value);
18
19
  private isStaticAuthApp;
19
20
  private isOAuthApp;
21
+ private isAutomaticallyInstallable;
20
22
  private getAppInstallUrl;
21
23
  private fetchAppData;
22
24
  private checkMarketplaceAppInstalls;
25
+ private waitUntilAppIsInstalled;
26
+ private autoInstallStaticAuthApp;
23
27
  private installAppOrOpenInstallUrl;
24
28
  private checkTestAccountAppInstallation;
29
+ private validateOauthAppRedirectUrl;
30
+ private resolveAppInstallPromise;
31
+ private handleAppInstallSuccessDevServerMessage;
32
+ private handleAppInstallInitiatedDevServerMessage;
33
+ private handleAppInstallFailureDevServerMessage;
25
34
  private onDevServerMessage;
26
35
  private onChangeProjectNodes;
27
- private setUpStateListeners;
28
36
  private removeStateListeners;
29
- setup(args: any): Promise<void>;
37
+ setup(): Promise<void>;
30
38
  start(): Promise<void>;
31
- fileChange(filePath: string, event: string): Promise<void>;
32
39
  cleanup(): Promise<void>;
33
40
  }
34
41
  export default AppDevModeInterface;
@@ -1,27 +1,25 @@
1
1
  import { fetchAppInstallationData } from '@hubspot/local-dev-lib/api/localDevAuth';
2
- import { fetchAppMetadataByUid, fetchPublicAppProductionInstallCounts,
3
- // installStaticAuthAppOnTestAccount,
4
- } from '@hubspot/local-dev-lib/api/appsDev';
5
- import { DevModeUnifiedInterface as UIEDevModeInterface } from '@hubspot/ui-extensions-dev-server';
6
- import { requestPorts } from '@hubspot/local-dev-lib/portManager';
2
+ import { fetchAppMetadataByUid, fetchPublicAppProductionInstallCounts, installStaticAuthAppOnTestAccount, } from '@hubspot/local-dev-lib/api/appsDev';
3
+ import { getAccountConfig } from '@hubspot/local-dev-lib/config';
7
4
  import { APP_AUTH_TYPES, APP_DISTRIBUTION_TYPES, APP_INSTALLATION_STATES, LOCAL_DEV_SERVER_MESSAGE_TYPES, } from '../../constants.js';
8
5
  import { EXIT_CODES } from '../../enums/exitCodes.js';
9
6
  import { isAppIRNode } from '../../projects/structure.js';
10
7
  import { uiLine } from '../../ui/index.js';
11
8
  import { logError } from '../../errorHandlers/index.js';
12
- import {
13
- // installAppAutoPrompt,
14
- installAppBrowserPrompt, } from '../../prompts/installAppPrompt.js';
9
+ import { installAppAutoPrompt, installAppBrowserPrompt, } from '../../prompts/installAppPrompt.js';
15
10
  import { confirmPrompt } from '../../prompts/promptUtils.js';
16
11
  import { lib } from '../../../lang/en.js';
17
12
  import { uiLogger } from '../../ui/logger.js';
18
13
  import { getOauthAppInstallUrl, getStaticAuthAppInstallUrl, } from '../../app/urls.js';
14
+ import { isDeveloperTestAccount, isSandbox } from '../../accountTypes.js';
19
15
  import SpinniesManager from '../../ui/SpinniesManager.js';
16
+ import { isServerRunningAtUrl } from '../../http.js';
20
17
  class AppDevModeInterface {
21
18
  localDevState;
22
19
  localDevLogger;
23
20
  _appNode;
24
21
  marketplaceAppInstalls;
22
+ appInstallResolve;
25
23
  constructor(options) {
26
24
  this.localDevState = options.localDevState;
27
25
  this.localDevLogger = options.localDevLogger;
@@ -43,10 +41,18 @@ class AppDevModeInterface {
43
41
  return this._appNode;
44
42
  }
45
43
  get appData() {
44
+ // These checks are primarily for type safety
45
+ // App data will never be accessed before being set
46
46
  if (!this.appNode) {
47
- return undefined;
47
+ uiLogger.log(lib.AppDevModeInterface.appDataNotFound);
48
+ process.exit(EXIT_CODES.ERROR);
49
+ }
50
+ const data = this.localDevState.getAppDataByUid(this.appNode.uid);
51
+ if (!data) {
52
+ uiLogger.log(lib.AppDevModeInterface.appDataNotFound);
53
+ process.exit(EXIT_CODES.ERROR);
48
54
  }
49
- return this.localDevState.getAppDataByUid(this.appNode.uid);
55
+ return data;
50
56
  }
51
57
  set appData(appData) {
52
58
  if (!this.appNode) {
@@ -60,32 +66,23 @@ class AppDevModeInterface {
60
66
  isOAuthApp() {
61
67
  return (this.appNode?.config.auth.type.toLowerCase() === APP_AUTH_TYPES.OAUTH);
62
68
  }
63
- // @TODO: Restore test account auto install functionality
64
- // private isAutomaticallyInstallable(): boolean {
65
- // const targetTestingAccount = getAccountConfig(
66
- // this.localDevState.targetTestingAccountId
67
- // );
68
- // if (!targetTestingAccount) {
69
- // return false;
70
- // }
71
- // const isTestAccount =
72
- // isDeveloperTestAccount(targetTestingAccount) ||
73
- // isSandbox(targetTestingAccount);
74
- // const hasCorrectParent =
75
- // targetTestingAccount.parentAccountId ===
76
- // this.localDevState.targetProjectAccountId;
77
- // return (
78
- // isTestAccount &&
79
- // hasCorrectParent &&
80
- // this.isStaticAuthApp()
81
- // );
82
- // }
69
+ isAutomaticallyInstallable() {
70
+ const targetTestingAccount = getAccountConfig(this.localDevState.targetTestingAccountId);
71
+ if (!targetTestingAccount) {
72
+ return false;
73
+ }
74
+ const isTestAccount = isDeveloperTestAccount(targetTestingAccount) ||
75
+ isSandbox(targetTestingAccount);
76
+ const hasCorrectParent = targetTestingAccount.parentAccountId ===
77
+ this.localDevState.targetProjectAccountId;
78
+ return isTestAccount && hasCorrectParent && this.isStaticAuthApp();
79
+ }
83
80
  async getAppInstallUrl() {
84
81
  if (this.appNode && this.isOAuthApp()) {
85
82
  return getOauthAppInstallUrl({
86
83
  targetAccountId: this.localDevState.targetTestingAccountId,
87
84
  env: this.localDevState.env,
88
- clientId: this.appData.clientId, // This is only called after checking that appData exists
85
+ clientId: this.appData.clientId,
89
86
  scopes: this.appNode.config.auth.requiredScopes,
90
87
  redirectUrls: this.appNode.config.auth.redirectUrls,
91
88
  });
@@ -120,13 +117,13 @@ class AppDevModeInterface {
120
117
  id: appData.id,
121
118
  clientId: appData.clientId,
122
119
  name: appData.name,
123
- installationState: APP_INSTALLATION_STATES.NOT_INSTALLED,
120
+ installationState: APP_INSTALLATION_STATES.UNKNOWN,
124
121
  scopeGroupIds: appData.scopeGroupIds,
125
122
  };
126
123
  this.marketplaceAppInstalls = uniquePortalInstallCount;
127
124
  }
128
125
  async checkMarketplaceAppInstalls() {
129
- if (!this.appData || !this.marketplaceAppInstalls) {
126
+ if (!this.marketplaceAppInstalls) {
130
127
  return;
131
128
  }
132
129
  SpinniesManager.fail('fetchAppData', {
@@ -142,53 +139,58 @@ class AppDevModeInterface {
142
139
  }
143
140
  this.localDevState.addUploadWarning(lib.AppDevModeInterface.defaultMarketplaceAppWarning(this.marketplaceAppInstalls));
144
141
  }
145
- // @TODO: Restore test account auto install functionality
146
- // private async autoInstallStaticAuthApp(): Promise<void> {
147
- // const shouldInstall = await installAppAutoPrompt();
148
- // if (!shouldInstall) {
149
- // uiLogger.log(lib.AppDevModeInterface.autoInstallDeclined);
150
- // process.exit(EXIT_CODES.SUCCESS);
151
- // }
152
- // await installStaticAuthAppOnTestAccount(
153
- // this.appData!.id,
154
- // this.localDevState.targetTestingAccountId,
155
- // this.appData!.scopeGroupIds
156
- // );
157
- // }
142
+ async waitUntilAppIsInstalled(installUrl) {
143
+ uiLogger.log(lib.AppDevModeInterface.waitUntilAppIsInstalled.link(installUrl));
144
+ SpinniesManager.add('waitUntilAppIsInstalled', {
145
+ text: lib.AppDevModeInterface.waitUntilAppIsInstalled.waiting,
146
+ });
147
+ await new Promise(resolve => {
148
+ this.appInstallResolve = resolve;
149
+ });
150
+ SpinniesManager.succeed('waitUntilAppIsInstalled', {
151
+ text: lib.AppDevModeInterface.waitUntilAppIsInstalled.success(this.appNode?.config.name || '', this.localDevState.targetTestingAccountId),
152
+ });
153
+ }
154
+ async autoInstallStaticAuthApp() {
155
+ const shouldInstall = await installAppAutoPrompt();
156
+ if (!shouldInstall) {
157
+ uiLogger.log(lib.AppDevModeInterface.autoInstallDeclined);
158
+ process.exit(EXIT_CODES.SUCCESS);
159
+ }
160
+ uiLogger.log('');
161
+ SpinniesManager.add('autoInstallStaticAuthApp', {
162
+ text: lib.AppDevModeInterface.autoInstallStaticAuthApp.installing(this.appData.name, this.localDevState.targetTestingAccountId),
163
+ });
164
+ try {
165
+ await installStaticAuthAppOnTestAccount(this.appData.id, this.localDevState.targetTestingAccountId, this.appData.scopeGroupIds);
166
+ SpinniesManager.succeed('autoInstallStaticAuthApp', {
167
+ text: lib.AppDevModeInterface.autoInstallStaticAuthApp.success(this.appData.name, this.localDevState.targetTestingAccountId),
168
+ });
169
+ return true;
170
+ }
171
+ catch (e) {
172
+ SpinniesManager.fail('autoInstallStaticAuthApp', {
173
+ text: lib.AppDevModeInterface.autoInstallStaticAuthApp.error(this.appData.name, this.localDevState.targetTestingAccountId),
174
+ failColor: 'white',
175
+ });
176
+ return false;
177
+ }
178
+ }
158
179
  async installAppOrOpenInstallUrl(isReinstall) {
159
- // @TODO: Restore test account auto install functionality
160
- // if (this.isAutomaticallyInstallable()) {
161
- // try {
162
- // await this.autoInstallStaticAuthApp();
163
- // uiLogger.success(
164
- // lib.AppDevModeInterface.autoInstallSuccess(
165
- // this.appData!.name,
166
- // this.localDevState.targetTestingAccountId
167
- // )
168
- // );
169
- // return;
170
- // } catch (e) {
171
- // uiLogger.error(
172
- // lib.AppDevModeInterface.autoInstallError(
173
- // this.appData!.name,
174
- // this.localDevState.targetTestingAccountId
175
- // )
176
- // );
177
- // }
178
- // }
179
- const staticAuthInstallOptions = this.isStaticAuthApp()
180
- ? {
181
- testingAccountId: this.localDevState.targetTestingAccountId,
182
- projectAccountId: this.localDevState.targetProjectAccountId,
183
- projectName: this.localDevState.projectConfig.name,
184
- appUid: this.appNode.uid,
180
+ if (this.isAutomaticallyInstallable()) {
181
+ const installSuccess = await this.autoInstallStaticAuthApp();
182
+ if (installSuccess) {
183
+ return;
185
184
  }
186
- : undefined;
185
+ }
187
186
  const installUrl = await this.getAppInstallUrl();
188
- await installAppBrowserPrompt(installUrl, isReinstall, staticAuthInstallOptions);
187
+ await installAppBrowserPrompt(installUrl, isReinstall);
188
+ if (!isReinstall) {
189
+ await this.waitUntilAppIsInstalled(installUrl);
190
+ }
189
191
  }
190
192
  async checkTestAccountAppInstallation() {
191
- if (!this.appNode || !this.appData) {
193
+ if (!this.appNode) {
192
194
  return {};
193
195
  }
194
196
  const { data: { isInstalledWithScopeGroups, previouslyAuthorizedScopeGroups }, } = await fetchAppInstallationData(this.localDevState.targetTestingAccountId, this.localDevState.projectId, this.appNode.uid, this.appNode.config.auth.requiredScopes, this.appNode.config.auth.optionalScopes);
@@ -205,11 +207,58 @@ class AppDevModeInterface {
205
207
  installationState: APP_INSTALLATION_STATES.INSTALLED_WITH_OUTDATED_SCOPES,
206
208
  };
207
209
  }
210
+ else {
211
+ this.appData = {
212
+ ...this.appData,
213
+ installationState: APP_INSTALLATION_STATES.NOT_INSTALLED,
214
+ };
215
+ }
208
216
  return { needsInstall: !isInstalledWithScopeGroups, isReinstall };
209
217
  }
210
- onDevServerMessage = (message) => {
218
+ async validateOauthAppRedirectUrl() {
219
+ const redirectUrl = this.appNode?.config.auth.redirectUrls[0];
220
+ if (!redirectUrl) {
221
+ return;
222
+ }
223
+ const serverIsRunningAtRedirectUrl = await isServerRunningAtUrl(redirectUrl);
224
+ if (!serverIsRunningAtRedirectUrl) {
225
+ uiLogger.log('');
226
+ uiLogger.error(lib.AppDevModeInterface.oauthAppRedirectUrlError(redirectUrl));
227
+ process.exit(EXIT_CODES.ERROR);
228
+ }
229
+ }
230
+ resolveAppInstallPromise() {
231
+ if (this.appInstallResolve) {
232
+ this.appInstallResolve();
233
+ this.appInstallResolve = undefined;
234
+ }
235
+ }
236
+ handleAppInstallSuccessDevServerMessage() {
237
+ this.resolveAppInstallPromise();
238
+ this.appData = {
239
+ ...this.appData,
240
+ installationState: APP_INSTALLATION_STATES.INSTALLED,
241
+ };
242
+ }
243
+ handleAppInstallInitiatedDevServerMessage() {
244
+ this.resolveAppInstallPromise();
245
+ }
246
+ handleAppInstallFailureDevServerMessage() {
247
+ uiLogger.error(lib.AppDevModeInterface.installationFailed);
248
+ process.exit(EXIT_CODES.ERROR);
249
+ }
250
+ onDevServerMessage = async (message) => {
211
251
  if (message === LOCAL_DEV_SERVER_MESSAGE_TYPES.WEBSOCKET_SERVER_CONNECTED) {
212
- this.checkTestAccountAppInstallation();
252
+ await this.checkTestAccountAppInstallation();
253
+ }
254
+ else if (message === LOCAL_DEV_SERVER_MESSAGE_TYPES.STATIC_AUTH_APP_INSTALL_SUCCESS) {
255
+ this.handleAppInstallSuccessDevServerMessage();
256
+ }
257
+ else if (message === LOCAL_DEV_SERVER_MESSAGE_TYPES.STATIC_AUTH_APP_INSTALL_FAILURE) {
258
+ this.handleAppInstallFailureDevServerMessage();
259
+ }
260
+ else if (message === LOCAL_DEV_SERVER_MESSAGE_TYPES.OAUTH_APP_INSTALL_INITIATED) {
261
+ this.handleAppInstallInitiatedDevServerMessage();
213
262
  }
214
263
  };
215
264
  onChangeProjectNodes = (nodes) => {
@@ -227,17 +276,11 @@ class AppDevModeInterface {
227
276
  this.localDevState.addUploadWarning(lib.AppDevModeInterface.authTypeChanged);
228
277
  }
229
278
  };
230
- setUpStateListeners() {
231
- this.localDevState.addListener('devServerMessage', this.onDevServerMessage);
232
- this.localDevState.addListener('projectNodes', this.onChangeProjectNodes);
233
- }
234
279
  removeStateListeners() {
235
280
  this.localDevState.removeListener('devServerMessage', this.onDevServerMessage);
236
281
  this.localDevState.removeListener('projectNodes', this.onChangeProjectNodes);
237
282
  }
238
- // @ts-expect-error TODO: reconcile types between CLI and UIE Dev Server
239
- // In the future, update UIE Dev Server to use LocalDevState
240
- async setup(args) {
283
+ async setup() {
241
284
  if (!this.appNode) {
242
285
  return;
243
286
  }
@@ -254,6 +297,10 @@ class AppDevModeInterface {
254
297
  failColor: 'white',
255
298
  });
256
299
  }
300
+ if (this.isOAuthApp()) {
301
+ await this.validateOauthAppRedirectUrl();
302
+ }
303
+ this.localDevState.addListener('devServerMessage', this.onDevServerMessage);
257
304
  await this.installAppOrOpenInstallUrl(isReinstall || false);
258
305
  }
259
306
  else {
@@ -268,32 +315,12 @@ class AppDevModeInterface {
268
315
  catch (e) {
269
316
  logError(e);
270
317
  }
271
- this.setUpStateListeners();
272
- return UIEDevModeInterface.setup(args);
273
318
  }
274
319
  async start() {
275
- if (!this.appNode) {
276
- return;
277
- }
278
- return UIEDevModeInterface.start({
279
- accountId: this.localDevState.targetTestingAccountId,
280
- // @ts-expect-error TODO: reconcile types between CLI and UIE Dev Server
281
- projectConfig: this.localDevState.projectConfig,
282
- requestPorts,
283
- });
284
- }
285
- async fileChange(filePath, event) {
286
- if (!this.appNode) {
287
- return;
288
- }
289
- return UIEDevModeInterface.fileChange(filePath, event);
320
+ this.localDevState.addListener('projectNodes', this.onChangeProjectNodes);
290
321
  }
291
322
  async cleanup() {
292
- if (!this.appNode) {
293
- return;
294
- }
295
323
  this.removeStateListeners();
296
- return UIEDevModeInterface.cleanup();
297
324
  }
298
325
  }
299
326
  export default AppDevModeInterface;
@@ -1,40 +1,21 @@
1
- import { ProjectConfig, ComponentTypes, Component } from '../../../types/Projects.js';
2
- type DevServerInterface = {
3
- setup?: Function;
4
- start?: (options: object) => Promise<void>;
5
- fileChange?: (filePath: string, event: string) => Promise<void>;
6
- cleanup?: () => Promise<void>;
7
- };
8
- type ComponentsByType = {
9
- [key in ComponentTypes]?: {
10
- [key: string]: Component;
11
- };
1
+ import LocalDevState from './LocalDevState.js';
2
+ import LocalDevLogger from './LocalDevLogger.js';
3
+ type DevServerManagerConstructorOptions = {
4
+ localDevState: LocalDevState;
5
+ logger: LocalDevLogger;
12
6
  };
13
7
  declare class DevServerManager {
14
8
  private initialized;
15
9
  private started;
16
- private componentsByType;
17
10
  private devServers;
18
- constructor();
19
- iterateDevServers(callback: (serverInterface: DevServerInterface, compatibleComponents: {
20
- [key: string]: Component;
21
- }) => Promise<void>): Promise<void>;
22
- arrangeComponentsByType(components: Component[]): ComponentsByType;
23
- setup({ components, onUploadRequired, accountId, setActiveApp, }: {
24
- components: Component[];
25
- onUploadRequired: () => void;
26
- accountId: number;
27
- setActiveApp: (appUid: string | undefined) => Promise<void>;
28
- }): Promise<void>;
29
- start({ accountId, projectConfig, }: {
30
- accountId: number;
31
- projectConfig: ProjectConfig;
32
- }): Promise<void>;
11
+ constructor(options: DevServerManagerConstructorOptions);
12
+ private iterateDevServers;
13
+ setup(): Promise<void>;
14
+ start(): Promise<void>;
33
15
  fileChange({ filePath, event, }: {
34
16
  filePath: string;
35
17
  event: string;
36
18
  }): Promise<void>;
37
19
  cleanup(): Promise<void>;
38
20
  }
39
- declare const Manager: DevServerManager;
40
- export default Manager;
21
+ export default DevServerManager;
@@ -1,93 +1,39 @@
1
- import { logger } from '@hubspot/local-dev-lib/logger';
2
- import { DevModeInterface as UIEDevModeInterface } from '@hubspot/ui-extensions-dev-server';
3
- import { startPortManagerServer, stopPortManagerServer, requestPorts, } from '@hubspot/local-dev-lib/portManager';
4
- import { getHubSpotApiOrigin, getHubSpotWebsiteOrigin, } from '@hubspot/local-dev-lib/urls';
5
- import { getAccountConfig } from '@hubspot/local-dev-lib/config';
6
- import { ComponentTypes, } from '../../../types/Projects.js';
1
+ import AppDevModeInterface from './AppDevModeInterface.js';
7
2
  import { lib } from '../../../lang/en.js';
8
- import { uiLogger } from '../../ui/logger.js';
9
- const SERVER_KEYS = {
10
- privateApp: 'privateApp',
11
- publicApp: 'publicApp',
12
- };
3
+ import UIExtensionsDevModeInterface from './UIExtensionsDevModeInterface.js';
13
4
  class DevServerManager {
14
5
  initialized;
15
6
  started;
16
- componentsByType;
17
7
  devServers;
18
- constructor() {
8
+ constructor(options) {
19
9
  this.initialized = false;
20
10
  this.started = false;
21
- this.componentsByType = {};
22
- this.devServers = {
23
- [SERVER_KEYS.privateApp]: {
24
- componentType: ComponentTypes.PrivateApp,
25
- serverInterface: UIEDevModeInterface,
26
- },
27
- [SERVER_KEYS.publicApp]: {
28
- componentType: ComponentTypes.PublicApp,
29
- serverInterface: UIEDevModeInterface,
30
- },
31
- };
11
+ const AppsDevServer = new AppDevModeInterface({
12
+ localDevState: options.localDevState,
13
+ localDevLogger: options.logger,
14
+ });
15
+ const UIExtensionsDevServer = new UIExtensionsDevModeInterface({
16
+ localDevState: options.localDevState,
17
+ });
18
+ this.devServers = [AppsDevServer, UIExtensionsDevServer];
32
19
  }
33
20
  async iterateDevServers(callback) {
34
- const serverKeys = Object.keys(this.devServers);
35
- for (let i = 0; i < serverKeys.length; i++) {
36
- const serverKey = serverKeys[i];
37
- const devServer = this.devServers[serverKey];
38
- const compatibleComponents = this.componentsByType[devServer.componentType] || {};
39
- if (Object.keys(compatibleComponents).length) {
40
- await callback(devServer.serverInterface, compatibleComponents);
41
- }
42
- else {
43
- uiLogger.debug(lib.DevServerManager.noCompatibleComponents(serverKey));
44
- }
45
- }
21
+ await Promise.all(this.devServers.map(devServer => callback(devServer)));
46
22
  }
47
- arrangeComponentsByType(components) {
48
- return components.reduce((acc, component) => {
49
- if (!acc[component.type]) {
50
- acc[component.type] = {};
23
+ async setup() {
24
+ for (const devServer of this.devServers) {
25
+ if (devServer.setup) {
26
+ // Run setup functions in order
27
+ await devServer.setup();
51
28
  }
52
- if ('name' in component.config && component.config.name) {
53
- acc[component.type][component.config.name] = component;
54
- }
55
- return acc;
56
- }, {});
57
- }
58
- async setup({ components, onUploadRequired, accountId, setActiveApp, }) {
59
- this.componentsByType = this.arrangeComponentsByType(components);
60
- let env;
61
- const accountConfig = getAccountConfig(accountId);
62
- if (accountConfig) {
63
- env = accountConfig.env;
64
29
  }
65
- await startPortManagerServer();
66
- await this.iterateDevServers(async (serverInterface, compatibleComponents) => {
67
- if (serverInterface.setup) {
68
- await serverInterface.setup({
69
- components: compatibleComponents,
70
- onUploadRequired,
71
- logger,
72
- urls: {
73
- api: getHubSpotApiOrigin(env),
74
- web: getHubSpotWebsiteOrigin(env),
75
- },
76
- setActiveApp,
77
- });
78
- }
79
- });
80
30
  this.initialized = true;
81
31
  }
82
- async start({ accountId, projectConfig, }) {
32
+ async start() {
83
33
  if (this.initialized) {
84
34
  await this.iterateDevServers(async (serverInterface) => {
85
35
  if (serverInterface.start) {
86
- await serverInterface.start({
87
- accountId,
88
- projectConfig,
89
- requestPorts,
90
- });
36
+ await serverInterface.start();
91
37
  }
92
38
  });
93
39
  }
@@ -112,9 +58,7 @@ class DevServerManager {
112
58
  await serverInterface.cleanup();
113
59
  }
114
60
  });
115
- await stopPortManagerServer();
116
61
  }
117
62
  }
118
63
  }
119
- const Manager = new DevServerManager();
120
- export default Manager;
64
+ export default DevServerManager;
@@ -0,0 +1,40 @@
1
+ import { ProjectConfig, ComponentTypes, Component } from '../../../types/Projects.js';
2
+ type DevServerInterface = {
3
+ setup?: Function;
4
+ start?: (options: object) => Promise<void>;
5
+ fileChange?: (filePath: string, event: string) => Promise<void>;
6
+ cleanup?: () => Promise<void>;
7
+ };
8
+ type ComponentsByType = {
9
+ [key in ComponentTypes]?: {
10
+ [key: string]: Component;
11
+ };
12
+ };
13
+ declare class DevServerManager_DEPRECATED {
14
+ private initialized;
15
+ private started;
16
+ private componentsByType;
17
+ private devServers;
18
+ constructor();
19
+ iterateDevServers(callback: (serverInterface: DevServerInterface, compatibleComponents: {
20
+ [key: string]: Component;
21
+ }) => Promise<void>): Promise<void>;
22
+ arrangeComponentsByType(components: Component[]): ComponentsByType;
23
+ setup({ components, onUploadRequired, accountId, setActiveApp, }: {
24
+ components: Component[];
25
+ onUploadRequired: () => void;
26
+ accountId: number;
27
+ setActiveApp: (appUid: string | undefined) => Promise<void>;
28
+ }): Promise<void>;
29
+ start({ accountId, projectConfig, }: {
30
+ accountId: number;
31
+ projectConfig: ProjectConfig;
32
+ }): Promise<void>;
33
+ fileChange({ filePath, event, }: {
34
+ filePath: string;
35
+ event: string;
36
+ }): Promise<void>;
37
+ cleanup(): Promise<void>;
38
+ }
39
+ declare const Manager: DevServerManager_DEPRECATED;
40
+ export default Manager;