@jacebenson/jsn 5.5.1-dev.169.1 → 5.5.1-dev.170.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jacebenson/jsn",
3
- "version": "5.5.1-dev.169.1",
3
+ "version": "5.5.1-dev.170.1",
4
4
  "description": "A command-line interface for ServiceNow that follows the Unix philosophy: simple, composable, and scriptable.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -2,7 +2,7 @@ import { constrainQuery, constrainedQueryHelp } from '../constrained-query.js';
2
2
  import { enrichRelatedLists, relatedListOptions } from '../related-lists.js';
3
3
  // Generic table-based CRUD command builder
4
4
 
5
- import { formatRecordForDisplay, getStringField, buildRecordPayload, confirmDelete, interactiveList, canPrompt } from '../helpers.js';
5
+ import { formatRecordForDisplay, findOmittedColumns, getStringField, buildRecordPayload, confirmDelete, interactiveList, canPrompt } from '../helpers.js';
6
6
  import { getRecord, listRecords, recordListParams, createRecord, updateRecord, deleteRecord, recordOptions } from '../records-engine.js';
7
7
  import { unwrapSysId } from '../resolve-record.js';
8
8
  import { getCurrentUser, getCurrentApplication } from '../context.js';
@@ -171,11 +171,19 @@ export function buildDevCmd(name, table, aliases, defaultColumns, wrap, opts = {
171
171
  const q = `${constrainedQuery}${constrainedQuery ? '^' : ''}ORDERBYDESCsys_updated_on`;
172
172
  const params = recordListParams({ limit, fields: ['sys_id', ...columns], query: q });
173
173
  const records = await listRecords(app.sdk, { table, params, displayValues: argv.displayValues ?? opts.referenceMode });
174
+ const missingColumns = findOmittedColumns(records, columns);
175
+ const presentColumns = missingColumns.length ? columns.filter(c => !missingColumns.includes(c)) : columns;
174
176
  app.ok({
175
177
  table,
176
178
  count: records.length,
177
179
  columns,
178
- records: argv.displayValues || opts.listProjection === 'full' ? records : records.map(r => formatRecordForDisplay(r, columns)),
180
+ ...(missingColumns.length ? {
181
+ missing_columns: missingColumns,
182
+ warnings: [
183
+ `Column(s) not returned by ServiceNow (non-existent or restricted on ${table}): ${missingColumns.join(', ')}. Run \`jsn columns --table ${table}\` to inspect valid fields.`,
184
+ ],
185
+ } : {}),
186
+ records: argv.displayValues || opts.listProjection === 'full' ? records : records.map(r => formatRecordForDisplay(r, presentColumns)),
179
187
  context: { instance_url: app.getEffectiveInstance() },
180
188
  }, {
181
189
  summary: `${records.length} ${name}(s)`,
@@ -2,7 +2,7 @@ import { enrichRelatedLists, relatedListOptions } from '../related-lists.js';
2
2
  // Generic command builder for CRUD operations on a ServiceNow table
3
3
  // Used by incidents, changes, requests, tasks, and most dev subcommands
4
4
 
5
- import { getStringField, formatRecordForDisplay, buildQuerySuffix, resolveFieldsParam, confirmDelete, interactiveList, canPrompt, buildRecordPayload } from '../helpers.js';
5
+ import { getStringField, formatRecordForDisplay, findOmittedColumns, buildQuerySuffix, resolveFieldsParam, confirmDelete, interactiveList, canPrompt, buildRecordPayload } from '../helpers.js';
6
6
  import { getRecord, listRecords, recordListParams, createRecord, updateRecord, deleteRecord, recordOptions } from '../records-engine.js';
7
7
  import { resolveSysId } from '../resolve-record.js';
8
8
  import { FormatAuto } from '../output.js';
@@ -88,7 +88,9 @@ export function buildTicketCommands(table, displayName, alias, defaultColumns, s
88
88
  const params = recordListParams({ limit, offset, fields, query: q });
89
89
 
90
90
  const records = await listRecords(app.sdk, { table, params, displayValues: argv.displayValues ?? opts.referenceMode });
91
- const displayRecords = fields && !argv.displayValues && opts.listProjection !== 'full' ? records.map(r => formatRecordForDisplay(r, columns)) : records;
91
+ const missingColumns = fields ? findOmittedColumns(records, columns) : [];
92
+ const presentColumns = missingColumns.length ? columns.filter(c => !missingColumns.includes(c)) : columns;
93
+ const displayRecords = fields && !argv.displayValues && opts.listProjection !== 'full' ? records.map(r => formatRecordForDisplay(r, presentColumns)) : records;
92
94
 
93
95
  const breadcrumbs = [
94
96
  { action: 'create', cmd: `jsn ${alias} create --description "..."`, description: `Create a new ${displayName}` },
@@ -114,6 +116,12 @@ export function buildTicketCommands(table, displayName, alias, defaultColumns, s
114
116
  table,
115
117
  count: records.length,
116
118
  columns,
119
+ ...(missingColumns.length ? {
120
+ missing_columns: missingColumns,
121
+ warnings: [
122
+ `Column(s) not returned by ServiceNow (non-existent or restricted on ${table}): ${missingColumns.join(', ')}. Run \`jsn columns --table ${table}\` to inspect valid fields.`,
123
+ ],
124
+ } : {}),
117
125
  records: displayRecords,
118
126
  pagination: { limit, offset, hasMore: records.length === limit },
119
127
  context: { instance_url: app.getEffectiveInstance() },
@@ -1,4 +1,4 @@
1
- import { formatCommandList, formatRecordForDisplay, buildQuerySuffix, buildRecordPayload, getStringField, interactiveList, resolveFieldsParam, checkDerivedFields, confirmDelete, verifyWriteBack } from '../helpers.js';
1
+ import { formatCommandList, formatRecordForDisplay, findOmittedColumns, buildQuerySuffix, buildRecordPayload, getStringField, interactiveList, resolveFieldsParam, checkDerivedFields, confirmDelete, verifyWriteBack } from '../helpers.js';
2
2
  import { listRecords, recordListParams, getRecord, createRecord, updateRecord, deleteRecord } from '../records-engine.js';
3
3
  import { resolveRecord, unwrapSysId } from '../resolve-record.js';
4
4
  import { errUsage } from '../errors.js';
@@ -149,7 +149,9 @@ export function recordsCmd(wrap) {
149
149
  const fields = resolveFieldsParam(columns);
150
150
  const params = recordListParams({ limit: argv['sys-id'] ? 1 : argv.limit, offset: argv.offset, fields, query });
151
151
  const records = await listRecords(app.sdk, { table, params, displayValues: argv.displayValues });
152
- const displayRecords = fields && !argv.displayValues ? records.map(r => formatRecordForDisplay(r, columns)) : records;
152
+ const missingColumns = fields ? findOmittedColumns(records, columns) : [];
153
+ const presentColumns = missingColumns.length ? columns.filter(c => !missingColumns.includes(c)) : columns;
154
+ const displayRecords = fields && !argv.displayValues ? records.map(r => formatRecordForDisplay(r, presentColumns)) : records;
153
155
 
154
156
  // include_counts: default opt-in on every list. Opt out per-profile
155
157
  // (config include_counts:false) or per-invocation (--no-count).
@@ -190,6 +192,12 @@ export function recordsCmd(wrap) {
190
192
  table,
191
193
  count: records.length,
192
194
  columns,
195
+ ...(missingColumns.length ? {
196
+ missing_columns: missingColumns,
197
+ warnings: [
198
+ `Column(s) not returned by ServiceNow (non-existent or restricted on ${table}): ${missingColumns.join(', ')}. Run \`jsn columns --table ${table}\` to inspect valid fields.`,
199
+ ],
200
+ } : {}),
193
201
  records: displayRecords,
194
202
  pagination: { limit: argv.limit, offset: argv.offset, ...(total != null ? { total, hasMore: argv.offset + argv.limit < total } : {}) },
195
203
  context: { instance_url: app.getEffectiveInstance() },
@@ -1,5 +1,5 @@
1
1
  import { enrichRelatedLists, relatedListOptions } from '../related-lists.js';
2
- import { formatRecordForDisplay, getStringField, buildQuerySuffix, resolveFieldsParam, buildRecordPayload, confirmDelete } from '../helpers.js';
2
+ import { formatRecordForDisplay, findOmittedColumns, getStringField, buildQuerySuffix, resolveFieldsParam, buildRecordPayload, confirmDelete } from '../helpers.js';
3
3
  import { getRecord, listRecords, recordListParams, createRecord, updateRecord, deleteRecord, recordOptions } from '../records-engine.js';
4
4
  import { resolveSysId } from '../resolve-record.js';
5
5
  import { declareCapabilities } from '../capabilities.js';
@@ -28,7 +28,9 @@ export function ticketsCmd(wrap) {
28
28
  const q = argv.query ? argv.query + '^ORDERBYDESCsys_updated_on' : 'ORDERBYDESCsys_updated_on';
29
29
  const params = recordListParams({ limit: argv.limit, offset: argv.offset, fields, query: q });
30
30
  const records = await listRecords(app.sdk, { table: 'task', params, displayValues: argv.displayValues });
31
- const displayRecords = fields && !argv.displayValues ? records.map(r => formatRecordForDisplay(r, columns)) : records;
31
+ const missingColumns = fields ? findOmittedColumns(records, columns) : [];
32
+ const presentColumns = missingColumns.length ? columns.filter(c => !missingColumns.includes(c)) : columns;
33
+ const displayRecords = fields && !argv.displayValues ? records.map(r => formatRecordForDisplay(r, presentColumns)) : records;
32
34
  const breadcrumbs = [
33
35
  { action: 'create', cmd: 'jsn tickets create -f short_description=New ticket', description: 'Create a new ticket' },
34
36
  ];
@@ -50,6 +52,12 @@ export function ticketsCmd(wrap) {
50
52
  table: 'task',
51
53
  count: records.length,
52
54
  columns,
55
+ ...(missingColumns.length ? {
56
+ missing_columns: missingColumns,
57
+ warnings: [
58
+ `Column(s) not returned by ServiceNow (non-existent or restricted on task): ${missingColumns.join(', ')}. Run \`jsn columns --table task\` to inspect valid fields.`,
59
+ ],
60
+ } : {}),
53
61
  records: displayRecords,
54
62
  pagination: { limit: argv.limit, offset: argv.offset, hasMore: records.length === argv.limit },
55
63
  context: { instance_url: app.getEffectiveInstance() },
package/src/helpers.js CHANGED
@@ -298,6 +298,22 @@ export function formatRecordForDisplay(record, columns) {
298
298
  return result;
299
299
  }
300
300
 
301
+ /**
302
+ * Identify requested columns that ServiceNow omitted from every returned row
303
+ * (because the field does not exist on the table or is blocked by ACLs).
304
+ * An existing empty column is still present as a key (`col in row === true`).
305
+ *
306
+ * @param {Array<object>} records — raw records from ServiceNow Table API
307
+ * @param {string[]} columns — requested column names
308
+ * @returns {string[]} columns absent from all returned records
309
+ */
310
+ export function findOmittedColumns(records, columns) {
311
+ if (!Array.isArray(records) || records.length === 0 || !Array.isArray(columns) || columns.includes('*')) {
312
+ return [];
313
+ }
314
+ return columns.filter(col => col && col !== '*' && !records.some(r => r && typeof r === 'object' && col in r));
315
+ }
316
+
301
317
  export function truncateString(str, maxLen) {
302
318
  if (!str || str.length <= maxLen) return str;
303
319
  return str.slice(0, maxLen - 3) + '...';
package/src/output.js CHANGED
@@ -364,6 +364,12 @@ export class OutputWriter {
364
364
  this.writeFormattedRecord(data, tableName);
365
365
  }
366
366
 
367
+ if (Array.isArray(data.warnings) && data.warnings.length > 0 && !data._formatted) {
368
+ for (const w of data.warnings) {
369
+ this.writer.write(colorYellow(`⚠ ${w}\n`));
370
+ }
371
+ }
372
+
367
373
  if (Array.isArray(data.records) && data.records.length > 0) {
368
374
  // A _formatted visual (e.g. cmdb relationship tree) replaces the
369
375
  // flat table in styled mode — showing both is noise.