@hubspot/cli 7.8.10-experimental.0 → 7.8.12-experimental.0

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ import yargs from 'yargs';
2
+ import { addAccountOptions, addConfigOptions, addUseEnvironmentOptions, addGlobalOptions, addJSONOutputOptions, } from '../../../lib/commonOpts.js';
3
+ import installCommand from '../install.js';
4
+ vi.mock('../../../lib/commonOpts');
5
+ describe('commands/app/install', () => {
6
+ const yargsMock = yargs;
7
+ describe('command', () => {
8
+ it('should have the correct command structure', () => {
9
+ expect(installCommand.command).toEqual('install <test-account-id>');
10
+ });
11
+ });
12
+ describe('describe', () => {
13
+ it('should provide a description', () => {
14
+ expect(installCommand.describe).not.toBeDefined();
15
+ });
16
+ });
17
+ describe('builder', () => {
18
+ it('should support the correct options', () => {
19
+ installCommand.builder(yargsMock);
20
+ expect(addGlobalOptions).toHaveBeenCalledTimes(1);
21
+ expect(addGlobalOptions).toHaveBeenCalledWith(yargsMock);
22
+ expect(addAccountOptions).toHaveBeenCalledTimes(1);
23
+ expect(addAccountOptions).toHaveBeenCalledWith(yargsMock);
24
+ expect(addConfigOptions).toHaveBeenCalledTimes(1);
25
+ expect(addConfigOptions).toHaveBeenCalledWith(yargsMock);
26
+ expect(addUseEnvironmentOptions).toHaveBeenCalledTimes(1);
27
+ expect(addUseEnvironmentOptions).toHaveBeenCalledWith(yargsMock);
28
+ expect(addJSONOutputOptions).toHaveBeenCalledTimes(1);
29
+ expect(addJSONOutputOptions).toHaveBeenCalledWith(yargsMock);
30
+ expect(yargsMock.positional).toHaveBeenCalledTimes(1);
31
+ expect(yargsMock.positional).toHaveBeenCalledWith('test-account-id', expect.objectContaining({
32
+ type: 'number',
33
+ required: true,
34
+ describe: expect.any(String),
35
+ }));
36
+ expect(yargsMock.option).toHaveBeenCalledTimes(2);
37
+ expect(yargsMock.option).toHaveBeenCalledWith('app-uid', expect.objectContaining({
38
+ type: 'string',
39
+ describe: expect.any(String),
40
+ }));
41
+ expect(yargsMock.option).toHaveBeenCalledWith('project-name', expect.objectContaining({
42
+ type: 'string',
43
+ describe: expect.any(String),
44
+ }));
45
+ });
46
+ });
47
+ });
@@ -0,0 +1,8 @@
1
+ import { CommonArgs, ConfigArgs, AccountArgs, EnvironmentArgs, YargsCommandModule, JSONOutputArgs } from '../../types/Yargs.js';
2
+ type InstallAppArgs = CommonArgs & ConfigArgs & AccountArgs & EnvironmentArgs & JSONOutputArgs & {
3
+ appUid?: string;
4
+ projectName?: string;
5
+ testAccountId: number;
6
+ };
7
+ declare const installAppCommand: YargsCommandModule<unknown, InstallAppArgs>;
8
+ export default installAppCommand;
@@ -0,0 +1,122 @@
1
+ import { fetchDeveloperTestAccountOauthAppInstallStatus, installOauthAppIntoDeveloperTestAccount, } from '@hubspot/local-dev-lib/api/developerTestAccounts';
2
+ import { trackCommandUsage } from '../../lib/usageTracking.js';
3
+ import { commands } from '../../lang/en.js';
4
+ import { EXIT_CODES } from '../../lib/enums/exitCodes.js';
5
+ import { makeYargsBuilder } from '../../lib/yargsUtils.js';
6
+ import { APP_AUTH_TYPES } from '../../lib/constants.js';
7
+ import { uiLogger } from '../../lib/ui/logger.js';
8
+ import SpinniesManager from '../../lib/ui/SpinniesManager.js';
9
+ import { poll } from '../../lib/polling.js';
10
+ import { getProjectConfig, validateProjectConfig, } from '../../lib/projects/config.js';
11
+ import { handleTranslate } from '../../lib/projects/upload.js';
12
+ import { isAppIRNode } from '../../lib/projects/structure.js';
13
+ import { logError } from '../../lib/errorHandlers/index.js';
14
+ const command = 'install <test-account-id>';
15
+ const describe = undefined; // commands.app.subcommands.install.describe;
16
+ async function handler(args) {
17
+ const { derivedAccountId, appUid, projectName, testAccountId, formatOutputAsJson, } = args;
18
+ trackCommandUsage('app-install', {}, derivedAccountId);
19
+ const jsonOutput = {};
20
+ let targetProjectName = projectName;
21
+ let targetAppUid = appUid;
22
+ const { projectConfig, projectDir } = await getProjectConfig();
23
+ if (!targetProjectName) {
24
+ validateProjectConfig(projectConfig, projectDir);
25
+ targetProjectName = projectConfig?.name;
26
+ }
27
+ if (!targetProjectName) {
28
+ uiLogger.error(commands.app.subcommands.install.errors.mustSpecifyProjectName);
29
+ process.exit(EXIT_CODES.ERROR);
30
+ }
31
+ let isAppOauth = true;
32
+ if (!targetAppUid) {
33
+ const intermediateRepresentation = await handleTranslate(projectDir, projectConfig, derivedAccountId, true, undefined);
34
+ if (intermediateRepresentation) {
35
+ Object.values(intermediateRepresentation.intermediateNodesIndexedByUid).forEach(node => {
36
+ if (isAppIRNode(node)) {
37
+ targetAppUid = node.uid;
38
+ isAppOauth = node.config.auth.type === APP_AUTH_TYPES.OAUTH;
39
+ }
40
+ });
41
+ }
42
+ }
43
+ if (!targetAppUid) {
44
+ uiLogger.error(commands.app.subcommands.install.errors.noAppUidFound);
45
+ process.exit(EXIT_CODES.ERROR);
46
+ }
47
+ if (!isAppOauth) {
48
+ uiLogger.error(commands.app.subcommands.install.errors.appMustBeOauth);
49
+ process.exit(EXIT_CODES.ERROR);
50
+ }
51
+ try {
52
+ const { data } = await installOauthAppIntoDeveloperTestAccount(derivedAccountId, testAccountId, targetProjectName, targetAppUid);
53
+ if (data?.authCodes.length > 0) {
54
+ jsonOutput.authCode = data.authCodes[0].authCode;
55
+ }
56
+ }
57
+ catch (err) {
58
+ logError(err);
59
+ process.exit(EXIT_CODES.ERROR);
60
+ }
61
+ SpinniesManager.init({
62
+ succeedColor: 'white',
63
+ });
64
+ SpinniesManager.add('installApp', {
65
+ text: commands.app.subcommands.install.polling.start,
66
+ });
67
+ let appInstallSucceeded = false;
68
+ try {
69
+ await poll(() => fetchDeveloperTestAccountOauthAppInstallStatus(derivedAccountId, targetProjectName, targetAppUid), {
70
+ successStates: ['SUCCESS'],
71
+ errorStates: [],
72
+ });
73
+ appInstallSucceeded = true;
74
+ }
75
+ catch (err) {
76
+ SpinniesManager.fail('installApp');
77
+ logError(err);
78
+ process.exit(EXIT_CODES.ERROR);
79
+ }
80
+ if (!appInstallSucceeded) {
81
+ SpinniesManager.fail('installApp');
82
+ process.exit(EXIT_CODES.ERROR);
83
+ }
84
+ SpinniesManager.succeed('installApp', {
85
+ text: commands.app.subcommands.install.polling.success,
86
+ });
87
+ if (formatOutputAsJson) {
88
+ uiLogger.json(jsonOutput);
89
+ }
90
+ process.exit(EXIT_CODES.SUCCESS);
91
+ }
92
+ function installAppBuilder(yargs) {
93
+ yargs.positional('test-account-id', {
94
+ describe: commands.app.subcommands.install.positionals.testAccountId,
95
+ required: true,
96
+ type: 'number',
97
+ });
98
+ yargs.option('app-uid', {
99
+ describe: commands.app.subcommands.install.options.appUid,
100
+ type: 'string',
101
+ });
102
+ yargs.option('project-name', {
103
+ describe: commands.app.subcommands.install.options.projectName,
104
+ type: 'string',
105
+ });
106
+ yargs.example('install 1234567890 --app-uid=my-app-uid --project-name=my-project', commands.app.subcommands.install.example);
107
+ return yargs;
108
+ }
109
+ const builder = makeYargsBuilder(installAppBuilder, command, commands.app.subcommands.install.describe, {
110
+ useGlobalOptions: true,
111
+ useAccountOptions: true,
112
+ useConfigOptions: true,
113
+ useEnvironmentOptions: true,
114
+ useJSONOutputOptions: true,
115
+ });
116
+ const installAppCommand = {
117
+ command,
118
+ describe,
119
+ handler,
120
+ builder,
121
+ };
122
+ export default installAppCommand;
package/commands/app.js CHANGED
@@ -1,11 +1,16 @@
1
1
  import migrateCommand from './app/migrate.js';
