@jacebenson/jsn 5.5.7-dev.216.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/skills/servicenow/SKILL.md +9 -1
- package/src/app.js +4 -79
- package/src/bounded-reads.js +13 -0
- package/src/capabilities.js +8 -3
- package/src/cli-adapter.js +8 -2
- package/src/cli.js +8 -15
- package/src/command-families.js +68 -0
- package/src/commands/_generic.js +1 -0
- package/src/commands/_ticket.js +1 -1
- package/src/commands/actions.js +9 -4
- package/src/commands/approvals.js +1 -1
- package/src/commands/atf.js +1 -1
- package/src/commands/attachments.js +1 -1
- package/src/commands/auth.js +21 -2
- package/src/commands/customizations.js +3 -4
- package/src/commands/decisiontables.js +4 -0
- package/src/commands/docs/docs.js +3 -5
- package/src/commands/domains.js +1 -1
- package/src/commands/eval.js +11 -5
- package/src/commands/flows.js +17 -5
- package/src/commands/groupmembers.js +1 -1
- package/src/commands/grouproles.js +1 -1
- package/src/commands/groups.js +1 -1
- package/src/commands/midservers.js +3 -5
- package/src/commands/perf.js +2 -3
- package/src/commands/records.js +12 -2
- package/src/commands/scopes.js +1 -1
- package/src/commands/scrapi.js +2 -2
- package/src/commands/skipped-updates.js +2 -3
- package/src/commands/subscriptions.js +3 -3
- package/src/commands/tickets.js +1 -1
- package/src/commands/users.js +1 -1
- package/src/commands/workflows.js +3 -5
- package/src/config.js +1 -0
- package/src/context.js +8 -56
- package/src/flow-create.js +9 -0
- package/src/intended-context.js +68 -0
- package/src/mutation-context.js +69 -46
- package/src/output.js +1 -1
- 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 +19 -1
- package/src/setup-preferences.js +2 -2
package/package.json
CHANGED
|
@@ -22,7 +22,15 @@ Discover commands with `jsn --help`, `jsn discover "search words"`, and
|
|
|
22
22
|
For development:
|
|
23
23
|
|
|
24
24
|
1. Choose or create the application scope and update set.
|
|
25
|
-
2.
|
|
25
|
+
2. Supply task-owned `--expect-scope <scope/name/id>` and
|
|
26
|
+
`--expect-update-set <name/id>` on customization writes, or explicitly save
|
|
27
|
+
profile-and-instance-bound `write_context` in local `.servicenow/config.json`.
|
|
28
|
+
Never derive intended values from current preferences. `--force` cannot bypass
|
|
29
|
+
missing intent, unknown context or mismatches. Domain-scoped customization
|
|
30
|
+
currently refuses, including `--expect-domain`, because `X-Now-Domain` does not
|
|
31
|
+
prove effective domain. Inspect with `auth status --context`; `--local` is offline.
|
|
32
|
+
Reads never print or fetch automatic context. Ordinary ticket/data edits do not
|
|
33
|
+
need customization expectations. Keep related development changes together.
|
|
26
34
|
3. Verify the results on the instance and report where changes were captured.
|
|
27
35
|
4. Offer to run relevant existing ATFs and instance scans, or create missing checks.
|
|
28
36
|
5. Ask whether anything else belongs in the update set. If the user confirms
|
package/src/app.js
CHANGED
|
@@ -10,14 +10,12 @@
|
|
|
10
10
|
import { AuthManager } from './auth.js';
|
|
11
11
|
import { createAuthRecovery } from './auth-recovery.js';
|
|
12
12
|
import { SDKClient } from './sdk.js';
|
|
13
|
-
import { OutputWriter, FormatAuto, FormatJSON, FormatMarkdown, FormatQuiet, FormatStyled
|
|
13
|
+
import { OutputWriter, FormatAuto, FormatJSON, FormatMarkdown, FormatQuiet, FormatStyled } from './output.js';
|
|
14
14
|
import { saveConfig, isTrustedCredentialDestination } from './config.js';
|
|
15
15
|
import { resolveSession, applySession, contextFromSession, requireSessionInstance } from './session.js';
|
|
16
|
-
import { getCurrentUser, getCurrentApplication, getCurrentUpdateSet } from './context.js';
|
|
17
16
|
import { errUsage, errAuth } from './errors.js';
|
|
18
17
|
import { canPrompt, canUsePicker } from './helpers.js';
|
|
19
18
|
import { guardMutationContext } from './mutation-context.js';
|
|
20
|
-
import process from 'node:process';
|
|
21
19
|
|
|
22
20
|
|
|
23
21
|
export class App {
|
|
@@ -86,85 +84,12 @@ export class App {
|
|
|
86
84
|
return this.session?.instance || '';
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (process.env.JSN_NO_HEADER) return;
|
|
92
|
-
if (this.output.getFormat() === FormatJSON || this.output.getFormat() === FormatQuiet) return;
|
|
93
|
-
|
|
94
|
-
// The banner is a terminal affordance, never data. `--get`/`--select`
|
|
95
|
-
// prints an extracted JSON value while the format still reports pretty, so
|
|
96
|
-
// a banner on stderr merged with `2>&1` landed in front of the JSON and
|
|
97
|
-
// broke `jsn ... 2>&1 | jq` / `json.load(sys.stdin)` at character 0. Skip
|
|
98
|
-
// it whenever an extraction was requested or stderr is not a terminal
|
|
99
|
-
// (nobody reads it there, and it costs five HTTP requests per command:
|
|
100
|
-
// user, application preference, update-set preference, scope, update set).
|
|
101
|
-
if (argv.get !== undefined && argv.get !== null && argv.get !== false) return;
|
|
102
|
-
if (process.stderr.isTTY !== true) return;
|
|
103
|
-
|
|
104
|
-
let userDisplayName = 'Unknown';
|
|
105
|
-
let userSysID = '';
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
const user = await getCurrentUser(this.sdk);
|
|
109
|
-
if (user) {
|
|
110
|
-
userDisplayName = user.name || user.user_name;
|
|
111
|
-
userSysID = user.sys_id;
|
|
112
|
-
this.context.username = userDisplayName;
|
|
113
|
-
}
|
|
114
|
-
} catch {
|
|
115
|
-
// ignore
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
let displayUserName = userDisplayName;
|
|
119
|
-
if (displayUserName.length > 10) {
|
|
120
|
-
displayUserName = displayUserName.slice(0, 6) + '...';
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Both lookups depend on the user, but not on one another.
|
|
124
|
-
const [application, selectedUpdateSet] = userSysID ? await Promise.all([
|
|
125
|
-
getCurrentApplication(this.sdk, userSysID, { unknownWhenMissing: true }).catch(() => null),
|
|
126
|
-
getCurrentUpdateSet(this.sdk, userSysID).catch(() => null),
|
|
127
|
-
]) : [null, null];
|
|
128
|
-
const scope = application?.scope || 'unknown';
|
|
129
|
-
const updateSet = selectedUpdateSet?.name && selectedUpdateSet.name !== '-'
|
|
130
|
-
? selectedUpdateSet.name : 'unknown';
|
|
131
|
-
const updateSetSysID = selectedUpdateSet?.name && selectedUpdateSet.name !== '-'
|
|
132
|
-
? selectedUpdateSet.sys_id : '';
|
|
133
|
-
this.context.scope = scope;
|
|
134
|
-
this.context.updateSet = updateSet;
|
|
135
|
-
|
|
136
|
-
const instance = this.getEffectiveInstance();
|
|
137
|
-
const instanceLink = instance;
|
|
138
|
-
const userLink = `${instance}/sys_user_list.do?sysparm_query=sys_id=${userSysID}`;
|
|
139
|
-
const scopeLink = `${instance}/sys_scope.do?sysparm_query=scope=${scope}`;
|
|
140
|
-
const updateSetLink = updateSetSysID
|
|
141
|
-
? `${instance}/sys_update_set.do?sys_id=${updateSetSysID}`
|
|
142
|
-
: `${instance}/sys_update_set_list.do`;
|
|
143
|
-
|
|
144
|
-
const scopeFormatted = `[${scope}]`;
|
|
145
|
-
|
|
146
|
-
// Terminal hyperlinks are invisible in a TTY and garbage in a pipe, so the
|
|
147
|
-
// banner only wraps values when stderr is actually a terminal.
|
|
148
|
-
const link = (text, url) => (process.stderr.isTTY === true ? hyperlink(text, url) : text);
|
|
149
|
-
|
|
150
|
-
// Read-only profiles get a lock badge on every command run, so the
|
|
151
|
-
// armed safety is always visible (not just in `auth status`).
|
|
152
|
-
const roBadge = this.session?.readOnly === true ? ' 🔒' : '';
|
|
153
|
-
|
|
154
|
-
process.stderr.write('# Use `jsn scopes` to change scope, `jsn updatesets set` to change updateset\n');
|
|
155
|
-
process.stderr.write('PROFILE USER [SCOPE] UPDATE SET\n');
|
|
156
|
-
|
|
157
|
-
const profileStr = `${link(String(this.context.profileName).padEnd(9), instanceLink)}${roBadge}`;
|
|
158
|
-
const userStr = link(String(displayUserName).padEnd(9), userLink);
|
|
159
|
-
const scopeStr = link(String(scopeFormatted).padEnd(17), scopeLink);
|
|
160
|
-
const updateSetStr = link(String(updateSet), updateSetLink);
|
|
161
|
-
|
|
162
|
-
process.stderr.write(`${profileStr} ${userStr} ${scopeStr} ${updateSetStr}\n\n`);
|
|
163
|
-
|
|
164
|
-
}
|
|
87
|
+
// Retained for SDK consumers. Automatic context banners are retired.
|
|
88
|
+
async printContextHeader() {}
|
|
165
89
|
|
|
166
90
|
async guardMutationContext(argv) {
|
|
167
91
|
this.mutationContext = await guardMutationContext(this, argv);
|
|
92
|
+
if (this.sdk) this.sdk.mutationContext = this.mutationContext;
|
|
168
93
|
}
|
|
169
94
|
|
|
170
95
|
ok(data, opts = {}) {
|
|
@@ -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
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
// // Subcommand verbs that mutate instance state. The mutation guard
|
|
9
9
|
// // (src/mutations.js) derives its command-path list from these.
|
|
10
10
|
// mutationSubcommands: ['create', 'update', 'delete'],
|
|
11
|
+
// // Omitted means conservative customization; operational skips capture
|
|
12
|
+
// // requirements, table follows sys_db_object ancestry to sys_metadata.
|
|
13
|
+
// mutationContext: 'table', table: 'sys_script',
|
|
14
|
+
// // Only declared flags are transaction overrides, not creation fields.
|
|
15
|
+
// transactionScopeOption: 'scope',
|
|
11
16
|
// // Command runs without a configured instance (joins the middleware
|
|
12
17
|
// // skip-list for the instance guard).
|
|
13
18
|
// noInstance: true,
|
|
@@ -31,9 +36,9 @@
|
|
|
31
36
|
// Note: yargs strips custom properties off command modules when it
|
|
32
37
|
// registers them (only original/description/handler/builder survive in
|
|
33
38
|
// getCommandHandlers()), so declarations live in this module-level map,
|
|
34
|
-
// keyed by root command name.
|
|
35
|
-
//
|
|
36
|
-
// 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.
|
|
37
42
|
|
|
38
43
|
const REGISTRY = new Map();
|
|
39
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,8 +12,7 @@ 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 {
|
|
15
|
-
import { isLocalPreview, noInstanceCommands, dailyCheckSkipCommands, skipsContextHeader } from './capabilities.js';
|
|
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';
|
|
18
18
|
|
|
@@ -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
|
|
|
@@ -158,6 +151,9 @@ export function buildCLI() {
|
|
|
158
151
|
.options({
|
|
159
152
|
'all-commands': { type: 'boolean', describe: 'Show the full command list, including admin and developer tools' },
|
|
160
153
|
|
|
154
|
+
'expect-scope': { type: 'string', description: 'Intended customization scope, exact scope/name or sys_id' },
|
|
155
|
+
'expect-update-set': { type: 'string', description: 'Intended in-progress capture set, exact name or sys_id' },
|
|
156
|
+
'expect-domain': { type: 'string', description: 'Intended domain; refuses writes when effective domain cannot be proven' },
|
|
161
157
|
force: {
|
|
162
158
|
type: 'boolean',
|
|
163
159
|
description: 'Approve Global + Default mutation context only after user approval; delete commands also use this for their separate confirmation',
|
|
@@ -354,10 +350,7 @@ export function buildCLI() {
|
|
|
354
350
|
}
|
|
355
351
|
}
|
|
356
352
|
|
|
357
|
-
//
|
|
358
|
-
if (!skipsContextHeader(argv)) {
|
|
359
|
-
await argv.app.printContextHeader(argv);
|
|
360
|
-
}
|
|
353
|
+
// Reads never probe or print runtime context. Writes use the guard result.
|
|
361
354
|
})
|
|
362
355
|
// CONFIGURATION
|
|
363
356
|
.command(setupCmd(wrap))
|
|
@@ -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) });
|
package/src/commands/_generic.js
CHANGED
|
@@ -99,6 +99,7 @@ export function buildDevCmd(name, table, aliases, defaultColumns, wrap, opts = {
|
|
|
99
99
|
const readOnly = opts.readOnly || false;
|
|
100
100
|
// Capability declaration: the readOnly flag drives the mutation registry.
|
|
101
101
|
declareCapabilities(name, {
|
|
102
|
+
mutationContext: 'table', table,
|
|
102
103
|
mutationSubcommands: readOnly ? [] : ['create', 'update', 'delete'],
|
|
103
104
|
});
|
|
104
105
|
const scopeValidation = opts.scopeValidation || false;
|
package/src/commands/_ticket.js
CHANGED
|
@@ -11,7 +11,7 @@ import { declareCapabilities } from '../capabilities.js';
|
|
|
11
11
|
export function buildTicketCommands(table, displayName, alias, defaultColumns, stateMap, iconFn, wrap, opts = {}) {
|
|
12
12
|
// Ticket-style CRUD: list/show are reads; create/update/delete mutate.
|
|
13
13
|
// Root-level command only.
|
|
14
|
-
declareCapabilities(displayName, { mutationSubcommands: ['create', 'update', 'delete'] });
|
|
14
|
+
declareCapabilities(displayName, { mutationContext: 'operational', mutationSubcommands: ['create', 'update', 'delete'] });
|
|
15
15
|
return {
|
|
16
16
|
command: `${displayName} [subcommand]`,
|
|
17
17
|
aliases: [table, alias],
|
package/src/commands/actions.js
CHANGED
|
@@ -4,6 +4,7 @@ import { resolveRecord, unwrapSysId } from '../resolve-record.js';
|
|
|
4
4
|
import { declareCapabilities } from '../capabilities.js';
|
|
5
5
|
import { ACTION_TABLE, actionScope } from '../processflow-actions.js';
|
|
6
6
|
import { errUsage } from '../errors.js';
|
|
7
|
+
import { assertMutationScope } from '../intended-context.js';
|
|
7
8
|
import { cancelled, pickDesignerRecord, designerScope, guidedActionCreate, guidedActionEdit, guidedActionTestInputs, interactiveDesigner, hasDefinitionData, confirmDesignerMutation } from '../flow-designer-interactive.js';
|
|
8
9
|
|
|
9
10
|
const ACTION_COMMANDS = [
|
|
@@ -87,7 +88,7 @@ export const actionsCmd = wrap => {
|
|
|
87
88
|
{ action: 'list', cmd: 'jsn actions list', description: 'Back to actions' },
|
|
88
89
|
],
|
|
89
90
|
});
|
|
90
|
-
declareCapabilities('actions', { mutationSubcommands: ['create', 'update', 'edit', 'delete', 'test'] });
|
|
91
|
+
declareCapabilities('actions', { transactionScopeOption: 'scope', mutationContextExemptSubcommands: ['test'], mutationSubcommands: ['create', 'update', 'edit', 'delete', 'test'] });
|
|
91
92
|
// Retain the common wrap and output controller; domain failures get a
|
|
92
93
|
// structured error envelope and nonzero exit, never a success-shaped dispatch.
|
|
93
94
|
const run = handler => wrap(async (argv, app) => {
|
|
@@ -110,6 +111,7 @@ export const actionsCmd = wrap => {
|
|
|
110
111
|
const guided = !hasDefinitionData(argv) ? await guidedActionCreate(argv, app) : undefined;
|
|
111
112
|
const definition = guided?.definition ?? parseDataArg(argv);
|
|
112
113
|
const scope = guided?.scope ?? await designerScope(argv, app);
|
|
114
|
+
assertMutationScope(app.mutationContext, scope, 'Action creation');
|
|
113
115
|
const result = await app.sdk.createProcessFlowAction(scope, definition);
|
|
114
116
|
app.ok(result, { summary: `Created and verified action ${result.sys_id}` });
|
|
115
117
|
}),
|
|
@@ -152,9 +154,11 @@ export const actionsCmd = wrap => {
|
|
|
152
154
|
if (!hasDefinitionData(argv) && !interactiveDesigner(argv, app)) throw errUsage('Provide --data-file or --data for the full action definition in noninteractive mode');
|
|
153
155
|
const id = await actionID(argv, app);
|
|
154
156
|
if (id === undefined) return;
|
|
157
|
+
const scope = await actionScope(app.sdk, id, app.mutationContext?.application_id ?? argv.scope);
|
|
158
|
+
assertMutationScope(app.mutationContext, scope, 'Action target');
|
|
155
159
|
const definition = hasDefinitionData(argv) ? parseDataArg(argv)
|
|
156
|
-
: await guidedActionEdit(argv, app, await app.sdk.getProcessFlowAction(id,
|
|
157
|
-
const result = await app.sdk.updateProcessFlowAction(id,
|
|
160
|
+
: await guidedActionEdit(argv, app, await app.sdk.getProcessFlowAction(id, scope));
|
|
161
|
+
const result = await app.sdk.updateProcessFlowAction(id, scope, definition);
|
|
158
162
|
app.ok(result, { summary: `Saved and verified action ${id}` });
|
|
159
163
|
}),
|
|
160
164
|
})
|
|
@@ -216,7 +220,8 @@ export const actionsCmd = wrap => {
|
|
|
216
220
|
handler: run(async (argv, app) => {
|
|
217
221
|
const id = await actionID(argv, app);
|
|
218
222
|
if (id === undefined) return;
|
|
219
|
-
await actionScope(app.sdk, id, argv.scope);
|
|
223
|
+
const scope = await actionScope(app.sdk, id, app.mutationContext?.application_id ?? argv.scope);
|
|
224
|
+
assertMutationScope(app.mutationContext, scope, 'Action target');
|
|
220
225
|
await confirmDesignerMutation(argv, app, `Delete action '${id}'`);
|
|
221
226
|
await app.sdk.delete(ACTION_TABLE, id);
|
|
222
227
|
// Verify the exact target is absent. Do not interpret a 403 as deletion.
|
|
@@ -25,7 +25,7 @@ import { errUsage, errNotFound } from '../errors.js';
|
|
|
25
25
|
import { declareCapabilities } from '../capabilities.js';
|
|
26
26
|
|
|
27
27
|
// approve/reject/submit change approval state on records.
|
|
28
|
-
declareCapabilities('approvals', { mutationSubcommands: ['approve', 'reject', 'submit'] });
|
|
28
|
+
declareCapabilities('approvals', { mutationContext: 'operational', mutationSubcommands: ['approve', 'reject', 'submit'] });
|
|
29
29
|
|
|
30
30
|
// Raw sysapproval_approver.state values (verified live).
|
|
31
31
|
const APPROVAL_STATES = [
|
package/src/commands/atf.js
CHANGED
|
@@ -27,7 +27,7 @@ import { errUsage, errNotFound } from '../errors.js';
|
|
|
27
27
|
import { declareCapabilities } from '../capabilities.js';
|
|
28
28
|
|
|
29
29
|
// run/run-suite schedule tests that act on records (top-level only).
|
|
30
|
-
declareCapabilities('atf', { mutationSubcommands: ['run', 'run-suite'] });
|
|
30
|
+
declareCapabilities('atf', { mutationContext: 'operational', mutationSubcommands: ['run', 'run-suite'] });
|
|
31
31
|
|
|
32
32
|
// sn_cicd progress statuses (now-sdk poller.ts)
|
|
33
33
|
const PROGRESS_PENDING = '0';
|
|
@@ -4,7 +4,7 @@ import { confirmDelete, getStringField } from '../helpers.js';
|
|
|
4
4
|
import { errUsage } from '../errors.js';
|
|
5
5
|
import { declareCapabilities } from '../capabilities.js';
|
|
6
6
|
|
|
7
|
-
declareCapabilities('attachments', { mutationSubcommands: ['upload', 'add'] });
|
|
7
|
+
declareCapabilities('attachments', { mutationContext: 'operational', mutationSubcommands: ['upload', 'add'] });
|
|
8
8
|
const identifier = value => {
|
|
9
9
|
if (typeof value !== 'string' || !/^[A-Za-z0-9_-]+$/.test(value)) throw errUsage('Supply a safe record or attachment sys_id.');
|
|
10
10
|
return value;
|
package/src/commands/auth.js
CHANGED
|
@@ -894,6 +894,8 @@ Examples:
|
|
|
894
894
|
}
|
|
895
895
|
|
|
896
896
|
export async function showAuthStatus(argv, app) {
|
|
897
|
+
if (argv.context && !argv.profile) argv = { ...argv, profile: app.session?.profileName || app.config.activeProfile || app.config.defaultProfile };
|
|
898
|
+
if (argv.context && !app.config.profiles?.[argv.profile]) throw errUsage('Select a configured profile for auth status --context.');
|
|
897
899
|
const configuredDefault = app.config.profiles?.[app.config.defaultProfile];
|
|
898
900
|
const defaultInstance = configuredDefault?.instance_url || app.config.instanceURL || '';
|
|
899
901
|
|
|
@@ -923,6 +925,7 @@ export async function showAuthStatus(argv, app) {
|
|
|
923
925
|
let verified = null;
|
|
924
926
|
let verifiedAt = null;
|
|
925
927
|
let probe;
|
|
928
|
+
let runtimeContext = argv.context ? { verified: false, status: 'not_attempted' } : undefined;
|
|
926
929
|
if (argv.local) {
|
|
927
930
|
probe = { status: 'not_attempted', code: 'not_requested', classification: 'not_checked' };
|
|
928
931
|
} else if (!instance) {
|
|
@@ -942,8 +945,17 @@ export async function showAuthStatus(argv, app) {
|
|
|
942
945
|
if (probe.status === 'succeeded' && user?.user_name) {
|
|
943
946
|
verified = true;
|
|
944
947
|
verifiedAt = user.user_name;
|
|
948
|
+
if (argv.context) {
|
|
949
|
+
try {
|
|
950
|
+
const { readWriteContext } = await import('../intended-context.js');
|
|
951
|
+
runtimeContext = { ...await readWriteContext(sdk), verified: true };
|
|
952
|
+
runtimeContext.domain.requested = profile.domain || null;
|
|
953
|
+
if (runtimeContext.user.user_name !== user.user_name) throw new Error('Context account mismatch');
|
|
954
|
+
} catch { runtimeContext = { verified: false, status: 'unavailable' }; }
|
|
955
|
+
}
|
|
945
956
|
if (profile.username && profile.username !== user.user_name) {
|
|
946
957
|
verified = false;
|
|
958
|
+
if (runtimeContext) runtimeContext = { verified: false, status: 'account_mismatch' };
|
|
947
959
|
probe = {
|
|
948
960
|
status: 'failed', code: 'account_mismatch', classification: 'account_mismatch',
|
|
949
961
|
message: 'The session account does not match the configured profile account.',
|
|
@@ -966,6 +978,7 @@ export async function showAuthStatus(argv, app) {
|
|
|
966
978
|
|
|
967
979
|
profiles.push({
|
|
968
980
|
name,
|
|
981
|
+
...(runtimeContext ? { context: runtimeContext } : {}),
|
|
969
982
|
instance,
|
|
970
983
|
username: profile.username || undefined,
|
|
971
984
|
active: name === (app.session?.profileName || app.config.activeProfile || app.config.defaultProfile),
|
|
@@ -1000,8 +1013,12 @@ export async function showAuthStatus(argv, app) {
|
|
|
1000
1013
|
const summary = `${profiles.length} ${profiles.length === 1 ? 'profile' : 'profiles'}`;
|
|
1001
1014
|
// Ship the styled view as _formatted (see renderAuthStatus); the
|
|
1002
1015
|
// OutputWriter prints it verbatim and suppresses the summary.
|
|
1003
|
-
result._formatted = renderAuthStatus(result, summary, { details: argv.details === true });
|
|
1004
|
-
if (
|
|
1016
|
+
result._formatted = renderAuthStatus(result, summary, { details: argv.details === true || argv.context === true });
|
|
1017
|
+
if (argv.context) result._formatted += profiles.map(p => {
|
|
1018
|
+
const c = p.context;
|
|
1019
|
+
return `\n${p.name}: ${c?.verified ? `user ${c.user.user_name}; scope ${c.scope}; update set ${c.update_set.name} (${c.update_set.sys_id}); domain unverified${c.domain.requested ? `, requested ${c.domain.requested}` : ''}` : `context ${c?.status || 'unavailable'}`}`;
|
|
1020
|
+
}).join('');
|
|
1021
|
+
if (!argv.details && !argv.context) {
|
|
1005
1022
|
delete result.default_instance;
|
|
1006
1023
|
result.profiles = profiles.map(({ instance: _instance, username: _username, verified_as: _verifiedAs, ...visible }) => visible);
|
|
1007
1024
|
}
|
|
@@ -1207,6 +1224,8 @@ export function authCmd(wrap) {
|
|
|
1207
1224
|
describe: 'Show authentication status (use --details for users and instance URLs)',
|
|
1208
1225
|
builder: sub => sub.option('local', {
|
|
1209
1226
|
type: 'boolean', describe: 'Show saved credential state without contacting any instance',
|
|
1227
|
+
}).option('context', {
|
|
1228
|
+
type: 'boolean', describe: 'Full context for selected/default profile, including live user, scope, capture set and domain verification limits; --local makes no requests',
|
|
1210
1229
|
}).option('details', {
|
|
1211
1230
|
type: 'boolean', describe: 'Include users and instance URLs in status output',
|
|
1212
1231
|
}),
|
|
@@ -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,4 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import { assertMutationScope } from '../intended-context.js';
|
|
2
3
|
import { getStringField, formatRecordForDisplay, interactiveList, assertSafeExactMatch, confirmDelete } from '../helpers.js';
|
|
3
4
|
import { resolveRecord, unwrapSysId, isSysId } from '../resolve-record.js';
|
|
4
5
|
import { inspectDecisionTable } from '../decision-table-inspection.js';
|
|
@@ -19,6 +20,7 @@ export const decisiontablesCmd = (wrap) => {
|
|
|
19
20
|
.option('data', { type: 'string', describe: 'Complete decision-table JSON payload' })
|
|
20
21
|
.option('data-file', { type: 'string', describe: 'Read complete decision-table JSON payload from a file' });
|
|
21
22
|
const resolveExecutionScope = async (app) => {
|
|
23
|
+
if (app.mutationContext?.verified) return app.mutationContext.application_id;
|
|
22
24
|
const scope = app.context?.scope;
|
|
23
25
|
if (!scope) return 'global';
|
|
24
26
|
const scopeSysId = await app.sdk.resolveScope(scope);
|
|
@@ -32,6 +34,7 @@ export const decisiontablesCmd = (wrap) => {
|
|
|
32
34
|
const records = await app.sdk.list('sys_decision', params);
|
|
33
35
|
if (records.length === 0) throw new Error(`Decision table not found in active scope: ${identifier}`);
|
|
34
36
|
if (records.length > 1) throw new Error(`Decision table ${field} is ambiguous in active scope: ${identifier}`);
|
|
37
|
+
assertMutationScope(app.mutationContext, records[0].sys_scope, 'Decision table target');
|
|
35
38
|
return records[0];
|
|
36
39
|
};
|
|
37
40
|
const resolveDecisionTableForUpdate = async (app, identifier, scopeSysId) => {
|
|
@@ -42,6 +45,7 @@ export const decisiontablesCmd = (wrap) => {
|
|
|
42
45
|
const records = await app.sdk.list('sys_decision', params);
|
|
43
46
|
if (records.length === 0) throw new Error(`Decision table not found${scopeSysId === 'global' ? '' : ' in active scope'}: ${identifier}`);
|
|
44
47
|
if (records.length > 1) throw new Error(`Decision table ${field} is ambiguous: ${identifier}`);
|
|
48
|
+
assertMutationScope(app.mutationContext, records[0].sys_scope, 'Decision table target');
|
|
45
49
|
const id = unwrapSysId(records[0]);
|
|
46
50
|
if (!isSysId(id)) throw new Error(`Decision table returned an invalid identifier: ${identifier}`);
|
|
47
51
|
return id;
|
|
@@ -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/domains.js
CHANGED
|
@@ -6,7 +6,7 @@ import { getStringField, interactiveList, assertSafeExactMatch } from '../helper
|
|
|
6
6
|
import { declareCapabilities } from '../capabilities.js';
|
|
7
7
|
|
|
8
8
|
// `domains set` writes the chosen domain into the profile config.
|
|
9
|
-
declareCapabilities('domains', { mutationSubcommands: ['set', 'session-set', 'session-reset'] });
|
|
9
|
+
declareCapabilities('domains', { mutationContext: 'operational', mutationSubcommands: ['set', 'session-set', 'session-reset'] });
|
|
10
10
|
|
|
11
11
|
const DETAIL_FIELDS = 'sys_id,name,parent,sys_domain_path,description,active,sys_created_on,sys_updated_on';
|
|
12
12
|
|