@jacebenson/jsn 5.5.1-dev.168.1 → 5.5.1-dev.169.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/cli.js +4 -5
- package/src/commands/auth.js +10 -5
- package/src/commands/setup.js +3 -4
- package/src/welcome.js +26 -13
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ import { App } from './app.js';
|
|
|
10
10
|
import { resolveSession, applySession } from './session.js';
|
|
11
11
|
import { renderHelp, renderTips } from './help.js';
|
|
12
12
|
import { isMutationCommand, refreshMutationCommands } from './mutations.js';
|
|
13
|
-
import {
|
|
13
|
+
import { maybeShowHome } from './welcome.js';
|
|
14
14
|
import { skippedUpdatesCmd } from './commands/skipped-updates.js';
|
|
15
15
|
import { isLocalPreview, noInstanceCommands, dailyCheckSkipCommands, contextHeaderSkipCommands } from './capabilities.js';
|
|
16
16
|
import { guardExit, exitWithError, AppError, CodeUsage } from './errors.js';
|
|
@@ -601,11 +601,10 @@ export function buildCLI() {
|
|
|
601
601
|
}
|
|
602
602
|
process.exit(0);
|
|
603
603
|
}
|
|
604
|
-
//
|
|
605
|
-
//
|
|
606
|
-
// format, no configured profile, and not shown before.
|
|
604
|
+
// Human terminals always get the compact local home. Machine and
|
|
605
|
+
// non-interactive discovery retain their existing reference output.
|
|
607
606
|
const config = loadConfig(formatArgv);
|
|
608
|
-
const welcome =
|
|
607
|
+
const welcome = maybeShowHome({ argv: formatArgv, requestedFormat, cfg: config });
|
|
609
608
|
if (!welcome) process.stdout.write(renderHelp(config, visibleCommandRegistry(cliInstance.commandRegistry(), config, formatArgv)) + '\n');
|
|
610
609
|
process.exit(0);
|
|
611
610
|
}
|
package/src/commands/auth.js
CHANGED
|
@@ -299,7 +299,7 @@ async function readBrowserSessionFile(file) {
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
/** Collect human answers, then call the same login operation as auth login. */
|
|
302
|
-
export async function loginWizard(app, argv = {}) {
|
|
302
|
+
export async function loginWizard(app, argv = {}, { concise = false } = {}) {
|
|
303
303
|
const { input, select, confirm, password } = await import('../prompts.js');
|
|
304
304
|
const explicitInstance = resolveWizardInstance(app, argv);
|
|
305
305
|
const instance = resolveInstanceArg(explicitInstance || await input({
|
|
@@ -333,8 +333,8 @@ export async function loginWizard(app, argv = {}) {
|
|
|
333
333
|
request['include-counts'] = settings.include_counts;
|
|
334
334
|
request.makeDefault = argv.makeDefault ?? (Object.keys(app.config.profiles || {}).length === 0 && !app.config.defaultProfile
|
|
335
335
|
? true : await confirm({ message: 'Use this profile by default?', default: !app.config.defaultProfile }));
|
|
336
|
-
const result = await loginProfile(request, app);
|
|
337
|
-
if (result.authenticated) {
|
|
336
|
+
const result = await loginProfile(request, app, { concise });
|
|
337
|
+
if (result.authenticated && !concise) {
|
|
338
338
|
process.stdout.write(`Connection preset: ${settings.read_only ? 'read-only' : 'writes allowed'} · deletes ${settings.skip_confirmations ? 'without confirmation' : 'ask first'} · totals ${settings.include_counts ? 'on' : 'off'}\nChange with: jsn auth modify ${result.profile} --read-only\n`);
|
|
339
339
|
}
|
|
340
340
|
return { instanceURL: instance, profileName: result.profile, loggedIn: result.authenticated };
|
|
@@ -552,7 +552,7 @@ function canLogoutBareProfile(app, instance, target, explicitlySelected) {
|
|
|
552
552
|
return sameInstance.length <= 1;
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
-
export async function loginProfile(argv, app) {
|
|
555
|
+
export async function loginProfile(argv, app, { concise = false } = {}) {
|
|
556
556
|
argv = profileSettingValues(argv);
|
|
557
557
|
validateLoginSelectors(argv);
|
|
558
558
|
if (argv.name !== undefined) {
|
|
@@ -810,7 +810,12 @@ Find your instance URL in your browser's address bar when logged into ServiceNow
|
|
|
810
810
|
description: 'Set these at login; --skip-confirmations disables delete prompts',
|
|
811
811
|
},
|
|
812
812
|
] : [];
|
|
813
|
-
|
|
813
|
+
if (concise && canUsePicker(app, argv)) {
|
|
814
|
+
const next = setDefault ? 'jsn incidents list' : `jsn --profile ${quoteShellArg(profileName)} incidents list`;
|
|
815
|
+
app.ok(result, { summary: `${summary}\nNext: ${next}`, breadcrumbs: [] });
|
|
816
|
+
} else {
|
|
817
|
+
app.ok(result, { summary, breadcrumbs });
|
|
818
|
+
}
|
|
814
819
|
return result;
|
|
815
820
|
}
|
|
816
821
|
|
package/src/commands/setup.js
CHANGED
|
@@ -89,7 +89,7 @@ export async function authHubMenu({ promptFn = authHubPrompt, input, output, has
|
|
|
89
89
|
*/
|
|
90
90
|
export async function dispatchSetupAction(app, argv, action) {
|
|
91
91
|
if (action === 'add') {
|
|
92
|
-
return loginWizard(app, argv);
|
|
92
|
+
return loginWizard(app, argv, { concise: true });
|
|
93
93
|
} else if (action === 'login') {
|
|
94
94
|
return loginProfile(argv, app);
|
|
95
95
|
} else if (action === 'status') {
|
|
@@ -147,14 +147,13 @@ export function setupCmd(wrap) {
|
|
|
147
147
|
await saveConfig(app.config);
|
|
148
148
|
}
|
|
149
149
|
if (profileNames.length === 0 && firstSetup) {
|
|
150
|
-
|
|
151
|
-
await showAuthStatus({ ...argv, profile: result.profileName }, app);
|
|
150
|
+
await loginWizard(app, argv, { concise: true });
|
|
152
151
|
return;
|
|
153
152
|
}
|
|
154
153
|
const action = await authHubMenu({ hasProfiles: profileNames.length > 0 });
|
|
155
154
|
if (action === undefined) return;
|
|
156
155
|
const result = await dispatchSetupAction(app, argv, action);
|
|
157
|
-
if (!['status', 'advanced'].includes(action)) await showAuthStatus({ ...argv, profile: result?.profile || result?.profileName }, app);
|
|
156
|
+
if (!['add', 'status', 'advanced'].includes(action)) await showAuthStatus({ ...argv, profile: result?.profile || result?.profileName }, app);
|
|
158
157
|
}),
|
|
159
158
|
};
|
|
160
159
|
}
|
package/src/welcome.js
CHANGED
|
@@ -116,12 +116,12 @@ function configLabels(env, configDir) {
|
|
|
116
116
|
* @param {number} width
|
|
117
117
|
* @returns {string[]}
|
|
118
118
|
*/
|
|
119
|
-
function renderSteps(width) {
|
|
120
|
-
const commandWidth = Math.max(...
|
|
119
|
+
function renderSteps(width, steps = STEPS) {
|
|
120
|
+
const commandWidth = Math.max(...steps.map((step) => step.command.length));
|
|
121
121
|
const alignedColumn = 4 + commandWidth + 2;
|
|
122
|
-
const oneLine =
|
|
122
|
+
const oneLine = steps.every((step) => alignedColumn + step.detail.length <= width);
|
|
123
123
|
const lines = [];
|
|
124
|
-
for (const step of
|
|
124
|
+
for (const step of steps) {
|
|
125
125
|
if (oneLine) {
|
|
126
126
|
lines.push(` ${step.command.padEnd(commandWidth)} ${step.detail}`);
|
|
127
127
|
continue;
|
|
@@ -289,16 +289,29 @@ export function markWelcomeSeen(configDir = globalConfigDir()) {
|
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
/**
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
* The marker is claimed before anything is printed, so an interrupted run
|
|
296
|
-
* (Ctrl-C) can leave the note unshown but never printed twice.
|
|
297
|
-
*
|
|
298
|
-
* @param {object} [opts] — same inputs as shouldShowWelcome, plus the
|
|
299
|
-
* welcomeText inputs (columns, version)
|
|
300
|
-
* @returns {string}
|
|
292
|
+
* Every human bare invocation gets a local-only home. The legacy welcome
|
|
293
|
+
* marker controls only the greeting, never whether the catalog is selected.
|
|
301
294
|
*/
|
|
295
|
+
export function maybeShowHome({ argv = {}, requestedFormat = '', cfg = {}, env = process.env,
|
|
296
|
+
configDir = globalConfigDir(), interactive = canPrompt(), columns = process.stdout?.columns } = {}) {
|
|
297
|
+
if (env.JSN_NO_WELCOME === '1' || !interactive || argv.get || !HUMAN_FORMATS.has(requestedFormat || '')) return '';
|
|
298
|
+
const width = layoutWidth(columns);
|
|
299
|
+
const selected = cfg.activeProfile || cfg.defaultProfile;
|
|
300
|
+
const profile = selected && cfg.profiles?.[selected] ? selected : undefined;
|
|
301
|
+
const steps = profile ? [
|
|
302
|
+
{ command: 'jsn incidents list', detail: 'browse incidents' },
|
|
303
|
+
{ command: 'jsn setup', detail: 'manage connections' },
|
|
304
|
+
{ command: 'jsn --help', detail: 'every command and flag' },
|
|
305
|
+
] : STEPS;
|
|
306
|
+
const greeting = shouldShowWelcome({ argv, requestedFormat, cfg, env, configDir, interactive })
|
|
307
|
+
&& claimWelcome(configDir) !== 'taken';
|
|
308
|
+
const heading = profile ? `Profile: ${profile}` : greeting ? 'Welcome to jsn' : 'Get started';
|
|
309
|
+
const text = [...wrapText(heading, width), '', ...renderSteps(width, steps)].join('\n');
|
|
310
|
+
process.stdout.write(`${text}\n\n`);
|
|
311
|
+
return text;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Legacy once-only note API; bare CLI discovery uses maybeShowHome. */
|
|
302
315
|
export function maybeShowWelcome(opts = {}) {
|
|
303
316
|
if (!shouldShowWelcome(opts)) return '';
|
|
304
317
|
const configDir = opts.configDir || globalConfigDir();
|