@hubspot/cli 5.2.1-beta.2 → 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.
Files changed (126) hide show
  1. package/bin/cli.js +1 -1
  2. package/commands/accounts/clean.js +3 -3
  3. package/commands/accounts/info.js +1 -1
  4. package/commands/accounts/list.js +1 -1
  5. package/commands/accounts/remove.js +1 -1
  6. package/commands/accounts/rename.js +1 -1
  7. package/commands/accounts/use.js +1 -1
  8. package/commands/accounts.js +1 -1
  9. package/commands/auth.js +3 -3
  10. package/commands/cms/convertFields.js +1 -1
  11. package/commands/cms/lighthouseScore.js +1 -1
  12. package/commands/cms/reactModules.js +1 -1
  13. package/commands/cms.js +1 -1
  14. package/commands/config/set/allowUsageTracking.js +1 -2
  15. package/commands/config/set/defaultMode.js +1 -1
  16. package/commands/config/set/httpTimeout.js +1 -1
  17. package/commands/config/set.js +1 -1
  18. package/commands/config.js +1 -1
  19. package/commands/create/api-sample.js +1 -1
  20. package/commands/create/module.js +1 -1
  21. package/commands/create/template.js +1 -1
  22. package/commands/create.js +1 -1
  23. package/commands/customObject/create.js +1 -1
  24. package/commands/customObject/schema/create.js +1 -2
  25. package/commands/customObject/schema/delete.js +1 -2
  26. package/commands/customObject/schema/fetch-all.js +1 -2
  27. package/commands/customObject/schema/fetch.js +1 -2
  28. package/commands/customObject/schema/list.js +1 -1
  29. package/commands/customObject/schema/update.js +1 -2
  30. package/commands/customObject/schema.js +1 -1
  31. package/commands/customObject.js +1 -1
  32. package/commands/feedback.js +1 -1
  33. package/commands/fetch.js +1 -1
  34. package/commands/filemanager/fetch.js +1 -1
  35. package/commands/filemanager/upload.js +1 -1
  36. package/commands/filemanager.js +1 -1
  37. package/commands/functions/deploy.js +1 -1
  38. package/commands/functions/list.js +1 -1
  39. package/commands/functions/server.js +1 -1
  40. package/commands/functions.js +1 -1
  41. package/commands/hubdb/clear.js +1 -1
  42. package/commands/hubdb/create.js +1 -1
  43. package/commands/hubdb/delete.js +1 -1
  44. package/commands/hubdb/fetch.js +1 -1
  45. package/commands/hubdb.js +1 -1
  46. package/commands/init.js +1 -1
  47. package/commands/lint.js +1 -1
  48. package/commands/list.js +1 -1
  49. package/commands/logs.js +1 -1
  50. package/commands/module/marketplace-validate.js +1 -1
  51. package/commands/module.js +1 -1
  52. package/commands/mv.js +1 -1
  53. package/commands/open.js +1 -1
  54. package/commands/project/add.js +1 -1
  55. package/commands/project/create.js +1 -1
  56. package/commands/project/deploy.js +1 -1
  57. package/commands/project/dev.js +37 -19
  58. package/commands/project/download.js +9 -5
  59. package/commands/project/listBuilds.js +1 -1
  60. package/commands/project/logs.js +1 -1
  61. package/commands/project/open.js +8 -4
  62. package/commands/project/upload.js +1 -1
  63. package/commands/project/watch.js +1 -1
  64. package/commands/project.js +1 -1
  65. package/commands/remove.js +1 -1
  66. package/commands/sandbox/create.js +4 -4
  67. package/commands/sandbox/delete.js +1 -1
  68. package/commands/sandbox/sync.js +2 -2
  69. package/commands/sandbox.js +1 -1
  70. package/commands/secrets/addSecret.js +1 -1
  71. package/commands/secrets/deleteSecret.js +1 -1
  72. package/commands/secrets/listSecrets.js +1 -1
  73. package/commands/secrets/updateSecret.js +1 -1
  74. package/commands/secrets.js +1 -1
  75. package/commands/theme/generate-selectors.js +1 -1
  76. package/commands/theme/marketplace-validate.js +1 -1
  77. package/commands/theme/preview.js +2 -2
  78. package/commands/theme.js +1 -1
  79. package/commands/upload.js +1 -1
  80. package/commands/watch.js +1 -1
  81. package/lang/en.lyaml +1378 -1374
  82. package/lib/DevServerManager.js +3 -2
  83. package/lib/LocalDevManager.js +89 -5
  84. package/lib/commonOpts.js +1 -1
  85. package/lib/developerTestAccountCreate.js +4 -5
  86. package/lib/developerTestAccounts.js +1 -1
  87. package/lib/errorHandlers/apiErrors.js +1 -1
  88. package/lib/errorHandlers/overrideErrors.js +1 -1
  89. package/lib/errorHandlers/standardErrors.js +1 -1
  90. package/lib/generate-selectors.js +1 -1
  91. package/lib/localDev.js +8 -12
  92. package/lib/process.js +1 -1
  93. package/lib/projects.js +6 -6
  94. package/lib/projectsWatch.js +1 -1
  95. package/lib/prompts/accountsPrompt.js +1 -1
  96. package/lib/prompts/buildIdPrompt.js +1 -1
  97. package/lib/prompts/cleanUploadPrompt.js +1 -1
  98. package/lib/prompts/cmsFieldPrompt.js +1 -1
  99. package/lib/prompts/createApiSamplePrompt.js +1 -1
  100. package/lib/prompts/createFunctionPrompt.js +1 -1
  101. package/lib/prompts/createModulePrompt.js +1 -1
  102. package/lib/prompts/createProjectPrompt.js +1 -1
  103. package/lib/prompts/createTemplatePrompt.js +1 -1
  104. package/lib/prompts/developerTestAccountNamePrompt.js +1 -1
  105. package/lib/prompts/downloadProjectPrompt.js +1 -1
  106. package/lib/prompts/enterAccountNamePrompt.js +1 -1
  107. package/lib/prompts/feedbackPrompt.js +1 -1
  108. package/lib/prompts/folderOverwritePrompt.js +1 -1
  109. package/lib/prompts/installPublicAppPrompt.js +42 -0
  110. package/lib/prompts/personalAccessKeyPrompt.js +1 -1
  111. package/lib/prompts/previewPrompt.js +1 -1
  112. package/lib/prompts/projectAddPrompt.js +1 -1
  113. package/lib/prompts/projectDevTargetAccountPrompt.js +1 -1
  114. package/lib/prompts/projectNamePrompt.js +2 -2
  115. package/lib/prompts/projectsLogsPrompt.js +1 -1
  116. package/lib/prompts/sandboxesPrompt.js +1 -1
  117. package/lib/prompts/secretPrompt.js +1 -1
  118. package/lib/prompts/setAsDefaultAccountPrompt.js +1 -1
  119. package/lib/prompts/uploadPrompt.js +1 -1
  120. package/lib/sandboxCreate.js +4 -5
  121. package/lib/sandboxSync.js +1 -1
  122. package/lib/sandboxes.js +7 -9
  123. package/lib/ui/git.js +1 -1
  124. package/lib/ui/index.js +2 -2
  125. package/lib/ui/serverlessFunctionLogs.js +1 -1
  126. package/package.json +6 -6
