@hubspot/cli 5.2.1-beta.3 → 5.2.1-beta.4

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.
@@ -221,7 +221,9 @@ exports.handler = async options => {
221
221
  parentAccountId: targetProjectAccountId,
222
222
  projectConfig,
223
223
  projectDir,
224
+ projectId: project.id,
224
225
  targetAccountId: targetTestingAccountId,
226
+ env,
225
227
  });
226
228
 
227
229
  await LocalDev.start();
package/lang/en.lyaml CHANGED
@@ -927,6 +927,7 @@ en:
927
927
  exitingStart: "Stopping local dev server ..."
928
928
  exitingSucceed: "Successfully exited"
929
929
  exitingFail: "Failed to cleanup before exiting"
930
+ missingUid: "Could not find a uid for the selected app. Confirm that the app config file contains the uid field and re-run {{ devCommand }}."
930
931
  uploadWarning:
931
932
  appLabel: "[App]"
932
933
  uiExtensionLabel: "[UI Extension]"
@@ -1231,6 +1232,10 @@ en:
1231
1232
  destRequired: "You must specify a destination directory."
1232
1233
  cleanUploadPrompt:
1233
1234
  message: "You are about to remove any remote files in \"{{ filePath }}\" on HubSpot account {{ accountId }} that don't exist locally. Are you sure you want to do this?"
1235
+ installPublicAppPrompt:
1236
+ explanation: "Local development requires this app to be installed in the target test account"
1237
+ prompt: "Open hubspot.com to install this app?"
1238
+ decline: "To continue local development of this app, install it in your target test account and re-run {{#bold}}`hs project dev`{{/bold}}"
1234
1239
  convertFields:
1235
1240
  positionals:
1236
1241
  src:
@@ -4,6 +4,12 @@ const chalk = require('chalk');
4
4
  const { i18n } = require('./lang');
5
5
  const { handleKeypress } = require('./process');
6
6
  const { logger } = require('@hubspot/local-dev-lib/logger');
