@jacebenson/jsn 5.5.7-dev.217.1 → 5.5.7-dev.218.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 +1 -1
- package/src/bounded-reads.js +13 -0
- package/src/capabilities.js +3 -3
- package/src/cli-adapter.js +8 -2
- package/src/cli.js +3 -10
- package/src/command-families.js +68 -0
- package/src/commands/customizations.js +3 -4
- package/src/commands/docs/docs.js +3 -5
- package/src/commands/flows.js +3 -5
- package/src/commands/midservers.js +3 -5
- package/src/commands/perf.js +2 -3
- package/src/commands/records.js +6 -2
- package/src/commands/skipped-updates.js +2 -3
- package/src/commands/subscriptions.js +3 -3
- package/src/commands/workflows.js +3 -5
- package/src/records/inspect.js +30 -16
- package/src/records-engine.js +2 -2
- package/src/sdk-batch.js +2 -1
- package/src/sdk.js +8 -1
- package/src/setup-preferences.js +2 -2
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Ordered results with at most four independent reads in flight. Callers must
|
|
2
|
+
// finish dependency discovery before scheduling; this helper never retries.
|
|
3
|
+
export async function boundedReads(items, read) {
|
|
4
|
+
const results = new Array(items.length);
|
|
5
|
+
let next = 0;
|
|
6
|
+
await Promise.all(Array.from({ length: Math.min(4, items.length) }, async () => {
|
|
7
|
+
while (next < items.length) {
|
|
8
|
+
const index = next++;
|
|
9
|
+
results[index] = await read(items[index], index);
|
|
10
|
+
}
|
|
11
|
+
}));
|
|
12
|
+
return results;
|
|
13
|
+
}
|
package/src/capabilities.js
CHANGED
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
// Note: yargs strips custom properties off command modules when it
|
|
37
37
|
// registers them (only original/description/handler/builder survive in
|
|
38
38
|
// getCommandHandlers()), so declarations live in this module-level map,
|
|
39
|
-
// keyed by root command name.
|
|
40
|
-
//
|
|
41
|
-
// is complete once buildCLI() returns.
|
|
39
|
+
// keyed by root command name. Eager factories declare during registration;
|
|
40
|
+
// lazy families declare in command-families.js, never in a deferred factory.
|
|
41
|
+
// The registry is complete once buildCLI() returns, before path resolution.
|
|
42
42
|
|
|
43
43
|
const REGISTRY = new Map();
|
|
44
44
|
|
package/src/cli-adapter.js
CHANGED
|
@@ -38,6 +38,12 @@ class CommandNode {
|
|
|
38
38
|
|
|
39
39
|
build() {
|
|
40
40
|
if (this.built) return;
|
|
41
|
+
if (this.definition.load) {
|
|
42
|
+
const definition = this.definition.load();
|
|
43
|
+
// Root identity is lightweight and authoritative. Implementations only
|
|
44
|
+
// supply builders/handlers; loading must not change token ownership.
|
|
45
|
+
this.definition = { ...definition, ...this.definition, load: undefined };
|
|
46
|
+
}
|
|
41
47
|
this.built = true;
|
|
42
48
|
if (typeof this.definition.builder === 'function') this.definition.builder(this.api());
|
|
43
49
|
}
|
|
@@ -293,10 +299,10 @@ export class LocalCLI {
|
|
|
293
299
|
* help page. Machine discovery leaves it out, so the JSON schema and bytes
|
|
294
300
|
* stay unchanged.
|
|
295
301
|
*/
|
|
296
|
-
commandRegistry({ summaries = false } = {}) {
|
|
302
|
+
commandRegistry({ summaries = false, shallow = false } = {}) {
|
|
297
303
|
const visible = (node) => !node.definition.hidden;
|
|
298
304
|
const serialize = (node) => {
|
|
299
|
-
node.build();
|
|
305
|
+
if (!shallow) node.build();
|
|
300
306
|
const entry = {
|
|
301
307
|
name: node.name,
|
|
302
308
|
command: node.definition.command || node.name,
|
package/src/cli.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { flowsCmd, workflowsCmd, midserversCmd, subscriptionsCmd, customizationsCmd, skippedUpdatesCmd, docsCmd, perfCmd } from './command-families.js';
|
|
1
2
|
import { visibleCommandRegistry } from './command-audience.js';
|
|
2
3
|
// Root CLI using the local yargs-compatible adapter
|
|
3
4
|
|
|
@@ -11,7 +12,6 @@ import { resolveSession, applySession } from './session.js';
|
|
|
11
12
|
import { renderHelp, renderTips } from './help.js';
|
|
12
13
|
import { isMutationCommand, refreshMutationCommands } from './mutations.js';
|
|
13
14
|
import { maybeShowHome } from './welcome.js';
|
|
14
|
-
import { skippedUpdatesCmd } from './commands/skipped-updates.js';
|
|
15
15
|
import { isLocalPreview, noInstanceCommands, dailyCheckSkipCommands } from './capabilities.js';
|
|
16
16
|
import { guardExit, exitWithError, AppError, CodeUsage } from './errors.js';
|
|
17
17
|
import { formatCommandList } from './helpers.js';
|
|
@@ -44,7 +44,6 @@ import { versionCmd } from './commands/version.js';
|
|
|
44
44
|
import { upgradeCmd } from './commands/upgrade.js';
|
|
45
45
|
import { skillCmd, checkSkill } from './commands/skill.js';
|
|
46
46
|
import { getVersion, checkLatest, getReleaseChannel, getInstallCommand } from './commands/version.js';
|
|
47
|
-
import { docsCmd } from './commands/docs/docs.js';
|
|
48
47
|
|
|
49
48
|
// Table and platform commands registered at root level for progressive disclosure
|
|
50
49
|
import {
|
|
@@ -64,8 +63,6 @@ import {
|
|
|
64
63
|
uimacrosCmd, uxlistsCmd, uxapplicabilityCmd,
|
|
65
64
|
} from './commands/_simple.js';
|
|
66
65
|
import { decisiontablesCmd } from './commands/decisiontables.js';
|
|
67
|
-
import { flowsCmd } from './commands/flows.js';
|
|
68
|
-
import { workflowsCmd } from './commands/workflows.js';
|
|
69
66
|
import { formsCmd } from './commands/forms.js';
|
|
70
67
|
import { listsCmd } from './commands/lists.js';
|
|
71
68
|
import { updateSetsCmd } from './commands/updatesets.js';
|
|
@@ -81,11 +78,7 @@ import { scanCmd } from './commands/scan.js';
|
|
|
81
78
|
import { storeCmd } from './commands/store.js';
|
|
82
79
|
import { pluginsCmd } from './commands/plugins.js';
|
|
83
80
|
import { compareCmd } from './commands/compare.js';
|
|
84
|
-
import { subscriptionsCmd } from './commands/subscriptions.js';
|
|
85
81
|
import { approvalsCmd } from './commands/approvals.js';
|
|
86
|
-
import { perfCmd } from './commands/perf.js';
|
|
87
|
-
import { customizationsCmd } from './commands/customizations.js';
|
|
88
|
-
import { midserversCmd } from './commands/midservers.js';
|
|
89
82
|
import { diffCmd } from './commands/diff.js';
|
|
90
83
|
import { graphqlCmd } from './commands/graphql.js';
|
|
91
84
|
|
|
@@ -554,7 +547,7 @@ export function buildCLI() {
|
|
|
554
547
|
const welcome = maybeShowHome({ argv: formatArgv, requestedFormat, cfg: config });
|
|
555
548
|
if (!welcome) {
|
|
556
549
|
const registry = visibleCommandRegistry(
|
|
557
|
-
cliInstance.commandRegistry({ summaries: true }), config, formatArgv);
|
|
550
|
+
cliInstance.commandRegistry({ summaries: true, shallow: true }), config, formatArgv);
|
|
558
551
|
process.stdout.write(renderHelp(config, registry, { full: formatArgv?.allCommands === true }) + '\n');
|
|
559
552
|
}
|
|
560
553
|
process.exit(0);
|
|
@@ -580,7 +573,7 @@ export function buildCLI() {
|
|
|
580
573
|
const options = cliInstance.parseGlobalOptions(process.argv.slice(2));
|
|
581
574
|
const config = loadConfig(options);
|
|
582
575
|
const registry = visibleCommandRegistry(
|
|
583
|
-
cliInstance.commandRegistry({ summaries: true }), config, options);
|
|
576
|
+
cliInstance.commandRegistry({ summaries: true, shallow: true }), config, options);
|
|
584
577
|
return renderHelp(config, registry, { full: options?.allCommands === true });
|
|
585
578
|
};
|
|
586
579
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Lightweight family identity and safety declarations. Implementations reuse these
|
|
2
|
+
// objects: aliases, root help and mutation policy never depend on loading a handler.
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { declareCapabilities } from './capabilities.js';
|
|
5
|
+
|
|
6
|
+
// Node >=24 supports synchronous require(ESM). These implementation graphs must
|
|
7
|
+
// remain synchronous (no top-level await); this preserves the synchronous adapter
|
|
8
|
+
// and complete-discovery API without pre-parsing argv or a generated catalog.
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
|
|
11
|
+
export const flowsCmdDefinition = {
|
|
12
|
+
command: 'flows [subcommand]',
|
|
13
|
+
aliases: ['flow'],
|
|
14
|
+
describe: 'Manage Flow Designer flows',
|
|
15
|
+
};
|
|
16
|
+
declareCapabilities('flows', { transactionScopeOption: 'scope', mutationContextExemptSubcommands: ['test', 'unlock'], mutationSubcommands: ['clone', 'copy', 'create', 'update', 'edit', 'delete', 'publish', 'test', 'unlock'] });
|
|
17
|
+
export const flowsCmd = wrap => ({ ...flowsCmdDefinition, load: () => require('./commands/flows.js').flowsCmd(wrap) });
|
|
18
|
+
|
|
19
|
+
export const workflowsCmdDefinition = {
|
|
20
|
+
command: 'workflows [subcommand]',
|
|
21
|
+
aliases: ['workflow'],
|
|
22
|
+
describe: 'Inspect legacy Workflow Editor workflows (read-only)',
|
|
23
|
+
};
|
|
24
|
+
declareCapabilities('workflows', { mutationSubcommands: [] });
|
|
25
|
+
export const workflowsCmd = wrap => ({ ...workflowsCmdDefinition, load: () => require('./commands/workflows.js').workflowsCmd(wrap) });
|
|
26
|
+
|
|
27
|
+
export const midserversCmdDefinition = {
|
|
28
|
+
command: 'midservers [subcommand]',
|
|
29
|
+
aliases: ['midserver', 'mid'],
|
|
30
|
+
describe: 'Manage ServiceNow MID Servers and run commands through them',
|
|
31
|
+
};
|
|
32
|
+
declareCapabilities('midservers', { mutationContext: 'operational', mutationSubcommands: ['add', 'remove', 'execute', 'start', 'stop', 'validate'] });
|
|
33
|
+
export const midserversCmd = wrap => ({ ...midserversCmdDefinition, load: () => require('./commands/midservers.js').midserversCmd(wrap) });
|
|
34
|
+
|
|
35
|
+
export const subscriptionsCmdDefinition = {
|
|
36
|
+
command: 'subscriptions [subcommand]', describe: 'Inspect local metering schedules and compare illustrative ITOM populations',
|
|
37
|
+
};
|
|
38
|
+
declareCapabilities('subscriptions', { noInstance: true, skipDailyChecks: true, mutationSubcommands: [] });
|
|
39
|
+
export const subscriptionsCmd = wrap => ({ ...subscriptionsCmdDefinition, load: () => require('./commands/subscriptions.js').subscriptionsCmd(wrap) });
|
|
40
|
+
|
|
41
|
+
export const customizationsCmdDefinition = {
|
|
42
|
+
command: 'customizations [subcommand]',
|
|
43
|
+
describe: 'Capture and compare read-only customization evidence locally',
|
|
44
|
+
};
|
|
45
|
+
declareCapabilities('customizations', { noInstance: true, skipDailyChecks: true, mutationSubcommands: [] });
|
|
46
|
+
export const customizationsCmd = wrap => ({ ...customizationsCmdDefinition, load: () => require('./commands/customizations.js').customizationsCmd(wrap) });
|
|
47
|
+
|
|
48
|
+
export const skippedUpdatesCmdDefinition = {
|
|
49
|
+
command: 'skipped-updates', describe: 'Review and process existing unresolved skipped updates across all upgrade history',
|
|
50
|
+
};
|
|
51
|
+
declareCapabilities('skipped-updates', { mutationSubcommands: ['process'] });
|
|
52
|
+
export const skippedUpdatesCmd = wrap => ({ ...skippedUpdatesCmdDefinition, load: () => require('./commands/skipped-updates.js').skippedUpdatesCmd(wrap) });
|
|
53
|
+
|
|
54
|
+
export const docsCmdDefinition = {
|
|
55
|
+
command: 'docs [query..]',
|
|
56
|
+
defaultPositionals: true,
|
|
57
|
+
describe: 'Search ServiceNow documentation (hosted by default; configure your service in setup)',
|
|
58
|
+
};
|
|
59
|
+
declareCapabilities('docs', { noInstance: true, skipDailyChecks: true });
|
|
60
|
+
export const docsCmd = wrap => ({ ...docsCmdDefinition, load: () => require('./commands/docs/docs.js').docsCmd(wrap) });
|
|
61
|
+
|
|
62
|
+
export const perfCmdDefinition = {
|
|
63
|
+
command: 'perf [subcommand]',
|
|
64
|
+
aliases: ['performance'],
|
|
65
|
+
describe: 'Capture and compare read-only ServiceNow performance summaries',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const perfCmd = wrap => ({ ...perfCmdDefinition, load: () => require('./commands/perf.js').perfCmd(wrap) });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { customizationsCmdDefinition } from '../command-families.js';
|
|
2
2
|
import { errUsageHint, errUsage } from '../errors.js';
|
|
3
3
|
import { canUsePicker } from '../helpers.js';
|
|
4
4
|
import { paginatedSearch } from '../paginated-search.js';
|
|
@@ -7,7 +7,7 @@ import { buildActionableReport, writeCustomizationHtml } from '../customizations
|
|
|
7
7
|
import { customizationGuidance, formatCustomizationGuidance } from '../customization-guidance.js';
|
|
8
8
|
|
|
9
9
|
// Only capture needs an instance. Saved reports never need network access.
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
const listHint = { action: 'list', cmd: 'jsn customizations list', description: 'Browse saved customization captures' };
|
|
12
12
|
const showHint = id => ({ action: 'show', cmd: `jsn customizations show ${id}`, description: 'Review this saved capture' });
|
|
13
13
|
const compareHint = id => ({ action: 'compare', cmd: `jsn customizations compare ${id} OTHER_RUN_ID`, description: 'Compare captured metadata and evidence' });
|
|
@@ -30,8 +30,7 @@ function show(app, report, options = {}) {
|
|
|
30
30
|
}
|
|
31
31
|
export function customizationsCmd(wrap) {
|
|
32
32
|
return {
|
|
33
|
-
|
|
34
|
-
describe: 'Capture and compare read-only customization evidence locally',
|
|
33
|
+
...customizationsCmdDefinition,
|
|
35
34
|
builder: y => y
|
|
36
35
|
.command({ command: 'capture', describe: 'Capture bounded read-only metadata and historical upgrade evidence',
|
|
37
36
|
builder: b => b.option('label', { type: 'string', describe: 'Label for this capture' })
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { docsCmdDefinition } from '../../command-families.js';
|
|
1
2
|
// Documentation search always uses the same API, hosted or self-hosted.
|
|
2
3
|
import { searchHostedDocs, getHostedDoc, getHostedDocsStatus, configuredDocsService } from './client.js';
|
|
3
4
|
import { documentationService } from './local.js';
|
|
4
5
|
|
|
5
|
-
import { declareCapabilities } from '../../capabilities.js';
|
|
6
6
|
import { docLink } from '../../docs-links.js';
|
|
7
7
|
import { AppError } from '../../errors.js';
|
|
8
8
|
import { resolveDocsRelease } from './db.js';
|
|
9
9
|
import { listDocsReleases } from './releases.js';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
|
|
13
13
|
function presented(data, text) {
|
|
14
14
|
return Object.defineProperty(data, '_formatted', { value: text, enumerable: false });
|
|
@@ -58,9 +58,7 @@ export function docsCmd(wrapHandler) {
|
|
|
58
58
|
return handler(argv, app);
|
|
59
59
|
});
|
|
60
60
|
return {
|
|
61
|
-
|
|
62
|
-
defaultPositionals: true,
|
|
63
|
-
describe: 'Search ServiceNow documentation (hosted by default; configure your service in setup)',
|
|
61
|
+
...docsCmdDefinition,
|
|
64
62
|
builder: y => y
|
|
65
63
|
.usage('Usage: jsn docs "search terms" [options]')
|
|
66
64
|
.epilogue(`Documentation for this command: ${docLink('docs')}`)
|
package/src/commands/flows.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { flowsCmdDefinition } from '../command-families.js';
|
|
1
2
|
import { searchFlows, formatFlowSearch } from '../flow-search.js';
|
|
2
3
|
import fs from 'node:fs';
|
|
3
4
|
import { prepareFlowClone, cloneFlow } from '../flow-clone.js';
|
|
4
5
|
import { canUsePicker } from '../helpers.js';
|
|
5
6
|
import { formatRecordForDisplay, formatCommandList, getStringField, interactiveList } from '../helpers.js';
|
|
6
7
|
import { discoverFlowContextFields, normalizeFlowContext, summarizeFlowContexts, formatFlowContextSummary, aggregateFlowContextMappings, mergeFlowContextStats, buildFlowContextQuery } from '../flow-context.js';
|
|
7
|
-
import { declareCapabilities } from '../capabilities.js';
|
|
8
8
|
import { docLink } from '../docs-links.js';
|
|
9
9
|
import { inspectFlow } from '../flow-inspection.js';
|
|
10
10
|
import { publishFlows, publishFlowLifecycle, publishDoctor, flowStatus } from '../flow-publish.js';
|
|
@@ -75,7 +75,7 @@ function triggerGuidance(trigger) {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
|
|
80
80
|
function renderChecks(checks) {
|
|
81
81
|
return checks.map((c) => {
|
|
@@ -88,9 +88,7 @@ export function flowsCmd(wrap) {
|
|
|
88
88
|
const originalWrap = wrap;
|
|
89
89
|
wrap = handler => originalWrap((argv, app) => cancelled(() => handler(argv, app)));
|
|
90
90
|
return {
|
|
91
|
-
|
|
92
|
-
aliases: ['flow'],
|
|
93
|
-
describe: 'Manage Flow Designer flows',
|
|
91
|
+
...flowsCmdDefinition,
|
|
94
92
|
builder: (yargs) => {
|
|
95
93
|
return yargs
|
|
96
94
|
.command({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { midserversCmdDefinition } from '../command-families.js';
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import process from 'node:process';
|
|
@@ -9,7 +10,6 @@ import { prepareWindowsRemoteMidServer, installWindowsRemoteMidServer, startWind
|
|
|
9
10
|
import { prepareLinuxRemoteMidServer, installLinuxRemoteMidServer, startLinuxRemoteMidServer, stopLinuxRemoteMidServer, logsLinuxRemoteMidServer, removeLinuxRemoteMidServer } from '../midserver-linux-remote.js';
|
|
10
11
|
import { downloadRemoteMidRecipe } from '../midserver-remote-recipe.js';
|
|
11
12
|
import { FormatAuto } from '../output.js';
|
|
12
|
-
import { declareCapabilities } from '../capabilities.js';
|
|
13
13
|
import { resolveRecord, unwrapSysId } from '../resolve-record.js';
|
|
14
14
|
import { detectDocker, defaultRun, installDockerMidServer, midInstallDirectory, normalizeMidName, validateMidCredentials } from '../midserver-install.js';
|
|
15
15
|
import { detectDirectPlatform, followDirectLog, installDirectMidServer, readDirectInstallation, removeDirectInstallation, resolveDirectLogFile, runDirectInstallation } from '../midserver-direct.js';
|
|
@@ -20,7 +20,7 @@ const LIST_FIELDS = ['sys_id', 'name', 'status', 'host_name', 'ip_address', 'ver
|
|
|
20
20
|
const DEFAULT_TIMEOUT = 120000;
|
|
21
21
|
const DEFAULT_INTERVAL = 2000;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
|
|
25
25
|
function agentName(record) {
|
|
26
26
|
const name = getStringField(record, 'name');
|
|
@@ -417,9 +417,7 @@ async function showMidServerLogs(app, identifier, argv) {
|
|
|
417
417
|
|
|
418
418
|
export function midserversCmd(wrap) {
|
|
419
419
|
return {
|
|
420
|
-
|
|
421
|
-
aliases: ['midserver', 'mid'],
|
|
422
|
-
describe: 'Manage ServiceNow MID Servers and run commands through them',
|
|
420
|
+
...midserversCmdDefinition,
|
|
423
421
|
builder: (y) => y
|
|
424
422
|
.command(midDiagnosticsCommand('issues', wrap))
|
|
425
423
|
.command(midDiagnosticsCommand('events', wrap))
|
package/src/commands/perf.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { perfCmdDefinition } from '../command-families.js';
|
|
1
2
|
import { errUsageHint, errUsage } from '../errors.js';
|
|
2
3
|
import { captureRun, listRuns, getRun, compareRuns, formatRunDetailed, formatRunList, formatComparisonDetailed } from '../perf.js';
|
|
3
4
|
import { topTransactionsCmd } from './transactions.js';
|
|
@@ -54,9 +55,7 @@ function compareHint(runId) {
|
|
|
54
55
|
|
|
55
56
|
export function perfCmd(wrap) {
|
|
56
57
|
return {
|
|
57
|
-
|
|
58
|
-
aliases: ['performance'],
|
|
59
|
-
describe: 'Capture and compare read-only ServiceNow performance summaries',
|
|
58
|
+
...perfCmdDefinition,
|
|
60
59
|
builder: (y) => y
|
|
61
60
|
.command({
|
|
62
61
|
command: 'capture',
|
package/src/commands/records.js
CHANGED
|
@@ -151,7 +151,8 @@ export function recordsCmd(wrap) {
|
|
|
151
151
|
// Text/table fallback (or sys-id direct lookup)
|
|
152
152
|
const fields = resolveFieldsParam(columns);
|
|
153
153
|
const params = recordListParams({ limit: argv['sys-id'] ? 1 : argv.limit, offset: argv.offset, fields, query });
|
|
154
|
-
const
|
|
154
|
+
const responseMetadata = {};
|
|
155
|
+
const records = await listRecords(app.sdk, { table, params, displayValues: argv.displayValues, responseMetadata });
|
|
155
156
|
const missingColumns = fields ? findOmittedColumns(records, columns) : [];
|
|
156
157
|
const presentColumns = missingColumns.length ? columns.filter(c => !missingColumns.includes(c)) : columns;
|
|
157
158
|
const displayRecords = fields && !argv.displayValues ? records.map(r => formatRecordForDisplay(r, presentColumns)) : records;
|
|
@@ -162,7 +163,10 @@ export function recordsCmd(wrap) {
|
|
|
162
163
|
const countsOn = argv.count !== false && profile.include_counts !== false;
|
|
163
164
|
let total;
|
|
164
165
|
if (countsOn && !argv['sys-id']) {
|
|
165
|
-
|
|
166
|
+
total = responseMetadata.total;
|
|
167
|
+
if (total === undefined) {
|
|
168
|
+
try { total = await app.sdk.aggregateCount(table, query); } catch { total = undefined; }
|
|
169
|
+
}
|
|
166
170
|
}
|
|
167
171
|
|
|
168
172
|
const breadcrumbs = [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { skippedUpdatesCmdDefinition } from '../command-families.js';
|
|
1
2
|
import { checkbox, select, confirm } from '../prompts.js';
|
|
2
3
|
import { canUsePicker, interactiveList, getStringField } from '../helpers.js';
|
|
3
|
-
import { declareCapabilities } from '../capabilities.js';
|
|
4
4
|
import { errUsage } from '../errors.js';
|
|
5
5
|
import { discoverSkippedUpdates, reviewSkippedUpdate, prepareSkippedBatch, processSkippedBatch, raw, SKIP_TABLE } from '../skipped-updates.js';
|
|
6
6
|
|
|
@@ -27,7 +27,6 @@ export function renderSkippedPreview(preview) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function skippedUpdatesCmd(wrap, ui = {}) {
|
|
30
|
-
declareCapabilities('skipped-updates', { mutationSubcommands: ['process'] });
|
|
31
30
|
const prompts = { checkbox, select, confirm, canUsePicker, interactiveList, ...ui };
|
|
32
31
|
async function showReview(app, id) {
|
|
33
32
|
const review = await reviewSkippedUpdate(app.sdk, id);
|
|
@@ -49,7 +48,7 @@ export function skippedUpdatesCmd(wrap, ui = {}) {
|
|
|
49
48
|
{ name: 'Return to base system, discard customization', value: 'revert' }] });
|
|
50
49
|
return { ids, action, instance: app.getEffectiveInstance() };
|
|
51
50
|
}
|
|
52
|
-
return {
|
|
51
|
+
return { ...skippedUpdatesCmdDefinition,
|
|
53
52
|
builder: y => y
|
|
54
53
|
.command({ command: 'list', describe: 'Discover unresolved skips instance-wide, independent of new upgrades',
|
|
55
54
|
builder: y => y.option('limit', { type: 'number', default: 100, describe: 'Page size, maximum 500' })
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { subscriptionsCmdDefinition } from '../command-families.js';
|
|
1
2
|
import { refreshSchedules } from '../schedule-cache.js';
|
|
2
|
-
import { declareCapabilities } from '../capabilities.js';
|
|
3
3
|
import { loadSchedule, scheduleCatalog, scheduleSnapshot, formatSchedule, estimateSubscription, formatEstimate } from '../subscriptions.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
export function subscriptionsCmd(wrap) {
|
|
7
7
|
const local = (argv, app) => {
|
|
8
8
|
const snapshot = scheduleSnapshot();
|
|
@@ -21,7 +21,7 @@ export function subscriptionsCmd(wrap) {
|
|
|
21
21
|
app.ok(data, { summary: 'Local dated metering schedules, not purchased rights' });
|
|
22
22
|
};
|
|
23
23
|
return {
|
|
24
|
-
|
|
24
|
+
...subscriptionsCmdDefinition,
|
|
25
25
|
builder: y => y.command({ command: 'refresh', describe: 'Explicitly download and validate schedule catalog; retain last-good on failure', builder: b => b.option('manifest-url', { type: 'string' }), handler: wrap(async (argv, app) => {
|
|
26
26
|
const origin = process.env.JSN_DOCS_URL || app.config?.docs?.url;
|
|
27
27
|
const manifest = argv.manifestUrl || process.env.JSN_SCHEDULES_MANIFEST_URL || app.config?.docs?.schedule_manifest_url || (origin ? new URL('/subscription-schedules/v1/manifest.json', origin).href : undefined);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { workflowsCmdDefinition } from '../command-families.js';
|
|
2
2
|
import { errUsage } from '../errors.js';
|
|
3
3
|
import {
|
|
4
4
|
inspectWorkflow,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
// request in workflow-inspection.js is a Table API GET. Declaring no mutation
|
|
12
12
|
// subcommands keeps the mutation guard and read-only profiles aligned with
|
|
13
13
|
// what the command can actually do.
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
|
|
16
16
|
// A curated human view belongs to the command; keeping it non-enumerable
|
|
17
17
|
// leaves the JSON envelope free of presentation text.
|
|
@@ -42,9 +42,7 @@ export function selectWorkflowStep(data, number) {
|
|
|
42
42
|
|
|
43
43
|
export function workflowsCmd(wrap) {
|
|
44
44
|
return {
|
|
45
|
-
|
|
46
|
-
aliases: ['workflow'],
|
|
47
|
-
describe: 'Inspect legacy Workflow Editor workflows (read-only)',
|
|
45
|
+
...workflowsCmdDefinition,
|
|
48
46
|
builder: (yargs) => yargs
|
|
49
47
|
.command({
|
|
50
48
|
command: 'list',
|
package/src/records/inspect.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { isHexString, getStringField, assertSafeExactMatch } from '../helpers.js';
|
|
2
2
|
import { discoverFlowContextFields, normalizeFlowContext } from '../flow-context.js';
|
|
3
|
+
import { tableReadParams } from '../table-read-params.js';
|
|
4
|
+
import { boundedReads } from '../bounded-reads.js';
|
|
3
5
|
|
|
4
6
|
export async function resolveIdentifier(app, table, identifier) {
|
|
5
7
|
// If it looks like a sys_id (32 hex chars), use it directly
|
|
@@ -86,24 +88,36 @@ async function resolveHistoryDisplayValues(app, table, history) {
|
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
//
|
|
91
|
+
// Preserve each exact field/value query and its one-row limit. Batching
|
|
92
|
+
// changes HTTP envelopes, not the number or authorization of server reads.
|
|
90
93
|
const choiceLabelMap = new Map();
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
94
|
+
const lookups = [...choiceLookups].map(key => {
|
|
95
|
+
const [field, val] = key.split('|');
|
|
96
|
+
return { key, params: new URLSearchParams({
|
|
97
|
+
sysparm_query: `name=${table}^element=${field}^value=${val}^language=en`,
|
|
98
|
+
sysparm_limit: '1', sysparm_fields: 'value,label', sysparm_display_value: 'all',
|
|
99
|
+
}) };
|
|
100
|
+
});
|
|
101
|
+
let choicesByLookup;
|
|
102
|
+
if (lookups.length > 1 && typeof app.sdk.batch === 'function') {
|
|
103
|
+
try {
|
|
104
|
+
const batch = await app.sdk.batch(lookups.map(({ params }, index) => ({
|
|
105
|
+
id: String(index), url: `/api/now/table/sys_choice?${tableReadParams(params, app.sdk)}`,
|
|
106
|
+
})));
|
|
107
|
+
choicesByLookup = batch.results.map(item => item.ok && Array.isArray(item.data?.result) ? item.data.result : []);
|
|
108
|
+
} catch {
|
|
109
|
+
// Existing policy: labels are optional. Never retry an ACL denial,
|
|
110
|
+
// malformed response or uncertain batch failure as individual reads.
|
|
111
|
+
choicesByLookup = lookups.map(() => []);
|
|
106
112
|
}
|
|
113
|
+
} else {
|
|
114
|
+
choicesByLookup = await boundedReads(lookups, async ({ params }) => {
|
|
115
|
+
try { return await app.sdk.list('sys_choice', params); } catch { return []; }
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
for (const [index, choices] of choicesByLookup.entries()) {
|
|
119
|
+
const label = choices[0]?.label?.display_value || choices[0]?.label;
|
|
120
|
+
if (label) choiceLabelMap.set(lookups[index].key, label);
|
|
107
121
|
}
|
|
108
122
|
|
|
109
123
|
// Apply resolutions to history entries
|
package/src/records-engine.js
CHANGED
|
@@ -20,10 +20,10 @@ export function recordListParams({ limit, offset, query, fields, displayValue: r
|
|
|
20
20
|
return params;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export function listRecords(sdk, { table, params, displayValues, ...options }) {
|
|
23
|
+
export function listRecords(sdk, { table, params, displayValues, responseMetadata, ...options }) {
|
|
24
24
|
const query = tableReadParams(params || recordListParams(options), sdk);
|
|
25
25
|
if (displayValues !== undefined) query.set('sysparm_display_value', displayValue(displayValues));
|
|
26
|
-
return sdk.list(table, query);
|
|
26
|
+
return responseMetadata ? sdk.list(table, query, { responseMetadata }) : sdk.list(table, query);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function getRecord(sdk, options) {
|
package/src/sdk-batch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Optional, read-only ServiceNow Batch REST transport. No ordinary SDK call is
|
|
2
2
|
// routed here implicitly; writes are deliberately outside this initial contract.
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { boundedReads } from './bounded-reads.js';
|
|
4
5
|
import { AppError, errAPI, errUsage } from './errors.js';
|
|
5
6
|
|
|
6
7
|
const UNSUPPORTED = new Set([404, 405, 501]);
|
|
@@ -121,7 +122,7 @@ export async function batchRead(sdk, requests, { fallback = true, chunkSize = 50
|
|
|
121
122
|
}
|
|
122
123
|
if (useIndividual) {
|
|
123
124
|
transports.add('individual');
|
|
124
|
-
|
|
125
|
+
results.push(...await boundedReads(chunk, request => individual(sdk, request, timeout)));
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
const successful = results.filter(item => item.ok).length;
|
package/src/sdk.js
CHANGED
|
@@ -334,7 +334,7 @@ export class SDKClient {
|
|
|
334
334
|
async request(endpoint, opts = {}) {
|
|
335
335
|
// Some provider mutations are GET-shaped. Keep this local replay policy
|
|
336
336
|
// out of fetch options rather than treating their HTTP method as read-only.
|
|
337
|
-
const { timeout = this.timeout, readOnly = false, stateful = false, touchLastSeen, domain = this.domain, ...requestOptions } = opts;
|
|
337
|
+
const { timeout = this.timeout, readOnly = false, stateful = false, touchLastSeen, domain = this.domain, responseMetadata, ...requestOptions } = opts;
|
|
338
338
|
if (readOnly && (requestOptions.method || 'GET').toUpperCase() !== 'GET') throw new Error('Read-only SDK requests require GET');
|
|
339
339
|
return this._withAuthenticatedRequest(endpoint, requestOptions, {
|
|
340
340
|
timeout,
|
|
@@ -350,6 +350,13 @@ export class SDKClient {
|
|
|
350
350
|
}, async (resp) => {
|
|
351
351
|
const body = await resp.text();
|
|
352
352
|
if (!resp.ok) throw errAPI(resp.status, body || resp.statusText);
|
|
353
|
+
if (responseMetadata) {
|
|
354
|
+
// Invocation-local receipt, never a cache: only accept a complete safe
|
|
355
|
+
// integer from this exact successful response (not an empty header).
|
|
356
|
+
const count = resp.headers.get('X-Total-Count');
|
|
357
|
+
responseMetadata.total = count !== null && /^\d+$/.test(count) && Number.isSafeInteger(Number(count))
|
|
358
|
+
? Number(count) : undefined;
|
|
359
|
+
}
|
|
353
360
|
if (resp.status === 204 || body === '') return null;
|
|
354
361
|
|
|
355
362
|
// Preserve read-only credential-write suppression and the existing empty-body behavior.
|
package/src/setup-preferences.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as prompts from './prompts.js';
|
|
2
2
|
const { confirm, select, input } = prompts;
|
|
3
|
-
import { ensureLocalDocumentation } from './commands/docs/local.js';
|
|
4
3
|
import { saveConfig } from './config.js';
|
|
5
|
-
import { docsServiceUrl, DEFAULT_DOCS_URL } from './commands/docs/client.js';
|
|
6
4
|
|
|
7
5
|
export function connectionPreferences(config, existing = {}, flags = {}) {
|
|
8
6
|
const saved = { read_only: false, skip_confirmations: false, include_counts: true };
|
|
@@ -32,11 +30,13 @@ export async function chooseConnectionPreferences(config, flags = {}, prompts =
|
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
export async function configureDocumentation(config, prompts = { input, confirm }) {
|
|
33
|
+
const { docsServiceUrl, DEFAULT_DOCS_URL } = await import('./commands/docs/client.js');
|
|
35
34
|
const current = config.docs || { source: 'hosted', url: DEFAULT_DOCS_URL };
|
|
36
35
|
const hosted = await prompts.confirm({ message: 'Use JSN-hosted documentation?', default: current.source === 'hosted' });
|
|
37
36
|
const next = { source: hosted ? 'hosted' : 'custom', url: DEFAULT_DOCS_URL };
|
|
38
37
|
if (!hosted && await prompts.confirm({ message: 'Run a local documentation server for you?', default: current.source !== 'custom' })) {
|
|
39
38
|
next.source = 'local';
|
|
39
|
+
const { ensureLocalDocumentation } = await import('./commands/docs/local.js');
|
|
40
40
|
next.url = (await ensureLocalDocumentation()).url;
|
|
41
41
|
} else if (!hosted) {
|
|
42
42
|
next.url = await prompts.input({ message: 'Docs service base URL:', default: current.source === 'custom' ? current.url : 'http://127.0.0.1:3000',
|