checkbox-cli 3.0.0 → 3.0.1

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 (2) hide show
  1. package/dist/checkbox.js +58 -26
  2. package/package.json +1 -1
package/dist/checkbox.js CHANGED
@@ -16,7 +16,7 @@ import { join } from 'path';
16
16
  // ── Config ──────────────────────────────────────────────────────────
17
17
  const CONFIG_DIR = join(homedir(), '.checkbox');
18
18
  const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
19
- const VERSION = '3.0.0';
19
+ const VERSION = '3.0.1';
20
20
  function loadConfig() {
21
21
  try {
22
22
  if (!existsSync(CONFIG_FILE))
@@ -56,7 +56,7 @@ function resolveConfig() {
56
56
  // ── API ─────────────────────────────────────────────────────────────
57
57
  function extractError(obj) {
58
58
  if (!obj)
59
- return 'Unknown error';
59
+ return '';
60
60
  if (typeof obj === 'string')
61
61
  return obj;
62
62
  if (typeof obj.error === 'string')
@@ -78,46 +78,78 @@ function api(cfg) {
78
78
  headers,
79
79
  body: JSON.stringify(body),
80
80
  });
81
- const json = await res.json().catch(() => null);
82
- if (!res.ok)
83
- throw new Error(extractError(json) || `Request failed (${res.status})`);
84
- if (json && json.success === false)
81
+ const text = await res.text().catch(() => '');
82
+ let json = null;
83
+ try {
84
+ json = JSON.parse(text);
85
+ }
86
+ catch { }
87
+ if (!res.ok) {
88
+ throw new Error(extractError(json) || text || `Request failed (${res.status})`);
89
+ }
90
+ if (json && json.success === false) {
85
91
  throw new Error(extractError(json) || 'Request failed');
92
+ }
86
93
  return json;
87
94
  }
88
95
  async function get(path) {
89
96
  const res = await fetch(`${cfg.apiUrl}${path}`, { headers });
90
- const json = await res.json().catch(() => null);
91
- if (!res.ok)
92
- throw new Error(extractError(json) || `Request failed (${res.status})`);
93
- if (json && json.success === false)
97
+ const text = await res.text().catch(() => '');
98
+ let json = null;
99
+ try {
100
+ json = JSON.parse(text);
101
+ }
102
+ catch { }
103
+ if (!res.ok) {
104
+ throw new Error(extractError(json) || text || `Request failed (${res.status})`);
105
+ }
106
+ if (json && json.success === false) {
94
107
  throw new Error(extractError(json) || 'Request failed');
108
+ }
95
109
  return json;
96
110
  }
97
111
  return { post, get };
98
112
  }
99
113
  // ── Data Helpers ────────────────────────────────────────────────────
100
114
  async function listEntities(post, orgId, entityType, filters) {
101
- const res = await post('/api/v2/query', {
102
- type: 'list_entities',
103
- organization_id: orgId,
104
- payload: { entity_type: entityType, organization_id: orgId, ...filters },
105
- });
106
- return Array.isArray(res.data) ? res.data : [];
115
+ try {
116
+ const res = await post('/api/v2/query', {
117
+ type: 'list_entities',
118
+ organization_id: orgId,
119
+ payload: { entity_type: entityType, organization_id: orgId, ...filters },
120
+ });
121
+ return Array.isArray(res.data) ? res.data : [];
122
+ }
123
+ catch (err) {
124
+ p.log.error(err.message || `Could not load ${entityType}`);
125
+ return [];
126
+ }
107
127
  }
108
128
  async function searchEntities(post, orgId, search, limit = 20) {
109
- const res = await post('/api/v2/introspection/entities', {
110
- organization_id: orgId,
111
- search,
112
- limit,
113
- });
114
- return res.data?.entities || [];
129
+ try {
130
+ const res = await post('/api/v2/introspection/entities', {
131
+ organization_id: orgId,
132
+ search,
133
+ limit,
134
+ });
135
+ return res.data?.entities || [];
136
+ }
137
+ catch (err) {
138
+ p.log.error(err.message || 'Search failed');
139
+ return [];
140
+ }
115
141
  }
116
142
  async function getWorkspaceNodes(post, orgId) {
117
- const res = await post('/api/v2/introspection/workspace', {
118
- organization_id: orgId,
119
- });
120
- return res.data?.nodes || [];
143
+ try {
144
+ const res = await post('/api/v2/introspection/workspace', {
145
+ organization_id: orgId,
146
+ });
147
+ return res.data?.nodes || [];
148
+ }
149
+ catch (err) {
150
+ p.log.error(err.message || 'Could not load workspace');
151
+ return [];
152
+ }
121
153
  }
122
154
  // ── Formatters ──────────────────────────────────────────────────────
123
155
  function truncate(s, max) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "checkbox-cli",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Beautiful, interactive CLI for Checkbox compliance management. Setup wizard, guided workflows, and full workspace control from your terminal.",
5
5
  "type": "module",
6
6
  "main": "dist/checkbox.js",