@hubspot/cli 7.0.2-experimental.0 → 7.0.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.
Files changed (54) hide show
  1. package/bin/cli.js +7 -2
  2. package/commands/account/info.d.ts +7 -0
  3. package/commands/account/info.js +28 -25
  4. package/commands/account/remove.js +4 -4
  5. package/commands/account/use.js +3 -3
  6. package/commands/auth.js +3 -3
  7. package/commands/function/deploy.js +1 -1
  8. package/commands/init.js +1 -1
  9. package/commands/logs.js +1 -7
  10. package/commands/project/cloneApp.js +1 -1
  11. package/commands/project/create.js +6 -0
  12. package/commands/project/installDeps.js +2 -4
  13. package/commands/project/migrateApp.js +1 -1
  14. package/commands/project/upload.js +5 -10
  15. package/commands/project/watch.js +4 -4
  16. package/commands/sandbox/create.js +2 -8
  17. package/commands/sandbox/delete.js +6 -10
  18. package/lang/en.lyaml +9 -4
  19. package/lib/LocalDevManager.d.ts +58 -1
  20. package/lib/LocalDevManager.js +162 -122
  21. package/lib/buildAccount.d.ts +12 -0
  22. package/lib/buildAccount.js +110 -95
  23. package/lib/commonOpts.d.ts +4 -8
  24. package/lib/commonOpts.js +2 -14
  25. package/lib/constants.d.ts +1 -7
  26. package/lib/constants.js +2 -8
  27. package/lib/developerTestAccounts.d.ts +1 -0
  28. package/lib/developerTestAccounts.js +1 -0
  29. package/lib/localDev.d.ts +17 -1
  30. package/lib/localDev.js +203 -197
  31. package/lib/polling.d.ts +13 -5
  32. package/lib/polling.js +21 -7
  33. package/lib/projects/buildAndDeploy.d.ts +1 -7
  34. package/lib/projects/buildAndDeploy.js +3 -3
  35. package/lib/projects/index.js +9 -4
  36. package/lib/projects/structure.d.ts +3 -0
  37. package/lib/projects/structure.js +21 -0
  38. package/lib/projects/upload.d.ts +4 -3
  39. package/lib/projects/upload.js +7 -31
  40. package/lib/prompts/createProjectPrompt.js +8 -1
  41. package/lib/prompts/installPublicAppPrompt.d.ts +1 -1
  42. package/lib/prompts/personalAccessKeyPrompt.d.ts +1 -1
  43. package/lib/prompts/projectDevTargetAccountPrompt.d.ts +2 -2
  44. package/lib/sandboxes.d.ts +1 -1
  45. package/lib/serverlessLogs.d.ts +4 -1
  46. package/lib/serverlessLogs.js +64 -60
  47. package/lib/ui/serverlessFunctionLogs.d.ts +8 -0
  48. package/lib/ui/serverlessFunctionLogs.js +1 -3
  49. package/lib/validation.d.ts +2 -0
  50. package/lib/validation.js +5 -8
  51. package/package.json +3 -4
  52. package/types/Projects.d.ts +8 -2
  53. package/types/Yargs.d.ts +14 -0
  54. package/types/Yargs.js +2 -0
@@ -197,13 +197,13 @@ function makePollTaskStatusFunc({ statusFn, structureFn, statusText, statusStrin
197
197
  resolve(taskStatus);
198
198
  }
199
199
  }
200
- }, constants_1.POLLING_DELAY);
200
+ }, constants_1.DEFAULT_POLLING_DELAY);
201
201
  });
202
202
  };
203
203
  }
204
204
  function pollBuildAutodeployStatus(accountId, taskName, buildId) {
205
205
  return new Promise((resolve, reject) => {
206
- let maxIntervals = (30 * 1000) / constants_1.POLLING_DELAY; // Num of intervals in ~30s
206
+ let maxIntervals = (30 * 1000) / constants_1.DEFAULT_POLLING_DELAY; // Num of intervals in ~30s
207
207
  const pollInterval = setInterval(async () => {
208
208
  let build;
209
209
  try {
@@ -224,7 +224,7 @@ function pollBuildAutodeployStatus(accountId, taskName, buildId) {
224
224
  else {
225
225
  maxIntervals -= 1;
226
226
  }
227
- }, constants_1.POLLING_DELAY);
227
+ }, constants_1.DEFAULT_POLLING_DELAY);
228
228
  });
229
229
  }
