@dishantlangayan/solace-cloud-cli 0.0.2 → 0.0.3

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,5 +1,6 @@
1
- import { Command } from '@oclif/core';
2
- export default class PlatformEnvCreate extends Command {
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ import { Environment } from '../../../types/environment.js';
3
+ export default class PlatformEnvCreate extends ScCommand<typeof PlatformEnvCreate> {
3
4
  static args: {};
4
5
  static description: string;
5
6
  static examples: string[];
@@ -9,6 +10,6 @@ export default class PlatformEnvCreate extends Command {
9
10
  isProduction: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
11
  name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
12
  };
12
- run(): Promise<void>;
13
+ run(): Promise<Environment>;
13
14
  private print;
14
15
  }
@@ -1,8 +1,8 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import { table } from 'table';
3
- import { camelCaseToTitleCase } from '../../../util/internal.js';
1
+ import { Flags } from '@oclif/core';
2
+ import { ScCommand } from '../../../sc-command.js';
3
+ import { camelCaseToTitleCase, renderKeyValueTable } from '../../../util/internal.js';
4
4
  import { ScConnection } from '../../../util/sc-connection.js';
5
- export default class PlatformEnvCreate extends Command {
5
+ export default class PlatformEnvCreate extends ScCommand {
6
6
  static args = {};
7
7
  static description = `Create a new environment.
8
8
 
@@ -49,22 +49,15 @@ export default class PlatformEnvCreate extends Command {
49
49
  // Display results
50
50
  this.log('Environment created successfully.');
51
51
  this.print(resp.data);
52
+ // Return raw json if --json flag is set
53
+ return resp.data;
52
54
  }
53
55
  print(environment) {
54
- this.log();
55
56
  const tableRows = [
56
57
  ['Key', 'Value'],
57
58
  ...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
58
59
  ];
59
- // Table config
60
- const config = {
61
- columns: {
62
- 1: { width: 50, wrapWord: true },
63
- },
64
- drawHorizontalLine(lineIndex, rowCount) {
65
- return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
66
- },
67
- };
68
- this.log(table(tableRows, config));
60
+ this.log();
61
+ this.log(renderKeyValueTable(tableRows));
69
62
  }
70
63
  }
@@ -1,5 +1,5 @@
1
- import { Command } from '@oclif/core';
2
- export default class PlatformEnvDelete extends Command {
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ export default class PlatformEnvDelete extends ScCommand<typeof PlatformEnvDelete> {
3
3
  static args: {};
4
4
  static description: string;
5
5
  static examples: string[];
@@ -7,5 +7,7 @@ export default class PlatformEnvDelete extends Command {
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
9
  };
10
- run(): Promise<void>;
10
+ run(): Promise<{
11
+ message: string;
12
+ }>;
11
13
  }
@@ -1,6 +1,7 @@
1
- import { Command, Flags } from '@oclif/core';
1
+ import { Flags } from '@oclif/core';
2
+ import { ScCommand } from '../../../sc-command.js';
2
3
  import { ScConnection } from '../../../util/sc-connection.js';
3
- export default class PlatformEnvDelete extends Command {
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.
6
7
 
@@ -28,20 +29,31 @@ export default class PlatformEnvDelete extends Command {
28
29
  let envIdToDelete = envId;
29
30
  // If env name provided, get the environment matching provided name and delete. If more than one environment matches, an error will be thrown.
30
31
  // If env id provided, delete environment with that id
32
+ let foundMultiple = false;
31
33
  if (name) {
32
34
  // API call to get environment by name
33
35
  const getEnvApiUrl = `${apiUrl}?name=${name}`;
34
36
  const resp = await conn.get(getEnvApiUrl);
35
37
  if (resp.data.length > 1) {
36
- this.error(`Multiple environments found with: ${name}. Exactly one environment must match the provided name.`);
38
+ foundMultiple = true;
37
39
  }
38
40
  else {
39
41
  envIdToDelete = resp.data[0]?.id;
40
42
  }
41
43
  }
42
- // API call to delete environment by id
43
- apiUrl += `/${envIdToDelete}`;
44
- await conn.delete(apiUrl);
45
- this.log(`Environment with id '${envIdToDelete}' has been deleted successfully.`);
44
+ let message = '';
45
+ if (foundMultiple) {
46
+ message = `Multiple environments found with: ${name}. Exactly one environment must match the provided name.`;
47
+ this.warn(message);
48
+ }
49
+ else {
50
+ // API call to delete environment by id
51
+ apiUrl += `/${envIdToDelete}`;
52
+ await conn.delete(apiUrl);
53
+ message = `Environment with id '${envIdToDelete}' has been deleted successfully.`;
54
+ this.log(message);
55
+ }
56
+ // Return raw json if --json flag is set
57
+ return { message };
46
58
  }
47
59
  }
@@ -1,5 +1,6 @@
1
- import { Command } from '@oclif/core';
2
- export default class PlatformEnvDisplay extends Command {
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ import { Environment } from '../../../types/environment.js';
3
+ export default class PlatformEnvDisplay extends ScCommand<typeof PlatformEnvDisplay> {
3
4
  static args: {};
4
5
  static description: string;
5
6
  static examples: string[];
@@ -7,6 +8,6 @@ export default class PlatformEnvDisplay extends Command {
7
8
  'env-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
8
9
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
10
  };
10
- run(): Promise<void>;
11
+ run(): Promise<Environment[]>;
11
12
  private print;
12
13
  }
@@ -1,15 +1,14 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import { table } from 'table';
3
- import { camelCaseToTitleCase } from '../../../util/internal.js';
1
+ import { Flags } from '@oclif/core';
2
+ import { ScCommand } from '../../../sc-command.js';
3
+ import { camelCaseToTitleCase, renderKeyValueTable } from '../../../util/internal.js';
4
4
  import { ScConnection } from '../../../util/sc-connection.js';
5
- export default class PlatformEnvDisplay extends Command {
5
+ export default class PlatformEnvDisplay extends ScCommand {
6
6
  static args = {};
7
7
  static description = `Display information about an Environment.
8
8
 
9
9
  Use either the Environment's ID (--env-id) or name of the Environment (--name).
10
10
 
11
- Required token permissions: [ environments:view ]
12
- `;
11
+ Required token permissions: [ environments:view ]`;
13
12
  static examples = ['<%= config.bin %> <%= command.id %> --name=MyEnvName', '<%= config.bin %> <%= command.id %> --env-id=MyEnvId'];
14
13
  static flags = {
15
14
  'env-id': Flags.string({
@@ -32,11 +31,13 @@ export default class PlatformEnvDisplay extends Command {
32
31
  // If env name provided, get all environments matching provided name
33
32
  // If env id provided, get environment with that id
34
33
  let apiUrl = `/platform/environments`;
34
+ let rawResp;
35
35
  if (envId) {
36
36
  // API call to get environment by id
37
37
  apiUrl += `/${envId}`;
38
38
  const resp = await conn.get(apiUrl);
39
39
  this.print(resp.data);
40
+ rawResp = [resp.data];
40
41
  }
41
42
  else if (name) {
42
43
  // API call to get environment by name
@@ -45,26 +46,20 @@ export default class PlatformEnvDisplay extends Command {
45
46
  for (const env of resp.data) {
46
47
  this.print(env);
47
48
  }
49
+ rawResp = resp.data;
48
50
  }
49
51
  else {
50
52
  this.error('Either --env-id or --name must be provided.');
51
53
  }
54
+ // Return raw json if --json flag is set
55
+ return rawResp;
52
56
  }
53
57
  print(environment) {
54
- this.log();
55
58
  const tableRows = [
56
59
  ['Key', 'Value'],
57
60
  ...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
58
61
  ];
59
- // Table config
60
- const config = {
61
- columns: {
62
- 1: { width: 50, wrapWord: true },
63
- },
64
- drawHorizontalLine(lineIndex, rowCount) {
65
- return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
66
- },
67
- };
68
- this.log(table(tableRows, config));
62
+ this.log();
63
+ this.log(renderKeyValueTable(tableRows));
69
64
  }
70
65
  }
@@ -1,5 +1,6 @@
1
- import { Command } from '@oclif/core';
2
- export default class PlatformEnvList extends Command {
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ import { Environment } from '../../../types/environment.js';
3
+ export default class PlatformEnvList extends ScCommand<typeof PlatformEnvList> {
3
4
  static args: {};
4
5
  static description: string;
5
6
  static examples: string[];
@@ -9,5 +10,5 @@ export default class PlatformEnvList extends Command {
9
10
  pageSize: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
11
  sort: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  };
12
- run(): Promise<void>;
13
+ run(): Promise<Environment[]>;
13
14
  }
@@ -1,24 +1,28 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import { table } from 'table';
1
+ import { Flags } from '@oclif/core';
2
+ import { ScCommand } from '../../../sc-command.js';
3
+ import { renderTable } from '../../../util/internal.js';
3
4
  import { ScConnection } from '../../../util/sc-connection.js';
4
- export default class PlatformEnvList extends Command {
5
+ export default class PlatformEnvList extends ScCommand {
5
6
  static args = {};
6
7
  static description = `Get a list of all Environments.
7
8
 
8
9
  Required token permissions: [ environments:view ]`;
9
10
  static examples = ['<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %> --name=Default --pageNumber=1 --pageSize=10 --sort=name:ASC'];
10
11
  static flags = {
11
- // flag with a value (-n, --name=VALUE)
12
- name: Flags.string({ char: 'n', description: 'Name of the environment to match on.' }),
13
- // pageNumber (--pageNumber=VALUE)
14
- pageNumber: Flags.integer({ description: 'The page number to get. Defaults to 10' }),
15
- // pageSize (--pageSize=VALUE)
12
+ name: Flags.string({
13
+ char: 'n',
14
+ description: 'Name of the environment to match on.'
15
+ }),
16
+ pageNumber: Flags.integer({
17
+ char: 'p',
18
+ description: 'The page number to get. Defaults to 10'
19
+ }),
16
20
  pageSize: Flags.integer({
21
+ char: 's',
17
22
  description: 'The number of environments to get per page. Defaults to 1',
18
23
  max: 100,
19
24
  min: 1,
20
25
  }),
21
- // sort (--sort=VALUE)
22
26
  sort: Flags.string({
23
27
  description: 'The query (fieldName:<ASC/DESC>) used to sort the environment list in the response.',
24
28
  }),
@@ -36,20 +40,20 @@ export default class PlatformEnvList extends Command {
36
40
  // API call
37
41
  const resp = await conn.get(apiUrl);
38
42
  // Array to output as table
39
- const envArray = [['Name', 'Id', 'Is Default', 'Is Production', 'Description'], ...resp.data.map((item) => [
43
+ const envArray = [
44
+ ['Name', 'Id', 'Is Default', 'Is Production', 'Description'],
45
+ ...resp.data.map((item) => [
40
46
  item.name,
41
47
  item.id,
42
48
  item.isDefault,
43
49
  item.isProduction,
44
50
  item.description,
45
- ])];
51
+ ])
52
+ ];
46
53
  // Display results as a table
47
- const config = {
48
- columns: {
49
- 4: { width: 50, wrapWord: true },
50
- },
51
- };
52
54
  this.log();
53
- this.log(table(envArray, config));
55
+ this.log(renderTable(envArray, { 4: { width: 50, wrapWord: true } }));
56
+ // Return raw json if --json flag is set
57
+ return resp.data;
54
58
  }
55
59
  }
@@ -1,5 +1,6 @@
1
- import { Command } from '@oclif/core';
2
- export default class PlatformEnvUpdate extends Command {
1
+ import { ScCommand } from '../../../sc-command.js';
2
+ import { Environment } from '../../../types/environment.js';
3
+ export default class PlatformEnvUpdate extends ScCommand<typeof PlatformEnvUpdate> {
3
4
  static args: {};
4
5
  static description: string;
5
6
  static examples: string[];
@@ -10,6 +11,6 @@ export default class PlatformEnvUpdate extends Command {
10
11
  name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
12
  'new-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
13
  };
13
- run(): Promise<void>;
14
+ run(): Promise<Environment>;
14
15
  private print;
15
16
  }
@@ -1,8 +1,8 @@
1
- import { Command, Flags } from '@oclif/core';
2
- import { table } from 'table';
3
- import { camelCaseToTitleCase } from '../../../util/internal.js';
1
+ import { Flags } from '@oclif/core';
2
+ import { ScCommand } from '../../../sc-command.js';
3
+ import { camelCaseToTitleCase, renderKeyValueTable } from '../../../util/internal.js';
4
4
  import { ScConnection } from '../../../util/sc-connection.js';
5
- export default class PlatformEnvUpdate extends Command {
5
+ export default class PlatformEnvUpdate extends ScCommand {
6
6
  static args = {};
7
7
  static description = `Modify an environment's attributes
8
8
 
@@ -69,22 +69,14 @@ export default class PlatformEnvUpdate extends Command {
69
69
  const resp = await conn.put(apiUrl, body);
70
70
  this.log(`Environment with id '${envIdToUdpate}' has been updated successfully.`);
71
71
  this.print(resp.data);
72
+ return resp.data;
72
73
  }
73
74
  print(environment) {
74
- this.log();
75
75
  const tableRows = [
76
76
  ['Key', 'Value'],
77
77
  ...Object.entries(environment).map(([key, value]) => [camelCaseToTitleCase(key), value]),
78
78
  ];
79
- // Table config
80
- const config = {
81
- columns: {
82
- 1: { width: 50, wrapWord: true },
83
- },
84
- drawHorizontalLine(lineIndex, rowCount) {
85
- return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
86
- },
87
- };
88
- this.log(table(tableRows, config));
79
+ this.log();
80
+ this.log(renderKeyValueTable(tableRows));
89
81
  }
90
82
  }
@@ -58,3 +58,28 @@ export interface EventBrokerServiceDetail {
58
58
  serviceClassId?: string;
59
59
  type?: string;
60
60
  }
61
+ /**
62
+ * For Broker Operation Status
63
+ */
64
+ export interface OperationResponse {
65
+ data: OperationData;
66
+ }
67
+ export interface OperationData {
68
+ id: string;
69
+ type: "operation";
70
+ operationType: string;
71
+ createdBy: string;
72
+ createdTime: string;
73
+ completedTime: string;
74
+ resourceId: string;
75
+ resourceType: string;
76
+ progressLogs?: ProgressLog[];
77
+ status: string;
78
+ }
79
+ export interface ProgressLog {
80
+ step: string;
81
+ message: string;
82
+ timestamp: string;
83
+ stepId: string;
84
+ status: string;
85
+ }
@@ -4,3 +4,15 @@
4
4
  * @param text Text to transform.
5
5
  */
6
6
  export declare function camelCaseToTitleCase(text: string): string;
7
+ export interface ColumnConfig {
8
+ width?: number;
9
+ wrapWord?: boolean;
10
+ }
11
+ export declare function renderTable<T>(data: T[][], columnConfig?: Record<number, ColumnConfig>): string;
12
+ export declare function renderKeyValueTable<T>(data: T[][], columnConfig?: Record<number, ColumnConfig>): string;
13
+ /**
14
+ * Sleep function.
15
+ * @param ms Num of milliseconds to wait
16
+ * @returns
17
+ */
18
+ export declare function sleep(ms: number): Promise<void>;
@@ -1,3 +1,4 @@
1
+ import { table } from 'table';
1
2
  /**
2
3
  * Formats a camel case style `string` into a title case.
3
4
  *
@@ -10,3 +11,33 @@ export function camelCaseToTitleCase(text) {
10
11
  .replaceAll(/\s{2,}/g, ' ')
11
12
  .trim();
12
13
  }
14
+ export function renderTable(data, columnConfig) {
15
+ // Table config
16
+ const tableConfig = {
17
+ columns: columnConfig
18
+ };
19
+ const tableStr = table(data, tableConfig);
20
+ return tableStr;
21
+ }
22
+ export function renderKeyValueTable(data, columnConfig) {
23
+ if (columnConfig === undefined) {
24
+ columnConfig = { 1: { width: 50, wrapWord: true } };
25
+ }
26
+ // Table config
27
+ const tableConfig = {
28
+ columns: columnConfig,
29
+ drawHorizontalLine(lineIndex, rowCount) {
30
+ return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount;
31
+ },
32
+ };
33
+ const tableStr = table(data, tableConfig);
34
+ return tableStr;
35
+ }
36
+ /**
37
+ * Sleep function.
38
+ * @param ms Num of milliseconds to wait
39
+ * @returns
40
+ */
41
+ export function sleep(ms) {
42
+ return new Promise(resolve => setTimeout(resolve, ms));
43
+ }