@jacebenson/jsn 5.5.11-dev.241.1 → 5.5.11

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/README.md CHANGED
@@ -28,31 +28,6 @@ jsn --help
28
28
 
29
29
  Instance reads use your selected profile; add `--profile <name>` to choose another. Documentation search needs no ServiceNow connection and uses the hosted service by default. Use `jsn <command> --help` for options or `jsn --all-commands --help` for the full reference.
30
30
 
31
- ## Saved Access Analyzer evidence
32
-
33
- ```sh
34
- jsn access-analyzer list --limit 20 --profile <name>
35
- jsn access-analyzer show <request-id> --json
36
- jsn access-analyzer explain <result-id> --format styled
37
- jsn access-analyzer show <request-id> --get data.request.user.value
38
- ```
39
-
40
- These commands read saved `sn_access_analyzer_request`,
41
- `sn_access_analyzer_access_result`, and `sn_access_analyzer_debug_log` records.
42
- They never evaluate access or save an analysis. The Access Analyzer application
43
- and read permissions on its tables are required; denied or unavailable table
44
- reads fail rather than appearing as empty evidence. ACL-filtered empty reads
45
- cannot prove access or absence of saved data.
46
-
47
- IDs must be exact 32-character hexadecimal sys_ids. Each command supports
48
- `--limit` (1–200) and `--offset` (default 0). JSON includes `pagination.has_more`
49
- and `next_offset` from one-row lookahead, not a total count. `show` preserves
50
- per-operation execution IDs; these are not shared run IDs and do not imply
51
- that outcomes belong to the request's last run. `explain` orders checks by log sequence then sys_id.
52
- Raw reference values and display labels are retained in JSON; joins use raw IDs.
53
- Passed, Blocked, Skipped and Undefined remain distinct. A record-availability
54
- failure with Business Rule evidence is not automatically an ACL failure.
55
-
56
31
  ## Choose output
57
32
 