7
+ const {
8
+ fetchAppInstallationData,
9
+ } = require('@hubspot/local-dev-lib/api/localDevAuth');
10
+ const {
11
+ fetchPublicAppsForPortal,
12
+ } = require('@hubspot/local-dev-lib/api/appsDev');
7
13
  const {
8
14
  getAccountId,
9
15
  getConfigDefaultAccount,
@@ -26,6 +32,8 @@ const {
26
32
  uiLink,
27
33
  uiLine,
28
34
  } = require('./ui');
35
+ const { logErrorInstance } = require('./errorHandlers/standardErrors');
36
+ const { installPublicAppPrompt } = require('./prompts/installPublicAppPrompt');
29
37
 
30
38
  const WATCH_EVENTS = {
31
39
  add: 'add',
@@ -44,6 +52,7 @@ class LocalDevManager {
44
52
 
45
53
  this.projectConfig = options.projectConfig;
46
54
  this.projectDir = options.projectDir;
55
+ this.projectId = options.projectId;
47
56
  this.debug = options.debug || false;
48
57
  this.deployedBuild = options.deployedBuild;
49
58
  this.isGithubLinked = options.isGithubLinked;
@@ -51,6 +60,8 @@ class LocalDevManager {
51
60
  this.uploadWarnings = {};
52
61
  this.runnableComponents = this.getRunnableComponents(options.components);
53
62
  this.activeApp = null;
63
+ this.activePublicAppData = null;
64
+ this.env = options.env;
54
65
 
55
66
  this.projectSourceDir = path.join(
56
67
  this.projectDir,
@@ -84,10 +95,43 @@ class LocalDevManager {
84
95
  return components.filter(component => component.runnable);
85
96
  }
86
97
 
87
- async setActiveApp(app) {
88
- this.activeApp = app;
98
+ async setActiveApp(appUid) {
99
+ if (!appUid) {
100
+ logger.error(
101
+ i18n(`${i18nKey}.missingUid`, {
102
+ devCommand: uiCommandReference('hs project dev'),
103
+ })
104
+ );
105
+ process.exit(EXIT_CODES.ERROR);
106
+ }
107
+ this.activeApp = this.runnableComponents.find(component => {
108
+ return component.config.uid === appUid;
109
+ });
89
110
 
90
- // TODO: Show the install warnings the first time this gets set
111
+ if (this.activeApp.type === COMPONENT_TYPES.publicApp) {
112
+ try {
113
+ await this.setActivePublicAppData();
114
+ await this.checkPublicAppInstallation();
115
+ } catch (e) {
116
+ logErrorInstance(e);
117
+ }
118
+ }
119
+ }
120
+
121
+ async setActivePublicAppData() {
122
+ if (!this.activeApp) {
123
+ return;
124
+ }
125
+
126
+ const portalPublicApps = await fetchPublicAppsForPortal(
127
+ this.targetProjectAccountId
128
+ );
129
+
130
+ const activePublicAppData = portalPublicApps.find(
131
+ ({ sourceId }) => sourceId === this.activeApp.config.uid
132
+ );
133
+
134
+ this.activePublicAppData = activePublicAppData;
91
135
  }
92
136
 
93
137
  async start() {
@@ -179,6 +223,32 @@ class LocalDevManager {
179
223
  process.exit(EXIT_CODES.SUCCESS);
180
224
  }
181
225
 
226
+ getActiveAppInstallationData() {
227
+ return fetchAppInstallationData(
228
+ this.targetAccountId,
229
+ this.projectId,
230
+ this.activeApp.config.uid,
231
+ this.activeApp.config.auth.requiredScopes,
232
+ this.activeApp.config.auth.optionalScopes
233
+ );
234
+ }
235
+
236
+ async checkPublicAppInstallation() {
237
+ const {
238
+ isInstalledWithScopeGroups: isInstalled,
239
+ } = await this.getActiveAppInstallationData();
240
+
241
+ if (!isInstalled) {
242
+ await installPublicAppPrompt(
243
+ this.env,
244
+ this.targetAccountId,
245
+ this.activePublicAppData.clientId,
246
+ this.activeApp.config.auth.requiredScopes,
247
+ this.activeApp.config.auth.redirectUrls
248
+ );
249
+ }
250
+ }
251
+
182
252
  updateKeypressListeners() {
183
253
  handleKeypress(async key => {
184
254
  if ((key.ctrl && key.name === 'c') || key.name === 'q') {
@@ -0,0 +1,42 @@
1
+ const open = require('open');
2
+ const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
3
+ const { logger } = require('@hubspot/local-dev-lib/logger');
4
+ const { promptUser } = require('./promptUtils');
5
+ const { i18n } = require('../lang');
6
+ const { EXIT_CODES } = require('../enums/exitCodes');
7
+
8
+ const i18nKey = 'lib.prompts.installPublicAppPrompt';
9
+
10
+ const installPublicAppPrompt = async (
11
+ env,
12
+ targetAccountId,
13
+ clientId,
14
+ scopes,
15
+ redirectUrls
16
+ ) => {
17
+ logger.log('');
18
+ logger.log(i18n(`${i18nKey}.explanation`));
19
+
20
+ const { shouldOpenBrowser } = await promptUser({
21
+ name: 'shouldOpenBrowser',
22
+ type: 'confirm',
23
+ message: i18n(`${i18nKey}.prompt`),
24
+ });
25
+
26
+ if (!shouldOpenBrowser) {
27
+ logger.log(i18n(`${i18nKey}.decline`));
28
+ process.exit(EXIT_CODES.SUCCESS);
29
+ }
30
+
31
+ const websiteOrigin = getHubSpotWebsiteOrigin(env);
32
+
33
+ const url =
34
+ `${websiteOrigin}/oauth/${targetAccountId}/authorize` +
35
+ `?client_id=${encodeURIComponent(clientId)}` +
36
+ `&scope=${encodeURIComponent(scopes)}` +
37
+ `&redirect_uri=${encodeURIComponent(redirectUrls)}`;
38
+
39
+ open(url);
40
+ };
41
+
42
+ module.exports = { installPublicAppPrompt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cli",
3
- "version": "5.2.1-beta.3",
3
+ "version": "5.2.1-beta.4",
4
4
  "description": "CLI for working with HubSpot",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,10 +8,10 @@
8
8
  "url": "https://github.com/HubSpot/hubspot-cms-tools"
9
9
  },
10
10
  "dependencies": {
11
- "@hubspot/local-dev-lib": "1.0.1",
12
- "@hubspot/serverless-dev-runtime": "5.2.1-beta.2",
11
+ "@hubspot/local-dev-lib": "1.1.0",
12
+ "@hubspot/serverless-dev-runtime": "5.2.1-beta.4",
13
13
  "@hubspot/theme-preview-dev-server": "0.0.5",
14
- "@hubspot/ui-extensions-dev-server": "0.8.15",
14
+ "@hubspot/ui-extensions-dev-server": "0.8.16",
15
15
  "archiver": "^5.3.0",
16
16
  "chalk": "^4.1.2",
17
17
  "chokidar": "^3.0.1",
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "70d81f550d7916e8eb80ec22ce41ac51265c9a36"
48
+ "gitHead": "59dbc8bff2ca377c95e1eea4dcc52389e98ac644"
49
49
  }