@@ -15,7 +15,7 @@ const {
15
15
  } = require('@hubspot/local-dev-lib/urls');
16
16
  const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
17
17
 
18
- const i18nKey = 'cli.lib.DevServerManager';
18
+ const i18nKey = 'lib.DevServerManager';
19
19
 
20
20
  const SERVER_KEYS = {
21
21
  privateApp: 'privateApp',
@@ -71,7 +71,7 @@ class DevServerManager {
71
71
  }, {});
72
72
  }
73
73
 
74
- async setup({ components, onUploadRequired, accountId }) {
74
+ async setup({ components, onUploadRequired, accountId, setActiveApp }) {
75
75
  this.componentsByType = this.arrangeComponentsByType(components);
76
76
  const { env } = getAccountConfig(accountId);
77
77
  await startPortManagerServer();
@@ -87,6 +87,7 @@ class DevServerManager {
87
87
  api: getHubSpotApiOrigin(env),
88
88
  web: getHubSpotWebsiteOrigin(env),
89
89
  },
90
+ setActiveApp,
90
91
  });
91
92
  }
92
93
  }
@@ -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',
@@ -34,19 +42,26 @@ const WATCH_EVENTS = {
34
42
  unlinkDir: 'unlinkDir',
35
43
  };
36
44
 