58
33
  Use the default terminal view for people, `--csv` or `--tsv` for flat rows, and `--json` when scripts need pagination, context, or errors. CSV/TSV do not fetch more pages or preserve both reference IDs and labels. Pagination notices go to stderr only when more results are explicitly known; silence does not prove completeness. JSON retains reference objects only if the command has not already flattened them. See [output details](https://jsn.jace.pro/docs/output/).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jacebenson/jsn",
3
- "version": "5.5.11-dev.241.1",
3
+ "version": "5.5.11",
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": {
@@ -105,7 +105,7 @@ class CommandNode {
105
105
  positional(name, config = {}) { node.positionals.set(name, { ...config, name }); return this; },
106
106
  demandCommand(count, message) { node.demand = { count, message }; return this; },
107
107
  middleware(fn) { node.middlewares.push(...(Array.isArray(fn) ? fn : [fn])); return this; },
108
- strict() { node.strict = true; return this; },
108
+ strict() { return this; },
109
109
  check() { return this; },
110
110
  usage(value) { node.usageText = value; return this; },
111
111
  epilogue(value) { node.epilogueText = value; return this; },
@@ -256,10 +256,6 @@ export class LocalCLI {
256
256
  catch (err) { this._fail(err.message, err); return { values: {}, positionals: [] }; }
257
257
  const argv = { _: path.map((n) => n.name) };
258
258
  for (const [key, value] of Object.entries(parsed.values)) {
259
- if (opts.validate !== false && path.some(node => node.strict) && !Object.hasOwn(defs, key)) {
260
- this._fail(`Unknown option: --${key}`);
261
- return null;
262
- }
263
259
  if (opts.validate !== false && key === 'q' && !options.has('q')) {
264
260
  this._fail('Option -q (--query) is not supported by this command.');
265
261
  return null;
@@ -541,9 +537,6 @@ export class LocalCLI {
541
537
  }
542
538
  for (const spec of specs) if (spec.demandOption && argv[spec.name] === undefined) return this._fail(`Missing required argument: --${spec.name}`);
543
539
  for (const pos of positions) if (pos.required && argv[pos.name] === undefined) return this._fail(`Missing required argument: ${pos.name}`);
544
- if (path.some(commandNode => commandNode.strict) && positionalIndex < parsed.positionals.length) {
545
- return this._fail(`Unexpected argument: ${parsed.positionals[positionalIndex]}`);
546
- }
547
540
  for (const middleware of this.middlewares) await middleware(argv);
548
541
  for (const commandNode of path) for (const middleware of commandNode.middlewares) await middleware(argv);
549
542
  if (node.definition.handler) await node.definition.handler(argv);
package/src/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- import { accessAnalyzerCmd, flowsCmd, workflowsCmd, midserversCmd, subscriptionsCmd, customizationsCmd, skippedUpdatesCmd, docsCmd, perfCmd } from './command-families.js';
1
+ import { flowsCmd, workflowsCmd, midserversCmd, subscriptionsCmd, customizationsCmd, skippedUpdatesCmd, docsCmd, perfCmd } from './command-families.js';
2
2
  import { visibleCommandRegistry } from './command-audience.js';
3
3
  // Root CLI using the local yargs-compatible adapter
4
4
 
@@ -380,7 +380,6 @@ export function buildCLI() {
380
380
  // AUTOMATION — Async
381
381
  .command(flowsCmd(wrap))
382
382
  .command(workflowsCmd(wrap))
383
- .command(accessAnalyzerCmd(wrap))
384
383
  .command(actionsCmd(wrap))
385
384
  .command(scriptactionsCmd(wrap))
386
385
  .command(scheduledjobsCmd(wrap))
@@ -8,13 +8,6 @@ import { declareCapabilities } from './capabilities.js';
8
8
  // and complete-discovery API without pre-parsing argv or a generated catalog.
9
9
  const require = createRequire(import.meta.url);
10
10
 
11
- export const accessAnalyzerCmdDefinition = {
12
- command: 'access-analyzer [subcommand]',
13
- describe: 'Inspect saved Access Analyzer requests, outcomes and checks (read-only)',
14
- };
15
- declareCapabilities('access-analyzer', { queryTable: 'sn_access_analyzer_request', mutationSubcommands: [] });
16
- export const accessAnalyzerCmd = wrap => ({ ...accessAnalyzerCmdDefinition, load: () => require('./commands/access-analyzer.js').accessAnalyzerCmd(wrap) });
17
-
18
11
  export const flowsCmdDefinition = {
19
12
  command: 'flows [subcommand]',
20
13
  aliases: ['flow'],
package/src/help.js CHANGED
@@ -93,7 +93,6 @@ const AUTOMATION_COMMANDS = [
93
93
  ];
94
94
 
95
95
  const ACCESS_COMMANDS = [
96
- { name: 'access-analyzer', desc: 'Saved access analysis evidence (read-only)' },
97
96
  { name: 'acls', alias: 'acl', desc: 'Access controls' },
98
97
  { name: 'b4rules', alias: 'b4r', desc: 'Before-query business rules (see also Automation)' },
99
98
  { name: 'roles', alias: 'role', desc: 'Roles' },
@@ -278,7 +277,7 @@ function renderConciseHelp(config, registry, width) {
278
277
  `\nCOMMON COMMANDS\n${renderRows(common.map((command) => ({ label: command.name, description: command.desc })), { width, indent: 2 })}`,
279
278
  '',
280
279
  'ALL COMMANDS BY GROUP',
281
- ...wrapText('jsn --all-commands --help for details', { width }),
280
+ ...wrapText('names only; jsn --all-commands --help for details', { width }),
282
281
  renderRows(groups, { width, indent: 2 }),
283
282
  '',
284
283
  'EXAMPLES',
@@ -1,92 +0,0 @@
1
- import { errNotFound, errUsage } from './errors.js';
2
-
3
- const REQUEST = 'sn_access_analyzer_request';
4
- const RESULT = 'sn_access_analyzer_access_result';
5
- const LOG = 'sn_access_analyzer_debug_log';
6
- const fields = {
7
- [REQUEST]: 'sys_id,analyze_by,analyzed_by,user,group,role,resource_type,target_table,target_record,target_field,target_ui_page,target_rest_endpoint,target_rest_endpoint_method,target_client_callable_script_include,operations,short_description,last_run,evaluated_using',
8
- [RESULT]: 'sys_id,access_analyzer_request,analyzed_by,operation,overall_access,security_data_filter_result,acl_result,accesshandler_result,datafiltration_result,execution_time,execution_id,insights,read_only_field,script_execution,current_resource,current_resource_type,record_available',
9
- [LOG]: 'sys_id,access_analyzer_request,access_result,type,path,status,roles,roles_result,condition_result,script_result,security_attribute,decision_type,record_ref,log_table_name,log_sequence,log_time,app,applies_to,is_acl_customized,script_execution,applies_to_condition_result,controlled_by_references_result,empty',
10
- };
11
-
12
- // Display labels are presentation only. Never use them as reference join keys.
13
- export const rawAccessValue = value => value && typeof value === 'object' ? String(value.value ?? '') : String(value ?? '');
14
- const text = value => value && typeof value === 'object' ? String(value.display_value ?? value.value ?? '') : String(value ?? '');
15
- function validateId(id) {
16
- if (typeof id !== 'string' || !/^[0-9a-f]{32}$/i.test(id)) throw errUsage('Provide a 32-character hexadecimal sys_id.');
17
- }
18
- function bounds(limit, offset) {
19
- if (!Number.isSafeInteger(limit) || limit < 1 || limit > 200) throw errUsage('--limit must be an integer from 1 to 200.');
20
- if (!Number.isSafeInteger(offset) || offset < 0 || offset > Number.MAX_SAFE_INTEGER - 201) throw errUsage('--offset must be a nonnegative safe integer.');
21
- }
22
- async function read(sdk, table, query, limit, offset = 0) {
23
- const params = new URLSearchParams({ sysparm_query: query, sysparm_fields: fields[table], sysparm_limit: String(limit), sysparm_offset: String(offset), sysparm_display_value: 'all' });
24
- const rows = await sdk.listStrict(table, params);
25
- if (!Array.isArray(rows) || rows.some(row => !row || typeof row !== 'object' || Array.isArray(row))) {
26
- throw Object.assign(new Error(`Malformed table response for ${table}`), { code: 'malformed_response' });
27
- }
28
- return rows;
29
- }
30
- async function one(sdk, table, id) {
31
- const rows = await read(sdk, table, `sys_id=${id}`, 1);
32
- if (!rows.length) throw errNotFound(`Saved Access Analyzer record ${id} was not found or is not readable.`);
33
- if (rawAccessValue(rows[0].sys_id) !== id) throw new Error('Access Analyzer returned a different record identity.');
34
- return rows[0];
35
- }
36
- async function page(sdk, table, query, limit, offset) {
37
- const rows = await read(sdk, table, query, limit + 1, offset);
38
- const hasMore = rows.length > limit;
39
- return { records: rows.slice(0, limit), count: Math.min(rows.length, limit), pagination: { limit, offset, has_more: hasMore, next_offset: hasMore ? offset + limit : null } };
40
- }
41
-
42
- export async function listAccessAnalyses(sdk, { limit = 20, offset = 0 } = {}) {
43
- bounds(limit, offset);
44
- return page(sdk, REQUEST, 'ORDERBYDESClast_run^ORDERBYsys_id', limit, offset);
45
- }
46
- export async function showAccessAnalysis(sdk, id, { limit = 50, offset = 0 } = {}) {
47
- validateId(id);
48
- bounds(limit, offset);
49
- const request = await one(sdk, REQUEST, id);
50
- const results = await page(sdk, RESULT, `access_analyzer_request=${rawAccessValue(request.sys_id)}^ORDERBYexecution_id^ORDERBYoperation^ORDERBYsys_id`, limit, offset);
51
- assertAssociation(results.records, 'access_analyzer_request', rawAccessValue(request.sys_id));
52
- // execution_id identifies an operation result, not a shared analysis run.
53
- return { request, ...results };
54
- }
55
- export async function explainAccessResult(sdk, id, { limit = 50, offset = 0 } = {}) {
56
- validateId(id);
57
- bounds(limit, offset);
58
- const result = await one(sdk, RESULT, id);
59
- const checks = await page(sdk, LOG, `access_result=${rawAccessValue(result.sys_id)}^ORDERBYlog_sequence^ORDERBYsys_id`, limit, offset);
60
- assertAssociation(checks.records, 'access_result', rawAccessValue(result.sys_id));
61
- const notes = ['Saved evidence only; this command does not run an access evaluation.'];
62
- if (['false', 'no'].includes(rawAccessValue(result.record_available).toLowerCase())) notes.push('The target record was unavailable. Business Rule/query filtering evidence is not itself an ACL failure.');
63
- return { result, ...checks, notes };
64
- }
65
-
66
- function assertAssociation(rows, field, id) {
67
- if (rows.some(row => rawAccessValue(row[field]) !== id)) throw new Error(`Access Analyzer returned a mismatched ${field} association.`);
68
- }
69
- function requestLine(row) {
70
- const identity = ['analyze_by', 'analyzed_by', 'user', 'group', 'role'].map(key => text(row[key])).filter(Boolean).join(' / ') || '(identity unavailable)';
71
- const target = ['resource_type', 'target_table', 'target_record', 'target_field', 'target_ui_page', 'target_rest_endpoint', 'target_rest_endpoint_method', 'target_client_callable_script_include'].map(key => text(row[key])).filter(value => value && value !== 'undefined').join(' / ') || '(target unavailable)';
72
- return `${rawAccessValue(row.sys_id)} | ${identity}\n Target: ${target}\n Last run: ${text(row.last_run) || '(unavailable)'}`;
73
- }
74
- function outcome(row) {
75
- return `${rawAccessValue(row.sys_id)} | ${text(row.operation) || '(operation unavailable)'}: ${text(row.overall_access) || '(undefined)'} | execution ${text(row.execution_id) || '(unavailable)'}\n ACL: ${text(row.acl_result) || '(undefined)'}; security data filter: ${text(row.security_data_filter_result) || '(undefined)'}; access handler: ${text(row.accesshandler_result) || '(undefined)'}; data filtration: ${text(row.datafiltration_result) || '(undefined)'}`;
76
- }
77
- export function formatAccessAnalysis(data, mode) {
78
- const lines = ['Saved Access Analyzer evidence (read-only)'];
79
- if (mode === 'list') lines.push(...data.records.map(requestLine));
80
- if (mode === 'show') lines.push(requestLine(data.request), ...data.records.map(outcome));
81
- if (mode === 'explain') {
82
- lines.push(outcome(data.result), ...data.notes);
83
- for (const row of data.records) {
84
- lines.push(`${text(row.log_sequence)}. ${text(row.type)} ${text(row.path)}: ${text(row.status) || '(undefined)'} [${rawAccessValue(row.sys_id)}]`);
85
- lines.push(` Referenced rule: ${text(row.record_ref) || '(unavailable)'}; table: ${text(row.log_table_name) || '(unavailable)'}; sys_id: ${rawAccessValue(row.record_ref) || '(unavailable)'}`);
86
- lines.push(` Roles: ${text(row.roles)} (${text(row.roles_result) || '(undefined)'}); condition: ${text(row.condition_result) || '(undefined)'}; script: ${text(row.script_result) || '(undefined)'}; security attribute: ${text(row.security_attribute) || '(undefined)'}; decision: ${text(row.decision_type) || '(undefined)'}`);
87
- }
88
- }
89
- if (!data.count) lines.push('No readable saved rows on this page. Empty results do not prove access or absence of ACL-filtered records.');
90
- lines.push(`Page: ${data.count} rows, offset ${data.pagination.offset}${data.pagination.has_more ? `; more available, next offset ${data.pagination.next_offset}` : '; no further readable rows'}.`);
91
- return lines.join('\n');
92
- }
@@ -1,37 +0,0 @@
1
- import { accessAnalyzerCmdDefinition } from '../command-families.js';
2
- import { errUsage } from '../errors.js';
3
- import { listAccessAnalyses, showAccessAnalysis, explainAccessResult, formatAccessAnalysis } from '../access-analyzer.js';
4
-
5
- export function accessAnalyzerCmd(wrap) {
6
- const commands = [
7
- ['list', 'List saved access analyses, identities, targets and last runs', listAccessAnalyses],
8
- ['show <request-id>', 'Show saved operation outcomes for a request sys_id', showAccessAnalysis],
9
- ['explain <result-id>', 'Explain ordered saved checks for an operation result sys_id', explainAccessResult],
10
- ];
11
- return {
12
- ...accessAnalyzerCmdDefinition,
13
- builder: y => {
14
- y = y.strict().middleware(argv => {
15
- if (argv.subcommand) throw errUsage(`Unknown access-analyzer subcommand: ${argv.subcommand}`);
16
- });
17
- for (const [command, describe, read] of commands) {
18
- const mode = command.split(' ')[0];
19
- y = y.command({ command, describe,
20
- builder: sub => {
21
- if (mode !== 'list') sub = sub.positional(`${mode === 'show' ? 'request' : 'result'}-id`, { type: 'string', describe: 'Exact 32-character hexadecimal sys_id' });
22
- return sub.option('limit', { type: 'number', default: mode === 'list' ? 20 : 50, describe: 'Page size (1–200)' })
23
- .option('offset', { type: 'number', default: 0, describe: 'Nonnegative page offset' });
24
- },
25
- handler: wrap(async (argv, app) => {
26
- app.requireInstance();
27
- const options = { limit: argv.limit, offset: argv.offset };
28
- const data = mode === 'list' ? await read(app.sdk, options) : await read(app.sdk, argv[mode === 'show' ? 'request-id' : 'result-id'], options);
29
- Object.defineProperty(data, '_formatted', { value: formatAccessAnalysis(data, mode), enumerable: false });
30
- app.ok(data, { summary: `${data.count} saved ${mode === 'list' ? 'analysis request(s)' : mode === 'show' ? 'operation result(s)' : 'check(s)'}${data.pagination.has_more ? ', more available' : ''}` });
31
- }),
32
- });
33
- }
34
- return y;
35
- },
36
- };
37
- }