230
230
  exports.pollBuildStatus = makePollTaskStatusFunc({
@@ -20,7 +20,6 @@ const github_1 = require("@hubspot/local-dev-lib/github");
20
20
  const projects_1 = require("@hubspot/local-dev-lib/api/projects");
21
21
  const index_1 = require("@hubspot/local-dev-lib/errors/index");
22
22
  const path_2 = require("@hubspot/local-dev-lib/path");
23
- const github_2 = require("@hubspot/local-dev-lib/github");
24
23
  const constants_1 = require("../constants");
25
24
  const promptUtils_1 = require("../prompts/promptUtils");
26
25
  const exitCodes_1 = require("../enums/exitCodes");
@@ -96,7 +95,10 @@ async function createProjectConfig(projectPath, projectName, template, templateS
96
95
  const projectConfigPath = path_1.default.join(projectPath, constants_1.PROJECT_CONFIG_FILE);
97
96
  logger_1.logger.log(`Creating project config in ${projectPath ? projectPath : 'the current folder'}`);
98
97
  const hasCustomTemplateSource = Boolean(templateSource);
99
- await (0, github_2.downloadGithubRepoContents)(templateSource || constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, template.path, projectPath, hasCustomTemplateSource ? undefined : githubRef);
98
+ await (0, github_1.cloneGithubRepo)(templateSource || constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, projectPath, {
99
+ sourceDir: template.path,
100
+ tag: hasCustomTemplateSource ? undefined : githubRef,
101
+ });
100
102
  const _config = JSON.parse(fs_extra_1.default.readFileSync(projectConfigPath).toString());
101
103
  writeProjectConfig(projectConfigPath, {
102
104
  ..._config,
@@ -169,7 +171,7 @@ async function pollFetchProject(accountId, projectName) {
169
171
  reject(err);
170
172
  }
171
173
  }
172
- }, constants_1.POLLING_DELAY);
174
+ }, constants_1.DEFAULT_POLLING_DELAY);
173
175
  });
174
176
  }
175
177
  async function ensureProjectExists(accountId, projectName, { forceCreate = false, allowCreate = true, noLogs = false, withPolling = false, uploadCommand = false, } = {}) {
@@ -248,7 +250,10 @@ async function createProjectComponent(component, name, projectComponentsVersion)
248
250
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
249
251
  }
250
252
  const componentPath = path_1.default.join(configInfo.projectDir, configInfo.projectConfig.srcDir, component.insertPath, componentName);
251
- await (0, github_2.downloadGithubRepoContents)(constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, component.path, componentPath, projectComponentsVersion);
253
+ await (0, github_1.cloneGithubRepo)(constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, componentPath, {
254
+ sourceDir: component.path,
255
+ tag: projectComponentsVersion,
256
+ });
252
257
  }