2
2
  import appSecretCommand from './app/secret.js';
3
+ import installAppCommand from './app/install.js';
3
4
  import { makeYargsBuilder } from '../lib/yargsUtils.js';
4
5
  import { commands } from '../lang/en.js';
5
6
  const command = ['app', 'apps'];
6
7
  const describe = commands.app.describe;
7
8
  function appBuilder(yargs) {
8
- yargs.command(migrateCommand).command(appSecretCommand).demandCommand(1, '');
9
+ yargs
10
+ .command(migrateCommand)
11
+ .command(appSecretCommand)
12
+ .command(installAppCommand)
13
+ .demandCommand(1, '');
9
14
  return yargs;
10
15
  }
11
16
  const builder = makeYargsBuilder(appBuilder, command, describe);
@@ -8,7 +8,7 @@ const command = ['custom-object', 'custom-objects', 'co'];
8
8
  const describe = uiBetaTag(i18n(`commands.customObject.describe`), false);
9
9
  function logBetaMessage() {
10
10
  uiBetaTag(i18n(`commands.customObject.betaMessage`));
11
- logger.log(uiLink(i18n(`commands.customObject.seeMoreLink`), 'https://developers.hubspot.com/docs/api/crm/crm-custom-objects'));
11
+ logger.log(uiLink(i18n(`commands.customObject.seeMoreLink`), 'https://developers.hubspot.com/docs/api-reference/crm-custom-objects-v3/guide#custom-objects-api-guide'));
12
12
  logger.log();
13
13
  }
