@solidactions/cli 1.7.1 → 1.8.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.
@@ -7,11 +7,19 @@ exports.webhookList = webhookList;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const api_1 = require("../utils/api");
10
+ const webhook_formatters_1 = require("../utils/webhook-formatters");
10
11
  async function webhookList(projectName, options = {}) {
12
+ const format = options.format ?? 'table';
13
+ if (format !== 'table' && format !== 'json') {
14
+ console.error(chalk_1.default.red(`Invalid --format: ${options.format}. Expected 'table' or 'json'.`));
15
+ process.exit(1);
16
+ }
11
17
  const config = await (0, api_1.requireConfigWithWorkspace)();
12
18
  const environment = options.env || 'dev';
13
19
  const projectSlug = environment === 'production' ? projectName : `${projectName}-${environment}`;
14
- console.log(chalk_1.default.blue(`Webhooks for project "${projectName}"${environment !== 'production' ? ` (${environment})` : ''}:`));
20
+ if (format === 'table') {
21
+ console.log(chalk_1.default.blue(`Webhooks for project "${projectName}"${environment !== 'production' ? ` (${environment})` : ''}:`));
22
+ }
15
23
  try {
16
24
  const params = {};
17
25
  if (options.showSecrets) {
@@ -22,27 +30,18 @@ async function webhookList(projectName, options = {}) {
22
30
  params,
23
31
  });
24
32
  const webhooks = response.data.data || [];
33
+ const showSecrets = options.showSecrets === true;
34
+ if (format === 'json') {
35
+ console.log((0, webhook_formatters_1.formatJson)(webhooks, { showSecrets }));
36
+ return;
37
+ }
38
+ // table mode
25
39
  if (webhooks.length === 0) {
26
40
  console.log(chalk_1.default.yellow('No webhooks found for project "' + projectName + '".'));
27
41
  return;
28
42
  }
29
43
  console.log('');
30
- if (options.showSecrets) {
31
- console.log(chalk_1.default.gray('WORKFLOW'.padEnd(30) + 'URL'.padEnd(60) + 'SECRET'));
32
- console.log(chalk_1.default.gray('-'.repeat(120)));
33
- }
34
- else {
35
- console.log(chalk_1.default.gray('WORKFLOW'.padEnd(30) + 'URL'));
36
- console.log(chalk_1.default.gray('-'.repeat(90)));
37
- }
38
- for (const webhook of webhooks) {
39
- const name = webhook.workflow_name || webhook.workflow_slug || '?';
40
- const url = webhook.webhook_path_url || webhook.webhook_url || '?';
41
- let line = name.padEnd(30) + chalk_1.default.cyan(url.padEnd(60));
42
- if (options.showSecrets) {
43
- const secret = webhook.webhook_secret || '-';
44
- line += chalk_1.default.gray(secret);
45
- }
44
+ for (const line of (0, webhook_formatters_1.formatTable)(webhooks, { showSecrets })) {
46
45
  console.log(line);
47
46
  }
48
47
  console.log('');
package/dist/index.js CHANGED
@@ -296,6 +296,7 @@ webhook
296
296
  .argument('<project>', 'Project name')
297
297
  .option('-e, --env <environment>', 'Environment (production/staging/dev)')
298
298
  .option('--show-secrets', 'Show webhook secrets')
299
+ .option('--format <format>', 'Output format: table or json', 'table')
299
300
  .action((projectName, options) => {
300
301
  (0, webhook_list_1.webhookList)(projectName, options);
301
302
  });
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.formatTable = formatTable;
7
+ exports.formatJson = formatJson;
8
+ // src/utils/webhook-formatters.ts
9
+ const chalk_1 = __importDefault(require("chalk"));
10
+ function columnWidth(min, values) {
11
+ return Math.max(min, ...values.map(v => v.length)) + 2;
12
+ }
13
+ function formatTable(webhooks, opts) {
14
+ const names = webhooks.map(w => w.workflow_name || w.workflow_slug || '?');
15
+ const urls = webhooks.map(w => w.webhook_path_url || w.webhook_url || '?');
16
+ const nameWidth = columnWidth(30, names);
17
+ const urlWidth = columnWidth(60, urls);
18
+ const headerPlain = opts.showSecrets
19
+ ? 'WORKFLOW'.padEnd(nameWidth) + 'URL'.padEnd(urlWidth) + 'SECRET'
20
+ : 'WORKFLOW'.padEnd(nameWidth) + 'URL';
21
+ const dividerWidth = opts.showSecrets ? nameWidth + urlWidth + 64 : nameWidth + urlWidth;
22
+ const lines = [];
23
+ lines.push(chalk_1.default.gray(headerPlain));
24
+ lines.push(chalk_1.default.gray('-'.repeat(dividerWidth)));
25
+ for (let i = 0; i < webhooks.length; i++) {
26
+ const name = names[i];
27
+ const url = urls[i];
28
+ let line = name.padEnd(nameWidth) + chalk_1.default.cyan(url.padEnd(urlWidth));
29
+ if (opts.showSecrets) {
30
+ const secret = webhooks[i].webhook_secret || '-';
31
+ line += chalk_1.default.gray(secret);
32
+ }
33
+ lines.push(line);
34
+ }
35
+ return lines;
36
+ }
37
+ function formatJson(webhooks, opts) {
38
+ const rows = webhooks.map(w => {
39
+ const base = {
40
+ workflow: w.workflow_name ?? w.workflow_slug ?? null,
41
+ url: w.webhook_path_url ?? w.webhook_url ?? null,
42
+ };
43
+ if (opts.showSecrets) {
44
+ base.secret = w.webhook_secret ?? '';
45
+ }
46
+ return base;
47
+ });
48
+ return JSON.stringify(rows, null, 2);
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidactions/cli",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "description": "SolidActions CLI - Deploy and manage workflow automation",
5
5
  "main": "dist/index.js",
6
6
  "bin": {