253
258
  async function getProjectComponentsByVersion(projectComponentsVersion) {
254
259
  const config = await (0, github_1.fetchFileFromRepository)(constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, 'config.json', projectComponentsVersion);
@@ -7,3 +7,6 @@ export declare function findProjectComponents(projectSourceDir: string): Promise
7
7
  export declare function getProjectComponentTypes(components: Array<Component>): {
8
8
  [key in ComponentTypes]?: boolean;
9
9
  };
10
+ export declare function getComponentUid(component?: Component | null): string | null;
11
+ export declare function componentIsApp(component?: Component | null): component is Component<PublicAppComponentConfig | PrivateAppComponentConfig>;
12
+ export declare function componentIsPublicApp(component?: Component | null): component is Component<PublicAppComponentConfig>;
@@ -37,6 +37,9 @@ exports.CONFIG_FILES = void 0;
37
37
  exports.getAppCardConfigs = getAppCardConfigs;
38
38
  exports.findProjectComponents = findProjectComponents;
39
39
  exports.getProjectComponentTypes = getProjectComponentTypes;
40
+ exports.getComponentUid = getComponentUid;
41
+ exports.componentIsApp = componentIsApp;
42
+ exports.componentIsPublicApp = componentIsPublicApp;
40
43
  const fs = __importStar(require("fs"));
41
44
  const path = __importStar(require("path"));
42
45
  const fs_1 = require("@hubspot/local-dev-lib/fs");
@@ -145,3 +148,21 @@ function getProjectComponentTypes(components) {
145
148
  components.forEach(({ type }) => (projectContents[type] = true));
146
149
  return projectContents;
147
150
  }
151
+ function getComponentUid(component) {
152
+ if (!component) {
153
+ return null;
154
+ }
155
+ else if ('uid' in component.config) {
156
+ return component.config.uid;
157
+ }
158
+ else {
159
+ return component.config.data.uid;
160
+ }
161
+ }
162
+ function componentIsApp(component) {
163
+ return (component?.type === Projects_1.ComponentTypes.PublicApp ||
164
+ component?.type === Projects_1.ComponentTypes.PrivateApp);
165
+ }
166
+ function componentIsPublicApp(component) {
167
+ return component?.type === Projects_1.ComponentTypes.PublicApp;
168
+ }
@@ -1,8 +1,9 @@
1
1
  import { FileResult } from 'tmp';
2
2
  import { ProjectConfig } from '../../types/Projects';
3
- type ProjectUploadCallbackFunction<T> = (accountId: number, projectConfig: ProjectConfig, tempFile: FileResult, buildId?: number) => Promise<T | undefined>;
4
- type ProjectUploadDefaultResult = {
3
+ type ProjectUploadCallbackFunction<T> = (accountId: number, projectConfig: ProjectConfig, tempFile: FileResult, buildId?: number) => Promise<T>;
4
+ type ProjectUploadResult<T> = {
5
+ result?: T;
5
6
  uploadError?: unknown;
6
7
  };
7
- export declare function handleProjectUpload<T = ProjectUploadDefaultResult>(accountId: number, projectConfig: ProjectConfig, projectDir: string, callbackFunc: ProjectUploadCallbackFunction<T>, uploadMessage: string, sendIR?: boolean): Promise<unknown>;
8
+ export declare function handleProjectUpload<T>(accountId: number, projectConfig: ProjectConfig, projectDir: string, callbackFunc: ProjectUploadCallbackFunction<T>, uploadMessage: string): Promise<ProjectUploadResult<T>>;
8
9
  export {};
@@ -15,11 +15,8 @@ const SpinniesManager_1 = __importDefault(require("../ui/SpinniesManager"));
15
15
  const ui_1 = require("../ui");
16
16
  const lang_1 = require("../lang");
17
17
  const exitCodes_1 = require("../enums/exitCodes");
18
- const project_parsing_lib_1 = require("@hubspot/project-parsing-lib");
19
- const errorHandlers_1 = require("../errorHandlers");
20
- const node_util_1 = __importDefault(require("node:util"));
21
18
  const i18nKey = 'lib.projectUpload';
22
- async function uploadProjectFiles(accountId, projectName, filePath, uploadMessage, platformVersion, intermediateRepresentation) {
19
+ async function uploadProjectFiles(accountId, projectName, filePath, uploadMessage, platformVersion) {
23
20
  SpinniesManager_1.default.init({});
24
21
  const accountIdentifier = (0, ui_1.uiAccountDescription)(accountId);
25
22
  SpinniesManager_1.default.add('upload', {
@@ -32,7 +29,7 @@ async function uploadProjectFiles(accountId, projectName, filePath, uploadMessag
32
29
  let buildId;
33
30
  let error;
34
31
  try {
35
- const { data: upload } = await (0, projects_1.uploadProject)(accountId, projectName, filePath, uploadMessage, platformVersion, intermediateRepresentation);
32
+ const { data: upload } = await (0, projects_1.uploadProject)(accountId, projectName, filePath, uploadMessage, platformVersion);
36
33
  buildId = upload.buildId;
37
34
  SpinniesManager_1.default.succeed('upload', {
38
35
  text: (0, lang_1.i18n)(`${i18nKey}.uploadProjectFiles.succeed`, {
@@ -58,7 +55,7 @@ async function uploadProjectFiles(accountId, projectName, filePath, uploadMessag
58
55
  }
59
56
  return { buildId, error };
60
57
  }
61
- async function handleProjectUpload(accountId, projectConfig, projectDir, callbackFunc, uploadMessage, sendIR = false) {
58
+ async function handleProjectUpload(accountId, projectConfig, projectDir, callbackFunc, uploadMessage) {
62
59
  const srcDir = path_1.default.resolve(projectDir, projectConfig.srcDir);
63
60
  const filenames = fs_extra_1.default.readdirSync(srcDir);
64
61
  if (!filenames || filenames.length === 0) {
@@ -74,38 +71,17 @@ async function handleProjectUpload(accountId, projectConfig, projectDir, callbac
74
71
  const output = fs_extra_1.default.createWriteStream(tempFile.name);
75
72
  const archive = (0, archiver_1.default)('zip');
76
73
  const result = new Promise(resolve => output.on('close', async function () {
77
- let uploadResult;
78
74
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.handleProjectUpload.compressed`, {
79
75
  byteCount: archive.pointer(),
80
76
  }));
81
- let intermediateRepresentation;
82
- if (sendIR) {
83
- try {
84
- intermediateRepresentation = await (0, project_parsing_lib_1.translate)({
85
- projectSourceDir: path_1.default.join(projectDir, projectConfig.srcDir),
86
- platformVersion: projectConfig.platformVersion,
87
- accountId,
88
- });
89
- logger_1.logger.debug(node_util_1.default.inspect(intermediateRepresentation, false, null, true));
90
- }
91
- catch (e) {
92
- if ((0, project_parsing_lib_1.isTranslationError)(e)) {
93
- logger_1.logger.error(e.toString());
94
- }
95
- else {
96
- (0, errorHandlers_1.logError)(e);
97
- }
98
- return process.exit(exitCodes_1.EXIT_CODES.ERROR);
99
- }
100
- }
101
- const { buildId, error } = await uploadProjectFiles(accountId, projectConfig.name, tempFile.name, uploadMessage, projectConfig.platformVersion, intermediateRepresentation);
77
+ const { buildId, error } = await uploadProjectFiles(accountId, projectConfig.name, tempFile.name, uploadMessage, projectConfig.platformVersion);
102
78
  if (error) {
103
- uploadResult = { uploadError: error };
79
+ resolve({ uploadError: error });
104
80
  }
105
81
  else if (callbackFunc) {
106
- uploadResult = await callbackFunc(accountId, projectConfig, tempFile, buildId);
82
+ const uploadResult = await callbackFunc(accountId, projectConfig, tempFile, buildId);
83
+ resolve({ result: uploadResult });
107
84
  }
108
- resolve(uploadResult || {});
109
85
  }));
110
86
  archive.pipe(output);
111
87
  let loggedIgnoredNodeModule = false;
@@ -23,7 +23,14 @@ async function createTemplateOptions(templateSource, githubRef) {
23
23
  const branch = hasCustomTemplateSource
24
24
  ? constants_1.DEFAULT_PROJECT_TEMPLATE_BRANCH
25
25
  : githubRef;
26
- const config = await (0, github_1.fetchFileFromRepository)(templateSource || constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, 'config.json', branch);
26
+ let config;
27
+ try {
28
+ config = await (0, github_1.fetchFileFromRepository)(templateSource || constants_1.HUBSPOT_PROJECT_COMPONENTS_GITHUB_PATH, 'config.json', branch);
29
+ }
30
+ catch (e) {
31
+ logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.missingConfigFileTemplateSource`));
32
+ process.exit(exitCodes_1.EXIT_CODES.ERROR);
33
+ }
27
34
  if (!config || !config[constants_1.PROJECT_COMPONENT_TYPES.PROJECTS]) {
28
35
  logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.noProjectsInConfig`));
29
36
  process.exit(exitCodes_1.EXIT_CODES.ERROR);
@@ -1 +1 @@
1
- export declare function installPublicAppPrompt(env: string, targetAccountId: number, clientId: number, scopes: string[], redirectUrls: string[], isReinstall?: boolean): Promise<void>;
1
+ export declare function installPublicAppPrompt(env: string, targetAccountId: number, clientId: string, scopes: string[], redirectUrls: string[], isReinstall?: boolean): Promise<void>;
@@ -21,7 +21,7 @@ type ScopesPromptResponse = {
21
21
  */
22
22
  export declare function personalAccessKeyPrompt({ env, account, }: {
23
23
  env: string;
24
- account?: string;
24
+ account?: number;
25
25
  }): Promise<PersonalAccessKeyPromptResponse>;
26
26
  export declare const OAUTH_FLOW: (PromptConfig<{
27
27
  name: string;
@@ -1,6 +1,6 @@
1
- import { CLIAccount, AccountType } from '@hubspot/local-dev-lib/types/Accounts';
1
+ import { CLIAccount } from '@hubspot/local-dev-lib/types/Accounts';
2
2
  import { DeveloperTestAccount } from '@hubspot/local-dev-lib/types/developerTestAccounts';
3
3
  export declare function selectSandboxTargetAccountPrompt(accounts: CLIAccount[], defaultAccountConfig: CLIAccount): Promise<DeveloperTestAccount | CLIAccount>;
4
4
  export declare function selectDeveloperTestTargetAccountPrompt(accounts: CLIAccount[], defaultAccountConfig: CLIAccount): Promise<DeveloperTestAccount | CLIAccount>;
5
- export declare function confirmDefaultAccountPrompt(accountName: string, accountType: AccountType): Promise<boolean>;
5
+ export declare function confirmDefaultAccountPrompt(accountName: string, accountType: string): Promise<boolean>;
6
6
  export declare function confirmUseExistingDeveloperTestAccountPrompt(account: DeveloperTestAccount): Promise<boolean>;
@@ -17,4 +17,4 @@ export declare const SANDBOX_API_TYPE_MAP: {
17
17
  export declare function getSandboxTypeAsString(accountType?: AccountType): string;
18
18
  export declare function getAvailableSyncTypes(parentAccountConfig: CLIAccount, config: CLIAccount): Promise<Array<SandboxSyncTask>>;
19
19
  export declare function validateSandboxUsageLimits(accountConfig: CLIAccount, sandboxType: AccountType, env: Environment): Promise<void>;
20
- export declare function handleSandboxCreateError(err: unknown, env: Environment, name: string, accountId: number): void;
20
+ export declare function handleSandboxCreateError(err: unknown, env: Environment, name: string, accountId: number): never;
@@ -1 +1,4 @@
1
- export {};
1
+ import { HubSpotPromise } from '@hubspot/local-dev-lib/types/Http';
2
+ import { FunctionLog, GetFunctionLogsResponse } from '@hubspot/local-dev-lib/types/Functions';
3
+ export declare function tailLogs(accountId: number, name: string, fetchLatest: () => HubSpotPromise<FunctionLog>, tailCall: (after?: string) => HubSpotPromise<GetFunctionLogsResponse>, compact?: boolean): Promise<void>;
4
+ export declare function outputBuildLog(buildLogUrl: string): Promise<string>;
@@ -1,89 +1,97 @@
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 https = require('https');
5
- const SpinniesManager = require('./ui/SpinniesManager');
6
- const { handleExit, handleKeypress } = require('./process');
7
- const chalk = require('chalk');
8
- const { logger } = require('@hubspot/local-dev-lib/logger');
9
- const { outputLogs } = require('./ui/serverlessFunctionLogs');
10
- const { logError, ApiErrorContext } = require('./errorHandlers/index');
11
- const { EXIT_CODES } = require('./enums/exitCodes');
12
- const { isHubSpotHttpError, isMissingScopeError, } = require('@hubspot/local-dev-lib/errors/index');
13
- const { SCOPE_GROUPS, PERSONAL_ACCESS_KEY_AUTH_METHOD, } = require('@hubspot/local-dev-lib/constants/auth');
14
- const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
15
- const { fetchScopeData } = require('@hubspot/local-dev-lib/api/localDevAuth');
16
- const { i18n } = require('./lang');
6
+ exports.tailLogs = tailLogs;
7
+ exports.outputBuildLog = outputBuildLog;
8
+ const https_1 = __importDefault(require("https"));
9
+ const chalk_1 = __importDefault(require("chalk"));
10
+ const logger_1 = require("@hubspot/local-dev-lib/logger");
11
+ const index_1 = require("@hubspot/local-dev-lib/errors/index");
12
+ const auth_1 = require("@hubspot/local-dev-lib/constants/auth");
13
+ const config_1 = require("@hubspot/local-dev-lib/config");
14
+ const localDevAuth_1 = require("@hubspot/local-dev-lib/api/localDevAuth");
15
+ const serverlessFunctionLogs_1 = require("./ui/serverlessFunctionLogs");
16
+ const index_2 = require("./errorHandlers/index");
17
+ const SpinniesManager_1 = __importDefault(require("./ui/SpinniesManager"));
18
+ const process_1 = require("./process");
19
+ const exitCodes_1 = require("./enums/exitCodes");
20
+ const lang_1 = require("./lang");
17
21
  const TAIL_DELAY = 5000;
18
- const base64EncodeString = valueToEncode => {
22
+ function base64EncodeString(valueToEncode) {
19
23
  if (typeof valueToEncode !== 'string') {
20
24
  return valueToEncode;
21
25
  }
22
26
  const stringBuffer = Buffer.from(valueToEncode);
23
27
  return encodeURIComponent(stringBuffer.toString('base64'));
24
- };
25
- const handleUserInput = () => {
28
+ }
29
+ function handleUserInput() {
26
30
  const onTerminate = async () => {
27
- SpinniesManager.remove('tailLogs');
28
- SpinniesManager.remove('stopMessage');
29
- process.exit(EXIT_CODES.SUCCESS);
31
+ SpinniesManager_1.default.remove('tailLogs');
32
+ SpinniesManager_1.default.remove('stopMessage');
33
+ process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
30
34
  };
31
- handleExit(onTerminate);
32
- handleKeypress(key => {
35
+ (0, process_1.handleExit)(onTerminate);
36
+ (0, process_1.handleKeypress)(key => {
33
37
  if ((key.ctrl && key.name == 'c') || key.name === 'q') {
34
38
  onTerminate();
35
39
  }
36
40
  });
37
- };
41
+ }
38
42
  async function verifyAccessKeyAndUserAccess(accountId, scopeGroup) {
39
- const accountConfig = getAccountConfig(accountId);
43
+ const accountConfig = (0, config_1.getAccountConfig)(accountId);
44
+ if (!accountConfig) {
45
+ return;
46
+ }
40
47
  // TODO[JOE]: Update this i18n key
41
48
  const i18nKey = 'lib.serverless';
42
49
  const { authType } = accountConfig;
43
- if (authType !== PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
50
+ if (authType !== auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
44
51
  return;
45
52
  }
46
53
  let scopesData;
47
54
  try {
48
- scopesData = await fetchScopeData(accountId, scopeGroup);
55
+ const resp = await (0, localDevAuth_1.fetchScopeData)(accountId, scopeGroup);
56
+ scopesData = resp.data;
49
57
  }
50
58
  catch (e) {
51
- logger.debug(i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.fetchScopeDataError`, {
59
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.verifyAccessKeyAndUserAccess.fetchScopeDataError`, {
52
60
  scopeGroup,
53
- error: e,
54
61
  }));
62
+ logger_1.logger.debug(e);
55
63
  return;
56
64
  }
57
65
  const { portalScopesInGroup, userScopesInGroup } = scopesData;
58
66
  if (!portalScopesInGroup.length) {
59
- logger.error(i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.portalMissingScope`));
67
+ logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.verifyAccessKeyAndUserAccess.portalMissingScope`));
60
68
  return;
61
69
  }
62
70
  if (!portalScopesInGroup.every(s => userScopesInGroup.includes(s))) {
63
- logger.error(i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.userMissingScope`));
71
+ logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.verifyAccessKeyAndUserAccess.userMissingScope`));
64
72
  }
65
73
  else {
66
- logger.error(i18n(`${i18nKey}.verifyAccessKeyAndUserAccess.genericMissingScope`));
74
+ logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.verifyAccessKeyAndUserAccess.genericMissingScope`));
67
75
  }
68
76
  }
69
- const tailLogs = async ({ accountId, compact, fetchLatest, tailCall, name, }) => {
70
- let initialAfter;
77
+ async function tailLogs(accountId, name, fetchLatest, tailCall, compact = false) {
78
+ let initialAfter = '';
71
79
  try {
72
80
  const { data: latestLog } = await fetchLatest();
73
81
  initialAfter = latestLog && base64EncodeString(latestLog.id);
74
82
  }
75
83
  catch (e) {
76
84
  // A 404 means no latest log exists(never executed)
77
- if (isHubSpotHttpError(e) && e.status !== 404) {
78
- if (isMissingScopeError(e)) {
79
- await verifyAccessKeyAndUserAccess(accountId, SCOPE_GROUPS.CMS_FUNCTIONS);
85
+ if ((0, index_1.isHubSpotHttpError)(e) && e.status !== 404) {
86
+ if ((0, index_1.isMissingScopeError)(e)) {
87
+ await verifyAccessKeyAndUserAccess(accountId, auth_1.SCOPE_GROUPS.CMS_FUNCTIONS);
80
88
  }
81
89
  else {
82
- await logError(e, new ApiErrorContext({ accountId }));
90
+ await (0, index_2.logError)(e, new index_2.ApiErrorContext({ accountId }));
83
91
  }
84
92
  }
85
93
  }
86
- const tail = async (after) => {
94
+ async function tail(after) {
87
95
  let latestLog;
88
96
  let nextAfter;
89
97
  try {
@@ -92,41 +100,41 @@ const tailLogs = async ({ accountId, compact, fetchLatest, tailCall, name, }) =>
92
100
  nextAfter = latestLog.paging.next.after;
93
101
  }
94
102
  catch (e) {
95
- if (isHubSpotHttpError(e) && e.status !== 404) {
96
- logError(e, new ApiErrorContext({
103
+ if ((0, index_1.isHubSpotHttpError)(e) && e.status !== 404) {
104
+ (0, index_2.logError)(e, new index_2.ApiErrorContext({
97
105
  accountId,
98
106
  }));
99
107
  }
100
- process.exit(EXIT_CODES.SUCCESS);
108
+ process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
101
109
  }
102
110
  if (latestLog && latestLog.results.length) {
103
- outputLogs(latestLog, {
111
+ (0, serverlessFunctionLogs_1.outputLogs)(latestLog, {
104
112
  compact,
105
113
  });
106
114
  }
107
115
  setTimeout(async () => {
108
116
  await tail(nextAfter);
109
117
  }, TAIL_DELAY);
110
- };
111
- SpinniesManager.init();
112
- SpinniesManager.add('tailLogs', {
118
+ }
119
+ SpinniesManager_1.default.init();
120
+ SpinniesManager_1.default.add('tailLogs', {
113
121
  text: `Following logs for ${name}`,
114
122
  });
115
- SpinniesManager.add('stopMessage', {
116
- text: `> Press ${chalk.bold('q')} to stop following`,
123
+ SpinniesManager_1.default.add('stopMessage', {
124
+ text: `> Press ${chalk_1.default.bold('q')} to stop following`,
117
125
  status: 'non-spinnable',
118
126
  });
119
127
  handleUserInput();
120
128
  await tail(initialAfter);
121
- };
122
- const outputBuildLog = async (buildLogUrl) => {
129
+ }
130
+ async function outputBuildLog(buildLogUrl) {
123
131
  if (!buildLogUrl) {
124
- logger.debug('Unable to display build output. No build log URL was provided.');
125
- return;
132
+ logger_1.logger.debug('Unable to display build output. No build log URL was provided.');
133
+ return '';
126
134
  }
127
135
  return new Promise(resolve => {
128
136
  try {
129
- https
137
+ https_1.default
130
138
  .get(buildLogUrl, response => {
131
139
  if (response.statusCode === 404) {
132
140
  resolve('');
@@ -136,21 +144,17 @@ const outputBuildLog = async (buildLogUrl) => {
136
144
  data += chunk;
137
145
  });
138
146
  response.on('end', () => {
139
- logger.log(data);
147
+ logger_1.logger.log(data);
140
148
  resolve(data);
141
149
  });
142
150
  })
143
151
  .on('error', () => {
144
- logger.error('The build log could not be retrieved.');
152
+ logger_1.logger.error('The build log could not be retrieved.');
145
153
  });
146
154
  }
147
155
  catch (e) {
148
- logger.error('The build log could not be retrieved.');
156
+ logger_1.logger.error('The build log could not be retrieved.');
149
157
  resolve('');
150
158
  }
151
159
  });
152
- };
153
- module.exports = {
154
- outputBuildLog,
155
- tailLogs,
156
- };
160
+ }
@@ -1 +1,9 @@
1
+ import { FunctionLog, GetFunctionLogsResponse } from '@hubspot/local-dev-lib/types/Functions';
2
+ type Options = {
3
+ compact?: boolean;
4
+ insertions?: {
5
+ header?: string;
6
+ };
7
+ };
8
+ export declare function outputLogs(logsResp: GetFunctionLogsResponse | FunctionLog, options: Options): void;
1
9
  export {};
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.outputLogs = outputLogs;
6
7
  const moment_1 = __importDefault(require("moment"));
7
8
  const chalk_1 = __importDefault(require("chalk"));
8
9
  const logger_1 = require("@hubspot/local-dev-lib/logger");
@@ -90,6 +91,3 @@ function processLogs(logsResp, options) {
90
91
  function outputLogs(logsResp, options) {
91
92
  logger_1.logger.log(processLogs(logsResp, options));
92
93
  }
93
- module.exports = {
94
- outputLogs,
95
- };
@@ -3,6 +3,8 @@ import { CmsPublishMode } from '@hubspot/local-dev-lib/types/Files';
3
3
  export declare function validateAccount(options: Arguments<{
4
4
  account?: string;
5
5
  accountId?: string;
6
+ derivedAccountId?: number;
7
+ providedAccountId?: string;
6
8
  }>): Promise<boolean>;
7
9
  export declare function validateCmsPublishMode(options: Arguments<{
8
10
  cmsPublishMode?: CmsPublishMode;
package/lib/validation.js CHANGED
@@ -50,21 +50,18 @@ const path_1 = require("@hubspot/local-dev-lib/path");
50
50
  const commonOpts_1 = require("./commonOpts");
51
51
  const index_1 = require("./errorHandlers/index");
52
52
  async function validateAccount(options) {
53
- const accountId = (0, commonOpts_1.getAccountId)(options);
54
- const { accountId: accountIdOption, account: accountOption } = options;
53
+ const { derivedAccountId, providedAccountId } = options;
54
+ const accountId = (0, config_1.getAccountId)(derivedAccountId);
55
55
  if (!accountId) {
56
- if (accountOption) {
57
- logger_1.logger.error(`The account "${accountOption}" could not be found in the config`);
58
- }
59
- else if (accountIdOption) {
60
- logger_1.logger.error(`The account "${accountIdOption}" could not be found in the config`);
56
+ if (providedAccountId) {
57
+ logger_1.logger.error(`The account "${providedAccountId}" could not be found in the config`);
61
58
  }
62
59
  else {
63
60
  logger_1.logger.error('An account needs to be supplied either via "--account" or through setting a "defaultPortal"');
64
61
  }
65
62
  return false;
66
63
  }
67
- if (accountOption && (0, config_1.loadConfigFromEnvironment)()) {
64
+ if (providedAccountId && (0, config_1.loadConfigFromEnvironment)()) {
68
65
  throw new Error('Cannot specify an account when environment variables are supplied. Please unset the environment variables or do not use the "--account" flag.');
69
66
  }
70
67
  const accountConfig = (0, config_1.getAccountConfig)(accountId);
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "@hubspot/cli",
3
- "version": "7.0.2-experimental.0",
3
+ "version": "7.0.2",
4
4
  "description": "The official CLI for developing on HubSpot",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "https://github.com/HubSpot/hubspot-cli",
7
7
  "dependencies": {
8
- "@hubspot/local-dev-lib": "3.1.1",
9
- "@hubspot/project-parsing-lib": "^0.0.2-experimental.0",
8
+ "@hubspot/local-dev-lib": "3.1.3",
10
9
  "@hubspot/serverless-dev-runtime": "7.0.1",
11
10
  "@hubspot/theme-preview-dev-server": "0.0.10",
12
- "@hubspot/ui-extensions-dev-server": "0.8.40",
11
+ "@hubspot/ui-extensions-dev-server": "0.8.42",
13
12
  "archiver": "^7.0.1",
14
13
  "chalk": "^4.1.2",
15
14
  "chokidar": "^3.0.1",
@@ -41,6 +41,12 @@ export type ProjectTemplateRepoConfig = {
41
41
  projects?: ProjectTemplate[];
42
42
  components?: ComponentTemplate[];
43
43
  };
44
+ export type ProjectPollResult = {
45
+ succeeded: boolean;
46
+ buildId: number;
47
+ buildResult: Build;
48
+ deployResult: Deploy | null;
49
+ };
44
50
  export type PrivateAppComponentConfig = {
45
51
  name: string;
46
52
  description: string;
@@ -103,9 +109,9 @@ export declare enum ComponentTypes {
103
109
  PublicApp = "public-app",
104
110
  HublTheme = "hubl-theme"
105
111
  }
106
- export type Component = {
112
+ export type Component<T = GenericComponentConfig> = {
107
113
  type: ComponentTypes;
108
- config: GenericComponentConfig;
114
+ config: T;
109
115
  runnable: boolean;
110
116
  path: string;
111
117
  };
@@ -0,0 +1,14 @@
1
+ import { Options } from 'yargs';
2
+ export type CommonArgs = {
3
+ derivedAccountId: number;
4
+ providedAccountId?: number;
5
+ d: boolean;
6
+ debug: boolean;
7
+ };
8
+ export type ConfigArgs = {
9
+ c?: string;
10
+ config?: string;
11
+ };
12
+ export type StringArgType = Options & {
13
+ type: 'string';
14
+ };
package/types/Yargs.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });