@hubspot/cli 5.2.1-beta.0 → 5.2.1-beta.2

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.
@@ -1,28 +1,42 @@
1
1
  const { promptUser } = require('./promptUtils');
2
2
  const { i18n } = require('../lang');
3
3
  const { uiAccountDescription, uiCommandReference } = require('../ui');
4
- const { isSandbox } = require('../sandboxes');
4
+ const { isSandbox, isDeveloperTestAccount } = require('../accountTypes');
5
5
  const { getAccountId } = require('@hubspot/local-dev-lib/config');
6
6
  const { getSandboxUsageLimits } = require('@hubspot/local-dev-lib/sandboxes');
7
7
  const {
8
8
  HUBSPOT_ACCOUNT_TYPES,
9
+ HUBSPOT_ACCOUNT_TYPE_STRINGS,
9
10
  } = require('@hubspot/local-dev-lib/constants/config');
10
11
  const { logger } = require('@hubspot/local-dev-lib/logger');
12
+ const {
13
+ fetchDeveloperTestAccounts,
14
+ } = require('@hubspot/local-dev-lib/developerTestAccounts');
11
15
 
12
16
  const i18nKey = 'cli.lib.prompts.projectDevTargetAccountPrompt';
13
17
 
14
- const mapSandboxAccount = accountConfig => ({
18
+ const mapNestedAccount = accountConfig => ({
15
19
  name: uiAccountDescription(accountConfig.portalId, false),
16
20
  value: {
17
21
  targetAccountId: getAccountId(accountConfig.name),
18
- createNewSandbox: false,
22
+ createNestedAccount: false,
23
+ parentAccountId: accountConfig.parentAccountId,
19
24
  },
20
25
  });
21
26
 
22
- const selectTargetAccountPrompt = async (accounts, defaultAccountConfig) => {
23
- let sandboxUsage = {};
24
- const defaultAccountId = getAccountId(defaultAccountConfig.name);
27
+ const getNonConfigDeveloperTestAccountName = account => {
28
+ return `${account.accountName} [${
29
+ HUBSPOT_ACCOUNT_TYPE_STRINGS[HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST]
30
+ }] (${account.id})`;
31
+ };
25
32
 
33
+ const selectSandboxTargetAccountPrompt = async (
34
+ accounts,
35
+ defaultAccountConfig
36
+ ) => {
37
+ const defaultAccountId = getAccountId(defaultAccountConfig.name);
38
+ let choices = [];
39
+ let sandboxUsage = {};
26
40
  try {
27
41
  sandboxUsage = await getSandboxUsageLimits(defaultAccountId);
28
42
  } catch (err) {
@@ -48,20 +62,19 @@ const selectTargetAccountPrompt = async (accounts, defaultAccountConfig) => {
48
62
  });
49
63
  }
50
64
  }
51
-
52
65
  // Order choices by Developer Sandbox -> Standard Sandbox
53
- const choices = [
66
+ choices = [
54
67
  ...sandboxAccounts
55
68
  .filter(a => a.accountType === HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX)
56
- .map(mapSandboxAccount),
69
+ .map(mapNestedAccount),
57
70
  ...sandboxAccounts
58
71
  .filter(a => a.accountType === HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX)
59
- .map(mapSandboxAccount),
72
+ .map(mapNestedAccount),
60
73
  {
61
74
  name: i18n(`${i18nKey}.createNewSandboxOption`),
62
75
  value: {
63
76
  targetAccountId: null,
64
- createNewSandbox: true,
77
+ createNestedAccount: true,
65
78
  },
66
79
  disabled: disabledMessage,
67
80
  },
@@ -69,17 +82,102 @@ const selectTargetAccountPrompt = async (accounts, defaultAccountConfig) => {
69
82
  name: i18n(`${i18nKey}.chooseDefaultAccountOption`),
70
83
  value: {
71
84
  targetAccountId: defaultAccountId,
72
- createNewSandbox: false,
85
+ createNestedAccount: false,
73
86
  },
74
87
  },
75
88
  ];
76
89
 
90
+ return selectTargetAccountPrompt(
91
+ defaultAccountId,
92
+ 'sandbox account',
93
+ choices
94
+ );
95
+ };
96
+
97
+ const selectDeveloperTestTargetAccountPrompt = async (
98
+ accounts,
99
+ defaultAccountConfig
100
+ ) => {
101
+ const defaultAccountId = getAccountId(defaultAccountConfig.name);
102
+ let choices = [];
103
+ let devTestAccountsResponse = undefined;
104
+ try {
105
+ devTestAccountsResponse = await fetchDeveloperTestAccounts(
106
+ defaultAccountId
107
+ );
108
+ } catch (err) {
109
+ logger.debug('Unable to fetch developer test account usage limits: ', err);
110
+ }
111
+
112
+ const devTestAccounts = accounts
113
+ .reverse()
114
+ .filter(
115
+ config =>
116
+ isDeveloperTestAccount(config) &&
117
+ config.parentAccountId === defaultAccountId
118
+ );
119
+ let disabledMessage = false;
120
+ if (
121
+ devTestAccountsResponse &&
122
+ devTestAccountsResponse.results.length >=
123
+ devTestAccountsResponse.maxTestPortals
124
+ ) {
125
+ disabledMessage = i18n(`${i18nKey}.developerTestAccountLimit`, {
126
+ authCommand: uiCommandReference('hs auth'),
127
+ limit: devTestAccountsResponse.maxTestPortals,
128
+ });
129
+ }
130
+
131
+ let devTestAccountsNotInConfig = [];
132
+ if (devTestAccountsResponse && devTestAccountsResponse.results) {
133
+ const inConfigIds = devTestAccounts.map(d => d.portalId);
134
+ devTestAccountsResponse.results.forEach(acct => {
135
+ if (inConfigIds.indexOf(acct.id) < 0) {
136
+ devTestAccountsNotInConfig.push({
137
+ name: getNonConfigDeveloperTestAccountName(acct),
138
+ value: {
139
+ targetAccountId: acct.id,
140
+ createdNestedAccount: false,
141
+ parentAccountId: defaultAccountId,
142
+ notInConfigAccount: acct,
143
+ },
144
+ });
145
+ }
146
+ });
147
+ }
148
+
149
+ choices = [
150
+ ...devTestAccounts.map(mapNestedAccount),
151
+ ...devTestAccountsNotInConfig,
152
+ {
153
+ name: i18n(`${i18nKey}.createNewDeveloperTestAccountOption`),
154
+ value: {
155
+ targetAccountId: null,
156
+ createNestedAccount: true,
157
+ },
158
+ disabled: disabledMessage,
159
+ },
160
+ ];
161
+
162
+ return selectTargetAccountPrompt(
163
+ defaultAccountId,
164
+ HUBSPOT_ACCOUNT_TYPE_STRINGS[HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST],
165
+ choices
166
+ );
167
+ };
168
+
169
+ const selectTargetAccountPrompt = async (
170
+ defaultAccountId,
171
+ accountType,
172
+ choices
173
+ ) => {
77
174
  const { targetAccountInfo } = await promptUser([
78
175
  {
79
176
  name: 'targetAccountInfo',
80
177
  type: 'list',
81
178
  message: i18n(`${i18nKey}.promptMessage`, {
82
179
  accountIdentifier: uiAccountDescription(defaultAccountId),
180
+ accountType,
83
181
  }),
84
182
  choices,
85
183
  },
@@ -102,7 +200,22 @@ const confirmDefaultAccountPrompt = async (accountName, accountType) => {
102
200
  return useDefaultAccount;
103
201
  };
104
202
 
203
+ const confirmUseExistingDeveloperTestAccountPrompt = async account => {
204
+ const { confirmUseExistingDeveloperTestAccount } = await promptUser([
205
+ {
206
+ name: 'confirmUseExistingDeveloperTestAccount',
207
+ type: 'confirm',
208
+ message: i18n(`${i18nKey}.confirmUseExistingDeveloperTestAccount`, {
209
+ accountName: getNonConfigDeveloperTestAccountName(account),
210
+ }),
211
+ },
212
+ ]);
213
+ return confirmUseExistingDeveloperTestAccount;
214
+ };
215
+
105
216
  module.exports = {
106
- selectTargetAccountPrompt,
217
+ selectSandboxTargetAccountPrompt,
218
+ selectDeveloperTestTargetAccountPrompt,
107
219
  confirmDefaultAccountPrompt,
220
+ confirmUseExistingDeveloperTestAccountPrompt,
108
221
  };
@@ -5,7 +5,7 @@ const { uiAccountDescription } = require('../ui');
5
5
  const {
6
6
  HUBSPOT_ACCOUNT_TYPES,
7
7
  } = require('@hubspot/local-dev-lib/constants/config');
8
- const { isSandbox } = require('../sandboxes');
8
+ const { isSandbox } = require('../accountTypes');
9
9
 
10
10
  const i18nKey = 'cli.lib.prompts.sandboxesPrompt';
11
11
 
@@ -2,11 +2,11 @@ const SpinniesManager = require('./ui/SpinniesManager');
2
2
  const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
3
3
  const { logger } = require('@hubspot/local-dev-lib/logger');
4
4
  const { i18n } = require('./lang');
5
+ const { isDevelopmentSandbox } = require('./accountTypes');
5
6
  const {
6
7
  getAvailableSyncTypes,
7
8
  pollSyncTaskStatus,
8
9
  syncTypes,
9
- isDevelopmentSandbox,
10
10
  } = require('./sandboxes');
11
11
  const { initiateSync } = require('@hubspot/local-dev-lib/sandboxes');
12
12
  const {
package/lib/sandboxes.js CHANGED
@@ -10,6 +10,7 @@ const {
10
10
  const { getConfig, getAccountId } = require('@hubspot/local-dev-lib/config');
11
11
  const CliProgressMultibarManager = require('./ui/CliProgressMultibarManager');
12
12
  const { promptUser } = require('./prompts/promptUtils');
13
+ const { isDevelopmentSandbox } = require('./accountTypes');
13
14
  const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
14
15
  const {
15
16
  HUBSPOT_ACCOUNT_TYPES,
@@ -41,19 +42,6 @@ const getSandboxTypeAsString = accountType => {
41
42
  const getSandboxName = config =>
42
43
  `[${getSandboxTypeAsString(config.accountType)} sandbox] `;
43
44
 
44
- const isSandbox = config =>
45
- config.accountType &&
46
- (config.accountType === HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX ||
47
- config.accountType === HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX);
48
-
49
- const isStandardSandbox = config =>
50
- config.accountType &&
51
- config.accountType === HUBSPOT_ACCOUNT_TYPES.STANDARD_SANDBOX;
52
-
53
- const isDevelopmentSandbox = config =>
54
- config.accountType &&
55
- config.accountType === HUBSPOT_ACCOUNT_TYPES.DEVELOPMENT_SANDBOX;
56
-
57
45
  function getHasSandboxesByType(parentAccountConfig, type) {
58
46
  const config = getConfig();
59
47
  const parentPortalId = getAccountId(parentAccountConfig.portalId);
@@ -356,9 +344,6 @@ module.exports = {
356
344
  sandboxTypeMap,
357
345
  sandboxApiTypeMap,
358
346
  syncTypes,
359
- isSandbox,
360
- isStandardSandbox,
361
- isDevelopmentSandbox,
362
347
  getSandboxName,
363
348
  getSandboxTypeAsString,
364
349
  getHasSandboxesByType,
package/lib/ui/index.js CHANGED
@@ -3,8 +3,12 @@ const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
3
3
  const { logger } = require('@hubspot/local-dev-lib/logger');
4
4
  const supportsHyperlinks = require('./supportHyperlinks');
5
5
  const supportsColor = require('./supportsColor');
6
- const { isSandbox, getSandboxName } = require('../sandboxes');
7
- const { isDeveloperTestAccount } = require('../developerTestAccounts');
6
+ const {
7
+ isSandbox,
8
+ isDeveloperTestAccount,
9
+ isAppDeveloperAccount,
10
+ } = require('../accountTypes');
11
+ const { getSandboxName } = require('../sandboxes');
8
12
  const { i18n } = require('../lang');
9
13
 
10
14
  const {
@@ -87,6 +91,10 @@ const uiAccountDescription = (accountId, bold = true) => {
87
91
  accountTypeString = `[${
88
92
  HUBSPOT_ACCOUNT_TYPE_STRINGS[HUBSPOT_ACCOUNT_TYPES.DEVELOPER_TEST]
89
93
  }] `;
94
+ } else if (isAppDeveloperAccount(account)) {
95
+ accountTypeString = `[${
96
+ HUBSPOT_ACCOUNT_TYPE_STRINGS[HUBSPOT_ACCOUNT_TYPES.APP_DEVELOPER]
97
+ }] `;
90
98
  }
91
99
  const message = `${account.name} ${accountTypeString}(${account.portalId})`;
92
100
  return bold ? chalk.bold(message) : message;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cli",
3
- "version": "5.2.1-beta.0",
3
+ "version": "5.2.1-beta.2",
4
4
  "description": "CLI for working with HubSpot",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,8 +8,8 @@
8
8
  "url": "https://github.com/HubSpot/hubspot-cms-tools"
9
9
  },
10
10
  "dependencies": {
11
- "@hubspot/local-dev-lib": "^0.3.13",
12
- "@hubspot/serverless-dev-runtime": "5.2.1-beta.0",
11
+ "@hubspot/local-dev-lib": "1.0.1",
12
+ "@hubspot/serverless-dev-runtime": "5.2.1-beta.2",
13
13
  "@hubspot/theme-preview-dev-server": "0.0.4",
14
14
  "@hubspot/ui-extensions-dev-server": "0.8.12",
15
15
  "archiver": "^5.3.0",
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "ce6013a55ac84a69335200abbcbc6fc8080585b7"
48
+ "gitHead": "eeed6c79043020a0be2552fd0b5271866f8d73f9"
49
49
  }