14
14
  function customObjectBuilder(yargs) {
@@ -1,5 +1,5 @@
1
- import { CommonArgs, JSONOutputArgs, YargsCommandModule } from '../../types/Yargs.js';
2
- type ProjectUploadArgs = CommonArgs & JSONOutputArgs & {
1
+ import { CommonArgs, EnvironmentArgs, JSONOutputArgs, YargsCommandModule } from '../../types/Yargs.js';
2
+ type ProjectUploadArgs = CommonArgs & JSONOutputArgs & EnvironmentArgs & {
3
3
  forceCreate: boolean;
4
4
  message: string;
5
5
  m: string;
@@ -25,7 +25,7 @@ async function handler(args) {
25
25
  validateProjectConfig(projectConfig, projectDir);
26
26
  let targetAccountId;
27
27
  if (useV3Api(projectConfig.platformVersion)) {
28
- targetAccountId = await loadAndValidateProfile(projectConfig, projectDir, profile);
28
+ targetAccountId = await loadAndValidateProfile(projectConfig, projectDir, profile, args.useEnv);
29
29
  }
30
30
  targetAccountId = targetAccountId || derivedAccountId;
31
31
  const accountConfig = getAccountConfig(targetAccountId);
@@ -75,6 +75,9 @@ async function handler(args) {
75
75
  resultJson.personalAccessKey = createResult.personalAccessKey;
76
76
  }
77
77
  catch (err) {
78
+ SpinniesManager.fail('createTestAccount', {
79
+ text: commands.testAccount.create.polling.createFailure,
80
+ });
78
81
  logError(err);
79
82
  SpinniesManager.fail('createTestAccount', {
80
83
  text: commands.testAccount.create.polling.createFailure,
package/lang/en.d.ts CHANGED
@@ -1557,6 +1557,28 @@ ${string}`;
1557
1557
  readonly app: {
1558
1558
  readonly describe: "Commands for managing apps.";
1559
1559
  readonly subcommands: {
1560
+ readonly install: {
1561
+ readonly describe: "Install an OAuth app into a test account.";
1562
+ readonly options: {
1563
+ readonly appUid: "The uid of the app to install";
1564
+ readonly projectName: "The name of the project that contains the app";
1565
+ };
1566
+ readonly positionals: {
1567
+ readonly testAccountId: "The id of the test account to install the app into";
1568
+ };
1569
+ readonly errors: {
1570
+ readonly mustSpecifyProjectName: `You must specify a project name. Use the ${string} flag to specify the project name or run this command from within a project directory.`;
1571
+ readonly noAppUidFound: `No app uid found. Please specify the app uid with the ${string} flag or run this command from within a project that contains an app.`;
1572
+ readonly appMustBeOauth: "This command only supports installing oauth apps. Please specify an app with oauth auth type.";
1573
+ };
1574
+ readonly polling: {
1575
+ readonly start: "Installing app...";
1576
+ readonly success: "App installed successfully";
1577
+ readonly failure: "App installation failed";
1578
+ readonly error: "Error installing app";
1579
+ };
1580
+ readonly example: "Install the app with uid my-app-uid from the project named \"my-project\" into the target account with id 1234567890";
1581
+ };
1560
1582
  readonly secret: {
1561
1583
  readonly describe: "Commands for managing secrets.";
1562
1584
  readonly subcommands: {
package/lang/en.js CHANGED
@@ -1555,6 +1555,28 @@ export const commands = {
1555
1555
  app: {
1556
1556
  describe: 'Commands for managing apps.',
1557
1557
  subcommands: {
1558
+ install: {
1559
+ describe: 'Install an OAuth app into a test account.',
1560
+ options: {
1561
+ appUid: 'The uid of the app to install',
1562
+ projectName: 'The name of the project that contains the app',
1563
+ },
1564
+ positionals: {
1565
+ testAccountId: 'The id of the test account to install the app into',
1566
+ },
1567
+ errors: {
1568
+ mustSpecifyProjectName: `You must specify a project name. Use the ${uiCommandReference('--project-name')} flag to specify the project name or run this command from within a project directory.`,
1569
+ noAppUidFound: `No app uid found. Please specify the app uid with the ${uiCommandReference('--app-uid')} flag or run this command from within a project that contains an app.`,
1570
+ appMustBeOauth: 'This command only supports installing oauth apps. Please specify an app with oauth auth type.',
1571
+ },
1572
+ polling: {
1573
+ start: 'Installing app...',
1574
+ success: 'App installed successfully',
1575
+ failure: 'App installation failed',
1576
+ error: 'Error installing app',
1577
+ },
1578
+ example: 'Install the app with uid my-app-uid from the project named "my-project" into the target account with id 1234567890',
1579
+ },
1558
1580
  secret: {
1559
1581
  describe: 'Commands for managing secrets.',
1560
1582
  subcommands: {
@@ -23,7 +23,7 @@ function createPlatformVersionError(err, subCategory) {
23
23
  }));
24
24
  logger.log(i18n(`lib.errorHandlers.suppressErrors.platformVersionErrors.updateProject`));
25
25
  logger.log(i18n(`lib.errorHandlers.suppressErrors.platformVersionErrors.betaLink`, {
26
- docsLink: uiLink(i18n(`lib.errorHandlers.suppressErrors.platformVersionErrors.docsLink`), 'https://developers.hubspot.com/docs/platform/platform-versioning'),
26
+ docsLink: uiLink(i18n(`lib.errorHandlers.suppressErrors.platformVersionErrors.docsLink`), 'https://developers.hubspot.com/docs/developer-tooling/platform/versioning'),
27
27
  }));
28
28
  uiLine();
29
29
  }
@@ -4,4 +4,4 @@ export declare function logProfileHeader(profileName: string): void;
4
4
  export declare function logProfileFooter(profile: HsProfileFile, includeVariables?: boolean): void;
5
5
  export declare function loadProfile(projectConfig: ProjectConfig | null, projectDir: string | null, profileName: string): HsProfileFile | undefined;
6
6
  export declare function exitIfUsingProfiles(projectConfig: ProjectConfig | null, projectDir: string | null): Promise<void>;
7
- export declare function loadAndValidateProfile(projectConfig: ProjectConfig | null, projectDir: string | null, argsProfile: string | undefined): Promise<number | undefined>;
7
+ export declare function loadAndValidateProfile(projectConfig: ProjectConfig | null, projectDir: string | null, argsProfile: string | undefined, useEnv?: boolean): Promise<number | undefined>;
@@ -38,7 +38,12 @@ export function loadProfile(projectConfig, projectDir, profileName) {
38
38
  uiLogger.error(lib.projectProfiles.loadProfile.errors.missingAccountId(profileFilename));
39
39
  return;
40
40
  }
41
- return profile;
41
+ return {
42
+ ...profile,
43
+ accountId: process.env.HUBSPOT_ACCOUNT_ID
44
+ ? Number(process.env.HUBSPOT_ACCOUNT_ID)
45
+ : profile.accountId,
46
+ };
42
47
  }
43
48
  catch (e) {
44
49
  uiLogger.error(lib.projectProfiles.loadProfile.errors.failedToLoadProfile(profileFilename));
@@ -54,7 +59,7 @@ export async function exitIfUsingProfiles(projectConfig, projectDir) {
54
59
  }
55
60
  }
56
61
  }
57
- export async function loadAndValidateProfile(projectConfig, projectDir, argsProfile) {
62
+ export async function loadAndValidateProfile(projectConfig, projectDir, argsProfile, useEnv = false) {
58
63
  if (argsProfile) {
59
64
  logProfileHeader(argsProfile);
60
65
  const profile = loadProfile(projectConfig, projectDir, argsProfile);
@@ -63,6 +68,9 @@ export async function loadAndValidateProfile(projectConfig, projectDir, argsProf
63
68
  process.exit(EXIT_CODES.ERROR);
64
69
  }
65
70
  logProfileFooter(profile, true);
71
+ if (useEnv) {
72
+ return Number(process.env.HUBSPOT_ACCOUNT_ID);
73
+ }
66
74
  return profile.accountId;
67
75
  }
68
76
  else {
@@ -1,5 +1,5 @@
1
1
  import { ComponentTypes, Component, GenericComponentConfig, PublicAppComponentConfig, PrivateAppComponentConfig, AppCardComponentConfig } from '../../types/Projects.js';
2
- import { IntermediateRepresentationNodeLocalDev } from '@hubspot/project-parsing-lib/src/lib/types.js';
2
+ import { IntermediateRepresentationNode, IntermediateRepresentationNodeLocalDev } from '@hubspot/project-parsing-lib/src/lib/types.js';
3
3
  import { AppIRNode } from '../../types/ProjectComponents.js';
4
4
  export declare const CONFIG_FILES: {
5
5
  [k in ComponentTypes]: string;
@@ -15,4 +15,4 @@ export declare function getProjectComponentTypes(components: Array<Component>):
15
15
  export declare function getComponentUid(component?: Component | null): string | null;
16
16
  export declare function componentIsApp(component?: Component | null): component is Component<PublicAppComponentConfig | PrivateAppComponentConfig>;
17
17
  export declare function componentIsPublicApp(component?: Component | null): component is Component<PublicAppComponentConfig>;
18
- export declare function isAppIRNode(component: IntermediateRepresentationNodeLocalDev): component is AppIRNode;
18
+ export declare function isAppIRNode(component: IntermediateRepresentationNodeLocalDev | IntermediateRepresentationNode): component is AppIRNode;
@@ -1,4 +1,5 @@
1
1
  import { FileResult } from 'tmp';
2
+ import { IntermediateRepresentation } from '@hubspot/project-parsing-lib';
2
3
  import { ProjectConfig } from '../../types/Projects.js';
3
4
  type ProjectUploadCallbackFunction<T> = (accountId: number, projectConfig: ProjectConfig, tempFile: FileResult, buildId: number) => Promise<T>;
4
5
  type ProjectUploadResult<T> = {
@@ -20,5 +21,5 @@ type HandleProjectUploadArg<T> = {
20
21
  export declare function handleProjectUpload<T>({ accountId, projectConfig, projectDir, callbackFunc, profile, uploadMessage, forceCreate, isUploadCommand, sendIR, skipValidation, }: HandleProjectUploadArg<T>): Promise<ProjectUploadResult<T>>;
21
22
  export declare function validateSourceDirectory(srcDir: string, projectConfig: ProjectConfig): void;
22
23
  export declare function validateNoHSMetaMismatch(srcDir: string, projectConfig: ProjectConfig): Promise<void>;
23
- export declare function handleTranslate(projectDir: string, projectConfig: ProjectConfig, accountId: number, skipValidation: boolean, profile: string | undefined): Promise<unknown>;
24
+ export declare function handleTranslate(projectDir: string, projectConfig: ProjectConfig, accountId: number, skipValidation: boolean, profile: string | undefined): Promise<IntermediateRepresentation | undefined>;
24
25
  export {};
@@ -133,4 +133,5 @@ export async function handleTranslate(projectDir, projectConfig, accountId, skip
133
133
  }
134
134
  throw e;
135
135
  }
136
+ return undefined;
136
137
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@hubspot/cli",
3
- "version": "7.8.10-experimental.0",
3
+ "version": "7.8.12-experimental.0",
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
  "type": "module",
8
8
  "dependencies": {
9
9
  "@hubspot/local-dev-lib": "3.19.1",
10
- "@hubspot/project-parsing-lib": "0.0.30-experimental.0",
10
+ "@hubspot/project-parsing-lib": "0.8.6",
11
11
  "@hubspot/serverless-dev-runtime": "7.0.6",
12
12
  "@hubspot/theme-preview-dev-server": "0.0.10",
13
13
  "@hubspot/ui-extensions-dev-server": "0.10.0",
package/types/Yargs.d.ts CHANGED
@@ -15,7 +15,7 @@ export type AccountArgs = {
15
15
  account?: string;
16
16
  };
17
17
  export type EnvironmentArgs = {
18
- 'use-env'?: string;
18
+ 'use-env'?: boolean;
19
19
  };
20
20
  export type OverwriteArgs = Options & {
21
21
  o?: boolean;