37
- const i18nKey = 'cli.lib.LocalDevManager';
45
+ const i18nKey = 'lib.LocalDevManager';
38
46
 
39
47
  class LocalDevManager {
40
48
  constructor(options) {
41
49
  this.targetAccountId = options.targetAccountId;
50
+ // The account that the project exists in. This is not always the targetAccountId
51
+ this.targetProjectAccountId = options.parentAccountId || options.accountId;
52
+
42
53
  this.projectConfig = options.projectConfig;
43
54
  this.projectDir = options.projectDir;
55
+ this.projectId = options.projectId;
44
56
  this.debug = options.debug || false;
45
57
  this.deployedBuild = options.deployedBuild;
46
58
  this.isGithubLinked = options.isGithubLinked;
47
59
  this.watcher = null;
48
60
  this.uploadWarnings = {};
49
61
  this.runnableComponents = this.getRunnableComponents(options.components);
62
+ this.activeApp = null;
63
+ this.activePublicAppData = null;
64
+ this.env = options.env;
50
65
 
51
66
  this.projectSourceDir = path.join(
52
67
  this.projectDir,
@@ -80,6 +95,45 @@ class LocalDevManager {
80
95
  return components.filter(component => component.runnable);
81
96
  }
82
97
 
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
+ });
110
+
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;
135
+ }
136
+
83
137
  async start() {
84
138
  SpinniesManager.stopAll();
85
139
  SpinniesManager.init();
@@ -88,7 +142,7 @@ class LocalDevManager {
88
142
  if (!this.deployedBuild) {
89
143
  logger.error(
90
144
  i18n(`${i18nKey}.noDeployedBuild`, {
91
- accountIdentifier: uiAccountDescription(this.targetAccountId),
145
+ accountIdentifier: uiAccountDescription(this.targetProjectAccountId),
92
146
  uploadCommand: this.getUploadCommand(),
93
147
  })
94
148
  );
@@ -117,7 +171,10 @@ class LocalDevManager {
117
171
  logger.log(
118
172
  uiLink(
119
173
  i18n(`${i18nKey}.viewInHubSpotLink`),
120
- getProjectDetailUrl(this.projectConfig.name, this.targetAccountId)
174
+ getProjectDetailUrl(
175
+ this.projectConfig.name,
176
+ this.targetProjectAccountId
177
+ )
121
178
  )
122
179
  );
123
180
  logger.log();
@@ -166,6 +223,32 @@ class LocalDevManager {
166
223
  process.exit(EXIT_CODES.SUCCESS);
167
224
  }
168
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
+
169
252
  updateKeypressListeners() {
170
253
  handleKeypress(async key => {
171
254
  if ((key.ctrl && key.name === 'c') || key.name === 'q') {
@@ -177,9 +260,9 @@ class LocalDevManager {
177
260
  getUploadCommand() {
178
261
  const currentDefaultAccount = getConfigDefaultAccount();
179
262
 
180
- return this.targetAccountId !== getAccountId(currentDefaultAccount)
263
+ return this.targetProjectAccountId !== getAccountId(currentDefaultAccount)
181
264
  ? uiCommandReference(
182
- `hs project upload --account=${this.targetAccountId}`
265
+ `hs project upload --account=${this.targetProjectAccountId}`
183
266
  )
184
267
  : uiCommandReference('hs project upload');
185
268
  }
@@ -325,6 +408,7 @@ class LocalDevManager {
325
408
  components: this.runnableComponents,
326
409
  onUploadRequired: this.logUploadWarning.bind(this),
327
410
  accountId: this.targetAccountId,
411
+ setActiveApp: this.setActiveApp.bind(this),
328
412
  });
329
413
  return true;
330
414
  } catch (e) {
package/lib/commonOpts.js CHANGED
@@ -13,7 +13,7 @@ const {
13
13
  } = require('@hubspot/local-dev-lib/config');
14
14
  const { i18n } = require('./lang');
15
15
 
16
- const i18nKey = 'cli.lib.commonOpts';
16
+ const i18nKey = 'lib.commonOpts';
17
17
 
18
18
  const addAccountOptions = program =>
19
19
  program.option('portal', {
@@ -29,7 +29,7 @@ const {
29
29
  } = require('./prompts/personalAccessKeyPrompt');
30
30
  const { enterAccountNamePrompt } = require('./prompts/enterAccountNamePrompt');
31
31
 
32
- const i18nKey = 'cli.lib.developerTestAccount';
32
+ const i18nKey = 'lib.developerTestAccount';
33
33
 
34
34
  const saveDevTestAccountToConfig = async (env, result, force = false) => {
35
35
  let personalAccessKey = result.personalAccessKey;
@@ -60,10 +60,9 @@ const saveDevTestAccountToConfig = async (env, result, force = false) => {
60
60
  if (!force) {
61
61
  logger.log('');
62
62
  logger.warn(
63
- i18n(
64
- `cli.lib.prompts.enterAccountNamePrompt.errors.accountNameExists`,
65
- { name: nameForConfig }
66
- )
63
+ i18n(`lib.prompts.enterAccountNamePrompt.errors.accountNameExists`, {
64
+ name: nameForConfig,
65
+ })
67
66
  );
68
67
  const { name: promptName } = await enterAccountNamePrompt(
69
68
  nameForConfig + `_${result.id}`
@@ -22,7 +22,7 @@ const getHasDevTestAccounts = appDeveloperAccountConfig => {
22
22
  return false;
23
23
  };
24
24
 
25
- const i18nKey = 'cli.lib.developerTestAccount';
25
+ const i18nKey = 'lib.developerTestAccount';
26
26
 
27
27
  const validateDevTestAccountUsageLimits = async accountConfig => {
28
28
  const accountId = getAccountId(accountConfig.portalId);
@@ -19,7 +19,7 @@ const {
19
19
  const { overrideErrors } = require('./overrideErrors');
20
20
  const { i18n } = require('../lang');
21
21
 
22
- const i18nKey = 'cli.lib.errorHandlers.apiErrors';
22
+ const i18nKey = 'lib.errorHandlers.apiErrors';
23
23
 
24
24
  class ApiErrorContext extends ErrorContext {
25
25
  constructor(props = {}) {
@@ -5,7 +5,7 @@ const { PLATFORM_VERSION_ERROR_TYPES } = require('../constants');
5
5
  const { i18n } = require('../lang');
6
6
  const { uiLine, uiLink } = require('../ui');
7
7
 
8
- const i18nKey = 'cli.lib.errorHandlers.overrideErrors';
8
+ const i18nKey = 'lib.errorHandlers.overrideErrors';
9
9
 
10
10
  function createPlatformVersionError(subCategory, errData) {
11
11
  const docsLink = uiLink(
@@ -5,7 +5,7 @@ const {
5
5
  } = require('@hubspot/local-dev-lib/errors/standardErrors');
6
6
  const { i18n } = require('../lang');
7
7
 
8
- const i18nKey = 'cli.lib.errorHandlers.standardErrors';
8
+ const i18nKey = 'lib.errorHandlers.standardErrors';
9
9
 
10
10
  // TODO: Make these TS interfaces
11
11
  class ErrorContext {
@@ -8,7 +8,7 @@ const CSS_PSEUDO_CLASS_REGEX = new RegExp(
8
8
  /: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/,
9
9
  'g'
10
10
  );
11
- const i18nKey = 'cli.commands.theme.subcommands.generateSelectors';
11
+ const i18nKey = 'commands.theme.subcommands.generateSelectors';
12
12
 
13
13
  let maxFieldsDepth = 0;
14
14
 
package/lib/localDev.js CHANGED
@@ -10,7 +10,6 @@ const {
10
10
  const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
11
11
  const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
12
12
  const { createProject } = require('@hubspot/local-dev-lib/api/projects');
13
-
14
13
  const {
15
14
  confirmDefaultAccountPrompt,
16
15
  selectSandboxTargetAccountPrompt,
@@ -63,7 +62,7 @@ const {
63
62
  PERSONAL_ACCESS_KEY_AUTH_METHOD,
64
63
  } = require('@hubspot/local-dev-lib/constants/auth');
65
64
 
66
- const i18nKey = 'cli.lib.localDev';
65
+ const i18nKey = 'lib.localDev';
67
66
 
68
67
  // If the user passed in the --account flag, confirm they want to use that account as
69
68
  // their target account, otherwise exit
@@ -152,14 +151,14 @@ const createSandboxForLocalDev = async (accountId, accountConfig, env) => {
152
151
  } catch (err) {
153
152
  if (isMissingScopeError(err)) {
154
153
  logger.error(
155
- i18n('cli.lib.sandbox.create.failure.scopes.message', {
154
+ i18n('lib.sandbox.create.failure.scopes.message', {
156
155
  accountName: accountConfig.name || accountId,
157
156
  })
158
157
  );
159
158
  const websiteOrigin = getHubSpotWebsiteOrigin(env);
160
159
  const url = `${websiteOrigin}/personal-access-key/${accountId}`;
161
160
  logger.info(
162
- i18n('cli.lib.sandbox.create.failure.scopes.instructions', {
161
+ i18n('lib.sandbox.create.failure.scopes.instructions', {
163
162
  accountName: accountConfig.name || accountId,
164
163
  url,
165
164
  })
@@ -230,20 +229,17 @@ const createDeveloperTestAccountForLocalDev = async (
230
229
  } catch (err) {
231
230
  if (isMissingScopeError(err)) {
232
231
  logger.error(
233
- i18n('cli.lib.developerTestAccount.create.failure.scopes.message', {
232
+ i18n('lib.developerTestAccount.create.failure.scopes.message', {
234
233
  accountName: accountConfig.name || accountId,
235
234
  })
236
235
  );
237
236
  const websiteOrigin = getHubSpotWebsiteOrigin(env);
238
237
  const url = `${websiteOrigin}/personal-access-key/${accountId}`;
239
238
  logger.info(
240
- i18n(
241
- 'cli.lib.developerTestAccount.create.failure.scopes.instructions',
242
- {
243
- accountName: accountConfig.name || accountId,
244
- url,
245
- }
246
- )
239
+ i18n('lib.developerTestAccount.create.failure.scopes.instructions', {
240
+ accountName: accountConfig.name || accountId,
241
+ url,
242
+ })
247
243
  );
248
244
  } else {
249
245
  logErrorInstance(err);
package/lib/process.js CHANGED
@@ -6,7 +6,7 @@ const {
6
6
  } = require('@hubspot/local-dev-lib/logger');
7
7
  const { i18n } = require('./lang');
8
8
 
9
- const i18nKey = 'cli.lib.process';
9
+ const i18nKey = 'lib.process';
10
10
 
11
11
  const handleExit = callback => {
12
12
  const terminationSignals = [
package/lib/projects.js CHANGED
@@ -47,7 +47,7 @@ const {
47
47
  } = require('./errorHandlers/apiErrors');
48
48
  const { HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH } = require('./constants');
49
49
 
50
- const i18nKey = 'cli.lib.projects';
50
+ const i18nKey = 'lib.projects';
51
51
 
52
52
  const SPINNER_STATUS = {
53
53
  SPINNING: 'spinning',
@@ -252,7 +252,7 @@ const ensureProjectExists = async (
252
252
  const project = withPolling
253
253
  ? await pollFetchProject(accountId, projectName)
254
254
  : await fetchProject(accountId, projectName);
255
- return !!project;
255
+ return { projectExists: !!project, project };
256
256
  } catch (err) {
257
257
  if (isSpecifiedError(err, { statusCode: 404 })) {
258
258
  let shouldCreateProject = forceCreate;
@@ -273,14 +273,14 @@ const ensureProjectExists = async (
273
273
 
274
274
  if (shouldCreateProject) {
275
275
  try {
276
- await createProject(accountId, projectName);
276
+ const project = await createProject(accountId, projectName);
277
277
  logger.success(
278
278
  i18n(`${i18nKey}.ensureProjectExists.createSuccess`, {
279
279
  projectName,
280
280
  accountIdentifier,
281
281
  })
282
282
  );
283
- return true;
283
+ return { projectExists: true, project };
284
284
  } catch (err) {
285
285
  return logApiErrorInstance(
286
286
  err,
@@ -296,7 +296,7 @@ const ensureProjectExists = async (
296
296
  })
297
297
  );
298
298
  }
299
- return false;
299
+ return { projectExists: false };
300
300
  }
301
301
  }
302
302
  if (
@@ -859,7 +859,7 @@ const createProjectComponent = async (
859
859
  name,
860
860
  projectComponentsVersion
861
861
  ) => {
862
- const i18nKey = 'cli.commands.project.subcommands.add';
862
+ const i18nKey = 'commands.project.subcommands.add';
863
863
  let componentName = name;
864
864
 
865
865
  const configInfo = await getProjectConfig();
@@ -20,7 +20,7 @@ const {
20
20
  const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/apiErrors');
21
21
  const { PROJECT_ERROR_TYPES } = require('./constants');
22
22
 
23
- const i18nKey = 'cli.commands.project.subcommands.watch';
23
+ const i18nKey = 'commands.project.subcommands.watch';
24
24
 
25
25
  const queue = new PQueue({
26
26
  concurrency: 10,
@@ -9,7 +9,7 @@ const mapAccountChoices = portals =>
9
9
  value: p.name || p.portalId,
10
10
  }));
11
11
 
12
- const i18nKey = 'cli.commands.accounts.subcommands.use';
12
+ const i18nKey = 'commands.accounts.subcommands.use';
13
13
 
14
14
  const selectAccountFromConfig = async (config, prompt) => {
15
15
  const { default: selectedDefault } = await promptUser([
@@ -1,7 +1,7 @@
1
1
  const { promptUser } = require('./promptUtils');
2
2
  const { i18n } = require('../lang');
3
3
 
4
- const i18nKey = 'cli.lib.prompts.buildIdPrompt';
4
+ const i18nKey = 'lib.prompts.buildIdPrompt';
5
5
 
6
6
  const buildIdPrompt = (latestBuildId, deployedBuildId, projectName) => {
7
7
  return promptUser({
@@ -1,7 +1,7 @@
1
1
  const { promptUser } = require('./promptUtils');
2
2
  const { i18n } = require('../lang');
3
3
 
4
- const i18nKey = 'cli.lib.prompts.cleanUploadPrompt';
4
+ const i18nKey = 'lib.prompts.cleanUploadPrompt';
5
5
 
6
6
  const cleanUploadPrompt = async (accountId, filePath) => {
7
7
  const promptAnswer = await promptUser([
@@ -3,7 +3,7 @@ const fs = require('fs');
3
3
  const { promptUser } = require('./promptUtils');
4
4
  const { i18n } = require('../lang');
5
5
  const escapeRegExp = require('@hubspot/local-dev-lib/escapeRegExp');
6
- const i18nKey = 'cli.lib.prompts.uploadPrompt';
6
+ const i18nKey = 'lib.prompts.uploadPrompt';
7
7
  const FIELDS_FILES = ['fields.json', 'fields.js', 'fields.cjs', 'fields.mjs'];
8
8
 
9
9
  const fieldsJsPrompt = async (filePath, projectDir, skipFiles = []) => {
@@ -1,7 +1,7 @@
1
1
  const { promptUser } = require('./promptUtils');
2
2
  const { i18n } = require('../lang');
3
3
 
4
- const i18nKey = 'cli.lib.prompts.createApiSamplePrompt';
4
+ const i18nKey = 'lib.prompts.createApiSamplePrompt';
5
5
 
6
6
  const getSampleTypesPrompt = choices => ({
7
7
  type: 'rawlist',
@@ -3,7 +3,7 @@ const { i18n } = require('../lang');
3
3
 
4
4
  const { STRING_WITH_NO_SPACES_REGEX } = require('../regex');
5
5
 
6
- const i18nKey = 'cli.lib.prompts.createFunctionPrompt';
6
+ const i18nKey = 'lib.prompts.createFunctionPrompt';
7
7
 
8
8
  const FUNCTIONS_FOLDER_PROMPT = {
9
9
  name: 'functionsFolder',
@@ -1,7 +1,7 @@
1
1
  const { promptUser } = require('./promptUtils');
2
2
  const { i18n } = require('../lang');
3
3
 
4
- const i18nKey = 'cli.lib.prompts.createModulePrompt';
4
+ const i18nKey = 'lib.prompts.createModulePrompt';
5
5
 
6
6
  const MODULE_LABEL_PROMPT = {
7
7
  name: 'moduleLabel',
@@ -11,7 +11,7 @@ const {
11
11
  DEFAULT_PROJECT_TEMPLATE_BRANCH,
12
12
  } = require('../constants');
13
13
 
14
- const i18nKey = 'cli.lib.prompts.createProjectPrompt';
14
+ const i18nKey = 'lib.prompts.createProjectPrompt';
15
15
 
16
16
  const PROJECT_PROPERTIES = ['name', 'label', 'path', 'insertPath'];
17
17
 
@@ -1,7 +1,7 @@
1
1
  const { promptUser } = require('./promptUtils');
2
2
  const { i18n } = require('../lang');
3
3
 
4
- const i18nKey = 'cli.lib.prompts.createTemplatePrompt';
4
+ const i18nKey = 'lib.prompts.createTemplatePrompt';
5
5
 
6
6
  const TEMPLATE_TYPE_PROMPT = {
7
7
  type: 'list',
@@ -2,7 +2,7 @@ const { promptUser } = require('./promptUtils');
2
2
  const { i18n } = require('../lang');
3
3
  const { accountNameExistsInConfig } = require('@hubspot/local-dev-lib/config');
4
4
 
5
- const i18nKey = 'cli.lib.prompts.developerTestAccountPrompt';
5
+ const i18nKey = 'lib.prompts.developerTestAccountPrompt';
6
6
 
7
7
  const developerTestAccountNamePrompt = currentPortalCount => {
8
8
  return promptUser([
@@ -8,7 +8,7 @@ const {
8
8
  const { EXIT_CODES } = require('../enums/exitCodes');
9
9
  const { i18n } = require('../lang');
10
10
 
11
- const i18nKey = 'cli.lib.prompts.downloadProjectPrompt';
11
+ const i18nKey = 'lib.prompts.downloadProjectPrompt';
12
12
 
13
13
  const createProjectsList = async () => {
14
14
  const accountId = getAccountId();
@@ -3,7 +3,7 @@ const { STRING_WITH_NO_SPACES_REGEX } = require('../regex');
3
3
  const { promptUser } = require('./promptUtils');
4
4
  const { i18n } = require('../lang');
5
5
 
6
- const i18nKey = 'cli.lib.prompts.enterAccountNamePrompt';
6
+ const i18nKey = 'lib.prompts.enterAccountNamePrompt';
7
7
 
8
8
  const accountNamePrompt = defaultName => ({
9
9
  name: 'name',
@@ -2,7 +2,7 @@ const { promptUser } = require('./promptUtils');
2
2
  const { i18n } = require('../lang');
3
3
  const { FEEDBACK_OPTIONS } = require('../constants');
4
4
 
5
- const i18nKey = 'cli.lib.prompts.feedbackPrompt';
5
+ const i18nKey = 'lib.prompts.feedbackPrompt';
6
6
 
7
7
  const feedbackTypePrompt = bypassPrompt => {
8
8
  return promptUser([
@@ -1,7 +1,7 @@
1
1
  const { promptUser } = require('./promptUtils');
2
2
  const { i18n } = require('../lang');
3
3
 
4
- const i18nKey = 'cli.lib.prompts.folderOverwritePrompt';
4
+ const i18nKey = 'lib.prompts.folderOverwritePrompt';
5
5
 
6
6
  const folderOverwritePrompt = folderName => {
7
7
  return promptUser({
@@ -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 };
@@ -12,7 +12,7 @@ const { i18n } = require('../lang');
12
12
  const { uiInfoSection } = require('../ui');
13
13
  const { EXIT_CODES } = require('../enums/exitCodes');
14
14
 
15
- const i18nKey = 'cli.lib.prompts.personalAccessKeyPrompt';
15
+ const i18nKey = 'lib.prompts.personalAccessKeyPrompt';
16
16
 
17
17
  /**
18
18
  * Displays notification to user that we are about to open the browser,
@@ -3,7 +3,7 @@ const { getCwd } = require('@hubspot/local-dev-lib/path');
3
3
  const { promptUser } = require('./promptUtils');
4
4
  const { i18n } = require('../lang');
5
5
 
6
- const i18nKey = 'cli.lib.prompts.previewPrompt';
6
+ const i18nKey = 'lib.prompts.previewPrompt';
7
7
 
8
8
  const previewPrompt = (promptOptions = {}) => {
9
9
  return promptUser([
@@ -4,7 +4,7 @@ const { i18n } = require('../lang');
4
4
  const { HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH } = require('../constants');
5
5
  const { PROJECT_COMPONENT_TYPES } = require('../constants');
6
6
 
7
- const i18nKey = 'cli.lib.prompts.projectAddPrompt';
7
+ const i18nKey = 'lib.prompts.projectAddPrompt';
8
8
 
9
9
  const createTypeOptions = async projectComponentsVersion => {
10
10
  const config = await fetchFileFromRepository(
@@ -13,7 +13,7 @@ const {
13
13
  fetchDeveloperTestAccounts,
14
14
  } = require('@hubspot/local-dev-lib/developerTestAccounts');
15
15
 
16
- const i18nKey = 'cli.lib.prompts.projectDevTargetAccountPrompt';
16
+ const i18nKey = 'lib.prompts.projectDevTargetAccountPrompt';
17
17
 
18
18
  const mapNestedAccount = accountConfig => ({
19
19
  name: uiAccountDescription(accountConfig.portalId, false),
@@ -3,7 +3,7 @@ const { i18n } = require('../lang');
3
3
  const { ensureProjectExists } = require('../projects');
4
4
  const { uiAccountDescription } = require('../ui');
5
5
 
6
- const i18nKey = 'cli.lib.prompts.projectNamePrompt';
6
+ const i18nKey = 'lib.prompts.projectNamePrompt';
7
7
 
8
8
  const projectNamePrompt = (accountId, options = {}) => {
9
9
  return promptUser({
@@ -14,7 +14,7 @@ const projectNamePrompt = (accountId, options = {}) => {
14
14
  if (typeof val !== 'string' || !val) {
15
15
  return i18n(`${i18nKey}.errors.invalidName`);
16
16
  }
17
- const projectExists = await ensureProjectExists(accountId, val, {
17
+ const { projectExists } = await ensureProjectExists(accountId, val, {
18
18
  allowCreate: false,
19
19
  noLogs: true,
20
20
  });