@dishantlangayan/solace-cloud-cli 0.2.1 → 0.3.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.
Files changed (37) hide show
  1. package/README.md +162 -139
  2. package/dist/commands/account/list.d.ts +10 -0
  3. package/dist/commands/account/list.js +36 -0
  4. package/dist/commands/account/login.d.ts +43 -0
  5. package/dist/commands/account/login.js +232 -0
  6. package/dist/commands/account/logout.d.ts +15 -0
  7. package/dist/commands/account/logout.js +113 -0
  8. package/dist/commands/missionctrl/broker/create.d.ts +1 -0
  9. package/dist/commands/missionctrl/broker/create.js +8 -2
  10. package/dist/commands/missionctrl/broker/delete.d.ts +1 -0
  11. package/dist/commands/missionctrl/broker/delete.js +8 -2
  12. package/dist/commands/missionctrl/broker/display.d.ts +1 -0
  13. package/dist/commands/missionctrl/broker/display.js +11 -3
  14. package/dist/commands/missionctrl/broker/list.d.ts +1 -0
  15. package/dist/commands/missionctrl/broker/list.js +8 -4
  16. package/dist/commands/missionctrl/broker/opstatus.d.ts +1 -0
  17. package/dist/commands/missionctrl/broker/opstatus.js +8 -2
  18. package/dist/commands/missionctrl/broker/state.d.ts +1 -0
  19. package/dist/commands/missionctrl/broker/state.js +8 -2
  20. package/dist/commands/missionctrl/broker/update.d.ts +1 -0
  21. package/dist/commands/missionctrl/broker/update.js +8 -3
  22. package/dist/commands/platform/env/create.d.ts +1 -0
  23. package/dist/commands/platform/env/create.js +9 -3
  24. package/dist/commands/platform/env/delete.d.ts +1 -0
  25. package/dist/commands/platform/env/delete.js +8 -2
  26. package/dist/commands/platform/env/display.d.ts +1 -0
  27. package/dist/commands/platform/env/display.js +8 -2
  28. package/dist/commands/platform/env/list.d.ts +1 -0
  29. package/dist/commands/platform/env/list.js +8 -2
  30. package/dist/commands/platform/env/update.d.ts +1 -0
  31. package/dist/commands/platform/env/update.js +9 -3
  32. package/dist/lib/org-utils.d.ts +24 -0
  33. package/dist/lib/org-utils.js +77 -0
  34. package/oclif.manifest.json +338 -13
  35. package/package.json +3 -3
  36. package/dist/config/env-vars.d.ts +0 -44
  37. package/dist/config/env-vars.js +0 -47
@@ -1,6 +1,7 @@
1
- import { renderTable, ScCommand, ScConnection, sleep } from '@dishantlangayan/sc-cli-core';
1
+ import { renderTable, ScCommand, sleep } from '@dishantlangayan/sc-cli-core';
2
2
  import { Flags } from '@oclif/core';
3
3
  import { MultiBar, Presets } from 'cli-progress';
