@jacebenson/jsn 5.5.7 → 5.5.8-dev.220.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/README.md +16 -1
- package/package.json +5 -6
- package/skills/servicenow/SKILL.md +9 -1
- package/src/app.js +4 -79
- package/src/auth/credential-store.js +33 -8
- package/src/auth/windows-credential-store.js +85 -0
- package/src/auth/windows-credential-store.ps1 +163 -0
- package/src/bounded-reads.js +13 -0
- package/src/capabilities.js +8 -3
- package/src/cli-adapter.js +26 -3
- package/src/cli.js +13 -14
- 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/codesearch.js +11 -2
- package/src/commands/compare.js +22 -0
- package/src/commands/customizations.js +3 -4
- package/src/commands/decisiontables.js +4 -0
- package/src/commands/docs/docs.js +5 -5
- package/src/commands/domains.js +1 -1
- package/src/commands/eval.js +11 -5
- package/src/commands/flows.js +24 -7
- 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 +4 -11
- package/src/commands/perf.js +2 -3
- package/src/commands/plugins.js +9 -0
- package/src/commands/records.js +12 -2
- package/src/commands/scopes.js +1 -1
- package/src/commands/scrapi.js +2 -2
- package/src/commands/setup.js +4 -34
- package/src/commands/skipped-updates.js +2 -3
- package/src/commands/store.js +4 -1
- package/src/commands/subscriptions.js +47 -0
- 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/docs-links.js +28 -0
- package/src/flow-create.js +9 -0
- package/src/help.js +4 -0
- package/src/helpers.js +17 -24
- package/src/instance-inventory.js +184 -0
- package/src/intended-context.js +68 -0
- package/src/mutation-context.js +69 -46
- package/src/output.js +1 -1
- package/src/paginated-search.js +146 -178
- package/src/picker-ui.js +20 -0
- package/src/prompt-engine.js +176 -0
- package/src/prompts.js +293 -43
- package/src/records/inspect.js +30 -16
- package/src/records-engine.js +2 -2
- package/src/schedule-cache.js +96 -0
- package/src/schedules/itom-2026-04-09.json +121 -0
- package/src/schedules/public-inventory.json +6224 -0
- package/src/sdk-batch.js +2 -1
- package/src/sdk.js +42 -16
- package/src/setup-preferences.js +2 -2
- package/src/subscriptions.js +176 -0
package/src/commands/flows.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
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 {
|
|
8
|
+
import { docLink } from '../docs-links.js';
|
|
8
9
|
import { inspectFlow } from '../flow-inspection.js';
|
|
9
10
|
import { publishFlows, publishFlowLifecycle, publishDoctor, flowStatus } from '../flow-publish.js';
|
|
10
11
|
import { resolveRecord, unwrapSysId } from '../resolve-record.js';
|
|
11
12
|
import { createFlowFromManifest, updateFlowFromManifest, readCurrentUpdateSet, readCatalogItemVariables } from '../flow-create.js';
|
|
12
13
|
import { alignUpdateSetCapture } from '../context.js';
|
|
14
|
+
import { assertMutationScope, assertMutationRecordScope } from '../intended-context.js';
|
|
13
15
|
import { EXCLUDED_TRIGGER_TYPES, SUPPORTED_TRIGGER_TYPES, readTriggerCatalog, readTriggerInputDefinitions } from '../flow-triggers.js';
|
|
14
16
|
import { testFlow } from '../flow-test.js';
|
|
15
17
|
import { releaseOwnFlowSafeEdit } from '../flow-safe-edit.js';
|
|
@@ -73,7 +75,7 @@ function triggerGuidance(trigger) {
|
|
|
73
75
|
};
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
|
|
77
79
|
|
|
78
80
|
function renderChecks(checks) {
|
|
79
81
|
return checks.map((c) => {
|
|
@@ -86,9 +88,7 @@ export function flowsCmd(wrap) {
|
|
|
86
88
|
const originalWrap = wrap;
|
|
87
89
|
wrap = handler => originalWrap((argv, app) => cancelled(() => handler(argv, app)));
|
|
88
90
|
return {
|
|
89
|
-
|
|
90
|
-
aliases: ['flow'],
|
|
91
|
-
describe: 'Manage Flow Designer flows',
|
|
91
|
+
...flowsCmdDefinition,
|
|
92
92
|
builder: (yargs) => {
|
|
93
93
|
return yargs
|
|
94
94
|
.command({
|
|
@@ -96,7 +96,11 @@ export function flowsCmd(wrap) {
|
|
|
96
96
|
describe: 'Download/decode visible flows into a private cache and search literal text (first use can be slow)',
|
|
97
97
|
builder: y => y
|
|
98
98
|
.positional('term', { type: 'string', describe: 'Case-insensitive literal text to find in readable definitions' })
|
|
99
|
-
.option('refresh', { type: 'boolean', default: false, describe: 'Rebuild the decoded cache; warm searches still revalidate source access' })
|
|
99
|
+
.option('refresh', { type: 'boolean', default: false, describe: 'Rebuild the decoded cache; warm searches still revalidate source access' })
|
|
100
|
+
.epilogue(`Example:
|
|
101
|
+
jsn flows search approval
|
|
102
|
+
Interactive use can pick a flow; scripts pass the term.
|
|
103
|
+
Documentation: ${docLink('flows')}`),
|
|
100
104
|
handler: wrap(async (argv, app) => {
|
|
101
105
|
app.requireInstance();
|
|
102
106
|
const session = app.session || {};
|
|
@@ -316,6 +320,7 @@ export function flowsCmd(wrap) {
|
|
|
316
320
|
resource: argv.action ? 'Custom action' : 'Flow',
|
|
317
321
|
}));
|
|
318
322
|
|
|
323
|
+
await assertMutationRecordScope(app, argv.action ? 'sys_hub_action_type_definition' : 'sys_hub_flow', sysID);
|
|
319
324
|
await confirmDesignerMutation(argv, app, `Publish and activate ${argv.action ? 'action' : 'flow'} ${sysID}?`);
|
|
320
325
|
if (!argv.action) {
|
|
321
326
|
const lifecycle = await publishFlowLifecycle(app.sdk, app.getEffectiveInstance(), sysID);
|
|
@@ -403,7 +408,12 @@ export function flowsCmd(wrap) {
|
|
|
403
408
|
app.requireInstance();
|
|
404
409
|
const identifier = await pickFlow(argv, app);
|
|
405
410
|
if (identifier === undefined) return;
|
|
411
|
+
if (app.mutationContext?.verified) {
|
|
412
|
+
const source = await resolveRecord(app.sdk, { table: 'sys_hub_flow', identifier, matchField: 'name', resource: 'Flow' });
|
|
413
|
+
assertMutationScope(app.mutationContext, source.sys_scope, 'Flow clone source');
|
|
414
|
+
}
|
|
406
415
|
const plan = await prepareFlowClone(app.sdk, app.getEffectiveInstance(), identifier, { ...argv, interactive: canUsePicker(app, argv) });
|
|
416
|
+
assertMutationScope(app.mutationContext, plan.scope, 'Flow clone');
|
|
407
417
|
await confirmDesignerMutation(argv, app,
|
|
408
418
|
`Clone ${plan.source.name} (${plan.source.id}) as ${JSON.stringify(plan.name)} in ${plan.scope}; inactive Draft, source unchanged`,
|
|
409
419
|
['flows', 'clone', plan.source.id, '--name', plan.name]);
|
|
@@ -432,6 +442,7 @@ export function flowsCmd(wrap) {
|
|
|
432
442
|
} catch (error) {
|
|
433
443
|
throw new Error(`Invalid flow manifest JSON: ${error.message}`, { cause: error });
|
|
434
444
|
}
|
|
445
|
+
assertMutationScope(app.mutationContext, manifest.scope, 'Flow creation manifest');
|
|
435
446
|
const result = await createFlowFromManifest(app.sdk, app.getEffectiveInstance(), manifest, {
|
|
436
447
|
readUpdateSet: () => readCurrentUpdateSet(app.sdk),
|
|
437
448
|
ensureCapture: intended => alignUpdateSetCapture(app.sdk, intended),
|
|
@@ -477,6 +488,11 @@ export function flowsCmd(wrap) {
|
|
|
477
488
|
} catch (error) {
|
|
478
489
|
throw new Error(`Invalid flow update manifest JSON: ${error.message}`, { cause: error });
|
|
479
490
|
}
|
|
491
|
+
if (!argv.preview && app.mutationContext?.verified) {
|
|
492
|
+
const target = await resolveRecord(app.sdk, { table: 'sys_hub_flow', identifier, matchField: 'name', resource: 'Flow' });
|
|
493
|
+
assertMutationScope(app.mutationContext, target.sys_scope, 'Flow update target');
|
|
494
|
+
if (manifest.scope !== undefined) assertMutationScope(app.mutationContext, manifest.scope, 'Flow update manifest');
|
|
495
|
+
}
|
|
480
496
|
if (!argv.preview) await confirmDesignerMutation(argv, app, `Update flow ${identifier}; unspecified components and inputs are preserved. A published flow is edited as its working definition: the published snapshot must stay unchanged.`);
|
|
481
497
|
const result = await updateFlowFromManifest(app.sdk, app.getEffectiveInstance(), argv.identifier, manifest, {
|
|
482
498
|
preview: argv.preview,
|
|
@@ -540,6 +556,7 @@ export function flowsCmd(wrap) {
|
|
|
540
556
|
sysparm_limit: '1',
|
|
541
557
|
}));
|
|
542
558
|
if (!flow) throw errUsage(`Flow ${identifier} (${sysID}) was not found`);
|
|
559
|
+
assertMutationScope(app.mutationContext, flow.sys_scope, 'Flow deletion target');
|
|
543
560
|
const name = getStringField(flow, 'name');
|
|
544
561
|
const active = getStringField(flow, 'active') === 'true';
|
|
545
562
|
const counted = async () => {
|
|
@@ -575,7 +592,7 @@ export function flowsCmd(wrap) {
|
|
|
575
592
|
}),
|
|
576
593
|
})
|
|
577
594
|
.epilogue('Run "jsn flows <command> --help" for details. In a terminal you can omit the target and pick\n'
|
|
578
|
-
+
|
|
595
|
+
+ `one; scripts use explicit identifiers and manifests.\nDocumentation: ${docLink('flows')}`);
|
|
579
596
|
},
|
|
580
597
|
handler: wrap(async (_argv, app) => {
|
|
581
598
|
const summary = 'Manage Flow Designer flows from the sys_hub_flow table. Flow structure comes from the ProcessFlow API, so V1, V2 and subflow definitions all render in full.';
|
|
@@ -3,7 +3,7 @@ import { declareCapabilities } from '../capabilities.js';
|
|
|
3
3
|
|
|
4
4
|
// add/remove write sys_user_grmember; the mutation guard (instance +
|
|
5
5
|
// read-only profile) and the delete confirmation both key off this.
|
|
6
|
-
declareCapabilities('groupmembers', { mutationSubcommands: ['add', 'remove'] });
|
|
6
|
+
declareCapabilities('groupmembers', { mutationContext: 'operational', mutationSubcommands: ['add', 'remove'] });
|
|
7
7
|
|
|
8
8
|
export function groupMembersCmd(wrap) {
|
|
9
9
|
return {
|
|
@@ -3,7 +3,7 @@ import { declareCapabilities } from '../capabilities.js';
|
|
|
3
3
|
|
|
4
4
|
// add/remove write sys_group_has_role; the mutation guard (instance +
|
|
5
5
|
// read-only profile) and the delete confirmation both key off this.
|
|
6
|
-
declareCapabilities('grouproles', { mutationSubcommands: ['add', 'remove'] });
|
|
6
|
+
declareCapabilities('grouproles', { mutationContext: 'operational', mutationSubcommands: ['add', 'remove'] });
|
|
7
7
|
|
|
8
8
|
export function groupRolesCmd(wrap) {
|
|
9
9
|
return {
|
package/src/commands/groups.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { formatRecordForDisplay, getStringField, interactiveList, resolveFieldsParam, assertSafeExactMatch, buildRecordPayload } from '../helpers.js';
|
|
2
2
|
import { declareCapabilities } from '../capabilities.js';
|
|
3
3
|
|
|
4
|
-
declareCapabilities('groups', { mutationSubcommands: ['create', 'update', 'delete'] });
|
|
4
|
+
declareCapabilities('groups', { mutationContext: 'operational', mutationSubcommands: ['create', 'update', 'delete'] });
|
|
5
5
|
|
|
6
6
|
export function groupsCmd(wrap) {
|
|
7
7
|
return {
|
|
@@ -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');
|
|
@@ -302,12 +302,7 @@ async function promptMidCredentials(app, argv) {
|
|
|
302
302
|
const validation = await validateMidCredentials(app.getEffectiveInstance(), username, password);
|
|
303
303
|
return { username, password, releaseName: validation.releaseName };
|
|
304
304
|
} catch (error) {
|
|
305
|
-
|
|
306
|
-
if (answer.trim().toLowerCase() === 'q') {
|
|
307
|
-
const quit = new Error('MID Server installation cancelled');
|
|
308
|
-
quit.code = 'cancelled';
|
|
309
|
-
throw quit;
|
|
310
|
-
}
|
|
305
|
+
await input({ message: `${error.message}. Press Enter to retry or Esc to cancel:` });
|
|
311
306
|
username = argv.username || '';
|
|
312
307
|
}
|
|
313
308
|
}
|
|
@@ -422,9 +417,7 @@ async function showMidServerLogs(app, identifier, argv) {
|
|
|
422
417
|
|
|
423
418
|
export function midserversCmd(wrap) {
|
|
424
419
|
return {
|
|
425
|
-
|
|
426
|
-
aliases: ['midserver', 'mid'],
|
|
427
|
-
describe: 'Manage ServiceNow MID Servers and run commands through them',
|
|
420
|
+
...midserversCmdDefinition,
|
|
428
421
|
builder: (y) => y
|
|
429
422
|
.command(midDiagnosticsCommand('issues', wrap))
|
|
430
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',
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { declareCapabilities } from '../capabilities.js';
|
|
2
|
+
import { inventoryCompareCommand } from '../instance-inventory.js';
|
|
3
|
+
|
|
4
|
+
declareCapabilities('plugins', { skipContextHeader: true });
|
|
5
|
+
export const pluginsCmd = wrap => ({
|
|
6
|
+
command: 'plugins', describe: 'Inspect platform plugin differences across instances',
|
|
7
|
+
builder: p => p.command(inventoryCompareCommand(wrap, 'plugins')),
|
|
8
|
+
handler: wrap(async (_argv, app) => app.ok({ commands: ['compare'] }, { summary: 'Use jsn compare --source pdi --target vendor for both inventories; jsn plugins compare --source pdi --target vendor for plugins only' })),
|
|
9
|
+
});
|
package/src/commands/records.js
CHANGED
|
@@ -5,8 +5,10 @@ import { errUsage } from '../errors.js';
|
|
|
5
5
|
import { AmbClient } from '../amb.js';
|
|
6
6
|
import { watchRecord } from '../record-watch.js';
|
|
7
7
|
import { declareCapabilities } from '../capabilities.js';
|
|
8
|
+
import { assertMutationRecordScope, assertMutationScope } from '../intended-context.js';
|
|
8
9
|
|
|
9
10
|
declareCapabilities('records', {
|
|
11
|
+
mutationContext: 'table',
|
|
10
12
|
mutationSubcommands: ['create', 'update', 'delete', 'bulk'],
|
|
11
13
|
});
|
|
12
14
|
|
|
@@ -149,7 +151,8 @@ export function recordsCmd(wrap) {
|
|
|
149
151
|
// Text/table fallback (or sys-id direct lookup)
|
|
150
152
|
const fields = resolveFieldsParam(columns);
|
|
151
153
|
const params = recordListParams({ limit: argv['sys-id'] ? 1 : argv.limit, offset: argv.offset, fields, query });
|
|
152
|
-
const
|
|
154
|
+
const responseMetadata = {};
|
|
155
|
+
const records = await listRecords(app.sdk, { table, params, displayValues: argv.displayValues, responseMetadata });
|
|
153
156
|
const missingColumns = fields ? findOmittedColumns(records, columns) : [];
|
|
154
157
|
const presentColumns = missingColumns.length ? columns.filter(c => !missingColumns.includes(c)) : columns;
|
|
155
158
|
const displayRecords = fields && !argv.displayValues ? records.map(r => formatRecordForDisplay(r, presentColumns)) : records;
|
|
@@ -160,7 +163,10 @@ export function recordsCmd(wrap) {
|
|
|
160
163
|
const countsOn = argv.count !== false && profile.include_counts !== false;
|
|
161
164
|
let total;
|
|
162
165
|
if (countsOn && !argv['sys-id']) {
|
|
163
|
-
|
|
166
|
+
total = responseMetadata.total;
|
|
167
|
+
if (total === undefined) {
|
|
168
|
+
try { total = await app.sdk.aggregateCount(table, query); } catch { total = undefined; }
|
|
169
|
+
}
|
|
164
170
|
}
|
|
165
171
|
|
|
166
172
|
const breadcrumbs = [
|
|
@@ -529,6 +535,10 @@ export function recordsCmd(wrap) {
|
|
|
529
535
|
offset += recs.length;
|
|
530
536
|
}
|
|
531
537
|
const targets = sysIDs.slice(0, argv.limit);
|
|
538
|
+
if (app.mutationContext?.verified) {
|
|
539
|
+
if (Object.hasOwn(set, 'sys_scope')) assertMutationScope(app.mutationContext, set.sys_scope, 'Bulk payload');
|
|
540
|
+
for (const id of targets) await assertMutationRecordScope(app, argv.table, id);
|
|
541
|
+
}
|
|
532
542
|
let updated = 0;
|
|
533
543
|
const failures = [];
|
|
534
544
|
for (const id of targets) {
|
package/src/commands/scopes.js
CHANGED
|
@@ -3,7 +3,7 @@ import { requireCurrentUserSysId, setCurrentApplication } from '../context.js';
|
|
|
3
3
|
import { declareCapabilities } from '../capabilities.js';
|
|
4
4
|
import { unwrapSysId } from '../resolve-record.js';
|
|
5
5
|
|
|
6
|
-
declareCapabilities('scopes', { mutationSubcommands: ['create', 'set'], mutationContextExemptSubcommands: ['
|
|
6
|
+
declareCapabilities('scopes', { mutationSubcommands: ['create', 'set'], mutationContextExemptSubcommands: ['set'] });
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Resolve a scope identifier to a single sys_scope record.
|
package/src/commands/scrapi.js
CHANGED
|
@@ -14,7 +14,7 @@ import { declareCapabilities } from '../capabilities.js';
|
|
|
14
14
|
|
|
15
15
|
// `scrapi create` builds a full Scripted REST API in one call (list/show are
|
|
16
16
|
// reads). Registered at the root.
|
|
17
|
-
declareCapabilities('scrapi', { mutationSubcommands: ['create'] });
|
|
17
|
+
declareCapabilities('scrapi', { transactionScopeOption: 'scope', mutationSubcommands: ['create'] });
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Parse a --resource flag value of the form:
|
|
@@ -257,7 +257,7 @@ export function scrapiCmd(wrap) {
|
|
|
257
257
|
const description = argv.description || '';
|
|
258
258
|
|
|
259
259
|
// 2. Resolve scope if provided
|
|
260
|
-
let scopeSysId = null;
|
|
260
|
+
let scopeSysId = app.mutationContext?.application_id || null;
|
|
261
261
|
if (argv.scope) {
|
|
262
262
|
scopeSysId = await app.sdk.resolveScope(argv.scope);
|
|
263
263
|
if (!scopeSysId) {
|
package/src/commands/setup.js
CHANGED
|
@@ -41,40 +41,10 @@ const setupHelp = () => [
|
|
|
41
41
|
'Configure settings directly: jsn setup --configure-defaults or jsn setup --configure-docs.',
|
|
42
42
|
].join('\n');
|
|
43
43
|
|
|
44
|
-
/** The setup hub
|
|
45
|
-
export const authHubPrompt = async (
|
|
46
|
-
const {
|
|
47
|
-
return
|
|
48
|
-
const [active, setActive] = useState(0);
|
|
49
|
-
const choices = config.choices;
|
|
50
|
-
|
|
51
|
-
useKeypress((key) => {
|
|
52
|
-
if (key.name === 'q' || key.name === 'escape') {
|
|
53
|
-
done(undefined);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (isEnterKey(key)) {
|
|
57
|
-
done(choices[active].value);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (isUpKey(key) && active > 0) setActive(active - 1);
|
|
61
|
-
if (isDownKey(key) && active < choices.length - 1) setActive(active + 1);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const page = usePagination({
|
|
65
|
-
items: choices,
|
|
66
|
-
active,
|
|
67
|
-
// Pagination budgets terminal lines, including the section headings.
|
|
68
|
-
pageSize: choices.length + new Set(choices.map(choice => choice.section)).size * 2 - 1,
|
|
69
|
-
loop: false,
|
|
70
|
-
renderItem: ({ item, isActive }) => {
|
|
71
|
-
const index = choices.indexOf(item);
|
|
72
|
-
const heading = choices[index - 1]?.section !== item.section ? `${index ? '\n' : ''} ${item.section}\n` : '';
|
|
73
|
-
return `${heading}${isActive ? '❯' : ' '} ${item.name}`;
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
return `${config.message}\n${page}\n\n↑↓ navigate • ⏎ select • q/Esc exit`;
|
|
77
|
-
})(...args);
|
|
44
|
+
/** The setup hub shares searchable local menus; Escape leaves the hub. */
|
|
45
|
+
export const authHubPrompt = async (config = {}, context = {}) => {
|
|
46
|
+
const { select, escapeResult } = await import('../prompts.js');
|
|
47
|
+
return select({ ...config, escapeValue: escapeResult(undefined) }, context);
|
|
78
48
|
};
|
|
79
49
|
|
|
80
50
|
/** Interactive hub: what do you want to do? Returns an action or undefined on exit. */
|
|
@@ -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' })
|
package/src/commands/store.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { inventoryCompareCommand } from '../instance-inventory.js';
|
|
1
2
|
import { confirmDelete, quoteShellArg, truncateString } from '../helpers.js';
|
|
2
3
|
import { declareCapabilities } from '../capabilities.js';
|
|
3
4
|
import { AppError, errUsage } from '../errors.js';
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
// App Client, which writes installed-application state rather than capturing
|
|
17
18
|
// metadata into the selected application/update set.
|
|
18
19
|
declareCapabilities('store', {
|
|
20
|
+
skipContextHeaderSubcommands: ['compare'],
|
|
19
21
|
mutationSubcommands: ['install', 'update'],
|
|
20
22
|
mutationContextExemptSubcommands: ['install', 'update'],
|
|
21
23
|
});
|
|
@@ -229,6 +231,7 @@ export function storeCmd(wrap) {
|
|
|
229
231
|
command: 'store [subcommand]',
|
|
230
232
|
describe: 'Discover ServiceNow Store applications, inspect versions and entitlement, and request explicit installs/updates',
|
|
231
233
|
builder: y => y
|
|
234
|
+
.command(inventoryCompareCommand(wrap, 'store'))
|
|
232
235
|
.command({
|
|
233
236
|
command: 'list',
|
|
234
237
|
describe: 'List Store applications for a tab (read-only)',
|
|
@@ -302,7 +305,7 @@ export function storeCmd(wrap) {
|
|
|
302
305
|
handler: wrap(async (argv, app) => runLifecycle(argv, app, 'update')),
|
|
303
306
|
}),
|
|
304
307
|
handler: wrap(async (argv, app) => {
|
|
305
|
-
report(app, argv, { commands: ['search', 'list', 'show', 'status', 'install', 'update'] }, {
|
|
308
|
+
report(app, argv, { commands: ['compare', 'search', 'list', 'show', 'status', 'install', 'update'] }, {
|
|
306
309
|
summary: 'ServiceNow Store applications',
|
|
307
310
|
breadcrumbs: [hint('list', 'jsn store list --tab installed', 'List installed applications'),
|
|
308
311
|
hint('search', 'jsn store search "<term>"', 'Search applications available to this instance'),
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { subscriptionsCmdDefinition } from '../command-families.js';
|
|
2
|
+
import { refreshSchedules } from '../schedule-cache.js';
|
|
3
|
+
import { loadSchedule, scheduleCatalog, scheduleSnapshot, formatSchedule, estimateSubscription, formatEstimate } from '../subscriptions.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export function subscriptionsCmd(wrap) {
|
|
7
|
+
const local = (argv, app) => {
|
|
8
|
+
const snapshot = scheduleSnapshot();
|
|
9
|
+
const schedules = scheduleCatalog({ product: argv.product, sku: argv.sku, id: argv.id, snapshot });
|
|
10
|
+
const data = { provenance: snapshot.provenance, schedules, coverage: { index_documents: new Set(snapshot.schedules.map(s => s.source_url)).size, archive: 'unavailable', sku_mapping: 'only explicitly normalized codes; empty results do not establish absence of rights' } };
|
|
11
|
+
Object.defineProperty(data, '_formatted', { value: [
|
|
12
|
+
`Local catalog snapshot (${data.provenance.source}; ${data.provenance.freshness}; revision ${data.provenance.revision || 'bundled'}; retrieved ${data.provenance.retrieved_at || 'bundled'}; stale ${data.provenance.stale}); contractual applicability unverified. Archive unavailable.`,
|
|
13
|
+
...schedules.flatMap(s => [
|
|
14
|
+
`${s.id} | ${s.product} | ${s.effective_date || s.source_version || 'date unverified'} | ${s.normalization_status || 'not specified'}`,
|
|
15
|
+
s.source_url,
|
|
16
|
+
`Measurement: ${s.measurement || 'not specified; inspection only'}. SKU mapping: ${(s.skus || []).join(', ') || 'unverified'}`,
|
|
17
|
+
...(s.unknowns || s.limitations || []),
|
|
18
|
+
...(argv.id ? [formatSchedule(s)] : []),
|
|
19
|
+
]),
|
|
20
|
+
].join('\n') });
|
|
21
|
+
app.ok(data, { summary: 'Local dated metering schedules, not purchased rights' });
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
...subscriptionsCmdDefinition,
|
|
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
|
+
const origin = process.env.JSN_DOCS_URL || app.config?.docs?.url;
|
|
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);
|
|
28
|
+
const provenance = await refreshSchedules(manifest);
|
|
29
|
+
app.ok({ provenance }, { summary: 'Validated schedule cache refreshed' });
|
|
30
|
+
}) }).command({ command: 'schedules', describe: 'Inspect validated cache or bundled source-backed schedules offline', builder: b => b.option('product', { type: 'string' }).option('sku', { type: 'string' }).option('id', { type: 'string' }), handler: wrap(local) })
|
|
31
|
+
.command({ command: 'estimate <product>', describe: 'Read-only ITOM population comparison, not billing or a 90-day meter',
|
|
32
|
+
builder: b => b.positional('product', { type: 'string', describe: 'ITOM; arbitrary SKUs and HRSD unsupported' })
|
|
33
|
+
.option('schedule', { type: 'string', describe: 'Explicit dated schedule ID from subscriptions schedules' })
|
|
34
|
+
.option('assume-eligible', { type: 'boolean', default: false, describe: 'Hypothetically treat mapped populations as managed and component-eligible, exclusions unknown' }),
|
|
35
|
+
handler: wrap(async (argv, app) => {
|
|
36
|
+
// Validate unsupported selections before requesting an instance.
|
|
37
|
+
const selected = loadSchedule(argv.schedule);
|
|
38
|
+
if (String(argv.product).toUpperCase() !== 'ITOM' || selected.measurement !== 'illustrative-population') await estimateSubscription(null, argv.product, { schedule: argv.schedule });
|
|
39
|
+
app.requireInstance();
|
|
40
|
+
const report = await estimateSubscription(app.sdk, argv.product, { schedule: argv.schedule, assumeEligible: argv.assumeEligible });
|
|
41
|
+
Object.defineProperty(report, '_formatted', { value: formatEstimate(report) });
|
|
42
|
+
app.ok(report, { summary: 'Incomplete illustrative ITOM population comparison; no authoritative total' });
|
|
43
|
+
}),
|
|
44
|
+
}),
|
|
45
|
+
handler: wrap(local),
|
|
46
|
+
};
|
|
47
|
+
}
|
package/src/commands/tickets.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getRecord, listRecords, recordListParams, createRecord, updateRecord, d
|
|
|
4
4
|
import { resolveSysId } from '../resolve-record.js';
|
|
5
5
|
import { declareCapabilities } from '../capabilities.js';
|
|
6
6
|
|
|
7
|
-
declareCapabilities('tickets', { mutationSubcommands: ['create', 'update', 'delete'] });
|
|
7
|
+
declareCapabilities('tickets', { mutationContext: 'operational', mutationSubcommands: ['create', 'update', 'delete'] });
|
|
8
8
|
|
|
9
9
|
export function ticketsCmd(wrap) {
|
|
10
10
|
return {
|
package/src/commands/users.js
CHANGED
|
@@ -2,7 +2,7 @@ import { formatRecordForDisplay, getStringField, interactiveList, resolveFieldsP
|
|
|
2
2
|
import { resolveRecord, resolveSysId } from '../resolve-record.js';
|
|
3
3
|
import { declareCapabilities } from '../capabilities.js';
|
|
4
4
|
|
|
5
|
-
declareCapabilities('users', { mutationSubcommands: ['create', 'update', 'delete'] });
|
|
5
|
+
declareCapabilities('users', { mutationContext: 'operational', mutationSubcommands: ['create', 'update', 'delete'] });
|
|
6
6
|
|
|
7
7
|
export function usersCmd(wrap) {
|
|
8
8
|
return {
|
|
@@ -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/config.js
CHANGED
|
@@ -58,6 +58,7 @@ function loadFromFile(cfg, filePath, source) {
|
|
|
58
58
|
if (fileCfg.connection_defaults && typeof fileCfg.connection_defaults === 'object') cfg.connectionDefaults = fileCfg.connection_defaults;
|
|
59
59
|
if (fileCfg.docs && typeof fileCfg.docs === 'object') cfg.docs = fileCfg.docs;
|
|
60
60
|
}
|
|
61
|
+
if (source === 'local' && Object.hasOwn(fileCfg, 'write_context')) cfg.writeContext = fileCfg.write_context;
|
|
61
62
|
if (fileCfg.instance_url) {
|
|
62
63
|
cfg.instanceURL = fileCfg.instance_url;
|
|
63
64
|
cfg.sources.instance_url = source;
|
package/src/context.js
CHANGED
|
@@ -122,62 +122,14 @@ export async function readEffectiveUpdateSet(sdk) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
/**
|
|
126
|
-
* Make the warmed session's effective capture set match the persisted choice
|
|
127
|
-
* before content writes, and verify the result.
|
|
128
|
-
*
|
|
129
|
-
* A fresh CLI invocation is a fresh authenticated session; the persisted
|
|
130
|
-
* preference is the user's intentional choice, but nothing guarantees the new
|
|
131
|
-
* session inherited it (`jsn updatesets create`/`set` may have selected the set
|
|
132
|
-
* in a session that has since ended). When the two disagree, re-apply the
|
|
133
|
-
* persisted selection through the same picker contract and verify it.
|
|
134
|
-
*
|
|
135
|
-
* Returns a report instead of throwing when the effective selection cannot be
|
|
136
|
-
* read at all (for example an auth mode that cannot keep a UI session). A
|
|
137
|
-
* readable-but-unalignable mismatch throws, so a content write never proceeds
|
|
138
|
-
* into a set the CLI would then wrongly report.
|
|
139
|
-
*/
|
|
125
|
+
/** Verify capture consistency without ever changing the session. */
|
|
140
126
|
export async function alignUpdateSetCapture(sdk, intended) {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
intended: intended || null,
|
|
148
|
-
effective: null,
|
|
149
|
-
aligned: null,
|
|
150
|
-
action: 'unverified',
|
|
151
|
-
reason: `effective session selection could not be read: ${error.message}`,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
const report = { intended: intended || null, effective, aligned: null, action: 'none' };
|
|
155
|
-
if (!intendedId) {
|
|
156
|
-
report.reason = 'no persisted update-set selection (Default or unreadable preference)';
|
|
157
|
-
return report;
|
|
158
|
-
}
|
|
159
|
-
if (effective.sys_id === intendedId) {
|
|
160
|
-
report.aligned = true;
|
|
161
|
-
return report;
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
await setCurrentUpdateSet(sdk, null, intendedId);
|
|
165
|
-
} catch (error) {
|
|
166
|
-
const message = `Session capture context could not be aligned with the selected update set before any content write. `
|
|
167
|
-
+ `This session resolves to ${effective.sys_id || 'an empty selection'} (${effective.name || 'unknown'}), `
|
|
168
|
-
+ `but the persisted selection is ${intended?.name || intendedId} (${intendedId}). ${error.message} `
|
|
169
|
-
+ 'No content was written. Re-select explicitly with `jsn updatesets set` in an interactive session, '
|
|
170
|
-
+ 'or use an auth profile that keeps a UI session, then retry.';
|
|
171
|
-
const failure = new Error(message, { cause: error });
|
|
172
|
-
failure.capture_context = { ...report, aligned: false, action: 'select_failed' };
|
|
173
|
-
throw failure;
|
|
174
|
-
}
|
|
175
|
-
report.previous_effective = effective;
|
|
176
|
-
report.effective = await readEffectiveUpdateSet(sdk);
|
|
177
|
-
report.action = 'selected';
|
|
178
|
-
report.aligned = report.effective.sys_id === intendedId;
|
|
179
|
-
if (!report.aligned) {
|
|
180
|
-
report.reason = 'session still resolves to a different set after re-selection';
|
|
127
|
+
const effective = await readEffectiveUpdateSet(sdk);
|
|
128
|
+
const report = { intended: intended || null, effective, aligned: false, action: 'refused' };
|
|
129
|
+
if (!intended?.sys_id || effective.sys_id !== intended.sys_id) {
|
|
130
|
+
const error = new Error('Effective capture set differs from the persisted selection or is unknown. No context was switched; select it explicitly with jsn updatesets set.');
|
|
131
|
+
error.capture_context = report;
|
|
132
|
+
throw error;
|
|
181
133
|
}
|
|
182
|
-
return report;
|
|
134
|
+
return { ...report, aligned: true, action: 'none' };
|
|
183
135
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// GENERATED FILENAME: keep in sync with site/config/docs-links.json.
|
|
2
|
+
// The npm package ships only cli/, so this projection is checked in and verified
|
|
3
|
+
// by site/test/docs_links_test.rb. Edit the registry, then regenerate this file.
|
|
4
|
+
export const SITE_ORIGIN = 'https://jsn.jace.pro';
|
|
5
|
+
export const ROOT_DOC_LINK = '/docs/';
|
|
6
|
+
export const DOC_LINKS = Object.freeze({
|
|
7
|
+
codesearch: '/features/servicenow-code-search-cli/',
|
|
8
|
+
docs: '/docs/cli-guide/#jsn-cli-guide',
|
|
9
|
+
flows: '/docs/flows/#flow-definition-search',
|
|
10
|
+
records: '/docs/records/#watching-a-servicenow-record',
|
|
11
|
+
updatesets: '/docs/updatesets/#transfer-an-update-set',
|
|
12
|
+
midservers: '/docs/midservers/#remote-mid-management-over-ssh',
|
|
13
|
+
setup: '/docs/setup/#connect-an-instance',
|
|
14
|
+
auth: '/docs/setup/#authentication-lifecycle-review',
|
|
15
|
+
skill: '/docs/agents/#use-jsn-with-ai-agents',
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/** Absolute documentation URL for one registered command family, or null when
|
|
19
|
+
* the family has no migrated guide. Callers decide how to render a miss. */
|
|
20
|
+
export function resolveDocLink(name) {
|
|
21
|
+
const path = DOC_LINKS[name];
|
|
22
|
+
return path ? `${SITE_ORIGIN}${path}` : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Absolute documentation URL for one registered command family. */
|
|
26
|
+
export function docLink(name) {
|
|
27
|
+
return resolveDocLink(name) || `${SITE_ORIGIN}${ROOT_DOC_LINK}`;
|
|
28
|
+
}
|
package/src/flow-create.js
CHANGED
|
@@ -1914,6 +1914,10 @@ async function planManifestSteps({ manifest, beforeDefinition, existingActions,
|
|
|
1914
1914
|
export async function createFlowFromManifest(sdk, instance, inputManifest, options = {}) {
|
|
1915
1915
|
const manifest = validateFlowManifest(inputManifest);
|
|
1916
1916
|
const scope = manifest.scope;
|
|
1917
|
+
if (sdk.mutationContext?.verified) {
|
|
1918
|
+
const { assertMutationScope } = await import('./intended-context.js');
|
|
1919
|
+
assertMutationScope(sdk.mutationContext, scope, 'Flow creation transaction');
|
|
1920
|
+
}
|
|
1917
1921
|
const idFactory = options.idFactory || (() => randomUUID());
|
|
1918
1922
|
const readUpdateSet = options.readUpdateSet || (async () => null);
|
|
1919
1923
|
const snapshots = [];
|
|
@@ -2141,6 +2145,11 @@ export async function updateFlowFromManifest(sdk, instance, identifier, inputMan
|
|
|
2141
2145
|
const published = !lifecycle.draft;
|
|
2142
2146
|
const targetScope = stringValue(target.flow.sys_scope) || stringValue(target.flow.scope);
|
|
2143
2147
|
const scope = manifest.scope ?? targetScope;
|
|
2148
|
+
if (sdk.mutationContext?.verified) {
|
|
2149
|
+
const { assertMutationScope } = await import('./intended-context.js');
|
|
2150
|
+
assertMutationScope(sdk.mutationContext, targetScope, 'Resolved flow target');
|
|
2151
|
+
assertMutationScope(sdk.mutationContext, scope, 'Flow update transaction');
|
|
2152
|
+
}
|
|
2144
2153
|
const readUpdateSet = options.readUpdateSet || (async () => null);
|
|
2145
2154
|
if (!scope) throw new Error(`Flow ${flowId} has no transaction scope`);
|
|
2146
2155
|
if (manifest.scope !== undefined && targetScope && manifest.scope !== targetScope) throw new Error(`Flow ${flowId} scope does not match the update manifest`);
|