4
+ import { resolveOrgConnection } from '../../../lib/org-utils.js';
4
5
  export default class MissionctrlBrokerOpstatus extends ScCommand {
5
6
  static args = {};
6
7
  static description = `Get the status of all operations being performed on an event broker service.
@@ -10,6 +11,7 @@ export default class MissionctrlBrokerOpstatus extends ScCommand {
10
11
  static examples = [
11
12
  '<%= config.bin %> <%= command.id %> -b <broker-id>',
12
13
  '<%= config.bin %> <%= command.id %> -n <broker-name>',
14
+ '<%= config.bin %> <%= command.id %> --org=my-org -b <broker-id>',
13
15
  ];
14
16
  static flags = {
15
17
  'broker-id': Flags.string({
@@ -22,6 +24,10 @@ export default class MissionctrlBrokerOpstatus extends ScCommand {
22
24
  description: 'Name of the event broker service.',
23
25
  exactlyOne: ['broker-id', 'name'],
24
26
  }),
27
+ org: Flags.string({
28
+ char: 'o',
29
+ description: 'Organization ID or alias to use. If not specified, uses the default organization.',
30
+ }),
25
31
  'show-progress': Flags.boolean({
26
32
  char: 'p',
27
33
  description: 'Displays a status bar of the in-progress operations. The command will wait for completion of each step of the operation.',
@@ -37,7 +43,7 @@ export default class MissionctrlBrokerOpstatus extends ScCommand {
37
43
  let brokerId = flags['broker-id'] ?? '';
38
44
  const showProgress = flags['show-progress'] ?? false;
39
45
  const waitMs = flags['wait-ms'] ?? 5000;
40
- const conn = new ScConnection();
46
+ const conn = await resolveOrgConnection(this, flags.org);
41
47
  // Base API url
42
48
  let apiUrl = `/missionControl/eventBrokerServices`;
43
49
  // If broker name provided, retrieve the broker service id first
@@ -7,6 +7,7 @@ export default class MissionctrlBrokerState extends ScCommand<typeof Missionctrl
7
7
  static flags: {
8
8
  'broker-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
9
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ org: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
11
  };
11
12
  run(): Promise<EventBrokerRedundancyApiResponse>;
12
13
  }
@@ -1,5 +1,6 @@
1
- import { printObjectAsKeyValueTable, ScCommand, ScConnection } from '@dishantlangayan/sc-cli-core';
1
+ import { printObjectAsKeyValueTable, ScCommand } from '@dishantlangayan/sc-cli-core';
2
2
  import { Flags } from '@oclif/core';
3
+ import { resolveOrgConnection } from '../../../lib/org-utils.js';
3
4
  export default class MissionctrlBrokerState extends ScCommand {
4
5
  static args = {};
5
6
  static description = `Get the availability state of an event broker service and the name of the active messaging node using the service's unique identifier.
@@ -10,6 +11,7 @@ export default class MissionctrlBrokerState extends ScCommand {
10
11
  static examples = [
11
12
  '<%= config.bin %> <%= command.id %> --broker-id=MyBrokerServiceId',
12
13
  '<%= config.bin %> <%= command.id %> --name=MyBrokerName',
14
+ '<%= config.bin %> <%= command.id %> --org=my-org --broker-id=MyBrokerServiceId',
13
15
  ];
14
16
  static flags = {
15
17
  'broker-id': Flags.string({
@@ -22,12 +24,16 @@ export default class MissionctrlBrokerState extends ScCommand {
22
24
  description: 'Name of the event broker service.',
23
25
  exactlyOne: ['broker-id', 'name'],
24
26
  }),
27
+ org: Flags.string({
28
+ char: 'o',
29
+ description: 'Organization ID or alias to use. If not specified, uses the default organization.',
30
+ }),
25
31
  };
26
32
  async run() {
27
33
  const { flags } = await this.parse(MissionctrlBrokerState);
28
34
  const name = flags.name ?? '';
29
35
  let brokerId = flags['broker-id'] ?? '';
30
- const conn = new ScConnection();
36
+ const conn = await resolveOrgConnection(this, flags.org);
31
37
  // API url
32
38
  let apiUrl = `/missionControl/eventBrokerServices`;
33
39
  if (name) {
@@ -9,6 +9,7 @@ export default class MissionctrlBrokerUpdate extends ScCommand<typeof Missionctr
9
9
  locked: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
10
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
11
  'new-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ org: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
13
  };
13
14
  run(): Promise<EventBrokerOperationApiResponse>;
14
15
  }
@@ -1,5 +1,6 @@
1
- import { printObjectAsKeyValueTable, ScCommand, ScConnection } from '@dishantlangayan/sc-cli-core';
1
+ import { printObjectAsKeyValueTable, ScCommand } from '@dishantlangayan/sc-cli-core';
2
2
  import { Flags } from '@oclif/core';
3
+ import { resolveOrgConnection } from '../../../lib/org-utils.js';
3
4
  export default class MissionctrlBrokerUpdate extends ScCommand {
4
5
  static args = {};
5
6
  static description = `Update the configuration of an existing event broker service.
@@ -11,7 +12,7 @@ export default class MissionctrlBrokerUpdate extends ScCommand {
11
12
  static examples = [
12
13
  '<%= config.bin %> <%= command.id %>',
13
14
  '<%= config.bin %> <%= command.id %> --broker-id <broker-id> --new-name <new-name>',
14
- '<%= config.bin %> <%= command.id %> --name <name> --new-name <new-name>',
15
+ '<%= config.bin %> <%= command.id %> --org=my-org --name <name> --new-name <new-name>',
15
16
  ];
16
17
  static flags = {
17
18
  'broker-id': Flags.string({
@@ -31,6 +32,10 @@ export default class MissionctrlBrokerUpdate extends ScCommand {
31
32
  'new-name': Flags.string({
32
33
  description: 'New name of the event broker service. The new service name must be unique within an organization.',
33
34
  }),
35
+ org: Flags.string({
36
+ char: 'o',
37
+ description: 'Organization ID or alias to use. If not specified, uses the default organization.',
38
+ }),
34
39
  };
35
40
  async run() {
36
41
  const { flags } = await this.parse(MissionctrlBrokerUpdate);
@@ -44,7 +49,7 @@ export default class MissionctrlBrokerUpdate extends ScCommand {
44
49
  ...(locked && { locked: lockedBoolValue }),
45
50
  ...(newName && { name: newName }),
46
51
  };
47
- const conn = new ScConnection();
52
+ const conn = await resolveOrgConnection(this, flags.org);
48
53
  // API url
49
54
  let apiUrl = `/missionControl/eventBrokerServices`;
50
55
  let brokerIdToUpdate = brokerId;
@@ -9,6 +9,7 @@ export default class PlatformEnvCreate extends ScCommand<typeof PlatformEnvCreat
9
9
  isDefault: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
10
  isProduction: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
11
  name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
+ org: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
13
  };
13
14
  run(): Promise<EnvironmentApiResponse>;
14
15
  }
@@ -1,12 +1,14 @@
1
- import { printObjectAsKeyValueTable, ScCommand, ScConnection } from '@dishantlangayan/sc-cli-core';
1
+ import { printObjectAsKeyValueTable, ScCommand } from '@dishantlangayan/sc-cli-core';
2
2
  import { Flags } from '@oclif/core';
3
+ import { resolveOrgConnection } from '../../../lib/org-utils.js';
3
4
  export default class PlatformEnvCreate extends ScCommand {
4
5
  static args = {};
5
6
  static description = `Create a new environment.
6
7
 
7
8
  Token Permissions: [ environments:edit ]`;
8
9
  static examples = [
9
- '<%= config.bin %> <%= command.id %> --name=MyEnvironment --description="My environment description" --isDefault --isProduction',
10
+ '<%= config.bin %> <%= command.id %> --name=MyEnvironment',
11
+ '<%= config.bin %> <%= command.id %> --org=my-org --name=MyEnvironment --description="My environment description" --isDefault --isProduction',
10
12
  ];
11
13
  static flags = {
12
14
  description: Flags.string({
@@ -27,6 +29,10 @@ export default class PlatformEnvCreate extends ScCommand {
27
29
  description: 'Name of the environment to create.',
28
30
  required: true,
29
31
  }),
32
+ org: Flags.string({
33
+ char: 'o',
34
+ description: 'Organization ID or alias to use. If not specified, uses the default organization.',
35
+ }),
30
36
  };
31
37
  async run() {
32
38
  const { flags } = await this.parse(PlatformEnvCreate);
@@ -34,7 +40,7 @@ export default class PlatformEnvCreate extends ScCommand {
34
40
  const desc = flags.description ?? '';
35
41
  const isDefault = flags.isDefault ?? false;
36
42
  const isProduction = flags.isProduction ?? false;
37
- const conn = new ScConnection();
43
+ const conn = await resolveOrgConnection(this, flags.org);
38
44
  // API url
39
45
  const apiUrl = `/platform/environments`;
40
46
  // API body
@@ -6,6 +6,7 @@ export default class PlatformEnvDelete extends ScCommand<typeof PlatformEnvDelet
6
6
  static flags: {
7
7
  'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
8
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ org: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
10
  };
10
11
  run(): Promise<{
11
12
  message: string;
@@ -1,5 +1,6 @@
1
- import { ScCommand, ScConnection } from '@dishantlangayan/sc-cli-core';
1
+ import { ScCommand } from '@dishantlangayan/sc-cli-core';
2
2
  import { Flags } from '@oclif/core';
3
+ import { resolveOrgConnection } from '../../../lib/org-utils.js';
3
4
  export default class PlatformEnvDelete extends ScCommand {
4
5
  static args = {};
5
6
  static description = `Delete an environment using either its name or unique identifier. The default environment cannot be deleted.
@@ -8,6 +9,7 @@ export default class PlatformEnvDelete extends ScCommand {
8
9
  static examples = [
9
10
  '<%= config.bin %> <%= command.id %> --name=MyEnvName',
10
11
  '<%= config.bin %> <%= command.id %> --env-id=MyEnvId',
12
+ '<%= config.bin %> <%= command.id %> --org=my-org --name=MyEnvName',
11
13
  ];
12
14
  static flags = {
13
15
  'env-id': Flags.string({
@@ -20,12 +22,16 @@ export default class PlatformEnvDelete extends ScCommand {
20
22
  description: 'Name of the environment.',
21
23
  exactlyOne: ['env-id', 'name'],
22
24
  }),
25
+ org: Flags.string({
26
+ char: 'o',
27
+ description: 'Organization ID or alias to use. If not specified, uses the default organization.',
28
+ }),
23
29
  };
24
30
  async run() {
25
31
  const { flags } = await this.parse(PlatformEnvDelete);
26
32
  const name = flags.name ?? '';
27
33
  const envId = flags['env-id'] ?? '';
28
- const conn = new ScConnection();
34
+ const conn = await resolveOrgConnection(this, flags.org);
29
35
  // API url
30
36
  let apiUrl = `/platform/environments`;
31
37
  let envIdToDelete = envId;
@@ -7,6 +7,7 @@ export default class PlatformEnvDisplay extends ScCommand<typeof PlatformEnvDisp
7
7
  static flags: {
8
8
  'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
9
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ org: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
11
  };
11
12
  run(): Promise<EnvironmentApiResponse | EnvironmentListApiResponse>;
12
13
  }
@@ -1,5 +1,6 @@
1
- import { printObjectAsKeyValueTable, ScCommand, ScConnection } from '@dishantlangayan/sc-cli-core';
1
+ import { printObjectAsKeyValueTable, ScCommand } from '@dishantlangayan/sc-cli-core';
2
2
  import { Flags } from '@oclif/core';
3
+ import { resolveOrgConnection } from '../../../lib/org-utils.js';
3
4
  export default class PlatformEnvDisplay extends ScCommand {
4
5
  static args = {};
5
6
  static description = `Display information about an Environment.
@@ -10,6 +11,7 @@ export default class PlatformEnvDisplay extends ScCommand {
10
11
  static examples = [
11
12
  '<%= config.bin %> <%= command.id %> --name=MyEnvName',
12
13
  '<%= config.bin %> <%= command.id %> --env-id=MyEnvId',
14
+ '<%= config.bin %> <%= command.id %> --org=my-org --env-id=MyEnvId',
13
15
  ];
14
16
  static flags = {
15
17
  'env-id': Flags.string({
@@ -22,12 +24,16 @@ export default class PlatformEnvDisplay extends ScCommand {
22
24
  description: 'Name of the environment.',
23
25
  exactlyOne: ['env-id', 'name'],
24
26
  }),
27
+ org: Flags.string({
28
+ char: 'o',
29
+ description: 'Organization ID or alias to use. If not specified, uses the default organization.',
30
+ }),
25
31
  };
26
32
  async run() {
27
33
  const { flags } = await this.parse(PlatformEnvDisplay);
28
34
  const name = flags.name ?? '';
29
35
  const envId = flags['env-id'] ?? '';
30
- const conn = new ScConnection();
36
+ const conn = await resolveOrgConnection(this, flags.org);
31
37
  // API url
32
38
  // If env name provided, get all environments matching provided name
33
39
  // If env id provided, get environment with that id
@@ -6,6 +6,7 @@ export default class PlatformEnvList extends ScCommand<typeof PlatformEnvList> {
6
6
  static examples: string[];
7
7
  static flags: {
8
8
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ org: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
10
  pageNumber: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
11
  pageSize: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  sort: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -1,5 +1,6 @@
1
- import { renderTable, ScCommand, ScConnection } from '@dishantlangayan/sc-cli-core';
1
+ import { renderTable, ScCommand } from '@dishantlangayan/sc-cli-core';
2
2
  import { Flags } from '@oclif/core';
3
+ import { resolveOrgConnection } from '../../../lib/org-utils.js';
3
4
  export default class PlatformEnvList extends ScCommand {
4
5
  static args = {};
5
6
  static description = `Get a list of all Environments.
@@ -7,6 +8,7 @@ export default class PlatformEnvList extends ScCommand {
7
8
  Required token permissions: [ environments:view ]`;
8
9
  static examples = [
9
10
  '<%= config.bin %> <%= command.id %>',
11
+ '<%= config.bin %> <%= command.id %> --org=my-org',
10
12
  '<%= config.bin %> <%= command.id %> --name=Default --pageNumber=1 --pageSize=10 --sort=name:ASC',
11
13
  ];
12
14
  static flags = {
@@ -14,6 +16,10 @@ export default class PlatformEnvList extends ScCommand {
14
16
  char: 'n',
15
17
  description: 'Name of the environment to match on.',
16
18
  }),
19
+ org: Flags.string({
20
+ char: 'o',
21
+ description: 'Organization ID or alias to use. If not specified, uses the default organization.',
22
+ }),
17
23
  pageNumber: Flags.integer({
18
24
  char: 'p',
19
25
  description: 'The page number to get. Defaults to 10',
@@ -30,7 +36,7 @@ export default class PlatformEnvList extends ScCommand {
30
36
  };
31
37
  async run() {
32
38
  const { flags } = await this.parse(PlatformEnvList);
33
- const conn = new ScConnection();
39
+ const conn = await resolveOrgConnection(this, flags.org);
34
40
  const pageSize = flags.pageSize ?? 10;
35
41
  const pageNumber = flags.pageNumber ?? 1;
36
42
  // API url
@@ -10,6 +10,7 @@ export default class PlatformEnvUpdate extends ScCommand<typeof PlatformEnvUpdat
10
10
  isDefault: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
11
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
12
  'new-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ org: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
14
  };
14
15
  run(): Promise<EnvironmentApiResponse>;
15
16
  }
@@ -1,5 +1,6 @@
1
- import { printObjectAsKeyValueTable, ScCommand, ScConnection } from '@dishantlangayan/sc-cli-core';
1
+ import { printObjectAsKeyValueTable, ScCommand } from '@dishantlangayan/sc-cli-core';
2
2
  import { Flags } from '@oclif/core';
3
+ import { resolveOrgConnection } from '../../../lib/org-utils.js';
3
4
  export default class PlatformEnvUpdate extends ScCommand {
4
5
  static args = {};
5
6
  static description = `Modify an environment's attributes
@@ -9,8 +10,9 @@ export default class PlatformEnvUpdate extends ScCommand {
9
10
  Token Permissions: [ environments:edit ]
10
11
  `;
11
12
  static examples = [
12
- '<%= config.bin %> <%= command.id %> --name=MyEnvName --new-name=MyNewEnvName --description="My description to update" --isDefault',
13
+ '<%= config.bin %> <%= command.id %> --name=MyEnvName --new-name=MyNewEnvName',
13
14
  '<%= config.bin %> <%= command.id %> --env-id=MyEnvId --new-name=MyNewEnvName --description="My description to update" --isDefault',
15
+ '<%= config.bin %> <%= command.id %> --org=my-org --name=MyEnvName --isDefault',
14
16
  ];
15
17
  static flags = {
16
18
  description: Flags.string({
@@ -33,6 +35,10 @@ export default class PlatformEnvUpdate extends ScCommand {
33
35
  'new-name': Flags.string({
34
36
  description: 'New name of the environment.',
35
37
  }),
38
+ org: Flags.string({
39
+ char: 'o',
40
+ description: 'Organization ID or alias to use. If not specified, uses the default organization.',
41
+ }),
36
42
  };
37
43
  async run() {
38
44
  const { flags } = await this.parse(PlatformEnvUpdate);
@@ -46,7 +52,7 @@ export default class PlatformEnvUpdate extends ScCommand {
46
52
  ...(desc && { description: desc }),
47
53
  ...(newName && { name: newName }),
48
54
  };
49
- const conn = new ScConnection();
55
+ const conn = await resolveOrgConnection(this, flags.org);
50
56
  // API url
51
57
  let apiUrl = `/platform/environments`;
52
58
  let envIdToUpdate = envId;
@@ -0,0 +1,24 @@
1
+ import { ScCommand, ScConnection } from '@dishantlangayan/sc-cli-core';
2
+ import { Command } from '@oclif/core';
3
+ /**
4
+ * Resolves organization and creates authenticated ScConnection
5
+ *
6
+ * This utility function handles the common pattern of resolving which organization
7
+ * to use for API calls. It supports both explicit org specification via the --org flag
8
+ * and automatic default org resolution.
9
+ *
10
+ * @param command - The ScCommand instance (for error handling and OrgManager access)
11
+ * @param orgIdentifier - Optional org ID or alias from --org flag
12
+ * @param timeout - Optional timeout override in milliseconds (default: 10000ms)
13
+ * @returns Configured ScConnection instance ready for API calls
14
+ * @throws Will call command.error() with user-friendly messages for various error scenarios
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // In a command's run() method:
19
+ * const {flags} = await this.parse(MyCommand)
20
+ * const conn = await resolveOrgConnection(this, flags.org)
21
+ * const resp = await conn.get('/api/endpoint')
22
+ * ```
23
+ */
24
+ export declare function resolveOrgConnection(command: ScCommand<typeof Command>, orgIdentifier?: string, timeout?: number): Promise<ScConnection>;
@@ -0,0 +1,77 @@
1
+ import { OrgError, OrgErrorCode } from '@dishantlangayan/sc-cli-core';
2
+ /**
3
+ * Resolves organization and creates authenticated ScConnection
4
+ *
5
+ * This utility function handles the common pattern of resolving which organization
6
+ * to use for API calls. It supports both explicit org specification via the --org flag
7
+ * and automatic default org resolution.
8
+ *
9
+ * @param command - The ScCommand instance (for error handling and OrgManager access)
10
+ * @param orgIdentifier - Optional org ID or alias from --org flag
11
+ * @param timeout - Optional timeout override in milliseconds (default: 10000ms)
12
+ * @returns Configured ScConnection instance ready for API calls
13
+ * @throws Will call command.error() with user-friendly messages for various error scenarios
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // In a command's run() method:
18
+ * const {flags} = await this.parse(MyCommand)
19
+ * const conn = await resolveOrgConnection(this, flags.org)
20
+ * const resp = await conn.get('/api/endpoint')
21
+ * ```
22
+ */
23
+ export async function resolveOrgConnection(command, orgIdentifier, timeout) {
24
+ try {
25
+ // Use type assertion to access protected method
26
+ const orgManager = await command.getOrgManager();
27
+ // If org identifier provided, validate and use it
28
+ if (orgIdentifier) {
29
+ const org = await orgManager.getOrg(orgIdentifier);
30
+ if (!org) {
31
+ command.error(`Organization '${orgIdentifier}' not found. Run 'sc account:list' to see available organizations.`, { exit: 2 });
32
+ }
33
+ // Use alias if available, otherwise use orgId
34
+ const connectionIdentifier = org.alias || org.orgId;
35
+ return await orgManager.createConnection(connectionIdentifier, timeout);
36
+ }
37
+ // No org specified, try default
38
+ const defaultOrg = await orgManager.getDefaultOrg();
39
+ if (!defaultOrg) {
40
+ const allOrgs = await orgManager.getAllOrgs();
41
+ if (allOrgs.length === 0) {
42
+ command.error("No organizations found. Please run 'sc account:login' to authenticate.", { exit: 2 });
43
+ }
44
+ else {
45
+ command.error("No default organization set. Please specify --org flag or set a default with 'sc account:login --set-default'.", { exit: 2 });
46
+ }
47
+ }
48
+ // Use alias if available, otherwise use orgId
49
+ const connectionIdentifier = defaultOrg.alias || defaultOrg.orgId;
50
+ return await orgManager.createConnection(connectionIdentifier, timeout);
51
+ }
52
+ catch (error) {
53
+ // Handle OrgManager-specific errors
54
+ if (error instanceof OrgError) {
55
+ switch (error.code) {
56
+ case OrgErrorCode.INVALID_ACCESS_TOKEN: {
57
+ command.error("Invalid access token. Please re-authenticate with 'sc account:login'.", { exit: 2 });
58
+ break;
59
+ }
60
+ case OrgErrorCode.NOT_INITIALIZED: {
61
+ command.error("Organization manager not initialized. Please run 'sc account:login' to authenticate.", { exit: 2 });
62
+ break;
63
+ }
64
+ case OrgErrorCode.ORG_NOT_FOUND: {
65
+ command.error("Organization not found. Run 'sc account:list' to see available organizations.", { exit: 2 });
66
+ break;
67
+ }
68
+ default: {
69
+ command.error(`Organization error: ${error.message}`, { exit: 2 });
70
+ break;
71
+ }
72
+ }
73
+ }
74
+ // Re-throw unexpected errors
75
+ throw error;
76
+ }
77
+ }